Mercurial > hg > Applications > TightVNC_orginal
changeset 40:3c072f2f39bb
add Screen change function.
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/drawing/AbstructRenderer.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/main/java/com/glavsoft/drawing/AbstructRenderer.java Mon Oct 22 17:40:32 2012 +0900 @@ -104,7 +104,7 @@ } /** - * Draw byte array bitmap data (from array with plain RGB color components. Assumed: rrrrrrrr gggggggg bbbbbbbb) + * Draw byte array bitmap data (from array with plain RGB color components. Assumed) */ public synchronized void drawUncaliberedRGBLine(byte[] bytes, int x, int y, int width) { int end = y * this.width + x + width;
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Mon Oct 22 17:40:32 2012 +0900 @@ -133,6 +133,7 @@ counter++; } } else if (isRunning) { + logger.severe("Close proxy: "); context.cleanUpSession("Connection closed."); } stopTask();
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/AcceptThread.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/AcceptThread.java Mon Oct 22 17:40:32 2012 +0900 @@ -44,6 +44,8 @@ } } + + /** * Instruction stop if you come from if WaitReply.
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Mon Oct 22 17:40:32 2012 +0900 @@ -108,6 +108,10 @@ public Socket accept() throws IOException { return servSock.accept(); } + + public void socketClose() throws IOException { + servSock.close(); + } void addSock(Socket sock) { cliList.add(sock);
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Mon Oct 22 17:40:32 2012 +0900 @@ -8,6 +8,7 @@ import java.util.logging.Logger; import jp.ac.u_ryukyu.treevnc.AcceptThread; +import jp.ac.u_ryukyu.treevnc.server.state.ChangeHost; @@ -43,11 +44,12 @@ private ConnectionManager connectionManager; private VncProxyService vps; private CreateThread createThread; - AcceptClient aClient; - private int port; + public AcceptClient aClient; + public int opendPort; // public AcceptClient acc; public VncProxyService(Parser parser) { this(); + aClient = new AcceptClient(); ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings); showControls = ParametersHandler.showControls; passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD); @@ -56,12 +58,11 @@ } public VncProxyService() { - rfb = new MyRfbProtoProxy(); - aClient = new AcceptClient(); connectionManager = new ConnectionManager(this, isApplet); connectionParams = new ParametersHandler.ConnectionParams(); settings = ProtocolSettings.getDefaultSettings(); uiSettings = super.uiSettings; + connectionParams.hostName="localhost"; } boolean isClient = false; @@ -99,6 +100,7 @@ //getHostData(); } //SwingUtilities.invokeLater(myClient); + /* Thread th = new Thread(vps); th.start(); try { @@ -106,6 +108,8 @@ } catch (InterruptedException e) { e.printStackTrace(); } + */ + vps.run(); vps.createConnectionAndStart(); } @@ -114,6 +118,7 @@ @Override public void run() { + rfb = new MyRfbProtoProxy(); // getHostData(); if (forceReconnection) { connectionManager.showReconnectDialog("Connection lost", reconnectionReason); @@ -129,7 +134,6 @@ break; } logger.info("Connected"); - try { workingSocket.setTcpNoDelay(true); // disable Nagle algorithm Reader reader = new Reader(workingSocket.getInputStream()); @@ -182,9 +186,10 @@ } public void createConnectionAndStart() { - port = rfb.selectPort(5999); - acceptThread = new AcceptThread(rfb, port); - Thread thread = new Thread(acceptThread); + Thread thread; + opendPort = rfb.selectPort(5999); + acceptThread = new AcceptThread(rfb, opendPort); + thread = new Thread(acceptThread); thread.start(); getCast = new GetBroadCastProxy(this, workingProtocol.getRemoteDesktopName(), @@ -250,7 +255,7 @@ createThread = new CreateThread(aClient); Thread thread = new Thread(createThread); thread.start(); - thread = new Thread(new ChangeHost(new VncProxyService(), forceReconnection,this)); + thread = new Thread(new ChangeHost(this, forceReconnection)); thread.start(); // createSocketAndSend(aClient.getList(),String.valueOf(port)); } @@ -292,8 +297,15 @@ } } - public void changeVNCServer() { - // sender and re + public void changeVNCServer(String hostName) throws UnknownHostException, IOException { + // sender and reader workingProtocol.cleanUpSession(); + // run call and change workingProtocol + this.connectionParams.hostName = hostName; + this.run(); + this.createConnectionAndStart(); + createSocketAndSend(aClient.getList(),String.valueOf(opendPort)); } + + }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/state/ChangeHost.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/state/ChangeHost.java Mon Oct 22 17:40:32 2012 +0900 @@ -3,19 +3,12 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.Socket; import java.net.UnknownHostException; import java.util.LinkedList; -import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.server.VncProxyService; -import com.glavsoft.rfb.protocol.ProtocolSettings; -import com.glavsoft.viewer.ConnectionManager; -import com.glavsoft.viewer.Viewer; -import com.glavsoft.viewer.swing.ParametersHandler; - -public class ChangeHost extends ConnectionManager implements Runnable,ScreenChanges { +public class ChangeHost implements Runnable,ScreenChanges { private VncProxyService vps; private ScreenChanges screenChange; @@ -24,16 +17,11 @@ public ChangeHost(VncProxyService _vps, boolean isApplet) { - super(_vps, isApplet); vps = _vps; screenChange = this; } - /** - * - */ - private static final long serialVersionUID = 1L; String str; @Override @@ -56,7 +44,7 @@ BufferedReader br = new BufferedReader(new InputStreamReader( System.in)); str = br.readLine(); - vps.changeVNCServer(); + vps.changeVNCServer(str); // vps.createConnectionAndStart(); // vps.aClient.setList(prevVps.aClient.getList()); // clientList = prevVps.aClient.getList(); @@ -66,32 +54,6 @@ } } - @Override - public Socket connectToHost( - final ParametersHandler.ConnectionParams connectionParams, - ProtocolSettings settings, MyRfbProto rfb) { - Socket socket = null; - connectionParams.hostName = str; - connectionParams.portNumber = 5900; - Viewer.logger.info("Connecting to host " + connectionParams.hostName - + ":" + connectionParams.portNumber); - try { - socket = new Socket(connectionParams.hostName, - connectionParams.portNumber); - } catch (UnknownHostException e) { - Viewer.logger.severe("Unknown host: " + connectionParams.hostName); - showConnectionErrorDialog("Unknown host: '" - + connectionParams.hostName + "'"); - } catch (IOException e) { - Viewer.logger.severe("Couldn't connect to: " - + connectionParams.hostName + ":" - + connectionParams.portNumber + ": " + e.getMessage()); - showConnectionErrorDialog("Couldn't connect to: '" - + connectionParams.hostName + "'\n" + e.getMessage()); - } - return socket; - } - @Override public boolean next() {
--- a/src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java Mon Oct 22 17:40:32 2012 +0900 @@ -24,7 +24,6 @@ package com.glavsoft.viewer; - import com.glavsoft.rfb.protocol.ProtocolSettings; import com.glavsoft.viewer.swing.ParametersHandler; import com.glavsoft.viewer.swing.Utils; @@ -40,7 +39,6 @@ import jp.ac.u_ryukyu.treevnc.MyRfbProto; - public class ConnectionManager implements Serializable { /** * @@ -57,120 +55,124 @@ } public void showReconnectDialog(String title, String message) { - JOptionPane reconnectPane = new JOptionPane(message + "\nTry another connection?", - JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION); - final JDialog reconnectDialog = reconnectPane.createDialog(containerFrame, title); - reconnectDialog.setModalityType(isApplet ? - Dialog.ModalityType.APPLICATION_MODAL : Dialog.ModalityType.TOOLKIT_MODAL); + JOptionPane reconnectPane = new JOptionPane(message + + "\nTry another connection?", JOptionPane.QUESTION_MESSAGE, + JOptionPane.YES_NO_OPTION); + final JDialog reconnectDialog = reconnectPane.createDialog( + containerFrame, title); + reconnectDialog + .setModalityType(isApplet ? Dialog.ModalityType.APPLICATION_MODAL + : Dialog.ModalityType.TOOLKIT_MODAL); try { reconnectDialog.setAlwaysOnTop(true); - } catch (SecurityException e) { /*nop*/ } + } catch (SecurityException e) { /* nop */ + } java.util.List<Image> icons = Utils.getIcons(); if (icons.size() != 0) { reconnectDialog.setIconImages(icons); } reconnectDialog.setVisible(true); - if (reconnectPane.getValue() == null || - (Integer)reconnectPane.getValue() == JOptionPane.NO_OPTION) { + if (reconnectPane.getValue() == null + || (Integer) reconnectPane.getValue() == JOptionPane.NO_OPTION) { appWindowListener.windowClosing(null); } else { forceConnectionDialog = !isApplet; } } - -/* - public Socket connectToTreeHost(final ParametersHandler.ConnectionParams connectionParams, ProtocolSettings settings) { - Socket socket = null; - boolean wasError = false; - GetHostClient bCast = new GetHostClient("who"); - bCast.createSocket(); - bCast.sendData(); - GetDataClient getBcast = new GetDataClient(); - Thread runBcast = new Thread(getBcast); - runBcast.start(); - getBcast.setStopFlag(true); - //connectionParams.hostName = getBcast.textAddress(); - if("notFound".equals(connectionParams.hostName)) { - getBcast.text.ipRegister(); - connectionParams.hostName = getBcast.textAddress(); - connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); - //connectionParams.portNumber = 5900; - } else { - // connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); - connectionParams.portNumber = 5900; - } - Viewer.logger.info("Connecting to host " + connectionParams.hostName + ":" + connectionParams.portNumber); - try { - socket = new Socket(connectionParams.hostName, connectionParams.portNumber); - wasError = false; - } catch (UnknownHostException e) { - Viewer.logger.severe("Unknown host: " + connectionParams.hostName); - showConnectionErrorDialog("Unknown host: '" + connectionParams.hostName + "'"); - wasError = true; - } catch (IOException e) { - Viewer.logger.severe("Couldn't connect to: " + - connectionParams.hostName + ":" + connectionParams.portNumber + - ": " + e.getMessage()); - showConnectionErrorDialog("Couldn't connect to: '" + connectionParams.hostName + - "'\n" + e.getMessage()); - wasError = true; - } - return socket; - } -*/ - public Socket connectToHost(final ParametersHandler.ConnectionParams connectionParams, ProtocolSettings settings, MyRfbProto rfb) { + /* + * public Socket connectToTreeHost(final ParametersHandler.ConnectionParams + * connectionParams, ProtocolSettings settings) { Socket socket = null; + * boolean wasError = false; GetHostClient bCast = new GetHostClient("who"); + * bCast.createSocket(); bCast.sendData(); GetDataClient getBcast = new + * GetDataClient(); Thread runBcast = new Thread(getBcast); + * runBcast.start(); getBcast.setStopFlag(true); //connectionParams.hostName + * = getBcast.textAddress(); + * if("notFound".equals(connectionParams.hostName)) { + * getBcast.text.ipRegister(); connectionParams.hostName = + * getBcast.textAddress(); connectionParams.portNumber = + * Integer.parseInt(getBcast.textPort()); //connectionParams.portNumber = + * 5900; } else { // connectionParams.portNumber = + * Integer.parseInt(getBcast.textPort()); connectionParams.portNumber = + * 5900; } Viewer.logger.info("Connecting to host " + + * connectionParams.hostName + ":" + connectionParams.portNumber); try { + * socket = new Socket(connectionParams.hostName, + * connectionParams.portNumber); wasError = false; } catch + * (UnknownHostException e) { Viewer.logger.severe("Unknown host: " + + * connectionParams.hostName); showConnectionErrorDialog("Unknown host: '" + + * connectionParams.hostName + "'"); wasError = true; } catch (IOException + * e) { Viewer.logger.severe("Couldn't connect to: " + + * connectionParams.hostName + ":" + connectionParams.portNumber + ": " + + * e.getMessage()); showConnectionErrorDialog("Couldn't connect to: '" + + * connectionParams.hostName + "'\n" + e.getMessage()); wasError = true; } + * return socket; } + */ + + public Socket connectToHost(final ParametersHandler.ConnectionParams connectionParams, + ProtocolSettings settings, MyRfbProto rfb) { Socket socket = null; ConnectionDialog connectionDialog = null; boolean wasError = false; do { - /* - if (forceConnectionDialog || wasError || - connectionParams.isHostNameEmpty() || - -1 == connectionParams.portNumber) { - forceConnectionDialog = false; - if (null == connectionDialog) { - connectionDialog = new ConnectionDialog(containerFrame, - appWindowListener, connectionParams.hostName, connectionParams.portNumber, - settings, isApplet); + if (rfb == null) { + if (forceConnectionDialog || wasError + || connectionParams.isHostNameEmpty() + || -1 == connectionParams.portNumber) { + forceConnectionDialog = false; + if (null == connectionDialog) { + connectionDialog = new ConnectionDialog(containerFrame, + appWindowListener, connectionParams.hostName, + connectionParams.portNumber, settings, isApplet); + } + connectionDialog.setVisible(true); + connectionParams.hostName = connectionDialog + .getServerNameString(); + connectionParams.portNumber = connectionDialog.getPort(); } - connectionDialog.setVisible(true); - connectionParams.hostName = connectionDialog.getServerNameString(); - connectionParams.portNumber = connectionDialog.getPort(); + } else { + // connectionParams.hostName = "localhost"; + connectionParams.portNumber = 5900; } - */ -// connectionParams.hostName = "localhost"; - connectionParams.portNumber = 5900; - Viewer.logger.info("Connecting to host " + connectionParams.hostName + ":" + connectionParams.portNumber); + Viewer.logger.info("Connecting to host " + + connectionParams.hostName + ":" + + connectionParams.portNumber); try { - socket = new Socket(connectionParams.hostName, connectionParams.portNumber); + socket = new Socket(connectionParams.hostName, + connectionParams.portNumber); wasError = false; } catch (UnknownHostException e) { - Viewer.logger.severe("Unknown host: " + connectionParams.hostName); - showConnectionErrorDialog("Unknown host: '" + connectionParams.hostName + "'"); + Viewer.logger.severe("Unknown host: " + + connectionParams.hostName); + showConnectionErrorDialog("Unknown host: '" + + connectionParams.hostName + "'"); wasError = true; } catch (IOException e) { - Viewer.logger.severe("Couldn't connect to: " + - connectionParams.hostName + ":" + connectionParams.portNumber + - ": " + e.getMessage()); - showConnectionErrorDialog("Couldn't connect to: '" + connectionParams.hostName + - "'\n" + e.getMessage()); + Viewer.logger.severe("Couldn't connect to: " + + connectionParams.hostName + ":" + + connectionParams.portNumber + ": " + e.getMessage()); + showConnectionErrorDialog("Couldn't connect to: '" + + connectionParams.hostName + "'\n" + e.getMessage()); wasError = true; } } while (!isApplet && (connectionParams.isHostNameEmpty() || wasError)); -// if (connectionDialog != null) { -// connectionDialog.dispose(); -// } + // if (connectionDialog != null) { + // connectionDialog.dispose(); + // } return socket; } public void showConnectionErrorDialog(final String message) { - JOptionPane errorPane = new JOptionPane(message, JOptionPane.ERROR_MESSAGE); - final JDialog errorDialog = errorPane.createDialog(containerFrame, "Connection error"); - errorDialog.setModalityType(isApplet ? Dialog.ModalityType.APPLICATION_MODAL : Dialog.ModalityType.TOOLKIT_MODAL); + JOptionPane errorPane = new JOptionPane(message, + JOptionPane.ERROR_MESSAGE); + final JDialog errorDialog = errorPane.createDialog(containerFrame, + "Connection error"); + errorDialog + .setModalityType(isApplet ? Dialog.ModalityType.APPLICATION_MODAL + : Dialog.ModalityType.TOOLKIT_MODAL); try { errorDialog.setAlwaysOnTop(true); - } catch (SecurityException e) { /*nop*/ } + } catch (SecurityException e) { /* nop */ + } errorDialog.setVisible(true); }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Mon Oct 22 17:40:32 2012 +0900 @@ -424,7 +424,7 @@ setSurfaceToHandleKbdFocus(); } }); - + JButton winButton = new JButton(Utils.getButtonIcon("win")); winButton.setToolTipText("Send 'Win' key as 'Ctrl-Esc'"); winButton.setMargin(BUTTONS_MARGIN); @@ -438,6 +438,22 @@ } }); + JButton testButton = new JButton(Utils.getButtonIcon("test")); + testButton.setToolTipText("test"); + testButton.setMargin(BUTTONS_MARGIN); + buttonBar.add(testButton); + kbdButtons.add(testButton); + testButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + testKey(context); + setSurfaceToHandleKbdFocus(); + } + }); + + + + JToggleButton ctrlButton = new JToggleButton(Utils.getButtonIcon("ctrl")); ctrlButton.setToolTipText("Ctrl Lock"); ctrlButton.setMargin(BUTTONS_MARGIN); @@ -587,6 +603,10 @@ context.sendMessage(new KeyEventMessage(Keymap.K_ESCAPE, false)); context.sendMessage(new KeyEventMessage(Keymap.K_CTRL_LEFT, false)); } + + private void testKey(ProtocolContext context) { + System.out.println("test"); + } @Override public void windowOpened(WindowEvent e) { /* nop */ } @@ -638,8 +658,15 @@ } public void setSocket(Socket soc) { - workingSocket = soc; + workingSocket = soc; } + /* + public void setSocket(String[] socAddr) { + connectionParams.hostName = socAddr[0]; + connectionParams.portNumber = Integer.parseInt(socAddr[1]); + System.out.println(connectionParams.hostName+" "+connectionParams.portNumber); + } + */ public void close() { try { @@ -654,7 +681,7 @@ } public int getPort() { - return connectionParams.portNumber; + return connectionParams.portNumber; } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/Surface.java Tue Oct 02 18:13:13 2012 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/Surface.java Mon Oct 22 17:40:32 2012 +0900 @@ -125,6 +125,7 @@ requestFocus(); } + @Override public void paintComponent(Graphics g) { ((Graphics2D)g).scale(scaleFactor, scaleFactor); @@ -145,6 +146,7 @@ } } + @Override public Dimension getPreferredSize() { return new Dimension((int)(this.width * scaleFactor), (int)(this.height * scaleFactor));