1 7 8 package org.jdesktop.jdnc.markup.attr; 9 10 import java.awt.Color ; 11 import java.awt.Component ; 12 import java.awt.Dimension ; 13 import java.awt.Font ; 14 15 import javax.swing.JComponent ; 16 17 import net.openmarkup.AttributeApplier; 18 import net.openmarkup.Realizable; 19 20 import org.jdesktop.jdnc.markup.Attributes; 21 import org.jdesktop.jdnc.markup.Namespace; 22 23 27 public class ComponentAttributes { 28 29 public static void applyBackground(Component component, String attributeValue) { 30 Color value = Decoder.decodeColor(attributeValue); 31 if (value != null) { 32 component.setBackground(value); 33 } 34 } 35 36 public static void applyForeground(Component component, String attributeValue) { 37 Color value = Decoder.decodeColor(attributeValue); 38 if (value != null) { 39 component.setForeground(value); 40 } 41 } 42 43 45 public static final AttributeApplier backgroundApplier = new AttributeApplier() { 46 public void apply(Realizable target, String namespaceURI, 47 String attributeName, String attributeValue) { 48 applyBackground((Component )target.getObject(), attributeValue); 49 } 50 }; 51 52 public static final AttributeApplier isEnabledApplier = new AttributeApplier() { 53 public void apply(Realizable target, String namespaceURI, 54 String attributeName, String attributeValue) { 55 Component component = (Component ) target.getObject(); 56 boolean isEnabled = Boolean.valueOf(attributeValue).booleanValue(); 57 component.setEnabled(isEnabled); 58 } 59 }; 60 61 public static final AttributeApplier isVisibleApplier = new AttributeApplier() { 62 public void apply(Realizable target, String namespaceURI, 63 String attributeName, String attributeValue) { 64 Component component = (Component ) target.getObject(); 65 boolean isVisible = Boolean.valueOf(attributeValue).booleanValue(); 66 component.setVisible(isVisible); 67 } 68 }; 69 70 public static final AttributeApplier fontApplier = new AttributeApplier() { 71 public void apply(Realizable target, String namespaceURI, 72 String attributeName, String attributeValue) { 73 Component component = (Component ) target.getObject(); 74 Font font = (Font )BaseAttribute.getReferencedObject(target, attributeValue); 75 component.setFont(font); 76 } 77 }; 78 79 public static final AttributeApplier foregroundApplier = new 80 AttributeApplier() { 81 public void apply(Realizable target, String namespaceURI, 82 String attributeName, String attributeValue) { 83 applyForeground( (Component ) target.getObject(), attributeValue); 84 } 85 }; 86 87 public static final AttributeApplier nameApplier = new AttributeApplier() { 88 public void apply(Realizable target, String namespaceURI, 89 String attributeName, String attributeValue) { 90 JComponent component = (JComponent ) target.getObject(); 91 component.setName(attributeValue); 92 } 93 }; 94 95 public static final AttributeApplier preferredSizeApplier = new AttributeApplier() { 96 public void apply(Realizable target, String namespaceURI, 97 String attributeName, String attributeValue) { 98 String [] args = attributeValue.split("\\s"); 99 if (args.length == 2) { 100 Dimension size = new Dimension ( 101 Integer.parseInt(args[0]), Integer.parseInt(args[1])); 102 JComponent component = (JComponent ) target.getObject(); 103 component.setPreferredSize(size); 104 } 105 } 106 }; 107 108 public static final AttributeApplier sizeApplier = new AttributeApplier() { 109 public void apply(Realizable target, String namespaceURI, 110 String attributeName, String attributeValue) { 111 String [] args = attributeValue.split("\\s"); 112 if (args.length == 2) { 113 Dimension size = new Dimension ( 114 Integer.parseInt(args[0]), Integer.parseInt(args[1])); 115 JComponent component = (JComponent ) target.getObject(); 116 component.setSize(size); 117 } 118 } 119 }; 120 121 } 123 | Popular Tags |