]> source.dussan.org Git - tigervnc.git/commitdiff
Remove some redundant variables related to scaling, fix loop when fixedRatioScale...
authorBrian Hinz <bphinz@users.sourceforge.net>
Tue, 11 Oct 2011 02:15:12 +0000 (02:15 +0000)
committerBrian Hinz <bphinz@users.sourceforge.net>
Tue, 11 Oct 2011 02:15:12 +0000 (02:15 +0000)
git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@4719 3789f03b-4d11-0410-bbf8-ca57d06f2519

java/com/tigervnc/vncviewer/CConn.java
java/com/tigervnc/vncviewer/DesktopWindow.java
java/com/tigervnc/vncviewer/OptionsDialog.java

index d504eb16b4d1661bff80faf3672b0f8b5a754a16..d9e16829d12ba980487aae73689b9d09284b669e 100644 (file)
@@ -71,22 +71,33 @@ class ViewportFrame extends JFrame
     });
     addComponentListener(new ComponentAdapter() {
       public void componentResized(ComponentEvent e) {
-        if (cc.options.autoScale || cc.options.fixedRatioScale) {
-          if (sp.getSize().width != cc.desktop.scaledWidth ||
-              sp.getSize().height != cc.desktop.scaledHeight) {
+        if ((getExtendedState() != JFrame.MAXIMIZED_BOTH) &&
+            cc.fullScreen) {
+          cc.toggleFullScreen();
+        }
+        String scaleString = cc.viewer.scalingFactor.getValue();
+        if (scaleString.equals("Auto") || scaleString.equals("FixedRatio")) {
+          if ((sp.getSize().width != cc.desktop.scaledWidth) ||
+              (sp.getSize().height != cc.desktop.scaledHeight)) {
+            int policy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
+            sp.setHorizontalScrollBarPolicy(policy);
             cc.desktop.setScaledSize();
             sp.setSize(new Dimension(cc.desktop.scaledWidth,
                                      cc.desktop.scaledHeight));
             sp.validate();
-            pack();
-            update(g);
+            if (getExtendedState() != JFrame.MAXIMIZED_BOTH)
+              pack();
             if (cc.desktop.cursor != null) {
               Cursor cursor = cc.desktop.cursor;
               cc.setCursor(cursor.width(),cursor.height(),cursor.hotspot, 
-                          cursor.data, cursor.mask);
+                           cursor.data, cursor.mask);
             }
           }
-        }      
+        } else {
+          int policy = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
+          sp.setHorizontalScrollBarPolicy(policy);
+          sp.validate();
+        }
       }
     });
   }
@@ -110,7 +121,7 @@ class ViewportFrame extends JFrame
     } else {
       setSize(w, h);
     }
-    if (!cc.options.autoScale && !cc.options.fixedRatioScale)
+    if (!cc.fullScreen)
       setLocation(x, y);
     setBackground(Color.BLACK);
   }
@@ -503,11 +514,18 @@ public class CConn extends CConnection
       if (!pack)
         viewport.setPreferredSize(new Dimension(w,h));
 
-      int x = (dpySize.width - w - wmDecorationWidth) / 2;
-      int y = (dpySize.height - h - wmDecorationHeight)/2;
-
-      viewport.setExtendedState(JFrame.NORMAL);
-      viewport.setGeometry(x, y, w, h, pack);
+      if (viewport.getExtendedState() == JFrame.MAXIMIZED_BOTH) {
+        w = viewport.getSize().width;
+        h = viewport.getSize().height;
+        int x = viewport.getLocation().x;
+        int y = viewport.getLocation().y;
+        viewport.setGeometry(x, y, w, h, pack);
+      } else {
+        int x = (dpySize.width - w - wmDecorationWidth) / 2;
+        int y = (dpySize.height - h - wmDecorationHeight)/2;
+        viewport.setExtendedState(JFrame.NORMAL);
+        viewport.setGeometry(x, y, w, h, pack);
+      }
     }
     viewport.update(viewport.g);
   }
@@ -822,25 +840,20 @@ public class CConn extends CConnection
     options.useLocalCursor.setSelected(viewer.useLocalCursor.getValue());
     options.fastCopyRect.setSelected(viewer.fastCopyRect.getValue());
     options.acceptBell.setSelected(viewer.acceptBell.getValue());
