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 org.zaval.awt.event.*;
044: import java.awt.*;
045: import java.util.*;
046:
047: public abstract class DecorativeComponent {
048: public static final int CENTER = 1;
049: public static final int LEFT = 2;
050: public static final int RIGHT = 3;
051:
052: private Color bColor = Color.white;
053: private Color fColor = Color.black;
054: private Font font;
055: private int align = CENTER;
056: private Dimension size = new Dimension(0, 0);
057: private boolean isValid = false;
058: private Component parent;
059: private Insets insets = new Insets(0, 2, 4, 4);
060: private ValidateListenerSupport listener = new ValidateListenerSupport();
061:
062: public DecorativeComponent() {
063: this (null);
064: }
065:
066: public DecorativeComponent(Component c) {
067: setParent(c);
068: invalidate();
069: }
070:
071: public void addValidateListener(ValidateListener l) {
072: listener.addListener(l);
073: }
074:
075: public void removeValidateListener(ValidateListener l) {
076: listener.removeListener(l);
077: }
078:
079: protected void validatePerform() {
080: listener
081: .perform(new ValidateEvent(this , ValidateEvent.VALIDATE));
082: }
083:
084: protected void invalidatePerform() {
085: listener.perform(new ValidateEvent(this ,
086: ValidateEvent.INVALIDATE));
087: }
088:
089: public void setFromComponent(Component c) {
090: if (c == null)
091: return;
092: if (c.getFont() != null)
093: setFont(c.getFont());
094: if (c.getBackground() != null)
095: setBackgroundColor(c.getBackground());
096: if (c.getForeground() != null)
097: setForegroundColor(c.getForeground());
098: }
099:
100: public Component getParent() {
101: return parent;
102: }
103:
104: public void setParent(Component p) {
105: parent = p;
106: }
107:
108: public Font getFont() {
109: return font;
110: }
111:
112: public void setFont(Font f) {
113: font = f;
114: invalidate();
115: }
116:
117: public int getAlign() {
118: return align;
119: }
120:
121: public void setAlign(int a) {
122: if (a == align)
123: return;
124: align = a;
125: }
126:
127: public Color getBackgroundColor() {
128: return bColor;
129: }
130:
131: public void setBackgroundColor(Color c) {
132: bColor = c;
133: }
134:
135: public Color getForegroundColor() {
136: return fColor;
137: }
138:
139: public void setForegroundColor(Color c) {
140: fColor = c;
141: }
142:
143: public void setSize(Dimension d) {
144: if (d == size)
145: return;
146: size.width = d.width;
147: size.height = d.height;
148: invalidate();
149: }
150:
151: public Dimension getSize() {
152: return size;
153: }
154:
155: public Insets getInsets() {
156: return insets;
157: }
158:
159: public void setInsets(Insets i) {
160: insets = i;
161: }
162:
163: protected void invalidate() {
164: //System.out.println ("invalidate()1" + isValid);
165: if (isValid) {
166: isValid = false;
167: //System.out.println ("invalidate()");
168: invalidatePerform();
169: }
170: }
171:
172: protected void validate() {
173: if (!isValid) {
174: isValid = true;
175: //System.out.println ("validate()");
176: validatePerform();
177: }
178: }
179:
180: public boolean isValid() {
181: return isValid;
182: }
183:
184: public void doValidate() {
185: validate();
186: }
187:
188: public void doPaint(int x, int y, int width, int height, Graphics g) {
189: validate();
190: if (!isValid())
191: return;
192: if (width <= 0 || height <= 0)
193: return;
194: draw(x, y, width, height, g);
195: }
196:
197: public void doPaint(int x, int y, Graphics g) {
198: validate();
199: if (!isValid())
200: return;
201: Dimension d = getSize();
202: if (d.width <= 0 || d.height <= 0)
203: return;
204: draw(x, y, d.width, d.height, g);
205:
206: }
207:
208: protected abstract void draw(int x, int y, int width, int height,
209: Graphics g);
210: }
|