Skip to content
Snippets Groups Projects
Commit 23b370f1 authored by Fabien Tessier's avatar Fabien Tessier
Browse files

Add config file for .ttool (no load)

parent e9528d5a
No related branches found
No related tags found
2 merge requests!30Merge project manager into master,!29Resolve "Implement Project Management in TTool"
package common;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import myutil.FileUtils;
import myutil.MalformedConfigurationException;
import myutil.TraceManager;
public class SpecConfigTTool {
public static String SystemCCodeDirectory="";
......@@ -25,6 +37,9 @@ public class SpecConfigTTool {
public static String AVATARExecutableSoclibCodeTraceCommand="";
public static String TMLCodeDirectory="";
public static int lastPanel = -1;
public static int lastTab = -1;
public static void loadConfiguration() {
SystemCCodeDirectory = ConfigurationTTool.SystemCCodeDirectory;
SystemCCodeCompileCommand = ConfigurationTTool.SystemCCodeCompileCommand;
......@@ -71,9 +86,119 @@ public class SpecConfigTTool {
public static void setBasicConfig(boolean systemcOn) {
try {
lastPanel = -1;
lastTab = -1;
ConfigurationTTool.loadConfiguration("./launch_configurations/config.xml", systemcOn);
} catch (MalformedConfigurationException e) {
System.out.println("Couldn't load configuration from file: config.xml");
}
}
public static File createProjectConfig(File dir) {
File base = new File("./launch_configurations/project_config.xml");
try {
FileUtils.copyFileToDirectory(base, dir, false);
return new File(dir + File.separator + "project_config.xml");
} catch (IOException e) {
System.err.println(e.getMessage());
}
return null;
}
public static void loadConfigFile(File f) throws MalformedConfigurationException {
if (!FileUtils.checkFileForOpen(f)) {
throw new MalformedConfigurationException("Filepb");
}
String data = FileUtils.loadFileData(f);
if (data == null) {
throw new MalformedConfigurationException("Filepb");
}
loadConfigurationFromXML(data);
SpecConfigTTool.loadConfiguration();
}
public static void loadConfigurationFromXML(String data) throws MalformedConfigurationException {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(data.getBytes());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
// building nodes from xml String
Document doc = db.parse(bais);
NodeList nl;
nl = doc.getElementsByTagName("LastOpenDiagram");
if (nl.getLength() > 0)
LastOpenDiagram(nl);
} catch (Exception e) {
throw new MalformedConfigurationException(e.getMessage());
}
}
private static void LastOpenDiagram(NodeList nl) throws MalformedConfigurationException {
try {
Element elt = (Element)(nl.item(0));
lastTab = Integer.parseInt(elt.getAttribute("tab"));
lastPanel = Integer.parseInt(elt.getAttribute("panel"));
} catch (Exception e) {
throw new MalformedConfigurationException(e.getMessage());
}
}
public static void saveConfiguration(File f) throws MalformedConfigurationException {
int index0, index1;
String tmp1, tmp2, location;
boolean write = false;
if (!FileUtils.checkFileForOpen(f)) {
throw new MalformedConfigurationException("Filepb");
}
String data = FileUtils.loadFileData(f);
if (data == null) {
throw new MalformedConfigurationException("Filepb");
}
index0 = data.indexOf("LastOpenDiagram");
if (index0 > -1) {
tmp1 = data.substring(0, index0+16);
tmp2 = data.substring(index0+20, data.length());
index1 = tmp2.indexOf("/>");
if (index1 > -1) {
tmp2 = tmp2.substring(index1, tmp2.length());
location = " tab=\"" + lastTab;
location += "\" panel=\"" + lastPanel + "\" ";
data = tmp1 + location + tmp2;
write = true;
}
} else {
index1= data.indexOf("</PROJECTCONFIGURATION>");
if (index1 > -1) {
location = "<LastOpenDiagram tab=\"" + lastTab;
location += "\" panel=\"" + lastPanel + "\"/>\n\n";
data = data.substring(0, index1) + location + data.substring(index1, data.length());
write = true;
}
}
if (write) {
//sb.append("Writing data=" + data);
try {
FileOutputStream fos = new FileOutputStream(f);
fos.write(data.getBytes());
fos.close();
} catch (Exception e) {
throw new MalformedConfigurationException("Saving file failed");
}
} else {
TraceManager.addError("Configuration could not be saved");
}
}
}
......@@ -286,6 +286,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
private File file;
private File dir;
private File config;
private File lotosfile;
private File simfile;
private File dtafile;
......@@ -355,7 +356,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
//PluginManager.pluginManager = new PluginManager();
}
public void setKey(String _sk) {
sk = _sk;
RshClient.sk = sk;
......@@ -364,7 +365,10 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
public String getKey() {
return sk;
}
public File getDir() {
return dir;
}
public boolean isAvatarOn() {
return avatarOn;
......@@ -1868,6 +1872,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
//gtm.saveOperation(tcdp);
file = null;
dir = null;
config = null;
frame.setTitle("TTool: unsaved project");
} else {
// check if previous modeling is saved
......@@ -1935,7 +1940,23 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
}
}
}
public void saveConfig() {
int i = 0;
for (; i < tabs.size(); i++) {
if (tabs.get(i) == activetdp.tp)
break;
}
int j = tabs.get(i).getIndexOfChild(activetdp);
SpecConfigTTool.lastTab = i;
SpecConfigTTool.lastPanel = j;
try {
SpecConfigTTool.saveConfiguration(config);
} catch (MalformedConfigurationException e) {
System.err.println(e.getMessage() + " : Can't save config file.");
}
}
public String loadFile(File f) {
String s = null;
......@@ -2339,9 +2360,16 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
SpecConfigTTool.setDirConfig(dir);
String filename = dir.getAbsolutePath() + "/" + dir.getName().replaceAll(".ttool", ".xml");
file = new File(filename);
config = new File(dir.getAbsolutePath() + "/project_config.xml");
try {
SpecConfigTTool.loadConfigFile(config);
} catch (MalformedConfigurationException e) {
System.err.println(e.getMessage() + " : Can't load config file.");
}
}
else {
dir = null;
config = null;
SpecConfigTTool.setBasicConfig(systemcOn);
file = _f;
}
......@@ -2434,9 +2462,16 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
}
dir = new File(ConfigurationTTool.LastOpenFile.substring(0, last));
SpecConfigTTool.setDirConfig(dir);
config = new File(dir.getAbsolutePath() + "/project_config.xml");
try {
SpecConfigTTool.loadConfigFile(config);
} catch (MalformedConfigurationException e) {
System.err.println(e.getMessage() + " : Can't load config file.");
}
}
else {
dir = null;
config = null;
SpecConfigTTool.setBasicConfig(systemcOn);
}
// close current modeling
......@@ -2499,7 +2534,6 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
JOptionPane.showMessageDialog(frame, "Modeling could not be correctly " + actionMessage, "Error when loading modeling", JOptionPane.INFORMATION_MESSAGE);
frame.setTitle("TToolt: unnamed project");
}
gtm.enableUndo(true);
gtm.saveOperation(getCurrentSelectedPoint());
dtree.forceUpdate();
......@@ -2653,6 +2687,12 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
dir = FileUtils.addFileExtensionIfMissing(dir, "ttool");
dir.mkdir();
SpecConfigTTool.setDirConfig(dir);
config = SpecConfigTTool.createProjectConfig(dir);
try {
SpecConfigTTool.loadConfigFile(config);
} catch (MalformedConfigurationException e) {
System.err.println(e.getMessage() + " : Can't load config file.");
}
String newname = FileUtils.removeFileExtension(dir.getName());
file = new File(dir, newname);
file = FileUtils.addFileExtensionIfMissing(file, TFileFilter.getExtension());
......@@ -2917,6 +2957,8 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
try {
if (ConfigurationTTool.LastOpenFileDefined) {
if (dir != null)
saveConfig();
ConfigurationTTool.saveConfiguration();
//TraceManager.addDev("Configuration written to file");
}
......@@ -7016,8 +7058,7 @@ public class MainGUI implements ActionListener, WindowListener, KeyListener, Pe
public void paneDiplodocusMethodologyAction(ChangeEvent e) {
//TraceManager.addDev("Pane design action size=" + tabs.size());
try {
TDiagramPanel tdp1 = getCurrentTURTLEPanel().panels.elementAt(getCurrentJTabbedPane().getSelectedIndex());
TDiagramPanel tdp1 = getCurrentTURTLEPanel().panels.elementAt(getCurrentJTabbedPane().getSelectedIndex());
//TraceManager.addDev("Pane design action 1");
if (activetdp != null) {
......
......@@ -686,6 +686,10 @@ public class TDiagramMouseManager extends MouseAdapter {//implements MouseListen
public void clearSelectComponents(){
this.selectedMultiComponents.clear();
}
public TDiagramPanel getTdp() {
return tdp;
}
//
// public void removeSelectedComponentFromList(){
// this.selectedMultiComponents.clear();
......
......@@ -810,6 +810,8 @@ public class JDialogSearchBox extends javax.swing.JFrame {
dbaddress=jTextaddressDB.getText().split(":")[0];
dbport=Integer.parseInt(jTextaddressDB.getText().split(":")[1]);
try {
if (tdmm.getTdp().getMainGUI().getDir() != null)
tdmm.getTdp().getMainGUI().saveConfig();
ConfigurationTTool.saveConfiguration();
} catch (MalformedConfigurationException e) {
e.printStackTrace();
......
<?xml version="1.0" encoding="ISO-8859-1" ?>
<PROJECTCONFIGURATION>
<LastOpenDiagram tab="0" panel="0"/>
</PROJECTCONFIGURATION>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment