1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.xulux.guilayer.swing.properties;
17
18 import java.awt.Component;
19 import java.util.StringTokenizer;
20
21 import org.xulux.api.gui.IProperty;
22 import org.xulux.api.gui.IWidget;
23 import org.xulux.api.gui.PropertyHandlerException;
24
25
26
27
28
29
30 public class SizeProperty extends SwingProperty {
31
32
33
34
35 public SizeProperty() {
36 super();
37 }
38
39
40
41
42
43
44 public boolean handleProperty(IWidget widget, IProperty property) {
45 if (widget.getNativeWidget() instanceof Component) {
46 Component comp = (Component) widget.getNativeWidget();
47 int width = -1;
48 int height = -1;
49 try {
50 StringTokenizer stn = new StringTokenizer(property.getValue(), ",");
51 String xStr = stn.nextToken().trim();
52 String yStr = stn.nextToken().trim();
53 width = Integer.parseInt(xStr);
54 height = Integer.parseInt(yStr);
55 }
56 catch (Exception nse) {
57 throw new PropertyHandlerException("Parsing error! Format should be width,heigth");
58 }
59 comp.setSize(width, height);
60 }
61 return false;
62 }
63
64 }