Exceptions while painting custom labels

TeeChart for Java (NetBeans, Eclipse, Android Studio, etc)
Post Reply
mts
Newbie
Newbie
Posts: 18
Joined: Fri Apr 29, 2011 12:00 am

Exceptions while painting custom labels

Post by mts » Wed Nov 09, 2011 4:13 pm

I have built a UI that is a JScrollPane with multiple charts aligned vertically. The number of charts varies but is usually around 30. Some of these charts graph numbers and others use custom labels to graph states like 0 = Off and 1 = On. When I only implemented the numbers everything worked fine. As soon as I added custom labels to display the strings like On and Off I started getting a lot of exceptions on the paint. This exceptions don't happen every time, but they do happen with enough regularity to reproduce and make the software unusable. I have tried to catch the exceptions when I call paint directly but they occur when the chart auto paints as well so I can't capture all of them. Here's what I'm getting:

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.steema.teechart.drawing.Graphics3DAWT.penPrepare(Graphics3DAWT.java:128)
at com.steema.teechart.drawing.Graphics3DAWT.line(Graphics3DAWT.java:479)
at com.steema.teechart.drawing.Graphics3D.doBevelRect(Graphics3D.java:4873)
at com.steema.teechart.drawing.Graphics3D.paintBevel(Graphics3D.java:4897)
at com.steema.teechart.Bevel.draw(Bevel.java:183)
at com.steema.teechart.Shape.paint(Shape.java:584)
at com.steema.teechart.Panel.draw(Panel.java:108)
at com.steema.teechart.Chart.paint(Chart.java:2026)
at com.steema.teechart.TChart.paintComponent(TChart.java:616)
at javax.swing.JComponent.paint(JComponent.java:1054)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5221)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java:1482)
at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1413)
at javax.swing.RepaintManager.paint(RepaintManager.java:1206)
at javax.swing.JComponent._paintImmediately(JComponent.java:5169)
at javax.swing.JComponent.paintImmediately(JComponent.java:4980)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:770)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:728)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:677)
at javax.swing.RepaintManager.access$700(RepaintManager.java:59)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1621)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
at java.awt.EventQueue.access$000(EventQueue.java:101)
at java.awt.EventQueue$3.run(EventQueue.java:666)
at java.awt.EventQueue$3.run(EventQueue.java:664)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)

The null pointer in penprepare is the most common but I also get:

Exception in thread "Thread-4" java.lang.NullPointerException
at com.steema.teechart.drawing.Graphics3DAWT.drawString(Graphics3DAWT.java:744)
at com.steema.teechart.drawing.Graphics3D.textOut(Graphics3D.java:3007)
at com.steema.teechart.drawing.Graphics3DAWT.textOut(Graphics3DAWT.java:748)
at com.steema.teechart.axis.Axis.drawAxisLabel(Axis.java:2332)
at com.steema.teechart.axis.Axis.drawAxisLabel(Axis.java:2107)
at com.steema.teechart.axis.AxisDraw.drawThisLabel(AxisDraw.java:525)
at com.steema.teechart.axis.AxisDraw.internalDrawLabel(AxisDraw.java:452)
at com.steema.teechart.axis.AxisDraw.doDefaultLabels(AxisDraw.java:609)
at com.steema.teechart.axis.AxisDraw.doNotCustomLabels(AxisDraw.java:692)
at com.steema.teechart.axis.AxisDraw.doCustomLabels(AxisDraw.java:720)
at com.steema.teechart.axis.AxisDraw.draw(AxisDraw.java:1044)
at com.steema.teechart.axis.Axis.draw(Axis.java:2579)
at com.steema.teechart.axis.Axes.draw(Axes.java:464)
at com.steema.teechart.Chart.internalDraw(Chart.java:731)
at com.steema.teechart.Chart.paint(Chart.java:2031)
at com.steema.teechart.exports.ImageExport.image(ImageExport.java:107)
at com.steema.teechart.Chart.image(Chart.java:310)
at com.steema.teechart.drawing.Graphics3DAWT.measureString(Graphics3DAWT.java:374)
at com.steema.teechart.drawing.Graphics3D.textWidth(Graphics3D.java:4201)
at com.steema.teechart.drawing.Graphics3D.textWidth(Graphics3D.java:4221)
at com.steema.teechart.Chart.calcString(Chart.java:1866)
at com.steema.teechart.Chart.multiLineTextWidth(Chart.java:1890)
at com.steema.teechart.axis.Axis.maxLabelsWidth(Axis.java:1232)
at com.steema.teechart.axis.Axis.internalCalcSize(Axis.java:1267)
at com.steema.teechart.axis.Axis.getSizeLabels(Axis.java:1282)

