📄 piechart.java
字号:
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2002-12-03 18:43:55
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: PieChart.java
package cn.com.fcsoft.chart;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.Hashtable;
import java.util.Vector;
// Referenced classes of package com.objectplanet.chart:
// Chart, ChartSample
public class PieChart extends Chart
{
public int getSeriesLabelStyle()
{
return seriesLabelStyle;
}
private void paintPies(Graphics g, Rectangle rectangle)
{
int i = getSeriesCount();
if(i == 1)
{
pieBounds[0] = rectangle;
double ad[] = getSampleValues(0);
paintPie(g, rectangle, ad, 0);
} else
{
int j = getSampleCount();
calculatePieBounds(rectangle, j);
for(int k = 0; k < j; k++)
{
double ad1[] = new double[i];
for(int l = 0; l < i; l++)
ad1[l] = getSampleValue(l, k);
paintPie(g, pieBounds[k], ad1, k);
}
}
}
public boolean isPercentLabelsOn()
{
return percentLabelsOn;
}
public boolean isSampleLabelsOn()
{
return sampleLabelsOn;
}
public boolean isPieLabelsOn()
{
return pieLabelsOn;
}
private void paintPieSegment(Graphics g, Color color, double d, double d1, int i,
int j, int k, int l, boolean flag, double d2, int i1)
{
if(d2 > 0.0D && d1 < 360D)
{
double d3 = -d + d1 / 2D;
double d5 = d3 * 0.017453292519943295D;
k += (int)Math.round(Math.cos(d5) * ((double)i * (d2 / 2D)));
l += (int)Math.round(Math.sin(d5) * ((double)j * (d2 / 2D)));
}
if(i1 == 1 || i1 == 2)
{
double d4 = d * 0.017453292519943295D;
double d6 = (d - d1) * 0.017453292519943295D;
int l1 = (int)Math.round((double)i * pieDepth * ((double)pieAngle / 90D));
int i2 = i / 2;
int j2 = j / 2;
double d7 = Math.abs(d4 - d6) / 6.2831853071795862D;
double d8 = 3.1415926535897931D * (double)Math.max(i, j);
double d9 = d7 * d8;
double d10 = Math.abs(d4 - d6) / d9;
if(d10 > 0.0D)
{
double d11 = d4;
double d12 = d4;
g.setColor(color.darker().darker());
while(d11 >= d6)
{
d11 -= d10;
int k2 = (int)Math.round(Math.cos(d11) * (double)i2);
int l2 = (int)Math.round(Math.sin(d11) * (double)j2);
if(l2 < 0)
g.drawLine(k + k2, l - l2, k + k2, (l - l2) + l1 + 1);
else
g.drawLine(k + k2, (l - l2) + 1, k + k2, (l - l2) + l1 + 2);
double d13 = d11;
}
}
}
if(i1 == 0 || i1 == 2)
{
int j1 = k - i / 2;
int k1 = l - j / 2;
g.setColor(color);
g.fillArc(j1, k1, i + 1, j + 1, (int)Math.round(d), (int)Math.round(-d1));
g.setColor(color.darker());
g.drawArc(j1, k1, i, j, (int)Math.round(d), (int)Math.round(-d1));
}
if(flag)
paintSelectionMarker(g, color, (int)Math.round(-d), (int)Math.round(-d1), i, j, k, l, selectionStyle);
}
protected void processEvent(AWTEvent awtevent)
{
switch(awtevent.getID())
{
case 504:
default:
break;
case 505:
selectedSample = -1;
selectedSeries = -1;
repaint();
break;
case 503:
case 506:
MouseEvent mouseevent = (MouseEvent)awtevent;
if(!seriesLabelsOn && !sampleLabelsOn && !isValueLabelsOn() && !percentLabelsOn)
break;
Point point = new Point(mouseevent.getX(), mouseevent.getY());
ChartSample chartsample = checkSelection(point);
boolean flag = false;
if(chartsample != null)
{
flag = chartsample.getIndex() != selectedSample || chartsample.getSeries() != selectedSeries;
selectedSample = chartsample.getIndex();
selectedSeries = chartsample.getSeries();
} else
{
flag = selectedSample != -1 || selectedSeries != -1;
selectedSample = -1;
selectedSeries = -1;
}
if(flag)
repaint();
break;
}
super.processEvent(awtevent);
}
public void setDepth(double d)
{
pieDepth = d;
super.hasChanged = true;
autoRepaint();
}
public float getDepth()
{
return (float)pieDepth;
}
public void setPercentLabelStyle(int i)
{
percentLabelStyle = 0;
if(i == 1 || i == 2)
percentLabelStyle = i;
super.hasChanged = true;
autoRepaint();
}
public int getPercentLabelStyle()
{
return percentLabelStyle;
}
public void setSampleLabelStyle(int i)
{
sampleLabelStyle = 0;
if(i == 1 || i == 2)
sampleLabelStyle = i;
super.hasChanged = true;
autoRepaint();
}
public int getSampleLabelStyle()
{
return sampleLabelStyle;
}
public void setDetachedDistance(double d)
{
detachedDistance = d;
super.hasChanged = true;
autoRepaint();
}
public double getDetachedDistance()
{
return detachedDistance;
}
public void setDetachedSlice(int i, int j, double d)
{
Double double1 = new Double(i * 0xf4240 + j);
if(d != 0.0D)
detachedSlices.put(double1, new Double(d));
else
detachedSlices.remove(double1);
super.hasChanged = true;
autoRepaint();
}
public double getDetachedSlice(int i, int j)
{
Double double1 = new Double(i * 0xf4240 + j);
Double double2 = (Double)detachedSlices.get(double1);
if(double2 != null)
return double2.doubleValue();
else
return 0.0D;
}
public boolean isSliceSeperatorOn()
{
return sliceSeperatorOn;
}
protected void calculateChartData(Rectangle rectangle, Rectangle rectangle1)
{
}
public double getPercentValue(int i, int j)
{
if(i < 0 || i >= getSeriesCount())
throw new IllegalArgumentException("Invalid series index: " + i);
if(j < 0 || j >= getSampleCount())
throw new IllegalArgumentException("Invalid sample index: " + j);
int k = getSeriesCount();
if(k == 1)
{
int l = getSampleCount();
double d1 = 0.0D;
for(int j1 = 0; j1 < l; j1++)
{
double d5 = getSampleValue(0, j1);
if(d5 > 0.0D)
d1 += d5;
}
double d3 = getSampleValue(0, j);
if(d3 >= 0.0D)
return (d3 / d1) * 100D;
} else
{
double d = 0.0D;
for(int i1 = 0; i1 < k; i1++)
{
double d4 = getSampleValue(i1, j);
if(d4 > 0.0D)
d += d4;
}
double d2 = getSampleValue(i, j);
if(d2 > 0.0D)
return (d2 / d) * 100D;
}
return 0.0D;
}
private void paintFloatingLabels(Graphics g, int i, int j)
{
int k = getSeriesCount();
int l = getSampleCount();
if(g == null || i < 0 || i >= k || j < -1 || j >= l)
return;
Font font = getFont("floatingLabelFont");
g.setFont(font);
FontMetrics fontmetrics = g.getFontMetrics();
boolean flag = isValueLabelsOn() && valueLabelStyle == 0;
boolean flag1 = percentLabelsOn && percentLabelStyle == 0;
boolean flag2 = sampleLabelsOn && sampleLabelStyle == 0;
boolean flag3 = seriesLabelsOn && k > 1 && seriesLabelStyle == 0;
if(j >= 0)
{
String s = constructLabel(i, j, flag3, flag2, flag, flag1);
paintFloatingLabel(g, s, i, j, font, fontmetrics);
} else
if(isFloatingOnLegendOn())
{
for(int i1 = 0; i1 < l; i1++)
{
String s1 = constructLabel(i, i1, flag3, flag2, flag, flag1);
paintFloatingLabel(g, s1, i, i1, font, fontmetrics);
}
}
}
private void paintSelectionMarker(Graphics g, Color color, double d, double d1, int i,
int j, int k, int l, int i1)
{
if(i1 == 1)
{
double d2 = d - d1 / 2D;
double d4 = d2 * 0.017453292519943295D;
int j1 = k + (int)Math.round(Math.cos(d4) * ((double)i * 0.40000000000000002D));
int l1 = l + (int)Math.round(Math.sin(d4) * ((double)j * 0.40000000000000002D));
int j2 = Math.max(i / 16, 3);
int l2 = Math.max(j / 16, 3);
int j3 = j2 / 2;
int k3 = l2 / 2;
g.setColor(color.darker());
g.fillOval(j1 - j3, l1 - k3, j2, l2);
g.setColor(color.darker());
g.drawArc(j1 - j3, l1 - k3, j2, l2, 45, 180);
g.setColor(color.darker().darker());
g.drawArc((j1 - j3) + 1, (l1 - k3) + 1, j2 - 2, l2 - 2, 45, 180);
g.setColor(color);
g.drawArc((j1 - j3) + 1, (l1 - k3) + 1, j2 - 2, l2 - 2, 45, -180);
g.setColor(color.brighter());
g.drawArc(j1 - j3, l1 - k3, j2, l2, 45, -180);
} else
if(i1 == 0)
{
double d3 = d - d1 / 2D;
double d5 = d3 * 0.017453292519943295D;
int k1 = (int)Math.round((double)i * 0.69999999999999996D);
int i2 = (int)Math.round((double)j * 0.69999999999999996D);
int k2 = k + (int)Math.round(Math.cos(d5) * ((double)i * 0.10000000000000001D));
int i3 = l + (int)Math.round(Math.sin(d5) * ((double)j * 0.10000000000000001D));
k2 -= (int)Math.round((double)k1 / 2D);
i3 -= (int)Math.round((double)i2 / 2D);
g.setColor(color.darker());
g.fillArc(k2, i3, k1 + 1, i2 + 1, (int)(-Math.round(d)), (int)Math.round(d1));
}
}
public void setPercentLabelsOn(boolean flag)
{
percentLabelsOn = flag;
super.hasChanged = true;
autoRepaint();
}
public void setSampleLabelsOn(boolean flag)
{
sampleLabelsOn = flag;
super.hasChanged = true;
autoRepaint();
}
public boolean isSeriesLabelsOn()
{
return seriesLabelsOn;
}
public void setPieLabelsOn(boolean flag)
{
pieLabelsOn = flag;
super.hasChanged = true;
autoRepaint();
}
private void paintPie(Graphics g, Rectangle rectangle, double ad[], int i)
{
if(rectangle == null || rectangle.width <= 0 || rectangle.height <= 0)
return;
int j = Math.min(rectangle.width, rectangle.height);
int k = j;
int l = k;
int j1 = rectangle.x + rectangle.width / 2;
int k1 = rectangle.y + rectangle.height / 2;
Font font = getFont("pieLabelFont");
if(font != null)
g.setFont(font);
else
g.setFont(getFont());
FontMetrics fontmetrics = g.getFontMetrics();
boolean flag = is3DModeOn();
if(flag)
{
int l1 = (int)Math.round((double)j * ((double)pieAngle / 90D));
k -= l1;
int i2 = (int)Math.round((double)j * pieDepth * ((double)pieAngle / 90D));
int i1 = k + i2;
k1 -= i2 / 2;
double d1 = (double)rectangle.width / (double)j;
int i3 = (int)Math.round((double)j * d1);
int l3 = (int)Math.round((double)k * d1);
i2 = (int)Math.round((double)i3 * pieDepth * ((double)pieAngle / 90D));
i1 = l3 + i2;
k1 = (rectangle.y + rectangle.height / 2) - i2 / 2;
if(k1 - l3 / 2 < rectangle.y)
{
double d6 = (double)l3 / (double)i1;
i1 = rectangle.height;
l3 = (int)Math.round((double)i1 * d6);
int j2 = rectangle.height - l3;
double d2 = (double)j / (double)k;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -