View Javadoc

1   // Copyright 2004, FreeHEP.
2   package hep.wired.heprep.edit;
3   
4   import javax.swing.undo.UndoableEdit;
5   
6   import hep.wired.edit.WiredEdit;
7   import hep.wired.edit.GraphicsPanelEdit;
8   import hep.wired.services.RecordPlot;
9   import hep.wired.services.GraphicsPanel;
10  import hep.wired.services.Edit;
11  import hep.wired.heprep.graphicspanel.HepRepPanel;
12  
13  /***
14   * Generic Edit for changing the GraphicsMode.
15   *
16   * @author Mark Donszelmann
17   * @version $Id: GraphicsModeEdit.java 2136 2005-07-30 00:25:21Z duns $
18   */
19  
20  public class GraphicsModeEdit extends WiredEdit implements GraphicsPanelEdit {
21      
22      private String name;
23      private Object oldValue;
24      private Object value;
25      
26      public GraphicsModeEdit(String name) {
27          this(name, null);
28      }
29      
30      public GraphicsModeEdit(String name, boolean value) {
31          this(name, new Boolean(value));
32      }
33          
34      public GraphicsModeEdit(String name, double value) {
35          this(name, new Double(value));
36      }
37      
38      public GraphicsModeEdit(String name, int value) {
39          this(name, new Integer(value));
40      }
41      
42      private GraphicsModeEdit(String name, Object value) {
43          super();
44          this.name = name;
45          this.value = value;
46          this.oldValue = null;
47      }
48  
49      public WiredEdit copy(RecordPlot plot) {
50          WiredEdit copy = new GraphicsModeEdit(name, value);
51          copy.setRecordPlot(plot);
52          return copy;
53      }
54  
55      public String getPresentationName() {
56          return "GraphicsModeEdit( "+name+" = "+value+" )";
57      }
58      
59      public boolean isSupportedBy(GraphicsPanel p) {
60          return p instanceof HepRepPanel;
61      }
62  
63      public boolean addEdit(UndoableEdit edit) {
64          if (edit instanceof GraphicsModeEdit) {
65              // only if they are equal
66              GraphicsModeEdit modeEdit = (GraphicsModeEdit)edit;
67              if (modeEdit.name.equals(name)) {
68                  return modeEdit.value.equals(value);
69              }
70          }
71          return false;
72      }
73  
74      public void redoEdit() {
75          HepRepPanel panel = (HepRepPanel)getRecordPlot().getGraphicsPanel();
76          oldValue = panel.getGraphicsMode().getValue(name);
77          panel.getGraphicsMode().setValue(name, value);
78          getRecordPlot().repaint();
79      }
80  
81      public void undoEdit() {
82          HepRepPanel panel = (HepRepPanel)getRecordPlot().getGraphicsPanel();
83          value = panel.getGraphicsMode().getValue(name);
84          panel.getGraphicsMode().setValue(name, oldValue);
85          getRecordPlot().repaint();
86      }
87  }