1 19 20 package org.netbeans.swing.tabcontrol.plaf; 21 22 import java.awt.event.ActionEvent ; 23 import javax.swing.Action ; 24 import javax.swing.BorderFactory ; 25 import javax.swing.Icon ; 26 import javax.swing.JButton ; 27 import org.netbeans.swing.tabcontrol.TabDisplayer; 28 import org.netbeans.swing.tabcontrol.event.TabActionEvent; 29 30 39 abstract class TabControlButton extends JButton { 40 41 public static final int ID_CLOSE_BUTTON = 1; 42 public static final int ID_PIN_BUTTON = 2; 43 public static final int ID_MAXIMIZE_BUTTON = 3; 44 public static final int ID_RESTORE_BUTTON = 4; 45 public static final int ID_SLIDE_LEFT_BUTTON = 5; 46 public static final int ID_SLIDE_RIGHT_BUTTON = 6; 47 public static final int ID_SLIDE_DOWN_BUTTON = 7; 48 public static final int ID_DROP_DOWN_BUTTON = 8; 49 public static final int ID_SCROLL_LEFT_BUTTON = 9; 50 public static final int ID_SCROLL_RIGHT_BUTTON = 10; 51 52 public static final int STATE_DEFAULT = 0; 53 public static final int STATE_PRESSED = 1; 54 public static final int STATE_DISABLED = 2; 55 public static final int STATE_ROLLOVER = 3; 56 57 private int buttonId; 58 private TabDisplayer displayer; 59 private String tabActionCommand; 60 61 64 TabControlButton( TabDisplayer displayer ) { 65 this( -1, displayer ); 66 } 67 68 72 TabControlButton( int buttonId, TabDisplayer displayer ) { 73 this.buttonId = buttonId; 74 this.displayer = displayer; 75 configureButton(); 76 } 77 78 83 protected abstract String getTabActionCommand( ActionEvent e ); 84 85 89 protected int getButtonId() { 90 return buttonId; 91 } 92 93 public Icon getIcon() { 94 if( null != displayer ) 95 return displayer.getUI().getButtonIcon( getButtonId(), STATE_DEFAULT ); 96 return null; 97 } 98 99 public Icon getPressedIcon() { 100 if( null != displayer ) 101 return displayer.getUI().getButtonIcon( getButtonId(), STATE_PRESSED ); 102 return null; 103 } 104 105 public Icon getRolloverIcon() { 106 if( null != displayer ) 107 return displayer.getUI().getButtonIcon( getButtonId(), STATE_ROLLOVER ); 108 return null; 109 } 110 111 public Icon getRolloverSelectedIcon() { 112 return getRolloverIcon(); 113 } 114 115 public Icon getDisabledIcon() { 116 if( null != displayer ) 117 return displayer.getUI().getButtonIcon( getButtonId(), STATE_DISABLED ); 118 return null; 119 } 120 121 public Icon getDisabledSelectedIcon() { 122 return getDisabledIcon(); 123 } 124 125 public void updateUI() { 126 super.updateUI(); 127 configureButton(); 128 } 129 130 133 protected void configureButton() { 134 setFocusable( false ); 135 setContentAreaFilled( false ); 136 setBorderPainted( false ); 137 setBorder( BorderFactory.createEmptyBorder() ); 138 setRolloverEnabled( getRolloverIcon() != null ); 139 } 140 141 protected void fireActionPerformed(ActionEvent event) { 142 super.fireActionPerformed(event); 143 performAction( event ); 144 getModel().setRollover( false ); 146 } 147 148 151 void performAction( ActionEvent e ) { 152 displayer.getUI().postTabAction( createTabActionEvent( e ) ); 153 } 154 155 158 protected TabActionEvent createTabActionEvent( ActionEvent e ) { 159 return new TabActionEvent( this, getTabActionCommand( e ), displayer.getSelectionModel().getSelectedIndex() ); 160 } 161 162 protected TabDisplayer getTabDisplayer() { 163 return displayer; 164 } 165 } 166 | Popular Tags |