Index: graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java =================================================================== RCS file: /cvs/graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java,v retrieving revision 1.71 diff -u -r1.71 RunDialog.java --- graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java 8 Jun 2007 08:44:57 -0000 1.71 +++ graph/examples/src/org/netbeans/modules/visual/examples/RunDialog.java 12 Jun 2007 11:44:55 -0000 @@ -106,6 +106,7 @@ "test.tool.ToolTest", "test.visible.VisibilityTest", "test.vmd.VMDCollisionTest", + "test.vmd.VMDColorSchemeTest", "test.vmd.VMDTest", "test.widget.AnimatedImageTest", "test.zoom.FitToViewTest", Index: graph/examples/src/test/vmd/VMDCollisionTest.java =================================================================== RCS file: /cvs/graph/examples/src/test/vmd/VMDCollisionTest.java,v retrieving revision 1.3 diff -u -r1.3 VMDCollisionTest.java --- graph/examples/src/test/vmd/VMDCollisionTest.java 14 Nov 2006 10:04:08 -0000 1.3 +++ graph/examples/src/test/vmd/VMDCollisionTest.java 12 Jun 2007 11:44:55 -0000 @@ -19,8 +19,6 @@ package test.vmd; import org.netbeans.api.visual.vmd.VMDGraphScene; -import org.netbeans.api.visual.vmd.VMDNodeWidget; -import org.netbeans.api.visual.vmd.VMDPinWidget; import org.openide.util.Utilities; import test.SceneSupport; @@ -46,36 +44,16 @@ public static void main (String[] args) { VMDGraphScene scene = new VMDGraphScene (); - String mobile = createNode (scene, 100, 100, IMAGE_LIST, "menu", "List", null); - createPin (scene, mobile, "start", IMAGE_ITEM, "Start", "Element"); + String mobile = VMDTest.createNode (scene, 100, 100, IMAGE_LIST, "menu", "List", null); + VMDTest.createPin (scene, mobile, "start", IMAGE_ITEM, "Start", "Element"); - String game = createNode (scene, 600, 100, IMAGE_CANVAS, "gameCanvas", "MyCanvas", Arrays.asList (GLYPH_PRE_CODE, GLYPH_CANCEL, GLYPH_POST_CODE)); - createPin (scene, game, "ok", IMAGE_COMMAND, "okCommand1", "Command"); + String game = VMDTest.createNode (scene, 600, 100, IMAGE_CANVAS, "gameCanvas", "MyCanvas", Arrays.asList (GLYPH_PRE_CODE, GLYPH_CANCEL, GLYPH_POST_CODE)); + VMDTest.createPin (scene, game, "ok", IMAGE_COMMAND, "okCommand1", "Command"); - createEdge (scene, "start", game); - createEdge (scene, "ok", mobile); + VMDTest.createEdge (scene, "start", game); + VMDTest.createEdge (scene, "ok", mobile); SceneSupport.show (scene); - } - - private static String createNode (VMDGraphScene scene, int x, int y, Image image, String name, String type, java.util.List glyphs) { - String nodeID = "node" + VMDCollisionTest.nodeID ++; - VMDNodeWidget widget = (VMDNodeWidget) scene.addNode (nodeID); - widget.setPreferredLocation (new Point (x, y)); - widget.setNodeProperties (image, name, type, glyphs); - scene.addPin (nodeID, nodeID + VMDGraphScene.PIN_ID_DEFAULT_SUFFIX); - return nodeID; - } - - private static void createPin (VMDGraphScene scene, String nodeID, String pinID, Image image, String name, String type) { - ((VMDPinWidget) scene.addPin (nodeID, pinID)).setProperties (name, null); - } - - private static void createEdge (VMDGraphScene scene, String sourcePinID, String targetNodeID) { - String edgeID = "edge" + VMDCollisionTest.edgeID ++; - scene.addEdge (edgeID); - scene.setEdgeSource (edgeID, sourcePinID); - scene.setEdgeTarget (edgeID, targetNodeID + VMDGraphScene.PIN_ID_DEFAULT_SUFFIX); } } Index: graph/examples/src/test/vmd/VMDColorSchemeTest.java =================================================================== RCS file: graph/examples/src/test/vmd/VMDColorSchemeTest.java diff -N graph/examples/src/test/vmd/VMDColorSchemeTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/examples/src/test/vmd/VMDColorSchemeTest.java 12 Jun 2007 11:44:55 -0000 @@ -0,0 +1,33 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package test.vmd; + +import org.netbeans.api.visual.vmd.VMDFactory; +import org.netbeans.api.visual.vmd.VMDGraphScene; + +/** + * @author David Kaspar + */ +public class VMDColorSchemeTest { + + public static void main (String[] args) { + VMDTest.runScene (new VMDGraphScene (VMDFactory.getNetBeans60Scheme ())); + } + +} Index: graph/examples/src/test/vmd/VMDTest.java =================================================================== RCS file: /cvs/graph/examples/src/test/vmd/VMDTest.java,v retrieving revision 1.10 diff -u -r1.10 VMDTest.java --- graph/examples/src/test/vmd/VMDTest.java 14 Nov 2006 10:04:08 -0000 1.10 +++ graph/examples/src/test/vmd/VMDTest.java 12 Jun 2007 11:44:55 -0000 @@ -50,7 +50,10 @@ public static void main (String[] args) { final VMDGraphScene scene = new VMDGraphScene (); + runScene (scene); + } + static void runScene (final VMDGraphScene scene) { String mobile = createNode (scene, 100, 100, IMAGE_LIST, "menu", "List", null); createPin (scene, mobile, "start", IMAGE_ITEM, "Start", "Element"); createPin (scene, mobile, "resume", IMAGE_ITEM, "Resume", "Element"); @@ -91,7 +94,7 @@ SceneSupport.show (scene); } - private static String createNode (VMDGraphScene scene, int x, int y, Image image, String name, String type, List glyphs) { + static String createNode (VMDGraphScene scene, int x, int y, Image image, String name, String type, List glyphs) { String nodeID = "node" + VMDTest.nodeID ++; VMDNodeWidget widget = (VMDNodeWidget) scene.addNode (nodeID); widget.setPreferredLocation (new Point (x, y)); @@ -100,11 +103,11 @@ return nodeID; } - private static void createPin (VMDGraphScene scene, String nodeID, String pinID, Image image, String name, String type) { + static void createPin (VMDGraphScene scene, String nodeID, String pinID, Image image, String name, String type) { ((VMDPinWidget) scene.addPin (nodeID, pinID)).setProperties (name, null); } - private static void createEdge (VMDGraphScene scene, String sourcePinID, String targetNodeID) { + static void createEdge (VMDGraphScene scene, String sourcePinID, String targetNodeID) { String edgeID = "edge" + VMDTest.edgeID ++; scene.addEdge (edgeID); scene.setEdgeSource (edgeID, sourcePinID); Index: graph/lib/apichanges.xml =================================================================== RCS file: /cvs/graph/lib/apichanges.xml,v retrieving revision 1.21 diff -u -r1.21 apichanges.xml --- graph/lib/apichanges.xml 8 Jun 2007 08:45:00 -0000 1.21 +++ graph/lib/apichanges.xml 12 Jun 2007 11:44:55 -0000 @@ -299,6 +299,21 @@ + + + + VMDColorScheme introduced + + + + + + VMDColorScheme abstract class has been introduced to define a UI of VMD widget. + There are two predefined schemes available in VMDFactory class. Use them as a paratemer in widget constructors. + + + + Index: graph/lib/manifest.mf =================================================================== RCS file: /cvs/graph/lib/manifest.mf,v retrieving revision 1.12 diff -u -r1.12 manifest.mf --- graph/lib/manifest.mf 8 Jun 2007 08:02:48 -0000 1.12 +++ graph/lib/manifest.mf 12 Jun 2007 11:44:55 -0000 @@ -1,4 +1,4 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.api.visual OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/visual/resources/Bundle.properties -OpenIDE-Module-Specification-Version: 2.4 +OpenIDE-Module-Specification-Version: 2.5 Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDColorScheme.java =================================================================== RCS file: graph/lib/src/org/netbeans/api/visual/vmd/VMDColorScheme.java diff -N graph/lib/src/org/netbeans/api/visual/vmd/VMDColorScheme.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/api/visual/vmd/VMDColorScheme.java 12 Jun 2007 11:44:55 -0000 @@ -0,0 +1,104 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.api.visual.vmd; + +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; + +/** + * This class specifies look and feel of vmd widgets. There are predefined schemes in VMDFactory class. + * + * @author David Kaspar + * @since 2.5 + */ +public abstract class VMDColorScheme { + + /** + * Creates a new vmd color scheme. + * @since 2.5 + */ + protected VMDColorScheme () { + } + + /** + * Called to install UI to a node widget. + * @param widget the node widget + * @since 2.5 + */ + public abstract void installUI (VMDNodeWidget widget); + + /** + * Called to update UI of a node widget. Called from VMDNodeWidget.notifyStateChanged method. + * @param widget the node widget + * @param previousState the previous state + * @param state the new state + * @since 2.5 + */ + public abstract void updateUI (VMDNodeWidget widget, ObjectState previousState, ObjectState state); + + /** + * Returns whether the node minimize button is on the right side of the node header. + * @param widget the node widget + * @return true, if the button is on the right side; false, if the button is on the left side + * @since 2.5 + */ + public abstract boolean isNodeMinimizeButtonOnRight (VMDNodeWidget widget); + + /** + * Called to create a pin-category widget. + * @param widget the node widget + * @param categoryDisplayName the category display name + * @return the pin-category widget + * @since 2.5 + */ + public abstract Widget createPinCategoryWidget (VMDNodeWidget widget, String categoryDisplayName); + + /** + * Called to install UI to a connection widget. + * @param widget the connection widget + * @since 2.5 + */ + public abstract void installUI (VMDConnectionWidget widget); + + /** + * Called to update UI of a connection widget. Called from VMDConnectionWidget.notifyStateChanged method. + * @param widget the connection widget + * @param previousState the previous state + * @param state the new state + * @since 2.5 + */ + public abstract void updateUI (VMDConnectionWidget widget, ObjectState previousState, ObjectState state); + + /** + * Called to install UI to a pin widget. + * @param widget the pin widget + * @since 2.5 + */ + public abstract void installUI (VMDPinWidget widget); + + /** + * Called to update UI of a pin widget. Called from VMDPinWidget.notifyStateChanged method. + * @param widget the pin widget + * @param previousState the previous state + * @param state the new state + * @since 2.5 + */ + public abstract void updateUI (VMDPinWidget widget, ObjectState previousState, ObjectState state); + +} Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDConnectionWidget.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/vmd/VMDConnectionWidget.java,v retrieving revision 1.4 diff -u -r1.4 VMDConnectionWidget.java --- graph/lib/src/org/netbeans/api/visual/vmd/VMDConnectionWidget.java 9 Mar 2007 16:41:54 -0000 1.4 +++ graph/lib/src/org/netbeans/api/visual/vmd/VMDConnectionWidget.java 12 Jun 2007 11:44:55 -0000 @@ -18,16 +18,10 @@ */ package org.netbeans.api.visual.vmd; -import org.netbeans.api.visual.anchor.AnchorShape; -import org.netbeans.api.visual.anchor.PointShape; -import org.netbeans.api.visual.anchor.PointShapeFactory; import org.netbeans.api.visual.model.ObjectState; import org.netbeans.api.visual.router.Router; import org.netbeans.api.visual.widget.ConnectionWidget; import org.netbeans.api.visual.widget.Scene; -import org.openide.util.Utilities; - -import java.awt.*; /** * This class represents a connection widget in the VMD visualization style. Can be combined with any other widget. @@ -36,23 +30,29 @@ */ public class VMDConnectionWidget extends ConnectionWidget { - private static final PointShape POINT_SHAPE_IMAGE = PointShapeFactory.createImagePointShape (Utilities.loadImage ("org/netbeans/modules/visual/resources/vmd-pin.png")); // NOI18N - - private static final Color COLOR_NORMAL = VMDNodeBorder.COLOR_BORDER; - private static final Color COLOR_HOVERED = Color.BLACK; - private static final Color COLOR_HIGHLIGHTED = new Color (49, 106, 197); + private VMDColorScheme scheme; /** - * Creates a connection widget. + * Creates a connection widget with a specific router. * @param scene the scene - * @param router + * @param router the router */ public VMDConnectionWidget (Scene scene, Router router) { + this (scene, VMDFactory.getOriginalScheme ()); + if (router != null) + setRouter (router); + } + + /** + * Creates a connection widget with a specific color scheme. + * @param scene the scene + * @param scheme the color scheme + */ + public VMDConnectionWidget (Scene scene, VMDColorScheme scheme) { super (scene); - setRouter (router); - setSourceAnchorShape (AnchorShape.NONE); - setTargetAnchorShape (AnchorShape.TRIANGLE_FILLED); - setPaintControlPoints (true); + assert scheme != null; + this.scheme = scheme; + scheme.installUI (this); setState (ObjectState.createNormal ()); } @@ -62,24 +62,7 @@ * @param state the new state */ public void notifyStateChanged (ObjectState previousState, ObjectState state) { - if (state.isHovered ()) - setForeground (COLOR_HOVERED); - else if (state.isSelected ()) - setForeground (VMDNodeWidget.COLOR_SELECTED); - else if (state.isHighlighted ()) - setForeground (COLOR_HIGHLIGHTED); - else if (state.isFocused ()) - setForeground (COLOR_HOVERED); - else - setForeground (COLOR_NORMAL); - - if (state.isSelected ()) { - setControlPointShape (PointShape.SQUARE_FILLED_SMALL); - setEndPointShape (PointShape.SQUARE_FILLED_BIG); - } else { - setControlPointShape (PointShape.NONE); - setEndPointShape (POINT_SHAPE_IMAGE); - } + scheme.updateUI (this, previousState, state); } } Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDFactory.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/vmd/VMDFactory.java,v retrieving revision 1.4 diff -u -r1.4 VMDFactory.java --- graph/lib/src/org/netbeans/api/visual/vmd/VMDFactory.java 9 Mar 2007 16:41:54 -0000 1.4 +++ graph/lib/src/org/netbeans/api/visual/vmd/VMDFactory.java 12 Jun 2007 11:44:55 -0000 @@ -19,6 +19,10 @@ package org.netbeans.api.visual.vmd; import org.netbeans.api.visual.border.Border; +import org.netbeans.modules.visual.vmd.VMDNetBeans60ColorScheme; +import org.netbeans.modules.visual.vmd.VMDOriginalColorScheme; + +import java.awt.*; /** * Used as a factory class for objects defined in VMD visualization style. @@ -27,17 +31,52 @@ */ public final class VMDFactory { - private static final Border BORDER_NODE = new VMDNodeBorder (); + private static VMDColorScheme SCHEME_ORIGINAL = new VMDOriginalColorScheme (); + private static VMDColorScheme SCHEME_NB60 = new VMDNetBeans60ColorScheme (); private VMDFactory () { } /** + * Creates the original vmd color scheme. Used by default. + * @return the color scheme + * @since 2.5 + */ + public static VMDColorScheme getOriginalScheme () { + return SCHEME_ORIGINAL; + } + + /** + * Creates the NetBeans 6.0 vmd color scheme. + * @return the color scheme + * @since 2.5 + */ + public static VMDColorScheme getNetBeans60Scheme () { + return SCHEME_NB60; + } + + /** * Creates a border used by VMD node. * @return the VMD node border */ public static Border createVMDNodeBorder () { - return BORDER_NODE; + return VMDOriginalColorScheme.BORDER_NODE; + } + + /** + * Creates a border used by VMD node with a specific colors. + * @return the VMD node border + * @param borderColor the border color + * @param borderThickness the border thickness + * @param color1 1. color of gradient background + * @param color2 2. color of gradient background + * @param color3 3. color of gradient background + * @param color4 4. color of gradient background + * @param color5 5. color of gradient background + * @since 2.5 + */ + public static Border createVMDNodeBorder (Color borderColor, int borderThickness, Color color1, Color color2, Color color3, Color color4, Color color5) { + return new VMDNodeBorder (borderColor, borderThickness, color1, color2, color3, color4, color5); } } Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDGraphScene.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/vmd/VMDGraphScene.java,v retrieving revision 1.23 diff -u -r1.23 VMDGraphScene.java --- graph/lib/src/org/netbeans/api/visual/vmd/VMDGraphScene.java 12 Jun 2007 11:26:34 -0000 1.23 +++ graph/lib/src/org/netbeans/api/visual/vmd/VMDGraphScene.java 12 Jun 2007 11:44:55 -0000 @@ -58,11 +58,21 @@ private WidgetAction moveAction = ActionFactory.createMoveAction (); private SceneLayout sceneLayout; + private VMDColorScheme scheme; /** * Creates a VMD graph scene. */ public VMDGraphScene () { + this (VMDFactory.getOriginalScheme ()); + } + + /** + * Creates a VMD graph scene with a specific color scheme. + * @param scheme the color scheme + */ + public VMDGraphScene (VMDColorScheme scheme) { + this.scheme = scheme; setKeyEventProcessingType (EventProcessingType.FOCUSED_WIDGET_AND_ITS_PARENTS); addChild (backgroundLayer); @@ -85,7 +95,7 @@ * @return the widget attached to the node */ protected Widget attachNodeWidget (String node) { - VMDNodeWidget widget = new VMDNodeWidget (this); + VMDNodeWidget widget = new VMDNodeWidget (this, scheme); mainLayer.addChild (widget); widget.getHeader ().getActions ().addAction (createObjectHoverAction ()); @@ -106,7 +116,7 @@ if (pin.endsWith (PIN_ID_DEFAULT_SUFFIX)) return null; - VMDPinWidget widget = new VMDPinWidget (this); + VMDPinWidget widget = new VMDPinWidget (this, scheme); ((VMDNodeWidget) findWidget (node)).attachPinWidget (widget); widget.getActions ().addAction (createObjectHoverAction ()); widget.getActions ().addAction (createSelectAction ()); @@ -120,7 +130,8 @@ * @return the widget attached to the edge */ protected Widget attachEdgeWidget (String edge) { - VMDConnectionWidget connectionWidget = new VMDConnectionWidget (this, router); + VMDConnectionWidget connectionWidget = new VMDConnectionWidget (this, scheme); + connectionWidget.setRouter (router); connectionLayer.addChild (connectionWidget); connectionWidget.getActions ().addAction (createObjectHoverAction ()); Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeBorder.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeBorder.java,v retrieving revision 1.3 diff -u -r1.3 VMDNodeBorder.java --- graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeBorder.java 14 Nov 2006 10:04:18 -0000 1.3 +++ graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeBorder.java 12 Jun 2007 11:44:55 -0000 @@ -28,33 +28,44 @@ */ class VMDNodeBorder implements Border { - static final Color COLOR_BORDER = new Color (0xBACDF0); - private static final Insets INSETS = new Insets (1, 1, 1, 1); -// private static final Color COLOR0 = new Color (169, 197, 235); - private static final Color COLOR1 = new Color (221, 235, 246); - private static final Color COLOR2 = new Color (255, 255, 255); - private static final Color COLOR3 = new Color (214, 235, 255); - private static final Color COLOR4 = new Color (241, 249, 253); - private static final Color COLOR5 = new Color (255, 255, 255); - - VMDNodeBorder () { + private Color colorBorder; + private Insets insets; + private Stroke stroke; + private Color color1; + private Color color2; + private Color color3; + private Color color4; + private Color color5; + + VMDNodeBorder (Color colorBorder, int thickness, Color color1, Color color2, Color color3, Color color4, Color color5) { + this.colorBorder = colorBorder; + this.insets = new Insets (thickness, thickness, thickness, thickness); + this.stroke = new BasicStroke (thickness); + this.color1 = color1; + this.color2 = color2; + this.color3 = color3; + this.color4 = color4; + this.color5 = color5; } public Insets getInsets () { - return INSETS; + return insets; } public void paint (Graphics2D gr, Rectangle bounds) { Shape previousClip = gr.getClip (); gr.clip (new RoundRectangle2D.Float (bounds.x, bounds.y, bounds.width, bounds.height, 4, 4)); - drawGradient (gr, bounds, COLOR1, COLOR2, 0f, 0.3f); - drawGradient (gr, bounds, COLOR2, COLOR3, 0.3f, 0.764f); - drawGradient (gr, bounds, COLOR3, COLOR4, 0.764f, 0.927f); - drawGradient (gr, bounds, COLOR4, COLOR5, 0.927f, 1f); - - gr.setColor (COLOR_BORDER); + drawGradient (gr, bounds, color1, color2, 0f, 0.3f); + drawGradient (gr, bounds, color2, color3, 0.3f, 0.764f); + drawGradient (gr, bounds, color3, color4, 0.764f, 0.927f); + drawGradient (gr, bounds, color4, color5, 0.927f, 1f); + + gr.setColor (colorBorder); + Stroke previousStroke = gr.getStroke (); + gr.setStroke (stroke); gr.draw (new RoundRectangle2D.Float (bounds.x + 0.5f, bounds.y + 0.5f, bounds.width - 1, bounds.height - 1, 4, 4)); + gr.setStroke (previousStroke); gr.setClip (previousClip); } @@ -69,4 +80,5 @@ public boolean isOpaque () { return true; } + } Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeWidget.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeWidget.java,v retrieving revision 1.37 diff -u -r1.37 VMDNodeWidget.java --- graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeWidget.java 4 Apr 2007 12:26:20 -0000 1.37 +++ graph/lib/src/org/netbeans/api/visual/vmd/VMDNodeWidget.java 12 Jun 2007 11:44:55 -0000 @@ -21,8 +21,6 @@ import org.netbeans.api.visual.action.WidgetAction; import org.netbeans.api.visual.anchor.Anchor; import org.netbeans.api.visual.anchor.AnchorFactory; -import org.netbeans.api.visual.border.Border; -import org.netbeans.api.visual.border.BorderFactory; import org.netbeans.api.visual.layout.LayoutFactory; import org.netbeans.api.visual.model.ObjectState; import org.netbeans.api.visual.model.StateModel; @@ -46,12 +44,6 @@ */ public class VMDNodeWidget extends Widget implements StateModel.Listener, VMDMinimizeAbility { - private static final Color BORDER_CATEGORY_BACKGROUND = new Color (0xCDDDF8); - private static final Border BORDER_MINIMIZE = BorderFactory.createRoundedBorder (2, 2, null, VMDNodeBorder.COLOR_BORDER); - static final Color COLOR_SELECTED = new Color (0x748CC0); - static final Border BORDER = BorderFactory.createOpaqueBorder (2, 8, 2, 8); - static final Border BORDER_HOVERED = BorderFactory.createLineBorder (2, 8, 2, 8, Color.BLACK); - private Widget header; private ImageWidget minimizeWidget; private ImageWidget imageWidget; @@ -62,35 +54,43 @@ private SeparatorWidget pinsSeparator; private HashMap pinCategoryWidgets = new HashMap (); - private Font fontPinCategory = getScene ().getFont ().deriveFont (10.0f); private StateModel stateModel = new StateModel (2); private Anchor nodeAnchor = new VMDNodeAnchor (this); + private VMDColorScheme scheme; /** * Creates a node widget. * @param scene the scene */ public VMDNodeWidget (Scene scene) { + this (scene, VMDFactory.getOriginalScheme ()); + } + + /** + * Creates a node widget with a specific color scheme. + * @param scene the scene + * @param scheme the color scheme + */ + public VMDNodeWidget (Scene scene, VMDColorScheme scheme) { super (scene); + assert scheme != null; + this.scheme = scheme; - setOpaque (false); - setBorder (VMDFactory.createVMDNodeBorder ()); setLayout (LayoutFactory.createVerticalFlowLayout ()); setMinimumSize (new Dimension (128, 8)); header = new Widget (scene); - header.setBorder (BORDER); - header.setBackground (COLOR_SELECTED); - header.setOpaque (false); header.setLayout (LayoutFactory.createHorizontalFlowLayout (LayoutFactory.SerialAlignment.CENTER, 8)); addChild (header); - minimizeWidget = new ImageWidget (scene, Utilities.loadImage ("org/netbeans/modules/visual/resources/vmd-collapse.png")); + boolean right = scheme.isNodeMinimizeButtonOnRight (this); + + minimizeWidget = new ImageWidget (scene, Utilities.loadImage ("org/netbeans/modules/visual/resources/vmd-collapse.png")); // NOI18N minimizeWidget.setCursor (Cursor.getPredefinedCursor (Cursor.HAND_CURSOR)); - minimizeWidget.setBorder (BORDER_MINIMIZE); minimizeWidget.getActions ().addAction (new ToggleMinimizedAction ()); - header.addChild (minimizeWidget); + if (! right) + header.addChild (minimizeWidget); imageWidget = new ImageWidget (scene); header.addChild (imageWidget); @@ -106,8 +106,14 @@ glyphSetWidget = new VMDGlyphSetWidget (scene); header.addChild (glyphSetWidget); + if (right) { + Widget widget = new Widget (scene); + widget.setOpaque (false); + header.addChild (widget, 1000); + header.addChild (minimizeWidget); + } + pinsSeparator = new SeparatorWidget (scene, SeparatorWidget.Orientation.HORIZONTAL); - pinsSeparator.setForeground (BORDER_CATEGORY_BACKGROUND); addChild (pinsSeparator); Widget topLayer = new Widget (scene); @@ -116,6 +122,7 @@ stateModel = new StateModel (); stateModel.addListener (this); + scheme.installUI (this); notifyStateChanged (ObjectState.createNormal (), ObjectState.createNormal ()); } @@ -175,13 +182,7 @@ * @param state the new state */ protected void notifyStateChanged (ObjectState previousState, ObjectState state) { - if (! previousState.isSelected () && state.isSelected ()) - bringToFront (); - else if (! previousState.isHovered () && state.isHovered ()) - bringToFront (); - - header.setOpaque (state.isSelected ()); - header.setBorder (state.isFocused () || state.isHovered () ? VMDNodeWidget.BORDER_HOVERED : VMDNodeWidget.BORDER); + scheme.updateUI (this, previousState, state); } /** @@ -331,13 +332,7 @@ Widget w = pinCategoryWidgets.get (categoryDisplayName); if (w != null) return w; - LabelWidget label = new LabelWidget (getScene (), categoryDisplayName); - label.setOpaque (true); - label.setBackground (BORDER_CATEGORY_BACKGROUND); - label.setForeground (Color.GRAY); - label.setFont (fontPinCategory); - label.setAlignment (LabelWidget.Alignment.CENTER); - label.setCheckClipping (true); + Widget label = scheme.createPinCategoryWidget (this, categoryDisplayName); if (stateModel.getBooleanState ()) label.setPreferredBounds (new Rectangle ()); pinCategoryWidgets.put (categoryDisplayName, label); @@ -364,6 +359,22 @@ */ public Widget getHeader () { return header; + } + + /** + * Returns a minimize button widget. + * @return the miminize button widget + */ + public Widget getMinimizeButton () { + return minimizeWidget; + } + + /** + * Returns a pins separator. + * @return the pins separator + */ + public Widget getPinsSeparator () { + return pinsSeparator; } private final class ToggleMinimizedAction extends WidgetAction.Adapter { Index: graph/lib/src/org/netbeans/api/visual/vmd/VMDPinWidget.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/vmd/VMDPinWidget.java,v retrieving revision 1.19 diff -u -r1.19 VMDPinWidget.java --- graph/lib/src/org/netbeans/api/visual/vmd/VMDPinWidget.java 9 Mar 2007 16:41:57 -0000 1.19 +++ graph/lib/src/org/netbeans/api/visual/vmd/VMDPinWidget.java 12 Jun 2007 11:44:55 -0000 @@ -36,6 +36,8 @@ */ public class VMDPinWidget extends Widget { + private VMDColorScheme scheme; + private LabelWidget nameWidget; private VMDGlyphSetWidget glyphsWidget; private VMDNodeAnchor anchor; @@ -45,15 +47,24 @@ * @param scene the scene */ public VMDPinWidget (Scene scene) { + this (scene, VMDFactory.getOriginalScheme ()); + } + + /** + * Creates a pin widget with a specific color scheme. + * @param scene the scene + * @param scheme the color scheme + */ + public VMDPinWidget (Scene scene, VMDColorScheme scheme) { super (scene); + assert scheme != null; + this.scheme = scheme; - setBorder (VMDNodeWidget.BORDER); - setBackground (VMDNodeWidget.COLOR_SELECTED); - setOpaque (false); setLayout (LayoutFactory.createHorizontalFlowLayout (LayoutFactory.SerialAlignment.CENTER, 8)); addChild (nameWidget = new LabelWidget (scene)); addChild (glyphsWidget = new VMDGlyphSetWidget (scene)); + scheme.installUI (this); notifyStateChanged (ObjectState.createNormal (), ObjectState.createNormal ()); } @@ -63,11 +74,7 @@ * @param state the new state */ protected void notifyStateChanged (ObjectState previousState, ObjectState state) { - setOpaque (state.isSelected ()); - setBorder (state.isFocused () || state.isHovered () ? VMDNodeWidget.BORDER_HOVERED : VMDNodeWidget.BORDER); -// LookFeel lookFeel = getScene ().getLookFeel (); -// setBorder (BorderFactory.createCompositeBorder (BorderFactory.createEmptyBorder (8, 2), lookFeel.getMiniBorder (state))); -// setForeground (lookFeel.getForeground (state)); + scheme.updateUI (this, previousState, state); } /** Index: graph/lib/src/org/netbeans/api/visual/widget/ConnectionWidget.java =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/widget/ConnectionWidget.java,v retrieving revision 1.38 diff -u -r1.38 ConnectionWidget.java --- graph/lib/src/org/netbeans/api/visual/widget/ConnectionWidget.java 5 Jun 2007 08:41:01 -0000 1.38 +++ graph/lib/src/org/netbeans/api/visual/widget/ConnectionWidget.java 12 Jun 2007 11:44:55 -0000 @@ -328,6 +328,7 @@ * @param router the path router */ public final void setRouter (Router router) { + assert router != null; this.router = router; reroute (); } Index: graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html =================================================================== RCS file: /cvs/graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html,v retrieving revision 1.17 diff -u -r1.17 documentation.html --- graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 8 Jun 2007 08:45:02 -0000 1.17 +++ graph/lib/src/org/netbeans/api/visual/widget/doc-files/documentation.html 12 Jun 2007 11:44:55 -0000 @@ -2099,6 +2099,9 @@

The VMDGraphScene.layoutGraph method layouts nodes on a scene using GridGraphLayout class. After calling the method, you have to call Scene.validate method manually to trigger the scene validation and therefore graph-oriented layout of a scene. +

+The VMDColorScheme class defines a UI of VMD widgets. There are two implementations available using VMDFactory.createOriginalColorScheme, VMDFactory.createNetBeans60ColorScheme method calls. The color scheme can be used as a parameter in widget constructors. +

Minimize Ability

Index: graph/lib/src/org/netbeans/modules/visual/vmd/VMDNetBeans60ColorScheme.java =================================================================== RCS file: graph/lib/src/org/netbeans/modules/visual/vmd/VMDNetBeans60ColorScheme.java diff -N graph/lib/src/org/netbeans/modules/visual/vmd/VMDNetBeans60ColorScheme.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/modules/visual/vmd/VMDNetBeans60ColorScheme.java 12 Jun 2007 11:44:55 -0000 @@ -0,0 +1,124 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.modules.visual.vmd; + +import org.netbeans.api.visual.border.Border; +import org.netbeans.api.visual.border.BorderFactory; +import org.netbeans.api.visual.vmd.*; +import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.anchor.PointShape; + +import java.awt.*; + +/** + * @author David Kaspar + */ +public class VMDNetBeans60ColorScheme extends VMDColorScheme { + + public static final Color COLOR60_SELECT = new Color (0xFF8500); + public static final Color COLOR60_HOVER = new Color (0x5B67B0); + public static final Color COLOR60_HOVER_BACKGROUND = new Color (0xB0C3E1); + + private static final Border BORDER_MINIMIZE = BorderFactory.createRoundedBorder (2, 2, null, COLOR60_HOVER); + + private static final Border BORDER60 = VMDFactory.createVMDNodeBorder (VMDOriginalColorScheme.COLOR_NORMAL, 2, VMDOriginalColorScheme.COLOR1, VMDOriginalColorScheme.COLOR2, VMDOriginalColorScheme.COLOR3, VMDOriginalColorScheme.COLOR4, VMDOriginalColorScheme.COLOR5); + private static final Border BORDER60_SELECT = VMDFactory.createVMDNodeBorder (COLOR60_SELECT, 2, VMDOriginalColorScheme.COLOR1, VMDOriginalColorScheme.COLOR2, VMDOriginalColorScheme.COLOR3, VMDOriginalColorScheme.COLOR4, VMDOriginalColorScheme.COLOR5); + private static final Border BORDER60_HOVER = VMDFactory.createVMDNodeBorder (COLOR60_HOVER, 2, VMDOriginalColorScheme.COLOR1, VMDOriginalColorScheme.COLOR2, VMDOriginalColorScheme.COLOR3, VMDOriginalColorScheme.COLOR4, VMDOriginalColorScheme.COLOR5); + + private static final Border BORDER60_PIN_SELECT = BorderFactory.createCompositeBorder (BorderFactory.createLineBorder (0, 1, 0, 1, COLOR60_SELECT), BorderFactory.createLineBorder (2, 7, 2, 7, COLOR60_SELECT)); +// private static final Border BORDER60_PIN_HOVER = BorderFactory.createLineBorder (2, 8, 2, 8, COLOR60_HOVER); + + public void installUI (VMDNodeWidget widget) { + widget.setBorder (BORDER60); + + Widget header = widget.getHeader (); + header.setBackground (COLOR60_HOVER_BACKGROUND); + header.setBorder (VMDOriginalColorScheme.BORDER_PIN); + + Widget minimize = widget.getMinimizeButton (); + minimize.setBorder (BORDER_MINIMIZE); + + Widget pinsSeparator = widget.getPinsSeparator (); + pinsSeparator.setForeground (VMDOriginalColorScheme.BORDER_CATEGORY_BACKGROUND); + } + + public void updateUI (VMDNodeWidget widget, ObjectState previousState, ObjectState state) { + if (! previousState.isSelected () && state.isSelected ()) + widget.bringToFront (); + + widget.getHeader ().setOpaque (state.isHovered () || state.isFocused ()); + if (state.isSelected ()) + widget.setBorder (BORDER60_SELECT); + else if (state.isHovered ()) + widget.setBorder (BORDER60_HOVER); + else if (state.isFocused ()) + widget.setBorder (BORDER60_HOVER); + else + widget.setBorder (BORDER60); + } + + public void installUI (VMDConnectionWidget widget) { + widget.setSourceAnchorShape (AnchorShape.NONE); + widget.setTargetAnchorShape (AnchorShape.TRIANGLE_FILLED); + widget.setPaintControlPoints (true); + } + + public void updateUI (VMDConnectionWidget widget, ObjectState previousState, ObjectState state) { + if (state.isSelected ()) + widget.setForeground (COLOR60_SELECT); + else if (state.isHighlighted ()) + widget.setForeground (VMDOriginalColorScheme.COLOR_HIGHLIGHTED); + else if (state.isHovered () || state.isFocused ()) + widget.setForeground (COLOR60_HOVER); + else + widget.setForeground (VMDOriginalColorScheme.COLOR_NORMAL); + + if (state.isSelected () || state.isHovered ()) { + widget.setControlPointShape (PointShape.SQUARE_FILLED_SMALL); + widget.setEndPointShape (PointShape.SQUARE_FILLED_BIG); + } else { + widget.setControlPointShape (PointShape.NONE); + widget.setEndPointShape (VMDOriginalColorScheme.POINT_SHAPE_IMAGE); + } + } + + public void installUI (VMDPinWidget widget) { + widget.setBorder (VMDOriginalColorScheme.BORDER_PIN); + widget.setBackground (COLOR60_HOVER_BACKGROUND); + } + + public void updateUI (VMDPinWidget widget, ObjectState previousState, ObjectState state) { + widget.setOpaque (state.isHovered () || state.isFocused ()); + if (state.isSelected ()) + widget.setBorder (BORDER60_PIN_SELECT); + else + widget.setBorder (VMDOriginalColorScheme.BORDER_PIN); + } + + public boolean isNodeMinimizeButtonOnRight (VMDNodeWidget widget) { + return true; + } + + public Widget createPinCategoryWidget (VMDNodeWidget widget, String categoryDisplayName) { + return VMDFactory.getOriginalScheme ().createPinCategoryWidget (widget, categoryDisplayName); + } + +} Index: graph/lib/src/org/netbeans/modules/visual/vmd/VMDOriginalColorScheme.java =================================================================== RCS file: graph/lib/src/org/netbeans/modules/visual/vmd/VMDOriginalColorScheme.java diff -N graph/lib/src/org/netbeans/modules/visual/vmd/VMDOriginalColorScheme.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ graph/lib/src/org/netbeans/modules/visual/vmd/VMDOriginalColorScheme.java 12 Jun 2007 11:44:55 -0000 @@ -0,0 +1,151 @@ +/* + * The contents of this file are subject to the terms of the Common Development + * and Distribution License (the License). You may not use this file except in + * compliance with the License. + * + * You can obtain a copy of the License at http://www.netbeans.org/cddl.html + * or http://www.netbeans.org/cddl.txt. + * + * When distributing Covered Code, include this CDDL Header Notice in each file + * and include the License file at http://www.netbeans.org/cddl.txt. + * If applicable, add the following below the CDDL Header, with the fields + * enclosed by brackets [] replaced by your own identifying information: + * "Portions Copyrighted [year] [name of copyright owner]" + * + * The Original Software is NetBeans. The Initial Developer of the Original + * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.modules.visual.vmd; + +import org.netbeans.api.visual.border.Border; +import org.netbeans.api.visual.border.BorderFactory; +import org.netbeans.api.visual.model.ObjectState; +import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.widget.LabelWidget; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.anchor.AnchorShape; +import org.netbeans.api.visual.anchor.PointShape; +import org.netbeans.api.visual.anchor.PointShapeFactory; +import org.netbeans.api.visual.vmd.*; +import org.openide.util.Utilities; + +import java.awt.*; + +/** + * This class specifies look and feel of vmd widgets. There are predefined schemes in VMDFactory class. + * + * @author David Kaspar + */ +public class VMDOriginalColorScheme extends VMDColorScheme { + + static final Color COLOR_NORMAL = new Color (0xBACDF0); + private static final Color COLOR_HOVERED = Color.BLACK; + private static final Color COLOR_SELECTED = new Color (0x748CC0); + static final Color COLOR_HIGHLIGHTED = new Color (0x316AC5); + +// private static final Color COLOR0 = new Color (169, 197, 235); + static final Color COLOR1 = new Color (221, 235, 246); + static final Color COLOR2 = new Color (255, 255, 255); + static final Color COLOR3 = new Color (214, 235, 255); + static final Color COLOR4 = new Color (241, 249, 253); + static final Color COLOR5 = new Color (255, 255, 255); + + public static final Border BORDER_NODE = VMDFactory.createVMDNodeBorder (COLOR_NORMAL, 1, COLOR1, COLOR2, COLOR3, COLOR4, COLOR5); + + static final Color BORDER_CATEGORY_BACKGROUND = new Color (0xCDDDF8); + static final Border BORDER_MINIMIZE = BorderFactory.createRoundedBorder (2, 2, null, COLOR_NORMAL); + static final Border BORDER_PIN = BorderFactory.createOpaqueBorder (2, 8, 2, 8); + private static final Border BORDER_PIN_HOVERED = BorderFactory.createLineBorder (2, 8, 2, 8, Color.BLACK); + + static final PointShape POINT_SHAPE_IMAGE = PointShapeFactory.createImagePointShape (Utilities.loadImage ("org/netbeans/modules/visual/resources/vmd-pin.png")); // NOI18N + + public VMDOriginalColorScheme () { + } + + public void installUI (VMDNodeWidget widget) { + widget.setBorder (VMDFactory.createVMDNodeBorder ()); + widget.setOpaque (false); + + Widget header = widget.getHeader (); + header.setBorder (BORDER_PIN); + header.setBackground (COLOR_SELECTED); + header.setOpaque (false); + + Widget minimize = widget.getMinimizeButton (); + minimize.setBorder (BORDER_MINIMIZE); + + Widget pinsSeparator = widget.getPinsSeparator (); + pinsSeparator.setForeground (BORDER_CATEGORY_BACKGROUND); + } + + public void updateUI (VMDNodeWidget widget, ObjectState previousState, ObjectState state) { + if (! previousState.isSelected () && state.isSelected ()) + widget.bringToFront (); + else if (! previousState.isHovered () && state.isHovered ()) + widget.bringToFront (); + + Widget header = widget.getHeader (); + header.setOpaque (state.isSelected ()); + header.setBorder (state.isFocused () || state.isHovered () ? BORDER_PIN_HOVERED : BORDER_PIN); + } + + public boolean isNodeMinimizeButtonOnRight (VMDNodeWidget widget) { + return false; + } + + public Widget createPinCategoryWidget (VMDNodeWidget widget, String categoryDisplayName) { + Scene scene = widget.getScene (); + LabelWidget label = new LabelWidget (scene, categoryDisplayName); + label.setOpaque (true); + label.setBackground (BORDER_CATEGORY_BACKGROUND); + label.setForeground (Color.GRAY); + Font fontPinCategory = scene.getDefaultFont ().deriveFont (10.0f); + label.setFont (fontPinCategory); + label.setAlignment (LabelWidget.Alignment.CENTER); + label.setCheckClipping (true); + return label; + } + + public void installUI (VMDConnectionWidget widget) { + widget.setSourceAnchorShape (AnchorShape.NONE); + widget.setTargetAnchorShape (AnchorShape.TRIANGLE_FILLED); + widget.setPaintControlPoints (true); + } + + public void updateUI (VMDConnectionWidget widget, ObjectState previousState, ObjectState state) { + if (state.isHovered ()) + widget.setForeground (COLOR_HOVERED); + else if (state.isSelected ()) + widget.setForeground (COLOR_SELECTED); + else if (state.isHighlighted ()) + widget.setForeground (COLOR_HIGHLIGHTED); + else if (state.isFocused ()) + widget.setForeground (COLOR_HOVERED); + else + widget.setForeground (COLOR_NORMAL); + + if (state.isSelected ()) { + widget.setControlPointShape (PointShape.SQUARE_FILLED_SMALL); + widget.setEndPointShape (PointShape.SQUARE_FILLED_BIG); + } else { + widget.setControlPointShape (PointShape.NONE); + widget.setEndPointShape (POINT_SHAPE_IMAGE); + } + } + + public void installUI (VMDPinWidget widget) { + widget.setBorder (BORDER_PIN); + widget.setBackground (COLOR_SELECTED); + widget.setOpaque (false); + } + + public void updateUI (VMDPinWidget widget, ObjectState previousState, ObjectState state) { + widget.setOpaque (state.isSelected ()); + widget.setBorder (state.isFocused () || state.isHovered () ? BORDER_PIN_HOVERED : BORDER_PIN); +// LookFeel lookFeel = getScene ().getLookFeel (); +// setBorder (BorderFactory.createCompositeBorder (BorderFactory.createEmptyBorder (8, 2), lookFeel.getMiniBorder (state))); +// setForeground (lookFeel.getForeground (state)); + } + +} Index: graph/www/documentation.html =================================================================== RCS file: /cvs/graph/www/documentation.html,v retrieving revision 1.91 diff -u -r1.91 documentation.html --- graph/www/documentation.html 8 Jun 2007 08:45:03 -0000 1.91 +++ graph/www/documentation.html 12 Jun 2007 11:44:55 -0000 @@ -177,6 +177,7 @@

  • test.visible.NotifyAddedRemovedTest - test of Widget.notifyAdded and Widget.notifyRemoved methods
  • test.visible.VisibilityTest - compatibility test of Layout implementations with Widget.visible property
  • test.vmd.VMDCollisionTest - test of WidgetCollisionCollector +
  • test.vmd.VMDColorSchemeTest - how to use VMDColorScheme
  • test.vmd.VMDTest - how to use VMD plug-in
  • test.widget.AnimatedImageTest - test of animated image in ImageWidget
  • test.zoom.CenteredZoomTest - how to use CenteredZoomAction