diff -r 5a000c71af9b visual.examples/src/test/inplace/TypedInplaceEditorTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/visual.examples/src/test/inplace/TypedInplaceEditorTest.java Mon Aug 18 11:00:49 2008 +0200 @@ -0,0 +1,60 @@ +package test.inplace; + +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.InplaceEditorProvider; +import org.netbeans.api.visual.action.TextFieldInplaceEditor; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.layout.LayoutFactory; +import org.netbeans.api.visual.widget.ComponentWidget; +import org.netbeans.api.visual.widget.LabelWidget; +import org.netbeans.api.visual.widget.Scene; +import org.netbeans.api.visual.widget.Widget; +import test.SceneSupport; + +import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +/** + * @author David Kaspar + */ +public class TypedInplaceEditorTest { + + public static void main (String[] args) { + final Scene scene = new Scene (); + scene.setBorder (BorderFactory.createEmptyBorder (8, 8, 8, 8)); + scene.setLayout (LayoutFactory.createVerticalFlowLayout (LayoutFactory.SerialAlignment.LEFT_TOP, 8)); + + final LabelWidget label = new LabelWidget (scene, "Double-click or press Enter to invoke in-place editor"); + final WidgetAction[] inplaceEditorAction = new WidgetAction[1]; + inplaceEditorAction[0] = ActionFactory.createInplaceEditorAction (new TextFieldInplaceEditor() { + public boolean isEnabled (Widget widget) { + InplaceEditorProvider.EditorController editorController = ActionFactory.getInplaceEditorController (inplaceEditorAction[0]); + InplaceEditorProvider.EditorInvocationType type = ((InplaceEditorProvider.TypedEditorController) editorController).getEditorInvocationType (); + JOptionPane.showMessageDialog (scene.getView (), "Inplace editor is Invoked by " + type.name ()); + return true; + } + public String getText (Widget widget) { + return ((LabelWidget) widget).getLabel (); + } + + public void setText (Widget widget, String text) { + ((LabelWidget) widget).setLabel (text); + } + }); + label.getActions ().addAction (inplaceEditorAction[0]); + scene.addChild (label); + + JButton button = new JButton ("Press this button to invoke the in-place editor for the label above"); + button.addActionListener (new ActionListener() { + public void actionPerformed (ActionEvent e) { + InplaceEditorProvider.EditorController inplaceEditorController = ActionFactory.getInplaceEditorController (inplaceEditorAction[0]); + inplaceEditorController.openEditor (label); + } + }); + scene.addChild (new ComponentWidget (scene, button)); + + SceneSupport.show (scene); + } + +}