org.netbeans.api.visual.widget.Scene Java Examples

The following examples show how to use org.netbeans.api.visual.widget.Scene. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectionWidgetCollisionsCollectorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCollisionsCollector () {
    Scene scene = new Scene ();

    ConnectionWidget widget = new ConnectionWidget (scene);
    widget.setSourceAnchor (AnchorFactory.createFixedAnchor (new Point (100, 100)));
    widget.setTargetAnchor (AnchorFactory.createFixedAnchor (new Point (300, 200)));
    widget.setRouter (RouterFactory.createOrthogonalSearchRouter (new CollisionsCollector() {
        public void collectCollisions (List<Rectangle> verticalCollisions, List<Rectangle> horizontalCollisions) {
            getRef ().println ("CollisionsCollector invoked");
        }
    }));
    scene.addChild (widget);

    JFrame frame = showFrame (scene);
    frame.setVisible(false);
    frame.dispose ();
    
    compareReferenceFiles ();
}
 
Example #2
Source File: LayerWidget103528Test.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testLayerPreferredLocation () {
    Scene scene = new Scene ();

    scene.addChild (new LayerWidget (scene));

    LayerWidget layer = new LayerWidget (scene);
    layer.setPreferredLocation (new Point (100, 100));
    scene.addChild (layer);

    Widget widget = new Widget (scene);
    widget.setPreferredBounds (new Rectangle (-20, -10, 100, 50));
    widget.setOpaque (true);
    widget.setBackground (Color.RED);
    layer.addChild (widget);

    Color color = (Color) (new DefaultLookFeel()).getBackground();
    assertScene (scene, color, new Rectangle (80, 90, 100, 50));
}
 
Example #3
Source File: ZoomManager.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void actionPerformed(ActionEvent e) {
    Scene scene = manager.getScene();
    JScrollPane pane = (JScrollPane) SwingUtilities.getAncestorOfClass(
            JScrollPane.class, scene.getView());
    if (pane == null) {
        // Unlikely, but we cannot assume it exists.
        return;
    }
    JViewport viewport = pane.getViewport();
    Rectangle visRect = viewport.getViewRect();
    Rectangle compRect = scene.getPreferredBounds();
    int zoomX = visRect.width * 100 / compRect.width;
    int zoomY = visRect.height * 100 / compRect.height;
    int zoom = Math.min(zoomX, zoomY);
    manager.setZoom(zoom);
}
 
Example #4
Source File: DiagramConnectionWidget.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/** Creates a new instance of ConnectionWidget */
public DiagramConnectionWidget(Connection connection, Scene scene) {
    super(scene);
    this.connection = connection;
    color = connection.getColor();
    if (connection.getStyle() == Connection.ConnectionStyle.DASHED) {
        this.setStroke(DASHED_STROKE);
    } else if (connection.getStyle() == Connection.ConnectionStyle.BOLD) {
        this.setStroke(BOLD_STROKE);
    } else {
        this.setStroke(NORMAL_STROKE);
    }
    this.setCheckClipping(true);
    clientArea = new Rectangle();
    updateControlPoints();
}
 
Example #5
Source File: DiagramConnectionWidget.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/** Creates a new instance of ConnectionWidget */
public DiagramConnectionWidget(Connection connection, Scene scene) {
    super(scene);
    this.connection = connection;
    color = connection.getColor();
    if (connection.getStyle() == Connection.ConnectionStyle.DASHED) {
        this.setStroke(DASHED_STROKE);
    } else if (connection.getStyle() == Connection.ConnectionStyle.BOLD) {
        this.setStroke(BOLD_STROKE);
    } else {
        this.setStroke(NORMAL_STROKE);
    }
    this.setCheckClipping(true);
    clientArea = new Rectangle();
    updateControlPoints();
}
 
Example #6
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Shows given Scene wrapped in TopComponent and JFrame.
 * @param scene Scene to be shown
 * @return TopComponent instance where scene resides
 */
