[Bojangles-cvs] cvs: bojangles / MainWindow.java
Status: Alpha
Brought to you by:
nehresma
|
From: kai5263499 <boj...@li...> - 2002-08-20 22:32:26
|
kai5263499 Tue Aug 20 15:32:24 2002 EDT
Modified files:
/bojangles MainWindow.java
Log:
Prefrences addition...
Index: bojangles/MainWindow.java
diff -u bojangles/MainWindow.java:1.13 bojangles/MainWindow.java:1.14
--- bojangles/MainWindow.java:1.13 Tue Aug 20 09:38:30 2002
+++ bojangles/MainWindow.java Tue Aug 20 15:32:24 2002
@@ -61,9 +61,12 @@
private File sdir = null;
private boolean appModified = false;
private String curTitle= "New Window";
+ private String lastfile, prefHost, prefPort, prefPath, prefBrowser;
+ private Document prefDocument = null;
/** Creates new form MainWindow */
public MainWindow() {
+ loadPrefrences();
loadWidgetDefinitions();
initComponents();
initPopupMenus();
@@ -275,8 +278,8 @@
}
});
- fileMenu.add(exitMenuItem);
fileMenu.add(saveMenuItem);
+ fileMenu.add(exitMenuItem);
helpMenu.add(genhelpMenuItem);
jMenuBar1.add(fileMenu);
jMenuBar1.add(helpMenu);
@@ -476,7 +479,7 @@
}
Container parent = null;
- // if we are the first thing in the tree, then set the parent equal to the displayPanel
+ // if we are the first thing in the tree, t hen set the parent equal to the displayPanel
if (null == popupOnTreeNode)
parent = displayPanel;
else {
@@ -603,7 +606,6 @@
}
private void loadWidgetDefinitions() {
-
File[] files = new File("widget_definitions").listFiles();
if (null == files) {
System.out.println("Unable to find the widget definitions.");
@@ -612,7 +614,8 @@
for (int i=0;i<files.length;i++) {
String name = files[i].getName();
- if (name.endsWith(".xml")) {
+ // Loop through the widget definition XML files. But exclude the example widget file.
+ if (name.endsWith(".xml") && !name.equalsIgnoreCase("EXAMPLE.xml")) {
try {
System.out.println("Loading widget definition from " + name);
Document document = new SAXReader().read("widget_definitions/" + name);
@@ -627,17 +630,29 @@
}
private void loadPrefrences() {
- File files = new File("prefs.xml");
- if (null == files) {
- System.out.println("No saved prefrences...");
- }
try {
+ File prefFile = new File("prefs.xml");
+ if (null == prefFile) {
+ System.out.println("No saved prefrences...");
+ // Lets make a document anyway to write collected prefrences to...
+ // Document prefDocument = new SAXDocument();
+ prefDocument = DocumentHelper.createDocument();
+ }
+ else {
System.out.println("Loading prefrences from prefs.xml");
- Document document = new SAXReader().read("prefs.xml");
- }
- catch (DocumentException e) {
+ prefDocument = new SAXReader().read("prefs.xml");
+ sdir = new File(prefDocument.selectSingleNode("/prefrences/prefSaveDir").getText());
+ lastfile = prefDocument.selectSingleNode("/prefrences/lastFileSaved").getText();
+ prefBrowser = prefDocument.selectSingleNode("/prefrences/browser").getText();
+ prefHost = prefDocument.selectSingleNode("/prefrences/testHost").getText();
+ prefPort = prefDocument.selectSingleNode("/prefrences/testPort").getText();
+ prefPath = prefDocument.selectSingleNode("/prefrences/testPath").getText();
+ System.out.println("URL: http://" + prefHost + ":" + prefPort + "/" + prefPath + "/" + lastfile);
+ System.out.println("Load ok!");
+ }
+ }
+ catch (Exception e) {
e.printStackTrace();
- System.exit(1);
}
}
@@ -649,19 +664,14 @@
private void saveXML() {
JFileChooser fc = new JFileChooser();
- if(sdir != null) fc.setCurrentDirectory(sdir);
// Try to read in prefrences from the prefs.xml doc...
- /*
- else {
- if(System.getProperty("os.name").equalsIgnoreCase("Linux")) {
- fc.setCurrentDirectory();
- }
- }*/
+ if(sdir != null) fc.setCurrentDirectory(sdir);
int returnVal = fc.showSaveDialog(this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
sdir = file.getAbsoluteFile();
+ //prefDocument
if (file.exists()) {
String suremsg = "Are you sure you want to overwrite?";
int choice = JOptionPane.showConfirmDialog(this,"File \"" + file.getName() + "\" will be overwritten.",suremsg,JOptionPane.YES_NO_OPTION);
|