Java Source Code: terppaint.saveChanges


   1: package terppaint;
   2: /*
   3:  * saveChanges.java
   4:  *
   5:  * Created on April 17, 2002, 5:31 PM
   6:  */
   7: 
   8: /**
   9:  *
  10:  * @author  Terp Paint
  11:  * @version 2.0
  12:  */
  13: 
  14: import java.awt.*;
  15: import java.awt.Toolkit.*;
  16: 
  17: /** saveChanges provides the user to choose to save or not all changes made on main canvas.
  18:  * There are no OS/Hardware dependencies and no variances.  There is no need for any
  19:  * security constraints and no references to external specifications.
  20:  */
  21:	  public class saveChanges extends JDialog {
  22:
  23:    /** Creates new form saveChanges */
  24:    String fileName;
  25:
  26:    /** Integer to signify 'YES', 'NO', and 'CANCEL'.
  27:     */
  28:    public int CHOICE;
  29:
  30:   /** Constructor initializes the dialog box to proper size.
  31:    * There are no OS/Hardware dependencies and no variances.  There is no need for any
  32:    * security constraints and no references to external specifications.
  33:    * @param parent Frame containing image frame
  34:    * @param modal boolean indicating true or false
  35:    * @param filename String containing the file nameS
  36:    */
  37:	      public saveChanges(Frame parent, boolean modal, String filename) {
  38:    super(parent, modal);
  39:    fileName = filename;
  40:    initComponents();
  41:    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  42:    double xMargin = (screenSize.getWidth()- this.getWidth()) / 2;
  43:    double yMargin = (screenSize.getHeight() - this.getHeight()) / 2;
  44:    this.setLocation((int)xMargin,(int)yMargin);
  45:    }
  46:
  47:    /** This method is called from within the constructor to
  48:     * initialize the form.
  49:     * WARNING: Do NOT modify this code. The content of this method is
  50:     * always regenerated by the Form Editor.
  51:     * There are no OS/Hardware dependencies and no variances.    There is no need for any
  52:     * security constraints and no references to external specifications.
  53:     */
  54:	      public void initComponents() {
  55:    jLabel1 = new javax.swing.JLabel();
  56:    YES = new javax.swing.JButton();
  57:    NO = new javax.swing.JButton();
  58:    CANCEL = new javax.swing.JButton();
  59:    Alert = new javax.swing.JButton();
  60:
  61:    getContentPane().setLayout(new java.awt.GridBagLayout());
  62:    GridBagConstraints gridBagConstraints1;
  63:
  64:	      addWindowListener(new java.awt.event.WindowAdapter() {
  65:	          public void windowClosing(WindowEvent evt) {
  66:        closeDialog(evt);
  67:        }
  68:    });
  69:
  70:    jLabel1.setText("Save changes to " + fileName + "?");
  71:    gridBagConstraints1 = new java.awt.GridBagConstraints();
  72:    gridBagConstraints1.gridx = 2;
  73:    gridBagConstraints1.gridy = 0;
  74:    gridBagConstraints1.gridwidth = 3;
  75:    getContentPane().add(jLabel1, gridBagConstraints1);
  76:
  77:    YES.setText("YES");
  78:	      YES.addActionListener(new java.awt.event.ActionListener() {
  79:	          public void actionPerformed(ActionEvent evt) {
  80:        YESActionPerformed(evt);
  81:        }
  82:    });
  83:
  84:    gridBagConstraints1 = new java.awt.GridBagConstraints();
  85:    gridBagConstraints1.gridx = 1;
  86:    gridBagConstraints1.gridy = 1;
  87:    getContentPane().add(YES, gridBagConstraints1);
  88:
  89:    NO.setText("NO");
  90:	      NO.addActionListener(new java.awt.event.ActionListener() {
  91:	          public void actionPerformed(ActionEvent evt) {
  92:        NOActionPerformed(evt);
  93:        }
  94:    });
  95:
  96:    gridBagConstraints1 = new java.awt.GridBagConstraints();
  97:    gridBagConstraints1.gridx = 2;
  98:    gridBagConstraints1.gridy = 1;
  99:    getContentPane().add(NO, gridBagConstraints1);
 100:
 101:    CANCEL.setText("CANCEL");
 102:	      CANCEL.addActionListener(new java.awt.event.ActionListener() {
 103:	          public void actionPerformed(ActionEvent evt) {
 104:        CANCELActionPerformed(evt);
 105:        }
 106:    });
 107:
 108:    gridBagConstraints1 = new java.awt.GridBagConstraints();
 109:    gridBagConstraints1.gridx = 3;
 110:    gridBagConstraints1.gridy = 1;
 111:    getContentPane().add(CANCEL, gridBagConstraints1);
 112:
 113:    Alert.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exclamation.gif")));
 114:    Alert.setBorder(null);
 115:	      Alert.addActionListener(new java.awt.event.ActionListener() {
 116:	          public void actionPerformed(ActionEvent evt) {
 117:        AlertActionPerformed(evt);
 118:        }
 119:    });
 120:
 121:    gridBagConstraints1 = new java.awt.GridBagConstraints();
 122:    gridBagConstraints1.gridx = 0;
 123:    gridBagConstraints1.gridy = 0;
 124:    getContentPane().add(Alert, gridBagConstraints1);
 125:
 126:    pack();
 127:    }
 128:
 129:    /** This method is performed when a user clicks YES button to save the changes.
 130:     * There are no OS/Hardware dependencies and no variances.    There is no need for any
 131:     * security constraints and no references to external specifications.
 132:     *@param evt performed by mouse action.
 133:     */
 134:	      public void YESActionPerformed(ActionEvent evt) {
 135:    CHOICE = choice.YES;
 136:    this.closeDialog(new java.awt.event.WindowEvent(this, 0));
 137:    // Add your handling code here:
 138:    }
 139:
 140:    /** This method is performed by mouse event when user clicks CANCEL button to cancel the changes.
 141:     * There are no OS/Hardware dependencies and no variances.    There is no need for any
 142:     * security constraints and no references to external specifications.
 143:     *@param evt performed by mouse event.
 144:     */
 145:	      public void CANCELActionPerformed(ActionEvent evt) {
 146:    CHOICE = choice.CANCEL;
 147:    this.closeDialog(new java.awt.event.WindowEvent(this, 0));
 148:    // Add your handling code here:
 149:    }
 150:
 151:    /** This method is performed by mouse event when user clicks NO button not to save the changes.
 152:     * There are no OS/Hardware dependencies and no variances.    There is no need for any
 153:     * security constraints and no references to external specifications.
 154:     *@param evt performed by mouse action.
 155:     */
 156:	      public void NOActionPerformed(ActionEvent evt) {
 157:    CHOICE = choice.NO;
 158:    this.closeDialog(new java.awt.event.WindowEvent(this, 0));
 159:    // Add your handling code here:
 160:    }
 161:
 162:    /** This method is executed by mouse event when user clicks Alert button.
 163:     * There are no OS/Hardware dependencies and no variances.    There is no need for any
 164:     * security constraints and no references to external specifications.
 165:     *@param evt performed by mouse event.
 166:     */
 167:	      public void AlertActionPerformed(ActionEvent evt) {
 168:    // Add your handling code here:
 169:    }
 170:
 171:    /** Closes the dialog.
 172:     * There are no OS/Hardware dependencies and no variances.    There is no need for any
 173:     * security constraints and no references to external specifications.
 174:     *@param evt performed by mouse event.
 175:     */
 176:	      private void closeDialog(WindowEvent evt) {
 177:    setVisible(false);
 178:    dispose();
 179:    }
 180:
 181:    /** Creates new saveChanges object.
 182:     * There are no OS/Hardware dependencies and no variances.    There is no need for any
 183:     * security constraints and no references to external specifications.
 184:     * @param args the command line arguments
 185:     */
 186:	      public static void main(String args[]) {
 187:    new saveChanges(new javax.swing.JFrame(), true,"HELLO").show();
 188:    }
 189:
 190:
 191:    // Variables declaration - do not modify
 192:    /** java swing GUI depicting the JLabel called jLabell.*/
 193:    public JLabel jLabel1;
 194:
 195:    /** java swing GUI depicting the Jbutton called YES.*/
 196:    public JButton YES;
 197:
 198:    /** java swing GUI depicting the Jbutton called NO.*/
 199:    public JButton NO;
 200:
 201:    /** java swing GUI depicting the Jbutton called CANCEL.*/
 202:    public JButton CANCEL;
 203:
 204:    /** java swing GUI depicting the Jbutton called Alert.*/
 205:    public JButton Alert;
 206:
 207:    // End of variables declaration
 208:
 209:}
 210:/** Subclass choice providing YES, NO, or CANCEL when made changes */
 211:	  class choice{
 212:    /** YES set to 0 */
 213:    public static int YES = 0;
 214:
 215:    /** NO set to 1 */
 216:    public static int NO = 1;
 217:
 218:    /** CANCEL set to 2 */
 219:    public static int CANCEL = 2;
 220:}