01: package net.xoetrope.builder.editor.helper;
02:
03: import javax.swing.text.BadLocationException;
04:
05: import net.xoetrope.builder.editor.XSourceEditor;
06: import net.xoetrope.xui.XProjectManager;
07: import java.util.Vector;
08: import java.awt.event.KeyEvent;
09: import java.util.ArrayList;
10: import net.xoetrope.xui.XProject;
11: import net.xoetrope.builder.editor.XEditorProject;
12: import net.xoetrope.builder.editor.XPageResource;
13:
14: /**
15: * A code helper for inserting of page event handlers
16: * <p> Copyright (c) Xoetrope Ltd., 2002-2003</p>
17: * <p> $Revision: 1.4 $</p>
18: * <p> License: see License.txt</p>
19: */
20: public class PageCodeHelper extends CodeHelper {
21: private static PageCodeHelper instance = new PageCodeHelper();
22:
23: private PageCodeHelper() {
24: }
25:
26: public static void register(ArrayList resources) {
27: if ((resources != null) && (!resources.contains(instance)))
28: resources.add(instance);
29: }
30:
31: /**
32: * Insert the new codes
33: */
34: public void doInsert(XSourceEditor editor,
35: XEditorProject currentProject, XPageResource pageRes) {
36: try {
37: String pcCode = "\n\t/**\n\t"
38: + " * A method called once the page has been created but not yet initialized.\n\t"
39: + " */\n\t" + "public void pageCreated()\n\t"
40: + "{\n\t" + "}\n\t";
41: String paCode = "\n\t"
42: + "/**\n\t"
43: + " A method called once the page has been created and initialized but just prior to display.\n\t"
44: + " */\n\t" + "public void pageActivated()\n\t"
45: + "{\n\t" + "}\n\t";
46: String pdCode = "\n\t"
47: + "/**\n\t"
48: + " * Called when the page is about to loose scope and be hidden.\n\t"
49: + " */\n\t" + "public void pageDeactivated()\n\t"
50: + "{\n\t" + "}\n\t" + "\n\t";
51: String methodText = editor.getText();
52: int methodPos = methodText
53: .indexOf("public void pageCreated()");
54: if (methodPos < 0)
55: editor.getDocument().insertString(
56: editor.getCaretPosition(), pcCode, null);
57:
58: methodText = editor.getText();
59: methodPos = methodText
60: .indexOf("public void pageActivated()");
61: if (methodPos < 0)
62: editor.getDocument().insertString(
63: editor.getCaretPosition(), paCode, null);
64:
65: methodText = editor.getText();
66: methodPos = methodText
67: .indexOf("public void pageDeactivated()");
68: if (methodPos < 0)
69: editor.getDocument().insertString(
70: editor.getCaretPosition(), pdCode, null);
71: } catch (BadLocationException ex) {
72: }
73: }
74:
75: /**
76: * Get the caption displayed on the popup menu
77: * @return the caption
78: */
79: public String getCaption() {
80: return "page event handlers";
81: }
82:
83: /**
84: * Get the mnemonic key for this item
85: * @return the mnemonic
86: */
87: public Integer getMnemonic() {
88: return new Integer(KeyEvent.VK_P);
89: }
90: }
|