public static TopComponent showScene(Scene scene) {
    JComponent sceneView = scene.getView();
    if (sceneView == null) {
        sceneView = scene.createView();
    }
    int width = 450, height = 250;
    JFrame frame = new JFrame("Test Scene");
    TopComponent tc = new TopComponent();
    tc.setLayout(new BorderLayout());
    tc.add(sceneView);
    frame.add(tc);
    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    frame.setBounds((screenSize.width - width) / 2, (screenSize.height - height) / 2, width, height);
    frame.setVisible(true);
    return tc;
}
 
Example #7
Source File: ConnectionWidgetCollisionsCollectorTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testConnectionWidgetCollisionsCollector () {
    Scene scene = new Scene ();

    final ConnectionWidget widget = new ConnectionWidget (scene);
    widget.setSourceAnchor (AnchorFactory.createFixedAnchor (new Point (100, 100)));
    widget.setTargetAnchor (AnchorFactory.createFixedAnchor (new Point (300, 200)));
    widget.setRouter (RouterFactory.createOrthogonalSearchRouter (new ConnectionWidgetCollisionsCollector () {
        public void collectCollisions (ConnectionWidget connectionWidget, List<Rectangle> verticalCollisions, List<Rectangle> horizontalCollisions) {
            getRef ().println ("ConnectionWidgetCollisionsCollector invoked - is widget valid: " + (connectionWidget == widget));
        }
    }));
    scene.addChild (widget);

    JFrame frame = showFrame (scene);
    frame.setVisible(false);
    frame.dispose ();

    compareReferenceFiles ();
}
 
Example #8
Source File: OffscreenRenderingTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testOffscreenRendering () {
    Scene scene = new Scene ();

    LayerWidget layer = new LayerWidget (scene);
    layer.setPreferredBounds (new Rectangle (0, 0, 80, 80));
    scene.addChild (layer);

    LabelWidget widget = new LabelWidget (scene, "Hi");
    widget.setVerticalAlignment (LabelWidget.VerticalAlignment.CENTER);
    widget.setAlignment (LabelWidget.Alignment.CENTER);
    widget.setBorder (BorderFactory.createLineBorder ());
    widget.setPreferredLocation (new Point (20, 20));
    widget.setPreferredBounds (new Rectangle (0, 0, 40, 40));
    layer.addChild (widget);

    BufferedImage image = dumpSceneOffscreenRendering (scene);
    Color backgroundColor = (Color) (new DefaultLookFeel()).getBackground();
    Color foregroundColor = (new DefaultLookFeel()).getForeground();
    assertCleaness (testCleaness (image, backgroundColor, foregroundColor), image, null);

    assertScene (scene, backgroundColor, new Rectangle (19, 19, 42, 42));
}
 
Example #9
Source File: DiagramConnectionWidget.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/** Creates a new instance of ConnectionWidget */
public DiagramConnectionWidget(Connection connection, Scene scene) {
    super(scene);
    this.connection = connection;
    color = connection.getColor();
    if (connection.getStyle() == Connection.ConnectionStyle.DASHED) {
        this.setStroke(DASHED_STROKE);
    } else if (connection.getStyle() == Connection.ConnectionStyle.BOLD) {
        this.setStroke(BOLD_STROKE);
    } else {
        this.setStroke(NORMAL_STROKE);
    }
    this.setCheckClipping(true);
    clientArea = new Rectangle();
    updateControlPoints();
}
 
Example #10
Source File: DiagramConnectionWidget.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/** Creates a new instance of ConnectionWidget */
public DiagramConnectionWidget(Connection connection, Scene scene) {
    super(scene);
    this.connection = connection;
    color = connection.getColor();
    if (connection.getStyle() == Connection.ConnectionStyle.DASHED) {
        this.setStroke(DASHED_STROKE);
    } else if (connection.getStyle() == Connection.ConnectionStyle.BOLD) {
        this.setStroke(BOLD_STROKE);
    } else {
        this.setStroke(NORMAL_STROKE);
    }
    this.setCheckClipping(true);
    clientArea = new Rectangle();
    updateControlPoints();
}
 
