src/share/classes/com/sun/java/swing/plaf/windows/WindowsTreeUI.java

Print this page




 110     static protected final int SIZE = 9;
 111 
 112     /**
 113      * Returns the default cell renderer that is used to do the
 114      * stamping of each node.
 115      */
 116     protected TreeCellRenderer createDefaultCellRenderer() {
 117         return new WindowsTreeCellRenderer();
 118     }
 119 
 120     /**
 121      * The minus sign button icon
 122      * <p>
 123      * <strong>Warning:</strong>
 124      * Serialized objects of this class will not be compatible with
 125      * future Swing releases.  The current serialization support is appropriate
 126      * for short term storage or RMI between applications running the same
 127      * version of Swing.  A future release of Swing will provide support for
 128      * long term persistence.
 129      */

 130     public static class ExpandedIcon implements Icon, Serializable {
 131 
 132         static public Icon createExpandedIcon() {
 133             return new ExpandedIcon();
 134         }
 135 
 136         Skin getSkin(Component c) {
 137             XPStyle xp = XPStyle.getXP();
 138             return (xp != null) ? xp.getSkin(c, Part.TVP_GLYPH) : null;
 139         }
 140 
 141         public void paintIcon(Component c, Graphics g, int x, int y) {
 142             Skin skin = getSkin(c);
 143             if (skin != null) {
 144                 skin.paintSkin(g, x, y, State.OPENED);
 145                 return;
 146             }
 147 
 148             Color     backgroundColor = c.getBackground();
 149 


 162             Skin skin = getSkin(null);
 163             return (skin != null) ? skin.getWidth() : SIZE;
 164         }
 165 
 166         public int getIconHeight() {
 167             Skin skin = getSkin(null);
 168             return (skin != null) ? skin.getHeight() : SIZE;
 169         }
 170     }
 171 
 172     /**
 173      * The plus sign button icon
 174      * <p>
 175      * <strong>Warning:</strong>
 176      * Serialized objects of this class will not be compatible with
 177      * future Swing releases.  The current serialization support is appropriate
 178      * for short term storage or RMI between applications running the same
 179      * version of Swing.  A future release of Swing will provide support for
 180      * long term persistence.
 181      */

 182     public static class CollapsedIcon extends ExpandedIcon {
 183         static public Icon createCollapsedIcon() {
 184             return new CollapsedIcon();
 185         }
 186 
 187         public void paintIcon(Component c, Graphics g, int x, int y) {
 188             Skin skin = getSkin(c);
 189             if (skin != null) {
 190                 skin.paintSkin(g, x, y, State.CLOSED);
 191             } else {
 192             super.paintIcon(c, g, x, y);
 193             g.drawLine(x + HALF_SIZE, y + 2, x + HALF_SIZE, y + (SIZE - 3));
 194             }
 195         }
 196     }
 197 

 198     public class WindowsTreeCellRenderer extends DefaultTreeCellRenderer {
 199 
 200         /**
 201          * Configures the renderer based on the passed in components.
 202          * The value is set from messaging the tree with
 203          * <code>convertValueToText</code>, which ultimately invokes
 204          * <code>toString</code> on <code>value</code>.
 205          * The foreground color is set based on the selection and the icon
 206          * is set based on on leaf and expanded.
 207          */
 208         public Component getTreeCellRendererComponent(JTree tree, Object value,
 209                                                       boolean sel,
 210                                                       boolean expanded,
 211                                                       boolean leaf, int row,
 212                                                       boolean hasFocus) {
 213             super.getTreeCellRendererComponent(tree, value, sel,
 214                                                expanded, leaf, row,
 215                                                hasFocus);
 216             // Windows displays the open icon when the tree item selected.
 217             if (!tree.isEnabled()) {




 110     static protected final int SIZE = 9;
 111 
 112     /**
 113      * Returns the default cell renderer that is used to do the
 114      * stamping of each node.
 115      */
 116     protected TreeCellRenderer createDefaultCellRenderer() {
 117         return new WindowsTreeCellRenderer();
 118     }
 119 
 120     /**
 121      * The minus sign button icon
 122      * <p>
 123      * <strong>Warning:</strong>
 124      * Serialized objects of this class will not be compatible with
 125      * future Swing releases.  The current serialization support is appropriate
 126      * for short term storage or RMI between applications running the same
 127      * version of Swing.  A future release of Swing will provide support for
 128      * long term persistence.
 129      */
 130     @SuppressWarnings("serial") // Same-version serialization only
 131     public static class ExpandedIcon implements Icon, Serializable {
 132 
 133         static public Icon createExpandedIcon() {
 134             return new ExpandedIcon();
 135         }
 136 
 137         Skin getSkin(Component c) {
 138             XPStyle xp = XPStyle.getXP();
 139             return (xp != null) ? xp.getSkin(c, Part.TVP_GLYPH) : null;
 140         }
 141 
 142         public void paintIcon(Component c, Graphics g, int x, int y) {
 143             Skin skin = getSkin(c);
 144             if (skin != null) {
 145                 skin.paintSkin(g, x, y, State.OPENED);
 146                 return;
 147             }
 148 
 149             Color     backgroundColor = c.getBackground();
 150 


 163             Skin skin = getSkin(null);
 164             return (skin != null) ? skin.getWidth() : SIZE;
 165         }
 166 
 167         public int getIconHeight() {
 168             Skin skin = getSkin(null);
 169             return (skin != null) ? skin.getHeight() : SIZE;
 170         }
 171     }
 172 
 173     /**
 174      * The plus sign button icon
 175      * <p>
 176      * <strong>Warning:</strong>
 177      * Serialized objects of this class will not be compatible with
 178      * future Swing releases.  The current serialization support is appropriate
 179      * for short term storage or RMI between applications running the same
 180      * version of Swing.  A future release of Swing will provide support for
 181      * long term persistence.
 182      */
 183     @SuppressWarnings("serial") // Superclass is not serializable across versions
 184     public static class CollapsedIcon extends ExpandedIcon {
 185         static public Icon createCollapsedIcon() {
 186             return new CollapsedIcon();
 187         }
 188 
 189         public void paintIcon(Component c, Graphics g, int x, int y) {
 190             Skin skin = getSkin(c);
 191             if (skin != null) {
 192                 skin.paintSkin(g, x, y, State.CLOSED);
 193             } else {
 194             super.paintIcon(c, g, x, y);
 195             g.drawLine(x + HALF_SIZE, y + 2, x + HALF_SIZE, y + (SIZE - 3));
 196             }
 197         }
 198     }
 199 
 200     @SuppressWarnings("serial") // Superclass is not serializable across versions
 201     public class WindowsTreeCellRenderer extends DefaultTreeCellRenderer {
 202 
 203         /**
 204          * Configures the renderer based on the passed in components.
 205          * The value is set from messaging the tree with
 206          * <code>convertValueToText</code>, which ultimately invokes
 207          * <code>toString</code> on <code>value</code>.
 208          * The foreground color is set based on the selection and the icon
 209          * is set based on on leaf and expanded.
 210          */
 211         public Component getTreeCellRendererComponent(JTree tree, Object value,
 212                                                       boolean sel,
 213                                                       boolean expanded,
 214                                                       boolean leaf, int row,
 215                                                       boolean hasFocus) {
 216             super.getTreeCellRendererComponent(tree, value, sel,
 217                                                expanded, leaf, row,
 218                                                hasFocus);
 219             // Windows displays the open icon when the tree item selected.
 220             if (!tree.isEnabled()) {