1 29 38 39 package org.planetamessenger.mos.forms; 40 41 import javax.swing.*; 42 import java.awt.*; 43 import java.awt.event.*; 44 import com.jgoodies.forms.builder.*; 45 import com.jgoodies.forms.layout.*; 46 import com.jgoodies.forms.debug.*; 47 import org.planetamessenger.mos.engine.*; 48 49 50 class JMOSMessageDialog extends JDialog { 51 52 private final int DEFAULT_WIDTH = 430; 53 private final int DEFAULT_HEIGHT = 120; 54 55 public static final int NONE_BUTTON = 0; 56 public static final int YES_BUTTON = 1; 57 public static final int NO_BUTTON = 2; 58 59 private JLabel infoLabel; 60 private JButton okButton; 61 private JButton cancelButton; 62 private int nButtonResult; 63 private String strTitle; 64 private String strMessage; 65 66 67 68 78 public JMOSMessageDialog( JDialog parent, String strTitle, String strMessage, boolean modal ) { 79 80 super( parent, modal ); 81 this.nButtonResult = NONE_BUTTON; 82 this.strTitle = strTitle; 83 this.strMessage = strMessage; 84 initComponents(); 85 } 86 87 91 private void initComponents() { 92 93 FormLayout layout = new FormLayout( "center:pref", "center:pref, center:4dlu, center:4dlu, center:pref" ); 94 PanelBuilder builder = new PanelBuilder( layout ); 95 CellConstraints cellConst = new CellConstraints(); 96 Box btnsPanel = Box.createHorizontalBox(); 97 98 99 okButton = new JButton(); 100 cancelButton = new JButton(); 101 infoLabel = new JLabel(); 102 103 setDefaultCloseOperation( JFrame.DO_NOTHING_ON_CLOSE ); 104 getContentPane().setLayout( new GridBagLayout() ); 105 setTitle( strTitle ); 106 107 infoLabel.setFont( JSystemFonts.FONT ); 108 infoLabel.setText( strMessage ); 109 getContentPane().add( infoLabel ); 110 111 cancelButton.setFont( JSystemFonts.FONT ); 112 cancelButton.setIcon( JSharedObjects.getResources().getIcon( JResources.CLOSE_BUTTON_ICON ) ); 113 cancelButton.setText( JSharedObjects.getLanguageManager().getStringEx( "NO" ) ); 114 cancelButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) ); 115 getContentPane().add( cancelButton ); 116 117 okButton.setFont( JSystemFonts.FONT ); 118 okButton.setIcon( JSharedObjects.getResources().getIcon( JResources.OK_BUTTON_ICON ) ); 119 okButton.setText( JSharedObjects.getLanguageManager().getStringEx( "YES" ) ); 120 okButton.setPreferredSize( new Dimension( JResources.DEFAULT_BUTTON_WIDTH, JResources.DEFAULT_BUTTON_HEIGHT ) ); 121 getContentPane().add( okButton ); 122 123 okButton.addActionListener( new ActionListener() { 125 public void actionPerformed( ActionEvent evt ) { 126 okButtonActionPerformed( evt ); 127 } 128 } 129 ); 130 131 cancelButton.addActionListener( new ActionListener() { 133 public void actionPerformed( ActionEvent evt ) { 134 cancelButtonActionPerformed( evt ); 135 } 136 } 137 ); 138 139 btnsPanel.add( Box.createHorizontalGlue() ); 140 btnsPanel.add( cancelButton ); 141 btnsPanel.add( okButton ); 142 143 builder.setDefaultDialogBorder(); 144 builder.add( infoLabel, cellConst.xy( 1, 1 ) ); 145 builder.add( btnsPanel, cellConst.xy( 1, 4 ) ); 146 147 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 148 setSize( new Dimension( DEFAULT_WIDTH, DEFAULT_HEIGHT ) ); 149 setLocation( ( screenSize.width - getSize().width ) / 2, ( screenSize.height - getSize().height ) / 2 ); 150 151 getContentPane().add( builder.getPanel() ); 152 } 153 154 159 private void okButtonActionPerformed( ActionEvent evt ) { 160 161 nButtonResult = YES_BUTTON; 162 closeDialog( null ); 163 } 164 165 170 private void cancelButtonActionPerformed( ActionEvent evt ) { 171 172 nButtonResult = NO_BUTTON; 173 closeDialog( null ); 174 } 175 176 180 private void closeDialog( WindowEvent evt ) { 181 182 setVisible( false ); 183 dispose(); 184 } 185 186 192 public void setEnabled( boolean bStatus ) { 193 194 okButton.setEnabled( bStatus ); 195 cancelButton.setEnabled( bStatus ); 196 super.setEnabled( bStatus ); 197 } 198 199 202 public int getButtonResult() { 203 204 return nButtonResult; 205 } 206 } 207 208 | Popular Tags |