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:
045: public class BorderedPanel extends Panel {
046: public static final int NONE = 0;
047: public static final int RAISED = 1;
048: public static final int SUNKEN = 2;
049: public static final int ETCHED = 3;
050: public static final int RAISED2 = 4;
051:
052: protected int type = RAISED;
053: protected int hideMode = 0;
054: protected Insets insets = new Insets(2, 2, 2, 2);
055: protected static Color[] colors = { Color.white, Color.gray };
056:
057: public BorderedPanel() {
058: this (ETCHED);
059: }
060:
061: public BorderedPanel(int type) {
062: this .type = type;
063: }
064:
065: public void setType(int t) {
066: if (type == t)
067: return;
068: type = t;
069: repaint();
070: }
071:
072: public void setHideMode(int m) {
073: if (hideMode == m)
074: return;
075: hideMode = m;
076: }
077:
078: public Insets getInsets() {
079: return insets;
080: }
081:
082: /* public Insets insets() {
083: return insets;
084: }*/
085:
086: public void paint(Graphics g) {
087: // System.err.println("+++ " + this + ": " + (type == NONE?"NONE":"VISIBLE"));
088: // this.list(System.err,0);
089: if (type == NONE) {
090: Rectangle r = bounds();
091: g.setColor(getParent().getBackground());
092: g.fillRect(0, 0, r.width, r.height);
093: return;
094: }
095: super .paint(g);
096:
097: Dimension d = size();
098: int x = 0;
099: int y = 0;
100: int x2 = d.width - 1;// - 2;
101: int y2 = d.height - 1;// - 2;
102:
103: leftLine(g, x, y, x2, y2);
104: rightLine(g, x, y, x2, y2);
105:
106: topLine(g, x, y, x2, y2);
107: bottomLine(g, x, y, x2, y2);
108: }
109:
110: public void leftLine(Graphics g, int x, int y, int x2, int y2) {
111: g.setColor(colors[1]);
112: switch (type) {
113: case ETCHED: {
114: g.setColor(colors[1]);
115: g.drawLine(x, y, x, y2 - 1); // Topleft to bottomleft
116: g.setColor(colors[0]);
117: g.drawLine(x + 1, y + 1, x + 1, y2 - 2); // Topleft to bottomleft
118: }
119: break;
120: case RAISED2: {
121: g.setColor(colors[0]);
122: g.drawLine(x, y, x, y2 + 2); // Topleft to bottomleft
123: }
124: break;
125: case RAISED: {
126: g.setColor(colors[0]);
127:
128: g.drawLine(x, y, x, y2 - 1); // Topleft to bottomleft
129: }
130: break;
131: case SUNKEN: {
132: g.setColor(colors[1]);
133: g.drawLine(x, y, x, y2 - 1); // Topleft to bottomleft
134: g.setColor(Color.black);
135: g.drawLine(x + 1, y + 1, x + 1, y2 - 2); // Topleft to bottomleft
136: }
137: }
138: }
139:
140: public void rightLine(Graphics g, int x, int y, int x2, int y2) {
141: g.setColor(colors[1]);
142: switch (type) {
143: case ETCHED: {
144: g.setColor(colors[1]);
145: g.drawLine(x2 - 1, y + 1, x2 - 1, y2); // Topright to bottomright
146: g.setColor(colors[0]);
147: g.drawLine(x2, y, x2, y2); // Topright to bottomright
148: }
149: break;
150: case RAISED: {
151: g.setColor(colors[1]);
152: g.drawLine(x2, y, x2, y2); // Topright to bottomright
153: g.setColor(colors[1]);
154: g.drawLine(x2 - 1, y + 1, x2 - 1, y2 - 1); // Topright to bottomright
155: }
156: break;
157: case SUNKEN: {
158: g.setColor(colors[0]);
159: g.drawLine(x2, y, x2, y2 - 1); // Topright to bottomright
160: // g.drawLine(x2 - 1, y+1, x2 - 1, y2 - 1); // Topright to bottomright
161: }
162: break;
163: case RAISED2:
164: g.setColor(colors[1]);
165: g.drawLine(x2, y, x2, y2); // Topright to bottomright
166: break;
167: }
168: }
169:
170: public void topLine(Graphics g, int x, int y, int x2, int y2) {
171: g.setColor(colors[1]);
172: switch (type) {
173: case ETCHED: {
174: g.setColor(colors[1]);
175: g.drawLine(x, y, x2 - 1, y); // Topleft to topright
176: g.setColor(colors[0]);
177: g.drawLine(x + 1, y + 1, x2 - 2, y + 1); // Topleft to topright
178: }
179: break;
180: case RAISED2: {
181: g.setColor(colors[0]);
182: g.drawLine(x, y, x2 + 2, y); // Topleft to topright
183: }
184: break;
185: case RAISED: {
186: g.setColor(colors[0]);
187: g.drawLine(x, y, x2 - 1, y); // Topleft to topright*/
188: }
189: break;
190: case SUNKEN: {
191: g.setColor(Color.black);
192: g.drawLine(x + 1, y + 1, x2 - 2, y + 1); // Topleft to topright
193: g.setColor(colors[1]);
194: g.drawLine(x, y, x2 - 1, y); // Topleft to topright
195: }
196: }
197: }
198:
199: public void bottomLine(Graphics g, int x, int y, int x2, int y2) {
200: g.setColor(colors[1]);
201: switch (type) {
202: case ETCHED: {
203: g.setColor(colors[1]);
204: g.drawLine(x, y2 - 1, x2 - 1, y2 - 1); // Bottomleft to bottomright
205: g.setColor(colors[0]);
206: g.drawLine(x, y2, x2, y2); // Bottomleft to bottomright
207: }
208: break;
209: case RAISED: {
210: g.setColor(colors[1]);
211: g.drawLine(x, y2, x2 - 1, y2); // Bottomleft to bottomright
212: g.setColor(colors[1]);
213: g.drawLine(x + 1, y2 - 1, x2 - 2, y2 - 1); // Bottomleft to bottomright
214: }
215: break;
216: case SUNKEN: {
217: g.setColor(colors[0]);
218: g.drawLine(x, y2, x2, y2); // Bottomleft to bottomright
219: g.drawLine(x + 1, y2 - 1, x2 - 1, y2 - 1); // Bottomleft to bottomright
220: }
221: break;
222: case RAISED2:
223: g.setColor(colors[1]);
224: g.drawLine(x + 1, y2, x2, y2); // Bottomleft to bottomright
225: break;
226: }
227: }
228:
229: int prevMode = -1;
230:
231: public void hide() {
232: //System.err.println("--- " + this + ": " + type + "/" + prevMode);
233: if (hideMode == 0)
234: super .hide();
235: else {
236: if (type == NONE)
237: return;
238: prevMode = type;
239: setType(NONE);
240: }
241: }
242:
243: public boolean isVisible() {
244: if (hideMode == 0)
245: return super .isVisible();
246: if (type == NONE)
247: return false;
248: return true;
249: }
250:
251: public void show() {
252: // System.err.println("*** " + this + ": " + type + "/" + prevMode);
253: if (hideMode == 0)
254: super .show();
255: else {
256: if (!super .isVisible())
257: super .show();
258: if (prevMode < 0)
259: return;
260: setType(prevMode);
261: prevMode = -1;
262: // System.err.println("*** " + this + ": VALIDATE as " + type + "/" + prevMode);
263: try {
264: super .hide();
265: super .show();
266: ((Component) this ).invalidate();
267: ((Component) this ).validate();
268: repaint();
269: } catch (Exception e) {
270: e.printStackTrace();
271: }
272: }
273: }
274:
275: // X11 fixes to avoid wrong repaints
276: public boolean mouseMove(Event e, int x, int y) {
277: return true;
278: }
279:
280: public boolean mouseExit(Event e, int x, int y) {
281: return true;
282: }
283:
284: public boolean mouseEnter(Event e, int x, int y) {
285: return true;
286: }
287: }
|