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: import java.awt.*;
044: import java.applet.*;
045: import java.util.*;
046:
047: import org.zaval.awt.event.*;
048:
049: public class ContextMenuBar extends MenuBar {
050: public final static int EV_MENU_REDRAW = 0xFFF0;
051: public final static int EV_MENU_EXIT = EV_MENU_REDRAW + 1;
052: public final static int EV_MENU_ENTER = EV_MENU_REDRAW + 2;
053: public final static int EV_MENU_REDRAWALL = EV_MENU_REDRAW + 3;
054:
055: // ====================================================================
056:
057: public Container parent = null;
058: ContextMenu act_menu = null;
059: boolean first = true;
060: ListenerSupport support = new ListenerSupport();
061:
062: // ====================================================================
063:
064: public ContextMenuBar(Container a_parent) {
065: parent = a_parent;
066: }
067:
068: // ====================================================================
069:
070: public ContextMenuBar() {
071: super ();
072: }
073:
074: // ====================================================================
075:
076: public void addListener(Listener l) {
077: support.addListener(l);
078: }
079:
080: // ====================================================================
081:
082: public void removeListener(Listener l) {
083: support.removeListener(l);
084: }
085:
086: // ====================================================================
087:
088: public void setParent(Container a_parent) {
089: parent = a_parent;
090: }
091:
092: // ====================================================================
093:
094: public Dimension getParentSize() {
095: if (parent == null)
096: return null;
097: else
098: return parent.size();
099: }
100:
101: // ====================================================================
102:
103: public void add(ContextMenu cm) {
104: cm.index = countMenus();
105: super .add(cm);
106: }
107:
108: // ====================================================================
109:
110: public void remove(int index) {
111: super .remove(index);
112: }
113:
114: // ====================================================================
115:
116: public void remove(MenuComponent mc) {
117: super .remove(mc);
118: }
119:
120: // ====================================================================
121:
122: public boolean init(int index, int x, int y) {
123: act_menu = get(index);
124: if ((act_menu == null) || (!act_menu.isEnabled())) {
125: act_menu = null;
126: return false;
127: }
128: act_menu.setPos(x, y);
129: first = true;
130: return true;
131: }
132:
133: // ====================================================================
134:
135: public void paint(Graphics gr) {
136: if (act_menu == null)
137: return;
138: if (first) {
139: first = false;
140: act_menu.paint(gr);
141: } else
142: act_menu.paintPart(gr);
143: }
144:
145: // ====================================================================
146:
147: public boolean isRedraw() {
148: return first;
149: }
150:
151: public boolean isActive() {
152: return parent != null && act_menu != null;
153: }
154:
155: // ====================================================================
156:
157: public ContextMenu get(int index) {
158: return (ContextMenu) super .getMenu(index);
159: }
160:
161: // ====================================================================
162:
163: public void disable(int index) {
164: get(index).disable();
165: }
166:
167: // ====================================================================
168:
169: public void enable(int index) {
170: get(index).enable();
171: }
172:
173: // ====================================================================
174:
175: public void repaint() {
176: if (parent == null)
177: return;
178: Graphics gr = parent.getGraphics();
179: paint(gr);
180: gr.dispose();
181: }
182:
183: // ====================================================================
184:
185: public void repaintAll() {
186: first = true;
187: if (act_menu != null && parent != null) {
188: Rectangle r = act_menu.getBounds();
189: parent.repaint(r.x, r.y, r.width, r.height);
190: }
191: repaint();
192: }
193:
194: // ====================================================================
195:
196: public void sendEvent(java.awt.Event evt) {
197: if ((parent == null) || (act_menu == null))
198: return;
199: switch (evt.id) {
200: case ContextMenuBar.EV_MENU_REDRAW: {
201: repaint();
202: }
203: break;
204:
205: case ContextMenuBar.EV_MENU_REDRAWALL: {
206: repaintAll();
207: }
208: break;
209: case ContextMenuBar.EV_MENU_EXIT: {
210: repaintAll();
211: act_menu = null;
212: }
213: break;
214: case ContextMenuBar.EV_MENU_ENTER: {
215: repaintAll();
216: act_menu = null;
217: evt.id = java.awt.Event.ACTION_EVENT;
218: if (support.size() > 0) {
219: org.zaval.awt.event.Event e = new org.zaval.awt.event.Event(
220: this , EV_MENU_ENTER);
221: e.put("event", evt);
222: support.perform(e);
223: } else
224: parent.postEvent(evt);
225: }
226: }
227: }
228:
229: // ====================================================================
230:
231: public boolean handleEvent(java.awt.Event evt) {
232: if ((act_menu == null) || (!act_menu.isEnabled()))
233: return false;
234: return act_menu.handleEvent(evt);
235: }
236:
237: }
|