View Javadoc

1   /*
2    * Copyright (c) 2003-2008 by Cosylab d. d.
3    *
4    * This file is part of CosyBeans-Common.
5    *
6    * CosyBeans-Common is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * CosyBeans-Common is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with CosyBeans-Common.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  
20  package com.cosylab.gui.components;
21  
22  import java.awt.Component;
23  import java.beans.IntrospectionException;
24  import java.beans.PropertyEditorSupport;
25  
26  import com.cosylab.util.BeanInfoSupport;
27  
28  
29  /**
30   * @author Igor Kriznar (igor.kriznarATcosylab.com)
31   *
32   */
33  public class AbstractDisplayerPanelBeanInfo extends BeanInfoSupport {
34  	
35  	public class OrientationPropertyEditor extends PropertyEditorSupport {
36  		private static final String DYNAMIC_LAYOUT = "Automatic Layout";
37  		private static final String VERTICAL_LAYOUT = "Vertical Layout";
38  		private static final String HORIZONTAL_LAYOUT = "Horizontal Layout";
39  
40  		private int value=0;
41  
42  		public boolean isPaintable() {
43  			return false;
44  		}
45  
46  		public boolean supportsCustomEditor() {
47  			return false;
48  		}
49  
50  		public Component getCustomEditor() {
51  			return null;
52  		}
53  
54  		public Object getValue() {
55  			return new Integer(value);
56  		}
57  
58  		public void setValue(Object value) {
59  			this.value = ((Number)value).intValue();
60  			firePropertyChange();
61  		}
62  
63  		public String getAsText() {
64  			if (value==AbstractDisplayerPanel.DYNAMIC_LAYOUT) return DYNAMIC_LAYOUT;
65  			if (value==AbstractDisplayerPanel.HORIZONTAL_LAYOUT) return HORIZONTAL_LAYOUT;
66  			if (value==AbstractDisplayerPanel.VERTICAL_LAYOUT) return VERTICAL_LAYOUT;
67  			return null;
68  		}
69  
70  		public String getJavaInitializationString() {
71  			return Integer.toString(value);
72  		}
73  
74  		public String[] getTags() {
75  			return new String[]{HORIZONTAL_LAYOUT,VERTICAL_LAYOUT,DYNAMIC_LAYOUT};
76  		}
77  
78  		public void setAsText(String text) throws IllegalArgumentException {
79  			if (text.equals(DYNAMIC_LAYOUT)) value = AbstractDisplayerPanel.DYNAMIC_LAYOUT;
80  			if (text.equals(HORIZONTAL_LAYOUT)) value = AbstractDisplayerPanel.HORIZONTAL_LAYOUT;
81  			if (text.equals(VERTICAL_LAYOUT)) value = AbstractDisplayerPanel.VERTICAL_LAYOUT;			
82  			firePropertyChange();
83  		}
84  
85  	}	
86  
87  	
88  	/**
89  	 * Creates new instance of AbstractDisplayerPanelBeanInfo.
90  	 * @throws IntrospectionException 
91  	 */
92  	public AbstractDisplayerPanelBeanInfo() throws IntrospectionException {
93  		setBeanDescriptor(AbstractDisplayerPanelCustomizer.class);
94  		loadDefaultPropertyDescriptors();
95  		setPropertyEditor("layoutOrientation",OrientationPropertyEditor.class);
96  		removePropertyDescriptor("state");
97  	}
98  
99  }