001: /**
002: * Caption: Zaval Java Resource Editor
003: * $Revision: 0.37 $
004: * $Date: 2002/03/28 9:24:42 $
005: *
006: * @author: Victor Krapivin
007: * @version: 1.3
008: *
009: * Zaval JRC Editor is a visual editor which allows you to manipulate
010: * localization strings for all Java based software with appropriate
011: * support embedded.
012: *
013: * For more info on this product read Zaval Java Resource Editor User's Guide
014: * (It comes within this package).
015: * The latest product version is always available from the product's homepage:
016: * http://www.zaval.org/products/jrc-editor/
017: * and from the SourceForge:
018: * http://sourceforge.net/projects/zaval0002/
019: *
020: * Contacts:
021: * Support : support@zaval.org
022: * Change Requests : change-request@zaval.org
023: * Feedback : feedback@zaval.org
024: * Other : info@zaval.org
025: *
026: * Copyright (C) 2001-2002 Zaval Creative Engineering Group (http://www.zaval.org)
027: *
028: * This program is free software; you can redistribute it and/or
029: * modify it under the terms of the GNU General Public License
030: * (version 2) as published by the Free Software Foundation.
031: *
032: * This program is distributed in the hope that it will be useful,
033: * but WITHOUT ANY WARRANTY; without even the implied warranty of
034: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
035: * GNU General Public License for more details.
036: *
037: * You should have received a copy of the GNU General Public License
038: * along with this program; if not, write to the Free Software
039: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
040: *
041: */package org.zaval.awt;
042:
043: // ====================================================================
044:
045: import org.zaval.awt.peer.*;
046: import java.awt.*;
047: import java.util.*;
048:
049: // =================================================================
050:
051: public class GraphTree extends SymTree {
052: ContextMenuBar menubar = null;
053:
054: // =================================================================
055:
056: public GraphTree() {
057: super ();
058: }
059:
060: // =================================================================
061:
062: public GraphTree(TreeNode tn) {
063: super ();
064: }
065:
066: // =================================================================
067:
068: public GraphTree(ContextMenuBar a_menubar) {
069: this ();
070: menubar = a_menubar;
071: }
072:
073: // =================================================================
074:
075: public void setMenuBar(ContextMenuBar mb) {
076: menubar = mb;
077: menubar.setParent(this );
078: }
079:
080: // =================================================================
081:
082: public ContextMenuBar getMenuBar() {
083: return menubar;
084: }
085:
086: // =================================================================
087:
088: public void setContextMenu(String name, int index) {
089: TreeNode tn = getNode(name);
090: if ((tn == null) || (menubar.get(index) == null))
091: return;
092: tn.setContextMenu(index);
093: }
094:
095: // =================================================================
096:
097: public void setContextMenu(String name, ContextMenu cm) {
098: TreeNode tn = getNode(name);
099: if (tn == null)
100: return;
101: for (int i = 0; i < menubar.countMenus(); i++)
102: if (menubar.get(i) == cm) {
103: tn.setContextMenu(i);
104: return;
105: }
106: addMenu(cm);
107: setContextMenu(name, menubar.countMenus() - 1);
108: }
109:
110: // =================================================================
111:
112: public ContextMenu getContextMenu(String name) {
113: TreeNode tn = getNode(name);
114: if ((menubar == null) || (tn == null)
115: || (tn.getContextMenu() < 0))
116: return null;
117: return menubar.get(tn.getContextMenu());
118: }
119:
120: // =================================================================
121:
122: public int addMenu(ContextMenu menu) {
123: if (menu == null)
124: return -1;
125: menubar.add(menu);
126: return menubar.countMenus() - 1;
127: }
128:
129: // =================================================================
130:
131: public void update(Graphics gr) {
132: paint(gr);
133: }
134:
135: public void paint(Graphics gr) {
136: if (menubar != null && menubar.isActive())
137: menubar.paint(gr);
138: else
139: super .paint(gr);
140: }
141:
142: // =================================================================
143:
144: int isRightKey = 0;
145:
146: public boolean mouseDown(Event evt, int x, int y) {
147: if (evt.modifiers == 4)
148: isRightKey = 1;
149: else {
150: isRightKey = 0;
151: return super .mouseDown(evt, x, y);
152: }
153: return true;
154: }
155:
156: // =================================================================
157:
158: public boolean mouseUp(Event evt, int x, int y) {
159: if (isRightKey == 1) {
160: isRightKey = 0;
161: changeSelection(evt, evt.x, evt.y, false, new boolean[1]);
162: TreeNode tn = getSelectedNode();
163: if ((noChoice) || (tn == null) || (tn.getContextMenu() < 0))
164: tn = getRootNode();
165: if ((tn != null) && (tn.getContextMenu() >= 0)) {
166: menubar.init(tn.getContextMenu(), x, y);
167: repaint();
168: }
169: }
170: return super .mouseUp(evt, x, y);
171: }
172:
173: // =================================================================
174:
175: public boolean action(Event evt, Object what) {
176: if (evt.target instanceof MenuItem) {
177: repaint();
178: return false;
179: } else
180: return super .action(evt, what);
181: }
182:
183: // =================================================================
184:
185: public boolean handleEvent(Event evt) {
186: if (evt.key == '\t')
187: return false;
188: if (menubar != null && menubar.handleEvent(evt))
189: return true;
190: return super .handleEvent(evt);
191: }
192:
193: // =================================================================
194:
195: public boolean postEvent(Event evt) {
196: if (evt.target instanceof MenuItem) {
197: if (noChoice)
198: evt.arg = null;
199: else
200: evt.arg = getSelectedNode().text;
201: }
202: return super .postEvent(evt);
203: }
204:
205: public void disableAll() {
206: if (menubar == null)
207: return;
208: int count = menubar.countMenus();
209: for (int i = 0; i < count; i++)
210: menubar.getMenu(i).disable();
211: }
212:
213: // =================================================================
214:
215: public void enableAll() {
216: if (menubar == null)
217: return;
218: int count = menubar.countMenus();
219: for (int i = 0; i < count; i++)
220: menubar.getMenu(i).enable();
221: }
222:
223: // =================================================================
224:
225: public void setContextMenu(TreeNode tn, int index) {
226: if ((tn == null) || (menubar.get(index) == null))
227: return;
228: tn.setContextMenu(index);
229: }
230:
231: // =================================================================
232:
233: public ContextMenu getContextMenu(TreeNode tn) {
234: if (tn == null)
235: return null;
236: return menubar.get(tn.getContextMenu());
237: }
238: }
|