1 7 8 package javax.swing; 9 10 import javax.swing.plaf.*; 11 import javax.accessibility.*; 12 13 import java.io.ObjectOutputStream ; 14 import java.io.ObjectInputStream ; 15 import java.io.IOException ; 16 17 18 52 public class JSeparator extends JComponent implements SwingConstants , Accessible 53 { 54 58 private static final String uiClassID = "SeparatorUI"; 59 60 private int orientation = HORIZONTAL; 61 62 63 public JSeparator() 64 { 65 this( HORIZONTAL ); 66 } 67 68 79 public JSeparator( int orientation ) 80 { 81 checkOrientation( orientation ); 82 this.orientation = orientation; 83 setFocusable(false); 84 updateUI(); 85 } 86 87 92 public SeparatorUI getUI() { 93 return (SeparatorUI)ui; 94 } 95 96 107 public void setUI(SeparatorUI ui) { 108 super.setUI(ui); 109 } 110 111 116 public void updateUI() { 117 setUI((SeparatorUI)UIManager.getUI(this)); 118 } 119 120 121 128 public String getUIClassID() { 129 return uiClassID; 130 } 131 132 133 138 private void writeObject(ObjectOutputStream s) throws IOException { 139 s.defaultWriteObject(); 140 if (getUIClassID().equals(uiClassID)) { 141 byte count = JComponent.getWriteObjCounter(this); 142 JComponent.setWriteObjCounter(this, --count); 143 if (count == 0 && ui != null) { 144 ui.installUI(this); 145 } 146 } 147 } 148 149 160 public int getOrientation() { 161 return this.orientation; 162 } 163 164 183 public void setOrientation( int orientation ) { 184 if (this.orientation == orientation) { 185 return; 186 } 187 int oldValue = this.orientation; 188 checkOrientation( orientation ); 189 this.orientation = orientation; 190 firePropertyChange("orientation", oldValue, orientation); 191 revalidate(); 192 repaint(); 193 } 194 195 private void checkOrientation( int orientation ) 196 { 197 switch ( orientation ) 198 { 199 case VERTICAL: 200 case HORIZONTAL: 201 break; 202 default: 203 throw new IllegalArgumentException ( "orientation must be one of: VERTICAL, HORIZONTAL" ); 204 } 205 } 206 207 208 218 protected String paramString() { 219 String orientationString = (orientation == HORIZONTAL ? 220 "HORIZONTAL" : "VERTICAL"); 221 222 return super.paramString() + 223 ",orientation=" + orientationString; 224 } 225 226 230 239 public AccessibleContext getAccessibleContext() { 240 if (accessibleContext == null) { 241 accessibleContext = new AccessibleJSeparator(); 242 } 243 return accessibleContext; 244 } 245 246 260 protected class AccessibleJSeparator extends AccessibleJComponent { 261 262 268 public AccessibleRole getAccessibleRole() { 269 return AccessibleRole.SEPARATOR; 270 } 271 } 272 } 273 | Popular Tags |