001/* =========================================================== 002 * Orson Charts : a 3D chart library for the Java(tm) platform 003 * =========================================================== 004 * 005 * (C)opyright 2013-2022, by David Gilbert. All rights reserved. 006 * 007 * https://github.com/jfree/orson-charts 008 * 009 * This program is free software: you can redistribute it and/or modify 010 * it under the terms of the GNU General Public License as published by 011 * the Free Software Foundation, either version 3 of the License, or 012 * (at your option) any later version. 013 * 014 * This program is distributed in the hope that it will be useful, 015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 017 * GNU General Public License for more details. 018 * 019 * You should have received a copy of the GNU General Public License 020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 021 * 022 * [Oracle and Java are registered trademarks of Oracle and/or its affiliates. 023 * Other names may be trademarks of their respective owners.] 024 * 025 * If you do not wish to be bound by the terms of the GPL, an alternative 026 * commercial license can be purchased. For details, please see visit the 027 * Orson Charts home page: 028 * 029 * http://www.object-refinery.com/orsoncharts/index.html 030 * 031 */ 032 033package org.jfree.chart3d.graphics3d.swing; 034 035import java.awt.event.ActionEvent; 036 037import javax.swing.AbstractAction; 038import javax.swing.Action; 039 040import org.jfree.chart3d.Resources; 041import org.jfree.chart3d.graphics3d.ViewPoint3D; 042import org.jfree.chart3d.internal.Args; 043 044/** 045 * An action that performs a zoom-in operation. 046 * <br><br> 047 * NOTE: This class is serializable, but the serialization format is subject 048 * to change in future releases and should not be relied upon for persisting 049 * instances of this class. 050 * 051 * @see ZoomOutAction 052 */ 053@SuppressWarnings("serial") 054public class ZoomInAction extends AbstractAction { 055 056 /** The panel that the action applies to. */ 057 private Panel3D panel; 058 059 private double zoomMultiplier; 060 061 /** 062 * Creates a new zoom-in action associated with the specified panel. 063 * 064 * @param panel the panel ({@code null} not permitted). 065 * @param fontAwesome if {@code true} an icon from Font Awesome is 066 * used for the action label, otherwise a regular text label is used. 067 */ 068 public ZoomInAction(Panel3D panel, boolean fontAwesome) { 069 super("\uf00e"); 070 Args.nullNotPermitted(panel, "panel"); 071 this.panel = panel; 072 this.zoomMultiplier = 0.95; 073 if (!fontAwesome) { 074 putValue(Action.NAME, Resources.localString("ZOOM_IN")); 075 } 076 putValue(Action.ACTION_COMMAND_KEY, "ZOOM_IN"); 077 putValue(Action.SHORT_DESCRIPTION, Resources.localString("ZOOM_IN")); 078 } 079 080 /** 081 * Returns the zoom multiplier. The default value is {@code 95 / 100} 082 * (the inverse of the multiplier in the {@link ZoomOutAction}). 083 * 084 * @return The zoom multiplier. 085 * 086 * @since 1.3 087 */ 088 public double getZoomMultiplier() { 089 return zoomMultiplier; 090 } 091 092 /** 093 * Sets the zoom multiplier (the current viewing distance is multiplied 094 * by this factor to determine the new viewing distance). 095 * 096 * @param multiplier the new multiplier. 097 * 098 * @since 1.3 099 */ 100 public void setZoomMultiplier(double multiplier) { 101 this.zoomMultiplier = multiplier; 102 } 103 104 /** 105 * Performs the zoom in action. 106 * 107 * @param e the action event. 108 */ 109 @Override 110 public void actionPerformed(ActionEvent e) { 111 ViewPoint3D viewPt = this.panel.getViewPoint(); 112 double minDistance = this.panel.getMinViewingDistance(); 113 double maxDistance = minDistance 114 * this.panel.getMaxViewingDistanceMultiplier(); 115 double valRho = Math.max(minDistance, 116 Math.min(maxDistance, viewPt.getRho() * this.zoomMultiplier)); 117 this.panel.getViewPoint().setRho(valRho); 118 this.panel.repaint(); 119 } 120 121}