Chart.java
上传用户:mingda
上传日期:2017-06-20
资源大小:27691k
文件大小:135k
- // Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2002-12-03 18:40:24
- // Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
- // Decompiler options: packimports(3)
- // Source File Name: Chart.java
- package cn.com.fcsoft.chart;
- import java.awt.*;
- import java.awt.event.*;
- import java.awt.image.MemoryImageSource;
- import java.awt.image.PixelGrabber;
- import java.io.PrintStream;
- import java.text.NumberFormat;
- import java.util.*;
- // Referenced classes of package com.objectplanet.chart:
- // ChartData, Chart2, ChartSample
- public abstract class Chart extends Component
- implements ItemSelectable, Runnable
- {
- public boolean isValueLinesOn()
- {
- return valueLinesOn;
- }
- public void setDefaultGridLinesOn(boolean flag)
- {
- setDefaultGridLinesOn(flag, -1D, -1D);
- }
- public void setDefaultGridLinesOn(boolean flag, double d, double d1)
- {
- defaultGridLines = null;
- if(flag)
- {
- if(d <= 0.0D && d1 > 0.0D)
- d = d1;
- if(d1 <= 0.0D)
- {
- int i = 0;
- if(chartType.equals("bar"))
- i = getSampleCount() - 1;
- else
- if(chartType.equals("line"))
- i = getSampleCount() - 2;
- double d2 = (rightSampleAxisRange - leftSampleAxisRange) / (double)(i + 1);
- defaultGridLines = new double[i];
- for(int l = 0; l < defaultGridLines.length; l++)
- defaultGridLines[l] = leftSampleAxisRange + d2 * (double)(l + 1);
- } else
- {
- int j = (int)Math.ceil((rightSampleAxisRange - d) / d1);
- defaultGridLines = new double[j];
- for(int k = 0; k < defaultGridLines.length; k++)
- defaultGridLines[k] = d + d1 * (double)k;
- }
- }
- hasChanged = true;
- autoRepaint();
- }
- public void setRangeLabelsOn(boolean flag)
- {
- rangeLabelsOn = flag;
- hasChanged = true;
- autoRepaint();
- }
- public Image createImage(int i, int j)
- {
- i = Math.max(1, i);
- j = Math.max(1, j);
- Image image = super.createImage(i, j);
- if(image == null)
- {
- Frame frame = new Frame();
- frame.addNotify();
- image = frame.createImage(i, j);
- frame.dispose();
- }
- return image;
- }
- public void setTargetValueLine(String s, double d, Color color, int i)
- {
- if(color == null)
- {
- targetsLabel.remove(s);
- targetsValue.remove(s);
- targetsColor.remove(s);
- targetsStyle.remove(s);
- } else
- {
- targetsLabel.put(s, s);
- targetsValue.put(s, new Double(d));
- targetsColor.put(s, color);
- targetsStyle.put(s, new Integer(i));
- }
- hasChanged = true;
- autoRepaint();
- }
- public double getTargetValueLine(String s)
- {
- if(targetsValue.get(s) != null)
- return ((Double)targetsValue.get(s)).doubleValue();
- else
- return 0.0D;
- }
- private int[] rotateImage(int ai[], int i, Dimension dimension, int j)
- {
- if(i % 360 == 0)
- return ai;
- if(i % 360 == 90)
- {
- int ai1[] = new int[ai.length];
- for(int k = 0; k < dimension.height; k++)
- {
- for(int l1 = 0; l1 < dimension.width; l1++)
- ai1[l1 * dimension.height + k] = ai[(dimension.width * dimension.height - dimension.width - k * dimension.width) + l1];
- }
- int l = dimension.width;
- dimension.width = dimension.height;
- dimension.height = l;
- return ai1;
- }
- if(i % 360 == 180)
- {
- int ai2[] = new int[ai.length];
- for(int i1 = 0; i1 < dimension.width; i1++)
- {
- for(int i2 = 0; i2 < dimension.height; i2++)
- ai2[i2 * dimension.width + i1] = ai[dimension.width * dimension.height - 1 - i2 * dimension.width - i1];
- }
- return ai2;
- }
- if(i % 360 == 270)
- {
- int ai3[] = new int[ai.length];
- for(int j1 = 0; j1 < dimension.height; j1++)
- {
- for(int j2 = 0; j2 < dimension.width; j2++)
- ai3[j2 * dimension.height + j1] = ai[(j1 * dimension.width + dimension.width) - j2 - 1];
- }
- int k1 = dimension.width;
- dimension.width = dimension.height;
- dimension.height = k1;
- return ai3;
- }
- i = -i;
- double d = Math.sin((double)i * 0.017453292519943295D);
- double d1 = Math.cos((double)i * 0.017453292519943295D);
- double ad[] = new double[2];
- Rectangle rectangle = new Rectangle(dimension);
- getAngledBounds(d1, d, rectangle, ad);
- int k2 = -rectangle.x;
- int l2 = -rectangle.y;
- int ai4[] = new int[rectangle.width * rectangle.height];
- int ai5[] = new int[rectangle.width];
- for(int i3 = 0; i3 < rectangle.height; i3++)
- {
- itransform(d1, d, 0 - k2, i3 - l2, ad);
- double d2 = ad[0];
- double d3 = ad[1];
- itransform(d1, d, rectangle.width - k2, i3 - l2, ad);
- double d4 = ad[0];
- double d5 = ad[1];
- double d6 = (d4 - d2) / (double)rectangle.width;
- double d7 = (d5 - d3) / (double)rectangle.width;
- for(int j3 = 0; j3 < rectangle.width; j3++)
- {
- int k3 = (int)Math.round(d2);
- int l3 = (int)Math.round(d3);
- if(k3 < 0 || l3 < 0 || k3 >= dimension.width || l3 >= dimension.height)
- ai5[j3] = j & 0xffffff;
- else
- ai5[j3] = ai[l3 * dimension.width + k3];
- d2 += d6;
- d3 += d7;
- }
- System.arraycopy(ai5, 0, ai4, i3 * rectangle.width, ai5.length);
- }
- dimension.width = rectangle.width;
- dimension.height = rectangle.height;
- return ai4;
- }
- public void setLegendLabels(String as[])
- {
- if(as != null)
- legendLabels = as;
- else
- legendLabels = null;
- checkDataIntegrity();
- labelSizeCache.clear();
- hasChanged = true;
- autoRepaint();
- }
- public String[] getLegendLabels()
- {
- if(legendLabels != null)
- return legendLabels;
- if(getSeriesCount() == 1)
- return getSampleLabels();
- else
- return getSeriesLabels();
- }
- private void getColorPixels(Color acolor[], int ai[])
- {
- acolor[0] = Color.white;
- if(acolor[0].equals(acolor[1]))
- acolor[0] = Color.black;
- Image image = createImage(2, 1);
- if(image != null)
- {
- Graphics g = image.getGraphics();
- g.setColor(acolor[0]);
- g.drawLine(0, 0, 0, 0);
- g.setColor(acolor[1]);
- g.drawLine(1, 0, 1, 0);
- PixelGrabber pixelgrabber = new PixelGrabber(image, 0, 0, 2, 1, ai, 0, 2);
- pixelgrabber.startGrabbing();
- pixelgrabber.getPixels();
- if(ai[0] == ai[1])
- acolor[0] = new Color(0x7fffff);
- image.flush();
- g.dispose();
- }
- }
- public synchronized void setLowerRange(int i, double d)
- {
- i = Math.max(0, Math.min(1, i));
- lowerRange[i] = d;
- currentLowerRange[i] = Math.max(currentLowerRange[i], d);
- if(!rangeAdjusterOn[i])
- currentLowerRange[i] = d;
- for(int j = 0; j < overlayCharts.size(); j++)
- ((Chart)overlayCharts.elementAt(j)).setLowerRange(i, d);
- hasChanged = true;
- autoRepaint();
- }
- public synchronized double getLowerRange(int i)
- {
- return (double)(long)lowerRange[Math.max(0, Math.min(1, i))];
- }
- public void setSeriesRange(int i, int j)
- {
- if(i >= 0 && i < getSeriesCount())
- seriesRange[i] = Math.max(0, Math.min(rangeOn.length - 1, j));
- hasChanged = true;
- autoRepaint();
- }
- public int getSeriesRange(int i)
- {
- if(i >= 0 && i < getSeriesCount())
- return seriesRange[i];
- else
- return 0;
- }
- public boolean is3DModeOn()
- {
- return display3dOn;
- }
- boolean isServletModeOn()
- {
- return servletModeOn;
- }
- /**
- * @deprecated Method setLowerRange is deprecated
- */
- public synchronized void setLowerRange(double d)
- {
- setLowerRange(0, d);
- }
- public void setChartForeground(Color color)
- {
- chartForeground = color;
- hasChanged = true;
- autoRepaint();
- }
- public void setGridLineColor(int i, Color color)
- {
- if(i >= maxGridLineCount || i < 0)
- throw new IllegalArgumentException("Illegal vertical grid line index: " + i);
- if(gridLineColors == null)
- gridLineColors = new Color[i + 1];
- if(i >= gridLineColors.length)
- {
- Color acolor[] = new Color[i + 1];
- System.arraycopy(gridLineColors, 0, acolor, 0, gridLineColors.length);
- gridLineColors = acolor;
- }
- gridLineColors[i] = color;
- hasChanged = true;
- autoRepaint();
- }
- public Color getGridLineColor(int i)
- {
- if(gridLineColors == null || i >= gridLineColors.length)
- return getValueLinesColor();
- else
- return gridLineColors[i];
- }
- public Color getChartForeground()
- {
- return chartForeground;
- }
- /**
- * @deprecated Method getLowerRange is deprecated
- */
- public synchronized long getLowerRange()
- {
- return (long)getLowerRange(0);
- }
- public void autoRepaint()
- {
- if(automaticRepaintOn)
- repaint();
- }
- private void paintRange(Graphics g, Rectangle rectangle, int i)
- {
- i = Math.max(0, Math.min(1, i));
- if(!rangeOn[i])
- return;
- String s = getLabel("rangeLabelPrefix");
- String s1 = getLabel("rangeLabelPostfix");
- g.setFont(getFont("rangeLabelFont"));
- FontMetrics fontmetrics = g.getFontMetrics();
- int j = 0;
- if(gridAlignment == 1)
- {
- j = (int)Math.round((double)rectangle.height / (double)fontmetrics.getHeight());
- } else
- {
- String s2 = formatNumber(upperRange[i], rangeDecimalCount[i]);
- String s3 = formatNumber(lowerRange[i], rangeDecimalCount[i]);
- if(s != null && s.length() > 0)
- {
- s2 = s + s2;
- s3 = s + s3;
- }
- if(s1 != null && s1.length() > 0)
- {
- s2 += s1;
- s3 += s1;
- }
- int l = Math.max(fontmetrics.stringWidth(s2), fontmetrics.stringWidth(s3)) + 4;
- j = (int)Math.round((double)rectangle.width / (double)l);
- }
- j = Math.min(maxValueLineCount, j);
- int k = (int)Math.round((currentUpperRange[i] - currentLowerRange[i]) * Math.pow(10D, rangeDecimalCount[i]));
- j = Math.min(j, k);
- j = Math.max(1, j);
- double d = (currentUpperRange[i] - currentLowerRange[i]) / (double)j;
- d = Math.abs(d);
- double d1 = d;
- boolean flag = false;
- for(double d2 = 9.9999999999999998E-013D; !flag && d2 < 100000000000000D; d2 *= 10D)
- {
- for(int i1 = 0; i1 < STEPS.length; i1++)
- {
- if(STEPS[i1] * d2 < d)
- continue;
- d1 = STEPS[i1] * d2;
- flag = true;
- break;
- }
- }
- int j1 = 0;
- if(i == 1)
- {
- int k1 = (int)(Math.abs(currentUpperRange[1] - currentLowerRange[1]) / d1 + 2D);
- valueLines = new double[k1];
- }
- Color color = getRangeColor(i);
- if(currentUpperRange[i] > 0.0D)
- {
- for(double d3 = Math.max(0.0D, currentLowerRange[i] - currentLowerRange[i] % d1); d3 < currentUpperRange[i]; d3 += d1)
- if(d3 != 0.0D)
- {
- String s8 = !rangeLabelsOn && i <= 0 ? null : formatNumber(d3, rangeDecimalCount[i]);
- if(i == 0)
- {
- if(s8 != null && s != null)
- s8 = s + s8;
- if(s8 != null && s1 != null)
- s8 += s1;
- }
- if(i == 1 && valueLines != null)
- valueLines[j1++] = d3;
- paintGridLine(g, rectangle, d3, valueLinesColor, s8, color, i == 0 && valueLinesOn, false, i, 0);
- }
- }
- if(currentLowerRange[i] < 0.0D)
- {
- for(double d4 = Math.min(0.0D, currentUpperRange[i] - currentUpperRange[i] % d1); d4 > currentLowerRange[i]; d4 -= d1)
- if(d4 != 0.0D)
- {
- String s9 = !rangeLabelsOn && i <= 0 ? null : formatNumber(d4, rangeDecimalCount[i]);
- if(i == 0)
- {
- if(s9 != null && s != null)
- s9 = s + s9;
- if(s9 != null && s1 != null)
- s9 += s1;
- }
- if(i == 1 && valueLines != null)
- valueLines[j1++] = d4;
- paintGridLine(g, rectangle, d4, valueLinesColor, s9, color, i == 0 && valueLinesOn, false, i, 0);
- }
- }
- if(rangeLabelsOn || i > 0)
- {
- String s4 = formatNumber(currentUpperRange[i], currentUpperRange[i] == 0.0D ? 0 : rangeDecimalCount[i]);
- if(i == 0)
- {
- s4 = s == null ? s4 : s + s4;
- s4 = s1 == null ? s4 : s4 + s1;
- }
- paintGridLine(g, rectangle, currentUpperRange[i], chartForeground, s4, color, i == 0, false, i, 0);
- s4 = !rangeLabelsOn && i <= 0 ? null : formatNumber(currentLowerRange[i], currentLowerRange[i] == 0.0D ? 0 : rangeDecimalCount[i]);
- if(i == 0)
- {
- s4 = s == null ? s4 : s + s4;
- s4 = s1 == null ? s4 : s4 + s1;
- }
- paintGridLine(g, rectangle, currentLowerRange[i], chartForeground, s4, color, i == 0, false, i, 0);
- }
- if(rangeLabelsOn || i > 0)
- {
- String s5 = "0";
- if(i == 0)
- {
- s5 = s == null ? s5 : s + s5;
- s5 = s1 == null ? s5 : s5 + s1;
- }
- paintGridLine(g, rectangle, 0.0D, i != 0 ? color : chartForeground, s5, color, true, false, i, 0);
- }
- if(i == 0)
- {
- for(Enumeration enumeration = targetsLabel.keys(); enumeration.hasMoreElements();)
- {
- String s7 = (String)enumeration.nextElement();
- String s10 = getTargetLabel(s7);
- Double double1 = (Double)targetsValue.get(s7);
- Color color2 = (Color)targetsColor.get(s7);
- if(double1 != null)
- paintGridLine(g, rectangle, double1.doubleValue(), color2, s10, color2, true, true, 0, 0);
- }
- }
- if(defaultGridLines != null)
- {
- for(int l1 = 0; l1 < defaultGridLines.length; l1++)
- paintGridLine(g, rectangle, defaultGridLines[l1], defaultGridLinesColor, null, null, true, false, 0, 1);
- }
- if(gridLines != null)
- {
- for(int i2 = 0; i2 < gridLines.length; i2++)
- {
- Color color1 = defaultGridLinesColor;
- if(gridLineColors != null && gridLineColors.length > i2 && gridLineColors[i2] != null)
- color1 = gridLineColors[i2];
- paintGridLine(g, rectangle, gridLines[i2], color1, null, null, true, true, 0, 1);
- }
- }
- String s6 = i != 0 ? getLabel("rangeAxisLabel_2") : getLabel("rangeAxisLabel");
- if(s6 != null)
- {
- Font font = getFont("rangeAxisLabelFont");
- g.setFont(font);
- g.setColor(color);
- FontMetrics fontmetrics1 = g.getFontMetrics();
- int j2 = 0;
- int k2 = 0;
- int l2 = i != 0 ? getLabelAngle("rangeAxisLabelAngle_2") : getLabelAngle("rangeAxisLabelAngle");
- l2 = gridAlignment != 1 ? 0 : l2;
- Dimension dimension = getLabelSize(s6, font);
- Dimension dimension1 = getAngledLabelSize(dimension, l2);
- int i3 = getRangeWidth(i, true);
- if(gridAlignment == 1)
- {
- if(rangePosition[i] == 0)
- j2 = rectangle.x - dimension1.width - i3 - 15;
- else
- j2 = rectangle.x + rectangle.width + i3 + 15;
- k2 = (rectangle.y + rectangle.height / 2) - dimension1.height / 2;
- if(l2 % 180 == 0)
- k2 += fontmetrics1.getAscent();
- if(display3dOn && rangePosition[i] == 0)
- {
- k2 -= depth3dPoint.y;
- j2 -= depth3dPoint.x;
- }
- } else
- {
- j2 = (rectangle.x + rectangle.width / 2) - dimension1.width / 2;
- int j3 = getFontMetrics(getFont("rangeLabelFont")).getHeight();
- if(rangePosition[i] == 0)
- {
- k2 = rectangle.y + rectangle.height + 5 + (rangeLabelsOn ? j3 : 0) + (l2 % 180 != 0 ? 0 : fontmetrics1.getMaxAscent() - 3);
- if(rangeAdjusterOn[0] && rangeAdjusterPosition[0] == 0 || rangeAdjusterOn[1] && rangeAdjusterPosition[1] == 0)
- k2 += 6;
- } else
- {
- k2 = rectangle.y - 4 - (rangeLabelsOn ? j3 : 0);
- if(rangeAdjusterOn[0] && rangeAdjusterPosition[0] == 0 || rangeAdjusterOn[1] && rangeAdjusterPosition[1] == 0)
- k2 -= 10;
- if(l2 % 180 != 0)
- k2 -= dimension1.height - 5;
- }
- if(display3dOn && rangePosition[i] == 0)
- {
- k2 -= depth3dPoint.y;
- j2 -= depth3dPoint.x;
- }
- }
- paintLabel(g, s6, j2, k2, dimension, 0, l2);
- }
- }
- public void set3DDepth(int i)
- {
- if(i >= -1 && i < 32767)
- {
- depth3d = i;
- if(i >= 0)
- {
- depth3dPoint.x = depth3d;
- depth3dPoint.y = -depth3d;
- }
- hasChanged = true;
- autoRepaint();
- }
- }
- public int get3DDepth()
- {
- return depth3d;
- }
- public static String getVersion()
- {
- return "2.6";
- }
- public void setVisibleSamples(int i, int j)
- {
- int k = getSampleCount();
- j = j == -1 ? k : j;
- i = Math.max(0, i);
- i = Math.min(k - 1, i);
- j = Math.max(1, j);
- j = Math.min(k - i, j);
- i = Math.min(k - j, i);
- leftScrollerFactor = (double)i / (double)k;
- rightScrollerFactor = (double)(k - j - i) / (double)k;
- hasChanged = true;
- autoRepaint();
- }
- public boolean isFloatingOnLegendOn()
- {
- return floatingOnLegendOn;
- }
- public boolean isRangeAdjusterOn(int i)
- {
- i = Math.min(rangeAdjusterOn.length - 1, Math.max(0, i));
- return rangeAdjusterOn[i];
- }
- /**
- * @deprecated Method isRangeAdjusterOn is deprecated
- */
- public boolean isRangeAdjusterOn()
- {
- return isRangeAdjusterOn(0);
- }
- synchronized void setLowerRelativeRangeIndex(int i, double d)
- {
- i = Math.min(rangeOn.length - 1, Math.max(0, i));
- double d1 = getLowestValue(i);
- if(i == 0)
- {
- for(Enumeration enumeration = targetsValue.elements(); enumeration.hasMoreElements();)
- d1 = Math.min(((Double)enumeration.nextElement()).doubleValue(), d1);
- }
- if(d1 < 0.0D)
- setLowerRange(i, d1 * Math.abs(d));
- else
- setLowerRange(i, 0.0D);
- }
- public void setLabelAngle(String s, int i)
- {
- if(s != null && s.length() > 0)
- {
- i %= 360;
- s = s.toLowerCase().trim();
- labelAngles.put(s, new Integer(i));
- angledLabelCache.clear();
- hasChanged = true;
- autoRepaint();
- }
- }
- public int getLabelAngle(String s)
- {
- if(s != null)
- {
- s = s.toLowerCase().trim();
- if(labelAngles.get(s) != null)
- return ((Integer)labelAngles.get(s)).intValue();
- }
- return 0;
- }
- public Object[] getSelectedObjects()
- {
- int i = getSeriesCount();
- int j = getSampleCount();
- int k = 0;
- for(int l = 0; l < i; l++)
- {
- for(int i1 = 0; i1 < j; i1++)
- if(isSelected(l, i1))
- k++;
- }
- if(k > 0)
- {
- Object aobj[] = new Object[k];
- int j1 = 0;
- for(int k1 = 0; k1 < i; k1++)
- {
- for(int l1 = 0; l1 < j; l1++)
- if(isSelected(k1, l1) && j1 < aobj.length)
- aobj[j1++] = getSample(k1, l1);
- }
- return aobj;
- } else
- {
- return null;
- }
- }
- void paint3DEdges(Graphics g, Rectangle rectangle)
- {
- Color color = getChartForeground();
- Color color1 = new Color(color.getRed() / 2 + 128, color.getGreen() / 2 + 128, color.getBlue() / 2 + 128);
- g.setColor(color1);
- Polygon polygon = new Polygon();
- polygon.addPoint((rectangle.x + rectangle.width) - depth3dPoint.x, rectangle.y - depth3dPoint.y);
- polygon.addPoint((rectangle.x + rectangle.width) - depth3dPoint.x, (rectangle.y + rectangle.height) - depth3dPoint.y);
- g.drawPolygon(polygon);
- if(rangeOn[1] && valueLines != null)
- {
- int _tmp = depth3dPoint.y / valueLines.length;
- for(int i = 0; i < valueLines.length; i++)
- {
- double d = (valueLines[i] - currentLowerRange[1]) / (currentUpperRange[1] - currentLowerRange[1]);
- if(gridAlignment == 1)
- {
- int j = (int)Math.round((double)(rectangle.y + rectangle.height) - d * (double)rectangle.height - (double)depth3dPoint.y);
- if(valueLines[i] != 0.0D && j > (rectangle.y - depth3dPoint.y) + 1)
- g.drawLine((rectangle.x + rectangle.width) - depth3dPoint.x, j, ((rectangle.x + rectangle.width) - depth3dPoint.x) + 2, j - 2);
- } else
- {
- int k = (int)Math.round((double)(rectangle.x + rectangle.width) - d * (double)rectangle.width);
- k = (rectangle.x * 2 + rectangle.width) - k - depth3dPoint.x;
- if(valueLines[i] != 0.0D && k < (rectangle.x + rectangle.width) - depth3dPoint.x)
- g.drawLine(k - 1, rectangle.y - depth3dPoint.y, k + 2, rectangle.y - depth3dPoint.y - 2);
- }
- }
- }
- polygon.xpoints[1] = rectangle.x - depth3dPoint.x;
- polygon.ypoints[1] = rectangle.y - depth3dPoint.y;
- g.drawPolygon(polygon);
- polygon.xpoints[1] = rectangle.x + rectangle.width;
- polygon.ypoints[1] = rectangle.y;
- g.drawPolygon(polygon);
- }
- public void setExternalGraphics(Graphics g, Image image)
- {
- externalGraphicsOn = true;
- offscreen = image;
- og = g;
- hasChanged = true;
- autoRepaint();
- }
- public void setOverlayChart(int i, Chart chart)
- {
- if(chart != null)
- {
- int j = overlayCharts.size();
- if(i >= 0 && i <= j)
- {
- if(i == j)
- overlayCharts.addElement(chart);
- else
- overlayCharts.setElementAt(chart, i);
- chart.setRange(0, getRange(0));
- chart.setRange(1, getRange(1));
- chart.setLowerRange(0, getLowerRange(0));
- chart.setLowerRange(1, getLowerRange(1));
- hasChanged = true;
- autoRepaint();
- } else
- {
- throw new IllegalArgumentException("Invalid index for overlay chart: " + i);
- }
- }
- }
- public Chart getOverlayChart(int i)
- {
- if(i >= 0 && i < overlayCharts.size())
- return (Chart)overlayCharts.elementAt(i);
- else
- return null;
- }
- public boolean isDefaultGridLinesOn()
- {
- return defaultGridLines != null;
- }
- public void setLegendImage(int i, String s)
- {
- if(i >= 0 && i < 1000)
- {
- if(legendImages == null)
- legendImages = new String[i + 1];
- if(i >= legendImages.length)
- {
- String as[] = new String[i + 1];
- System.arraycopy(legendImages, 0, as, 0, legendImages.length);
- legendImages = as;
- }
- legendImages[i] = s;
- hasChanged = true;
- autoRepaint();
- }
- }
- public String getLegendImage(int i)
- {
- if(legendImages != null && i >= 0 && i < legendImages.length)
- return legendImages[i];
- else
- return null;
- }
- public void removeExternalGraphics()
- {
- externalGraphicsOn = false;
- hasChanged = true;
- autoRepaint();
- }
- int getRangeWidth(int i, boolean flag)
- {
- i = Math.min(rangeOn.length - 1, Math.max(0, i));
- FontMetrics fontmetrics = getFontMetrics(getFont("rangeLabelFont"));
- int j = 0;
- if(rangeOn[i] && (i == 0 && rangeLabelsOn || i > 0))
- {
- int k = getRangeDecimalCount(i);
- String s = formatNumber(upperRange[i], k);
- if(i == 0 && rangeLabelsOn)
- {
- String s2 = getLabel("rangeLabelPrefix");
- String s4 = getLabel("rangeLabelPostfix");
- s += s2 == null ? "" : s2;
- s += s4 == null ? "" : s4;
- }
- j = fontmetrics.stringWidth(s);
- s = formatNumber(lowerRange[i], k);
- if(i == 0 && rangeLabelsOn)
- {
- String s3 = getLabel("rangeLabelPrefix");
- String s5 = getLabel("rangeLabelPostfix");
- s += s3 == null ? "" : s3;
- s += s5 == null ? "" : s5;
- }
- j = Math.max(fontmetrics.stringWidth(s), j);
- }
- if(flag && i == 0)
- {
- for(Enumeration enumeration = targetsLabel.keys(); enumeration.hasMoreElements();)
- {
- String s1 = getTargetLabel((String)enumeration.nextElement());
- if(s1 != null)
- j = Math.max(fontmetrics.stringWidth(s1), j);
- }
- }
- byte byte0 = ((byte)(!rangeAdjusterOn[i] || rangeAdjusterPosition[i] != rangePosition[i] ? 0 : 6));
- return j + 4 + byte0;
- }
- public void removeItemListener(ItemListener itemlistener)
- {
- if(itemlistener != null && listeners != null)
- listeners.removeElement(itemlistener);
- }
- public void setGridLines(double ad[])
- {
- gridLines = ad;
- hasChanged = true;
- autoRepaint();
- }
- public double[] getGridLines()
- {
- return gridLines;
- }
- public void setAutomaticRepaintOn(boolean flag)
- {
- automaticRepaintOn = flag;
- }
- public void setOverlayChartOn(int i, boolean flag)
- {
- Chart chart = getOverlayChart(i);
- if(chart != null)
- chart.overlayChartOn = flag;
- hasChanged = true;
- autoRepaint();
- }
- public abstract Rectangle getGraphBounds();
- Rectangle getGraphBounds(String as[])
- {
- if(as == null)
- throw new IllegalArgumentException("Labels is NULL");
- Dimension dimension = getSize();
- Rectangle rectangle = new Rectangle(10, 10, dimension.width - 20, dimension.height - 20);
- FontMetrics fontmetrics = getFontMetrics(getFont("legendFont"));
- fontmetrics.getHeight();
- Dimension dimension1 = null;
- if(chartTitleOn)
- {
- dimension1 = getLabelSize(chartTitle, getFont("titleFont"));
- rectangle.y += dimension1.height;
- rectangle.height -= dimension1.height;
- }
- if(legendOn)
- {
- getSampleCount();
- getSeriesCount();
- Font font = getFont("legendFont");
- FontMetrics fontmetrics1 = getFontMetrics(font);
- legend.width = 0;
- legend.height = 0;
- byte byte0 = 6;
- for(int i = 0; i < as.length; i++)
- {
- Dimension dimension2 = getLabelSize(as[i], font);
- Dimension dimension3 = getImageSize(getLegendImage(i));
- if(legendPosition == 1 || legendPosition == 0)
- {
- dimension3.width = Math.max(dimension3.width, byte0);
- legend.width = Math.max(legend.width, dimension2.width + dimension3.width + byte0 + 2);
- legend.height += Math.max(Math.max(dimension3.height, dimension2.height), byte0 + 6) + 2;
- } else
- {
- legend.height = Math.max(Math.max(legend.height, dimension2.height), dimension3.height + 1);
- dimension3.width = Math.max(dimension3.width, byte0);
- legend.width += dimension3.width + byte0 + dimension2.width;
- if(i < as.length - 1)
- legend.width += byte0 + 2;
- }
- }
- switch(legendPosition)
- {
- case 1: // ' 01'
- default:
- legend.x = dimension.width - legend.width - 3;
- legend.y = (dimension.height / 2 - legend.height / 2) + fontmetrics1.getDescent();
- rectangle.width -= legend.width;
- break;
- case 0: // ' '
- legend.x = 6;
- legend.y = (dimension.height / 2 - legend.height / 2) + fontmetrics1.getDescent();
- rectangle.x += legend.width;
- rectangle.width -= legend.width;
- break;
- case 2: // ' 02'
- legend.x = dimension.width / 2 - legend.width / 2;
- legend.y = dimension1 == null ? 9 : dimension1.height + 9;
- rectangle.y += legend.height + fontmetrics1.getDescent();
- rectangle.height -= legend.height + fontmetrics1.getDescent();
- break;
- case 3: // ' 03'
- legend.x = dimension.width / 2 - legend.width / 2;
- legend.y = dimension.height - legend.height - 2;
- rectangle.height -= legend.height + 4;
- break;
- }
- }
- if(sampleScrollerOn)
- if(gridAlignment == 1)
- {
- rectangle.height -= 10;
- } else
- {
- rectangle.width -= 10;
- rectangle.x += 10;
- }
- return rectangle;
- }
- public void run()
- {
- try
- {
- Thread.sleep(250L);
- }
- catch(InterruptedException _ex) { }
- double d = (double)(chartDataBounds.width / getSampleCount()) / (double)chartDataBounds.width;
- do
- {
- if(insideLeftButton)
- {
- d = Math.min(d, leftScrollerFactor);
- leftScrollerFactor -= d;
- rightScrollerFactor += d;
- hasChanged = true;
- repaint();
- }
- if(insideRightButton)
- {
- d = Math.min(d, rightScrollerFactor);
- leftScrollerFactor += d;
- rightScrollerFactor -= d;
- hasChanged = true;
- repaint();
- }
- try
- {
- Thread.sleep(35L);
- }
- catch(InterruptedException _ex) { }
- } while(true);
- }
- synchronized void paintLegend(Graphics g, Rectangle rectangle, String as[])
- {
- if(g == null || rectangle == null || as == null)
- return;
- if(legendBounds == null || legendBounds.length != as.length)
- {
- legendBounds = new Rectangle[as.length];
- for(int i = 0; i < legendBounds.length; i++)
- legendBounds[i] = new Rectangle();
- }
- byte byte0 = 6;
- int j = legend.y;
- int k = legend.x;
- int l = k + byte0;
- int i1 = legend.y;
- for(int k1 = 0; k1 < as.length; k1++)
- {
- Dimension dimension = getImageSize(getLegendImage(k1));
- l = Math.max(l, k + byte0 + dimension.width);
- }
- if(l == k + byte0)
- l += byte0;
- int l1 = getSampleCount();
- int i2 = getSeriesCount();
- Font font = getFont("legendFont");
- g.setFont(font);
- FontMetrics fontmetrics = g.getFontMetrics();
- for(int j2 = 0; j2 < as.length; j2++)
- {
- String s = getLegendImage(j2);
- Dimension dimension1 = getImageSize(s);
- if(legendPosition == 2 || legendPosition == 3)
- j = legend.y + (legend.height - (dimension1.height <= 0 ? 6 : dimension1.height)) / 2;
- if(s != null && dimension1.width > 0 && dimension1.height > 0)
- {
- Image image = (Image)images.get(s);
- if(image != null)
- if(legendPosition == 1 || legendPosition == 0)
- {
- int k2 = dimension1.width >= byte0 ? k : ((k + byte0 / 2) - dimension1.width / 2) + 1;
- int l2 = dimension1.height >= byte0 ? j : ((j + byte0 / 2) - dimension1.height / 2) + 1;
- g.drawImage(image, k2, l2, this);
- } else
- {
- g.drawImage(image, k, j, this);
- }
- } else
- {
- Color color = getLegendColor(j2);
- if(color != null)
- g.setColor(color);
- g.fillRect(k, j, byte0, byte0);
- g.setColor(Color.black);
- g.drawRect(k, j, byte0, byte0);
- }
- g.setColor(getForeground());
- if(i2 == 1 && j2 < l1)
- {
- Color color1 = getSampleLabelColor(j2);
- if(color1 != null)
- g.setColor(color1);
- } else
- if(i2 > 1 && j2 < i2)
- {
- Color color2 = getSeriesLabelColor(j2);
- if(color2 != null)
- g.setColor(color2);
- }
- Dimension dimension2 = getLabelSize(as[j2], font);
- dimension1.width = Math.max(dimension1.width, byte0);
- dimension1.height = Math.max(dimension1.height, byte0);
- int j1 = (j + dimension1.height / 2 + fontmetrics.getMaxAscent() / 2) - 1;
- if(legendPosition == 2 || legendPosition == 3)
- {
- l = k + dimension1.width + byte0;
- j1 = (legend.y + (legend.height - dimension2.height) / 2 + dimension2.height) - 2;
- }
- paintLabel(g, as[j2], l, j1, dimension2, -1, 0);
- Rectangle rectangle1 = legendBounds[j2];
- rectangle1.x = k - 3;
- rectangle1.y = Math.min(j1 - fontmetrics.getAscent(), j - 3);
- rectangle1.width = ((dimension2.width + l) - k) + 6;
- rectangle1.height = Math.max(dimension1.height + 5, dimension2.height + 1);
- rectangle1.height = Math.max(rectangle1.height, byte0 + 7);
- if(j2 >= 0 && j2 < legendSelection.length && legendSelection[j2])
- {
- g.setColor(getForeground());
- g.drawRect(rectangle1.x, rectangle1.y, rectangle1.width, rectangle1.height);
- }
- if(legendPosition == 0 || legendPosition == 1)
- {
- int i3 = Math.max(dimension1.height, dimension2.height);
- i3 = Math.max(i3, byte0 + 6) + 2;
- j += i3;
- } else
- {
- k += rectangle1.width + 2;
- }
- }
- }
- public synchronized String formatNumber(double d, int i)
- {
- if(i == 0 && d < 1000D && d > -1000D)
- return Math.round(d) + "";
- long l = (long)Math.pow(10D, i);
- long l1 = Math.round(d * (double)l);
- long l2 = Math.abs(l1) % l + l;
- if(d >= 1000000D || d <= -1000000D)
- l2 = l;
- l1 /= l;
- if(numberFormatter == null)
- numberFormatter = NumberFormat.getInstance();
- numberFormatter.setMaximumFractionDigits(0);
- String s = "";
- if(i > 0)
- s = "." + (l2 + "").substring(1);
- String s1 = numberFormatter.format(l1) + s;
- if(d < 0.0D && !s1.startsWith("-", 0))
- s1 = "-" + s1;
- return s1;
- }
- public boolean isLegendOn()
- {
- return legendOn;
- }
- public synchronized void setSeriesLabel(int i, String s)
- {
- chartData.setSeriesLabel(i, s);
- hasChanged = true;
- autoRepaint();
- }
- public synchronized String getSeriesLabel(int i)
- {
- return chartData.getSeriesLabel(i);
- }
- void paintLabel(Graphics g, String s, int i, int j, Dimension dimension, int k, int l)
- {
- //System.out.println("Label="+s+";"+k+"");
- // g.setFont(new Font("黑体", 1, 50));
- //mq modify 2003-12-06
- FontMetrics fontmetrics = g.getFontMetrics();
- if(s != null && l == 0)
- {
- for(StringTokenizer stringtokenizer = new StringTokenizer(s, "n"); stringtokenizer.hasMoreElements();)
- {
- String s1 = (String)stringtokenizer.nextElement();
-
- if(s1 != null && s1.length() > 0)
- if(k == -1)
- g.drawString(s1, i, j);
- else
- if(k == 1)
- g.drawString(s1, (i + dimension.width) - fontmetrics.stringWidth(s1), j);
- else
- g.drawString(s1, (i + dimension.width / 2) - fontmetrics.stringWidth(s1) / 2, j);
- j += fontmetrics.getMaxAscent() + 1;
- //System.out.println("s1="+s1);
- }
- } else
- if(s != null)
- {
- Long long1 = new Long(s.hashCode() + l + g.getFont().hashCode());
- Image image = (Image)angledLabelCache.get(long1);
- if(image == null)
- {
- if(rotateImage == null || dimension.width > rotateImage.getWidth(this) || dimension.height > rotateImage.getHeight(this))
- {
- if(rotateImage != null)
- rotateImage.flush();
- rotateImage = createImage(dimension.width, dimension.height);
- }
- Color acolor[] = new Color[2];
- acolor[1] = g.getColor();
- int ai[] = new int[2];
- getColorPixels(acolor, ai);
- Graphics g1 = rotateImage.getGraphics();
- g1.setColor(acolor[0]);
- g1.fillRect(0, 0, dimension.width, dimension.height);
- g1.setColor(acolor[1]);
- g1.setFont(g.getFont());
- paintLabel(g1, s, 0, (fontmetrics.getMaxAscent() - fontmetrics.getDescent()) + 2, dimension, 0, 0);
- g1.dispose();
- g1 = null;
- int ai1[] = new int[dimension.width * dimension.height];
- PixelGrabber pixelgrabber = new PixelGrabber(rotateImage, 0, 0, dimension.width, dimension.height, ai1, 0, dimension.width);
- pixelgrabber.startGrabbing();
- pixelgrabber.getPixels();
- int i1 = acolor[1].getRGB();
- for(int j1 = 0; j1 < ai1.length; j1++)
- if(ai1[j1] == ai[0])
- ai1[j1] = ai[0] & 0xffffff;
- else
- ai1[j1] = i1;
- Dimension dimension1 = new Dimension(dimension.width, dimension.height);
- int ai2[] = rotateImage(ai1, l, dimension1, ai[0]);
- image = createImage(new MemoryImageSource(dimension1.width, dimension1.height, ai2, 0, dimension1.width));
- if(!servletModeOn)
- angledLabelCache.put(long1, image);
- }
- if(l == 180)
- j -= fontmetrics.getAscent() - 2;
- g.drawImage(image, i, j, null);
- }
- }
- void paintGrid(Graphics g, Rectangle rectangle)
- {
- if(depth3d > -1)
- {
- depth3dPoint.x = depth3d;
- depth3dPoint.y = -depth3d;
- }
- Polygon polygon = new Polygon();
- polygon.addPoint(rectangle.x, rectangle.y);
- polygon.addPoint(rectangle.x - depth3dPoint.x, rectangle.y - depth3dPoint.y);
- polygon.addPoint(polygon.xpoints[1], polygon.ypoints[1] + rectangle.height);
- polygon.addPoint(rectangle.x, rectangle.y + rectangle.height);
- polygon.addPoint(rectangle.x, rectangle.y);
- Polygon polygon1 = new Polygon();
- polygon1.addPoint(rectangle.x, rectangle.y + rectangle.height);
- polygon1.addPoint(polygon.xpoints[2], polygon.ypoints[2]);
- polygon1.addPoint(polygon1.xpoints[1] + rectangle.width, polygon1.ypoints[1]);
- polygon1.addPoint(rectangle.x + rectangle.width, rectangle.y + rectangle.height);
- polygon1.addPoint(polygon1.xpoints[0], polygon1.ypoints[0]);
- Color color = getChartBackground();
- g.setColor(color);
- g.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
- if(display3dOn)
- {
- g.setColor(gridAlignment != 1 ? color.darker() : color);
- g.fillPolygon(polygon);
- g.setColor(gridAlignment != 0 ? color.darker() : color);
- g.fillPolygon(polygon1);
- }
- g.setColor(chartForeground);
- if(display3dOn)
- {
- g.drawPolygon(polygon);
- g.drawPolygon(polygon1);
- }
- g.drawRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
- g.setFont(getFont("rangeLabelFont"));
- FontMetrics fontmetrics = g.getFontMetrics();
- for(int i = rangeOn.length - 1; i >= 0; i--)
- paintRange(g, rectangle, i);
- g.setColor(chartForeground);
- if(getLabel("sampleAxisLabel") != null)
- {
- Dimension dimension = new Dimension();
- if(sampleLabelsOn && barLabelStyle != 1)
- {
- Font font = getFont();
- int k = 0;
- if(chartType.equals("bar"))
- {
- font = getFont("barLabelFont");
- k = getLabelAngle("barLabelAngle");
- } else
- if(chartType.equals("line"))
- {
- font = getFont("sampleLabelFont");
- k = getLabelAngle("sampleLabelAngle");
- }
- String as[] = barLabels == null ? getSampleLabels() : barLabels;
- for(int i1 = 0; i1 < as.length; i1++)
- {
- Dimension dimension1 = getLabelSize(as[i1], font);
- Dimension dimension2 = getAngledLabelSize(dimension1, k);
- dimension.width = Math.max(dimension.width, dimension2.width);
- dimension.height = Math.max(dimension.height, dimension2.height);
- }
- }
- String s = getLabel("sampleAxisLabel");
- Font font1 = getFont("sampleAxisLabelFont");
- g.setFont(font1);
- FontMetrics fontmetrics1 = g.getFontMetrics();
- int l = 0;
- int j1 = 0;
- int k1 = getLabelAngle("sampleAxisLabelAngle");
- k1 = gridAlignment != 0 ? 0 : k1;
- Dimension dimension3 = getLabelSize(s, font1);
- Dimension dimension4 = getAngledLabelSize(dimension3, k1);
- if(gridAlignment == 1)
- {
- l = (rectangle.x + rectangle.width / 2) - dimension4.width / 2;
- j1 = rectangle.y + rectangle.height + 7;
- if(k1 % 180 == 0)
- j1 += fontmetrics1.getMaxAscent() - 2;
- if(display3dOn)
- {
- l -= depth3dPoint.x;
- j1 -= depth3dPoint.y;
- }
- if(sampleLabelsOn)
- j1 += dimension.height + 1;
- if(sampleScrollerOn)
- j1 += 10;
- } else
- {
- l = rectangle.x - dimension4.width - 5;
- j1 = (rectangle.y + rectangle.height / 2) - dimension4.height / 2;
- if(k1 % 180 == 0)
- j1 += fontmetrics1.getAscent();
- if(sampleLabelsOn)
- l -= dimension.width + 4;
- if(display3dOn)
- {
- j1 -= depth3dPoint.y;
- l -= depth3dPoint.x;
- }
- if(sampleScrollerOn)
- l -= 10;
- }
- paintLabel(g, s, l, j1, dimension3, 0, k1);
- }
- for(int j = 0; j < rangeAdjusterOn.length; j++)
- paintRangeAdjuster(g, rectangle, j);
- if(sampleScrollerOn)
- paintSampleScroller(g, rectangle);
- }
- private void itransform(double d, double d1, double d2, double d3, double ad[])
- {
- ad[0] = d * d2 - d1 * d3;
- ad[1] = d * d3 + d1 * d2;
- }
- public void setSampleScrollerOn(boolean flag)
- {
- sampleScrollerOn = flag;
- hasChanged = true;
- autoRepaint();
- }
- protected abstract void calculateChartData(Rectangle rectangle, Rectangle rectangle1);
- public synchronized void setSampleValue(int i, int j, double d)
- {
- chartData.setSampleValue(i, j, d);
- hasChanged = true;
- if(isValueLabelsOn(i) && getLabelAngle("valueLabelAngle") != 0)
- angledLabelCache.clear();
- autoRepaint();
- }
- public synchronized double getSampleValue(int i, int j)
- {
- return chartData.getSampleValue(i, j);
- }
- public synchronized int appendSampleValue(int i, double d, boolean flag)
- {
- int j = chartData.appendSampleValue(i, d, flag);
- hasChanged = true;
- if(isValueLabelsOn(i) && getLabelAngle("valueLabelAngle") != 0)
- angledLabelCache.clear();
- autoRepaint();
- return j;
- }
- double getLowestValue(int i)
- {
- i = Math.min(rangeOn.length - 1, Math.max(0, i));
- int j = getSeriesCount();
- double d = 0.0D;
- for(int k = 0; k < j; k++)
- if(getSeriesRange(k) == i)
- d = Math.min(getMinValue(k), d);
- for(int l = 0; l < overlayCharts.size(); l++)
- {
- Chart chart = (Chart)overlayCharts.elementAt(l);
- if(chart != null && !chart.chartType.equals("pie"))
- {
- for(int i1 = 0; i1 < chart.getSeriesCount(); i1++)
- if(chart.getSeriesRange(i1) == i)
- d = Math.min(chart.getMinValue(i1), d);
- }
- }
- return d;
- }
- public void setPrintAsBitmap(boolean flag)
- {
- printAsBitmap = flag;
- }
- private void paintGridLine(Graphics g, Rectangle rectangle, double d, Color color, String s, Color color1,
- boolean flag, boolean flag1, int i, int j)
- {
- double d1 = 0.0D;
- if(j == 0)
- {
- i = Math.max(0, Math.min(rangeOn.length - 1, i));
- if(currentUpperRange[i] - currentLowerRange[i] != 0.0D)
- d1 = (d - currentLowerRange[i]) / (currentUpperRange[i] - currentLowerRange[i]);
- } else
- if(j == 1)
- {
- Rectangle rectangle1 = getDataBounds(rectangle);
- double d2;
- double d3;
- if(gridAlignment == 1)
- {
- d2 = ((double)(rectangle.x - rectangle1.x) / (double)rectangle1.width) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
- d3 = ((double)((rectangle.width + rectangle.x) - rectangle1.x) / (double)rectangle1.width) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
- } else
- {
- d2 = ((double)(rectangle.y - rectangle1.y) / (double)rectangle1.height) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
- d3 = ((double)((rectangle.height + rectangle.y) - rectangle1.y) / (double)rectangle1.height) * (rightSampleAxisRange - leftSampleAxisRange) + leftSampleAxisRange;
- }
- d1 = (d - d2) / (d3 - d2);
- }
- FontMetrics fontmetrics = g.getFontMetrics();
- int k = fontmetrics.getHeight();
- int l = fontmetrics.getDescent();
- int i1 = s == null ? 0 : fontmetrics.stringWidth(s);
- if(gridAlignment == 1 && j == 0 || gridAlignment == 0 && j == 1)
- {
- int j1 = (int)Math.round((double)(rectangle.y + rectangle.height) - d1 * (double)rectangle.height);
- if(j == 1)
- j1 = (int)Math.round((double)rectangle.y + d1 * (double)rectangle.height);
- boolean flag2 = j1 >= rectangle.y && j1 <= rectangle.y + rectangle.height;
- boolean flag3 = j1 - k / 2 > rectangle.y + l / 2;
- flag3 &= j1 + k / 2 < (rectangle.y + rectangle.height) - l / 2;
- flag3 |= j == 1 && j1 > rectangle.y && j1 < rectangle.y + rectangle.height;
- flag3 |= j == 0 && d == 0.0D;
- if(flag2 && (flag3 || flag1) || j == 0 && (d == currentLowerRange[i] || d == currentUpperRange[i]))
- {
- if(flag)
- {
- g.setColor(color);
- g.drawLine(rectangle.x + 1, j1, (rectangle.x + rectangle.width) - 1, j1);
- if(display3dOn)
- g.drawLine(rectangle.x, j1, rectangle.x - depth3dPoint.x, j1 - depth3dPoint.y);
- }
- if(s != null)
- {
- int l1 = rectangle.x - (!display3dOn || rangePosition[i] != 0 ? 0 : depth3dPoint.x);
- j1 -= !display3dOn || rangePosition[i] != 0 ? 0 : depth3dPoint.y;
- int i2 = 0;
- g.setColor(color1);
- if(rangePosition[i] == 0)
- {
- g.drawLine(l1, j1, l1 - 3, j1);
- i2 = l1 - i1 - 4;
- if(rangeAdjusterOn[0] && rangeAdjusterPosition[0] == 0 || rangeAdjusterOn[1] && rangeAdjusterPosition[1] == 0)
- i2 -= 6;
- } else
- {
- g.drawLine(l1 + rectangle.width, j1, l1 + rectangle.width + 2, j1);
- i2 = rectangle.x + rectangle.width + 5;
- if(rangeAdjusterOn[0] && rangeAdjusterPosition[0] == 1 || rangeAdjusterOn[1] && rangeAdjusterPosition[1] == 1)
- i2 += 7;
- }
- int j2 = ((j1 + k) - fontmetrics.getAscent()) + 1;
- g.drawString(s, i2, j2);
- }
- }
- } else
- {
- String s1 = formatNumber(currentUpperRange[i], rangeDecimalCount[i]);
- String s2 = formatNumber(currentLowerRange[i], rangeDecimalCount[i]);
- int k1 = (int)(d == 0.0D && j != 1 ? zeroLine[i] : Math.round((double)rectangle.x + d1 * (double)rectangle.width));
- boolean flag4 = k1 >= rectangle.x && k1 <= rectangle.x + rectangle.width;
- boolean flag5 = k1 - i1 / 2 > rectangle.x + fontmetrics.stringWidth(s2) / 2;
- flag5 &= k1 + i1 / 2 < (rectangle.x + rectangle.width) - fontmetrics.stringWidth(s1) / 2;
- flag5 |= j == 1 && k1 > rectangle.x && k1 < rectangle.x + rectangle.width;
- flag5 |= j == 0 && d == 0.0D;
- if(flag4 && (flag5 || flag1) || j == 0 && (d == currentLowerRange[i] || d == currentUpperRange[i]))
- {
- if(flag)
- {
- g.setColor(color);
- g.drawLine(k1, rectangle.y + 1, k1, (rectangle.y + rectangle.height) - 1);
- if(display3dOn)
- g.drawLine(k1, rectangle.y + rectangle.height, k1 - depth3dPoint.x, (rectangle.y + rectangle.height) - depth3dPoint.y);
- }
- if(s != null)
- {
- int k2 = rectangle.y - (!display3dOn || rangePosition[i] != 0 ? 0 : depth3dPoint.y);
- k1 -= !display3dOn || rangePosition[i] != 0 ? 0 : depth3dPoint.x;
- g.setColor(color1);
- int l2 = k1 - i1 / 2;
- int i3 = 0;
- if(rangePosition[i] == 0)
- {
- g.drawLine(k1, k2 + rectangle.height, k1, k2 + rectangle.height + 3);
- i3 = k2 + rectangle.height + fontmetrics.getHeight();
- if(rangeAdjusterOn[0] && rangeAdjusterPosition[0] == 0 || rangeAdjusterOn[1] && rangeAdjusterPosition[1] == 0)
- i3 += 7;
- if(flag1)
- i3 += fontmetrics.getHeight();
- } else
- {
- g.drawLine(k1, k2, k1, k2 - 3);
- i3 = k2 - 5;
- if(rangeAdjusterOn[0] && rangeAdjusterPosition[0] == 1 || rangeAdjusterOn[1] && rangeAdjusterPosition[1] == 1)
- i3 -= 6;
- if(flag1)
- i3 -= fontmetrics.getHeight();
- }
- g.setColor(color1);
- g.drawString(s, l2, i3);
- }
- }
- }
- }
- public synchronized void setLowerRelativeRange(double d)
- {
- setLowerRelativeRangeIndex(0, d);
- }
- public synchronized void setLowerRelativeRange(double d, double d1)
- {
- setLowerRelativeRange(0, d, d1);
- }
- public synchronized void setLowerRelativeRange(int i, double d, double d1)
- {
- i = Math.min(rangeOn.length - 1, Math.max(0, i));
- double d2 = getLowestValue(i);
- if(i == 0)
- {
- for(Enumeration enumeration = targetsValue.elements(); enumeration.hasMoreElements();)
- d2 = Math.min(((Double)enumeration.nextElement()).doubleValue(), d2);
- }
- if(d2 < 0.0D)
- {
- d1 = Math.abs(d1);
- double d3 = d2 * Math.abs(d);
- if(d1 % 1.0D == 0.0D)
- {
- if(d3 % d1 == 0.0D)
- setLowerRange(i, d3);
- else
- setLowerRange(i, d3 - d3 % d1 - d1);
- } else
- {
- double d4;
- for(d4 = 0.0D; d4 > d3; d4 -= d1);
- setLowerRange(i, d4);
- }
- } else
- {
- setLowerRange(i, 0.0D);
- }
- }
- public void setCurrentRange(int i, double d)
- {
- i = Math.min(upperRange.length - 1, Math.max(0, i));
- int j = rangeAdjusted[i];
- if(i == 0 && j == 2)
- j = 0;
- else
- if(i == 1 && j == 2)
- j = 1;
- d = Math.min(upperRange[j], d);
- d = Math.max(currentLowerRange[j], d);
- currentUpperRange[j] = d;
- hasChanged = true;
- autoRepaint();
- }
- public double getCurrentRange(int i)
- {
- i = Math.min(currentUpperRange.length - 1, Math.max(0, i));
- return currentUpperRange[i];
- }
- public void setValueLinesOn(boolean flag)
- {
- valueLinesOn = flag;
- hasChanged = true;
- autoRepaint();
- }
- public void setSampleAxisRange(double d, double d1)
- {
- if(d >= d1)
- {
- throw new IllegalArgumentException("Min is more or equal than max: " + d + ", " + d1);
- } else
- {
- leftSampleAxisRange = d;
- rightSampleAxisRange = d1;
- hasChanged = true;
- autoRepaint();
- return;
- }
- }
- public void setGraphInsets(int i, int j, int k, int l)
- {
- graphInsets.top = i;
- graphInsets.left = j;
- graphInsets.bottom = k;
- graphInsets.right = l;
- hasChanged = true;
- autoRepaint();
- }
- public Insets getGraphInsets()
- {
- return graphInsets;
- }
- public synchronized void setSampleLabels(String as[])
- {
- chartData.setSampleLabels(as);
- hasChanged = true;
- if(sampleLabelsOn && (getLabelAngle("sampleLabelAngle") != 0 || getLabelAngle("barLabelAngle") != 0))
- angledLabelCache.clear();
- labelSizeCache.clear();
- autoRepaint();
- }
- public synchronized String[] getSampleLabels()
- {
- return chartData.getSampleLabels();
- }
- public Image getImage(String s)
- {
- return (Image)images.get(s);
- }
- /**
- * @deprecated Method getFloatLowerRange is deprecated
- */
- public synchronized double getFloatLowerRange()
- {
- return getLowerRange(0);
- }
- /**
- * @deprecated Method setCurrentRange is deprecated
- */
- public void setCurrentRange(double d)
- {
- setCurrentRange(0, d);
- }
- /**
- * @deprecated Method getCurrentRange is deprecated
- */
- public double getCurrentRange()
- {
- return getCurrentRange(0);
- }
- public Image getImage(int i, int j)
- {
- i = Math.max(1, i);
- j = Math.max(1, j);
- Dimension dimension = getSize();
- Image image = createImage(i, j);
- if(image != null)
- {
- Graphics g = image.getGraphics();
- if(g != null)
- {
- offscreen = null;
- setSize(i, j);
- paint(g);
- }
- }
- setSize(dimension.width, dimension.height);
- return image;
- }
- private void paintRangeAdjuster(Graphics g, Rectangle rectangle, int i)
- {
- i = Math.min(1, Math.max(0, i));
- if(!rangeAdjusterOn[i])
- return;
- int j = rangeAdjusted[i];
- if(i == 0 && j == 2)
- j = 0;
- else
- if(i == 1 && j == 2)
- j = 1;
- if(gridAlignment == 1)
- {
- int k = 0;
- int i1 = rectangle.y;
- if(rangeAdjusterPosition[i] == 0)
- {
- k = rectangle.x - 5 - (display3dOn ? depth3dPoint.x : 0);
- i1 -= display3dOn ? depth3dPoint.y : 0;
- } else
- {
- k = rectangle.x + rectangle.width + 5;
- }
- g.setColor(getBackground().darker());
- g.drawLine(k, i1, k, i1 + rectangle.height);
- g.setColor(getBackground().brighter());
- g.drawLine(k + 1, i1, k + 1, i1 + rectangle.height);
- double d = 0.0D;
- double d2 = 0.0D;
- if(upperRange[j] - lowerRange[j] != 0.0D)
- {
- d = (currentUpperRange[j] - lowerRange[j]) / (upperRange[j] - lowerRange[j]);
- d2 = (currentLowerRange[j] - lowerRange[j]) / (upperRange[j] - lowerRange[j]);
- }
- int k1 = (int)Math.round((double)(i1 + rectangle.height) - d * (double)rectangle.height);
- int i2 = (int)Math.round((double)(i1 + rectangle.height) - d2 * (double)rectangle.height);
- rangeAdjusterBounds[i].setBounds(k - 3, k1, 7, i2 - k1);
- paintBox(g, Color.lightGray, k - 3, k1, 6, i2 - k1, false);
- g.setColor(Color.gray);
- g.drawLine(k - 2, k1 + 2, k + 2, k1 + 2);
- g.setColor(Color.white);
- g.drawLine(k - 2, i2 - 2, k + 2, i2 - 2);
- } else
- {
- int l = 0;
- int j1 = rectangle.x;
- if(rangeAdjusterPosition[i] == 0)
- {
- l = (rectangle.y + rectangle.height + 5) - (display3dOn ? depth3dPoint.y : 0);
- j1 -= display3dOn ? depth3dPoint.x : 0;
- } else
- {
- l = rectangle.y - 5;
- }
- g.setColor(getBackground().darker());
- g.drawLine(j1, l, j1 + rectangle.width, l);
- g.setColor(getBackground().brighter());
- g.drawLine(j1, l + 1, j1 + rectangle.width, l + 1);
- double d1 = 0.0D;
- double d3 = 0.0D;
- if(upperRange[j] - lowerRange[j] != 0.0D)
- {
- d1 = (currentUpperRange[j] - lowerRange[j]) / (upperRange[j] - lowerRange[j]);
- d3 = (currentLowerRange[j] - lowerRange[j]) / (upperRange[j] - lowerRange[j]);
- }
- int l1 = (int)Math.round((double)j1 + d3 * (double)rectangle.width);
- int j2 = (int)Math.round((double)j1 + d1 * (double)rectangle.width);
- rangeAdjusterBounds[i].setBounds(l1, l - 3, j2 - l1, 7);
- paintBox(g, Color.lightGray, l1, l - 3, j2 - l1, 6, false);
- g.setColor(Color.gray);
- g.drawLine(l1 + 2, l - 2, l1 + 2, l + 2);
- g.setColor(Color.white);
- g.drawLine(j2 - 2, l - 2, j2 - 2, l + 2);
- }
- }
- private void paintBox(Graphics g, Color color, int i, int j, int k, int l, boolean flag)
- {
- g.setColor(color);
- g.fillRect(i, j, k, l);
- g.setColor(flag ? color.darker() : Color.white);
- g.drawLine(i, j, i + k, j);
- g.drawLine(i, j + 1, i, j + l);
- g.setColor(flag ? Color.white : color.darker());
- g.drawLine(i + 1, j + l, i + k, j + l);
- g.drawLine(i + k, j + 1, i + k, j + l);
- }
- void paintTitle(Graphics g, Dimension dimension)
- {
- if(chartTitleOn && chartTitle != null)
- {
- Font font = getFont("titleFont");
- g.setFont(font);
- FontMetrics fontmetrics = g.getFontMetrics();
- Dimension dimension1 = getLabelSize(chartTitle, font);
- int i = dimension.width / 2 - dimension1.width / 2;
- int j = fontmetrics.getMaxAscent() + 2;
- g.setColor(getForeground());
- paintLabel(g, chartTitle, i, j, dimension1, 2, 0);
- }
- }
- public boolean isRangeOn(int i)
- {
- return rangeOn[Math.min(1, Math.max(0, i))];
- }
- public void set3DModeOn(boolean flag)
- {
- display3dOn = flag;
- hasChanged = true;
- autoRepaint();
- }
- void setServletModeOn(boolean flag)
- {
- servletModeOn = flag;
- }
- public Chart(int i)
- {
- this(1, i);
- }
- public Chart(int i, int j)
- {
- chartData = new ChartData(i, j);
- sampleLabelColors = new Color[j];
- seriesLabelColors = new Color[i];
- listeners = new Vector();
- labels = new Hashtable();
- labelFonts = new Hashtable();
- labelAngles = new Hashtable();
- graphInsets = new Insets(-1, -1, -1, -1);
- preferredSize = new Dimension(300, 200);
- targetsLabel = new Hashtable();
- targetsValue = new Hashtable();
- targetsColor = new Hashtable();
- targetsStyle = new Hashtable();
- chartDataBounds = new Rectangle();
- depth3dPoint = new Point();
- depth3d = -1;
- rangeAdjusterBounds = new Rectangle[2];
- rangeAdjusterBounds[0] = new Rectangle();
- rangeAdjusterBounds[1] = new Rectangle();
- sampleScrollerBounds = new Rectangle();
- RESIZE_CURSOR = new Cursor(8);
- RESIZE_HOR_CURSOR = new Cursor(11);
- MOVE_CURSOR = new Cursor(12);
- DEFAULT_CURSOR = new Cursor(0);
- legend = new Rectangle();
- angledLabelCache = new Hashtable();
- labelSizeCache = new Hashtable();
- valueLabelsOn = new boolean[i];
- rangeOn = new boolean[2];
- rangePosition = new int[rangeOn.length];
- upperRange = new double[rangeOn.length];
- lowerRange = new double[rangeOn.length];
- currentUpperRange = new double[rangeOn.length];
- currentLowerRange = new double[rangeOn.length];
- rangeDecimalCount = new int[rangeOn.length];
- rangeColor = new Color[rangeOn.length];
- zeroLine = new int[rangeOn.length];
- seriesRange = new int[i];
- rangeAdjusterOn = new boolean[rangeOn.length];
- rangeAdjusterPosition = new int[rangeOn.length];
- rangeAdjusterPosition[0] = 1;
- rangeAdjusterPosition[1] = 1;
- rangeAdjusted = new int[rangeOn.length];
- rangeAdjusted[1] = 1;
- overlayCharts = new Vector();
- legendSelection = new boolean[i <= 1 ? j : i];
- enableEvents(49L);
- //检查许可证
- /*try
- {
- c2 = new Chart2();
- c2.version = getVersion();
- }
- catch(Throwable _ex)
- {
- throw new IllegalAccessError("没有有效的许可证!");
- }
- */
- reset();
- }
- public synchronized void setSampleLabelColor(int i, Color color)
- {
- try
- {
- sampleLabelColors[i] = color;
- autoRepaint();
- }
- catch(IndexOutOfBoundsException _ex)
- {
- throw new IllegalArgumentException("无效的示例索引: " + i);
- }
- }
- public Color getSampleLabelColor(int i)
- {
- try
- {
- return sampleLabelColors[i];
- }
- catch(IndexOutOfBoundsException _ex)
- {
- throw new IllegalArgumentException("无效的示例索引: " + i);
- }
- }
- public void setDefaultGridLinesColor(Color color)
- {
- defaultGridLinesColor = color;
- if(defaultGridLinesColor == null)
- defaultGridLinesColor = Color.lightGray;
- hasChanged = true;
- autoRepaint();
- }
- public void setGridLinesColor(Color color)
- {
- if(gridLines != null)
- {
- Color acolor[] = new Color[gridLines.length];
- for(int i = 0; i < gridLines.length; i++)
- acolor[i] = color;
- setGridLineColors(acolor);
- }
- }
- public synchronized void setSampleCount(int i)
- {
- chartData.setSampleCount(i);
- checkDataIntegrity();
- hasChanged = true;
- autoRepaint();
- }
- public synchronized int getSampleCount()
- {
- return chartData.getSampleCount();
- }
- public void setSampleDecimalCount(int i, int j)
- {
- if(i == -1)
- {
- for(int k = 0; k < sampleDecimalCount.length; k++)
- sampleDecimalCount[k] = j;
- } else
- if(i >= 0 && i < sampleDecimalCount.length)
- sampleDecimalCount[i] = j;
- hasChanged = true;
- if(isValueLabelsOn(i) && getLabelAngle("valueLabelAngle") != 0)
- angledLabelCache.clear();
- autoRepaint();
- }
- public int getSampleDecimalCount(int i)
- {
- if(i >= 0 && i < sampleDecimalCount.length)
- return sampleDecimalCount[i];
- else
- return 0;
- }
- public boolean isSelected(int i, int j)
- {
- return chartData.isSelected(i, j);
- }
- public int getLastSelectedSample()
- {
- return lastSelectedSample;
- }
- /**
- * @deprecated Method setSampleDecimalCount is deprecated
- */
- public void setSampleDecimalCount(int i)
- {
- setSampleDecimalCount(0, i);
- }
- /**
- * @deprecated Method getSampleDecimalCount is deprecated
- */
- public int getSampleDecimalCount()
- {
- return getSampleDecimalCount(0);
- }
- public final void paint(Graphics g)
- {
- Dimension dimension = getSize();
- g.setColor(getBackground());
- g.fillRect(0, 0, dimension.width, dimension.height);
- g.setColor(getForeground());
- //if(c2 != null)
- //{
- if(chartData.hasChangedSince(lastRenderTime))
- hasChanged = true;
- render(g);
- hasChanged = false;
- lastRenderTime = System.currentTimeMillis();
- // c2.paint(g, dimension);
- //}
- }
- synchronized void setRelativeRangeIndex(int i, double d)
- {
- i = Math.min(rangeOn.length - 1, Math.max(0, i));