1 30 31 package com.jgoodies.looks; 32 33 import javax.swing.JComponent ; 34 import javax.swing.JMenuBar ; 35 import javax.swing.JToolBar ; 36 37 46 public final class BorderStyle { 47 48 public static final BorderStyle EMPTY = new BorderStyle("Empty"); 49 public static final BorderStyle SEPARATOR = new BorderStyle("Separator"); 50 public static final BorderStyle ETCHED = new BorderStyle("Etched"); 51 52 private final String name; 53 54 55 57 private BorderStyle(String name) { 58 this.name = name; 59 } 60 61 62 64 71 public static BorderStyle from(JToolBar toolBar, String clientPropertyKey) { 72 return from0(toolBar, clientPropertyKey); 73 } 74 75 83 public static BorderStyle from(JMenuBar menuBar, String clientPropertyKey) { 84 return from0(menuBar, clientPropertyKey); 85 } 86 87 97 private static BorderStyle from0(JComponent c, String clientPropertyKey) { 98 Object value = c.getClientProperty(clientPropertyKey); 99 if (value instanceof BorderStyle) 100 return (BorderStyle) value; 101 102 if (value instanceof String ) { 103 return BorderStyle.valueOf((String ) value); 104 } 105 106 return null; 107 } 108 109 private static BorderStyle valueOf(String name) { 110 if (name.equalsIgnoreCase(EMPTY.name)) 111 return EMPTY; 112 else if (name.equalsIgnoreCase(SEPARATOR.name)) 113 return SEPARATOR; 114 else if (name.equalsIgnoreCase(ETCHED.name)) 115 return ETCHED; 116 else 117 throw new IllegalArgumentException ("Invalid BorderStyle name " 118 + name); 119 } 120 121 public String toString() { 122 return name; 123 } 124 125 } | Popular Tags |