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; 042 043/** 044 * An action that performs a zoom out operation on the content in a 045 * {@link Panel3D}. 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 ZoomInAction 052 */ 053@SuppressWarnings("serial") 054public class ZoomOutAction extends AbstractAction { 055 056 /** The panel that the action applies to. */ 057 private final Panel3D panel; 058 059 /** The multiplier used to calculate the new viewing distance. */ 060 private double zoomMultiplier; 061 062 /** 063 * Creates a new zoom-out action associated with the specified panel. 064 * 065 * @param panel the panel ({@code null} not permitted). 066 * @param fontAwesome use the FontAwesome icon text? 067 */ 068 public ZoomOutAction(Panel3D panel, boolean fontAwesome) { 069 super("\uf010"); 070 this.panel = panel; 071 this.zoomMultiplier = 10.0 / 9.5; 072 if (!fontAwesome) { 073 putValue(Action.NAME, Resources.localString("ZOOM_OUT")); 074 } 075 putValue(Action.ACTION_COMMAND_KEY, "ZOOM_OUT"); 076 putValue(Action.SHORT_DESCRIPTION, Resources.localString("ZOOM_OUT")); 077 } 078 079 /** 080 * Returns the zoom multiplier. The default value is 081 * {@code 100 / 95} (the inverse of the multiplier in the 082 * {@link ZoomInAction}). 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 out 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}