diff --git a/src/myutil/FileUtils.java b/src/myutil/FileUtils.java index b8e5ceec81a3e3b09c230eedb858cd28a6096b95..c4dbc4eca7dbb830f8b145d8eed1008c89212c77 100755 --- a/src/myutil/FileUtils.java +++ b/src/myutil/FileUtils.java @@ -1,47 +1,47 @@ /**Copyright or (C) or Copr. GET / ENST, Telecom-Paris, Ludovic Apvrille -ludovic.apvrille AT enst.fr - -This software is a computer program whose purpose is to allow the -edition of TURTLE analysis, design and deployment diagrams, to -allow the generation of RT-LOTOS or Java code from this diagram, -and at last to allow the analysis of formal validation traces -obtained from external tools, e.g. RTL from LAAS-CNRS and CADP -from INRIA Rhone-Alpes. - -This software is governed by the CeCILL license under French law and -abiding by the rules of distribution of free software. You can use, -modify and/ or redistribute the software under the terms of the CeCILL -license as circulated by CEA, CNRS and INRIA at the following URL -"http://www.cecill.info". - -As a counterpart to the access to the source code and rights to copy, -modify and redistribute granted by the license, users are provided only -with a limited warranty and the software's author, the holder of the -economic rights, and the successive licensors have only limited -liability. - -In this respect, the user's attention is drawn to the risks associated -with loading, using, modifying and/or developing or reproducing the -software by the user in light of its specific status of free software, -that may mean that it is complicated to manipulate, and that also -therefore means that it is reserved for developers and experienced -professionals having in-depth computer knowledge. Users are therefore -encouraged to load and test the software's suitability as regards their -requirements in conditions enabling the security of their systems and/or -data to be ensured and, more generally, to use and operate it in the -same conditions as regards security. - -The fact that you are presently reading this means that you have had -knowledge of the CeCILL license and that you accept its terms. - -/** - * Class FileUtils - * Creation: 01/12/2003 - * @version 1.1 01/12/2003 - * @author Ludovic APVRILLE - * @see - */ + ludovic.apvrille AT enst.fr + + This software is a computer program whose purpose is to allow the + edition of TURTLE analysis, design and deployment diagrams, to + allow the generation of RT-LOTOS or Java code from this diagram, + and at last to allow the analysis of formal validation traces + obtained from external tools, e.g. RTL from LAAS-CNRS and CADP + from INRIA Rhone-Alpes. + + This software is governed by the CeCILL license under French law and + abiding by the rules of distribution of free software. You can use, + modify and/ or redistribute the software under the terms of the CeCILL + license as circulated by CEA, CNRS and INRIA at the following URL + "http://www.cecill.info". + + As a counterpart to the access to the source code and rights to copy, + modify and redistribute granted by the license, users are provided only + with a limited warranty and the software's author, the holder of the + economic rights, and the successive licensors have only limited + liability. + + In this respect, the user's attention is drawn to the risks associated + with loading, using, modifying and/or developing or reproducing the + software by the user in light of its specific status of free software, + that may mean that it is complicated to manipulate, and that also + therefore means that it is reserved for developers and experienced + professionals having in-depth computer knowledge. Users are therefore + encouraged to load and test the software's suitability as regards their + requirements in conditions enabling the security of their systems and/or + data to be ensured and, more generally, to use and operate it in the + same conditions as regards security. + + The fact that you are presently reading this means that you have had + knowledge of the CeCILL license and that you accept its terms. + + /** + * Class FileUtils + * Creation: 01/12/2003 + * @version 1.1 01/12/2003 + * @author Ludovic APVRILLE + * @see + */ package myutil; @@ -50,7 +50,7 @@ import java.io.*; public class FileUtils { - + public final static String xml = "xml"; public final static String rtl = "lot"; public final static String lib = "lib"; @@ -58,33 +58,33 @@ public class FileUtils { public final static String dta = "dta"; public final static String rg = "rg"; public final static String aut = "aut"; - public final static String bcg = "bcg"; + public final static String bcg = "bcg"; public final static String dot = "dot"; public final static String lot = "lot"; public final static String tlsa = "tlsa"; - public final static String tif = "tif"; - public final static String svg = "svg"; - + public final static String tif = "tif"; + public final static String svg = "svg"; + public static String getExtension(File f) { String ext = null; String s = f.getName(); int i = s.lastIndexOf('.'); - + if (i > 0 && i < s.length() - 1) { ext = s.substring(i+1).toLowerCase(); } return ext; } - + public static boolean checkFileForSave(File file) throws FileException { boolean ok = true; String pb = ""; - + if (file == null) { return false; } - + try { if (file != null) { if (!file.exists()) { @@ -101,13 +101,13 @@ public class FileUtils { } return true; } - + public static boolean checkFileForOpen(File file) { - + if (file == null) { return false; } - + try { if (file != null) { if (!file.exists()) { @@ -120,16 +120,16 @@ public class FileUtils { } catch (Exception e) { return false; } - + return true; } - + public static String loadFileData(File file) { byte[] ba; try { FileInputStream fis = new FileInputStream(file); int nb = fis.available(); - + ba = new byte[nb]; fis.read(ba); fis.close(); @@ -138,7 +138,7 @@ public class FileUtils { } return new String(ba); } - + // extension is given without the "." public static String addFileExtensionIfMissing(String fileName, String extension) { if (!fileName.endsWith("." + extension)) { @@ -146,61 +146,61 @@ public class FileUtils { } return fileName; } - + // extension is given without the "." public static File addFileExtensionIfMissing(File f, String extension) { /*if (f == null) { - TraceManager.addDev(" nullfile"); - } else { - TraceManager.addDev("non nullfile"); - }*/ - if (!hasExtension(f, extension)) { - /*if (f == null) { - TraceManager.addDev(" nullfile"); - } else { - TraceManager.addDev("non nullfile"); - }*/ - - TraceManager.addDev("file=" + f.getAbsolutePath()); + TraceManager.addDev(" nullfile"); + } else { + TraceManager.addDev("non nullfile"); + }*/ + if (!hasExtension(f, extension)) { + /*if (f == null) { + TraceManager.addDev(" nullfile"); + } else { + TraceManager.addDev("non nullfile"); + }*/ + + TraceManager.addDev("file=" + f.getAbsolutePath()); f = new File(f.getAbsolutePath() + "." + extension); } - + return f; } public static String addBeforeFileExtension(String filename, String tobeadded) { - int index = filename.indexOf("."); - - if (index == -1) { - return filename+tobeadded; - } - - filename = filename.substring(0, index) + tobeadded + filename.substring(index, filename.length()); - return filename; + int index = filename.indexOf("."); + + if (index == -1) { + return filename+tobeadded; + } + + filename = filename.substring(0, index) + tobeadded + filename.substring(index, filename.length()); + return filename; } - + public static String changeFileExtension(String filename, String extension) { - int index = filename.indexOf("."); - - if (index == -1) { - return filename+"." + extension; - } - - filename = filename.substring(0, index) + "." + extension; - return filename; + int index = filename.indexOf("."); + + if (index == -1) { + return filename+"." + extension; + } + + filename = filename.substring(0, index) + "." + extension; + return filename; } - + public static String removeFileExtension(String filename) { - int index = filename.indexOf("."); - - if (index == -1) { - return filename; - } - - filename = filename.substring(0, index); - return filename; + int index = filename.indexOf("."); + + if (index == -1) { + return filename; + } + + filename = filename.substring(0, index); + return filename; } - + public static boolean hasExtension(File f, String extension) { if (f == null) { @@ -213,16 +213,16 @@ public class FileUtils { } return false; } - + public static String loadFile(String name) throws FileException { File f = new File(name); String s = null; - + if(checkFileForOpen(f)) { try { FileInputStream fis = new FileInputStream(f); int nb = fis.available(); - + byte [] ba = new byte[nb]; fis.read(ba); fis.close(); @@ -235,10 +235,15 @@ public class FileUtils { } return s; } - + public static void saveFile(String name, String data) throws FileException { - File f = new File(name); - + File f = new File(name); + saveFile(f, data); + } + + + public static void saveFile(File f, String data) throws FileException { + if(checkFileForSave(f)) { try { if (data == null) { @@ -249,39 +254,39 @@ public class FileUtils { fos.close(); return; } catch(Exception e) { - throw new FileException("opening pb"); + throw new FileException("Pb when saving file"); } } else { - throw new FileException("opening pb"); + throw new FileException("Pb when saving file"); } } - + // d: directory, e : extension public static String deleteFiles(String d, String e ) { ExtensionFilter filter = new ExtensionFilter(e); File dir = new File(d); - + String[] list = dir.list(filter); File file; boolean isDeleted; - + String files = ""; - - if (list == null) { - return files; - } - + + if (list == null) { + return files; + } + if (list.length == 0) return files; - + for (int i = 0; i < list.length; i++) { file = new File(d + list[i]); isDeleted = file.delete(); - if (isDeleted) + if (isDeleted) files += file.toString() + "\n"; } return files; } - + static class ExtensionFilter implements FilenameFilter { private String extension; public ExtensionFilter( String extension ) { @@ -292,4 +297,4 @@ public class FileUtils { } } -} // Class \ No newline at end of file +} // Class diff --git a/src/ui/JMenuBarTurtle.java b/src/ui/JMenuBarTurtle.java index d70faba4ffbc367207be95728ca08bf75cba964d..5ae693e4b6bf1fbdaf859a9301e04c72db81bdd1 100755 --- a/src/ui/JMenuBarTurtle.java +++ b/src/ui/JMenuBarTurtle.java @@ -565,6 +565,8 @@ public class JMenuBarTurtle extends JMenuBar { menuItem.addMouseListener(mgui.mouseHandler); menuItem = capture.add(mgui.actions[TGUIAction.ACT_ALL_DIAGRAM_CAPTURE]); menuItem.addMouseListener(mgui.mouseHandler); + menuItem = capture.add(mgui.actions[TGUIAction.ACT_ALL_DIAGRAM_CAPTURE_SVG]); + menuItem.addMouseListener(mgui.mouseHandler); menuItem = capture.add(mgui.actions[TGUIAction.ACT_SELECTED_CAPTURE]); menuItem.addMouseListener(mgui.mouseHandler); @@ -608,6 +610,8 @@ public class JMenuBarTurtle extends JMenuBar { menuItem.addMouseListener(mgui.mouseHandler); menuItem = help.add(mgui.actions[TGUIAction.ACT_DIPLODOCUS_DOCUMENTATION]); menuItem.addMouseListener(mgui.mouseHandler); + menuItem = help.add(mgui.actions[TGUIAction.ACT_SYSMLSEC_DOCUMENTATION]); + menuItem.addMouseListener(mgui.mouseHandler); help.addSeparator(); menuItem = help.add(mgui.actions[TGUIAction.ACT_TURTLE_WEBSITE]); menuItem.addMouseListener(mgui.mouseHandler); diff --git a/src/ui/MainGUI.java b/src/ui/MainGUI.java index 9f3a938b7145ab78333574f86c5c52cde1f874fe..f1e8faa3f727aa8c326c5bd4988eacbda785644f 100755 --- a/src/ui/MainGUI.java +++ b/src/ui/MainGUI.java @@ -590,6 +590,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe actions[TGUIAction.ACT_TTOOL_CONFIGURATION].setEnabled(true); actions[TGUIAction.ACT_TURTLE_WEBSITE].setEnabled(true); actions[TGUIAction.ACT_TURTLE_DOCUMENTATION].setEnabled(true); + actions[TGUIAction.ACT_SYSMLSEC_DOCUMENTATION].setEnabled(true); actions[TGUIAction.ACT_DIPLODOCUS_DOCUMENTATION].setEnabled(true); actions[TGUIAction.ACT_VIEW_SAVED_LOT].setEnabled(true); actions[TGUIAction.ACT_VIEW_SAVED_DOT].setEnabled(true); @@ -630,6 +631,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe actions[TGUIAction.ACT_DIAGRAM_CAPTURE].setEnabled(true); actions[TGUIAction.ACT_SVG_DIAGRAM_CAPTURE].setEnabled(true); actions[TGUIAction.ACT_ALL_DIAGRAM_CAPTURE].setEnabled(true); + actions[TGUIAction.ACT_ALL_DIAGRAM_CAPTURE_SVG].setEnabled(true); actions[TGUIAction.ACT_GEN_DOC].setEnabled(true); actions[TGUIAction.ACT_GEN_DOC_REQ].setEnabled(true); actions[TGUIAction.ACT_VIEW_JAVA].setEnabled(true); @@ -3096,6 +3098,10 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe BrowserControl.startBrowerToURL("http://ttool.telecom-paristech.fr/avatar.html"); } + public void helpSysMLSec() { + BrowserControl.startBrowerToURL("http://sysml-sec.telecom-paristech.fr/"); + } + public void helpDIPLODOCUS() { BrowserControl.startBrowerToURL("http://ttool.telecom-paristech.fr/diplodocus.html"); } @@ -4980,7 +4986,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe File file = selectFileForCapture(); if (file == null) - return; + return; TURTLEPanel tp = getCurrentTURTLEPanel(); TDiagramPanel tdp1; @@ -5001,17 +5007,79 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe } file1 = FileUtils.addFileExtensionIfMissing(file1, TImgFilter.getExtension()); if (!writeImageCapture(image, file1, false)) { + JOptionPane.showMessageDialog(frame, + "Diagrams could NOT be captured in png format", + "Capture failed", + JOptionPane.INFORMATION_MESSAGE); return; } if (i ==0) { if (!writeImageCapture(image, file, false)) { + JOptionPane.showMessageDialog(frame, + "Diagrams could NOT be captured in png format", + "Capture failed", + JOptionPane.INFORMATION_MESSAGE); return; } } } JOptionPane.showMessageDialog(frame, - "All diagrams were sucessfully captured", + "All diagrams were sucessfully captured in png format", + "Capture ok", + JOptionPane.INFORMATION_MESSAGE); + } + + public void allDiagramCaptureSvg() { + if (tabs.size() < 1) { + JOptionPane.showMessageDialog(frame, + "No diagram is under edition", + "Error", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + File file = selectSVGFileForCapture(); + if (file == null) + return; + + TURTLEPanel tp;// = getCurrentTURTLEPanel(); + TDiagramPanel tdp1; + BufferedImage image; + File file1; + String name = file.getAbsolutePath(); + name = name.substring(0, name.length() - 4); + + //boolean actions; + for(int j=0; j<tabs.size(); j++) { + tp = (TURTLEPanel)(tabs.get(j)); + for(int i=0; i<tp.panels.size(); i++) { + tdp1 = (TDiagramPanel)(tp.panels.elementAt(i)); + tdp1.repaint(); + + String svgImg = tdp1.svgCapture(); + + if (i < 10) { + file1 = new File(name + j + "_" + "0" + i); + } else { + file1 = new File(name + j + "_" + i); + } + file1 = FileUtils.addFileExtensionIfMissing(file1, TSVGFilter.getExtension()); + try { + FileUtils.saveFile(file1, svgImg); + } catch(Exception e) { + JOptionPane.showMessageDialog(frame, + "Diagrams could NOT be captured in svg format", + "Capture failed", + JOptionPane.INFORMATION_MESSAGE); + return; + } + + } + } + + JOptionPane.showMessageDialog(frame, + "All diagrams were sucessfully captured in svg format", "Capture ok", JOptionPane.INFORMATION_MESSAGE); } @@ -7847,6 +7915,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe aboutTURTLE(); } else if (command.equals(actions[TGUIAction.ACT_TURTLE_DOCUMENTATION].getActionCommand())) { helpTURTLE(); + } else if (command.equals(actions[TGUIAction.ACT_SYSMLSEC_DOCUMENTATION].getActionCommand())) { + helpSysMLSec(); } else if (command.equals(actions[TGUIAction.ACT_DIPLODOCUS_DOCUMENTATION].getActionCommand())) { helpDIPLODOCUS(); } else if (command.equals(actions[TGUIAction.ACT_MODEL_CHECKING].getActionCommand())) { @@ -7957,6 +8027,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe svgDiagramCapture(); } else if (command.equals(actions[TGUIAction.ACT_ALL_DIAGRAM_CAPTURE].getActionCommand())) { allDiagramCapture(); + } else if (command.equals(actions[TGUIAction.ACT_ALL_DIAGRAM_CAPTURE_SVG].getActionCommand())) { + allDiagramCaptureSvg(); } else if (command.equals(actions[TGUIAction.ACT_SELECTED_CAPTURE].getActionCommand())) { selectedCapture(); } else if (command.equals(actions[TGUIAction.ACT_GEN_DOC].getActionCommand())) { diff --git a/src/ui/TGUIAction.java b/src/ui/TGUIAction.java index 91fd14e080150ac72dcaeb510692d4e1392d3a13..ab4cbb0e5c39ca63c1b90dbb1edc3204abffdcd3 100755 --- a/src/ui/TGUIAction.java +++ b/src/ui/TGUIAction.java @@ -82,6 +82,7 @@ public class TGUIAction extends AbstractAction { public static final int ACT_TURTLE_WEBSITE = 117; public static final int ACT_TURTLE_DOCUMENTATION = 118; public static final int ACT_DIPLODOCUS_DOCUMENTATION = 242; + public static final int ACT_SYSMLSEC_DOCUMENTATION = 426; public static final int ACT_ABOUT = 4; public static final int ACT_ENHANCE = 160; public static final int ACT_TTOOL_CONFIGURATION = 323; @@ -521,6 +522,7 @@ public class TGUIAction extends AbstractAction { public static final int ACT_DIAGRAM_CAPTURE = 60; public static final int ACT_SVG_DIAGRAM_CAPTURE = 366; public static final int ACT_ALL_DIAGRAM_CAPTURE = 114; + public static final int ACT_ALL_DIAGRAM_CAPTURE_SVG = 427; public static final int ACT_SELECTED_CAPTURE = 61; public static final int ACT_GEN_DOC = 247; @@ -568,7 +570,7 @@ public class TGUIAction extends AbstractAction { public static final int ACT_INTERNAL_SEARCH = 415; //-- - public static final int NB_ACTION = 426; + public static final int NB_ACTION = 428; private static final TAction [] actions = new TAction[NB_ACTION]; @@ -731,10 +733,11 @@ public class TGUIAction extends AbstractAction { actions[ACT_SCREEN_CAPTURE] = new TAction("screen-capture", "Screen capture", IconManager.imgic338, IconManager.imgic339, "Screen capture", "Capture the screen", 0); - actions[ACT_TTOOL_WINDOW_CAPTURE] = new TAction("tool-window-capture", "00 window capture", IconManager.imgic338, IconManager.imgic339, "Main window capture", "Capture the main window", 0); - actions[ACT_DIAGRAM_CAPTURE] = new TAction("diagram-capture", "Diagram capture", IconManager.imgic338, IconManager.imgic339, "Diagram capture", "Capture the currenlty opened diagram", 0); - actions[ACT_SVG_DIAGRAM_CAPTURE] = new TAction("svg-diagram-capture", "Diagram capture (SVG)", IconManager.imgic338, IconManager.imgic339, "Diagram capture (SVG)", "Capture the currenlty opened diagram in svg format", 0); - actions[ACT_ALL_DIAGRAM_CAPTURE] = new TAction("all-diagram-capture", "All diagram capture", IconManager.imgic338, IconManager.imgic339, "All diagram capture", "Capture the currenlty opened set of diagram (analysis, design, etc.)", 0); + actions[ACT_TTOOL_WINDOW_CAPTURE] = new TAction("tool-window-capture", "TTool Window capture", IconManager.imgic338, IconManager.imgic339, "Main window capture", "Capture the main window", 0); + actions[ACT_DIAGRAM_CAPTURE] = new TAction("diagram-capture", "Current diagram capture (PNG)", IconManager.imgic338, IconManager.imgic339, "Diagram capture", "Capture the currenlty opened diagram", 0); + actions[ACT_SVG_DIAGRAM_CAPTURE] = new TAction("svg-diagram-capture", "Current diagram capture (SVG)", IconManager.imgic338, IconManager.imgic339, "Diagram capture (SVG)", "Capture the currenlty opened diagram in svg format", 0); + actions[ACT_ALL_DIAGRAM_CAPTURE] = new TAction("all-diagram-capture", "All diagrams capture (PNG)", IconManager.imgic338, IconManager.imgic339, "All diagram capture (PNG)", "Capture in png images the currenlty opened set of diagram (analysis, design, etc.)", 0); + actions[ACT_ALL_DIAGRAM_CAPTURE_SVG] = new TAction("all-diagram-capture-svg", "All diagrams capture (SVG)", IconManager.imgic338, IconManager.imgic339, "All diagram capture (SVG)", "Capture in svg images the currenlty opened set of diagram (analysis, design, etc.)", 0); actions[ACT_SELECTED_CAPTURE] = new TAction("selected-capture", "Capture of selected components", IconManager.imgic338, IconManager.imgic339, "Capture of selected components", "Capture the selected components of the currently opened diagram", 0); actions[ACT_GEN_DOC] = new TAction("gen-doc", "Documentation generation", IconManager.imgic28, IconManager.imgic28, "Documentation generation", "Documentation may be automatically generated, in html format, from edited diagrams", 0); actions[ACT_GEN_DOC_REQ] = new TAction("gen-doc-req", "SysML requirements documentation", IconManager.imgic28, IconManager.imgic28, "SysML requirements documentation", "SysML requirements documentation is displayed in an array, and may be further automatically generated in html format", 0); @@ -743,6 +746,7 @@ public class TGUIAction extends AbstractAction { actions[ACT_TURTLE_WEBSITE] = new TAction("turtle-website-command", "TTool's website", IconManager.imgic30, IconManager.imgic31, "TTool's website", "Various information (e.g., documentation) on TTool", 0); actions[ACT_TURTLE_DOCUMENTATION] = new TAction("turtle-docu-command", "AVATAR online help", IconManager.imgic30, IconManager.imgic31, "AVATAR online help", "AVATAR online help", 0); actions[ACT_DIPLODOCUS_DOCUMENTATION] = new TAction("diplo-docu-command", "DIPLODOCUS online help", IconManager.imgic30, IconManager.imgic31, "DIPLODOCUS online help", "DIPLODOCUS online help", 0); + actions[ACT_SYSMLSEC_DOCUMENTATION] = new TAction("diplo-docu-command", "SysML-Sec online help", IconManager.imgic30, IconManager.imgic31, "SysML-Sec online help", "SysML-Sec online help", 0); actions[ACT_TTOOL_CONFIGURATION] = new TAction("configuration-command", "Configuration", IconManager.imgic76, IconManager.imgic77, "Configuration", "Configuration loaded at startup", 0); actions[ACT_ENHANCE] = new TAction("enhance-command", "Enhance", IconManager.imgic28, IconManager.imgic29, "Enhance", "Automatically enhance diagram", 0);