- Timestamp:
- 2013-09-07T17:52:27+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExtendedDialog.java
r6087 r6221 37 37 import org.openstreetmap.josm.tools.GBC; 38 38 import org.openstreetmap.josm.tools.ImageProvider; 39 import org.openstreetmap.josm.tools.Utils; 39 40 import org.openstreetmap.josm.tools.WindowGeometry; 40 41 … … 132 133 /** 133 134 * Same as above but lets you define if the dialog should be modal. 134 */ 135 public ExtendedDialog(Component parent, String title, String[] buttonTexts, 136 boolean modal) { 135 * @param parent The parent element that will be used for position and maximum size 136 * @param title The text that will be shown in the window titlebar 137 * @param buttonTexts String Array of the text that will appear on the buttons. The first button is the default one. 138 * @param modal Set it to {@code true} if you want the dialog to be modal 139 */ 140 public ExtendedDialog(Component parent, String title, String[] buttonTexts, boolean modal) { 137 141 this(parent, title, buttonTexts, modal, true); 138 142 } 139 143 140 public ExtendedDialog(Component parent, String title, String[] buttonTexts, 141 boolean modal, boolean disposeOnClose) { 144 public ExtendedDialog(Component parent, String title, String[] buttonTexts, boolean modal, boolean disposeOnClose) { 142 145 super(JOptionPane.getFrameForComponent(parent), title, modal ? ModalityType.DOCUMENT_MODAL : ModalityType.MODELESS); 143 146 this.parent = parent; 144 147 this.modal = modal; 145 bTexts = buttonTexts;148 bTexts = Utils.copyArray(buttonTexts); 146 149 if (disposeOnClose) { 147 150 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); … … 152 155 /** 153 156 * Allows decorating the buttons with icons. 154 * @param buttonIcons 157 * @param buttonIcons The button icons 158 * @return {@code this} 155 159 */ 156 160 public ExtendedDialog setButtonIcons(Icon[] buttonIcons) { 157 this.bIcons = buttonIcons;161 this.bIcons = Utils.copyArray(buttonIcons); 158 162 return this; 159 163 } … … 161 165 /** 162 166 * Convenience method to provide image names instead of images. 167 * @param buttonIcons The button icon names 168 * @return {@code this} 163 169 */ 164 170 public ExtendedDialog setButtonIcons(String[] buttonIcons) { … … 175 181 * 176 182 * @param toolTipTexts the tool tip texts. Ignored, if null. 183 * @return {@code this} 177 184 */ 178 185 public ExtendedDialog setToolTipTexts(String[] toolTipTexts) { 179 this.bToolTipTexts = toolTipTexts;186 this.bToolTipTexts = Utils.copyArray(toolTipTexts); 180 187 return this; 181 188 } … … 188 195 * 189 196 * @param content Any element that can be displayed in the message dialog 197 * @return {@code this} 190 198 */ 191 199 public ExtendedDialog setContent(Component content) { … … 201 209 * @param content Any element that can be displayed in the message dialog 202 210 * @param placeContentInScrollPane if true, places the content in a JScrollPane 203 * 211 * @return {@code this} 204 212 */ 205 213 public ExtendedDialog setContent(Component content, boolean placeContentInScrollPane) { … … 217 225 * 218 226 * @param message The text that should be shown to the user 227 * @return {@code this} 219 228 */ 220 229 public ExtendedDialog setContent(String message) { … … 225 234 * Decorate the dialog with an icon that is shown on the left part of 226 235 * the window area. (Similar to how it is done in {@link JOptionPane}) 236 * @param icon The icon to display 237 * @return {@code this} 227 238 */ 228 239 public ExtendedDialog setIcon(Icon icon) { … … 233 244 /** 234 245 * Convenience method to allow values that would be accepted by {@link JOptionPane} as messageType. 246 * @param messageType The {@link JOptionPane} messageType 247 * @return {@code this} 235 248 */ 236 249 public ExtendedDialog setIcon(int messageType) { … … 254 267 * Show the dialog to the user. Call this after you have set all options 255 268 * for the dialog. You can retrieve the result using {@link #getValue()}. 269 * @return {@code this} 256 270 */ 257 271 public ExtendedDialog showDialog() { … … 493 507 * existing preference is found (only takes effect if 494 508 * <code>pref</code> is not null or empty 495 * 509 * @return {@code this} 496 510 */ 497 511 public ExtendedDialog setRememberWindowGeometry(String pref, WindowGeometry wg) { … … 507 521 * Currently, this is not supported for non-modal dialogs. 508 522 * @param togglePref The preference to save the checkbox state to 523 * @return {@code this} 509 524 */ 510 525 public ExtendedDialog toggleEnable(String togglePref) { … … 520 535 * Call this if you "accidentally" called toggleEnable. This doesn't need 521 536 * to be called for every dialog, as it's the default anyway. 537 * @return {@code this} 522 538 */ 523 539 public ExtendedDialog toggleDisable() { … … 530 546 * if you want to give more information. Only has an effect if 531 547 * <code>toggleEnable</code> is set. 532 * @param text 548 * @param text The toggle checkbox text 549 * @return {@code this} 533 550 */ 534 551 public ExtendedDialog setToggleCheckboxText(String text) { … … 539 556 /** 540 557 * Sets the button that will react to ENTER. 558 * @param defaultButtonIdx The button index (starts to ) 559 * @return {@code this} 541 560 */ 542 561 public ExtendedDialog setDefaultButton(int defaultButtonIdx) { … … 549 568 * If the user presses 'cancel' the toggle settings are ignored and not saved to the pref 550 569 * @param cancelButtonIdx index of the button that stands for cancel, accepts multiple values 570 * @return {@code this} 551 571 */ 552 572 public ExtendedDialog setCancelButton(Integer... cancelButtonIdx) { … … 623 643 * @param helpTopic the help topic 624 644 * @param showHelpButton true, if the dialog displays a help button 645 * @return {@code this} 625 646 */ 626 647 public ExtendedDialog configureContextsensitiveHelp(String helpTopic, boolean showHelpButton) { -
trunk/src/org/openstreetmap/josm/gui/FileDrop.java
r6104 r6221 24 24 import java.util.ArrayList; 25 25 import java.util.Arrays; 26 import java.util.EventObject;27 26 import java.util.List; 28 27 import java.util.TooManyListenersException; … … 474 473 475 474 /** 476 * This is the event that is passed to the477 * {@link FileDrop.Listener#filesDropped filesDropped(...)} method in478 * your {@link FileDrop.Listener} when files are dropped onto479 * a registered drop target.480 *481 * <p>I'm releasing this code into the Public Domain. Enjoy.</p>482 *483 * @author Robert Harder484 * @author rob@iharder.net485 * @version 1.2486 */487 public static class Event extends EventObject {488 489 private File[] files;490 491 /**492 * Constructs an {@link Event} with the array493 * of files that were dropped and the494 * {@link FileDrop} that initiated the event.495 *496 * @param files The array of files that were dropped497 * @param source The event source498 */499 public Event( File[] files, Object source ) {500 super( source );501 this.files = files;502 } // end constructor503 504 /**505 * Returns an array of files that were dropped on a506 * registered drop target.507 *508 * @return array of files that were dropped509 */510 public File[] getFiles() {511 return files;512 } // end getFiles513 514 } // end inner class Event515 516 /* ******** I N N E R C L A S S ******** */517 518 /**519 475 * At last an easy way to encapsulate your custom objects for dragging and dropping 520 476 * in your Java programs! -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r6143 r6221 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 import static org.openstreetmap.josm.tools.I18n.trn; 6 import gnu.getopt.Getopt; 7 import gnu.getopt.LongOpt; 6 8 7 9 import java.awt.Image; … … 28 30 import javax.swing.RepaintManager; 29 31 import javax.swing.SwingUtilities; 30 31 import gnu.getopt.Getopt;32 import gnu.getopt.LongOpt;33 32 34 33 import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; … … 301 300 Main.platform.preStartupHook(); 302 301 303 Main.commandLineArgs = argArray;302 Main.commandLineArgs = Utils.copyArray(argArray); 304 303 305 304 if (args.containsKey(Option.VERSION)) { -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
r6198 r6221 48 48 import org.openstreetmap.josm.data.osm.Tag; 49 49 import org.openstreetmap.josm.data.preferences.BooleanProperty; 50 import org.openstreetmap.josm.gui.QuadStateCheckBox;51 50 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 52 51 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPritority; … … 54 53 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 55 54 import org.openstreetmap.josm.gui.widgets.JosmTextField; 55 import org.openstreetmap.josm.gui.widgets.QuadStateCheckBox; 56 56 import org.openstreetmap.josm.tools.GBC; 57 57 import org.openstreetmap.josm.tools.ImageProvider; -
trunk/src/org/openstreetmap/josm/gui/widgets/QuadStateCheckBox.java
r6219 r6221 1 1 // License: GPL. Copyright 2008 by Frederik Ramm and others 2 package org.openstreetmap.josm.gui ;2 package org.openstreetmap.josm.gui.widgets; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; … … 21 21 import javax.swing.plaf.ActionMapUIResource; 22 22 23 import org.openstreetmap.josm.tools.Utils; 24 25 /** 26 * A four-state checkbox. The states are enumerated in {@link State}. 27 * @since 591 28 */ 23 29 public class QuadStateCheckBox extends JCheckBox { 24 30 25 public enum State { NOT_SELECTED, SELECTED, UNSET, PARTIAL } 31 /** 32 * The 4 possible states of this checkbox. 33 */ 34 public enum State { 35 /** Not selected: the property is explicitly switched off */ 36 NOT_SELECTED, 37 /** Selected: the property is explicitly switched on */ 38 SELECTED, 39 /** Unset: do not set this property on the selected objects */ 40 UNSET, 41 /** Partial: different selected objects have different values, do not change */ 42 PARTIAL 43 } 26 44 27 45 private final QuadStateDecorator model; 28 46 private State[] allowed; 29 47 48 /** 49 * Constructs a new {@code QuadStateCheckBox}. 50 * @param text the text of the check box 51 * @param icon the Icon image to display 52 * @param initial The initial state 53 * @param allowed The allowed states 54 */ 30 55 public QuadStateCheckBox(String text, Icon icon, State initial, State[] allowed) { 31 56 super(text, icon); 32 this.allowed = allowed;57 this.allowed = Utils.copyArray(allowed); 33 58 // Add a listener for when the mouse is pressed 34 59 super.addMouseListener(new MouseAdapter() { … … 54 79 setState(initial); 55 80 } 81 82 /** 83 * Constructs a new {@code QuadStateCheckBox}. 84 * @param text the text of the check box 85 * @param initial The initial state 86 * @param allowed The allowed states 87 */ 56 88 public QuadStateCheckBox(String text, State initial, State[] allowed) { 57 89 this(text, null, initial, allowed); … … 60 92 /** Do not let anyone add mouse listeners */ 61 93 @Override public void addMouseListener(MouseListener l) { } 94 62 95 /** 63 96 * Set the new state. 64 */ 65 public void setState(State state) { model.setState(state); } 66 /** Return the current state, which is determined by the 67 * selection status of the model. */ 68 public State getState() { return model.getState(); } 69 @Override public void setSelected(boolean b) { 97 * @param state The new state 98 */ 99 public void setState(State state) { 100 model.setState(state); 101 } 102 103 /** 104 * Return the current state, which is determined by the selection status of the model. 105 * @return The current state 106 */ 107 public State getState() { 108 return model.getState(); 109 } 110 111 @Override 112 public void setSelected(boolean b) { 70 113 if (b) { 71 114 setState(State.SELECTED); … … 77 120 private class QuadStateDecorator implements ButtonModel { 78 121 private final ButtonModel other; 122 79 123 private QuadStateDecorator(ButtonModel other) { 80 124 this.other = other; 81 125 } 126 82 127 private void setState(State state) { 83 128 if (state == State.NOT_SELECTED) { … … 103 148 } 104 149 } 150 105 151 /** 106 152 * The current state is embedded in the selection / armed … … 139 185 @Override public void setSelected(boolean b) { } 140 186 @Override public void setPressed(boolean b) { } 141 /** We disable focusing on the component when it is not 142 * enabled. */ 187 /** We disable focusing on the component when it is not enabled. */ 143 188 @Override public void setEnabled(boolean b) { 144 189 setFocusable(b); -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r6175 r6221 30 30 import java.util.AbstractList; 31 31 import java.util.ArrayList; 32 import java.util.Arrays; 32 33 import java.util.Collection; 33 34 import java.util.Iterator; … … 241 242 } 242 243 244 /** 245 * Copies the given array. Unlike {@link Arrays#copyOf}, this method is null-safe. 246 * @param array The array to copy 247 * @return A copy of the original array, or {@code null} if {@code array} is null 248 * @since 6221 249 */ 250 public static <T> T[] copyArray(T[] array) { 251 if (array != null) { 252 return Arrays.copyOf(array, array.length); 253 } 254 return null; 255 } 256 243 257 /** 244 258 * Simple file copy function that will overwrite the target file.<br/>
Note:
See TracChangeset
for help on using the changeset viewer.