home *** CD-ROM | disk | FTP | other *** search
- import allaire.dcf.recordset.AppletParamRecordset;
- import allaire.dcf.recordset.Query;
- import allaire.dcf.recordset.Recordset;
- import allaire.util.Debug;
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.util.Date;
- import java.util.Vector;
-
- public class AreaChart extends Applet implements Runnable {
- static final int PARAMS = 1;
- static final int TEMPLATE = 2;
- static final Color[] defaultColors;
- Thread runner;
- Query query;
- int refreshTime;
- boolean debugInfoEnabled;
- String title;
- String titleFontName;
- Font titleFont;
- FontMetrics titleFontMetrics;
- int titleFontHeight;
- String legendFontName;
- Font legendFont;
- FontMetrics legendFontMetrics;
- int legendFontHeight;
- int legendHeight;
- int legendWidth;
- boolean legendEnabled;
- int orientation;
- int shadow;
- boolean barBorderEnabled;
- boolean showDateTime;
- boolean isCumulative;
- String currentDateTime;
- Color backgroundColor;
- Color fontColor;
- Color lineColor;
- Vector items;
- Vector pointerToItems;
- Recordset chartData;
- int rowCount;
- int groupCount;
- int itemCount;
- int maxItemLabelWidth;
- int maxGroupLabelWidth;
- double maxGroupSum;
-
- public void start() {
- if (this.runner == null) {
- this.runner = new Thread(this);
- this.runner.start();
- }
-
- }
-
- public void stop() {
- if (this.runner != null) {
- this.runner.stop();
- this.runner = null;
- }
-
- }
-
- private void getData(int var1) {
- try {
- switch (var1) {
- case 1:
- this.chartData = new AppletParamRecordset(this, "ChartData");
- break;
- case 2:
- this.query.execute();
- this.chartData = this.query.getRecordset();
- }
-
- if (this.refreshTime == 0) {
- ((Applet)this).getAppletContext().showStatus("Done");
- } else {
- ((Applet)this).getAppletContext().showStatus("...");
- }
-
- this.rowCount = this.chartData.getRowCount();
- if (this.rowCount != 0) {
- this.maxGroupSum = (double)0.0F;
- double var7 = (double)0.0F;
-
- for(int var2 = 0; var2 < this.rowCount; ++var2) {
- double var5;
- try {
- var5 = Math.abs(new Double(this.chartData.getData(var2 + 1, "Values")));
- } catch (Exception var11) {
- var5 = (double)0.0F;
- }
-
- if (var2 == 0) {
- this.groupCount = this.itemCount = 1;
- this.pointerToItems.setSize(this.rowCount);
- this.pointerToItems.setElementAt(new Integer(this.itemCount - 1), var2);
- this.items.setSize(this.itemCount);
- this.items.setElementAt(new Item(this.chartData.getData(var2 + 1, "Items")), this.itemCount - 1);
- this.maxItemLabelWidth = this.legendFontMetrics.stringWidth(this.chartData.getData(var2 + 1, "Items"));
- this.maxGroupLabelWidth = this.legendFontMetrics.stringWidth(this.chartData.getData(var2 + 1, "Groups"));
- } else {
- if (!this.chartData.getData(var2 + 1, "Groups").equals(this.chartData.getData(var2, "Groups"))) {
- if (this.maxGroupSum < var7) {
- this.maxGroupSum = var7;
- }
-
- this.maxGroupLabelWidth = Math.max(this.legendFontMetrics.stringWidth(this.chartData.getData(var2 + 1, "Groups")), this.maxGroupLabelWidth);
- if (!this.isCumulative) {
- var7 = (double)0.0F;
- }
-
- ++this.groupCount;
- }
-
- boolean var4 = false;
-
- for(int var3 = 0; var3 < var2; ++var3) {
- if (this.chartData.getData(var2 + 1, "Items").equals(this.chartData.getData(var3 + 1, "Items"))) {
- var4 = true;
- this.pointerToItems.setElementAt(this.pointerToItems.elementAt(var3), var2);
- break;
- }
- }
-
- if (!var4) {
- ++this.itemCount;
- this.pointerToItems.setElementAt(new Integer(this.itemCount - 1), var2);
- this.items.setSize(this.itemCount);
- this.items.setElementAt(new Item(this.chartData.getData(var2 + 1, "Items")), this.itemCount - 1);
- this.maxItemLabelWidth = Math.max(this.legendFontMetrics.stringWidth(this.chartData.getData(var2 + 1, "Items")), this.maxItemLabelWidth);
- }
- }
-
- var7 += var5;
- }
-
- if (this.maxGroupSum < var7) {
- this.maxGroupSum = var7;
- }
-
- for(int var13 = 0; var13 < this.itemCount; ++var13) {
- if (var13 < 9) {
- ((Item)this.items.elementAt(var13)).color = defaultColors[var13];
- } else if (var13 < 18) {
- ((Item)this.items.elementAt(var13)).color = defaultColors[var13 - 9].darker();
- } else if (var13 < 27) {
- ((Item)this.items.elementAt(var13)).color = defaultColors[var13 - 18].darker().darker();
- } else {
- ((Item)this.items.elementAt(var13)).color = Color.black;
- }
- }
- }
-
- this.currentDateTime = (new Date()).toLocaleString();
- } catch (Exception var12) {
- if (this.debugInfoEnabled) {
- Debug.write(((Throwable)var12).getMessage());
- }
-
- }
- }
-
- public boolean mouseExit(Event var1, int var2, int var3) {
- if (var1.id == 505) {
- ((Applet)this).getAppletContext().showStatus("");
- return true;
- } else {
- return false;
- }
- }
-
- static {
- defaultColors = new Color[]{Color.red, Color.blue, Color.green, Color.yellow, Color.magenta, Color.cyan, Color.orange, Color.pink, Color.darkGray};
- }
-
- private void pause(int var1) {
- try {
- Thread.sleep((long)var1);
- } catch (InterruptedException var4) {
- if (this.debugInfoEnabled) {
- Debug.write(((Throwable)var4).getMessage());
- }
-
- }
- }
-
- public boolean mouseEnter(Event var1, int var2, int var3) {
- if (var1.id == 504) {
- ((Applet)this).getAppletContext().showStatus("(c)1996 Allaire Corp.");
- return true;
- } else {
- return false;
- }
- }
-
- public void run() {
- while(this.refreshTime != 0) {
- this.pause(this.refreshTime * 1000);
- this.getData(2);
- ((Component)this).repaint();
- }
-
- this.stop();
- }
-
- public synchronized void init() {
- String var1 = ((Applet)this).getParameter("RefreshTime");
- if (var1 == null) {
- this.refreshTime = 0;
- } else {
- this.refreshTime = Integer.parseInt(var1);
- var1 = ((Applet)this).getParameter("RefreshDataFromURL");
- if (var1 == null) {
- this.refreshTime = 0;
- } else {
- if (var1.indexOf(63) == -1) {
- var1 = var1 + '?';
- }
-
- this.query = new Query(var1);
- this.query.addParam("RefreshTime", String.valueOf(this.refreshTime));
- }
- }
-
- var1 = ((Applet)this).getParameter("DebugInfoEnabled");
- if (var1 == null) {
- this.debugInfoEnabled = false;
- } else if (var1.toLowerCase().equals("yes")) {
- this.debugInfoEnabled = true;
- } else {
- this.debugInfoEnabled = false;
- }
-
- this.title = ((Applet)this).getParameter("Title");
- if (this.title == null) {
- this.title = "Chart";
- }
-
- this.titleFontName = ((Applet)this).getParameter("TitleFontName");
- if (this.titleFontName == null) {
- this.titleFontName = "TimesRoman";
- }
-
- var1 = ((Applet)this).getParameter("TitleFontHeight");
- if (var1 == null) {
- this.titleFontHeight = 12;
- } else {
- this.titleFontHeight = Integer.parseInt(var1);
- }
-
- this.legendFontName = ((Applet)this).getParameter("LegendFontName");
- if (this.legendFontName == null) {
- this.legendFontName = "TimesRoman";
- }
-
- var1 = ((Applet)this).getParameter("ShowLegend");
- if (var1 == null) {
- this.legendEnabled = true;
- } else if (var1.toLowerCase().equals("yes")) {
- this.legendEnabled = true;
- } else {
- this.legendEnabled = false;
- }
-
- var1 = ((Applet)this).getParameter("LegendFontHeight");
- if (var1 == null) {
- this.legendFontHeight = 10;
- } else {
- this.legendFontHeight = Integer.parseInt(var1);
- }
-
- var1 = ((Applet)this).getParameter("DrawBorders");
- if (var1 == null) {
- this.barBorderEnabled = true;
- } else if (var1.toLowerCase().equals("yes")) {
- this.barBorderEnabled = true;
- } else {
- this.barBorderEnabled = false;
- }
-
- var1 = ((Applet)this).getParameter("ShowDateTime");
- if (var1 == null) {
- this.showDateTime = true;
- } else if (var1.toLowerCase().equals("yes")) {
- this.showDateTime = true;
- } else {
- this.showDateTime = false;
- }
-
- var1 = ((Applet)this).getParameter("Cumulative");
- if (var1 == null) {
- this.isCumulative = false;
- } else if (var1.toLowerCase().equals("yes")) {
- this.isCumulative = true;
- } else {
- this.isCumulative = false;
- }
-
- var1 = ((Applet)this).getParameter("BackgroundColor");
- if (var1 == null) {
- this.backgroundColor = ((Component)this).getBackground();
- } else {
- this.backgroundColor = new Color(Integer.valueOf(var1, 16));
- }
-
- var1 = ((Applet)this).getParameter("FontColor");
- if (var1 == null) {
- this.fontColor = Color.black;
- } else {
- this.fontColor = new Color(Integer.valueOf(var1, 16));
- }
-
- var1 = ((Applet)this).getParameter("GridLineColor");
- if (var1 == null) {
- this.lineColor = Color.gray;
- } else {
- this.lineColor = new Color(Integer.valueOf(var1, 16));
- }
-
- ((Component)this).setBackground(this.backgroundColor);
- this.titleFont = new Font(this.titleFontName, 1, this.titleFontHeight);
- this.titleFontMetrics = ((Component)this).getFontMetrics(this.titleFont);
- this.legendFont = new Font(this.legendFontName, 0, this.legendFontHeight);
- this.legendFontMetrics = ((Component)this).getFontMetrics(this.legendFont);
- this.pointerToItems = new Vector();
- this.items = new Vector();
- this.getData(1);
- }
-
- public synchronized void paint(Graphics var1) {
- int[] var32 = new int[5];
- int[] var33 = new int[5];
- if (this.itemCount > 0) {
- if (this.maxGroupSum == (double)0.0F) {
- this.maxGroupSum = (double)1.0F;
- }
-
- int var4 = ((Component)this).size().width / 15;
- int var5 = ((Component)this).size().height / 15;
- double var12 = Math.pow((double)10.0F, Math.floor(Math.log(this.maxGroupSum) / Math.log((double)10.0F)));
- if (this.maxGroupSum / var12 < (double)2.0F) {
- var12 /= (double)5.0F;
- }
-
- if (this.maxGroupSum / var12 < (double)5.0F) {
- var12 /= (double)2.0F;
- }
-
- var1.setColor(this.fontColor);
- var1.setFont(this.titleFont);
- var1.drawString(this.title, Math.max((((Component)this).size().width - this.titleFontMetrics.stringWidth(this.title)) / 2, 0), ((Component)this).size().height - var5);
- var1.setFont(this.legendFont);
- if (this.showDateTime) {
- var1.drawString("(as of " + this.currentDateTime + ")", Math.max((((Component)this).size().width - this.legendFontMetrics.stringWidth("(as of " + this.currentDateTime + ")")) / 2, 0), ((Component)this).size().height - var5 + this.legendFontHeight * 3 / 2);
- }
-
- int var25;
- if (this.legendEnabled) {
- int var44 = Math.min((((Component)this).size().height - this.titleFontHeight - 3 * var5) / this.legendFontHeight, this.itemCount);
- int var45 = (((Component)this).size().height - this.titleFontHeight - 3 * var5) / var44;
- if (var45 > 2 * this.titleFontHeight) {
- var45 = 2 * this.titleFontHeight;
- }
-
- var25 = this.legendFontHeight * 2 + this.maxItemLabelWidth + var4;
- int var43 = var44 * var45;
- int var8 = ((Component)this).size().width - var25;
- int var9 = (((Component)this).size().height - 3 * var5 - this.titleFontHeight - var43) / 2 + var5;
- var1.drawRect(var8 - this.legendFontHeight, var9 - var45 / 2, var25 - var4 + 2 * this.legendFontHeight, var43 + var45 / 2);
-
- for(int var2 = 0; var2 < var44; ++var2) {
- var1.setColor(((Item)this.items.elementAt(var2)).color);
- var1.fillRect(var8, var9, this.legendFontHeight, this.legendFontHeight);
- if (this.barBorderEnabled) {
- var1.setColor(this.fontColor);
- var1.drawRect(var8, var9, this.legendFontHeight - 1, this.legendFontHeight - 1);
- }
-
- var1.setColor(this.fontColor);
- var1.drawString(((Item)this.items.elementAt(var2)).label, var8 + 2 * this.legendFontHeight, var9 + this.legendFontHeight - 1);
- var9 += var45;
- }
- } else {
- boolean var28 = false;
- boolean var27 = false;
- boolean var26 = false;
- var25 = 0;
- }
-
- int var23 = ((Component)this).size().width - 2 * var4 - var25;
- int var24 = ((Component)this).size().height - this.titleFontHeight - this.legendFontHeight - 3 * var5;
- double var10 = Math.max((double)var24 / this.maxGroupSum, (double)0.0F);
- int var22 = Math.max(var23 / this.groupCount, 2);
- int var6 = var4;
- int var7 = var5 + var24;
-
- for(double var14 = (double)0.0F; var14 < this.maxGroupSum; var14 += var12) {
- var1.setColor(this.lineColor);
- var1.drawLine(var6, var7 - (int)(var10 * var14), var6 + var23, var7 - (int)(var10 * var14));
- var1.drawString("" + var14, var6 - this.legendFontMetrics.stringWidth("" + var14) - 2, var7 - (int)(var10 * var14) + this.legendFontHeight / 2);
- }
-
- var6 += var22 / 2;
- double var20 = (double)0.0F;
- double var18 = (double)0.0F;
- String var30 = "";
- boolean var31 = true;
- var33[0] = var33[3] = var33[1] = var33[2] = var7;
- var32[0] = var32[1] = var32[2] = var32[3] = var6;
- var32[4] = var32[0];
- var33[4] = var33[0];
- double var16 = (double)0.0F;
-
- for(int var3 = 0; var3 < this.itemCount; ++var3) {
- ((Item)this.items.elementAt(var3)).value = (double)0.0F;
- ((Item)this.items.elementAt(var3)).previousValue = (double)0.0F;
- }
-
- for(int var38 = 0; var38 < this.rowCount; ++var38) {
- int var34 = (Integer)this.pointerToItems.elementAt(var38);
-
- String var29;
- try {
- var29 = this.chartData.getData(var38 + 1, "Groups");
- } catch (Exception var37) {
- var29 = "";
- }
-
- if (var38 > 0 && !var29.equals(var30)) {
- for(int var39 = 0; var39 < this.itemCount; ++var39) {
- var33[0] = var33[1];
- var33[3] = var33[2];
- var33[2] -= (int)((double)0.5F + Math.abs(var10 * ((Item)this.items.elementAt(var39)).value));
- var33[1] -= (int)((double)0.5F + Math.abs(var10 * ((Item)this.items.elementAt(var39)).previousValue));
- var32[4] = var32[0];
- var33[4] = var33[0];
- if (!var31) {
- var1.setColor(((Item)this.items.elementAt(var39)).color);
- var1.fillPolygon(var32, var33, 5);
- if (this.barBorderEnabled) {
- var1.setColor(this.fontColor);
- var1.drawPolygon(var32, var33, 5);
- }
- }
-
- if (!this.isCumulative) {
- ((Item)this.items.elementAt(var39)).copyValueAndReset();
- } else {
- ((Item)this.items.elementAt(var39)).copyValue();
- }
- }
-
- if (this.legendFontMetrics.stringWidth(var30) > var22) {
- var30 = var30.substring(0, var30.length() * var22 / this.legendFontMetrics.stringWidth(var30));
- }
-
- if (!var31) {
- var1.setColor(this.fontColor);
- if (!this.isCumulative) {
- var1.drawString("" + var20, var32[1] - this.legendFontMetrics.stringWidth("" + var20) / 2, var33[1] - 5);
- } else {
- var1.drawString("" + var20, var32[1] - this.legendFontMetrics.stringWidth("" + var20), var33[1] - 2);
- }
- }
-
- var1.setColor(this.fontColor);
- var1.drawString(var30, var6 - this.legendFontMetrics.stringWidth(var30) / 2, var7 + this.legendFontHeight);
- var6 += var22;
- var20 = var18;
- if (!this.isCumulative) {
- var18 = (double)0.0F;
- }
-
- var32[0] = var32[1] = var6 - var22;
- var32[2] = var32[3] = var6;
- var33[0] = var33[3] = var33[1] = var33[2] = var7;
- var32[4] = var32[0];
- var33[4] = var33[0];
- var31 = false;
- }
-
- var30 = var29;
-
- try {
- var16 = new Double(this.chartData.getData(var38 + 1, "Values"));
- } catch (Exception var36) {
- var16 = (double)0.0F;
- }
-
- var18 += Math.abs(var16);
- Item var10000 = (Item)this.items.elementAt(var34);
- var10000.value += var16;
- }
-
- for(int var40 = 0; var40 < this.itemCount; ++var40) {
- var33[0] = var33[1];
- var33[3] = var33[2];
- var33[2] -= (int)((double)0.5F + Math.abs(var10 * ((Item)this.items.elementAt(var40)).value));
- var33[1] -= (int)((double)0.5F + Math.abs(var10 * ((Item)this.items.elementAt(var40)).previousValue));
- var32[4] = var32[0];
- var33[4] = var33[0];
- var1.setColor(((Item)this.items.elementAt(var40)).color);
- var1.fillPolygon(var32, var33, 5);
- if (this.barBorderEnabled) {
- var1.setColor(this.fontColor);
- var1.drawPolygon(var32, var33, 5);
- }
- }
-
- if (this.legendFontMetrics.stringWidth(var30) > var22) {
- var30 = var30.substring(0, var30.length() * var22 / this.legendFontMetrics.stringWidth(var30));
- }
-
- var1.setColor(this.fontColor);
- if (!this.isCumulative) {
- var1.drawString("" + var20, var32[1] - this.legendFontMetrics.stringWidth("" + var20) / 2, var33[1] - 5);
- var1.drawString("" + var18, var32[2] - this.legendFontMetrics.stringWidth("" + var18) / 2, var33[2] - 5);
- } else {
- var1.drawString("" + var20, var32[1] - this.legendFontMetrics.stringWidth("" + var20), var33[1] - 2);
- var1.drawString("" + var18, var32[2] - this.legendFontMetrics.stringWidth("" + var18), var33[2] - 2);
- }
-
- var1.drawString(var30, var6 - this.legendFontMetrics.stringWidth(var30) / 2, var7 + this.legendFontHeight);
- }
-
- }
- }
-