1 29 38 39 package org.planetamessenger.mos.forms.preferences; 40 41 import java.awt.*; 42 import java.awt.event.*; 43 import javax.swing.*; 44 import javax.swing.tree.*; 45 import javax.swing.event.*; 46 import javax.swing.text.*; 47 import javax.swing.text.html.*; 48 import java.util.*; 49 import javax.swing.event.*; 50 import javax.swing.border.*; 51 import com.jgoodies.forms.builder.*; 52 import com.jgoodies.forms.layout.*; 53 import com.jgoodies.forms.debug.*; 54 import org.planetamessenger.mos.engine.*; 55 import org.planetamessenger.mos.ui.*; 56 import org.planetamessenger.plugin.*; 57 import org.planetamessenger.ui.*; 58 59 60 public class JYesNoPanel extends JPluginPreferencesContainer { 61 62 public static final int YES_BUTTON = 0; 63 public static final int NO_BUTTON = 1; 64 65 private FormLayout layout = null; 66 private PanelBuilder builder = null; 67 private String strCaption = null; 68 private JLabel caption = null; 69 private JButton yesButton = null; 70 private JButton noButton = null; 71 private ArrayList<ActionListener> listener = null; 72 73 74 78 public JYesNoPanel( String strCaption ) { 79 80 super(); 81 82 CellConstraints cellConst = new CellConstraints(); 83 Box btnsPanel = Box.createHorizontalBox(); 84 85 86 this.listener = new ArrayList<ActionListener>(); 87 this.yesButton = new JButton(); 88 this.noButton = new JButton(); 89 this.caption = new JLabel(); 90 this.layout = new FormLayout( "center:250dlu", "center:pref, center:pref" ); 91 this.builder = new PanelBuilder( layout ); 92 this.strCaption = strCaption; 93 94 caption.setOpaque( false ); 95 caption.setFont( JSystemFonts.FONT ); 96 97 yesButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) ); 98 yesButton.setMinimumSize( yesButton.getPreferredSize() ); 99 yesButton.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) ); 100 yesButton.addActionListener( new ActionListener() { 101 public void actionPerformed( java.awt.event.ActionEvent evt ) { 102 fireOnButtonAction( YES_BUTTON ); 103 } 104 } ); 105 106 noButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) ); 107 noButton.setMinimumSize( noButton.getPreferredSize() ); 108 noButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) ); 109 noButton.addActionListener( new ActionListener() { 110 public void actionPerformed( java.awt.event.ActionEvent evt ) { 111 fireOnButtonAction( NO_BUTTON ); 112 } 113 } ); 114 115 btnsPanel.add( javax.swing.Box.createHorizontalGlue() ); 116 btnsPanel.add( noButton ); 117 btnsPanel.add( yesButton ); 118 119 builder.setDefaultDialogBorder(); 120 builder.add( caption, cellConst.xy( 1, 1 ) ); 121 builder.add( btnsPanel, cellConst.xy( 1, 2 ) ); 122 } 123 124 131 private void fireOnButtonAction( int nButton ) { 132 133 ArrayList<ActionListener> cloneListener = ( ArrayList<ActionListener> ) listener.clone(); 134 JButton button = ( nButton == YES_BUTTON ? yesButton : noButton ); 135 ActionEvent evt = new ActionEvent( button, nButton, button.toString() ); 136 137 for( int nCount = 0; nCount < cloneListener.size(); nCount++ ) 138 cloneListener.get( nCount ).actionPerformed( evt ); 139 } 140 141 145 public void addEventListener( ActionListener listener ) { 146 147 this.listener.add( listener ); 148 } 149 150 154 public void removeEventListener( ActionListener listener ) { 155 156 this.listener.remove( listener ); 157 } 158 159 163 public void onShow() { 164 165 if( getComponentCount() == 0 ) 166 add( builder.getPanel() ); 167 } 168 169 173 public boolean onApply() { 174 175 return true; 176 } 177 178 181 public void onCancel() { 182 183 } 184 185 189 public void onLookAndFeelChanged() { 190 191 javax.swing.SwingUtilities.updateComponentTreeUI( this ); 192 } 193 194 198 public void onLanguageChanged( String strCountryCode ) { 199 200 caption.setText( JSharedObjects.getLanguageManager().getStringEx( strCaption ) ); 201 yesButton.setText( JSharedObjects.getLanguageManager().getStringEx( "YES" ) ); 202 noButton.setText( JSharedObjects.getLanguageManager().getStringEx( "NO" ) ); 203 } 204 } 205 206 | Popular Tags |