]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.trend/src/org/simantics/trend/impl/ItemNode.java
Replace System.err and System.out with SLF4J Logging
[simantics/platform.git] / bundles / org.simantics.trend / src / org / simantics / trend / impl / ItemNode.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.trend.impl;
13
14 import java.awt.AlphaComposite;
15 import java.awt.BasicStroke;
16 import java.awt.Color;
17 import java.awt.Composite;
18 import java.awt.Graphics2D;
19 import java.awt.RenderingHints;
20 import java.awt.geom.AffineTransform;
21 import java.awt.geom.Path2D;
22 import java.awt.geom.Point2D;
23 import java.awt.geom.Rectangle2D;
24 import java.util.Arrays;
25 import java.util.List;
26 import java.util.TreeSet;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29
30 import org.simantics.databoard.Bindings;
31 import org.simantics.databoard.accessor.StreamAccessor;
32 import org.simantics.databoard.accessor.error.AccessorException;
33 import org.simantics.databoard.binding.Binding;
34 import org.simantics.databoard.binding.BooleanBinding;
35 import org.simantics.databoard.binding.ByteBinding;
36 import org.simantics.databoard.binding.error.BindingException;
37 import org.simantics.databoard.binding.error.RuntimeBindingException;
38 import org.simantics.databoard.type.BooleanType;
39 import org.simantics.databoard.type.Datatype;
40 import org.simantics.databoard.type.NumberType;
41 import org.simantics.databoard.type.RecordType;
42 import org.simantics.databoard.util.Bean;
43 import org.simantics.history.HistoryException;
44 import org.simantics.history.HistoryItem;
45 import org.simantics.history.HistoryManager;
46 import org.simantics.history.ItemManager;
47 import org.simantics.history.util.Stream;
48 import org.simantics.history.util.ValueBand;
49 import org.simantics.history.util.subscription.SamplingFormat;
50 import org.simantics.scenegraph.g2d.G2DNode;
51 import org.simantics.trend.configuration.LineQuality;
52 import org.simantics.trend.configuration.Scale;
53 import org.simantics.trend.configuration.TrendItem;
54 import org.simantics.trend.configuration.TrendItem.DrawMode;
55 import org.simantics.trend.configuration.TrendItem.Renderer;
56 import org.simantics.trend.util.KvikDeviationBuilder;
57 import org.slf4j.LoggerFactory;
58
59 /**
60  * Data node for a TrendItem
61  * 
62  * @author toni.kalajainen
63  */
64 public class ItemNode extends G2DNode implements TrendLayout {
65
66         private static final long serialVersionUID = -4741446944761752871L;
67         private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(ItemNode.class);
68         
69         public static final AlphaComposite composite = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, .61f);
70
71         public TrendItem item;
72         VertRuler ruler;
73         TrendNode trendNode;
74
75         /** History Items */
76         Bean historyItems[];
77         
78         /** A list of items that is ordered in by interval value, starting from the lowest interval */
79         Bean[] renderableItems = new Bean[0];
80         
81         /** Format for the minmax stream, or null */  
82         Bean minmaxItem;
83         
84         /** Known item min->max value range, and from->end time range */
85         double from=Double.NaN, end=Double.NaN, min=0, max=1;
86
87         BasicStroke stroke;
88         Color color;
89         
90         Stream openStream;
91         StreamAccessor openStreamAccessor;
92         Bean openStreamItem;
93         
94         Logger log = Logger.getLogger( this.getClass().getName() );     
95         
96         boolean disabled = false;
97         Point2D.Double pt = new Point2D.Double();
98         Point2D.Double pt2 = new Point2D.Double();
99         
100         // Cached shapes
101         KvikDeviationBuilder dev = new KvikDeviationBuilder();
102         Path2D.Double line = new Path2D.Double();
103         
104         /**
105          * Set trend item and initialize history
106          * @param ti
107          * @param items all items in history
108          */
109         public void setTrendItem(TrendItem ti, ItemManager items) {
110                 if (openStream!=null) {
111                         openStream.close();
112                         openStream = null;
113                         openStreamAccessor = null;
114                         openStreamItem = null;
115                 }
116                 this.item = ti;
117                 this.minmaxItem = null;
118                 this.renderableItems = new HistoryItem[0];
119                 disabled = true;
120                 if (ti==null) return;
121                 
122                 try {
123                         List<Bean> trendItems = items.search("groupId", ti.groupId, "groupItemId", ti.groupItemId, "variableId", ti.variableId);
124                         this.historyItems = trendItems.toArray( new Bean[trendItems.size()] );
125                         Arrays.sort( this.historyItems, SamplingFormat.INTERVAL_COMPARATOR );
126                         
127                         // Read renderable formats, and minmax format
128                         TreeSet<Bean> streamFormats = new TreeSet<Bean>( SamplingFormat.INTERVAL_COMPARATOR );
129                         for (Bean item : trendItems) {
130                                 SamplingFormat format = new SamplingFormat();
131                                 format.readAvailableFields(item);
132                                 RecordType rt = (RecordType) format.format;
133                                 Boolean enabled = (Boolean) item.getField("enabled");
134                                 if (!enabled) continue;
135                                         
136                                 boolean isMinMaxFormat = format.interval==Double.MAX_VALUE &&
137                                                 format.deadband==Double.MAX_VALUE &&
138                                                 rt.getComponentIndex2("min")>=0 &&
139                                                 rt.getComponentIndex2("max")>=0;
140         
141                                 if (isMinMaxFormat) {
142                                         this.minmaxItem = item;
143                                 } else {
144                                         streamFormats.add(item);
145                                 }                                       
146                         }
147                         if (streamFormats.isEmpty()) return;
148                         
149                         renderableItems = streamFormats.toArray( new Bean[streamFormats.size()] );
150                         disabled = false;
151                 } catch (BindingException e) {
152                         throw new RuntimeException( e );
153                 }
154         }
155
156         /**
157          * Draw to graphics context as time,value pairs are.
158          * 
159          * Phases, 0-Init data, 1-Draw deviation, 2-Draw line, 3-Cleanup 
160          * 
161          * @param g
162          * @param phase 
163          */
164         public void draw(Graphics2D g, int phase, boolean bold) {
165                 boolean devAndLine = 
166                                 item.drawMode==DrawMode.DeviationAndAverage || 
167                                 item.drawMode==DrawMode.DeviationAndLine || 
168                                 item.drawMode==DrawMode.DeviationAndSample;
169                 
170                 // Draw deviation
171                 Object newQuality = getTrendNode().printing||getTrendNode().quality.lineQuality==LineQuality.Antialias?RenderingHints.VALUE_ANTIALIAS_ON:RenderingHints.VALUE_ANTIALIAS_OFF;
172                 if (phase == 1) {                       
173                         g.setColor(color);
174                         if (!dev.isEmpty()) {
175                                 Object old = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
176                                 g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, newQuality);
177
178                                 if (item.renderer == Renderer.Binary) {
179                                         dev.drawRectangles(g);
180                                 } 
181                                 
182                                 if (item.renderer == Renderer.Analog) {
183                                         if (devAndLine) {
184                                                 // Draw opaque
185                                                 Composite c = g.getComposite();
186                                                 g.setComposite( composite );
187                                                 dev.drawRectangles(g);
188                                                 g.setComposite( c );
189                                         } else if (item.drawMode == DrawMode.Deviation) {
190                                                 // Draw solid
191                                                 dev.drawRectangles(g);
192                                         }
193                                 }
194                     g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, old);
195                         }                       
196                 }
197                         
198                 // Draw line
199                 if (phase == 2) {
200                         g.setColor(color);
201                         Object old = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
202                         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, newQuality);
203                         g.draw(line);                   
204             g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, old);
205                 }
206                 
207         }
208         
209         private boolean validSample(ValueBand band) throws HistoryException {
210                 if(band.getTimeDouble() > 1e50) return false;
211                 if(band.getTimeDouble() > band.getEndTimeDouble()) return false;
212 //              if(band.getTimeDouble() < 0) return false;
213 //              if(band.getEndTimeDouble() < 0) return false;
214                 //if(band.getEndTimeDouble()-band.getTimeDouble() < 1e-9) return false;
215                 return true;
216         }
217         
218         // Draw state needed for clipping
219         double currentX;
220         double currentY;
221         double minX;
222         double maxX;
223         
224         void moveTo(double x, double y) {
225                 line.moveTo(x, y);
226                 currentX = x;
227                 currentY = y;
228         }
229
230         void lineToOrdered(double x, double y) {
231                 
232                 if(x < minX) return;
233                 if(currentX > maxX) return;
234                 
235                 // We have something to draw
236                 
237                 // Clip left
238                 if(currentX < minX) {
239                         double ny = currentY + (y-currentY) * (minX-currentX) / (x-currentX);
240                         line.moveTo(minX, ny);
241                         currentX = minX;
242                         currentY = ny;
243                 }
244
245                 // Right clip
246                 if(x > maxX) {
247                         double ny = currentY + (y-currentY) * (maxX-currentX) / (x-currentX);
248                         line.lineTo(maxX, ny);
249                         line.moveTo(x, y);              
250                 } else {
251                         line.lineTo(x, y);              
252                 }
253                 
254         }
255         
256         void lineTo(double x, double y) {
257
258                 // First assert ordering - if samples are in wrong order draw nothing
259                 if(currentX <= x) {
260                         lineToOrdered(x, y);
261                 } else {
262                         line.moveTo(x, y);
263                 }
264                 
265                 currentX = x;
266                 currentY = y;
267                 
268         }
269         
270
271         /**
272          * This method prepares line and deviation shapes.
273          * @param from
274          * @param end
275          * @param secondsPerPixel
276          * @param at 
277          * @throws HistoryException 
278          * @throws AccessorException 
279          */
280         public void prepareLine(double from, double end, double pixelsPerSecond, AffineTransform at) throws HistoryException, AccessorException
281         {
282 //              boolean devAndLine = 
283 //                              item.drawMode==DrawMode.DeviationAndAverage || 
284 //                              item.drawMode==DrawMode.DeviationAndLine || 
285 //                              item.drawMode==DrawMode.DeviationAndSample;
286 //              boolean deviationEnabled = devAndLine || 
287 //                              item.drawMode == DrawMode.Deviation;
288
289                 boolean devAndLine = false;
290                 boolean deviationEnabled = false;
291                 
292                 // Collect data
293                 dev.reset();
294                 line.reset();
295                 Stream s = openStream(pixelsPerSecond);
296                 if (s==null) return;
297                 ValueBand vb = new ValueBand(s.sampleBinding, s.sampleBinding.createDefaultUnchecked());
298                 boolean hasDeviation = vb.hasMin() && vb.hasMax();
299                 boolean drawDeviation = hasDeviation & deviationEnabled;
300                 
301                 Datatype valueType = vb.getValueBinding().type();
302                 s.reset();
303                 if ( valueType instanceof BooleanType == false && valueType instanceof NumberType == false ) return;
304                                 
305                 int start = s.binarySearch(Bindings.DOUBLE, from);
306                 int count = s.count();
307                 if (start<0) start = -2-start;
308                 if (start<0) start = 0;
309                                 
310                 // moveTo, on next draw, if true
311                 boolean lineNotAttached = true; // =next draw should be move to
312                 boolean devNotAttached = true;
313                 
314                 currentX = Double.NaN;
315                 currentY = Double.NaN;
316
317                 pt.setLocation(from, 0);
318                 at.transform(pt, pt);
319                 minX = pt.x;
320                 
321                 pt.setLocation(end, 0);
322                 at.transform(pt, pt);
323                 maxX = pt.x;
324                                 
325                 s.reset();
326                 
327                 boolean wentOver = false;
328                 
329                 for (int i=start; i<count; i++) {
330                         // Read sample
331                         s.accessor.get(i, s.sampleBinding, vb.getSample());
332                         
333                         if(!validSample(vb)) {
334                                 LOGGER.warn("-invalid value band: " + i + "/" + count + ":" + vb);
335                                 continue;
336                         }
337                         // Non-continuation point
338                         if (vb.hasQuality()) {
339                                 Byte b = (Byte) vb.getQuality(Bindings.BYTE);
340                                 boolean noncontinuation = b.equals( ValueBand.QUALITY_NOVALUE ); 
341                                 if ( noncontinuation ) {
342                                         lineNotAttached = true;
343                                         devNotAttached = true;
344                                         continue;
345                                 }
346                         }
347                                         
348                         // Line
349                         double t1 = vb.getTimeDouble();
350                         double t2 = vb.hasEndTime() ? vb.getEndTimeDouble() : t1;
351                                         
352                         // Analog signal
353                         if (item.renderer == Renderer.Analog) {
354                                                 
355                                 // Add points to line
356                                 if (item.drawMode == DrawMode.Deviation && hasDeviation) {
357                                         // ...
358                                 } else {
359                                         
360                                         double yy = Double.NaN;
361 //                                      boolean showBand = true;
362                                         boolean flat = false;
363
364                                         if( trendNode != null && trendNode.drawSamples ) {
365                                                 yy = vb.getValueDouble();
366                                                 flat = true;
367                                         } else {
368                                                 yy = vb.getValueDouble();
369                                                 // Only render the last band
370 //                                              if(i < count-1) showBand = false;                                       
371                                         }
372                                         
373 //                                      if (item.drawMode == DrawMode.DeviationAndAverage) {
374 //                                              yy = vb.hasMedian() ? vb.getMedianDouble() : ( vb.hasAvg() ? vb.getAvgDouble() : vb.getValueDouble() );
375 //                                      } else if (item.drawMode == DrawMode.Average || item.drawMode == DrawMode.DeviationAndAverage) {
376 //                                              yy = vb.hasAvg() ? vb.getAvgDouble() : vb.getValueDouble();
377 //                                      } else if (item.drawMode == DrawMode.Line || item.drawMode == DrawMode.DeviationAndLine) {
378 //                                              yy = vb.getValueDouble();
379 //                                              // Only render the last band
380 //                                              if(i < count-1) showBand = false;                                       
381 //                                      } else /* if (item.drawMode == DrawMode.Sample || item.drawMode == DrawMode.DeviationAndSample) */ {
382 //                                              yy = vb.getValueDouble();
383 //                                              flat = true;
384 //                                      } 
385                         
386                                         if ( Double.isNaN(yy) ) {
387                                                 lineNotAttached = true;
388                                         } else {
389 //                                              pt.setLocation(t1, yy);
390 //                                              at.transform(pt, pt);
391 //                                              if ( t1==t2 ) {
392 //                                                      if (lineNotAttached) {
393 //                                                              moveTo(pt.getX(), pt.getY());
394 //                                                      } else {
395 //                                                              if(flat) {
396 //                                                                      
397 //                                                              } else {
398 //                                                                      lineTo(pt.getX(), pt.getY());
399 //                                                              }
400 //                                                      }
401 //                                              } else {
402                                                         // Static variables may have months data that consists of single value
403                                                         // When zoomed in, the single line may be drawn from -1e10, ... 1e10
404                                                         // This is too much for Graphics2D, it refuses to draw.
405 //                                                      if (t1<from) {
406 //                                                              t1 = from;
407 //                                                      }
408 //                                                      if (t2>end) {
409 //                                                              t2 = end;
410 //                                                      }
411                                                                         
412                                                         pt.setLocation(t1, yy);
413                                                         at.transform(pt, pt);
414                                                         pt2.setLocation(t2, yy);
415                                                         at.transform(pt2, pt2);
416
417                                                         double x1 = pt.x, y1 = pt.y, x2 = pt2.x, y2 = pt2.y;
418
419                                                         if (lineNotAttached) {
420                                                                 moveTo(x1, y1);
421                                                         } else {
422                                                                 if(flat) {
423                                                                         lineTo(x1, currentY);
424                                                                         lineTo(x1, y1);
425                                                                 } else {
426                                                                         lineTo(x1, y1);
427                                                                 }
428                                                         }
429
430                                                         lineTo(x2, y2);
431                                                         
432 //                                                      if(showBand) {
433 //                                                              lineTo(x2, y2);
434 //                                                      }
435                                                         
436 //                                              }
437                                                 lineNotAttached = false;                                        
438                                         }
439                                 }
440                                                 
441                                 if (drawDeviation) {
442                                         double min = vb.getMinDouble();
443                                         double max = vb.getMaxDouble();
444
445                                         pt.setLocation(t1, min);
446                                         at.transform(pt, pt);
447                                         pt2.setLocation(t2, max);
448                                         at.transform(pt2, pt2);
449                                         double x1 = pt.x;
450                                         double x2 = pt2.x;
451                                         double y1 = pt.y;
452                                         double y2 = pt2.y;
453                                                         
454                                         double width = x2-x1;
455                                         boolean tooWide = devAndLine && (width>2.0);
456                                         if (Double.isNaN(min) || Double.isNaN(max) || tooWide || width<=0.0 || y1==y2) {
457                                                 devNotAttached = true;
458                                         } else {
459                                                 if (devNotAttached) {
460                                                         dev.addRectangle(x1, x2, y1, y2);
461                                                 } else {
462                                                         dev.extendRectangle(x1);
463                                                         dev.addRectangle(x1, x2, y1, y2);
464                                                 }
465                                                 devNotAttached = false;
466                                         }
467                                 }
468                         }
469                                         
470                         // Binary signal
471                         if (item.renderer == Renderer.Binary) {
472                                 byte value = 0;
473                                 if (vb.getValueBinding() instanceof BooleanBinding) {
474                                         value = ((Boolean) vb.getValue(Bindings.BOOLEAN)) ? (byte)0 : (byte)1;
475                                 } else if (vb.getValueBinding() instanceof ByteBinding) {
476                                         value = ((Byte) vb.getValue(Bindings.BYTE));
477                                 } else if (vb.hasMax()) {
478                                         value = (Byte) vb.getMax(Bindings.BYTE);
479                                 } else {
480                                         value = (Byte) vb.getValue(Bindings.BYTE);
481                                 }
482                                 pt.setLocation(t1, value==1 ? BINARY[1] : BINARY[0]);
483                                 at.transform(pt, pt);
484                                 pt2.setLocation(t2, BINARY[2]);
485                                 at.transform(pt2, pt2);
486                                 double x1 = pt.x;
487                                 double x2 = pt2.x;
488                                 double y1 = pt.y;
489                                 double y2 = pt2.y;
490                                 dev.extendRectangle(x1);
491                                 dev.addRectangle(x1, x2, y1, y2);
492                                 devNotAttached = false;                                 
493                         }
494                                         
495                         // Already over => break
496                         if(wentOver) break;
497                         
498                         // Out of range
499                         if (t2>=end) {
500                                 wentOver = true;
501                         }
502                 }       
503                 
504         }
505         
506         public boolean readMinMaxFromEnd() {
507                 if (disabled) return false;
508                 HistoryManager history = getTrendNode().historian;
509
510                 boolean hasVariable = !item.variableId.isEmpty() && !item.groupItemId.isEmpty() && !item.groupId.isEmpty();
511                 boolean canReadMinMax = minmaxItem != null;
512                 boolean manualScale = item.scale instanceof Scale.Manual;
513                 
514                 if ( !hasVariable ) {
515                         min = 0;
516                         max = 1;
517                         from = Double.NaN;
518                         end = Double.NaN;
519                         return false;
520                 }
521                 
522                 try {
523                         if (canReadMinMax && !manualScale) {            
524                                 String id = (String) minmaxItem.getFieldUnchecked("id");
525                                 StreamAccessor sa = history.openStream(id, "r");
526                                 if ( sa==null ) {
527                                         min = 0;
528                                         max = 1;
529                                         from = Double.NaN;
530                                         end = Double.NaN;
531                                         return false;
532                                 } else 
533                                 try {
534                                         if (sa.size()==0) return false;
535                                         min = Double.MAX_VALUE;
536                                         max = -Double.MAX_VALUE;
537                                         from = Double.MAX_VALUE;
538                                         end = -Double.MAX_VALUE;
539                                         for (int i=0; i<sa.size(); i++) {
540                                                 Binding binding = Bindings.getBinding( sa.type().componentType() );
541                                                 Object sample = sa.get(i, binding);
542                                                 ValueBand vb = new ValueBand(binding, sample);
543                                                 if (!vb.isNullValue() && !vb.isNanSample()) {
544                                                         min = Math.min(min, vb.getMinDouble());
545                                                         max = Math.max(max, vb.getMaxDouble());
546                                                 } 
547                                                 if (!vb.isNullValue()) {
548                                                         from = Math.min(from, vb.getTimeDouble());
549                                                         end = Math.max(end, vb.getEndTimeDouble());
550                                                 }
551                                         }
552                                         if ( min==Double.MAX_VALUE || max==-Double.MAX_VALUE) {
553                                                 min = 0; max = 1.0;
554                                         }
555                                         if ( from==Double.MAX_VALUE || end==-Double.MAX_VALUE) {
556                                                 from = 0; end = 100.0;
557                                         }
558                                         return true;
559                                 } finally {
560                                         try { sa.close(); } catch (AccessorException e) {}
561                                 } 
562                         } else {
563                                 
564                                 if (manualScale) {
565                                         Scale.Manual ms = (Scale.Manual) item.scale;
566                                         min = ms.min;
567                                         max = ms.max;
568                                 } 
569                                 
570                                 // Read from, end from any stream
571                                 if (openStreamAccessor==null) {
572                                         openStream(1);
573                                 } 
574                                 if (openStreamAccessor!=null){
575                                         // Open some stream
576                                         StreamAccessor sa = openStreamAccessor;
577                                         sa.reset();
578                                         int count = sa.size();
579                                         if (count>0) {
580                                                 Binding binding = Bindings.getBinding( sa.type().componentType() );
581                                                 Object sample = sa.get(0, binding);
582                                                 ValueBand vb = new ValueBand(binding, sample);
583                                                 from = vb.getTimeDouble();
584                                                 sa.get(count-1, binding, sample);
585                                                 end = vb.hasEndTime() ? vb.getEndTimeDouble() : vb.getTimeDouble();
586                                         }
587                                         return true;
588                                 } else {
589                                         return false;
590                                 }
591                         }
592                 } catch (AccessorException e) {
593                         log.log(Level.FINE, e.toString(), e);
594                         return false;
595                 } catch (HistoryException e) {
596                         log.log(Level.FINE, e.toString(), e);
597                         return false;
598                 }
599         }
600         
601         @Override
602         public void cleanup() {
603                 trendNode = null;
604                 if (openStreamAccessor != null) {
605                         try {
606                                 openStreamAccessor.close();
607                         } catch (AccessorException e) {
608                         }
609                         openStreamAccessor = null;
610                         openStreamItem = null;
611                 }
612                 super.cleanup();
613         }
614         
615         Bean getFormat(double pixelsPerSecond) {
616                 Bean result = null;
617                 if (renderableItems == null)
618                         return null;
619                 
620                 for (Bean format : renderableItems)
621                 {
622                         double interval = 0.0;
623                         try {
624                                 interval = format.hasField("interval") ? (Double) format.getFieldUnchecked("interval") : 0.0;
625                         } catch (RuntimeBindingException e) {
626                         } catch (BindingException e) {
627                         }
628                         if (Double.isNaN( interval ) || interval<=pixelsPerSecond) {
629                                 result = format;
630                         } else {
631                                 break;
632                         }
633                 }               
634                 if (result==null) {
635                         if ( renderableItems.length == 0 ) {
636                                 result = null;
637                         } else {
638                                 result = renderableItems[0];
639                         }
640                 }
641                 
642                 return result;
643         }
644         
645         public Stream openStream(double pixelsPerSecond) {
646                 Bean f = getFormat(pixelsPerSecond);
647                 if (f==openStreamItem) return openStream;
648                 
649                 if (openStream != null) {
650                         openStream.close();
651                         openStreamAccessor = null;
652                         openStreamItem = null;
653                         openStream = null;
654                 }
655                 
656                 if (disabled) return null;
657                 
658                 if (f!=null) {
659                         HistoryManager historian = getTrendNode().historian;
660                         try {
661                                 String id = (String) f.getFieldUnchecked("id");
662                                 openStreamAccessor = historian.openStream(id, "r");
663                                 if ( openStreamAccessor!=null ) {
664                                         openStream = new Stream(openStreamAccessor);
665                                         openStreamItem = f;                     
666                                 } else {
667                                         openStream = null;
668                                 }
669                         } catch (HistoryException e) {
670                                 log.log(Level.FINE, e.toString(), e);
671                         }
672                 }
673                 
674                 return openStream;
675         }
676         
677         @Override
678         public void render(Graphics2D g2d) {
679         }
680
681         @Override
682         public Rectangle2D getBoundsInLocal() {
683                 return null;
684         }
685         
686         TrendNode getTrendNode() {
687                 return (TrendNode) getParent();
688         }
689         
690 }