-/* Copyright (C) 2016 Brian P. Hinz
+/* Copyright (C) 2016-2019 Brian P. Hinz
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
"Lion or later.",
false);
- public static BoolParameter embed
- = new BoolParameter("Embed",
- "If the viewer is being run as an applet, display its output to " +
- "an embedded frame in the browser window rather than to a dedicated " +
- "window. Embed=1 implies FullScreen=0 and Scale=100.",
- false);
-
public static BoolParameter dotWhenNoCursor
= new BoolParameter("DotWhenNoCursor",
"Show the dot cursor when the server sends an invisible cursor",
return servername;
}
- public static String loadAppletParameters(VncViewer applet) {
- String servername = applet.getParameter("Server");
- String serverport = applet.getParameter("Port");
- String embedParam = applet.getParameter("Embed");
-
- if (servername == null)
- servername = applet.getCodeBase().getHost();
-
- if (serverport != null)
- servername = servername.concat("::"+serverport);
- else
- servername = servername.concat("::5900");
-
- if (embedParam != null)
- embed.setParam(embedParam);
-
- for (int i = 0; i < parameterArray.length; i++) {
- String value = applet.getParameter(parameterArray[i].getName());
- if (value == null)
- continue;
- if (parameterArray[i] instanceof StringParameter) {
- if (value.length() > 256) {
- vlog.error(String.format("Failed to read applet parameter %s: %s",
- parameterArray[i].getName(),
- "Invalid format or too large value"));
- continue;
- }
- ((StringParameter)parameterArray[i]).setParam(value);
- } else if (parameterArray[i] instanceof IntParameter) {
- ((IntParameter)parameterArray[i]).setParam(value);
- } else if (parameterArray[i] instanceof BoolParameter) {
- ((BoolParameter)parameterArray[i]).setParam(value);
- } else {
- vlog.error(String.format("Unknown parameter type for parameter %s",
- parameterArray[i].getName()));
-
- }
- }
-
- return servername;
- }
-
private static void updateConnHistory(String serverName) {
String hKey = "ServerDialog";
if (serverName != null && !serverName.isEmpty()) {
/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
* Copyright (C) 2011-2013 D. R. Commander. All Rights Reserved.
- * Copyright (C) 2011-2016 Brian P. Hinz
+ * Copyright (C) 2011-2019 Brian P. Hinz
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
*/
//
-// VncViewer - the VNC viewer applet. It can also be run from the
-// command-line, when it behaves as much as possibly like the windows and unix
+// VncViewer - the VNC viewer. It behaves as much as possible like the native
// viewers.
//
// Unfortunately, because of the way Java classes are loaded on demand, only
// configuration parameters defined in this file can be set from the command
-// line or in applet parameters.
+// line.
package com.tigervnc.vncviewer;
import static com.tigervnc.vncviewer.Parameters.*;
-public class VncViewer extends javax.swing.JApplet
- implements Runnable, ActionListener {
+public class VncViewer implements Runnable {
public static final String aboutText =
new String("TigerVNC Java Viewer v%s (%s)%n"+
VncViewer.class.getResourceAsStream("timestamp");
public static final String os =
System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
- private static VncViewer applet;
private String defaultServerName;
int VNCSERVERNAMELEN = 256;
viewer.start();
}
- public VncViewer() {
- // Only called in applet mode
- this(new String[0]);
- }
-
public VncViewer(String[] argv) {
SecurityClient.setDefaults();
}
}
- public boolean isAppletDragStart(MouseEvent e) {
- if(e.getID() == MouseEvent.MOUSE_DRAGGED) {
- // Drag undocking on Mac works, but introduces a host of
- // problems so disable it for now.
- if (os.startsWith("mac os x"))
- return false;
- else if (os.startsWith("windows"))
- return (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0;
- else
- return (e.getModifiersEx() & MouseEvent.SHIFT_DOWN_MASK) != 0;
- } else {
- return false;
- }
- }
-
- public void appletDragStarted() {
- embed.setParam(false);
- //cc.recreateViewport();
- JFrame f = (JFrame)JOptionPane.getFrameForComponent(this);
- // The default JFrame created by the drag event will be
- // visible briefly between appletDragStarted and Finished.
- if (f != null)
- f.setSize(0, 0);
- }
-
- public void appletDragFinished() {
- JFrame f = (JFrame)JOptionPane.getFrameForComponent(this);
- if (f != null)
- f.dispose();
- }
-
- public void setAppletCloseListener(ActionListener cl) {
- cc.setCloseListener(cl);
- }
-
- public void appletRestored() {
- cc.setCloseListener(null);
- }
-
- public static void setupEmbeddedFrame(JScrollPane sp) {
- InputMap im = sp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
- int ctrlAltShiftMask = Event.SHIFT_MASK | Event.CTRL_MASK | Event.ALT_MASK;
- if (im != null) {
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, ctrlAltShiftMask),
- "unitScrollUp");
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, ctrlAltShiftMask),
- "unitScrollDown");
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, ctrlAltShiftMask),
- "unitScrollLeft");
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, ctrlAltShiftMask),
- "unitScrollRight");
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, ctrlAltShiftMask),
- "scrollUp");
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, ctrlAltShiftMask),
- "scrollDown");
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_HOME, ctrlAltShiftMask),
- "scrollLeft");
- im.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, ctrlAltShiftMask),
- "scrollRight");
- }
- applet.getContentPane().removeAll();
- applet.getContentPane().add(sp);
- applet.validate();
- }
-
- public void init() {
- // Called right after zero-arg constructor in applet mode
- setLookAndFeel();
- setBackground(Color.white);
- applet = this;
- vncServerName.put(loadAppletParameters(applet).toCharArray()).flip();
- if (embed.getValue()) {
- fullScreen.setParam(false);
- remoteResize.setParam(false);
- maximize.setParam(false);
- scalingFactor.setParam("100");
- }
- setFocusTraversalKeysEnabled(false);
- addFocusListener(new FocusAdapter() {
- public void focusGained(FocusEvent e) {
- if (cc != null && cc.desktop != null)
- cc.desktop.viewport.requestFocusInWindow();
- }
- });
- Frame frame = (Frame)getFocusCycleRootAncestor();
- frame.setFocusTraversalKeysEnabled(false);
- frame.addWindowListener(new WindowAdapter() {
- // Transfer focus to scrollpane when browser receives it
- public void windowActivated(WindowEvent e) {
- if (cc != null && cc.desktop != null)
- cc.desktop.viewport.requestFocusInWindow();
- }
- public void windowDeactivated(WindowEvent e) {
- if (cc != null)
- cc.desktop.viewport.releaseDownKeys();
- }
- });
- }
-
private static void getTimestamp() {
if (version == null || build == null) {
try {
}
public void exit(int n) {
- if (embed.getValue())
- destroy();
- else
- System.exit(n);
- }
-
- // If "Reconnect" button is pressed
- public void actionPerformed(ActionEvent e) {
- getContentPane().removeAll();
- start();
+ System.exit(n);
}
void reportException(java.lang.Exception e) {
int msgType = JOptionPane.ERROR_MESSAGE;
title = "TigerVNC Viewer : Error";
e.printStackTrace();
- if (embed.getValue()) {
- getContentPane().removeAll();
- JLabel label = new JLabel("<html><center><b>" + title + "</b><p><i>" +
- msg + "</i></center></html>", JLabel.CENTER);
- label.setFont(new Font("Helvetica", Font.PLAIN, 24));
- label.setMaximumSize(new Dimension(getSize().width, 100));
- label.setVerticalAlignment(JLabel.CENTER);
- label.setAlignmentX(Component.CENTER_ALIGNMENT);
- JButton button = new JButton("Reconnect");
- button.addActionListener(this);
- button.setMaximumSize(new Dimension(200, 30));
- button.setAlignmentX(Component.CENTER_ALIGNMENT);
- setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
- add(label);
- add(button);
- validate();
- repaint();
- } else {
- JOptionPane.showMessageDialog(null, msg, title, msgType);
- }
+ JOptionPane.showMessageDialog(null, msg, title, msgType);
}
public void run() {
reportException(e);
if (cc != null)
cc.close();
- } else if (embed.getValue()) {
- reportException(new java.lang.Exception("Connection closed"));
- exit(0);
}
exit(1);
}