serverPort = Hostname.getPort(vncServerName);
} else {
ServerDialog dlg = new ServerDialog(options, vncServerName, this);
- if (!dlg.showDialog() || dlg.server.getSelectedItem().equals("")) {
- vlog.info("No server name specified!");
+ boolean ret = dlg.showDialog();
+ if (!ret) {
close();
return;
}
- vncServerName = (String)dlg.server.getSelectedItem();
- serverHost = Hostname.getHost(vncServerName);
- serverPort = Hostname.getPort(vncServerName);
+ serverHost = viewer.vncServerName.getValueStr();
+ serverPort = viewer.vncServerPort.getValue();
}
try {
pkgDate = attributes.getValue("Package-Date");
pkgTime = attributes.getValue("Package-Time");
} catch (IOException e) { }
+
+ Window fullScreenWindow = Viewport.getFullScreenWindow();
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(null);
JOptionPane.showMessageDialog((viewport != null ? viewport : null),
String.format(VncViewer.aboutText, VncViewer.version, VncViewer.build,
VncViewer.buildDate, VncViewer.buildTime),
"About TigerVNC Viewer for Java",
JOptionPane.INFORMATION_MESSAGE,
logo);
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(fullScreenWindow);
}
void showInfo() {
+ Window fullScreenWindow = Viewport.getFullScreenWindow();
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(null);
JOptionPane.showMessageDialog(viewport,
"Desktop name: "+cp.name()+"\n"
+"Host: "+sock.getPeerName()+":"+sock.getPeerPort()+"\n"
+" ["+csecurity.description()+"]",
"VNC connection info",
JOptionPane.PLAIN_MESSAGE);
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(fullScreenWindow);
}
public void refresh() {
current = "";
textArea.setText(current);
} else if (s instanceof JButton && (JButton)s == sendButton) {
- ok = true;
current = textArea.getText();
cc.writeClientCutText(current, current.length());
endDialog();
} else if (s instanceof JButton && (JButton)s == cancelButton) {
- ok = false;
endDialog();
}
}
package com.tigervnc.vncviewer;
import java.awt.*;
+import java.awt.Dialog.*;
import javax.swing.*;
-//class Dialog extends JFrame implements WindowListener {
-class Dialog extends JFrame {
+class Dialog extends JDialog {
- protected boolean ok, done;
- boolean modal;
-
- public Dialog(boolean modal_) {
- modal = modal_;
- //addWindowListener(this);
+ public Dialog(boolean modal) {
+ if (modal) {
+ setModalityType(ModalityType.APPLICATION_MODAL);
+ } else {
+ setModalityType(ModalityType.MODELESS);
+ }
}
public boolean showDialog(Component c) {
- ok = false;
- done = false;
initDialog();
if (c != null) {
setLocationRelativeTo(c);
ClassLoader cl = this.getClass().getClassLoader();
ImageIcon icon = new ImageIcon(cl.getResource("com/tigervnc/vncviewer/tigervnc.ico"));
setIconImage(icon.getImage());
- //setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- //setFont(new Font("SansSerif", Font.PLAIN, 11));
+ fullScreenWindow = Viewport.getFullScreenWindow();
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(null);
setVisible(true);
setFocusable(true);
- if (!modal) return true;
- synchronized(this) {
- try {
- while (!done)
- wait();
- } catch (InterruptedException e) {
- }
- }
- return ok;
+ setAlwaysOnTop(true);
+ return ret;
}
public boolean showDialog() {
}
public void endDialog() {
- done = true;
setVisible(false);
setFocusable(false);
- if (modal) {
- synchronized (this) {
- notify();
- }
- }
+ setAlwaysOnTop(false);
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(fullScreenWindow);
}
// initDialog() can be overridden in a derived class. Typically it is used
public void initDialog() {
}
- //------------------------------------------------------------------
- // implemented blank methods
- //public void windowClosed(WindowEvent event){}
- //public void windowDeiconified(WindowEvent event){}
- //public void windowIconified(WindowEvent event){}
- //public void windowActivated(WindowEvent event){}
- //public void windowDeactivated(WindowEvent event){}
- //public void windowOpened(WindowEvent event){}
-
- //------------------------------------------------------------------
-
- // method to check which window was closing
- //public void windowClosing(WindowEvent event) {
- // ok = false;
- // endDialog();
- //}
-
public void addGBComponent(JComponent c, JComponent cp,
int gx, int gy,
int gw, int gh,
cp.add(c, gbc);
}
- final public String getFileSeperator() {
- String seperator = System.getProperties().get("file.separator").toString();
- return seperator;
- }
-
- final public String getUserName() {
- String userName = (String)System.getProperties().get("user.name");
- return userName;
- }
+ private Window fullScreenWindow;
+ protected boolean ret = true;
}
package com.tigervnc.vncviewer;
+import java.awt.*;
import java.awt.Cursor;
import java.awt.event.*;
import javax.swing.JFrame;
fc.setDialogTitle("Save current configuration as:");
fc.setApproveButtonText("OK");
fc.setFileHidingEnabled(false);
+ Window fullScreenWindow = Viewport.getFullScreenWindow();
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(null);
int ret = fc.showOpenDialog(this);
+ if (fullScreenWindow != null)
+ Viewport.setFullScreenWindow(fullScreenWindow);
if (ret == JFileChooser.APPROVE_OPTION) {
String filename = fc.getSelectedFile().toString();
if (filename != null)
JButton cfLoadButton, cfSaveAsButton, defSaveButton, defReloadButton, defClearButton;
public OptionsDialog(OptionsDialogCallback cb_) {
- super(false);
+ super(true);
cb = cb_;
setResizable(false);
setTitle("VNC Viewer Options");
}
private void updatePreferences() {
- //UserPreferences.clear("global");
if (autoSelect.isSelected()) {
UserPreferences.set("global", "AutoSelect", true);
} else {
public void actionPerformed(ActionEvent e) {
Object s = e.getSource();
if (s instanceof JButton && (JButton)s == okButton) {
- ok = true;
if (cb != null) cb.getOptions();
endDialog();
} else if (s instanceof JButton && (JButton)s == cancelButton) {
- ok = false;
endDialog();
} else if (s instanceof JButton && (JButton)s == cfLoadButton) {
JFileChooser fc = new JFileChooser();
super(true);
setResizable(false);
setTitle(title);
- setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
+ addWindowListener(new WindowAdapter() {
+ public void windowClosing(WindowEvent e) {
+ endDialog();
+ }
+ });
JPanel p1 = new JPanel();
userLabel = new JLabel("Username:");
Object s = event.getSource();
if (s instanceof JTextField && (JTextField)s == userEntry) {
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
- ok = true;
endDialog();
}
} else if (s instanceof JPasswordField && (JPasswordField)s == passwdEntry) {
if (event.getKeyCode() == KeyEvent.VK_ENTER) {
- ok = true;
endDialog();
}
}
}
- public String getPassword(){
+ public String getPassword() {
return new String(passwdEntry.getPassword());
}
public String getPassphrase(){ return null; }
if (cc.viewer.nViewers == 1) {
cc.viewer.exit(1);
} else {
- ok = false;
+ ret = false;
endDialog();
}
}
}
public void itemStateChanged(ItemEvent e) {
- //Object s = e.getSource();
+ return;
}
public void actionPerformed(ActionEvent e) {
Object s = e.getSource();
if (s instanceof JButton && (JButton)s == okButton) {
- ok = true;
- String serverName = (String)server.getSelectedItem();
- if (serverName != null) {
- Configuration.setParam("Server", Hostname.getHost(serverName));
- Configuration.setParam("Port", Integer.toString(Hostname.getPort(serverName)));
- }
+ commit();
endDialog();
} else if (s instanceof JButton && (JButton)s == cancelButton) {
- ok = false;
+ if (cc.viewer.nViewers == 1)
+ cc.viewer.exit(1);
+ ret = false;
endDialog();
} else if (s instanceof JButton && (JButton)s == optionsButton) {
options.showDialog(this);
if (e.getActionCommand().equals("comboBoxEdited")) {
server.insertItemAt(editor.getItem(), 0);
server.setSelectedIndex(0);
- ok = true;
+ commit();
endDialog();
}
}
}
-
- public void endDialog() {
- if (ok) {
- if (!server.getSelectedItem().toString().equals("")) {
- String valueStr = UserPreferences.get("ServerDialog", "history");
- String t = (valueStr == null) ? "" : valueStr;
- StringTokenizer st = new StringTokenizer(t, ",");
- StringBuffer sb = new StringBuffer().append((String)server.getSelectedItem());
- while (st.hasMoreTokens()) {
- String s = st.nextToken();
- if (!s.equals((String)server.getSelectedItem()) && !s.equals("")) {
- sb.append(',');
- sb.append(s);
- }
- }
- UserPreferences.set("ServerDialog", "history", sb.toString());
- UserPreferences.save("ServerDialog");
- }
- }
- done = true;
- if (modal) {
- synchronized (this) {
- notify();
+ private void commit() {
+ String serverName = (String)server.getSelectedItem();
+ if (serverName == null || serverName.equals("")) {
+ vlog.error("Invalid servername specified");
+ if (cc.viewer.nViewers == 1)
+ cc.viewer.exit(1);
+ ret = false;
+ endDialog();
+ }
+ // set params
+ Configuration.setParam("Server", Hostname.getHost(serverName));
+ Configuration.setParam("Port", Integer.toString(Hostname.getPort(serverName)));
+ // Update the history list
+ String valueStr = UserPreferences.get("ServerDialog", "history");
+ String t = (valueStr == null) ? "" : valueStr;
+ StringTokenizer st = new StringTokenizer(t, ",");
+ StringBuffer sb = new StringBuffer().append((String)server.getSelectedItem());
+ while (st.hasMoreTokens()) {
+ String str = st.nextToken();
+ if (!str.equals((String)server.getSelectedItem()) && !str.equals("")) {
+ sb.append(',');
+ sb.append(str);
}
}
- this.dispose();
+ UserPreferences.set("ServerDialog", "history", sb.toString());
+ UserPreferences.save("ServerDialog");
+ }
+
+ public void endDialog() {
+ super.endDialog();
}
CConn cc;
import java.awt.event.*;
import java.awt.Dimension;
import java.awt.Event;
+import java.awt.GraphicsConfiguration;
+import java.awt.GraphicsDevice;
+import java.awt.GraphicsEnvironment;
+import java.awt.Window;
import javax.swing.*;
import com.tigervnc.rdr.*;
});
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
- cc.close();
+ if (cc.viewer.nViewers == 1) {
+ cc.viewer.exit(1);
+ } else {
+ cc.close();
+ }
}
});
addComponentListener(new ComponentAdapter() {
setBackground(Color.BLACK);
}
+ public static Window getFullScreenWindow() {
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice gd = ge.getDefaultScreenDevice();
+ Window fullScreenWindow = gd.getFullScreenWindow();
+ return fullScreenWindow;
+ }
+
+ public static void setFullScreenWindow(Window fullScreenWindow) {
+ GraphicsEnvironment ge =
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
+ GraphicsDevice gd = ge.getDefaultScreenDevice();
+ gd.setFullScreenWindow(fullScreenWindow);
+ }
CConn cc;
JScrollPane sp;