aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorwimba.com <wimba.com@3789f03b-4d11-0410-bbf8-ca57d06f2519>2005-02-08 17:15:23 +0000
committerwimba.com <wimba.com@3789f03b-4d11-0410-bbf8-ca57d06f2519>2005-02-08 17:15:23 +0000
commite8e1910bc39402d9547324a5d439d11a8febb2e2 (patch)
tree2cb0bd1b9482fe6930ac598c70f5b2614940dbc6 /java
parent275f6076fb621d31b74ff48d7321f410c4d985e7 (diff)
downloadtigervnc-e8e1910bc39402d9547324a5d439d11a8febb2e2.tar.gz
tigervnc-e8e1910bc39402d9547324a5d439d11a8febb2e2.zip
Fix so that the vnc viewer properly sizes on resizes. Using the LWScrollPane from the vncviewer.
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@2543 3789f03b-4d11-0410-bbf8-ca57d06f2519
Diffstat (limited to 'java')
-rw-r--r--java/src/com/tightvnc/rfbplayer/LWScrollPane.java260
-rw-r--r--java/src/com/tightvnc/rfbplayer/RfbPlayer.java20
-rw-r--r--java/src/com/tightvnc/rfbplayer/VncCanvas.java6
3 files changed, 275 insertions, 11 deletions
diff --git a/java/src/com/tightvnc/rfbplayer/LWScrollPane.java b/java/src/com/tightvnc/rfbplayer/LWScrollPane.java
new file mode 100644
index 00000000..c9b49606
--- /dev/null
+++ b/java/src/com/tightvnc/rfbplayer/LWScrollPane.java
@@ -0,0 +1,260 @@
+
+package com.HorizonLive.RfbPlayer;
+
+import java.awt.*;
+import java.awt.event.*;
+
+class LWScrollPane extends Container implements AdjustmentListener {
+
+ /** position info */
+ private Point scrollPosition = new Point(0, 0);
+
+ /** panel to hold component to scroll */
+ private Panel innerPanel = new Panel() {
+
+ public void update(Graphics g) {
+ if (needClear) {
+ super.update(g);
+ needClear = false;
+ } else
+ this.paint(g);
+ }
+
+ };
+
+ /** component to display */
+ private Component containedComp;
+
+ /** layout info */
+ private GridBagLayout gb;
+ private GridBagConstraints gbc;
+
+ /** scroll bars */
+ private Scrollbar xScroller;
+ private Scrollbar yScroller;
+
+ /** flags indicating which scollbars are visible */
+ private boolean showingXScroll = false;
+ private boolean showingYScroll = false;
+
+ /** flag indicating when innerpanel needs to repaint background */
+ private boolean needClear = false;
+
+ /** dimensions for our preferred size */
+ private int width = 0;
+ private int height = 0;
+
+ /** c'tor for a new scroll pane */
+ public LWScrollPane() {
+ // create scroll bars
+ xScroller = new Scrollbar(Scrollbar.HORIZONTAL) {
+
+ public boolean isFocusable() {
+ return false;
+ }
+
+ };
+ yScroller = new Scrollbar(Scrollbar.VERTICAL) {
+
+ public boolean isFocusable() {
+ return false;
+ }
+
+ };
+ xScroller.addAdjustmentListener(this);
+ yScroller.addAdjustmentListener(this);
+
+ // layout info
+ gb = new GridBagLayout();
+ gbc = new GridBagConstraints();
+ setLayout(gb);
+ setBackground(Color.white);
+
+ // added inner panel
+ //innerPanel.setBackground(Color.blue);
+ gbc.fill = GridBagConstraints.BOTH;
+ gbc.gridx = 0;
+ gbc.gridy = 0;
+ gbc.weightx = 100;
+ gbc.weighty = 100;
+ gb.setConstraints(innerPanel, gbc);
+ add(innerPanel);
+ innerPanel.setLayout(null);
+ }
+ /*
+ public void update(Graphics g) {
+ paint(g);
+ }
+ */
+ /*
+ public void paint(Graphics g) {
+ super.paint(g);
+ }
+ */
+
+ /**
+ * Provided to allow the containing frame to resize.
+ * OS X JVM 1.3 would not allow a frame to be made
+ * smaller without overriding getMinimumSize.
+ */
+ public Dimension getMinimumSize() {
+ return new Dimension(0, 0);
+ }
+
+ public Dimension getPreferredSize() {
+ return new Dimension(width, height);
+ }
+
+ public void setSize(int width, int height) {
+ this.width = width;
+ this.height = height;
+ super.setSize(width, height);
+ }
+
+ public void setSize(Dimension d) {
+ setSize(d.width, d.height);
+ }
+
+ /**
+ * Force component to clear itself before repainting.
+ * Primarily useful if the contained component shrinks
+ * without the scroll pane reducing in size.
+ */
+ public void clearAndRepaint() {
+ needClear = true;
+ innerPanel.repaint();
+ }
+
+ /** Add the component to be scrolled by scroll pane */
+ void addComp(Component comp) {
+ containedComp = comp;
+ innerPanel.add(containedComp);
+ }
+
+ /**
+ * Set the point of the component to display in the
+ * upper left corner of the viewport.
+ */
+ void setScrollPosition(int x, int y) {
+ Dimension vps = getViewportSize();
+ Dimension ccs = containedComp.getPreferredSize();
+
+ // skip entirely if component smaller than viewer
+ if (ccs.width <= vps.width && ccs.height <= vps.height)
+ return;
+
+ // don't scroll too far left or up
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+
+ // don't scroll too far right or down
+ if (ccs.width <= vps.width)
+ x = 0;
+ else if (x > (ccs.width - vps.width))
+ x = ccs.width - vps.width;
+ if (ccs.height <= vps.height)
+ y = 0;
+ else if (y > (ccs.height - vps.height))
+ y = ccs.height - vps.height;
+
+ scrollPosition = new Point(x, y);
+ containedComp.setLocation(-scrollPosition.x, -scrollPosition.y);
+ xScroller.setValue(scrollPosition.x);
+ yScroller.setValue(scrollPosition.y);
+ }
+
+ /** Returns the point at the upper left corner of viewport */
+ Point getScrollPosition() {
+ return new Point(scrollPosition);
+ }
+
+ /** Return the dimensions of the viewport */
+ public Dimension getViewportSize() {
+ int vpW, vpH;
+ Dimension size = getSize();
+ vpW = size.width;
+ vpH = size.height;
+ if (showingYScroll)
+ vpW -= yScroller.getSize().width;
+ if (showingXScroll)
+ vpH -= xScroller.getSize().height;
+
+ return new Dimension(vpW, vpH);
+ }
+
+ /**
+ * Ensure that the scroll pane is properly arranged after
+ * a component is added, the pane is resized, etc.
+ */
+ public void doLayout() {
+ /** Add scroll bars as necessary */
+ boolean needX = false, needY = false;
+ Dimension innerSize = containedComp.getPreferredSize();
+ Dimension scrollDimension = getSize();
+
+ if (innerSize.width > scrollDimension.width)
+ needX = true;
+ if (innerSize.height > scrollDimension.height)
+ needY = true;
+
+ showingXScroll = false;
+ showingYScroll = false;
+ remove(yScroller);
+ remove(xScroller);
+
+ if (needY) {
+ gbc.gridy = 0;
+ gbc.gridx = 1;
+ gbc.weightx = 0;
+ gb.setConstraints(yScroller, gbc);
+ add(yScroller);
+ showingYScroll = true;
+ }
+
+ if (needX) {
+ gbc.gridy = 1;
+ gbc.gridx = 0;
+ gbc.weightx = 100;
+ gbc.weighty = 0;
+ gb.setConstraints(xScroller, gbc);
+ add(xScroller);
+ showingXScroll = true;
+ }
+
+ /* set scroll bar values */
+ int vpW, vpH;
+ vpW = scrollDimension.width;
+ vpH = scrollDimension.height;
+ if (showingYScroll)
+ vpW -= yScroller.getSize().width;
+ if (showingXScroll)
+ vpH -= xScroller.getSize().height;
+ yScroller.setValues(0, vpH, 0, innerSize.height);
+ xScroller.setValues(0, vpW, 0, innerSize.width);
+
+ containedComp.setLocation(0, 0);
+ super.doLayout();
+ }
+
+ /**
+ * Adjustment listener method for receiving callbacks
+ * from scroll actions.
+ *
+ * @param e the AdjustmentEvent
+ * @return void
+ */
+ public void adjustmentValueChanged(AdjustmentEvent e) {
+ Point p = containedComp.getLocation();
+ if (e.getAdjustable() == xScroller) {
+ p.x = -e.getValue();
+ scrollPosition.x = e.getValue();
+ } else {
+ p.y = -e.getValue();
+ scrollPosition.y = e.getValue();
+ }
+ containedComp.setLocation(p);
+ }
+
+}
diff --git a/java/src/com/tightvnc/rfbplayer/RfbPlayer.java b/java/src/com/tightvnc/rfbplayer/RfbPlayer.java
index 7a767f17..9f7aa63c 100644
--- a/java/src/com/tightvnc/rfbplayer/RfbPlayer.java
+++ b/java/src/com/tightvnc/rfbplayer/RfbPlayer.java
@@ -57,7 +57,8 @@ public class RfbPlayer extends java.applet.Applet
Frame vncFrame;
Container vncContainer;
- ScrollPane desktopScrollPane;
+ //ScrollPane desktopScrollPane;
+ LWScrollPane desktopScrollPane;
GridBagLayout gridbag;
ButtonPanel buttonPanel;
VncCanvas vc;
@@ -141,23 +142,26 @@ public class RfbPlayer extends java.applet.Applet
// Create a panel which itself is resizeable and can hold
// non-resizeable VncCanvas component at the top left corner.
- Panel canvasPanel = new Panel();
- canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
- canvasPanel.add(vc);
+ //Panel canvasPanel = new Panel();
+ //canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
+ //canvasPanel.add(vc);
// Create a ScrollPane which will hold a panel with VncCanvas
// inside.
- desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
+ //desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
+ desktopScrollPane = new LWScrollPane();
gbc.fill = GridBagConstraints.BOTH;
- gridbag.setConstraints(canvasPanel, gbc);
- desktopScrollPane.add(canvasPanel);
+ gridbag.setConstraints(vc, gbc);
+ //gridbag.setConstraints(canvasPanel, gbc);
+ desktopScrollPane.addComp(vc);
+ desktopScrollPane.setSize(dispW, dispH);
+ //desktopScrollPane.add(canvasPanel);
// Now add the scroll bar to the container.
if (inSeparateFrame) {
gridbag.setConstraints(desktopScrollPane, gbc);
vncFrame.add(desktopScrollPane);
vncFrame.setTitle(rfb.desktopName);
- vncFrame.pack();
vc.resizeDesktopFrame();
} else {
// Size the scroll pane to display size.
diff --git a/java/src/com/tightvnc/rfbplayer/VncCanvas.java b/java/src/com/tightvnc/rfbplayer/VncCanvas.java
index 6c1beecc..9cc98a24 100644
--- a/java/src/com/tightvnc/rfbplayer/VncCanvas.java
+++ b/java/src/com/tightvnc/rfbplayer/VncCanvas.java
@@ -263,10 +263,10 @@ class VncCanvas extends Canvas implements Observer {
if (needResize)
player.desktopScrollPane.setSize(w, h);
- player.vncFrame.pack();
-
// size the canvas
setSize(getPreferredSize());
+
+ player.vncFrame.pack();
}
void resizeEmbeddedApplet() {
@@ -275,9 +275,9 @@ class VncCanvas extends Canvas implements Observer {
if (scrollSize.width != player.dispW ||
scrollSize.height != player.dispH) {
player.desktopScrollPane.setSize(player.dispW, player.dispH);
- player.desktopScrollPane.validate();
}
+ player.desktopScrollPane.validate();
// size the canvas
setSize(getPreferredSize());
}