1
2 package hep.wired.heprep.graphicspanel;
3
4 import java.text.*;
5 import java.util.*;
6 import javax.swing.event.*;
7
8 import org.jdom.Attribute;
9 import org.jdom.Element;
10
11 import org.freehep.xml.io.XMLIO;
12 import org.freehep.xml.io.XMLIOManager;
13 import org.freehep.util.Value;
14
15 import hep.wired.variable.Variable;
16 import hep.wired.variable.BooleanVariable;
17 import hep.wired.variable.IntegerVariable;
18 import hep.wired.variable.DoubleVariable;
19
20 import hep.wired.heprep.services.GraphicsMode;
21
22 /***
23 * Defines the general graphics mode for each plot.
24 *
25 * @author Mark Donszelmann
26 * @version $Id: HepRepGraphicsMode.java 2181 2005-08-03 19:11:28Z duns $
27 */
28 public class HepRepGraphicsMode implements GraphicsMode, XMLIO {
29
30 private Map
31
32 public boolean drawWideLines;
33 public boolean fillBoxes;
34 public boolean drawFrames;
35 public boolean antiAlias;
36 public boolean useLayering;
37
38 public double lineWidthMultiplier;
39 public double markSizeMultiplier;
40
41 /***
42 * Creates an empty graphics mode.
43 */
44 private HepRepGraphicsMode() {
45 variables = new HashMap();
46 }
47
48 /***
49 * Creates a graphics mode, with predefined and preset (fast) properties.
50 */
51 public HepRepGraphicsMode(boolean fast) {
52 this();
53
54 final BooleanVariable varDrawWideLines = addVariable("drawWideLines", false, "Draws lines using a line width different than 1.0 if applicable");
55 addVariable("fillBoxes", false, "Fills boxes of symbols");
56 addVariable("drawFrames", false, "Draws a frame around lines and symbols");
57 addVariable("antiAlias", false, "Anti-Alias the image");
58 addVariable("useLayering", !fast, "Use layering for drawing objects");
59
60
61 final DoubleVariable varLineWidthMultiplier = addVariable("lineWidthMultiplier", 0.1, 10, 2.0, null, "Multiplication factor for line width");
62 addVariable("markSizeMultiplier", 0.1, 25, 1.0, null, "Multiplication factor for marker size");
63
64
65 varDrawWideLines.addChangeListener(new ChangeListener() {
66 public void stateChanged(ChangeEvent event) {
67 varLineWidthMultiplier.setEnabled(varDrawWideLines.getBooleanVariable());
68 }
69 });
70 varLineWidthMultiplier.setEnabled(varDrawWideLines.getBooleanVariable());
71 }
72
73 /***
74 * Returns a copy of this graphics mode.
75 */
76 public GraphicsMode copy() {
77 HepRepGraphicsMode copy = new HepRepGraphicsMode(true);
78
79 copy.drawWideLines = drawWideLines;
80 copy.fillBoxes = fillBoxes;
81 copy.drawFrames =drawFrames;
82 copy.antiAlias = antiAlias;
83 copy.useLayering = useLayering;
84 copy.lineWidthMultiplier = lineWidthMultiplier;
85 copy.markSizeMultiplier = markSizeMultiplier;
86
87 return copy;
88 }
89
90 public Collection getVariables() {
91 return variables.values();
92 }
93
94 public void add(Variable var) {
95 variables.put(var.getName(), var);
96 }
97
98 /***
99 * Adds a named variable with minimum, maximum and default value.
100 */
101 protected DoubleVariable addVariable(String name, double min, double max, double def, String unit, String description) {
102 DoubleVariable variable = new DoubleVariable(name, this, min, max, def, unit, description);
103 add(variable);
104 return variable;
105 }
106
107 /***
108 * Adds a named variable with minimum, maximum and default value.
109 */
110 protected IntegerVariable addVariable(String name, int min, int max, int def, String unit, String description) {
111 IntegerVariable variable = new IntegerVariable(name, this, min, max, def, unit, description);
112 add(variable);
113 return variable;
114 }
115
116 /***
117 * Adds a named variable with default value.
118 */
119 protected BooleanVariable addVariable(String name, boolean def, String description) {
120 BooleanVariable variable = new BooleanVariable(name, this, def, description);
121 add(variable);
122 return variable;
123 }
124
125 public Variable getVariable(String name) {
126 return (Variable)variables.get(name);
127 }
128
129 public Object getValue(String name) {
130 Variable var = getVariable(name);
131 return var != null ? var.getValue() : null;
132 }
133
134 public void setValue(String name, Object value) {
135 Variable var = getVariable(name);
136 if (var != null) var.setValue(value);
137 }
138
139
140
141
142 public void save(XMLIOManager xmlioManager,
143 org.jdom.Element nodeEl) {
144
145
146
147
148
149
150
151
152
153
154
155
156 }
157
158 public void restore(XMLIOManager xmlioManager,
159 org.jdom.Element nodeEl) {
160
161
162
163
164
165
166
167
168
169
170
171 }
172 }