1 7 8 package org.jdesktop.jdnc.markup.attr; 9 10 import java.net.URL ; 11 12 import javax.swing.Icon ; 13 import javax.swing.ImageIcon ; 14 import javax.swing.JLabel ; 15 import javax.swing.SwingConstants ; 16 17 import net.openmarkup.ApplierException; 18 import net.openmarkup.AttributeApplier; 19 import net.openmarkup.Realizable; 20 21 import org.jdesktop.jdnc.markup.Namespace; 22 23 26 public class LabelAttributes { 27 28 public static void applyHorizontalAlignment(JLabel label, String attributeValue) { 29 32 int value = Decoder.decodeConstant(attributeValue); 33 if (value != -1) { 34 label.setHorizontalAlignment(value); 35 } 36 37 38 } 39 40 public static void applyHorizontalTextPosition(JLabel label, String attributeValue) { 41 44 int value = Decoder.decodeConstant(attributeValue); 45 if (value != -1) { 46 label.setHorizontalTextPosition(value); 47 } 48 } 49 50 public static void applyIcon(Realizable target, JLabel label, String attributeValue) { 51 try { 52 URL url = target.getResolvedURL(attributeValue); 53 if (url == null) { 54 System.out.println("Could not resolve URL: " + attributeValue); 55 } 56 else { 57 Icon icon = new ImageIcon (url); 59 label.setIcon(icon); 60 } 61 } 62 catch (Exception ex) { 63 System.out.println("LabelAttributes.iconApplier: " + ex); 64 } 65 } 66 67 public static void applyIconTextGap(JLabel label, String attributeValue) { 68 try { 69 int value = Integer.parseInt(attributeValue); 70 label.setIconTextGap(value); 71 } 72 catch (Exception ex) { 73 System.out.println("LabelAttributes.iconTextGapApplier: " + ex); 74 } 75 } 76 77 public static void applyVerticalAlignment(JLabel label, String attributeValue) { 78 int value = Decoder.decodeConstant(attributeValue); 79 if (value != -1) { 80 label.setVerticalAlignment(value); 81 } 82 } 83 84 public static void applyVerticalTextPosition(JLabel label, String attributeValue) { 85 int value = Decoder.decodeConstant(attributeValue); 86 if (value != -1) { 87 label.setVerticalTextPosition(value); 88 } 89 } 90 91 public static final AttributeApplier horizontalAlignmentApplier = new AttributeApplier() { 92 public void apply(Realizable target, String namespaceURI, 93 String attributeName, String attributeValue) { 94 applyHorizontalAlignment((JLabel )target.getObject(), attributeValue); 95 } 96 }; 97 98 public static final AttributeApplier horizontalTextPositionApplier = new AttributeApplier() { 99 public void apply(Realizable target, String namespaceURI, 100 String attributeName, String attributeValue) { 101 applyHorizontalTextPosition((JLabel )target.getObject(), attributeValue); 102 } 103 }; 104 105 public static final AttributeApplier iconApplier = new AttributeApplier() { 106 public void apply(Realizable target, String namespaceURI, 107 String attributeName, String attributeValue) throws ApplierException { 108 applyIcon(target, (JLabel )target.getObject(), attributeValue); 109 } 110 }; 111 112 public static final AttributeApplier iconTextGapApplier = new AttributeApplier() { 113 public void apply(Realizable target, String namespaceURI, 114 String attributeName, String attributeValue) throws 115 ApplierException { 116 applyIconTextGap((JLabel )target.getObject(), attributeValue); 117 } 118 }; 119 120 public static final AttributeApplier titleApplier = new AttributeApplier() { 121 public void apply(Realizable target, String namespaceURI, 122 String attributeName, String attributeValue) { 123 ((JLabel )target.getObject()).setText(attributeValue); 124 } 125 }; 126 127 public static final AttributeApplier verticalAlignmentApplier = new AttributeApplier() { 128 public void apply(Realizable target, String namespaceURI, 129 String attributeName, String attributeValue) { 130 applyVerticalAlignment((JLabel )target.getObject(), attributeValue); 131 } 132 }; 133 134 public static final AttributeApplier verticalTextPositionApplier = new AttributeApplier() { 135 public void apply(Realizable target, String namespaceURI, 136 String attributeName, String attributeValue) { 137 applyVerticalTextPosition( (JLabel ) target.getObject(), 138 attributeValue); 139 } 140 }; 141 142 } 143 | Popular Tags |