Renaming setName to setDesignName and setSize to setDesignSize to avoid clash with added methods of java.awt.Component that return void
5 package xelfi.design.components.xawt;
9 * @version 2.12, 03 Apr 1997
10 * @author Petr Hamernik
16 import xelfi.awt.TabControl;
17 import xelfi.design.components.*;
18 import xelfi.design.components.property.*;
19 import xelfi.design.forms.XelfiDesignForm;
20 import xelfi.design.util.XFDesignConstants;
21 import xelfi.design.util.XFDesignOptions;
22 import xelfi.design.util.XFDesignUtils;
24 public class XTabControl extends XAWTPanel {
25 private TabControl tabcontrol;
27 private static int propertyCount = 14;
28 private Object propDef[];
29 private boolean propDefSet = false;
30 private static int eventCount = 3;
31 private String events[] = new String[eventCount];
32 protected static Image icon = null;
34 public XTabControl() {
35 super(XAWTPanel.WITHOUT_DRAGBORDER);
36 setComponent(tabcontrol = new TabControl());
37 tabcontrol.propagate = true;
38 propDef = new Object[propertyCount];
39 for (int i=0; i<propertyCount; i++)
42 icon = loadIcon("tabcontrol.gif");
45 protected void regenForm(int what) {
46 if (parentForm != null)
47 parentForm.regenerateCode(this, what);
50 public String[] neededImports() {
51 String[] ret = new String[1];
52 ret[0] = "xelfi.awt.TabControl";
56 public Dimension preferredSize() {
58 Dimension sz = super.preferredSize();
59 if ((tabcontrol.getTabCount() == 0) &&
60 (XFDesignOptions.designMode == XFDesignConstants.DM_DESIGN)) {
66 public boolean handleEvent(Event evt) {
68 if (XFDesignOptions.designMode == XFDesignConstants.DM_REAL)
69 tabcontrol.propagate = false;
71 tabcontrol.propagate = true;
72 return super.handleEvent(evt);
75 public Image getIcon() {
79 private boolean propertyDefault(int i) throws XFPropertyIndexOutOfBoundsException {
81 propertiesSetDefault();
82 if (propDef[i] == null)
85 case 0: return ((Color) propDef[i]).equals(tabcontrol.getBackground());
86 case 1: return ((Color) propDef[i]).equals(tabcontrol.getForeground());
87 case 2: return (((Boolean) propDef[i]).booleanValue() == tabcontrol.isEnabled());
88 case 3: return (((Boolean) propDef[i]).booleanValue() == bVisible);
89 case 4: return ((Font) propDef[i]).equals(tabcontrol.getFont());
90 case 5: return (((Boolean) propDef[i]).booleanValue() == autoSize);
91 case 6: return (((Boolean) propDef[i]).booleanValue() == parentColor);
92 case 7: return (((Boolean) propDef[i]).booleanValue() == parentFont);
94 case 9: return (((Integer) propDef[i]).intValue() == tabcontrol.getTabIndex());
95 case 10: return (tabcontrol.defaultMinWidth == tabcontrol.getMinWidth());
96 case 11: return (tabcontrol.defaultBorderColor.equals(tabcontrol.getBorderColor()));
97 case 12: return (tabcontrol.defaultBorderWidth == tabcontrol.getBorderWidth());
98 case 13: return (tabcontrol.defaultDirection == tabcontrol.getDirection());
99 default: throw new XFPropertyIndexOutOfBoundsException();
103 private void propertiesSetDefault() {
107 if (getBackground() != null)
108 propDef[0] = new Color(tabcontrol.getBackground().getRGB());
109 if (getForeground() != null)
110 propDef[1] = new Color(tabcontrol.getForeground().getRGB());
111 propDef[2] = new Boolean(tabcontrol.isEnabled());
112 propDef[3] = new Boolean(bVisible);
113 if (tabcontrol.getFont() != null) {
114 Font f = tabcontrol.getFont();
115 propDef[4] = new Font(f.getName(), f.getStyle(), f.getSize());
117 propDef[5] = new Boolean(autoSize);
118 propDef[6] = new Boolean(parentColor);
119 propDef[7] = new Boolean(parentFont);
120 propDef[8] = new String[1];
121 propDef[9] = new Integer(-1);
122 propDef[10] = new Integer(tabcontrol.defaultMinWidth);
123 propDef[11] = tabcontrol.defaultBorderColor;
124 propDef[12] = new Integer(tabcontrol.defaultBorderWidth);
125 propDef[13] = new Boolean(tabcontrol.defaultDirection);
128 public int getPropertyCount() { return propertyCount; }
130 public Object getProperty(int index) throws XFPropertyIndexOutOfBoundsException {
132 case 0: return tabcontrol.getBackground();
133 case 1: return tabcontrol.getForeground();
134 case 2: return (tabcontrol.isEnabled()) ? Boolean.TRUE : Boolean.FALSE;
135 case 3: return (bVisible) ? Boolean.TRUE : Boolean.FALSE;
136 case 4: return tabcontrol.getFont();
137 case 5: return (autoSize) ? Boolean.TRUE : Boolean.FALSE;
138 case 6: return (parentColor) ? Boolean.TRUE : Boolean.FALSE;
139 case 7: return (parentFont) ? Boolean.TRUE : Boolean.FALSE;
140 case 8: int cnt = tabcontrol.getTabCount();
141 String[] ret = new String[cnt];
142 for (int i = 0; i < cnt; i++)
143 ret[i] = tabcontrol.getTabName(i);
145 case 9: return new Integer(tabcontrol.getTabIndex());
146 case 10: return new Integer(tabcontrol.getMinWidth());
147 case 11: return tabcontrol.getBorderColor();
148 case 12: return new Integer(tabcontrol.getBorderWidth());
149 case 13: return new Boolean(tabcontrol.getDirection());
150 default: throw new XFPropertyIndexOutOfBoundsException();
154 public String[] getPropertyNames() {
155 String list[] = new String[propertyCount];
156 list[0] = "Background Color";
157 list[1] = "Foreground Color";
161 list[5] = "Auto Size";
162 list[6] = "Parent Color";
163 list[7] = "Parent Font";
165 list[9] = "Selected";
166 list[10] = "Minimal Width";
167 list[11] = "Border Color";
168 list[12] = "Border Width";
169 list[13] = "Direction";
173 public String getPropertyString(int index) throws
174 XFPropertyIndexOutOfBoundsException {
177 case 1: return XColorPropertyType.viewString(getProperty(index));
179 case 3: return XBooleanPropertyType.viewString(getProperty(index));
180 case 4: return XFontPropertyType.viewString(getProperty(index));
183 case 7: return XBooleanPropertyType.viewString(getProperty(index));
184 case 8: return XStringArrayPropertyType.viewString(getProperty(index));
185 case 9: return XIntegerPropertyType.viewString(getProperty(index));
186 case 10: return XIntegerPropertyType.viewString(getProperty(index));
187 case 11: return XColorPropertyType.viewString(getProperty(index));
188 case 12: return XIntegerPropertyType.viewString(getProperty(index));
189 case 13: return XBooleanPropertyType.viewString(getProperty(index));
190 default: throw new XFPropertyIndexOutOfBoundsException();
194 public int getPropertyViewerType(int index) throws
195 XFPropertyIndexOutOfBoundsException {
198 case 1: return XFDesignConstants.PVT_SPECIAL;
200 case 3: return XFDesignConstants.PVT_CHECK;
201 case 4: return XFDesignConstants.PVT_SPECIAL;
204 case 7: return XFDesignConstants.PVT_CHECK;
205 case 8: return XFDesignConstants.PVT_SPECIAL;
206 case 9: return XFDesignConstants.PVT_INPUT_INT;
207 case 10: return XFDesignConstants.PVT_INPUT_INT;
208 case 11: return XFDesignConstants.PVT_SPECIAL;
209 case 12: return XFDesignConstants.PVT_INPUT_INT;
210 case 13: return XFDesignConstants.PVT_CHECK;
211 default: throw new XFPropertyIndexOutOfBoundsException();
215 public String[] getPropertyValueNames(int index) throws
216 XFPropertyIndexOutOfBoundsException {
218 default: throw new XFPropertyIndexOutOfBoundsException();
222 public Object[] getPropertyValueValues(int index) throws
223 XFPropertyIndexOutOfBoundsException {
225 default: throw new XFPropertyIndexOutOfBoundsException();
229 public int setProperty(int index, Object value) throws
230 XFPropertyIndexOutOfBoundsException,
231 XFPropertyBadValueTypeException
233 int ret = XFDesignConstants.RSP_OK;
234 int regen = XFDesignConstants.GEN_SETPROPS;
236 propertiesSetDefault();
238 case 0: if (!(value instanceof Color)) throw new XFPropertyBadValueTypeException();
239 tabcontrol.setBackground((Color)value);
240 ret = ret | XFDesignConstants.RSP_REPAINT_COMP;
243 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
245 tabcontrol.repaint();
247 case 1: if (!(value instanceof Color)) throw new XFPropertyBadValueTypeException();
248 tabcontrol.setForeground((Color)value);
249 ret = ret | XFDesignConstants.RSP_REPAINT_COMP;
252 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
254 tabcontrol.repaint();
256 case 2: if (!(value instanceof Boolean)) throw new XFPropertyBadValueTypeException();
257 tabcontrol.enable(((Boolean)value).booleanValue());
259 case 3: if (!(value instanceof Boolean)) throw new XFPropertyBadValueTypeException();
260 bVisible = ((Boolean)value).booleanValue();
262 case 4: if (!(value instanceof Font)) throw new XFPropertyBadValueTypeException();
263 tabcontrol.setFont((Font)value);
264 ret = ret | XFDesignConstants.RSP_REPAINT_COMP | XFDesignConstants.RSP_OTHER_PROP;
269 regen = regen | XFDesignConstants.GEN_RESHAPE;
274 case 5: if (!(value instanceof Boolean)) throw new XFPropertyBadValueTypeException();
275 setAutoSize(((Boolean)value).booleanValue());
278 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
279 tabcontrol.repaint();
281 regen = regen | XFDesignConstants.GEN_RESHAPE;
282 ret = ret | XFDesignConstants.RSP_REPAINT_COMP;
284 case 6: if (!(value instanceof Boolean)) throw new XFPropertyBadValueTypeException();
285 setParentColor(((Boolean)value).booleanValue());
287 ret = ret | XFDesignConstants.RSP_REPAINT_COMP;
289 case 7: if (!(value instanceof Boolean)) throw new XFPropertyBadValueTypeException();
290 setParentFont(((Boolean)value).booleanValue());
292 ret = ret | XFDesignConstants.RSP_REPAINT_COMP;
294 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
296 case 8: if (!(value instanceof String[])) throw new XFPropertyBadValueTypeException();
297 tabcontrol.removeAllTabs();
298 for (int i = 0; i < ((String [])value).length; i++)
299 tabcontrol.addTab(((String [])value)[i]);
302 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
306 case 9: if (!(value instanceof Integer)) throw new XFPropertyBadValueTypeException();
308 int newValue = ((Integer)value).intValue();
309 tabcontrol.setTabIndex(newValue);
310 tabcontrol.setVisible(newValue);
313 catch (ArrayIndexOutOfBoundsException e) {
314 System.out.println("Array Index Out Of Bounds Exception");
317 case 10:if (!(value instanceof Integer)) throw new XFPropertyBadValueTypeException();
318 tabcontrol.setMinWidth(((Integer)value).intValue());
321 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
325 case 11:if (!(value instanceof Color)) throw new XFPropertyBadValueTypeException();
326 tabcontrol.setBorderColor((Color)value);
327 ret = ret | XFDesignConstants.RSP_REPAINT_COMP;
329 case 12:if (!(value instanceof Integer)) throw new XFPropertyBadValueTypeException();
330 tabcontrol.setBorderWidth(((Integer)value).intValue());
333 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
337 case 13:if (!(value instanceof Boolean)) throw new XFPropertyBadValueTypeException();
338 tabcontrol.setDirection(((Boolean)value).booleanValue());
340 ret = ret | XFDesignConstants.RSP_OTHER_PROP;
342 default: throw new XFPropertyIndexOutOfBoundsException();
349 public void specialPropertyInput(Frame parent, int index) throws
350 XFPropertyIndexOutOfBoundsException,
351 XFPropertyNoSpecialInputException {
352 if ((index < 0) || (index >= propertyCount)) throw new XFPropertyIndexOutOfBoundsException();
355 case 1: XColorPropertyType.invokeSpecialInput(parent, this, index);
357 case 4: XFontPropertyType.invokeSpecialInput(parent, this, index);
359 case 8: XStringArrayPropertyType.invokeSpecialInput(parent, this, index);
361 case 11: XColorPropertyType.invokeSpecialInput(parent, this, index);
363 default: throw new XFPropertyNoSpecialInputException();
367 public int getEventCount() {
371 public String[] getEventNames() {
372 String list[] = new String[eventCount];
373 list[0] = "OnChangeTab";
374 list[1] = "OnGotFocus";
375 list[2] = "OnLostFocus";
379 public String getEvent(int index) throws
380 XFPropertyIndexOutOfBoundsException {
381 if ((index>=0) && (index<eventCount)) {
382 if (events[index] == null)
385 return new String(events[index]);
387 else throw new XFPropertyIndexOutOfBoundsException();
390 public void setEvent(int index, String value) throws
391 XFPropertyIndexOutOfBoundsException {
392 if ((index>=0) && (index<eventCount))
393 events[index] = value;
394 else throw new XFPropertyIndexOutOfBoundsException();
397 public String getClassName() {
401 public String generateCode(int what) {
404 case XFDesignConstants.GEN_VARIABLE:
405 gen = getClassName()+" "+ name + ";\n";
407 case XFDesignConstants.GEN_INIT:
408 gen = name + " = new " + getClassName() + "();\n";
410 case XFDesignConstants.GEN_SETPROPS:
412 propertiesSetDefault();
413 for (int i = 0; i < propertyCount; i++) {
414 if (!propertyDefault(i)) {
416 case 0: if (!parentColor)
417 gen = gen + name + ".setBackground(" +
418 XFDesignUtils.genColor(tabcontrol.getBackground()) + ");\n";
420 case 1: if (!parentColor)
421 gen = gen + name + ".setForeground(" +
422 XFDesignUtils.genColor(tabcontrol.getForeground()) + ");\n";
424 case 2: gen = gen + name + (tabcontrol.isEnabled() ? ".enable();\n" : ".disable();\n");
426 case 3: gen = gen + name + ((bVisible) ? ".show();\n" : ".hide();\n");
428 case 4: if (!parentFont) {
429 gen = gen + name + ".setFont(" +
430 XFDesignUtils.genFont(tabcontrol.getFont())+");\n";
433 case 8: for (int j = 0; j < tabcontrol.getTabCount(); j++)
434 gen = gen + name + ".addTab(\"" + tabcontrol.getTabName(j) + "\");\n";
436 case 9: gen = gen + name + ".setTabIndex(" + tabcontrol.getTabIndex() + ");\n";
438 case 10: gen = gen + name + ".setMinWidth(" + tabcontrol.getMinWidth() + ");\n";
440 case 11: gen = gen + name + ".setBorderColor(" +
441 XFDesignUtils.genColor(tabcontrol.getBorderColor()) + ");\n";
443 case 12: gen = gen + name + ".setBorderWidth(" + tabcontrol.getBorderWidth() + ");\n";
445 case 13: gen = gen + name + ".setDirection(" + (tabcontrol.getDirection() ? "true" : "false") + ");\n";
451 case XFDesignConstants.GEN_RESHAPE:
452 if (((XelfiVisualContainer) getParent()).getDesignLayout().allowsDragging()) {
454 if (getParent() instanceof XelfiDesignForm)
455 gen = name + ".reshape(insets.left+"+position.x+", insets.top+"+position.y+","+size.width+","+size.height+");\n";
457 gen = name + ".reshape("+position.x+","+position.y+","+size.width+","+size.height+");\n";
459 gen = name + ".resize(" + name + ".preferredSize());\n";
460 if (getParent() instanceof XelfiDesignForm)
461 gen = gen + name + ".move(insets.left+"+position.x+", insets.top+"+position.y+");\n";
463 gen = gen + name + ".move("+position.x+","+position.y+");\n";
471 public String generateEventCondition(int index) throws XFPropertyIndexOutOfBoundsException {
472 String evt = XFDesignOptions.eventVarName;
474 case 0: return evt +".id == TabControl.TAB_CHANGE && "+evt+".target == "+getName();
475 case 1: return evt +".id == Event.GOT_FOCUS && "+evt+".target == "+getName();
476 case 2: return evt +".id == Event.LOST_FOCUS && "+evt+".target == "+getName();
477 default: throw new XFPropertyIndexOutOfBoundsException();
481 public void loadFromStream(DataInput stream) throws IOException {
483 super.loadFromStream(stream);
486 propertiesSetDefault();
488 for (int i = 0; i < propertyCount; i++) {
489 if (stream.readBoolean())
492 case 0: tabcontrol.setBackground(XColorPropertyType.loadFromStream(stream)); break;
493 case 1: tabcontrol.setForeground(XColorPropertyType.loadFromStream(stream)); break;
494 case 2: tabcontrol.enable(XBooleanPropertyType.loadBFromStream(stream)); break;
495 case 3: bVisible = XBooleanPropertyType.loadBFromStream(stream); break;
496 case 4: tabcontrol.setFont(XFontPropertyType.loadFromStream(stream)); break;
497 case 5: setAutoSize(XBooleanPropertyType.loadBFromStream(stream)); break;
498 case 6: setParentColor(XBooleanPropertyType.loadBFromStream(stream)); break;
499 case 7: setParentFont(XBooleanPropertyType.loadBFromStream(stream)); break;
500 case 8: String[] str = (XStringArrayPropertyType.loadFromStream(stream));
501 for (int j = 0; j < str.length; j++)
502 tabcontrol.addTab(str[j]);
504 case 9: tabcontrol.setTabIndex(XIntegerPropertyType.loadFromStream(stream).intValue()); break;
505 case 10: tabcontrol.setMinWidth(XIntegerPropertyType.loadFromStream(stream).intValue()); break;
506 case 11: tabcontrol.setBorderColor(XColorPropertyType.loadFromStream(stream)); break;
507 case 12: tabcontrol.setBorderWidth(XIntegerPropertyType.loadFromStream(stream).intValue()); break;
508 case 13: tabcontrol.setDirection(XBooleanPropertyType.loadBFromStream(stream)); break;
512 for (int i = 0; i < eventCount; i++) {
513 if (stream.readBoolean())
514 parentForm.assignEvent(this, i, stream.readUTF());
518 public void saveToStream(DataOutput stream) throws IOException {
520 super.saveToStream(stream);
522 for (int i = 0; i < propertyCount; i++) {
523 boolean b = propertyDefault(i);
524 stream.writeBoolean(b);
527 case 0: XColorPropertyType.saveToStream(tabcontrol.getBackground(), stream); break;
528 case 1: XColorPropertyType.saveToStream(tabcontrol.getForeground(), stream); break;
529 case 2: XBooleanPropertyType.saveToStream(tabcontrol.isEnabled(), stream); break;
530 case 3: XBooleanPropertyType.saveToStream(bVisible, stream); break;
531 case 4: XFontPropertyType.saveToStream(tabcontrol.getFont(), stream); break;
532 case 5: XBooleanPropertyType.saveToStream(autoSize, stream); break;
533 case 6: XBooleanPropertyType.saveToStream(parentColor, stream); break;
534 case 7: XBooleanPropertyType.saveToStream(parentFont, stream); break;
535 case 8: String[] str = new String[tabcontrol.getTabCount()];
536 for (int j = 0; j < tabcontrol.getTabCount(); j++)
537 str[j] = tabcontrol.getTabName(j);
538 XStringArrayPropertyType.saveToStream(str, stream);
540 case 9: XIntegerPropertyType.saveToStream(new Integer(tabcontrol.getTabIndex()), stream); break;
541 case 10: XIntegerPropertyType.saveToStream(new Integer(tabcontrol.getMinWidth()), stream); break;
542 case 11: XColorPropertyType.saveToStream(tabcontrol.getBorderColor(), stream); break;
543 case 12: XIntegerPropertyType.saveToStream(new Integer(tabcontrol.getBorderWidth()), stream); break;
544 case 13: XBooleanPropertyType.saveToStream(tabcontrol.getDirection(), stream); break;
549 for (int i = 0; i < eventCount; i++) {
550 if ((events[i] != null) && (events[i].length() > 0)) {
551 stream.writeBoolean(true);
552 stream.writeUTF(events[i]);
554 else stream.writeBoolean(false);