Author: kono
Date: 2012-04-23 12:53:37 -0700 (Mon, 23 Apr 2012)
New Revision: 28952

Added:
   
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/BasicCollapsiblePanelTest.java
   
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/CheckBoxJListTest.java
Removed:
   
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/NetworkSelectorPanel.java
Modified:
   
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/AbstractCellEditor.java
   
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/BasicCollapsiblePanel.java
   
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
Log:
refs #875 New unit tests had been added to swing-util-api.

Modified: 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/AbstractCellEditor.java
===================================================================
--- 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/AbstractCellEditor.java
       2012-04-23 19:22:59 UTC (rev 28951)
+++ 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/AbstractCellEditor.java
       2012-04-23 19:53:37 UTC (rev 28952)
@@ -30,11 +30,13 @@
  * @CyAPI.Abstract.Class
  */
 public class AbstractCellEditor implements CellEditor {
+       
        protected EventListenerList listenerList = new EventListenerList();
 
        /**
         * {@inheritDoc}
         */
+       @Override
        public Object getCellEditorValue() {
                return null;
        }
@@ -42,6 +44,7 @@
        /**
         * {@inheritDoc}
         */
+       @Override
        public boolean isCellEditable(EventObject e) {
                return true;
        }
@@ -49,6 +52,7 @@
        /**
         * {@inheritDoc}
         */
+       @Override
        public boolean shouldSelectCell(EventObject anEvent) {
                return false;
        }
@@ -56,6 +60,7 @@
        /**
         * {@inheritDoc}
         */
+       @Override
        public boolean stopCellEditing() {
                return true;
        }
@@ -63,12 +68,14 @@
        /**
         * {@inheritDoc}
         */
+       @Override
        public void cancelCellEditing() {
        }
 
        /**
         * {@inheritDoc}
         */
+       @Override
        public void addCellEditorListener(CellEditorListener l) {
                listenerList.add(CellEditorListener.class, l);
        }
@@ -76,6 +83,7 @@
        /**
         * {@inheritDoc}
         */
+       @Override
        public void removeCellEditorListener(CellEditorListener l) {
                listenerList.remove(CellEditorListener.class, l);
        }

Modified: 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/BasicCollapsiblePanel.java
===================================================================
--- 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/BasicCollapsiblePanel.java
    2012-04-23 19:22:59 UTC (rev 28951)
+++ 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/BasicCollapsiblePanel.java
    2012-04-23 19:53:37 UTC (rev 28952)
@@ -1,16 +1,30 @@
 package org.cytoscape.util.swing;
 
-import javax.swing.*;
-import javax.swing.border.Border;
-import javax.swing.border.TitledBorder;
-
-import java.awt.*;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Insets;
+import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.net.URL;
 
+import javax.swing.AbstractAction;
+import javax.swing.AbstractButton;
+import javax.swing.BorderFactory;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JComponent;
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+import javax.swing.border.Border;
+import javax.swing.border.TitledBorder;
+
 /**
  * * Copyright (c) 2004 Memorial Sloan-Kettering Cancer Center
  * *
@@ -53,382 +67,400 @@
  */
 
 /**
- * A user-triggered collapsible panel containing the component (trigger) in 
the titled border
+ * A user-triggered collapsible panel containing the component (trigger) in the
+ * titled border
  */
 public class BasicCollapsiblePanel extends JPanel {
+       
        private static final long serialVersionUID = 2010434345567315524L;
-    //Border
-    CollapsableTitledBorder border; // includes upper left component and line 
type
-    Border collapsedBorderLine = BorderFactory.createEmptyBorder(2, 2, 2, 2); 
// no border
-    Border expandedBorderLine = null; // because this is null, default is 
used, etched lowered border on MAC
+       // Border
+       CollapsableTitledBorder border; // includes upper left component and 
line
+                                                                       // type
+       Border collapsedBorderLine = BorderFactory.createEmptyBorder(2, 2, 2, 
2); // no
+                                                                               
                                                                                
// border
+       Border expandedBorderLine = null; // because this is null, default is 
used,
+                                                                               
// etched lowered border on MAC
 
-    //Title
-    AbstractButton titleComponent; // displayed in the titled border
+       // Title
+       AbstractButton titleComponent; // displayed in the titled border
 
-    //Expand/Collapse button
-    final static int COLLAPSED = 0, EXPANDED = 1; // image States
-    ImageIcon[] iconArrow = createExpandAndCollapseIcon();
-    JButton arrow = createArrowButton();
+       // Expand/Collapse button
+       final static int COLLAPSED = 0, EXPANDED = 1; // image States
+       ImageIcon[] iconArrow = createExpandAndCollapseIcon();
+       JButton arrow = createArrowButton();
 
-    //Content Pane
-    JPanel panel;
+       // Content Pane
+       JPanel panel;
 
-    //Container State
-    boolean collapsed; // stores curent state of the collapsable panel
+       // Container State
+       boolean collapsed; // stores curent state of the collapsable panel
 
-    /**
-     * Constructor for an option button controlled collapsible panel.
-     * This is useful when a group of options each have unique sub contents. 
The radio buttons should be created,
-     * grouped, and then used to construct their own collapsible panels. This 
way choosing a different option in
-     * the same option group will collapse all unselected options. Expanded 
panels draw a border around the
-     * contents and through the radio button in the fashion of a titled border.
-     *
-     * @param component Radio button that expands and collapses the panel 
based on if it is selected or not
-     */
-    public BasicCollapsiblePanel(JRadioButton component) {
-        component.addItemListener(new 
BasicCollapsiblePanel.ExpandAndCollapseAction());
-        titleComponent = component;
-        collapsed = !component.isSelected();
-        commonConstructor();
-    }
+       /**
+        * Constructor for an option button controlled collapsible panel. This 
is
+        * useful when a group of options each have unique sub contents. The 
radio
+        * buttons should be created, grouped, and then used to construct their 
own
+        * collapsible panels. This way choosing a different option in the same
+        * option group will collapse all unselected options. Expanded panels 
draw a
+        * border around the contents and through the radio button in the 
fashion of
+        * a titled border.
+        * 
+        * @param component
+        *            Radio button that expands and collapses the panel based 
on if
+        *            it is selected or not
+        */
+       public BasicCollapsiblePanel(JRadioButton component) {
+               component.addItemListener(new 
BasicCollapsiblePanel.ExpandAndCollapseAction());
+               titleComponent = component;
+               collapsed = !component.isSelected();
+               commonConstructor();
+       }
 
-    /**
-     * Constructor for a label/button controlled collapsible panel. Displays a 
clickable title that resembles a
-     * native titled border except for an arrow on the right side indicating 
an expandable panel. The actual border
-     * only appears when the panel is expanded.
-     * 
-     * @param text Title of the collapsible panel in string format, used to 
create a button with text and an arrow icon
-     */
-    public BasicCollapsiblePanel(String text) {
-        arrow.setText(text);
-        titleComponent = arrow;
-        collapsed = true;
-        commonConstructor();
-    }
+       /**
+        * Constructor for a label/button controlled collapsible panel. 
Displays a
+        * clickable title that resembles a native titled border except for an 
arrow
+        * on the right side indicating an expandable panel. The actual border 
only
+        * appears when the panel is expanded.
+        * 
+        * @param text
+        *            Title of the collapsible panel in string format, used to
+        *            create a button with text and an arrow icon
+        */
+       public BasicCollapsiblePanel(String text) {
+               arrow.setText(text);
+               titleComponent = arrow;
+               collapsed = true;
+               commonConstructor();
+       }
 
-    /**
-     * Sets layout, creates the content panel and adds it and the title 
component to the container,
-     * all constructors have this procedure in common.
-     */
-    private void commonConstructor () {
-        setLayout(new BorderLayout());
+       /**
+        * Sets layout, creates the content panel and adds it and the title
+        * component to the container, all constructors have this procedure in
+        * common.
+        */
+       private void commonConstructor() {
+               setLayout(new BorderLayout());
 
-        panel = new JPanel();
-        panel.setLayout(new BorderLayout());
+               panel = new JPanel();
+               panel.setLayout(new BorderLayout());
 
-        add(titleComponent, BorderLayout.CENTER);
-        add(panel, BorderLayout.CENTER);
-        setCollapsed(collapsed);
+               add(titleComponent, BorderLayout.CENTER);
+               add(panel, BorderLayout.CENTER);
+               setCollapsed(collapsed);
 
-        placeTitleComponent();
-    }
+               placeTitleComponent();
+       }
 
-    /**
-     * Sets the bounds of the border title component so that it is properly 
positioned.
-     */
-    private void placeTitleComponent() {
-        Insets insets = this.getInsets();
-        Rectangle containerRectangle = this.getBounds();
-        Rectangle componentRectangle = 
border.getComponentRect(containerRectangle, insets);
-        titleComponent.setBounds(componentRectangle);
-    }
+       /**
+        * Sets the bounds of the border title component so that it is properly
+        * positioned.
+        */
+       private void placeTitleComponent() {
+               Insets insets = this.getInsets();
+               Rectangle containerRectangle = this.getBounds();
+               Rectangle componentRectangle = 
border.getComponentRect(containerRectangle, insets);
+               titleComponent.setBounds(componentRectangle);
+       }
 
-    /** Sets the title of of the border title component. 
-     * 
-     * @param text The string title.
-     */
-    public void setTitleComponentText(String text) {
-        if (titleComponent instanceof JButton) {
-            titleComponent.setText(text);
-        }
-        placeTitleComponent();
-    }
+       /**
+        * Sets the title of of the border title component.
+        * 
+        * @param text
+        *            The string title.
+        */
+       public void setTitleComponentText(String text) {
+               if (titleComponent instanceof JButton) {
+                       titleComponent.setText(text);
+               }
+               placeTitleComponent();
+       }
 
-    /**
-     * This class requires that all content be placed within a designated 
panel, this method returns that panel.
-     *
-     * @return panel The content panel.
-     */
-    public JPanel getContentPane() {
-        return panel;
-    }
-    
-    /**
-     * This method will not add components as might be expected, instead use 
the method getContentPane() which
-     * will return a panel, and you may use add() on that. This is true for 
all similar add() methods.
-     */
-    public Component add(Component c) {
-       return super.add(c);
-    }
+       /**
+        * This class requires that all content be placed within a designated 
panel,
+        * this method returns that panel.
+        * 
+        * @return panel The content panel.
+        */
+       public JPanel getContentPane() {
+               return panel;
+       }
 
-    /**
-     * Collapses or expands the panel.  This is done by adding or removing the 
content pane,
-     * alternating between a frame and empty border, and changing the title 
arrow.
-     * Also, the current state is stored in the collapsed boolean.
-     *
-     * @param collapse When set to true, the panel is collapsed, else it is 
expanded
-     */
-    public void setCollapsed(boolean collapse) {
-        if (collapse) {
-            //collapse the panel, remove content and set border to empty border
-            remove(panel);
-            arrow.setIcon(iconArrow[COLLAPSED]);
-            border = new CollapsableTitledBorder(collapsedBorderLine, 
titleComponent);
-        } else {
-            //expand the panel, add content and set border to titled border
-            add(panel, BorderLayout.NORTH);
-            arrow.setIcon(iconArrow[EXPANDED]);
-            border = new CollapsableTitledBorder(expandedBorderLine, 
titleComponent);
-        }
-        setBorder(border);
-        collapsed = collapse;
-        updateUI();
-    }
+       /**
+        * This method will not add components as might be expected, instead 
use the
+        * method getContentPane() which will return a panel, and you may use 
add()
+        * on that. This is true for all similar add() methods.
+        */
+       @Override
+       public Component add(Component c) {
+               return super.add(c);
+       }
 
-    /**
-     * Returns the current state of the panel, collapsed (true) or expanded 
(false).
-     *
-     * @return collapsed Returns true if the panel is collapsed and false if 
it is expanded
-     */
-    public boolean isCollapsed() {
-        return collapsed;
-    }
+       /**
+        * Collapses or expands the panel. This is done by adding or removing 
the
+        * content pane, alternating between a frame and empty border, and 
changing
+        * the title arrow. Also, the current state is stored in the collapsed
+        * boolean.
+        * 
+        * @param collapse
+        *            When set to true, the panel is collapsed, else it is 
expanded
+        */
+       public void setCollapsed(boolean collapse) {
+               if (collapse) {
+                       // collapse the panel, remove content and set border to 
empty border
+                       remove(panel);
+                       arrow.setIcon(iconArrow[COLLAPSED]);
+                       border = new 
CollapsableTitledBorder(collapsedBorderLine, titleComponent);
+               } else {
+                       // expand the panel, add content and set border to 
titled border
+                       add(panel, BorderLayout.NORTH);
+                       arrow.setIcon(iconArrow[EXPANDED]);
+                       border = new 
CollapsableTitledBorder(expandedBorderLine, titleComponent);
+               }
+               setBorder(border);
+               collapsed = collapse;
+               updateUI();
+       }
 
-    /**
-     * Returns an ImageIcon array with arrow images used for the different 
states of the panel.
-     *
-     * @return iconArrow An ImageIcon array holding the collapse and expanded 
versions of the right hand side arrow
-     */
-    private ImageIcon[] createExpandAndCollapseIcon () {
-        ImageIcon[] iconArrow = new ImageIcon[2];
-        URL iconURL;
+       /**
+        * Returns the current state of the panel, collapsed (true) or expanded
+        * (false).
+        * 
+        * @return collapsed Returns true if the panel is collapsed and false 
if it
+        *         is expanded
+        */
+       public boolean isCollapsed() {
+               return collapsed;
+       }
 
-        iconURL = getClass().getResource("/images/arrow_collapsed.png");
+       /**
+        * Returns an ImageIcon array with arrow images used for the different
+        * states of the panel.
+        * 
+        * @return iconArrow An ImageIcon array holding the collapse and 
expanded
+        *         versions of the right hand side arrow
+        */
+       private ImageIcon[] createExpandAndCollapseIcon() {
+               ImageIcon[] iconArrow = new ImageIcon[2];
+               URL iconURL;
 
-        if (iconURL != null) {
-            iconArrow[COLLAPSED] = new ImageIcon(iconURL);
-        }
-        iconURL = getClass().getResource("/images/arrow_expanded.png");
+               iconURL = getClass().getResource("/images/arrow_collapsed.png");
 
-        if (iconURL != null) {
-            iconArrow[EXPANDED] = new ImageIcon(iconURL);
-        }
-        return iconArrow;
-    }
+               if (iconURL != null) {
+                       iconArrow[COLLAPSED] = new ImageIcon(iconURL);
+               }
+               iconURL = getClass().getResource("/images/arrow_expanded.png");
 
-    /**
-     * Returns a button with an arrow icon and a collapse/expand action 
listener.
-     *
-     * @return button Button which is used in the titled border component
-     */
-    private JButton createArrowButton () {
-        JButton button = new JButton("arrow", iconArrow[COLLAPSED]);
-        button.setBorder(BorderFactory.createEmptyBorder(0,1,5,1));
-        button.setVerticalTextPosition(AbstractButton.CENTER);
-        button.setHorizontalTextPosition(AbstractButton.LEFT);
-        button.setMargin(new Insets(0,0,3,0));
+               if (iconURL != null) {
+                       iconArrow[EXPANDED] = new ImageIcon(iconURL);
+               }
+               return iconArrow;
+       }
 
-        //We want to use the same font as those in the titled border font
-        Font font = BorderFactory.createTitledBorder("Sample").getTitleFont();
-        Color color = 
BorderFactory.createTitledBorder("Sample").getTitleColor();
-        button.setFont(font);
-        button.setForeground(color);
-        button.setFocusable(false);
-        button.setContentAreaFilled(false);
+       /**
+        * Returns a button with an arrow icon and a collapse/expand action
+        * listener.
+        * 
+        * @return button Button which is used in the titled border component
+        */
+       private JButton createArrowButton() {
+               JButton button = new JButton("arrow", iconArrow[COLLAPSED]);
+               button.setBorder(BorderFactory.createEmptyBorder(0, 1, 5, 1));
+               button.setVerticalTextPosition(AbstractButton.CENTER);
+               button.setHorizontalTextPosition(AbstractButton.LEFT);
+               button.setMargin(new Insets(0, 0, 3, 0));
 
-        button.addActionListener(new 
BasicCollapsiblePanel.ExpandAndCollapseAction());
+               // We want to use the same font as those in the titled border 
font
+               Font font = 
BorderFactory.createTitledBorder("Sample").getTitleFont();
+               Color color = 
BorderFactory.createTitledBorder("Sample").getTitleColor();
+               button.setFont(font);
+               button.setForeground(color);
+               button.setFocusable(false);
+               button.setContentAreaFilled(false);
 
-        return button;
-    }
+               button.addActionListener(new 
BasicCollapsiblePanel.ExpandAndCollapseAction());
 
-    /**
-     * Handles expanding and collapsing of extra content on the user's click 
of the titledBorder component.
-     */
-    private class ExpandAndCollapseAction extends AbstractAction implements 
ActionListener, ItemListener {
+               return button;
+       }
+
+       /**
+        * Handles expanding and collapsing of extra content on the user's 
click of
+        * the titledBorder component.
+        */
+       private final class ExpandAndCollapseAction extends AbstractAction 
implements ActionListener, ItemListener {
                private static final long serialVersionUID = 
2010434345567315525L;
-        public void actionPerformed(ActionEvent e) {
-            setCollapsed(!isCollapsed());
-        }
-        public void itemStateChanged(ItemEvent e) {
-            setCollapsed(!isCollapsed());
-        }
-    }
 
-    /**
-     * Special titled border that includes a component in the title area
-     */
-    private class CollapsableTitledBorder extends TitledBorder {
-               private static final long serialVersionUID = 
2010434345567315526L;
-        JComponent component;
-        //Border border;
+               public void actionPerformed(ActionEvent e) {
+                       setCollapsed(!isCollapsed());
+               }
 
-        public CollapsableTitledBorder(JComponent component) {
-            this(null, component, LEFT, TOP);
-        }
+               public void itemStateChanged(ItemEvent e) {
+                       setCollapsed(!isCollapsed());
+               }
+       }
 
-        public CollapsableTitledBorder(Border border) {
-            this(border, null, LEFT, TOP);
-        }
+       /**
+        * Special titled border that includes a component in the title area
+        */
+       private final class CollapsableTitledBorder extends TitledBorder {
+               private static final long serialVersionUID = 
2010434345567315526L;
+               JComponent component;
 
-        public CollapsableTitledBorder(Border border, JComponent component) {
-            this(border, component, LEFT, TOP);
-        }
 
-        public CollapsableTitledBorder(Border border, JComponent component, 
int titleJustification, int titlePosition) {
-            //TitledBorder needs border, title, justification, position, font, 
and color
-            super(border, null, titleJustification, titlePosition, null, null);
-            this.component = component;
-            if (border == null) {
-                this.border = super.getBorder();
-            }
-        }
+               public CollapsableTitledBorder(Border border, JComponent 
component) {
+                       this(border, component, LEFT, TOP);
+               }
 
-        public void paintBorder(Component c, Graphics g, int x, int y, int 
width, int height) {
-            Rectangle borderR = new Rectangle(x + EDGE_SPACING, y + 
EDGE_SPACING, width - (EDGE_SPACING * 2), height - (EDGE_SPACING * 2));
-            Insets borderInsets;
-            if (border != null) {
-                borderInsets = border.getBorderInsets(c);
-            } else {
-                borderInsets = new Insets(0, 0, 0, 0);
-            }
+               public CollapsableTitledBorder(Border border, JComponent 
component, int titleJustification, int titlePosition) {
+                       // TitledBorder needs border, title, justification, 
position, font,
+                       // and color
+                       super(border, null, titleJustification, titlePosition, 
null, null);
+                       this.component = component;
+                       if (border == null) {
+                               this.border = super.getBorder();
+                       }
+               }
 
-            Rectangle rect = new Rectangle(x, y, width, height);
-            Insets insets = getBorderInsets(c);
-            Rectangle compR = getComponentRect(rect, insets);
-            int diff;
-            switch (titlePosition) {
-                case ABOVE_TOP:
-                    diff = compR.height + TEXT_SPACING;
-                    borderR.y += diff;
-                    borderR.height -= diff;
-                    break;
-                case TOP:
-                case DEFAULT_POSITION:
-                    diff = insets.top / 2 - borderInsets.top - EDGE_SPACING;
-                    borderR.y += diff;
-                    borderR.height -= diff;
-                    break;
-                case BELOW_TOP:
-                case ABOVE_BOTTOM:
-                    break;
-                case BOTTOM:
-                    diff = insets.bottom / 2 - borderInsets.bottom - 
EDGE_SPACING;
-                    borderR.height -= diff;
-                    break;
-                case BELOW_BOTTOM:
-                    diff = compR.height + TEXT_SPACING;
-                    borderR.height -= diff;
-                    break;
-            }
-            border.paintBorder(c, g, borderR.x, borderR.y, borderR.width, 
borderR.height);
-            Color col = g.getColor();
-            g.setColor(c.getBackground());
-            g.fillRect(compR.x, compR.y, compR.width, compR.height);
-            g.setColor(col);
-        }
+               public void paintBorder(Component c, Graphics g, int x, int y, 
int width, int height) {
+                       Rectangle borderR = new Rectangle(x + EDGE_SPACING, y + 
EDGE_SPACING, width - (EDGE_SPACING * 2), height
+                                       - (EDGE_SPACING * 2));
+                       Insets borderInsets;
+                       if (border != null) {
+                               borderInsets = border.getBorderInsets(c);
+                       } else {
+                               borderInsets = new Insets(0, 0, 0, 0);
+                       }
 
-        public Insets getBorderInsets(Component c, Insets insets) {
-            Insets borderInsets;
-            if (border != null) {
-                borderInsets = border.getBorderInsets(c);
-            } else {
-                borderInsets = new Insets(0, 0, 0, 0);
-            }
-            insets.top = EDGE_SPACING + TEXT_SPACING + borderInsets.top;
-            insets.right = EDGE_SPACING + TEXT_SPACING + borderInsets.right;
-            insets.bottom = EDGE_SPACING + TEXT_SPACING + borderInsets.bottom;
-            insets.left = EDGE_SPACING + TEXT_SPACING + borderInsets.left;
+                       Rectangle rect = new Rectangle(x, y, width, height);
+                       Insets insets = getBorderInsets(c);
+                       Rectangle compR = getComponentRect(rect, insets);
+                       int diff;
+                       switch (titlePosition) {
+                       case ABOVE_TOP:
+                               diff = compR.height + TEXT_SPACING;
+                               borderR.y += diff;
+                               borderR.height -= diff;
+                               break;
+                       case TOP:
+                       case DEFAULT_POSITION:
+                               diff = insets.top / 2 - borderInsets.top - 
EDGE_SPACING;
+                               borderR.y += diff;
+                               borderR.height -= diff;
+                               break;
+                       case BELOW_TOP:
+                       case ABOVE_BOTTOM:
+                               break;
+                       case BOTTOM:
+                               diff = insets.bottom / 2 - borderInsets.bottom 
- EDGE_SPACING;
+                               borderR.height -= diff;
+                               break;
+                       case BELOW_BOTTOM:
+                               diff = compR.height + TEXT_SPACING;
+                               borderR.height -= diff;
+                               break;
+                       }
+                       border.paintBorder(c, g, borderR.x, borderR.y, 
borderR.width, borderR.height);
+                       Color col = g.getColor();
+                       g.setColor(c.getBackground());
+                       g.fillRect(compR.x, compR.y, compR.width, compR.height);
+                       g.setColor(col);
+               }
 
-            if (c == null || component == null) {
-                return insets;
-            }
+               public Insets getBorderInsets(Component c, Insets insets) {
+                       Insets borderInsets;
+                       if (border != null) {
+                               borderInsets = border.getBorderInsets(c);
+                       } else {
+                               borderInsets = new Insets(0, 0, 0, 0);
+                       }
+                       insets.top = EDGE_SPACING + TEXT_SPACING + 
borderInsets.top;
+                       insets.right = EDGE_SPACING + TEXT_SPACING + 
borderInsets.right;
+                       insets.bottom = EDGE_SPACING + TEXT_SPACING + 
borderInsets.bottom;
+                       insets.left = EDGE_SPACING + TEXT_SPACING + 
borderInsets.left;
 
-            int compHeight = component.getPreferredSize().height;
+                       if (c == null || component == null) {
+                               return insets;
+                       }
 
-            switch (titlePosition) {
-                case ABOVE_TOP:
-                    insets.top += compHeight + TEXT_SPACING;
-                    break;
-                case TOP:
-                case DEFAULT_POSITION:
-                    insets.top += Math.max(compHeight, borderInsets.top) - 
borderInsets.top;
-                    break;
-                case BELOW_TOP:
-                    insets.top += compHeight + TEXT_SPACING;
-                    break;
-                case ABOVE_BOTTOM:
-                    insets.bottom += compHeight + TEXT_SPACING;
-                    break;
-                case BOTTOM:
-                    insets.bottom += Math.max(compHeight, borderInsets.bottom) 
- borderInsets.bottom;
-                    break;
-                case BELOW_BOTTOM:
-                    insets.bottom += compHeight + TEXT_SPACING;
-                    break;
-            }
-            return insets;
-        }
+                       int compHeight = component.getPreferredSize().height;
 
-        public JComponent getTitleComponent() {
-            return component;
-        }
+                       switch (titlePosition) {
+                       case ABOVE_TOP:
+                               insets.top += compHeight + TEXT_SPACING;
+                               break;
+                       case TOP:
+                       case DEFAULT_POSITION:
+                               insets.top += Math.max(compHeight, 
borderInsets.top) - borderInsets.top;
+                               break;
+                       case BELOW_TOP:
+                               insets.top += compHeight + TEXT_SPACING;
+                               break;
+                       case ABOVE_BOTTOM:
+                               insets.bottom += compHeight + TEXT_SPACING;
+                               break;
+                       case BOTTOM:
+                               insets.bottom += Math.max(compHeight, 
borderInsets.bottom) - borderInsets.bottom;
+                               break;
+                       case BELOW_BOTTOM:
+                               insets.bottom += compHeight + TEXT_SPACING;
+                               break;
+                       }
+                       return insets;
+               }
 
-        public void setTitleComponent(JComponent component) {
-            this.component = component;
-        }
+               public Rectangle getComponentRect(Rectangle rect, Insets 
borderInsets) {
+                       Dimension compD = component.getPreferredSize();
+                       Rectangle compR = new Rectangle(0, 0, compD.width, 
compD.height);
+                       switch (titlePosition) {
+                       case ABOVE_TOP:
+                               compR.y = EDGE_SPACING;
+                               break;
+                       case TOP:
+                       case DEFAULT_POSITION:
+                               if (titleComponent instanceof JButton) {
+                                       compR.y = EDGE_SPACING + 
(borderInsets.top - EDGE_SPACING - TEXT_SPACING - compD.height) / 2;
+                               } else if (titleComponent instanceof 
JRadioButton) {
+                                       compR.y = (borderInsets.top - 
EDGE_SPACING - TEXT_SPACING - compD.height) / 2;
+                               }
+                               break;
+                       case BELOW_TOP:
+                               compR.y = borderInsets.top - compD.height - 
TEXT_SPACING;
+                               break;
+                       case ABOVE_BOTTOM:
+                               compR.y = rect.height - borderInsets.bottom + 
TEXT_SPACING;
+                               break;
+                       case BOTTOM:
+                               compR.y = rect.height - borderInsets.bottom + 
TEXT_SPACING
+                                               + (borderInsets.bottom - 
EDGE_SPACING - TEXT_SPACING - compD.height) / 2;
+                               break;
+                       case BELOW_BOTTOM:
+                               compR.y = rect.height - compD.height - 
EDGE_SPACING;
+                               break;
+                       }
+                       switch (titleJustification) {
+                       case LEFT:
+                       case DEFAULT_JUSTIFICATION:
+                               // compR.x = TEXT_INSET_H + borderInsets.left;
+                               compR.x = TEXT_INSET_H + borderInsets.left - 
EDGE_SPACING;
+                               break;
+                       case RIGHT:
+                               compR.x = rect.width - borderInsets.right - 
TEXT_INSET_H - compR.width;
+                               break;
+                       case CENTER:
+                               compR.x = (rect.width - compR.width) / 2;
+                               break;
+                       }
+                       return compR;
+               }
+       }
 
-        public Rectangle getComponentRect(Rectangle rect, Insets borderInsets) 
{
-            Dimension compD = component.getPreferredSize();
-            Rectangle compR = new Rectangle(0, 0, compD.width, compD.height);
-            switch (titlePosition) {
-                case ABOVE_TOP:
-                    compR.y = EDGE_SPACING;
-                    break;
-                case TOP:
-                case DEFAULT_POSITION:
-                    if (titleComponent instanceof JButton) {
-                        compR.y = EDGE_SPACING + (borderInsets.top - 
EDGE_SPACING - TEXT_SPACING - compD.height) / 2;
-                    } else if (titleComponent instanceof JRadioButton) {
-                        compR.y = (borderInsets.top - EDGE_SPACING - 
TEXT_SPACING - compD.height) / 2;
-                    }
-                    break;
-                case BELOW_TOP:
-                    compR.y = borderInsets.top - compD.height - TEXT_SPACING;
-                    break;
-                case ABOVE_BOTTOM:
-                    compR.y = rect.height - borderInsets.bottom + TEXT_SPACING;
-                    break;
-                case BOTTOM:
-                    compR.y = rect.height - borderInsets.bottom + TEXT_SPACING 
+ (borderInsets.bottom - EDGE_SPACING - TEXT_SPACING - compD.height) / 2;
-                    break;
-                case BELOW_BOTTOM:
-                    compR.y = rect.height - compD.height - EDGE_SPACING;
-                    break;
-            }
-            switch (titleJustification) {
-                case LEFT:
-                case DEFAULT_JUSTIFICATION:
-                    //compR.x = TEXT_INSET_H + borderInsets.left;
-                    compR.x = TEXT_INSET_H + borderInsets.left - EDGE_SPACING;
-                    break;
-                case RIGHT:
-                    compR.x = rect.width - borderInsets.right - TEXT_INSET_H - 
compR.width;
-                    break;
-                case CENTER:
-                    compR.x = (rect.width - compR.width) / 2;
-                    break;
-            }
-            return compR;
-        }
-    }
-    
-    /** 
+       /**
         * Sets the tooltip text of this BasicCollapsiblePanel.
-     * @param text The string to set as the tooltip.
-     */
-    public void setToolTipText(String text)
-    {
-       super.setToolTipText(text);
-       titleComponent.setToolTipText(text);
-    }
+        * 
+        * @param text
+        *            The string to set as the tooltip.
+        */
+       @Override
+       public void setToolTipText(final String text) {
+               super.setToolTipText(text);
+               titleComponent.setToolTipText(text);
+       }
 }

Modified: 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
===================================================================
--- 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
    2012-04-23 19:22:59 UTC (rev 28951)
+++ 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/CheckBoxJList.java
    2012-04-23 19:53:37 UTC (rev 28952)
@@ -34,14 +34,26 @@
 */
 package org.cytoscape.util.swing;
 
-import javax.swing.*;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
-import java.awt.*;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Font;
 import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
+import javax.swing.DefaultListCellRenderer;
+import javax.swing.JCheckBox;
+import javax.swing.JComponent;
+import javax.swing.JList;
+import javax.swing.ListCellRenderer;
+import javax.swing.ListSelectionModel;
+import javax.swing.UIDefaults;
+import javax.swing.UIManager;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.event.ListSelectionListener;
 
+
 /**
  * <p>
  * This class is based on CheckBoxJList: from SWING HACKS
@@ -55,11 +67,13 @@
  * @CyAPI.Final.Class 
  */
 public final class CheckBoxJList extends JList implements 
ListSelectionListener {
+       
        private final static long serialVersionUID = 120233987581935L;
+       
        private static final Color SELECTED_COLOR = new Color(0, 100, 250, 250);
        private static final Color NORMAL_COLOR = new Color(100, 100, 100, 170);
        
-       private static Color listBackground;
+       private static final Color listBackground;
        private static final Font NORMAL_FONT = new Font("SansSerif", 
Font.PLAIN, 12);
        private static final Font SELECTED_FONT = new Font("SansSerif", 
Font.BOLD, 12);
 
@@ -74,13 +88,14 @@
                listBackground = uid.getColor("List.background");
        }
 
-       private HashSet<Integer> selectionCache = new HashSet<Integer>();
+       private final Set<Integer> selectionCache;
 
        /**
         * Creates a new CheckBoxJList object.
         */
        public CheckBoxJList() {
                super();
+               selectionCache = new HashSet<Integer>();
                setCellRenderer(new CheckBoxListCellRenderer());
                addListSelectionListener(this);
        }
@@ -89,30 +104,30 @@
         * Sets the specified items as selected.
         * @param selected the items to be selected.
         */
-       public void setSelectedItems(List<String> selected) {
-               ListSelectionListener[] listeners = 
this.getListSelectionListeners();
-               for(ListSelectionListener l :listeners) {
+       public void setSelectedItems(final List<String> selected) {
+               final ListSelectionListener[] listeners = 
this.getListSelectionListeners();
+               for(ListSelectionListener l :listeners)
                        removeListSelectionListener(l);
-               }
+               
                getSelectionModel().clearSelection();
                selectionCache.clear();
                
-               for(int i=0; i<this.getModel().getSize(); i++) {
+               final int size = this.getModel().getSize();
+               for(int i=0; i<size; i++) {
                        if(selected.contains(getModel().getElementAt(i))) {
                                getSelectionModel().addSelectionInterval(i, i);
                                selectionCache.add(i);
                        }
                }
                
-               for(ListSelectionListener l :listeners) {
+               for(ListSelectionListener l :listeners)
                        addListSelectionListener(l);
-               }
        }
 
-       // ListSelectionListener implementation
        /**
         * {@inheritDoc} 
         */
+       @Override
        public void valueChanged(ListSelectionEvent lse) {
                
                if (!lse.getValueIsAdjusting()) {
@@ -121,33 +136,32 @@
                        // remember everything selected as a result of this 
action
                        final HashSet<Integer> newSelections = new 
HashSet<Integer>();
                        final int size = getModel().getSize();
+                       final ListSelectionModel select = getSelectionModel();
 
                        for (int i = 0; i < size; i++) {
-                               if (getSelectionModel().isSelectedIndex(i)) {
+                               if (select.isSelectedIndex(i))
                                        newSelections.add(i);
-                               }
                        }
 
                        // turn on everything that was previously selected
                        for (Integer index : selectionCache) {
-                               getSelectionModel().addSelectionInterval(index, 
index);
+                               select.addSelectionInterval(index, index);
                        }
 
                        // add or remove the delta
                        for (Integer index : newSelections) {
                                if (selectionCache.contains(index))
-                                       
getSelectionModel().removeSelectionInterval(index, index);
+                                       select.removeSelectionInterval(index, 
index);
                                else
-                                       
getSelectionModel().addSelectionInterval(index, index);
+                                       select.addSelectionInterval(index, 
index);
                        }
 
                        // save selections for next time
                        selectionCache.clear();
 
                        for (int i = 0; i < size; i++) {
-                               if (getSelectionModel().isSelectedIndex(i)) {
+                               if (select.isSelectedIndex(i))
                                        selectionCache.add(i);
-                               }
                        }
 
                        addListSelectionListener(this);
@@ -155,13 +169,15 @@
                }
        }
 
-       private class CheckBoxListCellRenderer extends JComponent implements 
ListCellRenderer {
-       private final static long serialVersionUID = 120233987573888L;
+       private static final class CheckBoxListCellRenderer extends JComponent 
implements ListCellRenderer {
+               
+               private final static long serialVersionUID = 120233987573888L;
+               
                private final DefaultListCellRenderer defaultComp;
                private final JCheckBox checkbox;
                private final BorderLayout layout = new BorderLayout();
 
-               public CheckBoxListCellRenderer() {
+               CheckBoxListCellRenderer() {
                        setLayout(layout);
                        defaultComp = new DefaultListCellRenderer();
                        checkbox = new JCheckBox();
@@ -169,8 +185,9 @@
                        add(defaultComp, BorderLayout.CENTER);
                }
 
-               public Component getListCellRendererComponent(JList list, 
Object value, int index,
-                                                             boolean 
isSelected, boolean cellHasFocus) {
+               @Override
+               public Component getListCellRendererComponent(JList list, 
Object value, int index, boolean isSelected,
+                               boolean cellHasFocus) {
                        defaultComp.getListCellRendererComponent(list, value, 
index, isSelected, cellHasFocus);
 
                        checkbox.setSelected(isSelected);
@@ -189,10 +206,8 @@
 
                        final Component[] comps = getComponents();
                        final int length = comps.length;
-
-                       for (int i = 0; i < length; i++) {
+                       for (int i = 0; i < length; i++)
                                comps[i].setBackground(listBackground);
-                       }
 
                        return this;
                }

Deleted: 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/NetworkSelectorPanel.java
===================================================================
--- 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/NetworkSelectorPanel.java
     2012-04-23 19:22:59 UTC (rev 28951)
+++ 
core3/api/trunk/swing-util-api/src/main/java/org/cytoscape/util/swing/NetworkSelectorPanel.java
     2012-04-23 19:53:37 UTC (rev 28952)
@@ -1,121 +0,0 @@
-package org.cytoscape.util.swing;
-
-import java.awt.BorderLayout;
-import java.awt.event.ItemListener;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
-
-import javax.swing.JComboBox;
-import javax.swing.JPanel;
-
-import org.cytoscape.application.CyApplicationManager;
-import org.cytoscape.model.CyNetwork;
-import org.cytoscape.model.CyNetworkManager;
-import org.cytoscape.model.events.NetworkAddedEvent;
-import org.cytoscape.model.events.NetworkDestroyedEvent;
-import org.cytoscape.model.events.NetworkDestroyedListener;
-import org.cytoscape.model.events.NetworkAddedListener;
-import javax.swing.DefaultComboBoxModel;
-
-/**
- * A convenience JPanel for selecting networks.
- * @CyAPI.Final.Class 
- */
-public final class NetworkSelectorPanel extends JPanel implements 
NetworkAddedListener, NetworkDestroyedListener
-{
-       private static final long serialVersionUID = 8694272457769377810L;
-       
-       protected final JComboBox networkComboBox;
-       private CyNetworkManager cyNetworkManager;
-       private CyApplicationManager cyApplicationManager;
-
-       /**
-        * Constructor.
-        * @param cyApplicationManager The application manager used for 
tracking the current network.
-        * @param cyNetworkManager The network manager used for accessing all 
available networks.
-        */
-       public NetworkSelectorPanel(CyApplicationManager cyApplicationManager, 
CyNetworkManager cyNetworkManager) {
-               super();
-               this.setLayout(new BorderLayout());
-               networkComboBox = new JComboBox();
-
-               this.cyNetworkManager = cyNetworkManager;
-               this.cyApplicationManager = cyApplicationManager;
-               
-               //This should help to limit the length of combobox if the 
network name is too long
-               networkComboBox.setPreferredSize(new 
java.awt.Dimension(networkComboBox.getPreferredSize().width, 
-                               networkComboBox.getPreferredSize().height));
-
-               add(networkComboBox, BorderLayout.CENTER);
-               updateNetworkList();
-       }
-       
-       /**
-        * If selected, return selected network.
-        * Otherwise, return null.
-        * 
-        * @return The network that was selected.
-        */
-       public CyNetwork getSelectedNetwork() {
-               for (CyNetwork net : this.cyNetworkManager.getNetworkSet()) {
-                       String networkTitle = net.getRow(net).get("name", 
String.class);
-                       if 
(networkTitle.equals(networkComboBox.getSelectedItem()))
-                               return net;
-               }
-               
-               return null;
-       }
-
-       private void updateNetworkList() {
-               final Set<CyNetwork> networks = 
this.cyNetworkManager.getNetworkSet();
-               final SortedSet<String> networkNames = new TreeSet<String>();
-
-               for (CyNetwork net : networks)
-                       networkNames.add(net.getRow(net).get("name", 
String.class));
-
-               // Clear the comboBox
-               networkComboBox.setModel(new DefaultComboBoxModel());
-
-               for (String name : networkNames)
-                       networkComboBox.addItem(name);
-
-               CyNetwork currNetwork = 
this.cyApplicationManager.getCurrentNetwork();
-               if (currNetwork != null) {
-                       String networkTitle = 
currNetwork.getRow(currNetwork).get("name", String.class);
-                       networkComboBox.setSelectedItem(networkTitle);          
        
-               }
-       }
-
-       /**
-        * Updates the list based on network added events.
-        * @param e The network added event.
-        */
-       public void handleEvent(NetworkAddedEvent e){
-               updateNetworkList();
-       }
-
-       /**
-        * Updates the list based on network destroyed events.
-        * @param e The network destroyed event.
-        */
-       public void handleEvent(NetworkDestroyedEvent e){
-               updateNetworkList();
-       }
-       
-       /**
-        * Installs a new item listener for the embedded combo box.
-        * @param newListener The new item listener to be added.
-        */
-       public void addItemListener(final ItemListener newListener) {
-               networkComboBox.addItemListener(newListener);
-       }
-
-       /**
-        * Returns the network combobox.
-        * @return The network combobox.
-        */
-       public JComboBox getJCombobox(){
-               return this.networkComboBox;
-       }
-}

Added: 
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/BasicCollapsiblePanelTest.java
===================================================================
--- 
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/BasicCollapsiblePanelTest.java
                                (rev 0)
+++ 
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/BasicCollapsiblePanelTest.java
        2012-04-23 19:53:37 UTC (rev 28952)
@@ -0,0 +1,69 @@
+package org.cytoscape.util.swing;
+
+import static org.junit.Assert.*;
+
+import javax.swing.JPanel;
+import javax.swing.JRadioButton;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+public class BasicCollapsiblePanelTest {
+       
+       private BasicCollapsiblePanel panel;
+
+       @Before
+       public void setUp() throws Exception {
+               panel = new BasicCollapsiblePanel(new JRadioButton());
+       }
+
+
+       @Test
+       public void testBasicCollapsiblePanelConstructor() {
+               panel = new BasicCollapsiblePanel(new JRadioButton());
+               assertNotNull(panel);
+               
+               panel = new BasicCollapsiblePanel("Test");
+               assertNotNull(panel);
+       }
+
+       @Test
+       public void testSetTitleComponentText() {
+               final String title ="Title text";
+               
+               final String original = "original title";
+               panel = new BasicCollapsiblePanel(original);
+               assertEquals(original, panel.titleComponent.getText());
+               panel.setTitleComponentText(title);
+               assertEquals(title, panel.titleComponent.getText());
+               
+       }
+
+       @Test
+       public void testGetContentPane() {
+               assertNotNull(panel.getContentPane());
+       }
+
+       @Test
+       public void testAddComponent() {
+               JPanel testPanel = new JPanel();
+               assertNotNull(panel.add(testPanel));
+       }
+
+       @Test
+       public void testSetCollapsed() {
+               panel.setCollapsed(true);
+               assertTrue(panel.isCollapsed());
+               
+               panel.setCollapsed(false);
+               assertFalse(panel.isCollapsed());
+       }
+
+       @Test
+       public void testSetToolTipTextString() {
+               String text = "tooltip";
+               panel.setToolTipText(text);
+               assertEquals(text, panel.getToolTipText());
+       }
+}

Added: 
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/CheckBoxJListTest.java
===================================================================
--- 
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/CheckBoxJListTest.java
                                (rev 0)
+++ 
core3/api/trunk/swing-util-api/src/test/java/org/cytoscape/util/swing/CheckBoxJListTest.java
        2012-04-23 19:53:37 UTC (rev 28952)
@@ -0,0 +1,84 @@
+package org.cytoscape.util.swing;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.DefaultListModel;
+import javax.swing.ListModel;
+import javax.swing.event.ListSelectionEvent;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class CheckBoxJListTest {
+       private CheckBoxJList list;
+
+       @Before
+       public void setUp() throws Exception {
+               list = new CheckBoxJList();
+       }
+
+
+       @Test
+       public void testCheckBoxJList() {
+               assertNotNull(list);
+       }
+
+       @Test
+       public void testSetSelectedItems() {
+               
+               final List<String> selected = new ArrayList<String>();
+               DefaultListModel model = new DefaultListModel();
+               final String[] listItemStrings = new String[] {"test1", 
"test2", "test3"};
+               for(String item: listItemStrings)
+                       model.addElement(item);
+               list.setModel(model);
+               
+               selected.add("test2");
+               list.setSelectedItems(selected);
+               Object[] selectedVals = list.getSelectedValues();
+               assertEquals(1, selectedVals.length);
+               
+               selected.clear();
+               for(String item: listItemStrings)
+                       selected.add(item);
+               
+               list.setSelectedItems(selected);
+               selectedVals = list.getSelectedValues();
+               assertEquals(3, selectedVals.length);
+               
+               selected.clear();
+               selected.add("invalid");
+               
+               list.setSelectedItems(selected);
+               selectedVals = list.getSelectedValues();
+               assertEquals(0, selectedVals.length);
+       }
+
+       @Test
+       public void testValueChanged() {
+               
+               final List<String> selected = new ArrayList<String>();
+               DefaultListModel model = new DefaultListModel();
+               final String[] listItemStrings = new String[] {"test1", 
"test2", "test3"};
+               for(String item: listItemStrings)
+                       model.addElement(item);
+               list.setModel(model);
+               for(String item: listItemStrings)
+                       selected.add(item);
+               
+               list.setSelectedItems(selected);
+               
+               ListSelectionEvent lse = mock(ListSelectionEvent.class);
+               when(lse.getValueIsAdjusting()).thenReturn(false);
+               list.valueChanged(lse);
+               
+               verify(lse, times(1)).getValueIsAdjusting();
+       }
+
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to