|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| JavadocDialog.java | 0% | 31.7% | 12.5% | 22.2% |
|
||||||||||||||
| 1 | /*BEGIN_COPYRIGHT_BLOCK | |
| 2 | * | |
| 3 | * Copyright (c) 2001-2010, JavaPLT group at Rice University (drjava@rice.edu) | |
| 4 | * All rights reserved. | |
| 5 | * | |
| 6 | * Redistribution and use in source and binary forms, with or without | |
| 7 | * modification, are permitted provided that the following conditions are met: | |
| 8 | * * Redistributions of source code must retain the above copyright | |
| 9 | * notice, this list of conditions and the following disclaimer. | |
| 10 | * * Redistributions in binary form must reproduce the above copyright | |
| 11 | * notice, this list of conditions and the following disclaimer in the | |
| 12 | * documentation and/or other materials provided with the distribution. | |
| 13 | * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the | |
| 14 | * names of its contributors may be used to endorse or promote products | |
| 15 | * derived from this software without specific prior written permission. | |
| 16 | * | |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 20 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |
| 21 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
| 22 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
| 23 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
| 24 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | |
| 25 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
| 26 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
| 27 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 28 | * | |
| 29 | * This software is Open Source Initiative approved Open Source Software. | |
| 30 | * Open Source Initative Approved is a trademark of the Open Source Initiative. | |
| 31 | * | |
| 32 | * This file is part of DrJava. Download the current version of this project | |
| 33 | * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/ | |
| 34 | * | |
| 35 | * END_COPYRIGHT_BLOCK*/ | |
| 36 | ||
| 37 | package edu.rice.cs.drjava.ui; | |
| 38 | ||
| 39 | import edu.rice.cs.util.swing.DirectorySelectorComponent; | |
| 40 | import edu.rice.cs.util.swing.DirectoryChooser; | |
| 41 | import edu.rice.cs.drjava.DrJava; | |
| 42 | import edu.rice.cs.drjava.config.Configuration; | |
| 43 | import edu.rice.cs.drjava.config.OptionConstants; | |
| 44 | import edu.rice.cs.util.DirectorySelector; | |
| 45 | import edu.rice.cs.util.OperationCanceledException; | |
| 46 | import edu.rice.cs.util.swing.Utilities; | |
| 47 | ||
| 48 | import javax.swing.*; | |
| 49 | import java.io.File; | |
| 50 | ||
| 51 | /** Manages a dialog box that can select a destination directory for generating Javadoc. The getDirectory method should | |
| 52 | * be called to show the dialog, using the suggested location for the Javadoc as the "start" file. If the user | |
| 53 | * modifies the selection once, the user's choice will be remembered and no further suggestions will be used. | |
| 54 | * | |
| 55 | * @version $Id: JavadocDialog.java 5175 2010-01-20 08:46:32Z mgricken $ | |
| 56 | */ | |
| 57 | public class JavadocDialog implements DirectorySelector { | |
| 58 | /** Parent frame of the dialog. */ | |
| 59 | private final JFrame _frame; | |
| 60 | ||
| 61 | /** File field and button. */ | |
| 62 | private final DirectorySelectorComponent _selector; | |
| 63 | ||
| 64 | /** Whether to always prompt for destination. */ | |
| 65 | private final JCheckBox _checkBox; | |
| 66 | ||
| 67 | /** OptionPane from which to get the results. */ | |
| 68 | private final JOptionPane _optionPane; | |
| 69 | ||
| 70 | /** Dialog to show. */ | |
| 71 | private final JDialog _dialog; | |
| 72 | ||
| 73 | /** Whether to use the suggested directory each time the dialog is shown. */ | |
| 74 | private boolean _useSuggestion; | |
| 75 | ||
| 76 | /** Current suggestion for the destination directory, or null. */ | |
| 77 | private File _suggestedDir; | |
| 78 | ||
| 79 | /** Creates a new JavadocDialog to show from the given frame. | |
| 80 | * | |
| 81 | * @param frame Parent frame of this dialog | |
| 82 | */ | |
| 83 | 38 | public JavadocDialog(JFrame frame) { |
| 84 | 38 | _frame = frame; |
| 85 | 38 | _useSuggestion = true; |
| 86 | 38 | _suggestedDir = null; |
| 87 | ||
| 88 | // Create file chooser | |
| 89 | 38 | DirectoryChooser chooser = new DirectoryChooser(); |
| 90 | 38 | chooser.setMultiSelectionEnabled(false); |
| 91 | 38 | chooser.setApproveButtonText("Select"); |
| 92 | // chooser.setEditable(true); | |
| 93 | ||
| 94 | // Create components for dialog | |
| 95 | 38 | String msg = "Select a destination directory for the Javadoc files:"; |
| 96 | 38 | _selector = new DirectorySelectorComponent(_frame, chooser, DirectorySelectorComponent.DEFAULT_NUM_COLS, DirectorySelectorComponent.DEFAULT_FONT_SIZE, false); |
| 97 | 38 | _checkBox = new JCheckBox("Always Prompt For Destination"); |
| 98 | 38 | Object[] components = new Object[] { msg, _selector, _checkBox }; |
| 99 | ||
| 100 | 38 | _optionPane = new JOptionPane(components, |
| 101 | JOptionPane.QUESTION_MESSAGE, | |
| 102 | JOptionPane.OK_CANCEL_OPTION); | |
| 103 | 38 | _dialog = _optionPane.createDialog(_frame, "Select Javadoc Destination"); |
| 104 | 38 | chooser.setOwner(_dialog); |
| 105 | } | |
| 106 | ||
| 107 | ||
| 108 | 0 | public boolean isRecursive() { return false; } |
| 109 | ||
| 110 | /** Shows the dialog prompting the user for a destination directory in which to generate Javadoc. | |
| 111 | * | |
| 112 | * This operation must be executed from the event-handling thread! | |
| 113 | * | |
| 114 | * @param start The directory to display in the text box. If null, | |
| 115 | * the most recent suggested directory (passed in via setSuggestedDir) | |
| 116 | * is displayed, unless the user has modified a previous suggestion. | |
| 117 | * @return A directory to use for the Javadoc (which might not exist) | |
| 118 | * @throws OperationCanceledException if the selection request is canceled | |
| 119 | */ | |
| 120 | 0 | public File getDirectory(File start) throws OperationCanceledException { |
| 121 | 0 | if (start != null) { |
| 122 | // We were given a default - use it. | |
| 123 | 0 | _selector.setFileField(start); |
| 124 | } | |
| 125 | 0 | else if (_useSuggestion && (_suggestedDir != null)) { |
| 126 | // We weren't given one, so we need to use our suggestion. | |
| 127 | 0 | _selector.setFileField(_suggestedDir); |
| 128 | } | |
| 129 | ||
| 130 | 0 | Configuration config = DrJava.getConfig(); |
| 131 | 0 | boolean ask = config.getSetting(OptionConstants.JAVADOC_PROMPT_FOR_DESTINATION).booleanValue(); |
| 132 | ||
| 133 | 0 | if (ask) { |
| 134 | // The "always prompt" checkbox should be checked | |
| 135 | 0 | _checkBox.setSelected(true); |
| 136 | ||
| 137 | // Prompt the user | |
| 138 | 0 | Utilities.setPopupLoc(_dialog, _frame); |
| 139 | 0 | _dialog.setVisible(true); |
| 140 | ||
| 141 | // Get result | |
| 142 | 0 | if (!_isPositiveResult()) { |
| 143 | 0 | throw new OperationCanceledException(); |
| 144 | } | |
| 145 | ||
| 146 | // See if the user wants to suppress this dialog in the future. | |
| 147 | 0 | if (!_checkBox.isSelected()) { |
| 148 | 0 | config.setSetting(OptionConstants.JAVADOC_PROMPT_FOR_DESTINATION, |
| 149 | Boolean.FALSE); | |
| 150 | } | |
| 151 | ||
| 152 | // Check if the user disagreed with the suggestion | |
| 153 | 0 | if ((start == null) && |
| 154 | (_useSuggestion && (_suggestedDir != null)) && | |
| 155 | !_selector.getFileFromField().equals(_suggestedDir)) { | |
| 156 | 0 | _useSuggestion = false; |
| 157 | } | |
| 158 | } | |
| 159 | 0 | return _selector.getFileFromField(); |
| 160 | } | |
| 161 | ||
| 162 | /** Asks the user a yes/no question. | |
| 163 | * @return true if the user responded affirmatively, false if negatively | |
| 164 | */ | |
| 165 | 0 | public boolean askUser(String message, String title) { |
| 166 | 0 | int choice = JOptionPane.showConfirmDialog(_frame, message, title, JOptionPane.YES_NO_OPTION); |
| 167 | 0 | return (choice == JOptionPane.YES_OPTION); |
| 168 | } | |
| 169 | ||
| 170 | /** Warns the user about an error condition. */ | |
| 171 | 0 | public void warnUser(String message, String title) { |
| 172 | 0 | JOptionPane.showMessageDialog(_frame, message, title, JOptionPane.ERROR_MESSAGE); |
| 173 | } | |
| 174 | ||
| 175 | /** Sets the suggested destination directory for Javadoc generation. This directory will be displayed | |
| 176 | * in the file field if the user has not modified the suggestion in the past. | |
| 177 | * @param dir Suggested destination directory | |
| 178 | */ | |
| 179 | 0 | public void setSuggestedDir(File dir) { _suggestedDir = dir; } |
| 180 | ||
| 181 | /** Sets whether the dialog should use the suggested directory provided | |
| 182 | * to the getDirectory method as the default location. | |
| 183 | * @param use Whether to use the suggested directory | |
| 184 | */ | |
| 185 | 0 | public void setUseSuggestion(boolean use) { _useSuggestion = use; } |
| 186 | ||
| 187 | /** Returns whether the JOptionPane currently has the OK_OPTION result. */ | |
| 188 | 0 | private boolean _isPositiveResult() { |
| 189 | 0 | Object result = _optionPane.getValue(); |
| 190 | 0 | if ((result != null) && (result instanceof Integer)) { |
| 191 | 0 | int rc = ((Integer)result).intValue(); |
| 192 | 0 | return rc == JOptionPane.OK_OPTION; |
| 193 | } | |
| 194 | 0 | else return false; |
| 195 | } | |
| 196 | } |
|
||||||||||