Mercurial > hg > Applications > TreeVNC
view src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java @ 458:4ea47640942a
intoroduce retina scaled frame buffer postion
author | innparusu |
---|---|
date | Thu, 23 Jun 2016 18:57:12 +0900 |
parents | 34277b436cac |
children | 16f9b37ef43b |
line wrap: on
line source
package com.glavsoft.viewer; import com.glavsoft.rfb.protocol.ProtocolSettings; import com.glavsoft.transport.Reader; import com.glavsoft.transport.Writer; import com.glavsoft.viewer.cli.Parser; import com.glavsoft.viewer.swing.ConnectionParams; import com.glavsoft.viewer.swing.ParametersHandler; import com.glavsoft.viewer.swing.SwingConnectionWorkerFactory; import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; import javax.swing.*; import java.awt.*; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; import java.io.IOException; import java.io.InputStream; import java.net.Socket; import java.util.ArrayList; import java.util.jar.Attributes; import java.util.jar.Manifest; import java.util.logging.ConsoleHandler; import java.util.logging.Handler; import java.util.logging.Level; import java.util.logging.Logger; public class CuiViewer implements Runnable, WindowListener, ViewerInterface { private Logger logger; private int paramsMask; private boolean allowAppletInteractiveConnections; public final ConnectionParams connectionParams; protected String passwordFromParams; boolean isSeparateFrame = true; protected boolean isApplet = true; private final ProtocolSettings settings; protected UiSettings uiSettings; private ConnectionPresenter connectionPresenter; protected TreeRFBProto myRfb; private boolean cuiVersion; private boolean showTree = false; public int width; public int height; public static void main(String[] args) { Parser parser = new Parser(); ParametersHandler.completeParserOptions(parser); parser.parse(args); if (parser.isSet(ParametersHandler.ARG_HELP)) { printUsage(parser.optionsUsage()); System.exit(0); } CuiViewer viewer = new CuiViewer(parser); SwingUtilities.invokeLater(viewer); } public static void printUsage(String additional) { System.out .println("Usage: java -jar (progfilename) [hostname [port_number]] [Options]?n" + " or?n" + " java -jar (progfilename) [Options]?n" + " or?n java -jar (progfilename) -help?n to view this help?n?n" + "Where Options are:?n" + additional + "?nOptions format: -optionName=optionValue. Ex. -host=localhost -port=5900 -viewonly=yes?n" + "Both option name and option value are case insensitive."); } public CuiViewer() { logger = Logger.getLogger(getClass().getName()); connectionParams = new ConnectionParams(); settings = ProtocolSettings.getDefaultSettings(); uiSettings = new UiSettings(); } private CuiViewer(Parser parser) { this(); setLoggingLevel(parser.isSet(ParametersHandler.ARG_VERBOSE) ? Level.FINE : parser.isSet(ParametersHandler.ARG_VERBOSE_MORE) ? Level.FINER : Level.INFO); paramsMask = ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); logger.info("TightVNC Viewer version " + ver()); isApplet = false; } private void setLoggingLevel(Level levelToSet) { final Logger appLogger = Logger.getLogger("com.glavsoft"); appLogger.setLevel(levelToSet); ConsoleHandler ch = null; for (Handler h : appLogger.getHandlers()) { if (h instanceof ConsoleHandler) { ch = (ConsoleHandler) h; break; } } if (null == ch) { ch = new ConsoleHandler(); appLogger.addHandler(ch); } // ch.setFormatter(new SimpleFormatter()); ch.setLevel(levelToSet); } @Override public void windowClosing(WindowEvent e) { if (e != null && e.getComponent() != null) { final Window w = e.getWindow(); if (w != null) { w.setVisible(false); w.dispose(); } } closeApp(); } /** * Closes App(lication) or stops App(let). */ public void closeApp() { /* nop */ } private boolean checkJsch() { try { Class.forName("com.jcraft.jsch.JSch"); return true; } catch (ClassNotFoundException e) { return false; } } @Override public void run() { final boolean hasJsch = checkJsch(); final boolean allowInteractive = allowAppletInteractiveConnections || !isApplet; ConnectionPresenter connectionPresenter = new ConnectionPresenter(hasJsch, allowInteractive); connectionPresenter.addModel("ConnectionParamsModel", connectionParams); connectionPresenter.setConnectionWorkerFactory( new SwingConnectionWorkerFactory(null, passwordFromParams, connectionPresenter, null, myRfb)); connectionPresenter.setCuiVersion(true); connectionPresenter.startConnection(settings, uiSettings, paramsMask, false, null, null); } @Override public ConnectionPresenter getConnectionPresenter() { return connectionPresenter; } @Override public void setConnectionPresenter(ConnectionPresenter connectionPresenter) { this.connectionPresenter = connectionPresenter; } @Override public void changeToDirectConnectedServer(String hostName, Reader is, Writer os, int x, int y, int width, int height, int scale) { } @Override public void windowOpened(WindowEvent e) { /* nop */ } @Override public void windowClosed(WindowEvent e) { /* nop */ } @Override public void windowIconified(WindowEvent e) { /* nop */ } @Override public void windowDeiconified(WindowEvent e) { /* nop */ } @Override public void windowActivated(WindowEvent e) { /* nop */ } @Override public void windowDeactivated(WindowEvent e) { /* nop */ } public static String ver() { final InputStream mfStream = Viewer.class.getClassLoader() .getResourceAsStream("META-INF/MANIFEST.MF"); if (null == mfStream) { System.out.println("No Manifest file found."); return "-1"; } try { Manifest mf = new Manifest(); mf.read(mfStream); Attributes atts = mf.getMainAttributes(); return atts.getValue(Attributes.Name.IMPLEMENTATION_VERSION); } catch (IOException e) { return "-2"; } } public void setSocket(Socket soc) { connectionParams.setConnectionParam(soc.getInetAddress().getHostAddress(), soc.getPort()); } public void setOpenPort(int parseInt) { } public void setTerminationType(boolean b) { myRfb.setTerminationType(b); } public void startTreeViewer(String hostName, boolean cui, boolean addSerialNum) { CuiViewer viewer = new CuiViewer(); viewer.cuiVersion = cui; TreeRFBProto rfb = new TreeRFBProto(false, this); CreateConnectionParam cp = new CreateConnectionParam(rfb); if (hostName==null) { cp.findTreeVncRoot(); } else { cp.setHostName(hostName); } rfb.createConnectionAndStart(this); cp.sendWhereToConnect(viewer); rfb.setCuiVersion(cui); viewer.myRfb = rfb; SwingUtilities.invokeLater(viewer); } public void setIsTreeVNC(boolean flag) { } public TreeRFBProto getRfb() { return myRfb; } public boolean getCuiVersion() { return cuiVersion; } public void setCuiVersion(boolean flag) { // nop } @Override public void connectToParenet(int port, String hostname) throws IOException { setTerminationType(false); closeApp(); connectionParams.setConnectionParam(hostname, port); run(); } @Override public void inhelitClients(String hostName, short newVNCServerId, int x, int y, int width, int height, int scale) { } @Override public void proxyStart(String[] args, String hostName, int width, int height, boolean showTree, boolean checkDelay, boolean addSerialNum, boolean fixingSize, boolean filterSingleDisplay, boolean hasViewer) { } @Override public void setNoConnection(boolean noConnection) { } @Override public void setVisible(boolean b) { } @Override public Socket getVNCSocket() { return connectionPresenter.getSocket(); } @Override public boolean getShowTree() { return showTree; } @Override public void setWidth(int w) { width = w; } @Override public void setHeight(int h) { height = h; } @Override public void setFixingSize(int width, int height) { } @Override public java.util.ArrayList<FbRectangle> getScreenRectangles() { return null; } @Override public Point getScreenOffset(ArrayList<Rectangle> rectangles) { return null; } @Override public int retinaScale(int shareScreenNumber) { return 1; } @Override public void setFitScreen() { } }