Commit 612e7ebd authored by Letitia Li's avatar Letitia Li

Merge branch 'master' of gitlab.enst.fr:mbe-tools/TTool

parents 4110bd8e 0cbc9c49
......@@ -2275,12 +2275,17 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
if (returnVal == JFileChooser.APPROVE_OPTION) {
file = jfc.getSelectedFile();
openProjectFromFile(file);
}
}
public void openProjectFromFile(File _f) {
String s = null;
if(checkFileForOpen(file)) {
if(checkFileForOpen(_f)) {
try {
FileInputStream fis = new FileInputStream(file);
FileInputStream fis = new FileInputStream(_f);
int nb = fis.available();
byte [] ba = new byte[nb];
......@@ -2303,7 +2308,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
gtm.enableUndo(false);
// Update configuration
updateLastOpenFile(file);
updateLastOpenFile(_f);
//TraceManager.addDev("Loading");
// load the new TURTLE modeling
......
......@@ -60,6 +60,10 @@ import myutil.*;
public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements ActionListener, Runnable, LoaderFacilityInterface, CallbackLoaderInterface {
public final static String [] FEATURES = {"All", "Requirements", "Attacktrees", "Properties", "Partitioning", "Analysis", "Design", "Prototyping", "Security protocol"};
public final static String [] PROPS = {"All", "Safety", "Security", "Performance"};
private ArrayList<NetworkModel> listOfModels;
protected Frame f;
......@@ -76,6 +80,7 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac
private JTextAreaWriter textAreaWriter;
protected JButton start;
protected JButton stop;
protected JList<String> featureList;
protected JScrollPane jsp;
......@@ -86,6 +91,7 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac
private String url;
private NetworkModelPanel panel;
private String filePath;
/** Creates new form */
......@@ -124,10 +130,7 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac
c.setLayout(new BorderLayout());
//setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
panel = new NetworkModelPanel(this, listOfModels, this);
jsp = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
c.add(jsp, BorderLayout.CENTER);
JPanel lowPart = new JPanel(new BorderLayout());
......@@ -141,6 +144,13 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac
textAreaWriter = new JTextAreaWriter( jta );
jsp = new JScrollPane(jta, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jsp.setPreferredSize(new Dimension(400, 200));
JPanel options = new JPanel();
featureList = new JList<String>(FEATURES);
options.add(featureList);
lowPart.add(options, BorderLayout.NORTH);
lowPart.add(jsp, BorderLayout.CENTER);
......@@ -160,6 +170,12 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac
lowPart.add(jp2, BorderLayout.SOUTH);
c.add(lowPart, BorderLayout.SOUTH);
panel = new NetworkModelPanel(this, listOfModels, this, jta);
jsp = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
panel.setJSP(jsp);
c.add(jsp, BorderLayout.CENTER);
}
public void actionPerformed(ActionEvent evt) {
......@@ -210,12 +226,28 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac
nm = new NetworkModel(inputLine.substring(5, inputLine.length()).trim());
listOfModels.add(nm);
}
if (inputLine.startsWith("-TYPE")) {
if (inputLine.startsWith("-FEATURES")) {
if (nm != null) {
nm.type = NetworkModel.stringToNetworkModelType(inputLine.substring(5, inputLine.length()).trim());
String tmp = inputLine.substring(9, inputLine.length()).trim();
for (int i=1; i<FEATURES.length; i++) {
nm.features[i] = tmp.indexOf(FEATURES[i]) != -1;
}
//nm.type = NetworkModel.stringToNetworkModelType(inputLine.substring(5, inputLine.length()).trim());
}
}
if (inputLine.startsWith("-PROPS")) {
if (nm != null) {
String tmp = inputLine.substring(6, inputLine.length()).trim();
for (int i=1; i<PROPS.length; i++) {
nm.props[i] = tmp.indexOf(PROPS[i]) != -1;
}
//nm.type = NetworkModel.stringToNetworkModelType(inputLine.substring(5, inputLine.length()).trim());
}
}
if (inputLine.startsWith("-DESCRIPTION")) {
if (nm != null) {
nm.description = inputLine.substring(12, inputLine.length()).trim();
......@@ -276,11 +308,22 @@ public class JDialogLoadingNetworkModel extends javax.swing.JFrame implements Ac
}
public void load(int index) {
jta.append("Loading model: " + listOfModels.get(index).fileName);
String fileName = listOfModels.get(index).fileName;
jta.append("Loading model: " + fileName);
String urlToLoad = URLManager.getBaseURL(url) + fileName;
URLManager urlm = new URLManager();
filePath = ConfigurationTTool.FILEPath + "/" + fileName;
boolean ok = urlm.downloadFile(ConfigurationTTool.FILEPath + "/" + fileName, urlToLoad,this);
if (!ok) {
jta.append("Model transfer failed\nPlease, select another model, or retry\n");
panel.reactivateSelection();
}
}
public void loadDone() {
jta.append("Model transfered, opening it in TTool\n");
this.dispose();
mgui.openProjectFromFile(new File(filePath));
}
public void loadFailed() {
......
......@@ -55,7 +55,8 @@ import java.awt.image.*;
public class NetworkModel {
public String fileName;
public NetworkModelType type;
public boolean [] features;
public boolean [] props;
public String description;
public String image;
public BufferedImage bi;
......@@ -66,6 +67,11 @@ public class NetworkModel {
public NetworkModel(String _fileName) {
//super(_fileName);
fileName = _fileName;
features = new boolean[JDialogLoadingNetworkModel.FEATURES.length];
features[0] = true;
props = new boolean[JDialogLoadingNetworkModel.PROPS.length];
props[0] = true;
}
public void update() {
......
......@@ -79,11 +79,15 @@ public class NetworkModelPanel extends JPanel implements MouseListener, MouseMot
private ActionListener listener;
private LoaderFacilityInterface loader;
private JTextArea jta;
private JScrollPane jsp;
public NetworkModelPanel(LoaderFacilityInterface _loader, ArrayList<NetworkModel> _listOfModels, ActionListener _listener) {
public NetworkModelPanel(LoaderFacilityInterface _loader, ArrayList<NetworkModel> _listOfModels, ActionListener _listener, JTextArea _jta) {
loader = _loader;
listOfModels = _listOfModels;
listener = _listener;
jta = _jta;
//Dimension pSize = new Dimension(500, 400);
Dimension mSize = new Dimension(400, 300);
......@@ -97,6 +101,11 @@ public class NetworkModelPanel extends JPanel implements MouseListener, MouseMot
addMouseListener(this);
}
public void setJSP(JScrollPane _jsp) {
jsp = _jsp;
jsp.setViewportView(this);
}
public void preparePanel() {
//int cptColumn = 0;
//int cptRow = 0;
......@@ -188,6 +197,20 @@ public class NetworkModelPanel extends JPanel implements MouseListener, MouseMot
index ++;
}
Dimension currentPSize = getPreferredSize();
Dimension pSize = new Dimension(400, Math.max(300, (cptRow+1)*(buttonSizeY +spaceBetweenButtons) + 2* marginY));
setPreferredSize(pSize);
if (!((currentPSize.getWidth() == pSize.getWidth()) && (currentPSize.getHeight() == pSize.getHeight()))) {
if (jsp != null) {
TraceManager.addDev("repainting jsp");
jsp.setViewportView(this);
//jsp.revalidate();
//jsp.repaint();
}
}
//g.drawString(listOfModels.size() + " model(s) available", 20, 20);
//g.drawRect(200, 200, 200, 200);
}
......@@ -214,6 +237,10 @@ public class NetworkModelPanel extends JPanel implements MouseListener, MouseMot
indexOfSelected = -1;
}
if (indexOfSelected != previousIndex) {
if (indexOfSelected != -1) {
NetworkModel nm = listOfModels.get(indexOfSelected);
jta.append("\n--- " + nm.fileName + "---\n" + nm.description + "\n-------------\n\n");
}
repaint();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment