示例#1
0
  public static void main(String[] args) {
    final Scene scene = new Scene();
    scene.setBorder(BorderFactory.createEmptyBorder(10));
    scene.setLayout(
        LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.JUSTIFY, 10));

    JTextField textField =
        new JTextField(
            "Text for editing - try to edit me. When the JTextField component is hidden, then the Widget just renders it.");
    final ComponentWidget textFieldWidget = new ComponentWidget(scene, textField);

    JToggleButton button =
        new JToggleButton(
            "Click to hide/show JTextField component bellow. The ComponentWidget is still in the scene and rendered.");
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            textFieldWidget.setComponentVisible(!textFieldWidget.isComponentVisible());
            scene.validate();
          }
        });

    scene.addChild(new ComponentWidget(scene, button));
    scene.addChild(textFieldWidget);

    SeparatorWidget separator = new SeparatorWidget(scene, SeparatorWidget.Orientation.HORIZONTAL);
    scene.addChild(separator);

    JTextField textField2 = new JTextField("Text for editing - try to edit me.");
    final ComponentWidget textFieldWidget2 = new ComponentWidget(scene, textField2);

    JToggleButton button2 =
        new JToggleButton("Click to remove/add ComponentWidget from/to the scene.");
    button2.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            if (textFieldWidget2.getParentWidget() != null) scene.removeChild(textFieldWidget2);
            else scene.addChild(textFieldWidget2);
            scene.validate();
          }
        });

    scene.addChild(new ComponentWidget(scene, button2));
    scene.addChild(textFieldWidget2);

    SceneSupport.show(scene);
    // TODO - call detach method on all ComponentWidget to prevent memory leaks
  }
示例#2
0
  public ProxyAnchorExpandTest() {
    setBackground(Color.LIGHT_GRAY);

    // layer for widgets
    LayerWidget mainLayer = new LayerWidget(this);
    addChild(mainLayer);
    // layer for connections
    LayerWidget connLayer = new LayerWidget(this);
    addChild(connLayer);

    // outer widget
    Widget outerWidget = new Widget(this);
    outerWidget.setOpaque(true);
    outerWidget.setBackground(Color.WHITE);
    outerWidget.setBorder(BorderFactory.createLineBorder(10));
    outerWidget.setPreferredLocation(new Point(100, 100));
    outerWidget.setLayout(
        LayoutFactory.createVerticalFlowLayout(LayoutFactory.SerialAlignment.CENTER, 4));

    outerWidget.addChild(
        new LabelWidget(
            this, "The anchor switches based on a state in StateModel used by ProxyAnchor."));
    outerWidget.addChild(
        new LabelWidget(this, "ConnectionWidget has the same anchors assigned all the time."));

    // inner widget
    LabelWidget innerWidget = new LabelWidget(this, "Internal frame");
    innerWidget.setBorder(BorderFactory.createLineBorder());
    outerWidget.addChild(innerWidget);

    mainLayer.addChild(outerWidget);

    // the target widget
    Widget targetWidget =
        new LabelWidget(this, "Click here to switch the state in StateModel/anchor.");
    targetWidget.setOpaque(true);
    targetWidget.setBackground(Color.WHITE);
    targetWidget.setBorder(BorderFactory.createLineBorder(10));
    targetWidget.setPreferredLocation(new Point(450, 300));
    mainLayer.addChild(targetWidget);

    // an action for switching a state of a StateModel used by the ProxyAnchor to determinate an
    // active anchor
    WidgetAction switchAction = ActionFactory.createSelectAction(new SwitchProvider());
    targetWidget.getActions().addAction(switchAction);

    Anchor outerAnchor = AnchorFactory.createRectangularAnchor(outerWidget);
    Anchor innerAnchor = AnchorFactory.createRectangularAnchor(innerWidget);

    // a proxy anchor which acts like an one of the specified anchors.
    // The active anchor is defined by a state in the StateModel
    Anchor proxyAnchor = AnchorFactory.createProxyAnchor(model, outerAnchor, innerAnchor);

    // the connection widget
    ConnectionWidget conn = new ConnectionWidget(this);
    conn.setTargetAnchorShape(AnchorShape.TRIANGLE_FILLED);
    connLayer.addChild(conn);

    // the proxy anchor is used as a source
    conn.setSourceAnchor(proxyAnchor);
    // the target anchor is assigned to the targetWidget widget
    conn.setTargetAnchor(AnchorFactory.createRectangularAnchor(targetWidget));
  }