Back to index

wims  3.65+svn20090927
NewFileDialog.java
Go to the documentation of this file.
00001 /*
00002  * @(#)NewFileDialog.java
00003  *
00004  * $Id: NewFileDialog.java,v 1.6 2001/05/27 22:28:12 huaz Exp $
00005  *
00006  * Created on November 16, 2000, 12:00 AM
00007  */
00008 package SharpTools;
00009 import javax.swing.*;
00010 import java.awt.*;
00011 import java.awt.event.*;
00012 import java.util.*;
00022 public class NewFileDialog extends SharpDialog {
00023     private int rows;
00024     private int cols;
00025     final ImageIcon newFileIcon=new ImageIcon(getClass().getResource("/images/new32.gif"));
00026     //final private static ImageIcon newFileIcon = SharpTools.getImageIcon("new32.gif");
00027     final NumberField rowField;
00028     final NumberField colField;
00029     final JCheckBox saveDefault;
00030     
00031     public NewFileDialog(JFrame aFrame, int initrows, int initcols) {
00032         
00033        super(aFrame, "New", true);
00034 
00035        //various properties of the dialog labels and text fields 
00036        final JLabel msgString1 = new JLabel(SharpTools.translation.getProperty("Rows")+": ");
00037        final JLabel msgString2 = new JLabel(SharpTools.translation.getProperty("Columns")+": ");
00038        rowField = new NumberField(5, true, true);
00039        colField = new NumberField(5, true, true);
00040        msgString1.setLabelFor(rowField);
00041        msgString2.setLabelFor(colField);
00042        msgString1.setDisplayedMnemonic(KeyEvent.VK_R);
00043        msgString2.setDisplayedMnemonic(KeyEvent.VK_C);
00044 
00045        saveDefault = new JCheckBox(SharpTools.translation.getProperty("Save_as_default"), false);
00046        saveDefault.setMnemonic(KeyEvent.VK_S);
00047 
00048        rowField.setText(String.valueOf(initrows));
00049        colField.setText(String.valueOf(initcols));
00050        
00051        Object[] input = {msgString1, rowField, msgString2, colField,
00052                        saveDefault};
00053 
00054         setOptionPane(input, 
00055                     JOptionPane.QUESTION_MESSAGE,
00056                     JOptionPane.OK_CANCEL_OPTION,
00057                     newFileIcon);
00058        
00059        //     pack();
00060     }
00061 
00067     public int getRows() { return rows; }
00068     
00074     public int getColumns() { return cols; }
00075 
00082     private void newFileError(String error, JTextField com) {    
00083         SharpOptionPane.showMessageDialog(this, error, SharpTools.translation.getProperty("Error"),
00084                                      JOptionPane.ERROR_MESSAGE);
00085        com.selectAll();
00086        com.requestFocus();
00087     }
00088 
00089     protected boolean onOK() {
00090                   
00091        try {
00092            rows = rowField.getInteger().intValue();
00093        }
00094        catch (Exception e1) {
00095            rows = 0;
00096        }
00097        
00098        if (rows <= 0) {
00099            newFileError(SharpTools.translation.getProperty("Invalid_row_value"), rowField);
00100            return false;
00101        }
00102        
00103        try {
00104            cols = colField.getInteger().intValue();
00105        }
00106        catch (Exception e2) {
00107            cols = 0;
00108        }
00109        
00110        if (cols <= 0) {
00111            newFileError(SharpTools.translation.getProperty("Invalid_column_value"), colField);
00112            return false;
00113        }   
00114        
00115        if (saveDefault.isSelected()) {
00116            // save stuff
00117            Config config = SharpTools.getConfig();
00118            config.setInt("ROWS", rows);
00119            config.setInt("COLUMNS", cols);
00120        }                    
00121        
00122        return true;
00123     }
00124 
00125     protected boolean onCancel() {
00126        rows = cols = 0;
00127        return true;
00128     }
00129        
00130     protected void onOpen() {
00131        // set the initial focus to rowField
00132        rowField.selectAll();
00133        rowField.requestFocus();
00134     }
00135               
00136     protected boolean onClose() {
00137        // cancelled
00138        rows = cols = 0;
00139        return true;
00140     }
00141 }