01: package org.enhydra.jawe.components.graph.actions;
02:
03: import java.awt.Dimension;
04: import java.awt.event.ActionEvent;
05:
06: import org.enhydra.jawe.ActionBase;
07: import org.enhydra.jawe.JaWEComponent;
08: import org.enhydra.jawe.components.graph.Graph;
09: import org.enhydra.jawe.components.graph.GraphController;
10:
11: /**
12: * Zoom out (for 15%)
13: * @author Sasa Bojanic
14: */
15: public class ZoomOut extends ActionBase {
16:
17: public ZoomOut(JaWEComponent jawecomponent) {
18: super (jawecomponent);
19: }
20:
21: public void enableDisableAction() {
22: GraphController gc = (GraphController) jawecomponent;
23:
24: if (gc.getSelectedGraph() != null)
25: if (gc.getSelectedGraph().getScale() > 0.1) {
26: setEnabled(true);
27: return;
28: }
29:
30: setEnabled(false);
31: }
32:
33: public void actionPerformed(ActionEvent e) {
34: Graph selectedGraph = ((GraphController) jawecomponent)
35: .getSelectedGraph();
36: if (selectedGraph == null)
37: return;
38: //setResizeAction(null);
39: double scale = selectedGraph.getScale() / 1.15;
40: scale = Math.max(Math.min(scale, 2), 0.1);
41: selectedGraph.setScale(scale);
42: try {
43: Dimension prefSize = selectedGraph.getSize();
44: prefSize.width = (int) (prefSize.width / 1.15);
45: prefSize.height = (int) (prefSize.height / 1.15);
46: selectedGraph.setPreferredSize(prefSize);
47: } catch (Exception ex) {
48: }
49:
50: // With JGraph3.4.1 this causes problems
51: /*if (editor.getGraph().getSelectionCell() != null) {
52: editor.getGraph().scrollCellToVisible(editor.getGraph().getSelectionCell());
53: }*/
54:
55: GraphController gc = (GraphController) jawecomponent;
56: gc.getSettings().getAction("ZoomIn").getAction()
57: .enableDisableAction();
58: gc.getSettings().getAction("ZoomOut").getAction()
59: .enableDisableAction();
60: gc.getSettings().getAction("ActualSize").getAction()
61: .enableDisableAction();
62: }
63: }
|