Example #11
Source File: VisualTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Takes a snapshot of a scene. This method assumes that the scene view is already shown on the screen
 * and therefore the scene is initialized correctly.
 * @param scene the scene
 * @return the snapshot
 */
public BufferedImage takeSnapshot (Scene scene) {
    assert scene != null;
    Dimension viewSize = scene.getView().getSize();
    assert viewSize.width >= 0  &&  viewSize.height >= 0;
    return takeSnapshot (scene, viewSize.width, viewSize.height);
}
 
Example #12
Source File: FlowLayoutWeightOverflow108052Test.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testFlowLayoutWeightOverflow () {
    Scene scene = new Scene ();
    LayerWidget layer = new LayerWidget (scene);
    layer.setMinimumSize (new Dimension (300, 200));
    scene.addChild (layer);

    Widget vbox = new Widget (scene);
    vbox.setBorder (BorderFactory.createLineBorder (1, Color.BLACK));
    vbox.setLayout (LayoutFactory.createVerticalFlowLayout (LayoutFactory.SerialAlignment.JUSTIFY, 0));
    layer.addChild (vbox);

    Widget hbox1 = new Widget (scene);
    hbox1.setBorder (BorderFactory.createLineBorder (1, Color.BLUE));
    hbox1.setLayout (LayoutFactory.createHorizontalFlowLayout ());
    vbox.addChild (hbox1);

    Widget item1 = new LabelWidget (scene, "Item1");
    item1.setBorder (BorderFactory.createLineBorder (1, Color.GREEN));
    hbox1.addChild (item1);

    Widget item2 = new LabelWidget (scene, "Item2");
    item2.setBorder (BorderFactory.createLineBorder (1, Color.YELLOW));
    hbox1.addChild (item2, 1000);

    Widget item3 = new LabelWidget (scene, "Item3");
    item3.setBorder (BorderFactory.createLineBorder (1, Color.RED));
    hbox1.addChild (item3);

    Widget hbox2 = new Widget (scene);
    hbox2.setBorder (BorderFactory.createLineBorder (1, Color.BLUE));
    hbox2.setPreferredSize (new Dimension (200, 20));
    vbox.addChild (hbox2);
    
    Color color = (Color) (new DefaultLookFeel()).getBackground();
    assertScene (scene, color, new Rectangle (-5, -5, 210, 100));
}
 
Example #13
Source File: VisualTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Takes a snapshot of a scene. This method assumes that the scene view is already shown on the screen
 * and therefore the scene is initialized correctly.
 * @param scene the scene
 * @param width the snapshot width
 * @param height the snapshot height
 * @return the snapshot
 */
