Beispiel #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
  }
Beispiel #2
0
  public static void main(String[] args) {
    final Scene scene = new Scene();

    LayerWidget layer = new LayerWidget(scene);
    scene.addChild(layer);

    Widget nodeWidget = new Widget(scene);
    nodeWidget.setBorder(BorderFactory.createLineBorder(1, Color.RED));
    nodeWidget.setPreferredLocation(new Point(100, 100));
    layer.addChild(nodeWidget);

    final Widget deferredWidget = new Widget(scene);
    deferredWidget.setLayout(LayoutFactory.createCardLayout(deferredWidget));
    deferredWidget.setBorder(BorderFactory.createLineBorder(1, Color.BLUE));
    nodeWidget.addChild(deferredWidget);

    final Widget label = new LabelWidget(scene, "Click me to add ComponentWidget");
    label.setBorder(BorderFactory.createLineBorder(1, Color.GREEN));
    deferredWidget.addChild(label);
    LayoutFactory.setActiveCard(deferredWidget, label);

    label
        .getActions()
        .addAction(
            ActionFactory.createEditAction(
                new EditProvider() {
                  public void edit(Widget widget) {
                    ComponentWidget component =
                        new ComponentWidget(scene, new JButton("This is the new ComponentWidget"));
                    component.setBorder(BorderFactory.createLineBorder(1, Color.GREEN));
                    deferredWidget.addChild(component);
                    LayoutFactory.setActiveCard(deferredWidget, component);
                  }
                }));

    scene
        .getActions()
        .addAction(
            ActionFactory.createEditAction(
                new EditProvider() {
                  public void edit(Widget widget) {
                    LayoutFactory.setActiveCard(deferredWidget, label);
                  }
                }));

    // to force the boundary
    //        nodeWidget.setPreferredBounds (new Rectangle (0, 0, 70, 30));
    //        nodeWidget.setPreferredSize (new Dimension (70, 30));
    nodeWidget.setLayout(LayoutFactory.createOverlayLayout());
    nodeWidget.setCheckClipping(true);
    //

    SceneSupport.show(scene);
  }