-    options.autoScale = false;
-    options.fixedRatioScale = false;
     String scaleString = viewer.scalingFactor.getValue();
     if (scaleString.equals("Auto")) {
-      options.autoScale = true;
       options.scalingFactor.setSelectedItem("Auto");
-      // FIXME: set scaleFactor?
     } else if(scaleString.equals("FixedRatio")) {
-      options.fixedRatioScale = true;
       options.scalingFactor.setSelectedItem("Fixed Aspect Ratio");
-      // FIXME: set scaleFactor?
     } else { 
       digit = Integer.parseInt(scaleString);
       if (digit >= 1 && digit <= 1000) {
         options.scalingFactor.setSelectedItem(digit+"%");
       } else {
-        options.scalingFactor.setSelectedItem(Integer.parseInt(viewer.scalingFactor.getDefaultStr())+"%");
+        digit = Integer.parseInt(viewer.scalingFactor.getDefaultStr());
+        options.scalingFactor.setSelectedItem(digit+"%");
       }
-      scaleFactor = 
+      int scaleFactor = 
         Integer.parseInt(scaleString.substring(0, scaleString.length()));
       if (desktop != null)
         desktop.setScaledSize();
@@ -901,30 +914,23 @@ public class CConn extends CConnection
     viewer.sendClipboard.setParam(options.sendClipboard.isSelected());
     viewer.fastCopyRect.setParam(options.fastCopyRect.isSelected());
     viewer.acceptBell.setParam(options.acceptBell.isSelected());
-    if (options.autoScale) {
+    String scaleString =
+      options.scalingFactor.getSelectedItem().toString();
+    if (scaleString.equals("Auto")) {
       viewer.scalingFactor.setParam("Auto");
-      scaleFactor = -1;
-      if (desktop != null) {
+      if (desktop != null)
         reconfigureViewport();
-        viewport.update(viewport.g);
-      }
-    } else if(options.fixedRatioScale) {
+    } else if(scaleString.equals("Fixed Aspect Ratio")) {
       viewer.scalingFactor.setParam("FixedRatio");
-      scaleFactor = -1;
-      if (desktop != null) {
+      if (desktop != null)
         reconfigureViewport();
-        viewport.update(viewport.g);
-      }
     } else { 
-      String scaleString =
-        options.scalingFactor.getSelectedItem().toString();
-      viewer.scalingFactor.setParam(scaleString.substring(0, scaleString.length()-1));
-      int oldScaleFactor = scaleFactor;
-      scaleFactor = 
-        Integer.parseInt(scaleString.substring(0, scaleString.length()-1));
-      if (oldScaleFactor != scaleFactor && desktop != null) {
+      scaleString=scaleString.substring(0, scaleString.length()-1);
+      String oldScaleFactor = viewer.scalingFactor.getValue();
+      viewer.scalingFactor.setParam(scaleString);
+      if ((desktop != null) && (!oldScaleFactor.equals("Auto") ||
+           !oldScaleFactor.equals("FixedRatio"))) {
         reconfigureViewport();
-        viewport.update(viewport.g);
       }
     }
 
@@ -1291,7 +1297,5 @@ public class CConn extends CConnection
   boolean firstUpdate;
   boolean pendingUpdate;
   
-  int scaleFactor = 100;
-  
   static LogWriter vlog = new LogWriter("CConn");
 }
index e3d5a58eb1348fa497cab277c7623989322c7667..21e2e8ead76d263b3819fe9d224e9f64123816ff 100644 (file)
@@ -315,9 +315,13 @@ class DesktopWindow extends JPanel implements
   }
 
   public void setScaledSize() {
-    if (!cc.options.autoScale && !cc.options.fixedRatioScale) {
-      scaledWidth = (int)Math.floor((float)cc.cp.width * (float)cc.scaleFactor/100.0);
-      scaledHeight = (int)Math.floor((float)cc.cp.height * (float)cc.scaleFactor/100.0);
+    String scaleString = cc.viewer.scalingFactor.getValue();
+    if (!scaleString.equals("Auto") && !scaleString.equals("FixedRatio")) {
+      int scalingFactor = Integer.parseInt(scaleString);
+      scaledWidth = 
+        (int)Math.floor((float)cc.cp.width * (float)scalingFactor/100.0);
+      scaledHeight = 
+        (int)Math.floor((float)cc.cp.height * (float)scalingFactor/100.0);
     } else {
       if (cc.viewport == null) {
         scaledWidth = cc.cp.width;
@@ -330,7 +334,7 @@ class DesktopWindow extends JPanel implements
                         vpSize.height - vpInsets.top - vpInsets.bottom);
         if (availableSize.width == 0 || availableSize.height == 0)
           availableSize = new Dimension(cc.cp.width, cc.cp.height);
-        if (cc.options.fixedRatioScale) {
+        if (scaleString.equals("FixedRatio")) {
           float widthRatio = (float)availableSize.width / (float)cc.cp.width;
           float heightRatio = (float)availableSize.height / (float)cc.cp.height;
           float ratio = Math.min(widthRatio, heightRatio);
index 2ca1e603c746acf40d0f24739982fb1ebc02b9c0..9a463fb35b1f29067d957ed18e712093fa9bfbb9 100644 (file)
@@ -50,9 +50,6 @@ class OptionsDialog extends Dialog implements
   JButton defSaveButton;
   UserPrefs defaults;
 
-  boolean autoScale = false;
-  boolean fixedRatioScale = false;
-
   public OptionsDialog(OptionsDialogCallback cb_) { 
     super(false);
     cb = cb_;
@@ -287,9 +284,6 @@ class OptionsDialog extends Dialog implements
     veryLowColour.setEnabled(!autoSelect.isSelected());
     compressLevel.setEnabled(customCompressLevel.isSelected());
     qualityLevel.setEnabled(noJpeg.isSelected());
-    autoScale = (scalingFactor.getSelectedItem().equals("Auto"));
-    fixedRatioScale = 
-      (scalingFactor.getSelectedItem().equals("Fixed Aspect Ratio"));
     sendLocalUsername.setEnabled(secVeNCrypt.isEnabled()&&
       (secPlain.isSelected()||secIdent.isSelected()));
   }
@@ -335,9 +329,6 @@ class OptionsDialog extends Dialog implements
   public void actionPerformed(ActionEvent e) {
     Object s = e.getSource();
     if (s instanceof JButton && (JButton)s == okButton) {
-      autoScale = (scalingFactor.getSelectedItem().equals("Auto"));
-      fixedRatioScale = 
-        (scalingFactor.getSelectedItem().equals("Fixed Aspect Ratio"));
       ok = true;
       if (cb != null) cb.getOptions();
       endDialog();