public BufferedImage takeSnapshot (Scene scene, int width, int height) {
    assert scene != null;
    BufferedImage snapshot = new BufferedImage (width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D snapshotGraphics = snapshot.createGraphics();
    scene.paint(snapshotGraphics);
    snapshotGraphics.dispose ();
    return snapshot;
}
 
Example #14
Source File: CheckBoxWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param scene
 * @param text
 */
public CheckBoxWidget(Scene scene, String text) {
    super(scene, null, text);
    setImage(new UncheckedImageWidget(scene, 8));
    setSelectedImage(new CheckedImageWidget(scene, 8));
    setBorder(BorderFactory.createEmptyBorder(1));
}
 
Example #15
Source File: VisualTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Takes a one-time snapshot. Similar to takeSnapshot method but it automatically creates and disposes a frame for it.
 * @param scene the scene
 * @return the snapshot
 */
public BufferedImage takeOneTimeSnapshot (Scene scene) {
    JFrame frame = showFrame (scene);
    BufferedImage snapshot = takeSnapshot (scene);
    assert scene != null;
    frame.setVisible(false);
    frame.dispose ();
    return snapshot;
}
 
Example #16
Source File: BasicTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testShow () {
    Scene scene = new Scene ();
    
    LayerWidget mainLayer = new LayerWidget (scene);
    scene.addChild(mainLayer);
    
    Widget w1 = new Widget (scene);
    w1.setBorder (BorderFactory.createLineBorder ());
    w1.setPreferredLocation (new Point (100, 100));
    w1.setPreferredSize (new Dimension (40, 20));
    mainLayer.addChild(w1);
    
    Widget w2 = new Widget (scene);
    w2.setBorder (BorderFactory.createLineBorder ());
    w2.setPreferredLocation (new Point (200, 100));
    w2.setPreferredSize (new Dimension (40, 20));
    mainLayer.addChild(w2);
    
    LayerWidget connLayer = new LayerWidget (scene);
    scene.addChild(connLayer);
    
    ConnectionWidget conn = new ConnectionWidget(scene);
    conn.setSourceAnchor(AnchorFactory.createRectangularAnchor(w1));
    conn.setTargetAnchor(AnchorFactory.createRectangularAnchor(w2));
    connLayer.addChild(conn);
    
    Color color = (Color) (new DefaultLookFeel()).getBackground();
    assertScene (scene, color,
            new Rectangle (99, 99, 42, 22),
            new Rectangle (199, 99, 42, 22),
            new Rectangle (138, 108, 64, 4)
    );
}
 
Example #17
Source File: VisualTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Takes a one-time snapshot. Similar to takeSnapshot method but it automatically creates and disposes a frame for it.
 * @param scene the scene
 * @param width the scene width
 * @param height the scene height
 * @return the snapshot
 */
public BufferedImage takeOneTimeSnapshot (Scene scene, int width, int height) {
    JFrame frame = showFrame (scene, width, height);
    BufferedImage snapshot = takeSnapshot (scene, width, height);
    assert scene != null;
    frame.setVisible(false);
    frame.dispose ();
    return snapshot;
}
 
Example #18
Source File: AnchorNotificationTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testNotify () {
    StringBuffer log = new StringBuffer ();
    Scene scene = new Scene ();

    Widget w = new Widget (scene);
    scene.addChild (w);

    ConnectionWidget c = new ConnectionWidget (scene);
    scene.addChild (c);
    TestAnchor testAnchor = new TestAnchor (w, log);
    c.setSourceAnchor (testAnchor);
    c.setTargetAnchor (testAnchor);

    JFrame frame = showFrame (scene);

    c.setSourceAnchor (null);
    c.setTargetAnchor (null);
    scene.validate ();

    frame.setVisible (false);
    frame.dispose ();

    assertEquals (log.toString (),
            "notifyEntryAdded\n" +
            "notifyUsed\n" +
            "notifyRevalidate\n" +
            "notifyEntryAdded\n" +
            "notifyRevalidate\n" +
            "notifyRevalidate\n" +
            "compute\n" +
            "compute\n" +
            "notifyEntryRemoved\n" +
            "notifyRevalidate\n" +
            "notifyEntryRemoved\n" +
            "notifyUnused\n" +
            "notifyRevalidate\n"
            );
}
 
Example #19
Source File: ExtendedSatelliteComponent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public ExtendedSatelliteComponent(Scene scene) {
    this.scene = scene;
    setDoubleBuffered(true);
    setPreferredSize(new Dimension(128, 128));
    addMouseListener(this);
    addMouseMotionListener(this);
}
 
Example #20
Source File: BlockWidget.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public BlockWidget(Scene scene, Diagram d, InputBlock blockNode) {
    super(scene);
    this.blockNode = blockNode;
    this.diagram = d;
    this.setBackground(BACKGROUND_COLOR);
    this.setOpaque(true);
    this.setCheckClipping(true);
}
 
Example #21
Source File: ButtonWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param scene
 * @param icon
 * @param text
 */
public ButtonWidget(Scene scene, Image image, String text) {
    super(scene, image ,text);
    setRoundedBorder(BORDER_RADIUS,0,0,null);
    getActions().addAction(ActionFactory.createSelectAction(ButtonSelectProvider.DEFAULT));
    getActions().addAction(scene.createWidgetHoverAction());
}
 
Example #22
Source File: ListItemWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a list item widget.
 * @param scene the scene
 */
public ListItemWidget (Scene scene) {
    super (scene);
    GeomUtil.LOG.warning ("org.netbeans.api.visual.widget.general.ListItemWidget class is deprecated. Use org.netbeans.modules.visual.experimental.widget.general.ListItemWidget class instead. Since it is an experimental class outside of public-API packages, you have to set an implementation dependency on the org.netbeans.api.visual module."); // NOI18N

    setState (ObjectState.createNormal ());
}
 
Example #23
Source File: VmdSceneGeneratorHelper.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Scene createScene(Dependency dependency) {
    VMDGraphScene scene = new VMDGraphScene();
    IVmdSceneGenerator generator = getGenerator(dependency);
    generator.populateScene(scene);
    scene.layoutScene();
    return scene;
}
 
Example #24
Source File: GraphColorScheme.java    From Llunatic with GNU General Public License v3.0 5 votes vote down vote up
static Widget createPinCategoryWidgetCore(VMDNodeWidget widget, String categoryDisplayName, boolean changeFont) {
    Scene scene = widget.getScene();
    LabelWidget label = new LabelWidget(scene, categoryDisplayName);
    label.setOpaque(true);
    label.setBackground(BORDER_CATEGORY_BACKGROUND);
    label.setForeground(Color.GRAY);
    if (changeFont) {
        Font fontPinCategory = scene.getDefaultFont().deriveFont(10.0f);
        label.setFont(fontPinCategory);
    }
    label.setAlignment(LabelWidget.Alignment.CENTER);
    label.setCheckClipping(true);
    return label;
}
 
Example #25
Source File: ExtendedSatelliteComponent.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public ExtendedSatelliteComponent(Scene scene) {
    this.scene = scene;
    setDoubleBuffered(true);
    setPreferredSize(new Dimension(128, 128));
    addMouseListener(this);
    addMouseMotionListener(this);
}
 
Example #26
Source File: BlockWidget.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public BlockWidget(Scene scene, Diagram d, InputBlock blockNode) {
    super(scene);
    this.blockNode = blockNode;
    this.diagram = d;
    this.setBackground(BACKGROUND_COLOR);
    this.setOpaque(true);
    this.setCheckClipping(true);
}
 
Example #27
Source File: VMDPinWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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;

    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 ());
}
 
