001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Pavel Dolgov, Dmitry A. Durnev
019: * @version $Revision$
020: */package java.awt;
021:
022: import java.io.FilenameFilter;
023:
024: import org.apache.harmony.awt.internal.nls.Messages;
025:
026: public class FileDialog extends Dialog {
027: private static final long serialVersionUID = 5035145889651310422L;
028:
029: public static final int LOAD = 0;
030:
031: public static final int SAVE = 1;
032:
033: private String file;
034: private String directory;
035: private int mode;
036: private FilenameFilter filenameFilter;
037:
038: public FileDialog(Frame owner) {
039: this (owner, ""); //$NON-NLS-1$
040: toolkit.lockAWT();
041: try {
042: } finally {
043: toolkit.unlockAWT();
044: }
045: }
046:
047: public FileDialog(Frame owner, String title) {
048: this (owner, title, LOAD);
049: toolkit.lockAWT();
050: try {
051: } finally {
052: toolkit.unlockAWT();
053: }
054: }
055:
056: public FileDialog(Frame owner, String title, int mode) {
057: super (owner, title, true); // initially always modal
058: toolkit.lockAWT();
059: try {
060: setMode(mode);
061: setLayout(null);
062: } finally {
063: toolkit.unlockAWT();
064: }
065: }
066:
067: public FileDialog(Dialog owner) {
068: this (owner, ""); //$NON-NLS-1$
069: toolkit.lockAWT();
070: try {
071: } finally {
072: toolkit.unlockAWT();
073: }
074: }
075:
076: public FileDialog(Dialog owner, String title) {
077: this (owner, title, LOAD);
078: toolkit.lockAWT();
079: try {
080: } finally {
081: toolkit.unlockAWT();
082: }
083: }
084:
085: public FileDialog(Dialog owner, String title, int mode) {
086: super (owner, title, true); // initially always modal
087: toolkit.lockAWT();
088: try {
089: setMode(mode);
090: setLayout(null);
091: } finally {
092: toolkit.unlockAWT();
093: }
094: }
095:
096: public String getFile() {
097: toolkit.lockAWT();
098: try {
099: return file;
100: } finally {
101: toolkit.unlockAWT();
102: }
103: }
104:
105: @Override
106: protected String paramString() {
107: /* The format is based on 1.5 release behavior
108: * which can be revealed by the following code:
109: * System.out.println(new FileDialog(new Frame()));
110: */
111:
112: toolkit.lockAWT();
113: try {
114: return (super .paramString() + ",dir=" + directory + //$NON-NLS-1$
115: ",file=" + file + "," + //$NON-NLS-1$ //$NON-NLS-2$
116: (mode == LOAD ? "load" : "save")); //$NON-NLS-1$ //$NON-NLS-2$
117: } finally {
118: toolkit.unlockAWT();
119: }
120: }
121:
122: @Override
123: public void addNotify() {
124: toolkit.lockAWT();
125: try {
126: // TODO: implement
127: super .addNotify();
128: } finally {
129: toolkit.unlockAWT();
130: }
131: }
132:
133: public String getDirectory() {
134: toolkit.lockAWT();
135: try {
136: return directory;
137: } finally {
138: toolkit.unlockAWT();
139: }
140: }
141:
142: public FilenameFilter getFilenameFilter() {
143: toolkit.lockAWT();
144: try {
145: return filenameFilter;
146: } finally {
147: toolkit.unlockAWT();
148: }
149: }
150:
151: public int getMode() {
152: toolkit.lockAWT();
153: try {
154: return mode;
155: } finally {
156: toolkit.unlockAWT();
157: }
158: }
159:
160: public void setDirectory(String dir) {
161: toolkit.lockAWT();
162: try {
163: directory = (dir == "" ? null : dir); //$NON-NLS-1$
164: } finally {
165: toolkit.unlockAWT();
166: }
167: }
168:
169: public void setFile(String file) {
170: toolkit.lockAWT();
171: try {
172: this .file = (file == "" ? null : file); //$NON-NLS-1$
173: } finally {
174: toolkit.unlockAWT();
175: }
176: }
177:
178: public void setFilenameFilter(FilenameFilter filter) {
179: toolkit.lockAWT();
180: try {
181: this .filenameFilter = filter;
182: } finally {
183: toolkit.unlockAWT();
184: }
185: }
186:
187: public void setMode(int mode) {
188: toolkit.lockAWT();
189: try {
190: if (!((mode == LOAD) || (mode == SAVE))) {
191: // awt.145=illegal file dialog mode
192: throw new IllegalArgumentException(Messages
193: .getString("awt.145")); //$NON-NLS-1$
194: }
195: this .mode = mode;
196: } finally {
197: toolkit.unlockAWT();
198: }
199: }
200:
201: @Override
202: void showImpl() {
203: if (toolkit.theme.showFileDialog(this )) {
204: super .showImpl();
205: }
206: }
207:
208: @Override
209: void hideImpl() {
210: if (toolkit.theme.hideFileDialog(this )) {
211: super .hideImpl();
212: }
213: }
214:
215: @Override
216: ComponentBehavior createBehavior() {
217: return new HWBehavior(this ) {
218: @Override
219: public void removeNotify() {
220: super .removeNotify();
221: hideImpl();
222: }
223: };
224: }
225:
226: @Override
227: String autoName() {
228: return "filedlg" + toolkit.autoNumber.nextFileDialog++; //$NON-NLS-1$
229: }
230: }
|