1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.plugin.desktoputil;
import java.awt.*;
import java.io.*;
import java.net.*;
import org.jitsi.util.*;
/**
* Implements <tt>SipCommFileChooser</tt> for AWT's <tt>FileDialog</tt>.
*
* @author Valentin Martinet
*/
public class SipCommFileDialogImpl
extends FileDialog
implements SipCommFileChooser
{
/**
* The serialization-related version of the <tt>SipCommFileDialogImpl</tt>
* class explicitly defined to silence a related warning (e.g. in Eclipse
* IDE) since the <tt>SipCommFileDialogImpl</tt> class does not add instance
* fields.
*/
private static final long serialVersionUID = 0L;
/**
* The selection mode, the default is files only, can be changed to
* DIRECTORIES_ONLY.
*/
private int selectionMode = FILES_ONLY;
/**
* Constructor
*
* @param parent the parent frame of this dialog
* @param title the title for this dialog
*/
public SipCommFileDialogImpl(Frame parent, String title)
{
super(parent, title);
}
/**
* Constructor
*
* @param parent the parent frame of this dialog
* @param title the title for this dialog
* @param fileOperation request a 'load file' or 'save file' dialog
*/
public SipCommFileDialogImpl(Frame parent, String title, int fileOperation)
{
super(parent, title, fileOperation);
}
/**
* Returns the selected file by the user from the dialog.
*
* @return File the selected file from the dialog
*/
public File getApprovedFile()
{
String file = getFile();
return (file != null) ? new File(getDirectory(), file) : null;
}
/**
* Sets the default path to be considered for browsing among files.
*
* @param path the default start path for this dialog
*/
public void setStartPath(String path)
{
// If the path is null, we have nothing more to do here.
if (path == null)
return;
// If the path is an URL extract the path from the URL in order to
// remove the "file:" part, which doesn't work with methods provided
// by the file chooser.
try
{
URL url = new URL(path);
path = url.getPath();
}
catch (MalformedURLException e) {}
File file = new File(path);
if ((file != null) && !file.isDirectory())
{
setDirectory(file.getParent());
setFile(file.getName());
}
else
{
setDirectory(path);
setFile(null);
}
}
/**
* Shows the dialog and returns the selected file.
*
* @return File the selected file in this dialog
*/
public File getFileFromDialog()
{
this.setVisible(true);
return this.getApprovedFile();
}
/**
* Adds a file filter to this dialog.
*
* @param filter the filter to add
*/
public void addFilter(SipCommFileFilter filter)
{
this.setFilenameFilter(filter);
}
/**
* Sets a file filter to this dialog.
*
* @param filter the filter to add
*/
public void setFileFilter(SipCommFileFilter filter)
{
this.setFilenameFilter(filter);
}
/**
* Returns the filter the user has chosen for saving a file.
*
* @return SipCommFileFilter the used filter when saving a file
*/
public SipCommFileFilter getUsedFilter()
{
return (SipCommFileFilter)this.getFilenameFilter();
}
/**
* Change the selection mode for the file choose.
* Possible values are DIRECTORIES_ONLY or FILES_ONLY, default is
* FILES_ONLY.
*
* @param mode the mode to use.
*/
public void setSelectionMode(int mode)
{
this.selectionMode = mode;
}
/**
* Shows or hides the file chooser dialog.
* @param b if <code>true</code>, shows the dialog;
* otherwise, hides it
*/
@Override
public void setVisible(boolean b)
{
// workaround to make sure we choose only folders on macosx
if(OSUtils.IS_MAC && selectionMode == DIRECTORIES_ONLY)
System.setProperty(
"apple.awt.fileDialogForDirectories", "true");
super.setVisible(b);
if(OSUtils.IS_MAC && selectionMode == DIRECTORIES_ONLY)
System.setProperty(
"apple.awt.fileDialogForDirectories", "false");
}
}
|