-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathCellLattice.java
More file actions
251 lines (209 loc) · 6.44 KB
/
CellLattice.java
File metadata and controls
251 lines (209 loc) · 6.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
* Open Source Physics software is free software as described near the bottom of this code file.
*
* For additional information and documentation on Open Source Physics please see:
* <http://www.opensourcephysics.org/>
*/
package org.opensourcephysics.display2d;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import org.opensourcephysics.display.DrawingPanel;
/**
* A CellLattice that displays an array where each array element can assume one of 256
* values.
*
* Values can be set between -128 and 127. Because byte values larger
* than 127 overflow to negative, values can also be set between 0 and 255. The
* lattice is drawn as an array of rectangles to distinguish between the two
* possible values.
*
* @author Wolfgang Christian
* @created July 3, 2005
* @version 1.0
*/
public class CellLattice implements ByteLattice {
ByteLattice lattice = null;
static String osName;
static {
try {
osName = System.getProperty("os.name", ""); //$NON-NLS-1$ //$NON-NLS-2$
} catch(Exception ex) {
osName = ""; //$NON-NLS-1$
}
}
/**
* Constructor CellLattice
*/
public CellLattice() {
if(osName.indexOf("Mac")>-1) { //$NON-NLS-1$
lattice = new CellLatticeOSX();
} else {
lattice = new CellLatticePC();
}
}
/**
* Constructor CellLattice
* @param nx
* @param ny
*/
public CellLattice(int nx, int ny) {
if(osName.indexOf("Mac")>-1) { //$NON-NLS-1$
lattice = new CellLatticeOSX(nx, ny);
} else {
lattice = new CellLatticePC(nx, ny);
}
}
public double getXMin() {
return lattice.getXMin();
}
public double getXMax() {
return lattice.getXMax();
}
public double getYMin() {
return lattice.getYMin();
}
public double getYMax() {
return lattice.getYMax();
}
public boolean isMeasured() {
return lattice.isMeasured();
}
public void draw(DrawingPanel panel, Graphics g) {
lattice.draw(panel, g);
}
public int getNx() {
return lattice.getNx();
}
public int getNy() {
return lattice.getNy();
}
public int indexFromPoint(double x, double y) {
return lattice.indexFromPoint(x, y);
}
public int xToIndex(double x) {
return lattice.xToIndex(x);
}
public int yToIndex(double y) {
return lattice.yToIndex(y);
}
public byte getValue(int ix, int iy) {
return lattice.getValue(ix, iy);
}
public void setValue(int ix, int iy, byte val) {
lattice.setValue(ix, iy, val);
}
public void randomize() {
lattice.randomize();
}
public void resizeLattice(int nx, int ny) {
lattice.resizeLattice(nx, ny);
}
/**
* Sets the lattice values and scale.
*
* The lattice is resized to fit the new data if needed.
*
* @param val int[][] the new values
* @param xmin double
* @param xmax double
* @param ymin double
* @param ymax double
*/
public void setAll(byte val[][], double xmin, double xmax, double ymin, double ymax) {
lattice.setAll(val, xmin, xmax, ymin, ymax);
}
public void setBlock(int ix_offset, int iy_offset, byte[][] val) {
lattice.setBlock(ix_offset, iy_offset, val);
}
public void setBlock(byte[][] val) {
lattice.setBlock(val);
}
public void setCol(int ix, int iy_offset, byte[] val) {
lattice.setCol(ix, iy_offset, val);
}
public void setRow(int iy, int ix_offset, byte[] val) {
lattice.setRow(iy, ix_offset, val);
}
public void setShowGridLines(boolean show) {
lattice.setShowGridLines(show);
}
public void setGridLineColor(Color c) {
lattice.setGridLineColor(c);
}
public JFrame showLegend() {
return lattice.showLegend();
}
public void setVisible(boolean isVisible) {
lattice.setVisible(isVisible);
}
public void setColorPalette(Color[] colors) {
lattice.setColorPalette(colors);
}
public void setIndexedColor(int i, Color color) {
lattice.setIndexedColor(i, color);
}
public void setMinMax(double xmin, double xmax, double ymin, double ymax) {
lattice.setMinMax(xmin, xmax, ymin, ymax);
}
/**
* Creates a new SiteLattice containing the same data as this lattice.
*/
public SiteLattice createSiteLattice() {
if(osName.indexOf("Mac")>-1) { //$NON-NLS-1$
return((CellLatticeOSX) lattice).createSiteLattice();
}
return((CellLatticePC) lattice).createSiteLattice();
}
/**
* Sets a block of cells using integer values.
*
* @param ix_offset int
* @param iy_offset int
* @param val int[][]
*/
public void setBlock(int ix_offset, int iy_offset, int val[][]) {
if(osName.indexOf("Mac")>-1) { //$NON-NLS-1$
((CellLatticeOSX) lattice).setBlock(ix_offset, iy_offset, val);
} else {
((CellLatticePC) lattice).setBlock(ix_offset, iy_offset, val);
}
}
public void setXMin(double xmin) {
lattice.setXMin(xmin);
}
public void setXMax(double xmax) {
lattice.setXMax(xmax);
}
public void setYMin(double ymin) {
lattice.setYMin(ymin);
}
public void setYMax(double ymax) {
lattice.setYMax(ymax);
}
public void createDefaultColors() {
lattice.createDefaultColors();
}
}
/*
* Open Source Physics software is free software; you can redistribute
* it and/or modify it under the terms of the GNU General Public License (GPL) as
* published by the Free Software Foundation; either version 2 of the License,
* or(at your option) any later version.
* Code that uses any portion of the code in the org.opensourcephysics package
* or any subpackage (subdirectory) of this package must must also be be released
* under the GNU GPL license.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston MA 02111-1307 USA
* or view the license online at http://www.gnu.org/copyleft/gpl.html
*
* Copyright (c) 2007 The Open Source Physics project
* http://www.opensourcephysics.org
*/