View Javadoc

1   /*
2      Copyright 2006 Martin van den Bemt
3   
4      Licensed under the Apache License, Version 2.0 (the "License");
5      you may not use this file except in compliance with the License.
6      You may obtain a copy of the License at
7   
8          http://www.apache.org/licenses/LICENSE-2.0
9   
10     Unless required by applicable law or agreed to in writing, software
11     distributed under the License is distributed on an "AS IS" BASIS,
12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13     See the License for the specific language governing permissions and
14     limitations under the License.
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   * @author <a href="mailto:martin@mvdb.net">Martin van den Bemt</a>
28   * @version $Id: $
29   */
30  public class SizeProperty extends SwingProperty {
31  
32      /**
33       * 
34       */
35      public SizeProperty() {
36          super();
37      }
38  
39      /**
40       * TODO : Add propertyhandlerexception to interface !
41       * @see org.xulux.api.gui.IPropertyHandler#handleProperty(org.xulux.api.gui.IWidget, java.lang.String)
42       * @throws PropertyHandlerException
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  }