001: /**
002: * Caption: Zaval Java Resource Editor
003: * @author: Victor Krapivin
004: * @version: 2.0
005: *
006: * Zaval JRC Editor is a visual editor which allows you to manipulate
007: * localization strings for all Java based software with appropriate
008: * support embedded.
009: *
010: * For more info on this product read Zaval Java Resource Editor User's Guide
011: * (It comes within this package).
012: * The latest product version is always available from the product's homepage:
013: * http://www.zaval.org/products/jrc-editor/
014: * and from the SourceForge:
015: * http://sourceforge.net/projects/zaval0002/
016: *
017: * Contacts:
018: * Support : support@zaval.org
019: * Change Requests : change-request@zaval.org
020: * Feedback : feedback@zaval.org
021: * Other : info@zaval.org
022: *
023: * Copyright (C) 2001-2002 Zaval Creative Engineering Group (http://www.zaval.org)
024: *
025: * This program is free software; you can redistribute it and/or
026: * modify it under the terms of the GNU General Public License
027: * (version 2) as published by the Free Software Foundation.
028: *
029: * This program is distributed in the hope that it will be useful,
030: * but WITHOUT ANY WARRANTY; without even the implied warranty of
031: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
032: * GNU General Public License for more details.
033: *
034: * You should have received a copy of the GNU General Public License
035: * along with this program; if not, write to the Free Software
036: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
037: *
038: */package org.zaval.tools.i18n.translator;
039:
040: import org.zaval.awt.*;
041:
042: import java.awt.*;
043: import java.util.*;
044:
045: public class LangDialog extends Dialog {
046: private java.awt.List edit;
047: private Button ok, cancel;
048: private boolean isApply;
049: private Component listener;
050: private IELabel label;
051:
052: public LangDialog(Frame f, String s, boolean b, Component l) {
053: super (f, s, b);
054: setLayout(new GridBagLayout());
055:
056: label = new IELabel("List of languages");
057: constrain(this , label, 0, 0, 1, 1, GridBagConstraints.NONE,
058: GridBagConstraints.WEST, 0.0, 0.0, 5, 5, 5, 5);
059: constrain(this , edit = new java.awt.List(10, true), 0, 1, 4, 1,
060: GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
061: 1.0, 0.0, 5, 5, 5, 5);
062:
063: ok = new Button("Ok");
064: cancel = new Button("Cancel");
065:
066: Panel p = new Panel();
067: p.setLayout(new GridLayout(1, 2, 2, 0));
068: p.add(ok);
069: p.add(cancel);
070:
071: constrain(this , p, 0, 2, 2, 1, GridBagConstraints.NONE,
072: GridBagConstraints.EAST, 1.0, 0.0, 5, 5, 5, 5);
073:
074: listener = l;
075: pack();
076: }
077:
078: public void setList(LangItem[] t) {
079: edit.clear();
080: if (t == null)
081: return;
082: for (int j = 0; j < t.length; ++j) {
083: String s = t[j].getLangId() + ": "
084: + t[j].getLangDescription();
085: edit.add(s);
086: }
087: edit.select(0); // english is always selected
088: }
089:
090: public String[] getList() {
091: edit.select(0); // english is always selected
092: return edit.getSelectedItems();
093: }
094:
095: public void setButtonsCaption(String o, String c) {
096: ok.setLabel(o);
097: cancel.setLabel(c);
098: }
099:
100: public void setLabelCaption(String l) {
101: label.setText(l);
102: }
103:
104: public boolean handleEvent(Event e) {
105: if (e.id == Event.WINDOW_DESTROY
106: || (e.target == cancel && e.id == Event.ACTION_EVENT)) {
107: isApply = false;
108: dispose();
109: }
110:
111: if (e.target == ok && e.id == Event.ACTION_EVENT) {
112: isApply = true;
113: listener.postEvent(new Event(this , e.ACTION_EVENT, null));
114: dispose();
115: }
116: return super .handleEvent(e);
117: }
118:
119: public boolean isApply() {
120: return isApply;
121: }
122:
123: public void toCenter() {
124: Dimension s = Toolkit.getDefaultToolkit().getScreenSize();
125: Dimension d = getSize();
126: move((s.width - d.width) / 2, (s.height - d.height) / 2);
127: }
128:
129: static public void constrain(Container c, Component p, int x,
130: int y, int w, int h, int f, int a, double wx, double wy,
131: int t, int l, int r, int b) {
132: GridBagConstraints cc = new GridBagConstraints();
133:
134: cc.gridx = x;
135: cc.gridy = y;
136: cc.gridwidth = w;
137: cc.gridheight = h;
138:
139: cc.fill = f;
140: cc.anchor = a;
141: cc.weightx = wx;
142: cc.weighty = wy;
143:
144: if (t + b + l + r > 0)
145: cc.insets = new Insets(t, l, b, r);
146: LayoutManager lm = c.getLayout();
147: if (lm instanceof GridBagLayout) {
148: GridBagLayout gbl = (GridBagLayout) lm;
149: gbl.setConstraints(p, cc);
150: } else if (lm instanceof ExGridLayout) {
151: ExGridLayout gbl = (ExGridLayout) lm;
152: gbl.setConstraints(p, cc);
153: }
154: c.add(p);
155: }
156:
157: static public void constrain(Container c, Component p, int x,
158: int y, int w, int h) {
159: constrain(c, p, x, y, w, h, GridBagConstraints.NONE,
160: GridBagConstraints.NORTHWEST, 1.0, 1.0, 0, 0, 5, 3);
161: }
162:
163: static public void constrain(Container c, Component p, int x,
164: int y, int w, int h, int f, int a) {
165: constrain(c, p, x, y, w, h, f, a, 1.0, 1.0, 0, 0, 5, 3);
166: }
167:
168: public boolean keyDown(Event e, int key) {
169: if ((e.target == ok && key == Event.ENTER)
170: || (e.target == edit && key == Event.ENTER)) {
171: isApply = true;
172: listener.postEvent(new Event(this , e.ACTION_EVENT, null));
173: dispose();
174: return true;
175: }
176: if (e.target == cancel && key == Event.ENTER) {
177: isApply = false;
178: dispose();
179: return true;
180: }
181: return false;
182: }
183:
184: public Dimension preferredSize() {
185: Dimension d = super .preferredSize();
186: d.width *= 2;
187: return d;
188: }
189:
190: public boolean doModal() {
191: pack();
192: toCenter();
193: show();
194: return true;
195: }
196: }
|