-
Notifications
You must be signed in to change notification settings - Fork 73
Expand file tree
/
Copy pathChartsController.java
More file actions
239 lines (176 loc) · 7.46 KB
/
Copy pathChartsController.java
File metadata and controls
239 lines (176 loc) · 7.46 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
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ChartsController {
private static List<PositionedChart> charts = Collections.synchronizedList(new ArrayList<PositionedChart>());
private static float dpiScalingFactorJava8 = (int) Math.round((double) Toolkit.getDefaultToolkit().getScreenResolution() / 100.0); // will be reset to 1.0 if using java 9+
private static float dpiScalingFactorJava9 = 1; // will be updated dynamically if using java 9+
private static float dpiScalingFactorUser = 1; // may be updated by the user
/**
* @return The display scaling factor. This takes into account the true DPI scaling requested by the OS, plus the user's modification (if any.)
*/
public static float getDisplayScalingFactor() {
return dpiScalingFactorUser * dpiScalingFactorJava8 * dpiScalingFactorJava9;
}
/**
* @return The display scaling factor for GUI widgets.
*/
public static float getDisplayScalingFactorForGUI() {
return dpiScalingFactorJava8 * dpiScalingFactorJava9;
}
/**
* @return The display scaling factor requested by the user.
*/
public static float getDisplayScalingFactorUser() {
return dpiScalingFactorUser;
}
/**
* @param newFactor The new display scaling factor specified by the user.
*/
public static void setDisplayScalingFactorUser(float newFactor) {
if(newFactor < 1) newFactor = 1;
if(newFactor > 10) newFactor = 10;
dpiScalingFactorUser = newFactor;
}
/**
* @param newFactor The new display scaling factor specified by the OS if using Java 9+.
*/
public static void setDisplayScalingFactorJava9(float newFactor) {
if(newFactor == dpiScalingFactorJava9)
return;
if(newFactor < 1) newFactor = 1;
if(newFactor > 10) newFactor = 10;
dpiScalingFactorJava9 = newFactor;
dpiScalingFactorJava8 = 1; // only use the Java9 scaling factor
}
/**
* @return An array of Strings, one for each possible chart type.
*/
public static String[] getChartTypes() {
return new String[] {
"Time Domain",
"Frequency Domain",
"Histogram",
"Statistics",
"Dial",
"Quaternion",
"Camera",
"Timeline",
"Acceleration"
};
}
/**
* Creates a PositionedChart and adds it to the charts list.
*
* @param chartType One of the Strings from Controller.getChartTypes()
* @param x1 The x-coordinate of a bounding-box corner in the OpenGLChartsRegion grid.
* @param y1 The y-coordinate of a bounding-box corner in the OpenGLChartsRegion grid.
* @param x2 The x-coordinate of the opposite bounding-box corner in the OpenGLChartsRegion grid.
* @param y2 The x-coordinate of the opposite bounding-box corner in the OpenGLChartsRegion grid.
* @return That chart, or null if chartType is invalid.
*/
public static PositionedChart createAndAddChart(String chartType, int x1, int y1, int x2, int y2) {
PositionedChart chart = null;
if(chartType.equals("Time Domain")) chart = new OpenGLTimeDomainChart(x1, y1, x2, y2);
else if(chartType.equals("Frequency Domain")) chart = new OpenGLFrequencyDomainChart(x1, y1, x2, y2);
else if(chartType.equals("Histogram")) chart = new OpenGLHistogramChart(x1, y1, x2, y2);
else if(chartType.equals("Statistics")) chart = new OpenGLStatisticsChart(x1, y1, x2, y2);
else if(chartType.equals("Dial")) chart = new OpenGLDialChart(x1, y1, x2, y2);
else if(chartType.equals("Quaternion")) chart = new OpenGLQuaternionChart(x1, y1, x2, y2);
else if(chartType.equals("Camera")) chart = new OpenGLCameraChart(x1, y1, x2, y2);
else if(chartType.equals("Timeline")) chart = new OpenGLTimelineChart(x1, y1, x2, y2);
else if(chartType.equals("Acceleration")) chart = new OpenGLAccelerationChart(x1, y1, x2, y2);
if(chart != null)
ChartsController.addChart(chart);
return chart;
}
/**
* @param chart New chart to insert and display.
*/
public static void addChart(PositionedChart chart) {
charts.add(chart);
updateTileOccupancy(null);
}
/**
* Reorders the list of charts so the specified chart will be rendered after all other charts.
*
* @param chart The chart to render last.
*/
public static void drawChartLast(PositionedChart chart) {
if(charts.size() < 2)
return;
Collections.swap(charts, charts.indexOf(chart), charts.size() - 1);
}
/**
* Removes a specific chart.
*
* @param chart Chart to remove.
*/
public static void removeChart(PositionedChart chart) {
ConfigureView.instance.closeIfUsedFor(chart);
chart.dispose();
charts.remove(chart);
updateTileOccupancy(null);
}
/**
* Removes all charts.
*/
public static void removeAllCharts() {
// many a temporary copy of the list because you can't remove from a list that you are iterating over
List<PositionedChart> list = new ArrayList<PositionedChart>(charts);
for(PositionedChart chart : list)
removeChart(chart);
}
/**
* @return All charts.
*/
public static List<PositionedChart> getCharts() {
return charts;
}
/**
* Checks if a region is available in the ChartsRegion.
*
* @param x1 The x-coordinate of a bounding-box corner in the OpenGLChartsRegion grid.
* @param y1 The y-coordinate of a bounding-box corner in the OpenGLChartsRegion grid.
* @param x2 The x-coordinate of the opposite bounding-box corner in the OpenGLChartsRegion grid.
* @param y2 The y-coordinate of the opposite bounding-box corner in the OpenGLChartsRegion grid.
* @return True if available, false if not.
*/
public static boolean gridRegionAvailable(int x1, int y1, int x2, int y2) {
int topLeftX = x1 < x2 ? x1 : x2;
int topLeftY = y1 < y2 ? y1 : y2;
int bottomRightX = x2 > x1 ? x2 : x1;
int bottomRightY = y2 > y1 ? y2 : y1;
for(PositionedChart chart : charts)
if(chart.regionOccupied(topLeftX, topLeftY, bottomRightX, bottomRightY))
return false;
return true;
}
private static boolean[][] tileOccupied = new boolean[SettingsController.getTileColumns()][SettingsController.getTileRows()];
/**
* Updates the array that tracks which tiles in the OpenGLChartsRegion are occupied by charts.
*
* @param removingChart If not null, pretend this chart does not exist, so the tiles behind it will be drawn while this chart fades away.
*/
public static void updateTileOccupancy(PositionedChart removingChart) {
int columns = SettingsController.getTileColumns();
int rows = SettingsController.getTileRows();
tileOccupied = new boolean[columns][rows];
for(PositionedChart chart : getCharts()) {
for(int x = chart.topLeftX; x <= chart.bottomRightX; x++)
for(int y = chart.topLeftY; y <= chart.bottomRightY; y++)
tileOccupied[x][rows - y - 1] = true;
}
if(removingChart != null)
for(int x = removingChart.topLeftX; x <= removingChart.bottomRightX; x++)
for(int y = removingChart.topLeftY; y <= removingChart.bottomRightY; y++)
tileOccupied[x][rows - y - 1] = false;
}
/**
* @return An array indicating which tiles in the OpenGLChartsRegion are occupied.
*/
public static boolean[][] getTileOccupancy() {
return tileOccupied;
}
}