[Bojangles-cvs] cvs: bojangles / MainWindow.java Makefile xmlFileFilter.java
Status: Alpha
Brought to you by:
nehresma
From: kai5263499 <boj...@li...> - 2002-10-08 18:29:52
|
kai5263499 Tue Oct 8 11:29:50 2002 EDT Added files: /bojangles xmlFileFilter.java Modified files: /bojangles Makefile MainWindow.java Log: Figured out how to open an existing document and read it in as if the user were redoing it all over again (using some "borrowed code from treePopupMenuAddActionPerformed()) Also added a file filter so we can only save/open .xml files (i'll add .gz capabilities later as i dont think its a priority right now) If you try to open an XML file, it only adds the root node now (a correlations NPE problem) Index: bojangles/Makefile diff -u bojangles/Makefile:1.1 bojangles/Makefile:1.2 --- bojangles/Makefile:1.1 Fri Sep 6 07:49:05 2002 +++ bojangles/Makefile Tue Oct 8 11:29:49 2002 @@ -14,6 +14,7 @@ RemoveButtonEditor.class \ RemoveButtonRenderer.class \ testAppPrefsDlg.class \ +xmlFileFilter.class \ MainWindow.class %.class: %.java Index: bojangles/MainWindow.java diff -u bojangles/MainWindow.java:1.37 bojangles/MainWindow.java:1.38 --- bojangles/MainWindow.java:1.37 Fri Oct 4 14:05:06 2002 +++ bojangles/MainWindow.java Tue Oct 8 11:29:49 2002 @@ -874,6 +874,8 @@ if(wantDlg) { JFileChooser fc = new JFileChooser(); + fc.addChoosableFileFilter(new xmlFileFilter()); + fc.setApproveButtonText("Save"); // Try to read in prefrences from the prefs.xml doc... if(sdir != null) fc.setCurrentDirectory(sdir); @@ -911,8 +913,10 @@ private void loadXML() { try{ JFileChooser fc = new JFileChooser(); + fc.addChoosableFileFilter(new xmlFileFilter()); + fc.setApproveButtonText("Open"); if(sdir != null) fc.setCurrentDirectory(sdir); - int returnVal = fc.showSaveDialog(this); + int returnVal = fc.showOpenDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); sdir = file.getAbsoluteFile(); @@ -924,21 +928,73 @@ } // Make a psudo document to create our main document from Document tempdoc = new SAXReader().read(file.getAbsolutePath()); - List list = tempdoc.selectNodes("/"); + java.util.List list = tempdoc.selectNodes("//outer_type/parent::*"); ListIterator li = list.listIterator(); + boolean firstElement; while (li.hasNext()) { - Node thinge = (Node)li.next(); - if(thingie.SelectSingleNode("/widget/class") == "container") { - //DIG! - } + Node thingie = (Node)li.next(); + String outerType = thingie.selectSingleNode("outer_type").getText(); + Document doc = (Document)widgetDefinitions.get(outerType); + Container parent = null; + Element parentEle = thingie.getParent(); + if(parentEle == null) { + // if we are the first thing in the tree, then set the parent equal to the displayPanel + parent = displayPanel; + firstElement = true; + } else { - //add it... + Hashtable h = correlations.getCorrelation(popupOnTreeNode); + //parent = (Container)h.get("widget"); + parent = displayPanel; + firstElement = true; + } + + // retrieve the name of the widget for this outerType + String name = doc.selectSingleNode("/widget/name").getText(); + + String path = null; + DefaultMutableTreeNode treeNode = null; + // are we starting at the begining of the new document? + if (firstElement) { + String rootText = name; + rootNode = new DefaultMutableTreeNode(rootText); + treeModel = new DefaultTreeModel(rootNode); + widgetTree.setModel(treeModel); + treeNode = rootNode; + path = xmlHandler.addElement(null, rootText, null); + } else { + if (!(parent instanceof Widget)) { + JOptionPane.showMessageDialog(null, "Attempt to add child widget to a parent that is not a widget!\nFile corrupted!", "Error", JOptionPane.ERROR_MESSAGE); + return; + } + name = name+System.currentTimeMillis(); + + Hashtable h = correlations.getCorrelation((Widget)parent); + DefaultMutableTreeNode parentTreeNode = (DefaultMutableTreeNode)h.get("node"); + String parentPath = (String)h.get("path"); + treeNode = new DefaultMutableTreeNode(name); + treeModel.insertNodeInto(treeNode, parentTreeNode, parentTreeNode.getChildCount()); + //widgetTree.expandPath(; + path = xmlHandler.addElement(parentPath, name, null); } + + // add the widget's defined properties to the application's XML document + addWidgetProperties(doc, path, name, outerType); + + Widget w = new Widget(path, xmlHandler, this); + w.addElementFocusListener(this); + parent.add(w); + + // set the initial starting point and height/width + setInitialWidgetProperties(w, doc, outerType); + + // map the element, path, and the treenode into the correlations table + correlations.addCorrelation(path, treeNode, w); } } else { System.out.println("Load canceled"); return; - } + } } catch (Exception e) { e.printStackTrace(); Index: bojangles/xmlFileFilter.java +++ bojangles/xmlFileFilter.java package bojangles; import java.io.*; public class xmlFileFilter extends javax.swing.filechooser.FileFilter { public boolean accept(File file) { String filename = file.getName(); return filename.endsWith(".xml"); } public String getDescription() { return "*.xml"; } } |