changeset 8012:2e40d9c0d7e4

[SCENEBUILDER] Fix for DTL-6790 (Add Zoom In (CMD +) and Zoom Out (CMD -) to Menubar > View > Zoom).
author Eric Le Ponner <eric.le.ponner@oracle.com>
date Tue, 09 Sep 2014 10:24:55 +0200
parents 359d7111ad78
children d62cb8404b84
files apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/i18n/SceneBuilderApp.properties apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java
diffstat 2 files changed, 92 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/i18n/SceneBuilderApp.properties	Tue Sep 09 09:36:57 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/i18n/SceneBuilderApp.properties	Tue Sep 09 10:24:55 2014 +0200
@@ -133,6 +133,8 @@
 menu.title.enable.guides = Enable Alig_nment Guides
 menu.title.show.sample.controller.skeleton = Show Sample Controller S_keleton
 menu.title.zoom = _Zoom
+menu.title.zoom.in = Zoom _In
+menu.title.zoom.out = Zoom _Out
 # Modify menu items
 menu.title.fit = Fi_t to Parent
 menu.title.use.computed.sizes = _Use Computed Sizes
--- a/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java	Tue Sep 09 09:36:57 2014 +0200
+++ b/apps/scenebuilder/SceneBuilderApp/src/com/oracle/javafx/scenebuilder/app/menubar/MenuBarController.java	Tue Sep 09 10:24:55 2014 +0200
@@ -1108,9 +1108,24 @@
     /*
      * Private (zoom menu)
      */
+    
+    final static double[] scalingTable = {0.25, 0.50, 0.75, 1.00, 1.50, 2.0, 4.0};
+    
     private void updateZoomMenu() {
         final double[] scalingTable = {0.25, 0.50, 0.75, 1.00, 1.50, 2.0, 4.0};
 
+        final MenuItem zoomInMenuItem = new MenuItem(I18N.getString("menu.title.zoom.in"));
+        zoomInMenuItem.setUserData(new ZoomInActionController());
+        zoomInMenuItem.setAccelerator(new KeyCharacterCombination("+", modifier)); //NOI18N
+        zoomMenu.getItems().add(zoomInMenuItem);
+        
+        final MenuItem zoomOutMenuItem = new MenuItem(I18N.getString("menu.title.zoom.out"));
+        zoomOutMenuItem.setUserData(new ZoomOutActionController());
+        zoomOutMenuItem.setAccelerator(new KeyCharacterCombination("-", modifier)); //NOI18N
+        zoomMenu.getItems().add(zoomOutMenuItem);
+        
+        zoomMenu.getItems().add(new SeparatorMenuItem());
+        
         for (int i = 0; i < scalingTable.length; i++) {
             final double scaling = scalingTable[i];
             final String title = String.format("%.0f%%", scaling * 100); //NOI18N
@@ -1120,6 +1135,20 @@
         }
     }
 
+    
+    private static int findZoomScaleIndex(double zoomScale) {
+        int result = -1;
+        
+        for (int i = 0; i < scalingTable.length; i++) {
+            if (MathUtils.equals(zoomScale, scalingTable[i])) {
+                result = i;
+                break;
+            }
+        }
+        
+        return result;
+    }
+    
     private void updateOpenRecentMenuItems() {
 
         final List<MenuItem> menuItems = new ArrayList<>();
@@ -1699,6 +1728,67 @@
 
     }
     
+    class ZoomInActionController extends MenuItemController {
+
+        @Override
+        public boolean canPerform() {
+            boolean result;
+            if (documentWindowController == null) {
+                result = false;
+            } else {
+                final ContentPanelController contentPanelController
+                        = documentWindowController.getContentPanelController();
+                final int currentScalingIndex
+                        = findZoomScaleIndex(contentPanelController.getScaling());
+                result = currentScalingIndex+1 < scalingTable.length;
+            }
+            return result;
+        }
+
+        @Override
+        public void perform() {
+            final ContentPanelController contentPanelController
+                    = documentWindowController.getContentPanelController();
+            final int currentScalingIndex
+                    = findZoomScaleIndex(contentPanelController.getScaling());
+            final double newScaling
+                    = scalingTable[currentScalingIndex+1];
+            contentPanelController.setScaling(newScaling);
+        }
+
+    }
+    
+
+    class ZoomOutActionController extends MenuItemController {
+
+        @Override
+        public boolean canPerform() {
+            boolean result;
+            if (documentWindowController == null) {
+                result = false;
+            } else {
+                final ContentPanelController contentPanelController
+                        = documentWindowController.getContentPanelController();
+                final int currentScalingIndex
+                        = findZoomScaleIndex(contentPanelController.getScaling());
+                result = 0 <= currentScalingIndex-1;
+            }
+            return result;
+        }
+
+        @Override
+        public void perform() {
+            final ContentPanelController contentPanelController
+                    = documentWindowController.getContentPanelController();
+            final int currentScalingIndex
+                    = findZoomScaleIndex(contentPanelController.getScaling());
+            final double newScaling
+                    = scalingTable[currentScalingIndex-1];
+            contentPanelController.setScaling(newScaling);
+        }
+
+    }
+    
     private void updatePreviewWindowSize(Size size) {
         if (documentWindowController != null
                 && documentWindowController.getPreviewWindowController() != null