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 47 public final class HeaderStyle { 48 49 public static final HeaderStyle SINGLE = new HeaderStyle("Single"); 50 public static final HeaderStyle BOTH = new HeaderStyle("Both"); 51 52 private final String name; 53 54 55 private HeaderStyle(String name) { 56 this.name = name; 57 } 58 59 60 67 public static HeaderStyle from(JMenuBar menuBar) { 68 return from0(menuBar); 69 } 70 71 72 79 public static HeaderStyle from(JToolBar toolBar) { 80 return from0(toolBar); 81 } 82 83 84 91 private static HeaderStyle from0(JComponent c) { 92 Object value = c.getClientProperty(Options.HEADER_STYLE_KEY); 93 if (value instanceof HeaderStyle) 94 return (HeaderStyle) value; 95 96 if (value instanceof String ) { 97 return HeaderStyle.valueOf((String ) value); 98 } 99 100 return null; 101 } 102 103 104 110 private static HeaderStyle valueOf(String name) { 111 if (name.equalsIgnoreCase(SINGLE.name)) 112 return SINGLE; 113 else if (name.equalsIgnoreCase(BOTH.name)) 114 return BOTH; 115 else 116 throw new IllegalArgumentException ("Invalid HeaderStyle name " + name); 117 } 118 119 120 public String toString() { 121 return name; 122 } 123 124 } | Popular Tags |