private LabelWidget createEdgeLabel(Edge edge) { LabelWidget label = new LabelWidget(this, edge.toString()); label.setFont(Util.FIXED_WIDTH_FONT); label.setBorder(BorderFactory.createEmptyBorder(0, 0, 2, 0)); label.getActions().addAction(hoverAction); label.getActions().addAction(editAction); label.getActions().addAction(moveAction); label.getActions().addAction(edgePopupAction); return label; }
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 }