[Bojangles-cvs] cvs: bojangles / MainWindow.java
Status: Alpha
Brought to you by:
nehresma
From: kai5263499 <boj...@li...> - 2002-08-20 16:38:35
|
kai5263499 Tue Aug 20 09:38:33 2002 EDT Modified files: /bojangles MainWindow.java Log: Lunch update... Added window naming stuff. Index: bojangles/MainWindow.java diff -u bojangles/MainWindow.java:1.12 bojangles/MainWindow.java:1.13 --- bojangles/MainWindow.java:1.12 Tue Aug 20 05:32:41 2002 +++ bojangles/MainWindow.java Tue Aug 20 09:38:30 2002 @@ -39,7 +39,7 @@ private JComboBox propertiesComboBox; private JMenu treeAddMenu, fileMenu, helpMenu, containerMenu, componentMenu; private JMenuBar jMenuBar1; - private JMenuItem exitMenuItem, treeDelMenuItem, genhelpMenuItem; + private JMenuItem exitMenuItem, saveMenuItem, treeDelMenuItem, genhelpMenuItem; private JPopupMenu treePopup; private JScrollPane jScrollPane1; private JSplitPane jSplitPane1, jSplitPane2; @@ -60,6 +60,7 @@ private boolean prefsSet = false; private File sdir = null; private boolean appModified = false; + private String curTitle= "New Window"; /** Creates new form MainWindow */ public MainWindow() { @@ -126,6 +127,7 @@ fileMenu = new javax.swing.JMenu(); helpMenu = new javax.swing.JMenu(); exitMenuItem = new javax.swing.JMenuItem(); + saveMenuItem = new javax.swing.JMenuItem(); genhelpMenuItem = new javax.swing.JMenuItem(); treePopup.addPopupMenuListener(new javax.swing.event.PopupMenuListener() { @@ -258,7 +260,13 @@ exitMenuItemActionPerformed(evt); } }); - + saveMenuItem.setText("Save"); + saveMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + saveMenuItemActionPerformed(evt); + } + }); + helpMenu.setText("Help"); genhelpMenuItem.setText("General Help"); genhelpMenuItem.addActionListener(new java.awt.event.ActionListener() { @@ -268,6 +276,7 @@ }); fileMenu.add(exitMenuItem); + fileMenu.add(saveMenuItem); helpMenu.add(genhelpMenuItem); jMenuBar1.add(fileMenu); jMenuBar1.add(helpMenu); @@ -334,7 +343,7 @@ saveXML(); } // Redundant? Redundant? - if(this.appModified == false) { + if(!this.appModified) { if(this.prefsSet) { return; } @@ -346,9 +355,15 @@ } private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) { + if(this.appModified) { + } System.exit(0); } + private void saveMenuItemActionPerformed(java.awt.event.ActionEvent evt) { + saveXML(); + } + private void genhelpMenuItemActionPerformed(java.awt.event.ActionEvent evt) { // TODO here... } @@ -357,7 +372,7 @@ // Kill de widget! System.out.println(evt.toString()); System.out.println("There is no spoon..."); - this.appModified = true; + appModified(true); } public void elementFocusChanged(String path) { @@ -386,7 +401,7 @@ public void tableChanged(TableModelEvent e) { if (null == currentElement) return; if (null == e) return; - this.appModified = true; + appModified(true); int row = e.getFirstRow(); String propertyName = (String)propertiesTableModel.getValueAt(row, 1); @@ -494,8 +509,8 @@ String parentPath = (String)h.get("path"); treeNode = new DefaultMutableTreeNode(name); treeModel.insertNodeInto(treeNode, parentTreeNode, parentTreeNode.getChildCount()); - path = xmlHandler.addElement(parentPath, name, null); + appModified(true); } // add the widget's defined properties to the application's XML document @@ -599,7 +614,7 @@ String name = files[i].getName(); if (name.endsWith(".xml")) { try { - System.out.println("loading widget definition from " + name); + System.out.println("Loading widget definition from " + name); Document document = new SAXReader().read("widget_definitions/" + name); String outerType = document.selectSingleNode("/widget/outer_type").getText(); widgetDefinitions.put(outerType, document); @@ -626,9 +641,15 @@ } } + private void appModified(boolean moded) { + appModified = moded; + if(moded) this.setTitle(curTitle + "*"); + else this.setTitle(curTitle); + } + private void saveXML() { JFileChooser fc = new JFileChooser(); - if(this.sdir != null) fc.setCurrentDirectory(this.sdir); + if(sdir != null) fc.setCurrentDirectory(sdir); // Try to read in prefrences from the prefs.xml doc... /* else { @@ -640,13 +661,14 @@ int returnVal = fc.showSaveDialog(this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); - this.sdir = file.getAbsoluteFile(); + sdir = file.getAbsoluteFile(); if (file.exists()) { - String suremsg = "Are you sure you want to overwrite " + file + " ?"; - int choice = JOptionPane.showConfirmDialog(this,"File will be overwritten.",suremsg,JOptionPane.YES_NO_OPTION); + 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); if(choice == JOptionPane.NO_OPTION) return; - this.appModified = false; - System.out.println("Saved " + file); + System.out.println("Saved " + file.getName()); + curTitle = file.getName(); + appModified(false); } xmlHandler.saveXML(file); } else { @@ -657,6 +679,7 @@ public static void main(String[] args) { MainWindow win = new MainWindow(); + win.setTitle("New App"); win.show(); } } |