Mercurial > hg > Applications > TreeVNC
changeset 562:87ae979b88cd
-p mode use ScreenSelectionPanel. Blocking is not working yet, but we can debug it in -p mode.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 02 Feb 2020 19:58:17 +0900 |
parents | 52da5806661c |
children | 5bbe53b47d0a |
files | src/main/java/jp/ac/u_ryukyu/treevnc/ScreenChangeSelectionPanel.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java src/viewer_swing/java/com/glavsoft/viewer/swing/SwingRfbConnectionWorker.java src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java |
diffstat | 5 files changed, 84 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/ScreenChangeSelectionPanel.java Sun Feb 02 11:12:24 2020 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/ScreenChangeSelectionPanel.java Sun Feb 02 19:58:17 2020 +0900 @@ -1,6 +1,8 @@ package jp.ac.u_ryukyu.treevnc; import com.glavsoft.rfb.protocol.ProtocolContext; +import com.glavsoft.viewer.Viewer; +import com.glavsoft.viewer.ViewerInterface; import com.glavsoft.viewer.swing.SwingViewerWindow; import javax.swing.*; @@ -21,11 +23,11 @@ private double width = 750; private double height = 500; - private SwingViewerWindow viewerWindow; + private ViewerInterface viewerWindow; private ProtocolContext context; - public ScreenChangeSelectionPanel(SwingViewerWindow viewerWindow, ProtocolContext context) { + public ScreenChangeSelectionPanel(ViewerInterface viewerWindow, ProtocolContext context) { this.context = context; this.viewerWindow = viewerWindow; setTitle("Select Share Screen");
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sun Feb 02 11:12:24 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sun Feb 02 19:58:17 2020 +0900 @@ -33,7 +33,6 @@ import com.glavsoft.viewer.swing.SwingViewerWindow; import jp.ac.u_ryukyu.treevnc.BroadcastRFBListener; import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; -import jp.ac.u_ryukyu.treevnc.FindRoot; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; import javax.swing.*; @@ -42,7 +41,6 @@ import java.awt.event.WindowListener; import java.io.IOException; import java.io.InputStream; -import java.lang.reflect.Field; import java.net.Socket; import java.util.ArrayList; import java.util.Comparator; @@ -392,7 +390,7 @@ connectionPresenter1.setSingleWidth(width); connectionPresenter1.setSingleHeight(height); connectionPresenter1.setRetinaScale(scale); - connectionPresenter1.setMulticast(connectionPresenter.isUseMulticast()); + connectionPresenter1.setMulticast(myRfb.multicastBlocking); // System.out.println("Sarver change accepted from id :" + newVNCServerId); return connectionPresenter1; } @@ -468,7 +466,9 @@ connectionParams.setConnectionParam(hostName, vncport); isApplet = true; settings.setViewOnly(true); // to avoid unnecessary upward traffic - run(); + ConnectionPresenter cp = createNewConnectionPresenter(hostName, myRfb.getId(), 0, 0, 0, 0, 1); + createScreenSelectionPanel(null); + myRfb.getAcceptThread().waitForShutdown(); } public void initRoot(TreeRFBProto myRfbProto, String hostName) {
--- a/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Sun Feb 02 11:12:24 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ViewerInterface.java Sun Feb 02 19:58:17 2020 +0900 @@ -1,8 +1,13 @@ package com.glavsoft.viewer; +import com.glavsoft.rfb.protocol.ProtocolContext; import com.glavsoft.transport.Reader; import com.glavsoft.transport.Writer; +import com.glavsoft.viewer.swing.ConnectionParams; +import com.glavsoft.viewer.swing.SwingViewerWindow; import jp.ac.u_ryukyu.treevnc.BroadcastRFBListener; +import jp.ac.u_ryukyu.treevnc.ScreenChangeRequest; +import jp.ac.u_ryukyu.treevnc.ScreenChangeSelectionPanel; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; import java.awt.*; @@ -69,4 +74,69 @@ BroadcastRFBListener getRfbBroadcastListener(); public boolean getIsRetinaDisplay(int shareScreenNumber); + + default void changeVncServer(int x, int y, int width, int height, int scale, short id) { + String localhost = "127.0.0.1"; // InetAddress.getLocalHost().getHostName() + try { + getRfb().changeVNCServer(this, localhost, ConnectionParams.DEFAULT_RFB_PORT, x, y, width, height, scale, id, null, null); + } catch (Exception e1) { + System.out.println("can't change server :" + e1.getMessage()); + } + } + + default void screenChangeRequest(ProtocolContext context, int shareScreenNumber) { + ArrayList<FbRectangle> rectangles = getScreenRectangles(); + FbRectangle rectangle1 = rectangles.get(shareScreenNumber); + int singleWidth = (int) (rectangle1.getWidth()); + int singleHeight = (int) (rectangle1.getHeight()); + int x = rectangle1.getXfb(); + int y = rectangle1.getYfb(); + int scale = rectangle1.getRetinaScale(); + // System.out.println("request scrren change rectangles = "+rectangle1); + // showScreenInfo("request screen change id = " + viewer.getRfb().getId(), 0, x, y, singleWidth, singleHeight, scale); + if (getRfb().isTreeManager() || context == null) { + changeVncServer(x, y, singleWidth * scale, singleHeight * scale, scale, getRfb().getId()); + } + if (getRfb().hasParent() && context != null ) { + String adr = getRfb().getMyAddress(); + if (scanPort(adr, ConnectionParams.DEFAULT_RFB_PORT)) { + // -1 means request to reverse direct connection socket + short id = getRfb().isTreeManager() ? (short) -1 : getRfb().getId(); + context.sendMessage(new ScreenChangeRequest(adr, ConnectionParams.DEFAULT_VNC_ROOT, id, x, y, singleWidth * scale, singleHeight * scale, scale)); + } + } + } + + // scan port is not enough to check VNC server. Root server should send error message to the requested + // node when authentication failures are happened + default boolean scanPort(String adr, int port) { + try { + Socket socket = new Socket(adr, port); + socket.close(); + return true; + } catch (Exception e) { + String message = "Please screen sharing settings"; + // show error panel + getConnectionPresenter().showPortErrorDialog(message); + getConnectionPresenter().clearMessage(); + return false; + } + } + + default void createScreenSelectionPanel(ProtocolContext context) { + ArrayList<FbRectangle> rectangles = getScreenRectangles(); + if (rectangles.size() == 1) { // single display + screenChangeRequest(context, 0); + } else if (rectangles.size() > 1){ // dual display + ScreenChangeSelectionPanel selectionPanel = new ScreenChangeSelectionPanel(this, context); + for (int i = 0; i < rectangles.size(); i++) { + Rectangle rectangle = rectangles.get(i); + int screenWidth = rectangle.width; + int screenHeight = rectangle.height; + selectionPanel.checkBox(screenWidth+" X "+screenHeight); + } + selectionPanel.setButton(); + selectionPanel.visible(); + } + } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingRfbConnectionWorker.java Sun Feb 02 11:12:24 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingRfbConnectionWorker.java Sun Feb 02 19:58:17 2020 +0900 @@ -164,7 +164,10 @@ @Override public void startVNCConnection() { presenter.showMessage("Handshake established"); - SwingViewerWindow previousViewerWindow = myRfb.getViewer().getConnectionPresenter().getViewer(); + SwingViewerWindow previousViewerWindow = null ; + if (myRfb.getViewer()!=null && myRfb.getViewer().getConnectionPresenter() != null ) { + previousViewerWindow = myRfb.getViewer().getConnectionPresenter().getViewer(); + } myRfb.newVNCConnection(workingProtocol, presenter); ClipboardControllerImpl clipboardController; if(!myRfb.getCuiVersion())
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Sun Feb 02 11:12:24 2020 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Sun Feb 02 19:58:17 2020 +0900 @@ -33,8 +33,6 @@ import com.glavsoft.utils.Keymap; import com.glavsoft.viewer.*; import com.glavsoft.viewer.swing.gui.OptionsDialog; -import jp.ac.u_ryukyu.treevnc.ScreenChangeRequest; -import jp.ac.u_ryukyu.treevnc.ScreenChangeSelectionPanel; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; import javax.swing.*; @@ -43,7 +41,6 @@ import javax.swing.border.EmptyBorder; import java.awt.*; import java.awt.event.*; -import java.net.Socket; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -68,7 +65,7 @@ private Surface surface; private boolean isSeparateFrame; private final boolean isApplet; - private ViewerInterface viewer; + public ViewerInterface viewer; private String connectionString; private ConnectionPresenter presenter; private Rectangle oldContainerBounds; @@ -851,7 +848,7 @@ JButton screenButton = buttonsBar.createButton("share", "Share my screen", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { - createScreenSelectionPanel(context, viewerWindow); + viewer.createScreenSelectionPanel(context); } }); @@ -898,62 +895,6 @@ setButtonsBarVisible(true, container); } - public void createScreenSelectionPanel(ProtocolContext context, SwingViewerWindow viewerWindow) { - ArrayList<FbRectangle> rectangles = viewer.getScreenRectangles(); - if (rectangles.size() == 1) { // single display - screenChangeRequest(context, 0); - } else if (rectangles.size() > 1){ // dual display - ScreenChangeSelectionPanel selectionPanel = new ScreenChangeSelectionPanel(viewerWindow, context); - for (int i = 0; i < rectangles.size(); i++) { - Rectangle rectangle = rectangles.get(i); - int screenWidth = rectangle.width; - int screenHeight = rectangle.height; - selectionPanel.checkBox(screenWidth+" X "+screenHeight); - } - selectionPanel.setButton(); - selectionPanel.visible(); - } - } - - public void screenChangeRequest(ProtocolContext context, int shareScreenNumber) { - ArrayList<FbRectangle> rectangles = viewer.getScreenRectangles(); - FbRectangle rectangle1 = rectangles.get(shareScreenNumber); - int singleWidth = (int) (rectangle1.getWidth()); - int singleHeight = (int) (rectangle1.getHeight()); - int x = rectangle1.getXfb(); - int y = rectangle1.getYfb(); - int scale = rectangle1.getRetinaScale(); - // System.out.println("request scrren change rectangles = "+rectangle1); - // showScreenInfo("request screen change id = " + viewer.getRfb().getId(), 0, x, y, singleWidth, singleHeight, scale); - if (viewer.getRfb().isTreeManager()) { - changeVncServer(viewer, x, y, singleWidth * scale, singleHeight * scale, scale, viewer.getRfb().getId()); - } - if (viewer.getRfb().hasParent()) { - String adr = viewer.getRfb().getMyAddress(); - if (scanPort(adr, ConnectionParams.DEFAULT_RFB_PORT)) { - // -1 means request to reverse direct connection socket - short id = viewer.getRfb().isTreeManager() ? (short) -1 : viewer.getRfb().getId(); - context.sendMessage(new ScreenChangeRequest(adr, ConnectionParams.DEFAULT_VNC_ROOT, id, x, y, singleWidth * scale, singleHeight * scale, scale)); - } - } - } - - // scan port is not enough to check VNC server. Root server should send error message to the requested - // node when authentication failures are happened - private boolean scanPort(String adr, int port) { - try { - Socket socket = new Socket(adr, port); - socket.close(); - return true; - } catch (Exception e) { - String message = "Please screen sharing settings"; - // show error panel - presenter.showPortErrorDialog(message); - presenter.clearMessage(); - return false; - } - } - /** * change screen viewer scale to fit the selected server screen size in multi screens */ @@ -1092,15 +1033,6 @@ frame.setVisible(b); } - private void changeVncServer(ViewerInterface viewer, int x, int y, int width, int height, int scale, short id) { - String localhost = "127.0.0.1"; // InetAddress.getLocalHost().getHostName() - try { - viewer.getRfb().changeVNCServer(viewer, localhost, ConnectionParams.DEFAULT_RFB_PORT, x, y, width, height, scale, id, null, null); - } catch (Exception e1) { - System.out.println("can't change server :" + e1.getMessage()); - } - } - public UiSettings getUiSettings() { return uiSettings; }