|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| DirectoryOptionComponent.java | 0% | 40% | 33.3% | 33.3% |
|
||||||||||||||
| 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.config; | |
| 38 | ||
| 39 | import java.io.File; | |
| 40 | import javax.swing.*; | |
| 41 | import javax.swing.event.*; | |
| 42 | import javax.swing.filechooser.FileFilter; | |
| 43 | ||
| 44 | import edu.rice.cs.drjava.config.*; | |
| 45 | import edu.rice.cs.drjava.*; | |
| 46 | import edu.rice.cs.util.swing.DirectorySelectorComponent; | |
| 47 | import edu.rice.cs.util.swing.DirectoryChooser; | |
| 48 | import edu.rice.cs.util.swing.SwingFrame; | |
| 49 | ||
| 50 | /** Graphical form of a FileOption. | |
| 51 | * | |
| 52 | * @version $Id: DirectoryOptionComponent.java 5232 2010-04-24 00:14:05Z mgricken $ | |
| 53 | */ | |
| 54 | public class DirectoryOptionComponent extends OptionComponent<File,DirectorySelectorComponent> implements OptionConstants { | |
| 55 | ||
| 56 | private DirectorySelectorComponent _component; | |
| 57 | ||
| 58 | 76 | public DirectoryOptionComponent (FileOption opt, String text, SwingFrame parent, DirectoryChooser dc) { |
| 59 | 76 | super(opt, text, parent); |
| 60 | ||
| 61 | 76 | _component = new DirectorySelectorComponent(parent, dc, 30, 10f); |
| 62 | 76 | _component.setFileField(DrJava.getConfig().getSetting(_option)); |
| 63 | 76 | _component.getFileField().getDocument().addDocumentListener(new DocumentListener() { |
| 64 | 0 | public void insertUpdate(DocumentEvent e) { notifyChangeListeners(); } |
| 65 | 0 | public void removeUpdate(DocumentEvent e) { notifyChangeListeners(); } |
| 66 | 0 | public void changedUpdate(DocumentEvent e) { notifyChangeListeners(); } |
| 67 | }); | |
| 68 | ||
| 69 | 76 | setComponent(_component); |
| 70 | } | |
| 71 | ||
| 72 | /** Constructor that allows for a tooltip description. */ | |
| 73 | 76 | public DirectoryOptionComponent (FileOption opt, String text, SwingFrame parent, String desc, DirectoryChooser dc) { |
| 74 | 76 | this(opt, text, parent, dc); |
| 75 | 76 | setDescription(desc); |
| 76 | } | |
| 77 | ||
| 78 | /** Sets the tooltip description text for this option. | |
| 79 | * @param description the tooltip text | |
| 80 | */ | |
| 81 | 76 | public void setDescription(String description) { _label.setToolTipText(description); } |
| 82 | ||
| 83 | /** Updates the config object with the new setting. | |
| 84 | * @return true if the new value is set successfully | |
| 85 | */ | |
| 86 | 0 | public boolean updateConfig() { |
| 87 | 0 | File componentFile = _component.getFileFromField(); |
| 88 | 0 | File currentFile = DrJava.getConfig().getSetting(_option); |
| 89 | ||
| 90 | 0 | if (componentFile != null && !componentFile.equals(currentFile)) { |
| 91 | 0 | DrJava.getConfig().setSetting(_option, componentFile); |
| 92 | } | |
| 93 | 0 | else if (componentFile == null) { |
| 94 | 0 | DrJava.getConfig().setSetting(_option, _option.getDefault()); |
| 95 | } | |
| 96 | ||
| 97 | 0 | return true; |
| 98 | } | |
| 99 | ||
| 100 | /** Displays the given value. */ | |
| 101 | 0 | public void setValue(File value) { _component.setFileField(value); } |
| 102 | ||
| 103 | // /** Return's this OptionComponent's configurable component. */ | |
| 104 | // public DirectorySelectorComponent getComponent() { return _component; } | |
| 105 | ||
| 106 | /** Adds a filter to decide if a directory can be chosen. */ | |
| 107 | 0 | public void addChoosableFileFilter(FileFilter filter) { _component.addChoosableFileFilter(filter); } |
| 108 | } |
|
||||||||||