1 | package com.ether; |
---|
2 | |
---|
3 | import gov.noaa.pmel.sgt.CartesianGraph; |
---|
4 | import gov.noaa.pmel.sgt.ColorMap; |
---|
5 | import gov.noaa.pmel.sgt.ContourLevels; |
---|
6 | import gov.noaa.pmel.sgt.Graph; |
---|
7 | import gov.noaa.pmel.sgt.GridAttribute; |
---|
8 | import gov.noaa.pmel.sgt.IndexedColorMap; |
---|
9 | import gov.noaa.pmel.sgt.JPane; |
---|
10 | import gov.noaa.pmel.sgt.Layer; |
---|
11 | import gov.noaa.pmel.sgt.LineAttribute; |
---|
12 | import gov.noaa.pmel.sgt.LineCartesianRenderer; |
---|
13 | import gov.noaa.pmel.sgt.LineKey; |
---|
14 | import gov.noaa.pmel.sgt.LinearTransform; |
---|
15 | import gov.noaa.pmel.sgt.PlainAxis; |
---|
16 | import gov.noaa.pmel.sgt.SGLabel; |
---|
17 | import gov.noaa.pmel.sgt.StackedLayout; |
---|
18 | import gov.noaa.pmel.sgt.TimeAxis; |
---|
19 | import gov.noaa.pmel.sgt.demo.TestData; |
---|
20 | import gov.noaa.pmel.sgt.dm.SGTData; |
---|
21 | import gov.noaa.pmel.sgt.dm.SGTMetaData; |
---|
22 | import gov.noaa.pmel.sgt.dm.SimpleGrid; |
---|
23 | import gov.noaa.pmel.sgt.dm.SimpleLine; |
---|
24 | import gov.noaa.pmel.sgt.swing.JPlotLayout; |
---|
25 | import gov.noaa.pmel.util.Dimension2D; |
---|
26 | import gov.noaa.pmel.util.GeoDate; |
---|
27 | import gov.noaa.pmel.util.GeoDateArray; |
---|
28 | import gov.noaa.pmel.util.IllegalTimeValue; |
---|
29 | import gov.noaa.pmel.util.Point2D; |
---|
30 | import gov.noaa.pmel.util.Range2D; |
---|
31 | import gov.noaa.pmel.util.SoTPoint; |
---|
32 | import gov.noaa.pmel.util.SoTRange; |
---|
33 | import gov.noaa.pmel.util.TimeRange; |
---|
34 | import org.jetbrains.annotations.NotNull; |
---|
35 | import org.jetbrains.annotations.Nullable; |
---|
36 | |
---|
37 | import javax.swing.*; |
---|
38 | import javax.swing.border.EtchedBorder; |
---|
39 | import java.awt.*; |
---|
40 | import java.util.Date; |
---|
41 | import java.util.Locale; |
---|
42 | import java.util.ResourceBundle; |
---|
43 | |
---|
44 | public class EtherPlotContentServiceImpl |
---|
45 | { |
---|
46 | /** |
---|
47 | * First layer contains axes, labels and the first set of data |
---|
48 | * Others layers contains only the other sets of data |
---|
49 | * |
---|
50 | * @param megapoliPlot |
---|
51 | * @return |
---|
52 | */ |
---|
53 | @NotNull |
---|
54 | public JPane createTimeSeriePlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight ) |
---|
55 | { |
---|
56 | final JPane mainPane = new JPane( "Time Serie Pane", new Dimension( plotWidth, plotHeight ) ); |
---|
57 | mainPane.setLayout( new StackedLayout() ); |
---|
58 | mainPane.setBorder( BorderFactory.createLineBorder( Color.pink ) ); |
---|
59 | |
---|
60 | /** ***************************** **/ |
---|
61 | /** *********** LINES ************ **/ |
---|
62 | /** ***************************** **/ |
---|
63 | final double[] dataArray = (double[]) megapoliPlot.getData().getFirstArray(); |
---|
64 | final Date[] dateValues = (Date[]) megapoliPlot.getData().getSecondArray(); |
---|
65 | |
---|
66 | final SimpleLine line0 = new SimpleLine( new GeoDateArray( dateValues ), dataArray, "legend" ); |
---|
67 | SGTMetaData meta = new SGTMetaData( "", "", false, false ); |
---|
68 | line0.setXMetaData( meta ); |
---|
69 | |
---|
70 | meta = new SGTMetaData( megapoliPlot.getParameterName(), megapoliPlot.getParameterUnitCode(), false, false ); |
---|
71 | line0.setYMetaData( meta ); |
---|
72 | |
---|
73 | |
---|
74 | SimpleLine line; |
---|
75 | GeoDate start = null; |
---|
76 | GeoDate stop = null; |
---|
77 | TimeRange tr; |
---|
78 | TestData td; |
---|
79 | try |
---|
80 | { |
---|
81 | start = new GeoDate( "1992-11-01", "yyyy-MM-dd" ); |
---|
82 | stop = new GeoDate( "1993-02-20", "yyyy-MM-dd" ); |
---|
83 | } |
---|
84 | catch( IllegalTimeValue e ) |
---|
85 | { |
---|
86 | } |
---|
87 | tr = new TimeRange( start, stop ); |
---|
88 | td = new TestData( TestData.TIME_SERIES, tr, 1.0f, |
---|
89 | TestData.RANDOM, 1.2f, 0.5f, 30.0f ); |
---|
90 | line = (SimpleLine) td.getSGTData(); |
---|
91 | |
---|
92 | |
---|
93 | /** ***************************** **/ |
---|
94 | /** *********** AXIS ************ **/ |
---|
95 | /** ***************************** **/ |
---|
96 | final SoTRange ynRange; |
---|
97 | final SoTRange yRange; |
---|
98 | final SoTRange tnRange; |
---|
99 | final String yLabel; |
---|
100 | yRange = line.getYRange(); |
---|
101 | // yRange.add( line2.getYRange() ); |
---|
102 | tnRange = line.getXRange(); |
---|
103 | final Integer intervalsNumber = 10; |
---|
104 | ynRange = Graph.computeRange( yRange, intervalsNumber ); |
---|
105 | yLabel = line.getYMetaData().getName(); |
---|
106 | |
---|
107 | |
---|
108 | /** ***************************** **/ |
---|
109 | /** *********** LAYERS ********** **/ |
---|
110 | /** ***************************** **/ |
---|
111 | /* |
---|
112 | * xsize, ysize are the width and height in physical units |
---|
113 | * of the Layer graphics region. |
---|
114 | * |
---|
115 | * xstart, xend are the start and end points for the TimeAxis |
---|
116 | * ystart, yend are the start and end points for the Y axis |
---|
117 | */ |
---|
118 | final double xsize = 4.0; |
---|
119 | final double xstart = 0.6; |
---|
120 | final double xend = 3.25; |
---|
121 | final double ysize = 4.0; |
---|
122 | final double ystart = 0.6; |
---|
123 | final double yend = 2.50; |
---|
124 | |
---|
125 | Layer layer2; |
---|
126 | SGLabel label, title, ytitle; |
---|
127 | CartesianGraph graph, graph2; |
---|
128 | LinearTransform xt, yt; |
---|
129 | PlainAxis yleft; |
---|
130 | TimeAxis xbot; |
---|
131 | LineKey lkey; |
---|
132 | GeoDate stime; |
---|
133 | |
---|
134 | final Layer layer = new Layer( "First Layer", new Dimension2D( xsize, ysize ) ); |
---|
135 | |
---|
136 | /** ***************************** **/ |
---|
137 | /** *********** LEGENDS ********* **/ |
---|
138 | /** ***************************** **/ |
---|
139 | /* |
---|
140 | * create a LineKey |
---|
141 | * the LineKey will be a legend for the two lines created |
---|
142 | * position the key in the upper right corner |
---|
143 | * and add to the first layer |
---|
144 | */ |
---|
145 | lkey = new LineKey(); |
---|
146 | lkey.setId( "Legend" ); |
---|
147 | lkey.setLocationP( new Point2D.Double( xsize - 1, ysize - 1 ) ); |
---|
148 | lkey.setVAlign( LineKey.TOP ); |
---|
149 | lkey.setHAlign( LineKey.RIGHT ); |
---|
150 | layer.addChild( lkey ); |
---|
151 | /* |
---|
152 | * add the first layer to the Pane |
---|
153 | */ |
---|
154 | mainPane.add( layer ); |
---|
155 | /* |
---|
156 | * create first CartesianGraph and transforms |
---|
157 | */ |
---|
158 | graph = new CartesianGraph( "First Graph" ); |
---|
159 | xt = new LinearTransform( new Range2D( xstart, xend ), tnRange ); |
---|
160 | graph.setXTransform( xt ); |
---|
161 | yt = new LinearTransform( new Range2D( ystart, yend ), ynRange ); |
---|
162 | graph.setYTransform( yt ); |
---|
163 | /* |
---|
164 | * Create the time axis, set its range in user units |
---|
165 | * and its origin. Add the axis to the first graph. |
---|
166 | */ |
---|
167 | SoTPoint point = new SoTPoint( ynRange.getStart(), tnRange.getStart() ); |
---|
168 | xbot = new TimeAxis( "Bottom Axis", TimeAxis.MONTH_YEAR ); |
---|
169 | xbot.setRangeU( tnRange ); |
---|
170 | xbot.setLocationU( point ); |
---|
171 | Font xbfont = new Font( "Helvetica", Font.ITALIC, 14 ); |
---|
172 | xbot.setLabelFont( xbfont ); |
---|
173 | xbot.setMinorLabelInterval( 1 ); |
---|
174 | graph.addXAxis( xbot ); |
---|
175 | /* |
---|
176 | * Create the vertical axis, set its range in user units |
---|
177 | * and its origin. Create the axis title and add the |
---|
178 | * axis to the first graph. |
---|
179 | */ |
---|
180 | yleft = new PlainAxis( "Left Axis" ); |
---|
181 | yleft.setRangeU( ynRange ); |
---|
182 | yleft.setLocationU( point ); |
---|
183 | yleft.setLabelFont( xbfont ); |
---|
184 | ytitle = new SGLabel( "Y-Axis Title", yLabel, |
---|
185 | new Point2D.Double( 0.0, 0.0 ) ); |
---|
186 | Font ytfont = new Font( "Helvetica", Font.PLAIN, 14 ); |
---|
187 | ytitle.setFont( ytfont ); |
---|
188 | ytitle.setHeightP( 0.2 ); |
---|
189 | yleft.setTitle( ytitle ); |
---|
190 | graph.addYAxis( yleft ); |
---|
191 | /* |
---|
192 | * Add the first graph to the first layer. |
---|
193 | */ |
---|
194 | layer.setGraph( graph ); |
---|
195 | /* |
---|
196 | * Create a LineAttribute for the display of the first |
---|
197 | * line. Associate the attribute and the line with the |
---|
198 | * first graph. Add the line to the LineKey. |
---|
199 | */ |
---|
200 | LineAttribute attr; |
---|
201 | |
---|
202 | attr = new LineAttribute( LineAttribute.MARK, 20, Color.red ); |
---|
203 | attr.setMarkHeightP( 0.1 ); |
---|
204 | graph.setData( line, attr ); |
---|
205 | lkey.addLineGraph( (LineCartesianRenderer) graph.getRenderer(), |
---|
206 | new SGLabel( "1st line", "Red Data", |
---|
207 | new Point2D.Double( 0.0, 0.0 ) ) ); |
---|
208 | /* |
---|
209 | * Create the second layer and add it the the Pane. |
---|
210 | * Create the second graph and associate it with the |
---|
211 | * second layer. |
---|
212 | */ |
---|
213 | // layer2 = new Layer( "Second Layer", new Dimension2D( xsize, ysize ) ); |
---|
214 | // mainPane.add( layer2 ); |
---|
215 | // graph2 = new CartesianGraph( "Second Graph", xt, yt ); |
---|
216 | // layer2.setGraph( graph2 ); |
---|
217 | /* |
---|
218 | * Create a LineAttribute for the display of the second |
---|
219 | * line. Associate the attribute and the line with the |
---|
220 | * second graph. Add the line to the LineKey. |
---|
221 | */ |
---|
222 | // LineAttribute attr2; |
---|
223 | // attr2 = new LineAttribute( LineAttribute.MARK, 2, Color.blue ); |
---|
224 | // attr2.setMarkHeightP( 0.1 ); |
---|
225 | // graph2.setData( line2, attr2 ); |
---|
226 | // lkey.addLineGraph( (LineCartesianRenderer) graph2.getRenderer(), |
---|
227 | // new SGLabel( "2nd line", "Blue Data", |
---|
228 | // new Point2D.Double( 0.0, 0.0 ) ) ); |
---|
229 | |
---|
230 | return mainPane; |
---|
231 | } |
---|
232 | |
---|
233 | @NotNull |
---|
234 | public JPane create2DPlot( @NotNull final MegapoliPlot megapoliPlot, @NotNull final Integer plotWidth, @NotNull final Integer plotHeight ) |
---|
235 | { |
---|
236 | /* |
---|
237 | * This example uses a pre-created "Layout" for raster time |
---|
238 | * series to simplify the construction of a plot. The |
---|
239 | * JPlotLayout can plot a single grid with |
---|
240 | * a ColorKey, time series with a LineKey, point collection with a |
---|
241 | * PointCollectionKey, and general X-Y plots with a |
---|
242 | * LineKey. JPlotLayout supports zooming, object selection, and |
---|
243 | * object editing. |
---|
244 | */ |
---|
245 | SGTData newData; |
---|
246 | TestData td; |
---|
247 | JPlotLayout rpl; |
---|
248 | ContourLevels clevels; |
---|
249 | /* |
---|
250 | * Create a test grid with sinasoidal-ramp data. |
---|
251 | */ |
---|
252 | Range2D xr = new Range2D( 190.0f, 250.0f, 1.0f ); |
---|
253 | Range2D yr = new Range2D( 0.0f, 45.0f, 1.0f ); |
---|
254 | td = new TestData( TestData.XY_GRID, xr, yr, |
---|
255 | TestData.SINE_RAMP, 12.0f, 30.f, 5.0f ); |
---|
256 | newData = td.getSGTData(); |
---|
257 | /* |
---|
258 | * Create the layout without a Logo image and with the |
---|
259 | * ColorKey on a separate Pane object. |
---|
260 | */ |
---|
261 | rpl = new JPlotLayout( true, false, false, "JGridDemo Pane", null, true ); |
---|
262 | rpl.setEditClasses( false ); |
---|
263 | /* |
---|
264 | * Create a GridAttribute for CONTOUR style. |
---|
265 | */ |
---|
266 | Range2D datar = new Range2D( -20.0f, 45.0f, 5.0f ); |
---|
267 | clevels = ContourLevels.getDefault( datar ); |
---|
268 | GridAttribute gridAttr_ = new GridAttribute( clevels ); |
---|
269 | /* |
---|
270 | * Create a ColorMap and change the style to RASTER_CONTOUR. |
---|
271 | */ |
---|
272 | ColorMap cmap = createColorMap( datar ); |
---|
273 | gridAttr_.setColorMap( cmap ); |
---|
274 | gridAttr_.setStyle( GridAttribute.RASTER_CONTOUR ); |
---|
275 | /* |
---|
276 | * Add the grid to the layout and give a label for |
---|
277 | * the ColorKey. |
---|
278 | */ |
---|
279 | rpl.addData( newData, gridAttr_, "First Data" ); |
---|
280 | /* |
---|
281 | * Change the layout's three title lines. |
---|
282 | */ |
---|
283 | rpl.setTitles( "Raster Plot Demo", |
---|
284 | "using a JPlotLayout", |
---|
285 | "" ); |
---|
286 | /* |
---|
287 | * Resize the graph and place in the "Center" of the frame. |
---|
288 | */ |
---|
289 | rpl.setSize( new Dimension( 600, 400 ) ); |
---|
290 | /* |
---|
291 | * Resize the key Pane, both the device size and the physical |
---|
292 | * size. Set the size of the key in physical units and place |
---|
293 | * the key pane at the "South" of the frame. |
---|
294 | */ |
---|
295 | // rpl.setKeyLayerSizeP(new Dimension2D(6.0, 1.02)); |
---|
296 | // rpl.setKeyBoundsP(new Rectangle2D.Double(0.01, 1.01, 5.98, 1.0)); |
---|
297 | |
---|
298 | return rpl; |
---|
299 | } |
---|
300 | |
---|
301 | @NotNull |
---|
302 | public JPanel createControlPanel() |
---|
303 | { |
---|
304 | final JPanel controlPanel = new JPanel(); |
---|
305 | final ButtonGroup gridtype = new ButtonGroup(); |
---|
306 | final JCheckBox stacked = new JCheckBox(); |
---|
307 | final JCheckBox grid = new JCheckBox(); |
---|
308 | |
---|
309 | controlPanel.setLayout( new GridBagLayout() ); |
---|
310 | // controlPanel.setBackground(new java.awt.Color(200,200,200)); |
---|
311 | controlPanel.setBounds( 0, 679, 426, 33 ); |
---|
312 | controlPanel.setBorder( new EtchedBorder() ); |
---|
313 | gridtype.add( stacked ); |
---|
314 | stacked.setSelected( true ); |
---|
315 | stacked.setText( "Overlayed" ); |
---|
316 | |
---|
317 | GridBagConstraints gbc = new GridBagConstraints(); |
---|
318 | gbc.gridx = 0; |
---|
319 | gbc.gridy = 0; |
---|
320 | gbc.gridwidth = 1; |
---|
321 | gbc.gridheight = 1; |
---|
322 | gbc.weightx = 0.0; |
---|
323 | gbc.weighty = 1.0; |
---|
324 | gbc.anchor = GridBagConstraints.EAST; |
---|
325 | gbc.fill = GridBagConstraints.BOTH; |
---|
326 | gbc.insets = new Insets( 5, 15, 5, 5 ); |
---|
327 | gbc.ipadx = 0; |
---|
328 | gbc.ipady = 0; |
---|
329 | controlPanel.add( stacked, gbc ); |
---|
330 | stacked.setBounds( 15, 5, 84, 23 ); |
---|
331 | gridtype.add( grid ); |
---|
332 | grid.setText( "Grid" ); |
---|
333 | |
---|
334 | gbc.gridx = 1; |
---|
335 | gbc.gridy = 0; |
---|
336 | gbc.gridwidth = 1; |
---|
337 | gbc.gridheight = 1; |
---|
338 | gbc.weightx = 0.5; |
---|
339 | gbc.weighty = 1.0; |
---|
340 | gbc.anchor = GridBagConstraints.WEST; |
---|
341 | gbc.fill = GridBagConstraints.VERTICAL; |
---|
342 | gbc.insets = new Insets( 5, 5, 5, 0 ); |
---|
343 | gbc.ipadx = 0; |
---|
344 | gbc.ipady = 0; |
---|
345 | controlPanel.add( grid, gbc ); |
---|
346 | grid.setBounds( 109, 5, 53, 23 ); |
---|
347 | final JButton showTree = new JButton(); |
---|
348 | showTree.setText( "Show Class Tree" ); |
---|
349 | |
---|
350 | gbc.gridx = 2; |
---|
351 | gbc.gridy = 0; |
---|
352 | gbc.gridwidth = 1; |
---|
353 | gbc.gridheight = 1; |
---|
354 | gbc.weightx = 1.0; |
---|
355 | gbc.weighty = 1.0; |
---|
356 | gbc.anchor = GridBagConstraints.EAST; |
---|
357 | gbc.fill = GridBagConstraints.VERTICAL; |
---|
358 | gbc.insets = new Insets( 5, 5, 5, 15 ); |
---|
359 | gbc.ipadx = 0; |
---|
360 | gbc.ipady = 0; |
---|
361 | controlPanel.add( showTree, gbc ); |
---|
362 | showTree.setBackground( Color.yellow.brighter() ); |
---|
363 | showTree.setBounds( 302, 5, 109, 23 ); |
---|
364 | |
---|
365 | final SymItem lSymItem = new SymItem( stacked, grid ); |
---|
366 | stacked.addItemListener( lSymItem ); |
---|
367 | grid.addItemListener( lSymItem ); |
---|
368 | // SymAction lSymAction = new SymAction(); |
---|
369 | // showTree.addActionListener( lSymAction ); |
---|
370 | |
---|
371 | return controlPanel; |
---|
372 | } |
---|
373 | |
---|
374 | /** |
---|
375 | * Change the Pane layout to StackedLayout. |
---|
376 | * |
---|
377 | * @param event |
---|
378 | */ |
---|
379 | |
---|
380 | void stacked_itemStateChanged( java.awt.event.ItemEvent event ) |
---|
381 | { |
---|
382 | /* |
---|
383 | * Get the component list for mainPane_ and change |
---|
384 | * the layout to StackedLayout. |
---|
385 | */ |
---|
386 | // Component[] comps = mainPane_.getComponents(); |
---|
387 | // mainPane_.setBatch( true ); |
---|
388 | // mainPane_.setLayout( new StackedLayout() ); |
---|
389 | // /* |
---|
390 | // * Remove any axes that have been associated with |
---|
391 | // * the second graph. With the layers overlayed it |
---|
392 | // * is not necessary to have duplicate axes. |
---|
393 | // */ |
---|
394 | // Graph gr2 = ( (Layer) comps[1] ).getGraph(); |
---|
395 | // ( (CartesianGraph) gr2 ).removeAllXAxes(); |
---|
396 | // ( (CartesianGraph) gr2 ).removeAllYAxes(); |
---|
397 | // /* |
---|
398 | // * Tell the Applet that the mainPane_ needs to |
---|
399 | // * be layed out and re-draw the mainPane_. |
---|
400 | // */ |
---|
401 | // if( isApplet_ ) |
---|
402 | // { |
---|
403 | // validate(); |
---|
404 | // } |
---|
405 | // else |
---|
406 | // { |
---|
407 | // frame.validate(); |
---|
408 | // } |
---|
409 | // mainPane_.setBatch( false ); |
---|
410 | // if( tree_ != null ) |
---|
411 | // { |
---|
412 | // if( tree_.isVisible() ) |
---|
413 | // { |
---|
414 | // tree_.setJPane( mainPane_ ); |
---|
415 | // tree_.expandTree(); |
---|
416 | // } |
---|
417 | // } |
---|
418 | } |
---|
419 | |
---|
420 | /** |
---|
421 | * Change the Pane layout to GridLayout. |
---|
422 | * |
---|
423 | * @param event |
---|
424 | */ |
---|
425 | |
---|
426 | void grid_itemStateChanged( java.awt.event.ItemEvent event ) |
---|
427 | { |
---|
428 | /* |
---|
429 | * Get the component list for mainPane_ and change |
---|
430 | * the layout to GridLayout. |
---|
431 | */ |
---|
432 | // Component[] comps = mainPane_.getComponents(); |
---|
433 | // mainPane_.setBatch( true ); |
---|
434 | // mainPane_.setLayout( new GridLayout( 2, 0 ) ); |
---|
435 | // /* |
---|
436 | // * Get the first and second graphs from the first |
---|
437 | // * and second layers, respectively. |
---|
438 | // */ |
---|
439 | // Graph gr = ( (Layer) comps[0] ).getGraph(); |
---|
440 | // Graph gr2 = ( (Layer) comps[1] ).getGraph(); |
---|
441 | // /* |
---|
442 | // * Create copies of all X-Axes associated with the first |
---|
443 | // * graph for the second graph. If the axes are not copied then |
---|
444 | // * the second graph will have the second line plotted, but without |
---|
445 | // * any axes. |
---|
446 | // */ |
---|
447 | // for( Enumeration xa = ( (CartesianGraph) gr ).xAxisElements(); xa.hasMoreElements(); ) |
---|
448 | // { |
---|
449 | // ( (CartesianGraph) gr2 ).addXAxis( ( (Axis) xa.nextElement() ).copy() ); |
---|
450 | // } |
---|
451 | // /* |
---|
452 | // * Create copies of all Y-Axes associated with the first |
---|
453 | // * graph for the second graph. |
---|
454 | // */ |
---|
455 | // for( Enumeration ya = ( (CartesianGraph) gr ).yAxisElements(); ya.hasMoreElements(); ) |
---|
456 | // { |
---|
457 | // ( (CartesianGraph) gr2 ).addYAxis( ( (Axis) ya.nextElement() ).copy() ); |
---|
458 | // } |
---|
459 | // /* |
---|
460 | // * Tell the Applet that the mainPane_ needs to |
---|
461 | // * be layed out and re-draw the mainPane_. |
---|
462 | // */ |
---|
463 | // if( isApplet_ ) |
---|
464 | // { |
---|
465 | // validate(); |
---|
466 | // } |
---|
467 | // else |
---|
468 | // { |
---|
469 | // frame.validate(); |
---|
470 | // } |
---|
471 | // // mainPane_.draw(); |
---|
472 | // mainPane_.setBatch( false ); |
---|
473 | // if( tree_ != null ) |
---|
474 | // { |
---|
475 | // if( tree_.isVisible() ) |
---|
476 | // { |
---|
477 | // tree_.setJPane( mainPane_ ); |
---|
478 | // tree_.expandTree(); |
---|
479 | // } |
---|
480 | // } |
---|
481 | } |
---|
482 | |
---|
483 | void showTree_ActionPerformed( java.awt.event.ActionEvent event ) |
---|
484 | { |
---|
485 | // /* |
---|
486 | // * Create the ClassTree dialog to display the classes used |
---|
487 | // * in the mainPane_ and allow editing. |
---|
488 | // */ |
---|
489 | // if( tree_ == null ) |
---|
490 | // { |
---|
491 | // tree_ = new JClassTree( "Classes for LayoutDemo" ); |
---|
492 | // } |
---|
493 | // tree_.setJPane( mainPane_ ); |
---|
494 | // tree_.show(); |
---|
495 | } |
---|
496 | |
---|
497 | @NotNull |
---|
498 | private JPlotLayout createJPlotLayoutFor2DOrig( final MegapoliPlot megapoliPlot, final Integer plotWidth, final Integer plotHeight, @Nullable final Locale locale ) |
---|
499 | { |
---|
500 | final ResourceBundle bundle = WebHelper.getBundle( locale ); |
---|
501 | |
---|
502 | final double[] parameterArray = (double[]) megapoliPlot.getData().getFirstArray(); |
---|
503 | final double[] latitudeArray = (double[]) megapoliPlot.getData().getSecondArray(); |
---|
504 | final double[] longitudeValues = (double[]) megapoliPlot.getData().getThirdArray(); |
---|
505 | |
---|
506 | // final SimpleLine data = new SimpleLine( longitudeValues, latitudeArray, "legend" ); |
---|
507 | final SimpleGrid data = new SimpleGrid( parameterArray, longitudeValues, latitudeArray, "Test Series" ); |
---|
508 | SGTMetaData meta = new SGTMetaData( bundle.getString( "plot.longitude" ), bundle.getString( "plot.degres" ), false, true ); |
---|
509 | // TODO : vérifier modulo = 360 |
---|
510 | // meta.setModuloValue( 360 ); |
---|
511 | data.setXMetaData( meta ); |
---|
512 | |
---|
513 | meta = new SGTMetaData( bundle.getString( "plot.latitude" ), bundle.getString( "plot.degres" ), false, true ); |
---|
514 | // TODO : vérifier modulo = 360 |
---|
515 | // meta.setModuloValue( 360 ); |
---|
516 | data.setYMetaData( meta ); |
---|
517 | |
---|
518 | // Graph |
---|
519 | final JPlotLayout jPlotLayout = new JPlotLayout( true, false, false, "JGridDemo Pane", null, true ); |
---|
520 | jPlotLayout.setEditClasses( false ); |
---|
521 | /* |
---|
522 | * Create a GridAttribute for CONTOUR style. |
---|
523 | */ |
---|
524 | final Range2D datar = new Range2D( -20.0f, 45.0f, 5.0f ); |
---|
525 | final ContourLevels clevels = ContourLevels.getDefault( datar ); |
---|
526 | final GridAttribute gridAttr = new GridAttribute( clevels ); |
---|
527 | /* |
---|
528 | * Create a ColorMap and change the style to RASTER_CONTOUR. |
---|
529 | */ |
---|
530 | final ColorMap cmap = createColorMap( datar ); |
---|
531 | gridAttr.setColorMap( cmap ); |
---|
532 | gridAttr.setStyle( GridAttribute.RASTER_CONTOUR ); |
---|
533 | /* |
---|
534 | * Add the grid to the layout and give a label for |
---|
535 | * the ColorKey. |
---|
536 | */ |
---|
537 | jPlotLayout.addData( data, gridAttr, "First Data" ); |
---|
538 | |
---|
539 | // final JPlotLayoutEther jPlotLayout = new JPlotLayoutEther( false, megapoliPlot.isXTime(), false, "Trajectory data", null, megapoliPlot.isLegendToHide() ); |
---|
540 | // jPlotLayout.setTitles( "", "", "" ); |
---|
541 | |
---|
542 | // Replace legend |
---|
543 | // final String legend = megapoliPlot.getData().getTitle(); |
---|
544 | // final Dimension2D layerSizeP = jPlotLayout.getLayerSizeP(); |
---|
545 | // final double factorForPlotWidthInPhysicalUnits = layerSizeP.getWidth() / Double.valueOf( plotWidth ); |
---|
546 | // final double legendSizeInPhysicalUnits = legend.length() * factorForPlotWidthInPhysicalUnits * 7; |
---|
547 | // jPlotLayout.setKeyLocationP( new Point2D.Double( layerSizeP.getWidth() - legendSizeInPhysicalUnits, layerSizeP.getHeight() - 0.1 ) ); |
---|
548 | |
---|
549 | // Add data and legend |
---|
550 | // jPlotLayout.addData( megapoliPlot.getData(), legend ); |
---|
551 | jPlotLayout.setSize( plotWidth, plotHeight ); |
---|
552 | jPlotLayout.setVisible( true ); |
---|
553 | |
---|
554 | jPlotLayout.addNotify(); |
---|
555 | jPlotLayout.validate(); |
---|
556 | jPlotLayout.setOpaque( true ); |
---|
557 | return jPlotLayout; |
---|
558 | } |
---|
559 | |
---|
560 | @NotNull |
---|
561 | protected String formatTitle( @Nullable final String title ) |
---|
562 | { |
---|
563 | if( null == title ) |
---|
564 | return ""; |
---|
565 | else |
---|
566 | { |
---|
567 | final String formatTitle = title.replaceAll( "\\n", "<br>" ); |
---|
568 | return "<html>" + formatTitle + "</html>"; |
---|
569 | } |
---|
570 | } |
---|
571 | |
---|
572 | @NotNull |
---|
573 | private ColorMap createColorMap( final Range2D datar ) |
---|
574 | { |
---|
575 | final int[] red = |
---|
576 | {0, 0, 0, 0, 0, 0, 0, 0, |
---|
577 | 0, 0, 0, 0, 0, 0, 0, 0, |
---|
578 | 0, 0, 0, 0, 0, 0, 0, 0, |
---|
579 | 0, 7, 23, 39, 55, 71, 87, 103, |
---|
580 | 119, 135, 151, 167, 183, 199, 215, 231, |
---|
581 | 247, 255, 255, 255, 255, 255, 255, 255, |
---|
582 | 255, 255, 255, 255, 255, 255, 255, 255, |
---|
583 | 255, 246, 228, 211, 193, 175, 158, 140}; |
---|
584 | final int[] green = |
---|
585 | {0, 0, 0, 0, 0, 0, 0, 0, |
---|
586 | 0, 11, 27, 43, 59, 75, 91, 107, |
---|
587 | 123, 139, 155, 171, 187, 203, 219, 235, |
---|
588 | 251, 255, 255, 255, 255, 255, 255, 255, |
---|
589 | 255, 255, 255, 255, 255, 255, 255, 255, |
---|
590 | 255, 247, 231, 215, 199, 183, 167, 151, |
---|
591 | 135, 119, 103, 87, 71, 55, 39, 23, |
---|
592 | 7, 0, 0, 0, 0, 0, 0, 0}; |
---|
593 | final int[] blue = |
---|
594 | {0, 143, 159, 175, 191, 207, 223, 239, |
---|
595 | 255, 255, 255, 255, 255, 255, 255, 255, |
---|
596 | 255, 255, 255, 255, 255, 255, 255, 255, |
---|
597 | 255, 247, 231, 215, 199, 183, 167, 151, |
---|
598 | 135, 119, 103, 87, 71, 55, 39, 23, |
---|
599 | 7, 0, 0, 0, 0, 0, 0, 0, |
---|
600 | 0, 0, 0, 0, 0, 0, 0, 0, |
---|
601 | 0, 0, 0, 0, 0, 0, 0, 0}; |
---|
602 | |
---|
603 | final IndexedColorMap cmap = new IndexedColorMap( red, green, blue ); |
---|
604 | cmap.setTransform( new LinearTransform( 0.0, (double) red.length, datar.start, datar.end ) ); |
---|
605 | return cmap; |
---|
606 | } |
---|
607 | |
---|
608 | // Dimensions of the jPanes |
---|
609 | protected static final int MAX_WIDTH = 800; |
---|
610 | protected static final int MAX_HEIGHT = 700; |
---|
611 | protected static final int MARGIN_LEFT_RIGHT = 50; |
---|
612 | |
---|
613 | protected static final int TITLE_FONT_SIZE = 20; |
---|
614 | protected static final int FONT_SIZE = 12; |
---|
615 | protected static final int ERROR_FONT_SIZE = 10; |
---|
616 | } |
---|