svn commit: r17511 - trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java

Bob Tarling <[email protected]>
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: bobtarling
Date: 2009-11-21 03:54:39-0800
New Revision: 17511

Modified:
   trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java

Log:
Use a label with +/- instead of a button

Modified: trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java?view=diff&pathrev=17511&r1=17510&r2=17511
==============================================================================
--- trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java	(original)
+++ trunk/src/argouml-core-umlpropertypanels/src/org/argouml/core/propertypanels/ui/UMLExpandableRowSelector.java	2009-11-21 03:54:39-0800
@@ -26,20 +26,16 @@
 
 import java.awt.BorderLayout;
 import java.awt.Dimension;
-import java.awt.event.ActionEvent;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 
-import javax.swing.AbstractAction;
 import javax.swing.Icon;
-import javax.swing.JButton;
+import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.JTree;
-import javax.swing.ListModel;
 import javax.swing.plaf.TreeUI;
 import javax.swing.plaf.basic.BasicTreeUI;
-import javax.swing.plaf.metal.MetalTreeUI;
-
-import org.tigris.toolbar.toolbutton.ToolButton;
 
 /**
  * A control for displaying the contents of a list model elements in a panel
@@ -49,36 +45,31 @@
  * @author Bob Tarling
  * @since 0.29.2
  */
-public class UMLExpandableRowSelector extends JPanel {
+public class UMLExpandableRowSelector extends JPanel
+        implements MouseListener {
     
     /**
-     * The scrollpane that will contain the list
+     * class uid
      */
-    private JScrollPane scroll;
-
-    private Dimension shrunkPreferredSize = null;
-    private Dimension shrunkMinimumSize = null;
-    private Dimension expandedPreferredSize = null;
-    private Dimension expandedMinimumSize = null;
-    private Dimension expandedMaximumSize = null;
+    private static final long serialVersionUID = 3937183621483536749L;
     
-    private boolean expanded = false;
+    /**
+     * The icon to use when the control is expanded
+     */
+    private static Icon expandedIcon;
     
     /**
-     * Constructor
-     * @param model The single item list model
+     * The icon to use when the control is collapsed
      */
-    public UMLExpandableRowSelector(UMLModelElementListModel model) {
-        super(new BorderLayout());
-        
+    private static Icon collapsedIcon;
+    
+    static {
         final JTree dummyTree = new JTree();
         
         final TreeUI tu = dummyTree.getUI();
-        final Icon expandedIcon;
-        final Icon collapsedIcon;
         
         if (tu instanceof BasicTreeUI) {
-            BasicTreeUI btu = (BasicTreeUI) tu;
+            final BasicTreeUI btu = (BasicTreeUI) tu;
             expandedIcon = btu.getExpandedIcon();
             collapsedIcon = btu.getCollapsedIcon();
         } else {
@@ -86,21 +77,58 @@
             expandedIcon = null;
             collapsedIcon = null;
         }
+    }
+    
+    /**
+     * The scrollpane that will contain the list
+     */
+    private JScrollPane scroll;
+
+    /**
+     * The preferred size of the component when shrunk
+     */
+    private Dimension shrunkPreferredSize = null;
+
+    /**
+     * The preferred size of the component when expanded
+     */
+    private Dimension expandedPreferredSize = null;
+
+    /**
+     * The maximum size of the component when expanded
+     */
+    private Dimension expandedMaximumSize = null;
+    
+    /**
+     * The current expanded state
+     */
+    private boolean expanded = false;
+
+    private JLabel expander;
+    
+    /**
+     * Constructor
+     * @param model The single item list model
+     */
+    public UMLExpandableRowSelector(UMLModelElementListModel model) {
+        super(new BorderLayout());
+        
         JPanel buttonPanel = new JPanel();
-        buttonPanel.add(new ToolButton(new ExpandAction(expandedIcon)), BorderLayout.NORTH);
+        expander = new JLabel();
+        expander.addMouseListener(this);
+        setIcon();
+        buttonPanel.add(expander, BorderLayout.NORTH);
         add(buttonPanel, BorderLayout.WEST);
         scroll = new ScrollList(model, 1);
         add(scroll);
         
         shrunkPreferredSize = scroll.getPreferredSize();
-        shrunkMinimumSize = scroll.getMinimumSize();
         
         remove(scroll);
         scroll = new ScrollList(model);
         
         add(scroll);
         expandedPreferredSize = scroll.getPreferredSize();
-        expandedMinimumSize = scroll.getMinimumSize();
         expandedMaximumSize = scroll.getMaximumSize();
         
         scroll.setHorizontalScrollBarPolicy(
@@ -141,24 +169,70 @@
         }
     }
     
-    private class ExpandAction extends AbstractAction {
-        ExpandAction(Icon icon) {
-            super(null, icon);
-        }
+    @Override
+    public void mouseClicked(MouseEvent e) {
+        expanded = !expanded;
+        
+        setIcon();
+        
+        // TODO: This forces a redraw but what is the minimum we really
+        // need here?
+        getParent().validate();
+        getParent().invalidate();
+        getParent().repaint();
+        getParent().doLayout();
+        getParent().validate();
+        getParent().invalidate();
+        getParent().repaint();
+        getParent().doLayout();
+    }
+    
+    @Override
+    public void mouseEntered(MouseEvent e) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void mouseExited(MouseEvent e) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void mousePressed(MouseEvent e) {
+        // TODO Auto-generated method stub
+        
+    }
+
+    @Override
+    public void mouseReleased(MouseEvent e) {
+        // TODO Auto-generated method stub
+        
+    }
+    
+    private void toggleExpansion() {
+        expanded = !expanded;
+        
+        setIcon();
+        
+        // TODO: This forces a redraw but what is the minimum we really
+        // need here?
+        getParent().validate();
+        getParent().invalidate();
+        getParent().repaint();
+        getParent().doLayout();
+        getParent().validate();
+        getParent().invalidate();
+        getParent().repaint();
+        getParent().doLayout();
+    }
 
-        @Override
-        public void actionPerformed(ActionEvent arg0) {
-            expanded = !expanded;
-            // TODO: This forces a redraw but what is the minimum we really
-            // need here?
-            getParent().validate();
-            getParent().invalidate();
-            getParent().repaint();
-            getParent().doLayout();
-            getParent().validate();
-            getParent().invalidate();
-            getParent().repaint();
-            getParent().doLayout();
+    private void setIcon() {
+        if (expanded) {
+            expander.setIcon(expandedIcon);
+        } else {
+            expander.setIcon(collapsedIcon);
         }
     }
 }

------------------------------------------------------
http://argouml.tigris.org/ds/viewMessage.do?dsForumId=5905&dsMessageId=2422727

To unsubscribe from this discussion, e-mail: [[email protected]].
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.