[Mc4j-cvs] mc4j/src/org/mc4j/console/dashboard BorderFactory.java,1.5,1.6
Brought to you by:
ghinkl
From: Greg H. <gh...@us...> - 2004-04-02 03:46:37
|
Update of /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17719/src/org/mc4j/console/dashboard Modified Files: BorderFactory.java Log Message: Added support for Line borders Index: BorderFactory.java =================================================================== RCS file: /cvsroot/mc4j/mc4j/src/org/mc4j/console/dashboard/BorderFactory.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** BorderFactory.java 7 Feb 2004 16:10:41 -0000 1.5 --- BorderFactory.java 2 Apr 2004 03:34:33 -0000 1.6 *************** *** 21,28 **** --- 21,37 ---- import java.awt.Color; + import java.beans.PropertyEditor; + import java.beans.PropertyEditorManager; + import java.util.Map; import javax.swing.border.Border; import javax.swing.border.TitledBorder; + import org.openide.ErrorManager; + import org.openide.windows.IOProvider; + + import org.mc4j.console.dashboard.context.ContextHelper; + import org.mc4j.console.util.BeanUtil; + import org.w3c.dom.Element; *************** *** 40,44 **** public static final String TYPE = "type"; ! public Border buildBorder(Element element) { String type = element.getAttribute(TYPE); --- 49,53 ---- public static final String TYPE = "type"; ! public Border buildBorder(Element element, Map context) { String type = element.getAttribute(TYPE); *************** *** 47,75 **** TitledBorder border = new TitledBorder("Initial"); return border; ! /* ! GridBagConstraints c = new GridBagConstraints(); ! ! if (element.getAttribute("gridx") != null) { ! c.gridx = Integer.parseInt(element.getAttribute("gridx")); ! } ! ! if (element.getAttribute("gridy") != null) { ! c.gridx = Integer.parseInt(element.getAttribute("gridy")); ! } ! ! if (element.getAttribute("weightx") != null) { ! c.gridx = Integer.parseInt(element.getAttribute("weightx")); ! } ! if (element.getAttribute("weighty") != null) { ! c.gridx = Integer.parseInt(element.getAttribute("weighty")); } - - //gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; - //gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; - //gridBagConstraints.insets = new java.awt.Insets(9, 0, 9, 10); - - return c;*/ } ! return javax.swing.BorderFactory.createLineBorder(Color.green); } } --- 56,119 ---- TitledBorder border = new TitledBorder("Initial"); return border; ! ! } else if (type.equals("javax.swing.border.LineBorder")) { ! Class borderType = javax.swing.border.LineBorder.class; ! // Attributes: color, thickness, *roundedCorners ! ! ! String colorString = element.getAttribute("color"); ! Color color = (Color) getAttributeValue(colorString,context, Color.class, borderType); ! ! String thicknessString = element.getAttribute("thickness"); ! Integer thickness = (Integer) getAttributeValue(thicknessString, context, Integer.class, borderType); ! ! //String roundedCornersString = element.getAttribute("roundedCornersString"); ! //Boolean roundedCorners = (Boolean) getAttributeValue(roundedCornersString, context, Boolean.class, borderType); ! ! if (color == null) ! IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). ! println("You must provide a color attribute for a LineBorder declaration."); ! if (thickness == null) ! IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). ! println("You must provide a thickness attribute for a LineBorder declaration."); ! //if (roundedCorners == null) ! // IOProvider.getDefault().getIO("Dashboard debugging",false).getOut(). ! // println("You must provide a roundedCorners attribute for a LineBorder declaration."); ! ! return javax.swing.BorderFactory.createLineBorder(color, thickness.intValue()); ! } ! return javax.swing.BorderFactory.createLineBorder(Color.green, 5); ! } ! ! private Object getAttributeValue(String attributeString, Map context, Class attributeType, Class borderType) { ! Object value = null; ! ! try { ! value = ContextHelper.getValue(attributeString, context); ! } catch (RuntimeException re) { ! ErrorManager.getDefault().notify(re); ! } ! ! if (value instanceof String) { ! String valueString = (String) value; ! try { ! PropertyEditor editor = PropertyEditorManager.findEditor(attributeType); ! editor.setAsText(valueString); ! value = editor.getValue(); ! } catch (IllegalArgumentException iae) { ! // Perhaps its a constant? ! Object constValue = null; ! try { ! constValue = BeanUtil.getStaticFieldValue(borderType, valueString); ! } catch(NoSuchFieldException nsfe) { ! ! } catch(IllegalAccessException iae2) { ! ! } ! if (constValue != null) ! value = constValue; } } ! return value; } } |