001 /*
002 * Copyright 2007 - 2007 JEuclid, http://jeuclid.sf.net
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017 /* $Id: JMathComponentBeanInfo.java 312 2007-05-19 07:46:11Z maxberger $ */
018
019 package net.sourceforge.jeuclid.swing;
020
021 import java.awt.Image;
022 import java.beans.BeanDescriptor;
023 import java.beans.BeanInfo;
024 import java.beans.IntrospectionException;
025 import java.beans.PropertyDescriptor;
026 import java.beans.SimpleBeanInfo;
027
028 import javax.swing.ImageIcon;
029
030 /**
031 * This is the class providing bean information about the swing component
032 * {@link JMathComponent}. This class might be useful for applications using
033 * JEuclid in their application. With help of this class they can query useful
034 * information about JMathComponent when the application uses it as a bean.
035 *
036 * @author Matthias Hanisch
037 * @author Max Berger
038 * @version $Revision: 312 $
039 */
040 public class JMathComponentBeanInfo extends SimpleBeanInfo {
041 private static final Class<JMathComponent> BEANCLASS = JMathComponent.class;
042
043 private final Image icoColor16 = new ImageIcon(
044 JMathComponentBeanInfo.BEANCLASS
045 .getResource("/icons/jeuclid_16x16.png")).getImage();
046
047 private final Image icoColor32 = new ImageIcon(
048 JMathComponentBeanInfo.BEANCLASS
049 .getResource("/icons/jeuclid_32x32.png")).getImage();
050
051 private final Image icoBw16 = new ImageIcon(
052 JMathComponentBeanInfo.BEANCLASS
053 .getResource("/icons/jeuclid_16x16_bw.png")).getImage();
054
055 private final Image icoBw32 = new ImageIcon(
056 JMathComponentBeanInfo.BEANCLASS
057 .getResource("/icons/jeuclid_32x32_bw.png")).getImage();
058
059 /**
060 * Default Constructor.
061 */
062 public JMathComponentBeanInfo() {
063 // Empty on purpose.
064 }
065
066 /** {@inheritDoc} */
067 @Override
068 public Image getIcon(final int iconKind) {
069 final Image retVal;
070 switch (iconKind) {
071 case BeanInfo.ICON_COLOR_16x16:
072 retVal = this.icoColor16;
073 break;
074 case BeanInfo.ICON_COLOR_32x32:
075 retVal = this.icoColor32;
076 break;
077 case BeanInfo.ICON_MONO_16x16:
078 retVal = this.icoBw16;
079 break;
080 case BeanInfo.ICON_MONO_32x32:
081 retVal = this.icoBw32;
082 break;
083 default:
084 return this.icoColor32;
085 }
086 return retVal;
087 }
088
089 /** {@inheritDoc} */
090 @Override
091 public BeanDescriptor getBeanDescriptor() {
092 final BeanDescriptor beanDescriptor = new BeanDescriptor(
093 JMathComponentBeanInfo.BEANCLASS);
094 beanDescriptor.setName("JEuclid");
095 beanDescriptor.setDisplayName("JEuclid Bean");
096 beanDescriptor
097 .setShortDescription("The JEuclid project creates the possibility to "
098 + "display MathML content. "
099 + "This Bean supports rendering MathML content as a Swing component.");
100 return beanDescriptor;
101 }
102
103 /** {@inheritDoc} */
104 @Override
105 public PropertyDescriptor[] getPropertyDescriptors() {
106 try {
107 final PropertyDescriptor propertyFontSize = this
108 .createPropertyDescriptor("fontSize", "Font size",
109 "This will modify the font size of the displayed MathML elements");
110
111 final PropertyDescriptor propertyContent = this
112 .createPropertyDescriptor("content", "Content",
113 "The XML content for the JEuclid Bean");
114
115 final PropertyDescriptor fgContent = this
116 .createPropertyDescriptor("foreground",
117 "Foreground Color",
118 "Foreground color if not specified within the document");
119
120 final PropertyDescriptor bgContent = this
121 .createPropertyDescriptor("background",
122 "Background Color",
123 "Background color for this component");
124
125 final PropertyDescriptor opaqueContent = this
126 .createPropertyDescriptor("opaque", "Opaque",
127 "If true, will always overpaint the background");
128
129 final PropertyDescriptor fontsContent1 = this
130 .createPropertyDescriptor("fontsSerif", "Serif Fonts",
131 "Fonts to use for Serif characters (the default font)");
132 final PropertyDescriptor fontsContent2 = this
133 .createPropertyDescriptor("fontsSanserif",
134 "Sans-Serif Fonts",
135 "Fonts to use for Sans-Serif characters");
136 final PropertyDescriptor fontsContent3 = this
137 .createPropertyDescriptor("fontsMonospaced",
138 "Monospaced Fonts",
139 "Fonts to use for Monospaced characters");
140 final PropertyDescriptor fontsContent4 = this
141 .createPropertyDescriptor("fontsScript", "Script Fonts",
142 "Fonts to use for Script characters");
143 final PropertyDescriptor fontsContent5 = this
144 .createPropertyDescriptor("fontsFraktur",
145 "Fraktur Fonts",
146 "Fonts to use for Fraktur characters");
147 final PropertyDescriptor fontsContent6 = this
148 .createPropertyDescriptor("fontsDoublestruck",
149 "Double-Struck Fonts",
150 "Fonts to use for Double-Struck characters");
151
152 final PropertyDescriptor vAlign = this
153 .createPropertyDescriptor("verticalAlignment",
154 "Vertical Alignment",
155 "Vertical alignment, as defined by javax.swing.JLabel#getHorizontalAlignment");
156
157 final PropertyDescriptor hAlign = this
158 .createPropertyDescriptor(
159 "horizontalAlignment",
160 "Horizontal Alignment",
161 "Horizontal alignment, as defined by javax.swing.JLabel#getHorizontalAlignment");
162 final PropertyDescriptor border = this.createPropertyDescriptor(
163 "border", "Border", "Swing Border Property");
164
165 return new PropertyDescriptor[] { propertyContent,
166 propertyFontSize, fgContent, bgContent, opaqueContent,
167 fontsContent1, fontsContent2, fontsContent3,
168 fontsContent4, fontsContent5, fontsContent6, vAlign,
169 hAlign, border, };
170 } catch (final IntrospectionException ex) {
171 // should never occur as we know which classes/methods can be used
172 // in this BeanInfo class
173 return super.getPropertyDescriptors();
174 }
175 }
176
177 private PropertyDescriptor createPropertyDescriptor(
178 final String attribute, final String displayName,
179 final String description) throws IntrospectionException {
180 final PropertyDescriptor propertyFontSize = new PropertyDescriptor(
181 attribute, JMathComponentBeanInfo.BEANCLASS);
182 propertyFontSize.setDisplayName(displayName);
183 propertyFontSize.setShortDescription(description);
184 return propertyFontSize;
185 }
186 }