and

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: com.steema.teechart.drawing.Color cannot be cast to java.awt.GradientPaint
at sun.java2d.pipe.BufferedPaints.setPaint(Unknown Source)
at sun.java2d.pipe.BufferedContext.validate(Unknown Source)
at sun.java2d.pipe.BufferedContext.validateContext(Unknown Source)
at sun.java2d.d3d.D3DMaskFill.validateContext(Unknown Source)
at sun.java2d.pipe.BufferedMaskFill.MaskFill(Unknown Source)
at sun.java2d.pipe.AlphaColorPipe.renderPathTile(Unknown Source)
at sun.java2d.pipe.DuctusShapeRenderer.renderTiles(Unknown Source)
at sun.java2d.pipe.DuctusShapeRenderer.fillParallelogram(Unknown Source)
at sun.java2d.pipe.PixelToParallelogramConverter.fillRectangle(Unknown Source)
at sun.java2d.pipe.PixelToParallelogramConverter.fill(Unknown Source)
at sun.java2d.pipe.ValidatePipe.fill(Unknown Source)
at sun.java2d.SunGraphics2D.fill(Unknown Source)
at com.steema.teechart.drawing.Graphics3DAWT.rectangle(Graphics3DAWT.java:602)
at com.steema.teechart.Shape.paint(Shape.java:576)
at com.steema.teechart.Panel.draw(Panel.java:108)
at com.steema.teechart.Chart.paint(Chart.java:2026)
at com.steema.teechart.TChart.paintComponent(TChart.java:616)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at com.Mahle.Graphics.Components.Support.ds.paint(DashoA7*..)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at com.Mahle.Graphics.Components.Support.ds.paint(DashoA7*..)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JViewport.paint(Unknown Source)
at javax.swing.JComponent.paintChildren(Unknown Source)
at javax.swing.JComponent.paint(Unknown Source)
at javax.swing.JComponent.paintToOffscreen(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
at javax.swing.BufferStrategyPaintManager.paint(Unknown Source)
at javax.swing.RepaintManager.paint(Unknown Source)
at javax.swing.JComponent._paintImmediately(Unknown Source)
at javax.swing.JComponent.paintImmediately(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
at javax.swing.RepaintManager.seqPaintDirtyRegions(Unknown Source)
at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(Unknown Source)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

and

Exception in thread "Thread-23" java.lang.ClassCastException: sun.java2d.NullSurfaceData cannot be cast to sun.java2d.d3d.D3DSurfaceData
at sun.java2d.d3d.D3DTextRenderer.validateContext(Unknown Source)
at sun.java2d.pipe.BufferedTextPipe.drawGlyphList(Unknown Source)
at sun.java2d.pipe.GlyphListPipe.drawString(Unknown Source)
at sun.java2d.pipe.ValidatePipe.drawString(Unknown Source)
at sun.java2d.SunGraphics2D.drawString(Unknown Source)
at com.steema.teechart.drawing.Graphics3DAWT.drawString(Graphics3DAWT.java:744)
at com.steema.teechart.drawing.Graphics3D.textOut(Graphics3D.java:3007)
at com.steema.teechart.drawing.Graphics3DAWT.textOut(Graphics3DAWT.java:748)
at com.steema.teechart.axis.Axis.drawAxisLabel(Axis.java:2332)
at com.steema.teechart.axis.Axis.drawAxisLabel(Axis.java:2107)
at com.steema.teechart.axis.AxisDraw.drawThisLabel(AxisDraw.java:529)
at com.steema.teechart.axis.AxisDraw.internalDrawLabel(AxisDraw.java:452)
at com.steema.teechart.axis.AxisDraw.doDefaultLabels(AxisDraw.java:609)
at com.steema.teechart.axis.AxisDraw.doNotCustomLabels(AxisDraw.java:692)
at com.steema.teechart.axis.AxisDraw.doCustomLabels(AxisDraw.java:720)
at com.steema.teechart.axis.AxisDraw.draw(AxisDraw.java:1044)
at com.steema.teechart.axis.Axis.draw(Axis.java:2579)
at com.steema.teechart.axis.Axes.draw(Axes.java:455)
at com.steema.teechart.Chart.internalDraw(Chart.java:731)
at com.steema.teechart.Chart.paint(Chart.java:2031)
at com.steema.teechart.exports.ImageExport.image(ImageExport.java:107)
at com.steema.teechart.Chart.image(Chart.java:310)
at com.steema.teechart.drawing.Graphics3DAWT.measureString(Graphics3DAWT.java:374)
at com.steema.teechart.drawing.Graphics3D.textWidth(Graphics3D.java:4201)
at com.steema.teechart.drawing.Graphics3D.textWidth(Graphics3D.java:4221)
at com.steema.teechart.Chart.multiLineTextWidth(Chart.java:1884)
at com.steema.teechart.axis.AxisLabels.internalLabelSize(AxisLabels.java:400)
at com.steema.teechart.axis.AxisLabels.labelHeight(AxisLabels.java:448)
at com.steema.teechart.axis.Axis.getCalcIncrement(Axis.java:1836)
at com.steema.teechart.axis.Axis.maxLabelsValueWidth(Axis.java:1183)
at com.steema.teechart.axis.Axis.maxLabelsWidth(Axis.java:1216)
at com.steema.teechart.axis.Axis.internalCalcSize(Axis.java:1267)
at com.steema.teechart.axis.Axis.getSizeLabels(Axis.java:1282)

I'll attach a screenshot of what my layout looks like. Here is a code snippet of how I initialize the chart and series and where I call get size labels, since that call seems to be throwing an exception. Also I call repaint directly because I do some custom drawing on the chart when the user moves a slider.

Here's where I initalize the chart and series (note that SEVPair is the state where 0 = the string On etc, this is not used on every chart but only some):
chart1 = new TChart();
fCreateReader();
fDoCommonMouseDebugSetup(null);


lineSeries1 = new Line(chart1.getChart());
lineSeries1.getLinePen().setWidth(2);
lineSeries1.getPointer().setStyle(PointerStyle.CROSS);
lineSeries1.getPointer().setVisible(false);
lineSeries1.getPointer().setColor(com.steema.teechart.drawing.Color.black);


/* Prepare chart for maximum speed: */
chart1.setClipPoints(false);
chart1.getHeader().setVisible(false);
chart1.getLegend().setVisible(false);
chart1.getAxes().getLeft().getAxisPen().setWidth(1);
chart1.getAxes().getBottom().getAxisPen().setWidth(1);
chart1.getAspect().setView3D(false);
chart1.getAspect().setSmoothingMode(true);
chart1.getAspect().setTextSmooth(false);

chart1.getWalls().getLeft().getBrush().getGradient().setStartColor(Color.GRAY);
chart1.getWalls().getLeft().getBrush().getGradient().setEndColor(Color.BLACK);
chart1.getWalls().getLeft().getBrush().getGradient().setVisible(true);

chart1.getWalls().getBottom().setColor(Color.BLACK);

chart1.getWalls().getBack().setTransparency(100);

chart1.getPanel().getGradient().setStartColor(Color.white);
chart1.getPanel().getGradient().setVisible(true);


chart1.addChartPaintListener( new ChartPaintAdapter() {

public void chartPainted(ChartDrawEvent e) {

if(spPlayback!=null){
if(dCurrentTime >= chart1.getAxes().getBottom().getMinimum() && dCurrentTime <= chart1.getAxes().getBottom().getMaximum()){
IGraphics3D g = chart1.getGraphics3D();
Point top = new Point(chart1.getAxes().getBottom().calcXPosValue(dCurrentTime),chart1.getAxes().getTop().getPosition());
Point bottom = new Point(chart1.getAxes().getBottom().calcXPosValue(dCurrentTime),chart1.getAxes().getBottom().getPosition());
g.getPen().setColor(Color.black);
g.moveTo(top);
g.lineTo(bottom);
}
}
};
});


chart1.addChartMotionListener(new ChartMotionListener(){

public void scrolled(ChartEvent e) {
if(ExtraData != null)
((JSPlaybackGraphs)ExtraData).fDoChartScrollAction(chart1.getAxes().getBottom().getMinimum(),chart1.getAxes().getBottom().getMaximum());
}

public void unzoomed(ChartEvent e) {
if(ExtraData != null)
((JSPlaybackGraphs)ExtraData).fDoChartUnzoomAction();
}

public void zoomed(ChartEvent e) {
Zoom z = chart1.getZoom();
if(ExtraData != null)
((JSPlaybackGraphs)ExtraData).fDoChartZoomAction(z);
}
});



//lineSeries1.setAutoRepaint(true);
/* Set Ordering to none, to increment speed when adding points */
lineSeries1.getXValues().setOrder(ValueListOrder.NONE);
chart1.getAspect().setClipPoints(true);

if(vciConvQItem != null){
if ( vciConvQItem.vcRead.iConversionType == CONVERSION_SEV ) {
if ( vciConvQItem.vcRead.vciSEV != null ) {
for(int i=0; i<vciConvQItem.vcRead.vciSEV.listPairs.size(); ++i){
SEVPair pair = vciConvQItem.vcRead.vciSEV.listPairs.get(i);
chart1.getAxes().getLeft().getCustomLabels().add((double)i, pair.sValue);
}
}
}
}


----------------------------------------------

Here's adding data to the series (note again the SEVPair if present is used with the custom labels):

lineSeries1.clear();
GraphData graphData;
double lastTime=-1,lastValue=0,dMax=0,dMin=0;
for (int i = 0; i<vciDataItem.length; ++i) {
double dValue = vciDataItem.Value;
if ( vciConvQItem.vcRead.iConversionType == CONVERSION_SEV ) {
if ( vciConvQItem.vcRead.vciSEV != null ) {
SEVPair sevPair = vciConvQItem.vcRead.vciSEV.fFindPair((int)dValue);
dValue = (sevPair!=null)?(sevPair.iIndex):0;
} else dValue = 0;
}
if(vciConvQItem.vcRead.iConversionType == CONVERSION_FLOAT){
if(Config.bIsSecondaryConversions && vciConvQItem.vcRead.tEquationSecondary != null){
vciConvQItem.vcRead.tEquationSecondary.fSetVariableListValue(0,dValue);
dValue = vciConvQItem.vcRead.tEquationSecondary.Calculate();
}
}
if(i==0){
dMax = dValue;
dMin = dValue;
}
else{
if(dValue > dMax)
dMax = dValue;
if(dValue < dMin)
dMin = dValue;
}
graphData = new GraphData(1.0*vciDataItem.Time/1000, dValue);
lastTime = 1.0*vciDataItem.Time/1000;
lastValue = dValue;
//System.out.println(lastTime + " " + lastValue);
PIDDataList.add(graphData);
}
if(lastTime > -1){
graphData = new GraphData(spPlayback.dDuration,lastValue);
PIDDataList.add(graphData);
graphData = new GraphData(spPlayback.dDuration+1,lastValue);
PIDDataList.add(graphData);
}

for(int i=0; i<PIDDataList.size(); ++i)
lineSeries1.add(PIDDataList.get(i).x,PIDDataList.get(i).y);

if(vciConvQItem.vcRead.iConversionType == CONVERSION_SEV){
if(vciConvQItem.vcRead.vciSEV != null ){
dMax = vciConvQItem.vcRead.vciSEV.listPairs.size();
dMin = 0;
}
else{
dMin = 0;
dMax = 1;
}

}
dGraphOriginalMax = dMax;
dGraphOriginalMin = dMin;

//chart1.getChart().getPanel().setMarginLeft(50);
chart1.getAxes().getLeft().setAutomatic(false);
chart1.getAxes().getLeft().setMaximum(dMax + 1);
chart1.getAxes().getLeft().setMinimum(dMin - 1);
chart1.getAxes().getBottom().setAutomatic(false);
chart1.getAxes().getBottom().setMinimum(0);
chart1.getAxes().getBottom().setMaximum(spPlayback.dDuration+1);
int duration = (int)spPlayback.dDuration+1;
double d = duration;
chart1.getAxes().getBottom().setIncrement(d/20.0);

---------------------------------------------
Here's where I call repaint directly (you can see in my initalization code that when this time parameter changes I draw a vertical line on the graph):

if(dCurrentTime != spPlayback.dCurrentTime){
dCurrentTime = spPlayback.dCurrentTime;
try{
chart1.repaint();
}
catch(Exception ex){
System.out.println("Exception in chart paint");
ex.printStackTrace();
}

return 1;
}

---------------------
Here's getting the size of the labels:

public int fGetLabelWidth(){
return chart1.getAxes().getLeft().getSizeLabels();
}
Attachments
graphs2.png
graphs2.png (178.43 KiB) Viewed 8365 times

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Exceptions while painting custom labels

Post by Yeray » Mon Nov 14, 2011 12:22 pm

Hello mts,

Excuse us for the delayed reply here.
I'm trying to use the code snipped you posted in a new simple application to test it and try to reproduce the exceptions but I can't. There are some undefined variables and methods I can't know what are they doing.

Could you please try the recently published v3 BETA to see if the problems are still reproducible with it in your application?
If they are still present, please, try to arrange a simple example project we can run as-is to reproduce the problems here.
Thanks in advance.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply