aboutsummaryrefslogtreecommitdiffstats
path: root/java/com/tigervnc
diff options
context:
space:
mode:
authorBrian P. Hinz <bphinz@users.sf.net>2016-08-28 21:15:17 -0400
committerBrian P. Hinz <bphinz@users.sf.net>2016-08-28 21:15:17 -0400
commit2272734ca298a8db63ea58fe0e40cc8a630209d7 (patch)
treec9b56933c1c3ca6a00cab7091ca1cea12819e2d5 /java/com/tigervnc
parentc456387fe1ed922c5bfb5daf0e780f0000cab2fb (diff)
downloadtigervnc-2272734ca298a8db63ea58fe0e40cc8a630209d7.tar.gz
tigervnc-2272734ca298a8db63ea58fe0e40cc8a630209d7.zip
Added filename filters to file chooser dialogs
Diffstat (limited to 'java/com/tigervnc')
-rw-r--r--java/com/tigervnc/vncviewer/Dialog.java15
-rw-r--r--java/com/tigervnc/vncviewer/F8Menu.java7
-rw-r--r--java/com/tigervnc/vncviewer/OptionsDialog.java9
-rw-r--r--java/com/tigervnc/vncviewer/ServerDialog.java11
4 files changed, 34 insertions, 8 deletions
diff --git a/java/com/tigervnc/vncviewer/Dialog.java b/java/com/tigervnc/vncviewer/Dialog.java
index 4419159e..6204ba10 100644
--- a/java/com/tigervnc/vncviewer/Dialog.java
+++ b/java/com/tigervnc/vncviewer/Dialog.java
@@ -34,6 +34,7 @@ import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import javax.swing.border.*;
+import javax.swing.filechooser.*;
import javax.swing.text.*;
class Dialog extends JDialog implements ActionListener,
@@ -137,17 +138,29 @@ class Dialog extends JDialog implements ActionListener,
return width + gap;
}
- public static File showChooser(String title, File defFile, Container c) {
+ public static File showChooser(String title, File defFile,
+ Container c, FileNameExtensionFilter f) {
JFileChooser fc = new JFileChooser(defFile);
fc.setDialogTitle(title);
fc.setApproveButtonText("OK \u21B5");
fc.setFileHidingEnabled(false);
+ if (f != null)
+ fc.setFileFilter(f);
if (fc.showOpenDialog(c) == JFileChooser.APPROVE_OPTION)
return fc.getSelectedFile();
else
return null;
}
+ public static File showChooser(String title, File defFile, Container c) {
+ return showChooser(title, defFile, c, null);
+ }
+
+ protected File showChooser(String title, File defFile,
+ FileNameExtensionFilter f) {
+ return showChooser(title, defFile, this, f);
+ }
+
protected File showChooser(String title, File defFile) {
return showChooser(title, defFile, this);
}
diff --git a/java/com/tigervnc/vncviewer/F8Menu.java b/java/com/tigervnc/vncviewer/F8Menu.java
index 6aadb2d3..d7f9e482 100644
--- a/java/com/tigervnc/vncviewer/F8Menu.java
+++ b/java/com/tigervnc/vncviewer/F8Menu.java
@@ -23,6 +23,7 @@ import java.awt.*;
import java.awt.Cursor;
import java.awt.event.*;
import java.io.File;
+import javax.swing.filechooser.*;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JDialog;
import javax.swing.JFrame;
@@ -139,7 +140,9 @@ public class F8Menu extends JPopupMenu implements ActionListener {
File dflt = new File(FileUtils.getVncHomeDir().concat("default.tigervnc"));
if (!dflt.exists() || !dflt.isFile())
dflt = new File(FileUtils.getVncHomeDir());
- File f = Dialog.showChooser(title, dflt, this);
+ FileNameExtensionFilter filter =
+ new FileNameExtensionFilter("TigerVNC configuration (*.tigervnc)", "tigervnc");
+ File f = Dialog.showChooser(title, dflt, this, filter);
while (f != null && f.exists() && f.isFile()) {
String msg = f.getAbsolutePath();
msg = msg.concat(" already exists. Do you want to overwrite?");
@@ -154,7 +157,7 @@ public class F8Menu extends JPopupMenu implements ActionListener {
if (op.getValue() == options[0])
break;
else
- f = Dialog.showChooser(title, f, this);
+ f = Dialog.showChooser(title, f, this, filter);
}
if (f != null && (!f.exists() || f.canWrite()))
saveViewerParameters(f.getAbsolutePath(), vncServerName.getValue());
diff --git a/java/com/tigervnc/vncviewer/OptionsDialog.java b/java/com/tigervnc/vncviewer/OptionsDialog.java
index 8d49a2e3..4bcb7d8a 100644
--- a/java/com/tigervnc/vncviewer/OptionsDialog.java
+++ b/java/com/tigervnc/vncviewer/OptionsDialog.java
@@ -27,6 +27,7 @@ import java.text.Format;
import java.text.NumberFormat;
import javax.swing.*;
import javax.swing.border.*;
+import javax.swing.filechooser.*;
import javax.swing.UIManager.*;
import javax.swing.text.*;
import java.util.*;
@@ -779,7 +780,9 @@ class OptionsDialog extends Dialog {
public void actionPerformed(ActionEvent e) {
JComponent c = ((JButton)e.getSource()).getRootPane();
File dflt = new File(CSecurityTLS.X509CA.getValueStr());
- File f = showChooser("Path to X509 CA certificate", dflt, c);
+ FileNameExtensionFilter filter =
+ new FileNameExtensionFilter("X.509 certificate", "crt", "cer", "pem");
+ File f = showChooser("Path to X509 CA certificate", dflt, c, filter);
if (f != null && f.exists() && f.canRead())
caInput.setText(f.getAbsolutePath());
}
@@ -791,7 +794,9 @@ class OptionsDialog extends Dialog {
public void actionPerformed(ActionEvent e) {
JComponent c = ((JButton)e.getSource()).getRootPane();
File dflt = new File(CSecurityTLS.X509CRL.getValueStr());
- File f = showChooser("Path to X509 CRL file", dflt, c);
+ FileNameExtensionFilter filter =
+ new FileNameExtensionFilter("X.509 CRL", "crl");
+ File f = showChooser("Path to X509 CRL file", dflt, c, filter);
if (f != null && f.exists() && f.canRead())
crlInput.setText(f.getAbsolutePath());
}
diff --git a/java/com/tigervnc/vncviewer/ServerDialog.java b/java/com/tigervnc/vncviewer/ServerDialog.java
index 338e6266..4b3f26bf 100644
--- a/java/com/tigervnc/vncviewer/ServerDialog.java
+++ b/java/com/tigervnc/vncviewer/ServerDialog.java
@@ -24,6 +24,7 @@ import java.awt.event.*;
import java.io.File;
import javax.swing.*;
import javax.swing.border.*;
+import javax.swing.filechooser.*;
import javax.swing.WindowConstants.*;
import java.util.*;
@@ -221,7 +222,9 @@ class ServerDialog extends Dialog implements Runnable {
private void handleLoad() {
String title = "Select a TigerVNC configuration file";
File dflt = new File(FileUtils.getVncHomeDir().concat("default.tigervnc"));
- File f = showChooser(title, dflt);
+ FileNameExtensionFilter filter =
+ new FileNameExtensionFilter("TigerVNC configuration (*.tigervnc)", "tigervnc");
+ File f = showChooser(title, dflt, filter);
if (f != null && f.exists() && f.canRead())
loadViewerParameters(f.getAbsolutePath());
}
@@ -231,7 +234,9 @@ class ServerDialog extends Dialog implements Runnable {
File dflt = new File(FileUtils.getVncHomeDir().concat("default.tigervnc"));
if (!dflt.exists() || !dflt.isFile())
dflt = new File(FileUtils.getVncHomeDir());
- File f = showChooser(title, dflt);
+ FileNameExtensionFilter filter =
+ new FileNameExtensionFilter("TigerVNC configuration (*.tigervnc)", "tigervnc");
+ File f = showChooser(title, dflt, filter);
while (f != null && f.exists() && f.isFile()) {
String msg = f.getAbsolutePath();
msg = msg.concat(" already exists. Do you want to overwrite?");
@@ -246,7 +251,7 @@ class ServerDialog extends Dialog implements Runnable {
if (op.getValue() == options[0])
break;
else
- f = showChooser(title, f);
+ f = showChooser(title, f, filter);
}
if (f != null && (!f.exists() || f.canWrite()))
saveViewerParameters(f.getAbsolutePath(), (String)server.getSelectedItem());