Added
Link Here
|
1 |
package test.inplace; |
2 |
|
3 |
import org.netbeans.api.visual.action.ActionFactory; |
4 |
import org.netbeans.api.visual.action.InplaceEditorProvider; |
5 |
import org.netbeans.api.visual.action.TextFieldInplaceEditor; |
6 |
import org.netbeans.api.visual.action.WidgetAction; |
7 |
import org.netbeans.api.visual.layout.LayoutFactory; |
8 |
import org.netbeans.api.visual.widget.ComponentWidget; |
9 |
import org.netbeans.api.visual.widget.LabelWidget; |
10 |
import org.netbeans.api.visual.widget.Scene; |
11 |
import org.netbeans.api.visual.widget.Widget; |
12 |
import test.SceneSupport; |
13 |
|
14 |
import javax.swing.*; |
15 |
import java.awt.event.ActionEvent; |
16 |
import java.awt.event.ActionListener; |
17 |
|
18 |
/** |
19 |
* @author David Kaspar |
20 |
*/ |
21 |
public class TypedInplaceEditorTest { |
22 |
|
23 |
public static void main (String[] args) { |
24 |
final Scene scene = new Scene (); |
25 |
scene.setBorder (BorderFactory.createEmptyBorder (8, 8, 8, 8)); |
26 |
scene.setLayout (LayoutFactory.createVerticalFlowLayout (LayoutFactory.SerialAlignment.LEFT_TOP, 8)); |
27 |
|
28 |
final LabelWidget label = new LabelWidget (scene, "Double-click or press Enter to invoke in-place editor"); |
29 |
final WidgetAction[] inplaceEditorAction = new WidgetAction[1]; |
30 |
inplaceEditorAction[0] = ActionFactory.createInplaceEditorAction (new TextFieldInplaceEditor() { |
31 |
public boolean isEnabled (Widget widget) { |
32 |
InplaceEditorProvider.EditorController editorController = ActionFactory.getInplaceEditorController (inplaceEditorAction[0]); |
33 |
InplaceEditorProvider.EditorInvocationType type = ((InplaceEditorProvider.TypedEditorController) editorController).getEditorInvocationType (); |
34 |
JOptionPane.showMessageDialog (scene.getView (), "Inplace editor is Invoked by " + type.name ()); |
35 |
return true; |
36 |
} |
37 |
public String getText (Widget widget) { |
38 |
return ((LabelWidget) widget).getLabel (); |
39 |
} |
40 |
|
41 |
public void setText (Widget widget, String text) { |
42 |
((LabelWidget) widget).setLabel (text); |
43 |
} |
44 |
}); |
45 |
label.getActions ().addAction (inplaceEditorAction[0]); |
46 |
scene.addChild (label); |
47 |
|
48 |
JButton button = new JButton ("Press this button to invoke the in-place editor for the label above"); |
49 |
button.addActionListener (new ActionListener() { |
50 |
public void actionPerformed (ActionEvent e) { |
51 |
InplaceEditorProvider.EditorController inplaceEditorController = ActionFactory.getInplaceEditorController (inplaceEditorAction[0]); |
52 |
inplaceEditorController.openEditor (label); |
53 |
} |
54 |
}); |
55 |
scene.addChild (new ComponentWidget (scene, button)); |
56 |
|
57 |
SceneSupport.show (scene); |
58 |
} |
59 |
|
60 |
} |