KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > antlr > works > plugin > container > PCXJFrameInterface


1 package org.antlr.works.plugin.container;
2
3 import org.antlr.xjlib.appkit.frame.XJFrame;
4 import org.antlr.xjlib.appkit.frame.XJFrameInterface;
5 import org.antlr.xjlib.appkit.menu.XJMainMenuBar;
6 import org.antlr.xjlib.appkit.menu.XJMenu;
7 import org.antlr.xjlib.appkit.menu.XJMenuItem;
8 import org.antlr.xjlib.appkit.undo.XJUndo;
9 import org.antlr.xjlib.appkit.undo.XJUndoDelegate;
10 import org.antlr.xjlib.appkit.undo.XJUndoEngine;
11
12 import javax.swing.*;
13 import javax.swing.text.DefaultEditorKit JavaDoc;
14 import java.awt.*;
15 /*
16
17 [The "BSD licence"]
18 Copyright (c) 2005-2006 Jean Bovet
19 All rights reserved.
20
21 Redistribution and use in source and binary forms, with or without
22 modification, are permitted provided that the following conditions
23 are met:
24
25 1. Redistributions of source code must retain the above copyright
26 notice, this list of conditions and the following disclaimer.
27 2. Redistributions in binary form must reproduce the above copyright
28 notice, this list of conditions and the following disclaimer in the
29 documentation and/or other materials provided with the distribution.
30 3. The name of the author may not be used to endorse or promote products
31 derived from this software without specific prior written permission.
32
33 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
34 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
35 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
36 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
37 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
38 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
42 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
43
44 */

45
46 public class PCXJFrameInterface implements XJFrameInterface {
47
48     private PluginContainer container;
49     private XJUndoEngine undoEngine;
50
51     public PCXJFrameInterface(PluginContainer container) {
52         this.container = container;
53         undoEngine = new XJUndoEngine();
54     }
55
56     public void registerUndo(XJUndoDelegate delegate, JTextPane textPane) {
57         undoEngine.registerUndo(new XJUndo(undoEngine, delegate), textPane);
58     }
59
60     public XJUndo getUndo(JTextPane textPane) {
61         return undoEngine.getUndo(textPane);
62     }
63
64     public XJUndo getCurrentUndo() {
65         return undoEngine.getCurrentUndo();
66     }
67
68     public XJMainMenuBar getMainMenuBar() {
69         return container.getMainMenuBar();
70     }
71
72     public Container getJavaContainer() {
73         return container.getContentPane();
74     }
75
76     public JLayeredPane getLayeredPane() {
77         return container.getLayeredPane();
78     }
79
80     public JRootPane getRootPane() {
81         return container.getRootPane();
82     }
83
84     private void performUndo() {
85         XJUndo undo = getCurrentUndo();
86         if(undo != null) {
87             undo.performUndo();
88         }
89     }
90
91     private void performRedo() {
92         XJUndo undo = getCurrentUndo();
93         if(undo != null) {
94             undo.performRedo();
95         }
96     }
97
98     public void handleMenuEvent(XJMenu menu, XJMenuItem item) {
99         switch(item.getTag()) {
100             case XJMainMenuBar.MI_UNDO:
101                 performUndo();
102                 break;
103             case XJMainMenuBar.MI_REDO:
104                 performRedo();
105                 break;
106             case XJMainMenuBar.MI_CUT:
107                 XJFrame.performActionOnFocusedJComponent(DefaultEditorKit.cutAction);
108                 break;
109             case XJMainMenuBar.MI_COPY:
110                 XJFrame.performActionOnFocusedJComponent(DefaultEditorKit.copyAction);
111                 break;
112             case XJMainMenuBar.MI_PASTE:
113                 XJFrame.performActionOnFocusedJComponent(DefaultEditorKit.pasteAction);
114                 break;
115             case XJMainMenuBar.MI_SELECT_ALL:
116                 XJFrame.performActionOnFocusedJComponent(DefaultEditorKit.selectAllAction);
117                 break;
118         }
119
120     }
121
122
123 }
124
Popular Tags