1 33 34 package edu.rice.cs.drjava.ui; 35 36 import edu.rice.cs.util.swing.DirectorySelectorComponent; 37 import edu.rice.cs.util.swing.DirectoryChooser; 38 import edu.rice.cs.drjava.DrJava; 39 import edu.rice.cs.drjava.config.Configuration; 40 import edu.rice.cs.drjava.config.OptionConstants; 41 import edu.rice.cs.util.DirectorySelector; 42 import edu.rice.cs.util.OperationCanceledException; 43 44 import javax.swing.*; 45 import java.io.File ; 46 47 53 public class JavadocDialog implements DirectorySelector { 54 55 private final JFrame _frame; 56 57 58 private final DirectorySelectorComponent _selector; 59 60 61 private final JCheckBox _checkBox; 62 63 64 private final JOptionPane _optionPane; 65 66 67 private final JDialog _dialog; 68 69 70 private boolean _useSuggestion; 71 72 73 private File _suggestedDir; 74 75 79 public JavadocDialog(JFrame frame) { 80 _frame = frame; 81 _useSuggestion = true; 82 _suggestedDir = null; 83 84 DirectoryChooser chooser = new DirectoryChooser(); 86 chooser.setMultiSelectionEnabled(false); 87 chooser.setApproveButtonText("Select"); 88 90 String msg = "Select a destination directory for the Javadoc files:"; 92 _selector = new DirectorySelectorComponent(_frame, chooser, DirectorySelectorComponent.DEFAULT_NUM_COLS, DirectorySelectorComponent.DEFAULT_FONT_SIZE, false); 93 _checkBox = new JCheckBox("Always Prompt For Destination"); 94 Object [] components = new Object [] { msg, _selector, _checkBox }; 95 96 _optionPane = new JOptionPane(components, 97 JOptionPane.QUESTION_MESSAGE, 98 JOptionPane.OK_CANCEL_OPTION); 99 _dialog = _optionPane.createDialog(_frame, "Select Javadoc Destination"); 100 chooser.setOwner(_dialog); 101 } 102 103 104 public boolean isRecursive() { return false; } 105 106 116 public File getDirectory(File start) throws OperationCanceledException { 117 if (start != null) { 118 _selector.setFileField(start); 120 } 121 else if (_useSuggestion && (_suggestedDir != null)) { 122 _selector.setFileField(_suggestedDir); 124 } 125 126 Configuration config = DrJava.getConfig(); 127 boolean ask = config.getSetting(OptionConstants.JAVADOC_PROMPT_FOR_DESTINATION).booleanValue(); 128 129 if (ask) { 130 _checkBox.setSelected(true); 132 133 MainFrame.setPopupLoc(_dialog, _frame); 135 _dialog.setVisible(true); 136 137 if (!_isPositiveResult()) { 139 throw new OperationCanceledException(); 140 } 141 142 if (!_checkBox.isSelected()) { 144 config.setSetting(OptionConstants.JAVADOC_PROMPT_FOR_DESTINATION, 145 Boolean.FALSE); 146 } 147 148 if ((start == null) && 150 (_useSuggestion && (_suggestedDir != null)) && 151 !_selector.getFileFromField().equals(_suggestedDir)) { 152 _useSuggestion = false; 153 } 154 } 155 return _selector.getFileFromField(); 156 } 157 158 161 public boolean askUser(String message, String title) { 162 int choice = JOptionPane.showConfirmDialog(_frame, message, title, JOptionPane.YES_NO_OPTION); 163 return (choice == JOptionPane.YES_OPTION); 164 } 165 166 167 public void warnUser(String message, String title) { 168 JOptionPane.showMessageDialog(_frame, message, title, JOptionPane.ERROR_MESSAGE); 169 } 170 171 175 public void setSuggestedDir(File dir) { _suggestedDir = dir; } 176 177 181 public void setUseSuggestion(boolean use) { _useSuggestion = use; } 182 183 184 private boolean _isPositiveResult() { 185 Object result = _optionPane.getValue(); 186 if ((result != null) && (result instanceof Integer )) { 187 int rc = ((Integer )result).intValue(); 188 return rc == JOptionPane.OK_OPTION; 189 } 190 else return false; 191 } 192 } | Popular Tags |