You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by ca...@apache.org on 2007/11/13 11:35:04 UTC

svn commit: r594472 - in /xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser: DOMViewer.java JSVGViewerFrame.java NodePickerPanel.java

Author: cam
Date: Tue Nov 13 02:35:03 2007
New Revision: 594472

URL: http://svn.apache.org/viewvc?rev=594472&view=rev
Log:
Remove some Java 1.4-isms.

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/DOMViewer.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/NodePickerPanel.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/DOMViewer.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/DOMViewer.java?rev=594472&r1=594471&r2=594472&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/DOMViewer.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/DOMViewer.java Tue Nov 13 02:35:03 2007
@@ -350,8 +350,10 @@
      */
     protected class CloseButtonAction extends AbstractAction {
         public void actionPerformed(ActionEvent e) {
-            panel.tree.setSelectionRow(0);
-            dispose();
+            if (panel.attributePanel.panelHiding()) {
+                panel.tree.setSelectionRow(0);
+                DOMViewer.this.dispose();
+            }
         }
     }
 
@@ -1700,25 +1702,25 @@
             }
 
             // Sort the value list and then iterate through node templates
-            Collection values = templates.getNodeTemplatesMap().values();
-            List valuesAsList = Collections.list(Collections.enumeration(values));
-            Collections.sort(valuesAsList, new Comparator() {
+            ArrayList values =
+                new ArrayList(templates.getNodeTemplatesMap().values());
+            Collections.sort(values, new Comparator() {
                 public int compare(Object o1, Object o2) {
                     NodeTemplateDescriptor n1 = (NodeTemplateDescriptor) o1;
                     NodeTemplateDescriptor n2 = (NodeTemplateDescriptor) o2;
                     return n1.getName().compareTo(n2.getName());
                 }
             });
-            Iterator iter = valuesAsList.iterator();
+            Iterator iter = values.iterator();
             while (iter.hasNext()) {
-                NodeTemplateDescriptor desc = (NodeTemplateDescriptor) iter
-                        .next();
+                NodeTemplateDescriptor desc =
+                    (NodeTemplateDescriptor) iter .next();
                 String toParse = desc.getXmlValue();
                 short nodeType = desc.getType();
                 String nodeCategory = desc.getCategory();
                 JMenuItem currentItem = new JMenuItem(desc.getName());
-                currentItem.addActionListener(new NodeTemplateParser(toParse,
-                        nodeType));
+                currentItem.addActionListener
+                    (new NodeTemplateParser(toParse, nodeType));
                 JMenu currentSubmenu = (JMenu)menuMap.get(nodeCategory);
                 currentSubmenu.add(currentItem);
             }

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java?rev=594472&r1=594471&r2=594472&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java Tue Nov 13 02:35:03 2007
@@ -2277,7 +2277,7 @@
         }
 
         public void openDOMViewer() {
-            if (domViewer == null) {
+            if (domViewer == null || domViewer.isDisplayable()) {
                 domViewer = new DOMViewer
                     (svgCanvas.new JSVGViewerDOMViewerController());
                 Rectangle fr = getBounds();

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/NodePickerPanel.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/NodePickerPanel.java?rev=594472&r1=594471&r2=594472&view=diff
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/NodePickerPanel.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/NodePickerPanel.java Tue Nov 13 02:35:03 2007
@@ -697,6 +697,12 @@
      *            the element to set
      */
     public void setPreviewElement(Element elem) {
+        if (previewElement != elem && isDirty) {
+            if (!promptForChanges()) {
+                return;
+            }
+        }
+
         this.previewElement = elem;
         enterViewMode();
 
@@ -705,6 +711,14 @@
     }
 
     /**
+     * Invoked by the {@link DOMViewer} to inform the
+     * <code>NodePickerPanel</code> that it is being hidden.
+     */
+    boolean panelHiding() {
+        return !isDirty || promptForChanges();
+    }
+
+    /**
      * Gets the current working mode.
      *
      * @return the mode
@@ -886,21 +900,24 @@
     /**
      * Shows a dialog to save changes.
      */
-    public void promptForChanges() {
-        isDirty = false;
+    public boolean promptForChanges() {
         // If the xml is well formed
         if (getApplyButton().isEnabled() && isElementModified()) {
             String confirmString = resources.getString("ConfirmDialog.message");
             int option = JOptionPane.showConfirmDialog(getSvgInputPanel(),
-                    confirmString);
+                                                       confirmString);
             if (option == JOptionPane.YES_OPTION) {
                 getApplyButton().doClick();
+            } else if (option == JOptionPane.CANCEL_OPTION) {
+                return false;
             } else {
                 getResetButton().doClick();
             }
         } else {
             getResetButton().doClick();
         }
+        isDirty = false;
+        return true;
     }
 
     /**
@@ -932,14 +949,15 @@
             isDirty = isElementModified();
         }
 
-        public void focusLost(FocusEvent e) {
+        // XXX Java 1.3 does not have getOppositeComponent()
+        /*public void focusLost(FocusEvent e) {
             // Prompts the user to save changes that he made for an element,
-            // when the NodePicker looses focus
+            // when the NodePicker loses focus
             if (!isANodePickerComponent(e.getOppositeComponent())
                     && !e.isTemporary() && isDirty) {
                 promptForChanges();
             }
-        }
+        }*/
     }
 
     /**