1 56 package org.objectstyle.cayenne.modeler.dialog; 57 58 import java.awt.Component ; 59 import java.io.File ; 60 61 import javax.swing.JDialog ; 62 import javax.swing.JOptionPane ; 63 64 67 public class OverwriteDialog { 68 69 private static final String SELECT_ANOTHER = "Select Another"; 70 private static final String OVERWRITE = "Overwrite"; 71 private static final String CANCEL = "Cancel"; 72 private static final String [] OPTIONS = new String [] { 73 SELECT_ANOTHER, OVERWRITE, CANCEL 74 }; 75 76 protected File file; 77 protected Component parent; 78 protected String result = CANCEL; 79 80 public OverwriteDialog(File file, Component parent) { 81 this.file = file; 82 this.parent = parent; 83 } 84 85 public void show() { 86 JOptionPane pane = new JOptionPane ("Do you want to overwrite an existing file: " 87 + file, JOptionPane.QUESTION_MESSAGE); 88 pane.setOptions(OPTIONS); 89 90 JDialog dialog = pane.createDialog(parent, "File exists"); 91 dialog.setVisible(true); 92 93 Object selectedValue = pane.getValue(); 94 result = (selectedValue != null) ? selectedValue.toString() : CANCEL; 95 } 96 97 public boolean shouldSelectAnother() { 98 return SELECT_ANOTHER.equals(result); 99 } 100 101 public boolean shouldOverwrite() { 102 return OVERWRITE.equals(result); 103 } 104 105 public boolean shouldCancel() { 106 return result == null || CANCEL.equals(result); 107 } 108 } | Popular Tags |