Example #28
Source File: ExpanderWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of ExpanderWidget.
 *
 * @param  scene       the Scene to contain this widget.
 * @param  expandable  the expandable widget this expander will control.
 * @param  expanded    true if widget is initially expanded, false if collapsed.
 */
public ExpanderWidget(Scene scene, ExpandableWidget expandable, boolean expanded) {
    super(scene, (String) null);
    this.expandable = expandable;
    setImage(new ExpanderImageWidget(scene, true, 8, 30));
    setSelectedImage(new ExpanderImageWidget(scene, false, 8, 30));
    setSelected(expanded);
    setRoundedBorder(0, 4, 4, null);
    setAction(new AbstractAction() {

        public void actionPerformed(ActionEvent arg0) {
            ExpanderWidget.this.expandable.setExpanded(!ExpanderWidget.this.expandable.isExpanded());
        }
    });
}
 
Example #29
Source File: VMDConnectionWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
    assert scheme != null;
    this.scheme = scheme;
    scheme.installUI (this);
    setState (ObjectState.createNormal ());
}
 
Example #30
Source File: ButtonWidget.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
protected void notifyRemoved() {
    super.notifyRemoved();
    Scene scene = getScene();
    if(scene instanceof ObjectScene) {
        ((ObjectScene)scene).removeObject(hashKey());
    }
}