📄 chartapplet.java
字号:
// Decompiled by DJ v2.9.9.60 Copyright 2000 Atanas Neshkov Date: 2002-12-21 10:58:01
// Home Page : http://members.fortunecity.com/neshkov/dj.html - Check often for new version!
// Decompiler options: packimports(3)
// Source File Name: ChartApplet.java
package cn.com.fcsoft.chart;
import java.applet.Applet;
import java.applet.AppletContext;
import java.awt.*;
import java.awt.event.*;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
// Referenced classes of package com.objectplanet.chart:
// ChartSample, Chart, LineChartApplet, BarChartApplet,
// PieChartApplet, NonFlickerPanel
public abstract class ChartApplet extends Applet
implements Runnable, ItemListener, MouseMotionListener
{
public void stop()
{
if(refreshThread != null)
{
refreshThread.stop();
refreshThread = null;
}
}
protected Color[] getColorValues(String s)
{
Color acolor[] = null;
if(s != null)
{
StringTokenizer stringtokenizer = new StringTokenizer(s, ",");
acolor = new Color[stringtokenizer.countTokens()];
for(int i = 0; i < acolor.length; i++)
if(stringtokenizer.hasMoreTokens())
acolor[i] = createColor(stringtokenizer.nextToken().trim());
}
return acolor;
}
private URL getSampleURL(int i, int j, int k)
{
String s = createURLParam("url", j, k);
URL url = (URL)urlList.get(s);
if(url == null)
{
String s1;
if(i > 1)
s1 = createURLParam("url", j, -1);
else
s1 = createURLParam("url", -1, k);
url = (URL)urlList.get(s1);
}
if(url == null)
url = (URL)urlList.get(createURLParam("url", -1, -1));
return url;
}
public void reset()
{
urlList = new Hashtable();
urlTargetList = new Hashtable();
HAND_CURSOR = new Cursor(12);
POINT_CURSOR = new Cursor(0);
lastSelectedSample = -1;
lastSelectedSeries = -1;
theChart.reset();
}
public void mouseDragged(MouseEvent mouseevent)
{
}
public ChartApplet()
{
labelDelimiter = ",";
automaticRefreshTime = 2500;
rangeStep = new double[2];
theChart = createChart(null);
overlayChartApplets = new Vector();
prefix = "";
setLayout(new BorderLayout());
theChart.addItemListener(this);
theChart.addMouseMotionListener(this);
}
public void itemStateChanged(ItemEvent itemevent)
{
ChartSample chartsample = (ChartSample)itemevent.getItem();
Chart chart = (Chart)itemevent.getSource();
if(itemevent.getStateChange() == 1 && chartsample != null && chart != null)
{
int i = chart.getSeriesCount();
int j = chartsample.getIndex();
int k = chartsample.getSeries();
long l = System.currentTimeMillis();
boolean flag = j == lastSelectedSample && k == lastSelectedSeries;
if(flag && l - lastSelectedTime < 350L)
{
URL url = getSampleURL(i, k, j);
if(url != null)
{
String s = createURLParam("urltarget", k, j);
String s1 = (String)urlTargetList.get(s);
if(s1 == null)
{
String s2;
if(i > 1)
s2 = createURLParam("urltarget", k, -1);
else
s2 = createURLParam("urltarget", -1, j);
s1 = (String)urlTargetList.get(s2);
}
if(s1 == null)
s1 = (String)urlTargetList.get("urltarget");
AppletContext appletcontext = getAppletContext();
if(appletcontext != null)
appletcontext.showDocument(url, s1);
}
}
lastSelectedSample = j;
lastSelectedSeries = k;
lastSelectedTime = l;
}
}
public void mouseMoved(MouseEvent mouseevent)
{
if(urlList.size() == 0)
return;
Chart chart = (Chart)mouseevent.getSource();
ChartSample chartsample = chart.checkSelection(new Point(mouseevent.getX(), mouseevent.getY()));
int i = chart.getSeriesCount();
Cursor cursor = POINT_CURSOR;
if(chartsample != null)
{
URL url = getSampleURL(i, chartsample.getSeries(), chartsample.getIndex());
if(url != null)
cursor = HAND_CURSOR;
}
setCursor(cursor);
}
private boolean shouldSet(String s, boolean flag)
{
String s1 = getParameter(s);
return s1 != null && s1.trim().length() > 0 || flag;
}
static String convertLineBreaks(String s)
{
if(s == null)
return null;
char ac[] = s.toCharArray();
char ac1[] = new char[ac.length];
int i = 0;
for(int j = 0; j < ac.length; j++)
if(j < ac.length - 1 && ac[j] == '\\' && ac[j + 1] == 'n')
{
ac1[i++] = '\n';
j++;
} else
{
ac1[i++] = ac[j];
}
return new String(ac1, 0, i);
}
private static int getFontType(String s)
{
s = s.toLowerCase().trim();
if(s.equals("bold"))
return 1;
if(s.equals("italic"))
return 2;
else
return s.equals("bolditalic") || s.equals("italicbold") ? 3 : 0;
}
public void setParentApplet(Applet applet)
{
if(applet == this)
applet = null;
parentApplet = applet;
}
protected static Color createColor(String s)
{
if(s == null || s.length() == 0)
return null;
if(s.indexOf(",") >= 0)
{
StringTokenizer stringtokenizer = new StringTokenizer(s, ", ");
try
{
return new Color(Integer.parseInt(stringtokenizer.nextToken()), Integer.parseInt(stringtokenizer.nextToken()), Integer.parseInt(stringtokenizer.nextToken()));
}
catch(Exception exception1)
{
System.out.println("Invalid RGB color: " + s);
}
} else
if(s.startsWith("#"))
{
try
{
return new Color(Integer.parseInt(s.substring(1, 3), 16), Integer.parseInt(s.substring(3, 5), 16), Integer.parseInt(s.substring(5, 7), 16));
}
catch(Exception exception)
{
System.out.println("Invalid hex color: " + s);
}
} else
{
s = s.toLowerCase();
if(s.equals("black"))
return Color.black;
if(s.equals("blue"))
return Color.blue;
if(s.equals("cyan"))
return Color.cyan;
if(s.equals("darkgray"))
return Color.darkGray;
if(s.equals("gray"))
return Color.gray;
if(s.equals("green"))
return Color.green;
if(s.equals("lightgray"))
return Color.lightGray;
if(s.equals("magenta"))
return Color.magenta;
if(s.equals("orange"))
return Color.orange;
if(s.equals("pink"))
return Color.pink;
if(s.equals("red"))
return Color.red;
if(s.equals("white"))
return Color.white;
if(s.equals("yellow"))
return Color.yellow;
System.out.println("Invalid color name: " + s);
}
return null;
}
protected void setRangeParameters(boolean flag)
{
if(shouldSet(prefix + "rangeStep", flag))
setParameter("rangeStep", getParameter(prefix + "rangeStep"));
if(shouldSet(prefix + "range", flag))
setParameter("range", getParameter(prefix + "range"));
if(shouldSet(prefix + "lowerRange", flag))
setParameter("lowerRange", getParameter(prefix + "lowerRange"));
setParameter("rangeOn_2", getParameter(prefix + "rangeOn_2"));
if(shouldSet(prefix + "rangeStep_2", flag))
setParameter("rangeStep_2", getParameter(prefix + "rangeStep_2"));
if(shouldSet(prefix + "range_2", flag))
setParameter("range_2", getParameter(prefix + "range_2"));
if(shouldSet(prefix + "lowerRange_2", flag))
setParameter("lowerRange_2", getParameter(prefix + "lowerRange_2"));
initParameter("rangeAdjusterOn", getParameter(prefix + "rangeAdjusterOn"));
initParameter("rangeAdjusterOn_2", getParameter(prefix + "rangeAdjusterOn_2"));
}
public void setParameterPrefix(String s)
{
prefix = s != null ? s : "";
}
public String getParameterPrefix()
{
return prefix;
}
protected abstract Chart createChart(String s);
public void start()
{
if(automaticRefreshTime > 0)
{
refreshThread = new Thread(this);
refreshThread.start();
}
}
private void initParameter(String s, String s1)
{
if(s1 != null)
setParameter(s, s1);
}
protected static Double[] getDoubleValues(String s)
{
Double adouble[] = null;
if(s != null && !s.equals(""))
{
boolean flag = s.trim().startsWith(",");
StringTokenizer stringtokenizer = new StringTokenizer(s, ",");
adouble = new Double[stringtokenizer.countTokens() + (flag ? 1 : 0)];
for(int i = flag ? 1 : 0; i < adouble.length; i++)
try
{
adouble[i] = new Double(stringtokenizer.nextToken());
}
catch(NumberFormatException numberformatexception) { }
}
return adouble;
}
protected String[] getStringValues(String s)
{
String as[] = null;
if(s != null)
{
boolean flag = s.trim().startsWith(labelDelimiter);
StringTokenizer stringtokenizer = new StringTokenizer(s, labelDelimiter);
as = new String[stringtokenizer.countTokens() + (flag ? 1 : 0)];
for(int i = flag ? 1 : 0; i < as.length; i++)
as[i] = stringtokenizer.nextToken();
}
return as;
}
public void setParameter(String s, String s1)
{
if(s == null || theChart == null)
return;
s = s.toLowerCase();
if(s.startsWith("series") && s.endsWith("_values"))
try
{
int i = Integer.parseInt(s.substring(6, s.indexOf("_values")));
s = "sampleValues_" + i;
}
catch(NumberFormatException numberformatexception) { }
if(s.equals("width"))
{
if(s1 != null && s1.trim().length() > 0)
try
{
int j = Integer.parseInt(s1.trim());
setSize(j, theChart.getSize().height);
theChart.setSize(j, theChart.getSize().height);
}
catch(NumberFormatException numberformatexception1)
{
System.out.println("Invalid width: " + s1);
}
} else
if(s.equals("height"))
{
if(s1 != null && s1.trim().length() > 0)
try
{
int k = Integer.parseInt(s1.trim());
setSize(theChart.getSize().width, k);
theChart.setSize(theChart.getSize().width, k);
}
catch(NumberFormatException numberformatexception2)
{
System.out.println("Invalid height: " + s1);
}
} else
if(s.equals("samplevalues"))
{
Double adouble[] = getDoubleValues(s1);
if(adouble != null && s1.trim().length() > 0)
{
int i5 = theChart.getSampleCount();
for(int k6 = 0; k6 < i5; k6++)
if(k6 < adouble.length && adouble[k6] != null)
{
theChart.setSampleValue(0, k6, adouble[k6].doubleValue());
} else
{
ChartSample chartsample = theChart.getSample(0, k6);
if(chartsample != null)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -