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,v 8afef6dd0d58 2007/09/14 08:29:58 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 * @version $Revision: 8afef6dd0d58 $ 037 */ 038 public class JMathComponentBeanInfo extends SimpleBeanInfo { 039 private static final Class<JMathComponent> BEANCLASS = JMathComponent.class; 040 041 private final Image icoColor16 = new ImageIcon( 042 JMathComponentBeanInfo.BEANCLASS 043 .getResource("/icons/jeuclid_16x16.png")).getImage(); 044 045 private final Image icoColor32 = new ImageIcon( 046 JMathComponentBeanInfo.BEANCLASS 047 .getResource("/icons/jeuclid_32x32.png")).getImage(); 048 049 private final Image icoBw16 = new ImageIcon( 050 JMathComponentBeanInfo.BEANCLASS 051 .getResource("/icons/jeuclid_16x16_bw.png")).getImage(); 052 053 private final Image icoBw32 = new ImageIcon( 054 JMathComponentBeanInfo.BEANCLASS 055 .getResource("/icons/jeuclid_32x32_bw.png")).getImage(); 056 057 /** 058 * Default Constructor. 059 */ 060 public JMathComponentBeanInfo() { 061 // Empty on purpose. 062 } 063 064 /** {@inheritDoc} */ 065 @Override 066 public Image getIcon(final int iconKind) { 067 final Image retVal; 068 switch (iconKind) { 069 case BeanInfo.ICON_COLOR_16x16: 070 retVal = this.icoColor16; 071 break; 072 case BeanInfo.ICON_COLOR_32x32: 073 retVal = this.icoColor32; 074 break; 075 case BeanInfo.ICON_MONO_16x16: 076 retVal = this.icoBw16; 077 break; 078 case BeanInfo.ICON_MONO_32x32: 079 retVal = this.icoBw32; 080 break; 081 default: 082 return this.icoColor32; 083 } 084 return retVal; 085 } 086 087 /** {@inheritDoc} */ 088 @Override 089 public BeanDescriptor getBeanDescriptor() { 090 final BeanDescriptor beanDescriptor = new BeanDescriptor( 091 JMathComponentBeanInfo.BEANCLASS); 092 beanDescriptor.setName("JEuclid"); 093 beanDescriptor.setDisplayName("JEuclid Bean"); 094 beanDescriptor 095 .setShortDescription("The JEuclid project creates the possibility to " 096 + "display MathML content. " 097 + "This Bean supports rendering MathML content as a Swing component."); 098 return beanDescriptor; 099 } 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 }