1
2 package hep.wired.edit;
3
4 import java.awt.*;
5 import java.awt.geom.*;
6 import java.util.logging.*;
7 import javax.swing.*;
8 import javax.swing.undo.*;
9
10 import hep.wired.services.RecordPlot;
11 import hep.wired.services.GraphicsPanel;
12 import hep.wired.services.ViewPort;
13 import hep.wired.feature.Scaleable;
14 import hep.wired.feature.Scaleable2D;
15 import hep.wired.feature.Scaleable3D;
16 import hep.wired.util.XYZindices;
17
18 /***
19 * Set Scale of a plot in 2D or 3D.
20 *
21 * @author Mark Donszelmann
22 * @version $Id: SetScale.java 2083 2005-07-20 17:16:52Z duns $
23 */
24
25 public class SetScale extends WiredEdit implements GraphicsPanelEdit, XYZindices {
26
27 private static Logger logger = Logger.getLogger(SetScale.class.getPackage().getName());
28 private double sx, sy, sz;
29 private double[] oldS;
30
31 public SetScale(double tx, double ty, double tz) {
32 super(0);
33 this.sx = sx;
34 this.sy = sy;
35 this.sz = sz;
36 oldS = null;
37 }
38
39 public WiredEdit copy(RecordPlot plot) {
40 WiredEdit copy = new SetScale(sx, sy, sz);
41 copy.setRecordPlot(plot);
42 return copy;
43 }
44
45 public String getPresentationName() {
46 StringBuffer s = new StringBuffer();
47 s.append(toString());
48 s.append(" (");
49 s.append(format.format(sx));
50 if ((sy != 1) || (sz != 1)) {
51 s.append(", ");
52 s.append(format.format(sy));
53 }
54 if (sz != 1) {
55 s.append(", ");
56 s.append(format.format(sz));
57 }
58 s.append(")");
59 return s.toString();
60 }
61
62 public String toString() {
63 return "SetScale";
64 }
65
66 public boolean addEdit(UndoableEdit edit) {
67 return false;
68 }
69
70 public boolean isSupportedBy(GraphicsPanel p) {
71 return p.supports(Scaleable2D.class) || p.supports(Scaleable3D.class);
72 }
73
74 protected void redoEdit() {
75 GraphicsPanel panel = getRecordPlot().getGraphicsPanel();
76 Scaleable3D scaleable3D = (Scaleable3D)panel.getFeature(Scaleable3D.class);
77 if (scaleable3D != null) {
78 oldS = scaleable3D.getScale();
79 scaleable3D.setScale(sx, sy, sz);
80 } else {
81 Scaleable2D scaleable2D = (Scaleable2D)panel.getFeature(Scaleable2D.class);
82 if (scaleable2D == null) {
83 System.err.println("Could not redo: "+this);
84 return;
85 }
86 oldS = scaleable2D.getScale();
87 scaleable2D.setScale(sx, sy);
88 }
89 getRecordPlot().repaint();
90 logger.finer(toString());
91 }
92
93 protected void undoEdit() {
94 if (oldS == null) {
95 System.err.println("Could not undo: "+this);
96 return;
97 }
98
99 GraphicsPanel panel = getRecordPlot().getGraphicsPanel();
100 Scaleable3D scaleable3D = (Scaleable3D)panel.getFeature(Scaleable3D.class);
101 if (scaleable3D != null) {
102 scaleable3D.setScale(oldS[X], oldS[Y], oldS[Z]);
103 } else {
104 Scaleable2D scaleable2D = (Scaleable2D)panel.getFeature(Scaleable2D.class);
105 if (scaleable2D == null) {
106 System.err.println("Could not undo: "+this);
107 return;
108 }
109 scaleable2D.setScale(oldS[X], oldS[Y]);
110 }
111 getRecordPlot().repaint();
112 logger.finer(toString());
113 }
114 }