View Javadoc

1   /*
2    * Copyright 2007 - 2007 JEuclid, http://jeuclid.sf.net
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  
17  /* $Id: JMathComponentBeanInfo.java 518 2007-09-14 08:29:58Z maxberger $ */
18  
19  package net.sourceforge.jeuclid.swing;
20  
21  import java.awt.Image;
22  import java.beans.BeanDescriptor;
23  import java.beans.BeanInfo;
24  import java.beans.IntrospectionException;
25  import java.beans.PropertyDescriptor;
26  import java.beans.SimpleBeanInfo;
27  
28  import javax.swing.ImageIcon;
29  
30  /**
31   * This is the class providing bean information about the swing component
32   * {@link JMathComponent}. This class might be useful for applications using
33   * JEuclid in their application. With help of this class they can query useful
34   * information about JMathComponent when the application uses it as a bean.
35   * 
36   * @version $Revision: 518 $
37   */
38  public class JMathComponentBeanInfo extends SimpleBeanInfo {
39      private static final Class<JMathComponent> BEANCLASS = JMathComponent.class;
40  
41      private final Image icoColor16 = new ImageIcon(
42              JMathComponentBeanInfo.BEANCLASS
43                      .getResource("/icons/jeuclid_16x16.png")).getImage();
44  
45      private final Image icoColor32 = new ImageIcon(
46              JMathComponentBeanInfo.BEANCLASS
47                      .getResource("/icons/jeuclid_32x32.png")).getImage();
48  
49      private final Image icoBw16 = new ImageIcon(
50              JMathComponentBeanInfo.BEANCLASS
51                      .getResource("/icons/jeuclid_16x16_bw.png")).getImage();
52  
53      private final Image icoBw32 = new ImageIcon(
54              JMathComponentBeanInfo.BEANCLASS
55                      .getResource("/icons/jeuclid_32x32_bw.png")).getImage();
56  
57      /**
58       * Default Constructor.
59       */
60      public JMathComponentBeanInfo() {
61          // Empty on purpose.
62      }
63  
64      /** {@inheritDoc} */
65      @Override
66      public Image getIcon(final int iconKind) {
67          final Image retVal;
68          switch (iconKind) {
69          case BeanInfo.ICON_COLOR_16x16:
70              retVal = this.icoColor16;
71              break;
72          case BeanInfo.ICON_COLOR_32x32:
73              retVal = this.icoColor32;
74              break;
75          case BeanInfo.ICON_MONO_16x16:
76              retVal = this.icoBw16;
77              break;
78          case BeanInfo.ICON_MONO_32x32:
79              retVal = this.icoBw32;
80              break;
81          default:
82              return this.icoColor32;
83          }
84          return retVal;
85      }
86  
87      /** {@inheritDoc} */
88      @Override
89      public BeanDescriptor getBeanDescriptor() {
90          final BeanDescriptor beanDescriptor = new BeanDescriptor(
91                  JMathComponentBeanInfo.BEANCLASS);
92          beanDescriptor.setName("JEuclid");
93          beanDescriptor.setDisplayName("JEuclid Bean");
94          beanDescriptor
95                  .setShortDescription("The JEuclid project creates the possibility to "
96                          + "display MathML content. "
97                          + "This Bean supports rendering MathML content as a Swing component.");
98          return beanDescriptor;
99      }
100 
101     /** {@inheritDoc} */
102     @Override
103     public PropertyDescriptor[] getPropertyDescriptors() {
104         try {
105             final PropertyDescriptor propertyFontSize = this
106                     .createPropertyDescriptor("fontSize", "Font size",
107                             "This will modify the font size of the displayed MathML elements");
108 
109             final PropertyDescriptor propertyContent = this
110                     .createPropertyDescriptor("content", "Content",
111                             "The XML content for the JEuclid Bean");
112 
113             final PropertyDescriptor fgContent = this
114                     .createPropertyDescriptor("foreground",
115                             "Foreground Color",
116                             "Foreground color if not specified within the document");
117 
118             final PropertyDescriptor bgContent = this
119                     .createPropertyDescriptor("background",
120                             "Background Color",
121                             "Background color for this component");
122 
123             final PropertyDescriptor opaqueContent = this
124                     .createPropertyDescriptor("opaque", "Opaque",
125                             "If true, will always overpaint the background");
126 
127             final PropertyDescriptor fontsContent1 = this
128                     .createPropertyDescriptor("fontsSerif", "Serif Fonts",
129                             "Fonts to use for Serif characters (the default font)");
130             final PropertyDescriptor fontsContent2 = this
131                     .createPropertyDescriptor("fontsSanserif",
132                             "Sans-Serif Fonts",
133                             "Fonts to use for Sans-Serif characters");
134             final PropertyDescriptor fontsContent3 = this
135                     .createPropertyDescriptor("fontsMonospaced",
136                             "Monospaced Fonts",
137                             "Fonts to use for Monospaced characters");
138             final PropertyDescriptor fontsContent4 = this
139                     .createPropertyDescriptor("fontsScript", "Script Fonts",
140                             "Fonts to use for Script characters");
141             final PropertyDescriptor fontsContent5 = this
142                     .createPropertyDescriptor("fontsFraktur",
143                             "Fraktur Fonts",
144                             "Fonts to use for Fraktur characters");
145             final PropertyDescriptor fontsContent6 = this
146                     .createPropertyDescriptor("fontsDoublestruck",
147                             "Double-Struck Fonts",
148                             "Fonts to use for Double-Struck characters");
149 
150             final PropertyDescriptor vAlign = this
151                     .createPropertyDescriptor("verticalAlignment",
152                             "Vertical Alignment",
153                             "Vertical alignment, as defined by javax.swing.JLabel#getHorizontalAlignment");
154 
155             final PropertyDescriptor hAlign = this
156                     .createPropertyDescriptor(
157                             "horizontalAlignment",
158                             "Horizontal Alignment",
159                             "Horizontal alignment, as defined by javax.swing.JLabel#getHorizontalAlignment");
160             final PropertyDescriptor border = this.createPropertyDescriptor(
161                     "border", "Border", "Swing Border Property");
162 
163             return new PropertyDescriptor[] { propertyContent,
164                     propertyFontSize, fgContent, bgContent, opaqueContent,
165                     fontsContent1, fontsContent2, fontsContent3,
166                     fontsContent4, fontsContent5, fontsContent6, vAlign,
167                     hAlign, border, };
168         } catch (final IntrospectionException ex) {
169             // should never occur as we know which classes/methods can be used
170             // in this BeanInfo class
171             return super.getPropertyDescriptors();
172         }
173     }
174 
175     private PropertyDescriptor createPropertyDescriptor(
176             final String attribute, final String displayName,
177             final String description) throws IntrospectionException {
178         final PropertyDescriptor propertyFontSize = new PropertyDescriptor(
179                 attribute, JMathComponentBeanInfo.BEANCLASS);
180         propertyFontSize.setDisplayName(displayName);
181         propertyFontSize.setShortDescription(description);
182         return propertyFontSize;
183     }
184 }