Mercurial > hg > Applications > TreeVNC
view src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java @ 188:f176bffcdc4a
add showTreeNode option.
author | oc |
---|---|
date | Tue, 24 Jun 2014 16:49:29 +0900 |
parents | c1b91dd27a13 |
children | aa00e4b2fc27 |
line wrap: on
line source
package com.glavsoft.viewer; import com.glavsoft.rfb.protocol.ProtocolSettings; 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 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.jar.Attributes; import java.util.jar.Manifest; import java.util.logging.*; import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; 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 MyRfbProto myRfb; private boolean cuiVersion; 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 = new ConnectionPresenter(hasJsch, allowInteractive); connectionPresenter.addModel("ConnectionParamsModel", connectionParams); /* * SwingViewerWindowFactory viewerWindowFactory = new * SwingViewerWindowFactory( isSeparateFrame, isApplet, this); * * connectionPresenter.setConnectionWorkerFactory(new * SwingConnectionWorkerFactory( connectionView.getFrame(), * passwordFromParams, connectionPresenter, viewerWindowFactory, * myRfb)); */ connectionPresenter.setConnectionWorkerFactory( new SwingConnectionWorkerFactory(null, passwordFromParams, connectionPresenter, null, myRfb)); connectionPresenter.setCuiVersion(true); connectionPresenter.startConnection(settings, uiSettings, paramsMask); } @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 setTeminationType(boolean b) { myRfb.setTerminationType(b); } public void startTreeViewer(String hostName, boolean cui) { CuiViewer viewer = new CuiViewer(); viewer.cuiVersion = cui; MyRfbProtoClient rfb = new MyRfbProtoClient(); CreateConnectionParam cp = new CreateConnectionParam(rfb); if (hostName==null) { try { cp.findTreeVncRoot(); } catch (InterruptedException e) { } } else { cp.setHostName(hostName); } rfb.createConnectionAndStart(this); cp.sendWhereToConnect(viewer); rfb.setViewer(viewer); rfb.setCuiVersion(cui); viewer.myRfb = rfb; SwingUtilities.invokeLater(viewer); } public void setIsTreeVNC(boolean flag) { } public MyRfbProto getRfb() { return myRfb; } public boolean getCuiVersion() { return cuiVersion; } public void setCuiVersion(boolean flag) { // nop } @Override public void connectToParenet(int port, String hostname) throws IOException { setTeminationType(false); closeApp(); connectionParams.setConnectionParam(hostname, port); run(); } @Override public void inhelitClients(ViewerInterface vncProxyService, String hostName) { } @Override public void proxyStart(String[] args, int width, int height, boolean showTree) { } @Override public void setNoConnection(boolean noConnection) { } }