001: /**
002: * L2FProd.com Common Components 7.3 License.
003: *
004: * Copyright 2005-2007 L2FProd.com
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */package com.l2fprod.common.swing;
018:
019: import com.l2fprod.common.swing.plaf.DirectoryChooserUI;
020: import com.l2fprod.common.swing.plaf.JDirectoryChooserAddon;
021: import com.l2fprod.common.swing.plaf.LookAndFeelAddons;
022:
023: import java.awt.Component;
024: import java.awt.HeadlessException;
025: import java.io.File;
026:
027: import javax.swing.JComponent;
028: import javax.swing.JDialog;
029: import javax.swing.JFileChooser;
030: import javax.swing.filechooser.FileSystemView;
031: import javax.swing.plaf.ComponentUI;
032:
033: /**
034: * An extension of the JFileChooser but dedicated to directory selection. <br>
035: *
036: * @javabean.class
037: * name="JDirectoryChooser"
038: * shortDescription="JDirectoryChooser allows to select one or more directories."
039: * stopClass="javax.swing.JFileChooser"
040: *
041: * @javabean.icons
042: * mono16="JDirectoryChooser16-mono.gif"
043: * color16="JDirectoryChooser16.gif"
044: * mono32="JDirectoryChooser32-mono.gif"
045: * color32="JDirectoryChooser32.gif"
046: */
047: public class JDirectoryChooser extends JFileChooser {
048:
049: public final static String UI_CLASS_ID = "l2fprod/DirectoryChooserUI";
050:
051: // ensure at least the default ui is registered
052: static {
053: LookAndFeelAddons.contribute(new JDirectoryChooserAddon());
054: }
055:
056: private boolean showingCreateDirectory;
057:
058: /**
059: * Used when generating PropertyChangeEvents for the "showingCreateDirectory" property
060: */
061: public static final String SHOWING_CREATE_DIRECTORY_CHANGED_KEY = "showingCreateDirectory";
062:
063: /**
064: * Creates a JDirectoryChooser pointing to the user's home directory.
065: */
066: public JDirectoryChooser() {
067: super ();
068: setShowingCreateDirectory(true);
069: }
070:
071: /**
072: * Creates a JDirectoryChooser using the given File as the path.
073: *
074: * @param currentDirectory
075: */
076: public JDirectoryChooser(File currentDirectory) {
077: super (currentDirectory);
078: setShowingCreateDirectory(true);
079: }
080:
081: /**
082: * Creates a JDirectoryChooser using the given current directory and
083: * FileSystemView
084: *
085: * @param currentDirectory
086: * @param fsv
087: */
088: public JDirectoryChooser(File currentDirectory, FileSystemView fsv) {
089: super (currentDirectory, fsv);
090: setShowingCreateDirectory(true);
091: }
092:
093: /**
094: * Creates a JDirectoryChooser using the given FileSystemView
095: *
096: * @param fsv
097: */
098: public JDirectoryChooser(FileSystemView fsv) {
099: super (fsv);
100: setShowingCreateDirectory(true);
101: }
102:
103: /**
104: * Creates a JDirectoryChooser using the given path.
105: *
106: * @param currentDirectoryPath
107: */
108: public JDirectoryChooser(String currentDirectoryPath) {
109: super (currentDirectoryPath);
110: setShowingCreateDirectory(true);
111: }
112:
113: public JDirectoryChooser(String currentDirectoryPath,
114: FileSystemView fsv) {
115: super (currentDirectoryPath, fsv);
116: setShowingCreateDirectory(true);
117: }
118:
119: /**
120: * Notification from the <code>UIManager</code> that the L&F has changed.
121: * Replaces the current UI object with the latest version from the <code>UIManager</code>.
122: *
123: * @see javax.swing.JComponent#updateUI
124: */
125: public void updateUI() {
126: setUI((DirectoryChooserUI) LookAndFeelAddons.getUI(this ,
127: DirectoryChooserUI.class));
128: }
129:
130: /**
131: * Sets the L&F object that renders this component.
132: *
133: * @param ui the <code>DirectoryChooserUI</code> L&F object
134: * @see javax.swing.UIDefaults#getUI
135: *
136: * @beaninfo bound: true hidden: true description: The UI object that
137: * implements the taskpane group's LookAndFeel.
138: */
139: public void setUI(DirectoryChooserUI ui) {
140: super .setUI((ComponentUI) ui);
141: }
142:
143: /**
144: * Returns the name of the L&F class that renders this component.
145: *
146: * @return the string {@link #UI_CLASS_ID}
147: * @see javax.swing.JComponent#getUIClassID
148: * @see javax.swing.UIDefaults#getUI
149: */
150: public String getUIClassID() {
151: return UI_CLASS_ID;
152: }
153:
154: /**
155: *
156: * @return true if the "Make New Folder" button is shown, false otherwise
157: */
158: public boolean isShowingCreateDirectory() {
159: return showingCreateDirectory;
160: }
161:
162: /**
163: * Sets whether or not the "Make New Folder" button is shown in the control
164: * button area. Default is true.
165: *
166: * @param showingCreateDirectory
167: * @javabean.property
168: * bound="true"
169: * preferred="true"
170: */
171: public void setShowingCreateDirectory(boolean showingCreateDirectory) {
172: this .showingCreateDirectory = showingCreateDirectory;
173: firePropertyChange(SHOWING_CREATE_DIRECTORY_CHANGED_KEY,
174: !showingCreateDirectory, showingCreateDirectory);
175: }
176:
177: protected JDialog createDialog(Component parent)
178: throws HeadlessException {
179: JDialog dialog = super .createDialog(parent);
180: ((JComponent) dialog.getContentPane())
181: .setBorder(LookAndFeelTweaks.WINDOW_BORDER);
182: return dialog;
183: }
184:
185: }
|