Browse Source

More random code tidying

Change-Id: I91c512b1d7c0bcba3793d30d8f83c93808d8a7b2
Reviewed-on: http://gerrit.dmdirc.com/1740
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Greg Holmes <greg@dmdirc.com>
tags/0.6.5
Chris Smith 13 years ago
parent
commit
bd54b3c9c9

+ 7
- 3
src/com/dmdirc/addons/dcc/kde/KDialogProcess.java View File

@@ -32,10 +32,10 @@ import java.util.ArrayList;
32 32
 public class KDialogProcess {
33 33
 
34 34
     /** Is kdialog in /bin? */
35
-    private static final boolean IS_BIN = (new File("/bin/kdialog")).exists();
35
+    private static final boolean IS_BIN = new File("/bin/kdialog").exists();
36 36
 
37 37
     /** Does KDialog exist? */
38
-    private static final boolean HAS_KDIALOG = (new File("/usr/bin/kdialog")).exists() || IS_BIN;
38
+    private static final boolean HAS_KDIALOG = IS_BIN || new File("/usr/bin/kdialog").exists();
39 39
 
40 40
     /** Stream for the stdout stream for this process */
41 41
     private final StreamReader stdOutputStream;
@@ -50,11 +50,12 @@ public class KDialogProcess {
50 50
      * Execute kdialog with the Parameters in params
51 51
      *
52 52
      * @param params Parameters to pass to kdialog
53
+     * @throws IOException if an I/O error occurs
53 54
      */
54 55
     public KDialogProcess(final String[] params) throws IOException {
55 56
         final String[] exec = new String[params.length + 1];
56 57
         System.arraycopy(params, 0, exec, 1, params.length);
57
-        exec[0] = (IS_BIN) ? "/bin/kdialog" : "/usr/bin/kdialog";
58
+        exec[0] = IS_BIN ? "/bin/kdialog" : "/usr/bin/kdialog";
58 59
         process = Runtime.getRuntime().exec(exec);
59 60
         stdOutputStream = new StreamReader(process.getInputStream(), new ArrayList<String>());
60 61
         stdErrorStream = new StreamReader(process.getErrorStream(), new ArrayList<String>());
@@ -100,6 +101,9 @@ public class KDialogProcess {
100 101
 
101 102
     /**
102 103
      * Wait for the process to finish.
104
+     *
105
+     * @throws InterruptedException if the current thread is interrupted by
106
+     * another thread while it is waiting
103 107
      */
104 108
     public void waitFor() throws InterruptedException {
105 109
         process.waitFor();

+ 74
- 66
src/com/dmdirc/addons/dcc/kde/KFileChooser.java View File

@@ -23,7 +23,6 @@
23 23
 package com.dmdirc.addons.dcc.kde;
24 24
 
25 25
 import com.dmdirc.addons.dcc.DCCPlugin;
26
-
27 26
 import com.dmdirc.config.IdentityManager;
28 27
 
29 28
 import java.awt.Component;
@@ -70,155 +69,155 @@ public final class KFileChooser extends JFileChooser {
70 69
     /** The plugin that this file chooser is for. */
71 70
     private final DCCPlugin plugin;
72 71
 
73
-    /**
74
-     * Should a KFileChooser be used rather than a JFileChooser?
75
-     *
76
-     * @param plugin The DCC Plugin that is requesting a chooser
77
-     * @return return true if getFileChooser() will return a KFileChooser not a
78
-     *         JFileChooser
79
-     */
80
-    public static boolean useKFileChooser(final DCCPlugin plugin) {
81
-        return KDialogProcess.hasKDialog() && IdentityManager.getGlobalConfig().getOptionBool(plugin.getDomain(), "general.useKFileChooser");
82
-    }
83
-
84 72
     /**
85 73
      * Constructs a FileChooser pointing to the user's default directory.
86 74
      *
87
-     * @param plugin The DCC Plugin that is requesting a chooser
88
-     * @return The relevant FileChooser
75
+     * @param plugin The plugin that owns this KFileChooser
89 76
      */
90
-    public static JFileChooser getFileChooser(final DCCPlugin plugin) {
91
-        return useKFileChooser(plugin) ? new KFileChooser(plugin) : new JFileChooser();
77
+    private KFileChooser(final DCCPlugin plugin) {
78
+        super();
79
+
80
+        this.plugin = plugin;
92 81
     }
93 82
 
94 83
     /**
95 84
      * Constructs a FileChooser using the given File as the path.
96 85
      *
97
-     * @param plugin The DCC Plugin that is requesting a chooser
86
+     * @param plugin The plugin that owns this KFileChooser
98 87
      * @param currentDirectory Directory to use as the base directory
99
-     * @return The relevant FileChooser
100 88
      */
101
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final File currentDirectory) {
102
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectory) : new JFileChooser(currentDirectory);
89
+    private KFileChooser(final DCCPlugin plugin, final File currentDirectory) {
90
+        super(currentDirectory);
91
+
92
+        this.plugin = plugin;
103 93
     }
104 94
 
105 95
     /**
106 96
      * Constructs a FileChooser using the given current directory and FileSystemView.
107 97
      *
108
-     * @param plugin The DCC Plugin that is requesting a chooser
98
+     * @param plugin The plugin that owns this KFileChooser
109 99
      * @param currentDirectory Directory to use as the base directory
110 100
      * @param fsv The FileSystemView to use
111
-     * @return The relevant FileChooser
112 101
      */
113
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
114
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectory, fsv) : new JFileChooser(currentDirectory, fsv);
102
+    private KFileChooser(final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
103
+        super(currentDirectory, fsv);
104
+
105
+        this.plugin = plugin;
115 106
     }
116 107
 
117 108
     /**
118 109
      * Constructs a FileChooser using the given FileSystemView.
119 110
      *
120
-     * @param plugin The DCC Plugin that is requesting a chooser
111
+     * @param plugin The plugin that owns this KFileChooser
121 112
      * @param fsv The FileSystemView to use
122
-     * @return The relevant FileChooser
123 113
      */
124
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final FileSystemView fsv) {
125
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, fsv) : new JFileChooser(fsv);
114
+    private KFileChooser(final DCCPlugin plugin, final FileSystemView fsv) {
115
+        super(fsv);
116
+
117
+        this.plugin = plugin;
126 118
     }
127 119
 
128 120
     /**
129 121
      * Constructs a FileChooser using the given path.
130 122
      *
131
-     * @param plugin The DCC Plugin that is requesting a chooser
123
+     * @param plugin The plugin that owns this KFileChooser
132 124
      * @param currentDirectoryPath Directory to use as the base directory
133
-     * @return The relevant FileChooser
134 125
      */
135
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final String currentDirectoryPath) {
136
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectoryPath) : new JFileChooser(currentDirectoryPath);
126
+    private KFileChooser(final DCCPlugin plugin, final String currentDirectoryPath) {
127
+        super(currentDirectoryPath);
128
+
129
+        this.plugin = plugin;
137 130
     }
138 131
 
139 132
     /**
140 133
      * Constructs a FileChooser using the given current directory path and FileSystemView.
141 134
      *
142
-     * @param plugin The DCC Plugin that is requesting a chooser
135
+     * @param plugin The plugin that owns this KFileChooser
143 136
      * @param currentDirectoryPath Directory to use as the base directory
144 137
      * @param fsv The FileSystemView to use
145
-     * @return The relevant FileChooser
146 138
      */
147
-    public static JFileChooser getFileChooser(final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
148
-        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectoryPath, fsv) : new JFileChooser(currentDirectoryPath, fsv);
139
+    private KFileChooser(final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
140
+        super(currentDirectoryPath, fsv);
141
+
142
+        this.plugin = plugin;
149 143
     }
150 144
 
151 145
     /**
152
-     * Constructs a FileChooser pointing to the user's default directory.
146
+     * Should a KFileChooser be used rather than a JFileChooser?
153 147
      *
154
-     * @param plugin The plugin that owns this KFileChooser
148
+     * @param plugin The DCC Plugin that is requesting a chooser
149
+     * @return return true if getFileChooser() will return a KFileChooser not a
150
+     *         JFileChooser
155 151
      */
156
-    private KFileChooser(final DCCPlugin plugin) {
157
-        super();
152
+    public static boolean useKFileChooser(final DCCPlugin plugin) {
153
+        return KDialogProcess.hasKDialog() && IdentityManager.getGlobalConfig().getOptionBool(plugin.getDomain(), "general.useKFileChooser");
154
+    }
158 155
 
159
-        this.plugin = plugin;
156
+    /**
157
+     * Constructs a FileChooser pointing to the user's default directory.
158
+     *
159
+     * @param plugin The DCC Plugin that is requesting a chooser
160
+     * @return The relevant FileChooser
161
+     */
162
+    public static JFileChooser getFileChooser(final DCCPlugin plugin) {
163
+        return useKFileChooser(plugin) ? new KFileChooser(plugin) : new JFileChooser();
160 164
     }
161 165
 
162 166
     /**
163 167
      * Constructs a FileChooser using the given File as the path.
164 168
      *
165
-     * @param plugin The plugin that owns this KFileChooser
169
+     * @param plugin The DCC Plugin that is requesting a chooser
166 170
      * @param currentDirectory Directory to use as the base directory
171
+     * @return The relevant FileChooser
167 172
      */
168
-    private KFileChooser(final DCCPlugin plugin, final File currentDirectory) {
169
-        super(currentDirectory);
170
-
171
-        this.plugin = plugin;
173
+    public static JFileChooser getFileChooser(final DCCPlugin plugin, final File currentDirectory) {
174
+        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectory) : new JFileChooser(currentDirectory);
172 175
     }
173 176
 
174 177
     /**
175 178
      * Constructs a FileChooser using the given current directory and FileSystemView.
176 179
      *
177
-     * @param plugin The plugin that owns this KFileChooser
180
+     * @param plugin The DCC Plugin that is requesting a chooser
178 181
      * @param currentDirectory Directory to use as the base directory
179 182
      * @param fsv The FileSystemView to use
183
+     * @return The relevant FileChooser
180 184
      */
181
-    private KFileChooser(final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
182
-        super(currentDirectory, fsv);
183
-
184
-        this.plugin = plugin;
185
+    public static JFileChooser getFileChooser(final DCCPlugin plugin, final File currentDirectory, final FileSystemView fsv) {
186
+        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectory, fsv) : new JFileChooser(currentDirectory, fsv);
185 187
     }
186 188
 
187 189
     /**
188 190
      * Constructs a FileChooser using the given FileSystemView.
189 191
      *
190
-     * @param plugin The plugin that owns this KFileChooser
192
+     * @param plugin The DCC Plugin that is requesting a chooser
191 193
      * @param fsv The FileSystemView to use
194
+     * @return The relevant FileChooser
192 195
      */
193
-    private KFileChooser(final DCCPlugin plugin, final FileSystemView fsv) {
194
-        super(fsv);
195
-
196
-        this.plugin = plugin;
196
+    public static JFileChooser getFileChooser(final DCCPlugin plugin, final FileSystemView fsv) {
197
+        return useKFileChooser(plugin) ? new KFileChooser(plugin, fsv) : new JFileChooser(fsv);
197 198
     }
198 199
 
199 200
     /**
200 201
      * Constructs a FileChooser using the given path.
201 202
      *
202
-     * @param plugin The plugin that owns this KFileChooser
203
+     * @param plugin The DCC Plugin that is requesting a chooser
203 204
      * @param currentDirectoryPath Directory to use as the base directory
205
+     * @return The relevant FileChooser
204 206
      */
205
-    private KFileChooser(final DCCPlugin plugin, final String currentDirectoryPath) {
206
-        super(currentDirectoryPath);
207
-
208
-        this.plugin = plugin;
207
+    public static JFileChooser getFileChooser(final DCCPlugin plugin, final String currentDirectoryPath) {
208
+        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectoryPath) : new JFileChooser(currentDirectoryPath);
209 209
     }
210 210
 
211 211
     /**
212 212
      * Constructs a FileChooser using the given current directory path and FileSystemView.
213 213
      *
214
-     * @param plugin The plugin that owns this KFileChooser
214
+     * @param plugin The DCC Plugin that is requesting a chooser
215 215
      * @param currentDirectoryPath Directory to use as the base directory
216 216
      * @param fsv The FileSystemView to use
217
+     * @return The relevant FileChooser
217 218
      */
218
-    private KFileChooser(final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
219
-        super(currentDirectoryPath, fsv);
220
-
221
-        this.plugin = plugin;
219
+    public static JFileChooser getFileChooser(final DCCPlugin plugin, final String currentDirectoryPath, final FileSystemView fsv) {
220
+        return useKFileChooser(plugin) ? new KFileChooser(plugin, currentDirectoryPath, fsv) : new JFileChooser(currentDirectoryPath, fsv);
222 221
     }
223 222
 
224 223
     /**
@@ -245,20 +244,24 @@ public final class KFileChooser extends JFileChooser {
245 244
         if (!useKFileChooser(plugin)) {
246 245
             return super.showOpenDialog(parent);
247 246
         }
247
+
248 248
         final ArrayList<String> params = new ArrayList<String>();
249 249
         if (isMultiSelectionEnabled()) {
250 250
             params.add("--multiple");
251 251
             params.add("--separate-output");
252 252
         }
253
+
253 254
         if (getDialogTitle() != null && !getDialogTitle().isEmpty()) {
254 255
             params.add("--caption");
255 256
             params.add(getDialogTitle());
256 257
         }
258
+
257 259
         if (getFileSelectionMode() == DIRECTORIES_ONLY) {
258 260
             params.add("--getexistingdirectory");
259 261
         } else {
260 262
             params.add("--getopenfilename");
261 263
         }
264
+
262 265
         if (getSelectedFile() != null && getFileSelectionMode() != DIRECTORIES_ONLY && !getSelectedFile().getPath().isEmpty()) {
263 266
             if (getSelectedFile().getPath().charAt(0) != '/') {
264 267
                 params.add(getCurrentDirectory().getPath() + File.separator + getSelectedFile().getPath());
@@ -268,9 +271,11 @@ public final class KFileChooser extends JFileChooser {
268 271
         } else if (getCurrentDirectory() != null) {
269 272
             params.add(getCurrentDirectory().getPath());
270 273
         }
274
+
271 275
         if (getFileSelectionMode() != DIRECTORIES_ONLY && fileFilter != null && !fileFilter.isEmpty()) {
272 276
             params.add(fileFilter);
273 277
         }
278
+
274 279
         KDialogProcess kdp;
275 280
         try {
276 281
             kdp = new KDialogProcess(params.toArray(new String[0]));
@@ -302,11 +307,13 @@ public final class KFileChooser extends JFileChooser {
302 307
         if (!useKFileChooser(plugin)) {
303 308
             return super.showSaveDialog(parent);
304 309
         }
310
+
305 311
         final ArrayList<String> params = new ArrayList<String>();
306 312
         if (getDialogTitle() != null && !getDialogTitle().isEmpty()) {
307 313
             params.add("--caption");
308 314
             params.add(getDialogTitle());
309 315
         }
316
+
310 317
         params.add("--getsavefilename");
311 318
         if (getSelectedFile() != null && !getSelectedFile().getPath().isEmpty()) {
312 319
             if (getSelectedFile().getPath().charAt(0) != '/') {
@@ -317,6 +324,7 @@ public final class KFileChooser extends JFileChooser {
317 324
         } else if (getCurrentDirectory() != null) {
318 325
             params.add(getCurrentDirectory().getPath());
319 326
         }
327
+
320 328
         KDialogProcess kdp;
321 329
         try {
322 330
             kdp = new KDialogProcess(params.toArray(new String[0]));

Loading…
Cancel
Save