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.Insets;
044:
045: public class Align implements AlignConstants {
046: private int align = CENTER;
047: private String alignStr = STR_CENTER;
048: private Insets code = new Insets(0, 0, 0, 0);
049:
050: /**
051: * Constructs a new Align.
052: */
053: public Align() {
054: }
055:
056: /**
057: * Sets the arrangement type as int value.
058: * @param a new int value of the align property.
059: */
060: public void setAlign(int a) {
061: if (align == a)
062: return;
063: code = align2insets(a);
064: alignStr = align2str(a);
065: align = a;
066: }
067:
068: /**
069: * Returns the align type as int value.
070: * @return int value of the align property.
071: */
072: public int getAlign() {
073: return align;
074: }
075:
076: /**
077: * Sets the align type as Insets value.
078: * @param i new java.awt.Insets value of the align property.
079: */
080: public void setAlignInsets(Insets i) {
081: if (i == code)
082: return;
083: align = insets2align(i);
084: }
085:
086: /**
087: * Returns the align type as Insets value.
088: * @return java.awt.Insets value of the align property.
089: */
090: public Insets getAlignInsets() {
091: return code;
092: }
093:
094: /**
095: * Returns the align type as String value.
096: * @return String value of the align property.
097: * </FONT>
098: */
099: public String getAlignString() {
100: return alignStr;
101: }
102:
103: public static Insets align2insets(int a) {
104: Insets i = new Insets(-1, -1, -1, -1);
105: i.top = ((a & Align.TOP) > 0) ? 1 : 0;
106: i.left = ((a & Align.LEFT) > 0) ? 1 : 0;
107: i.bottom = ((a & Align.BOTTOM) > 0) ? 1 : 0;
108: i.right = ((a & Align.RIGHT) > 0) ? 1 : 0;
109: if (!check(i))
110: return null;
111: return i;
112: }
113:
114: public static String align2str(int a) {
115: String r = null;
116: switch (a) {
117: case Align.TOP:
118: r = Align.STR_TOP;
119: break;
120: case Align.BOTTOM:
121: r = Align.STR_BOTTOM;
122: break;
123: case Align.LEFT:
124: r = Align.STR_LEFT;
125: break;
126: case Align.RIGHT:
127: r = Align.STR_RIGHT;
128: break;
129: case Align.TLEFT:
130: r = Align.STR_TLEFT;
131: break;
132: case Align.TRIGHT:
133: r = Align.STR_TRIGHT;
134: break;
135: case Align.BRIGHT:
136: r = Align.STR_BRIGHT;
137: break;
138: case Align.BLEFT:
139: r = Align.STR_BLEFT;
140: break;
141: case Align.CENTER:
142: r = Align.STR_CENTER;
143: break;
144: }
145: return r;
146: }
147:
148: public static int insets2align(Insets i) {
149: if (i == null || !check(i))
150: return -1;
151: int a = 0;
152: a |= ((i.top > 0) ? Align.TOP : 0);
153: a |= ((i.left > 0) ? Align.LEFT : 0);
154: a |= ((i.bottom > 0) ? Align.BOTTOM : 0);
155: a |= ((i.right > 0) ? Align.RIGHT : 0);
156: return a;
157: }
158:
159: protected static boolean check(Insets i) {
160: if ((i.top > 0 && i.bottom > 0) || (i.left > 0 && i.right > 0))
161: return false;
162:
163: if (i.top < 0 || i.bottom < 0 || i.left < 0 || i.right < 0)
164: return false;
165: return true;
166: }
167: }
|