home *** CD-ROM | disk | FTP | other *** search
- package com.sfs.html;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.net.URL;
- import java.util.Hashtable;
- import java.util.Stack;
- import java.util.StringTokenizer;
- import java.util.Vector;
-
- class HtmlPager {
- private static final int BUTTON = -1;
- private static final int MARGIN = 20;
- private static final int[] sizes = new int[]{32, 28, 24, 20, 17, 15, 14};
- private int offset;
- private Stack fonts = new Stack();
- private Font font;
- private int spaceWidth;
- private FontMetrics metrics;
- private Stack anchors = new Stack();
- private boolean anchor;
- private int leftMargin = 20;
- private int rightMargin = -20;
- private int center;
- private int preformatted;
- private Stack lists = new Stack();
- private int list = -1;
- private Vector hrefs = new Vector();
- private Hashtable names = new Hashtable();
- private int[] heights;
- private Vector lines = new Vector();
- private HtmlPagerLine line;
- private Href href;
- private boolean lineEmpty = true;
- private boolean prevLineEmpty;
- private URL url;
- private HtmlCanvas parent;
- private int width = -1;
- private Color bgColor;
- private Color textColor;
- private Color linkColor;
- private Stack fontColors = new Stack();
- private Color fontColor;
-
- protected void pushListNumber() {
- this.lists.push(new Integer(this.list));
- this.list += 0;
- }
-
- protected void pushBold() {
- this.pushFont(this.font.getName(), this.font.getStyle() | 1, this.font.getSize());
- }
-
- protected void setBase(URL var1) {
- this.url = var1;
- }
-
- protected void popList() {
- if (this.lists.size() > 0) {
- this.list = (Integer)this.lists.pop();
- }
-
- }
-
- private void finishLine() {
- this.prevLineEmpty = this.lineEmpty;
- if (this.center > 0) {
- this.line.translate((this.rightMargin - this.offset) / 2);
- }
-
- this.line = new HtmlPagerLine();
- this.lines.addElement(this.line);
- this.offset = 0;
- this.addItem(new HtmlPagerItem(this.fontColor, this.font, ""));
- this.offset = this.leftMargin;
- this.lineEmpty = true;
- }
-
- protected void pushPreformatted() {
- this.pushFixedFont();
- this.drawNewLine(true);
- ++this.preformatted;
- this.prevLineEmpty = true;
- }
-
- protected void popPreformatted() {
- this.preformatted += -1;
- this.drawNewLine(true);
- this.popFont();
- }
-
- protected void pushFontColor(Color var1) {
- this.fontColors.push(this.fontColor);
- this.fontColor = var1;
- }
-
- protected void popFontColor() {
- if (this.fontColors.size() > 0) {
- this.fontColor = (Color)this.fontColors.pop();
- }
-
- }
-
- protected Color getFontColor() {
- return this.fontColor;
- }
-
- protected synchronized void drawImage(HtmlImage var1, String var2) {
- Color var3 = this.anchor ? this.linkColor : null;
- this.drawNewLine(var1.w);
- if ("TOP".equalsIgnoreCase(var2)) {
- this.addItem(new HtmlPagerItem(var3, var1, 1));
- } else if ("MIDDLE".equalsIgnoreCase(var2)) {
- this.addItem(new HtmlPagerItem(var3, var1, 0));
- } else {
- this.addItem(new HtmlPagerItem(var3, var1, -1));
- }
-
- this.offset += var1.w;
- }
-
- protected void pushItalic() {
- this.pushFont(this.font.getName(), this.font.getStyle() | 2, this.font.getSize());
- }
-
- protected void pushStandardFont() {
- this.pushFont("TimesRoman", this.font.getStyle(), this.font.getSize());
- }
-
- protected void pushFixedFont() {
- this.pushFont("Courier", this.font.getStyle(), this.font.getSize());
- }
-
- protected void pushLeftMargin(boolean var1) {
- this.leftMargin += 20;
- if (var1) {
- this.drawNewLine(true);
- }
-
- }
-
- protected void finish() {
- int var1 = this.lines.size();
- int[] var2 = new int[var1 + 2];
- var2[0] = 20;
-
- for(int var3 = 0; var3 < var1; ++var3) {
- var2[var3 + 1] = var2[var3] + ((HtmlPagerLine)this.lines.elementAt(var3)).getHeight();
- }
-
- var2[var1 + 1] = var2[var1] + 20;
- Href[] var8 = new Href[this.hrefs.size()];
- this.hrefs.copyInto(var8);
- Vector var4 = new Vector();
- Image var5 = null;
- if (this.width > 0) {
- var5 = this.parent.createImage(this.width, var2[var1 + 1]);
- if (var5 != null) {
- this.parent.setBackground(this.bgColor);
- Graphics var6 = var5.getGraphics();
- var6.setColor(this.bgColor);
- var6.fillRect(0, 0, this.width, var2[var1 + 1]);
-
- for(int var7 = 0; var7 < var1; ++var7) {
- ((HtmlPagerLine)this.lines.elementAt(var7)).draw(var6, var2[var7], var4);
- }
- }
- }
-
- HtmlImage[] var9 = new HtmlImage[var4.size()];
- var4.copyInto(var9);
- this.parent.setData(var2, var8, this.names, var9, var5);
- }
-
- protected void popLeftMargin(boolean var1) {
- this.leftMargin -= 20;
- if (var1) {
- this.drawNewLine(true);
- }
-
- }
-
- protected void pushRightMargin() {
- this.rightMargin -= 20;
- }
-
- protected void popRightMargin() {
- this.rightMargin += 20;
- }
-
- protected HtmlPager(HtmlCanvas var1, int var2) {
- this.width = var2;
- this.parent = var1;
- this.rightMargin += var2;
- this.pushFont("TimesRoman", 0, sizes[6]);
- this.drawNewLine(true);
- this.bgColor = ((Component)var1).getBackground();
- this.textColor = ((Component)var1).getForeground();
- this.linkColor = Color.blue;
- this.fontColor = this.textColor;
- }
-
- protected void drawListItem() {
- int var1 = this.offset;
- this.offset = this.leftMargin - 20;
- if (this.list == -1) {
- this.addItem(new HtmlPagerItem(this.fontColor, this.font, "-"));
- } else {
- this.addItem(new HtmlPagerItem(this.fontColor, this.font, String.valueOf(++this.list)));
- }
-
- this.offset = var1;
- }
-
- protected void drawNewLine(boolean var1) {
- if (this.lineEmpty) {
- this.offset = this.leftMargin;
- }
-
- if (!this.lineEmpty || this.lines.size() != 1) {
- if (this.lineEmpty) {
- if ((this.preformatted > 0 || var1) && !this.prevLineEmpty) {
- this.finishLine();
- return;
- }
- } else {
- this.finishLine();
- if (var1) {
- this.finishLine();
- }
- }
-
- }
- }
-
- private void drawNewLine(int var1) {
- if (this.offset + var1 >= this.rightMargin) {
- this.drawNewLine(false);
- }
-
- }
-
- protected void pushCenter() {
- this.drawNewLine(false);
- ++this.center;
- }
-
- protected void popCenter() {
- this.drawNewLine(false);
- this.center += -1;
- }
-
- protected void pushFontSize(int var1) {
- if (var1 < 0) {
- var1 = 0;
- }
-
- if (var1 >= sizes.length) {
- var1 = sizes.length - 1;
- }
-
- this.pushFont(this.font.getName(), this.font.getStyle(), sizes[var1]);
- }
-
- protected int getFontSize() {
- int var1 = this.font.getSize();
-
- for(int var2 = 0; var2 < sizes.length; ++var2) {
- if (var1 == sizes[var2]) {
- return var2;
- }
- }
-
- return -1;
- }
-
- private void pushFont(String var1, int var2, int var3) {
- this.fonts.push(this.font);
- this.font = new Font(var1, var2, var3);
- this.metrics = this.parent.getFontMetrics(this.font);
- this.spaceWidth = this.metrics.stringWidth(" ");
- }
-
- protected void popFont() {
- if (this.fonts.size() > 1) {
- this.font = (Font)this.fonts.pop();
- this.metrics = this.parent.getFontMetrics(this.font);
- this.spaceWidth = this.metrics.stringWidth(" ");
- }
-
- }
-
- private void addItem(HtmlPagerItem var1) {
- this.line.addItem(this.metrics, this.offset, var1);
- this.lineEmpty = false;
- }
-
- protected void pushAnchor(String var1, String var2) {
- this.anchors.push(new Boolean(this.anchor));
- if (var1 != null) {
- this.anchor = true;
- this.pushFontColor(this.linkColor);
- this.href = new Href();
- this.href.startLine = this.lines.size() - 1;
- this.href.startOffset = this.offset;
-
- try {
- this.href.url = new URL(this.url, var1);
- } catch (Exception var3) {
- this.href.url = null;
- }
- }
-
- if (var2 != null) {
- this.names.put(var2, new Integer(this.lines.size()));
- }
-
- }
-
- protected void popAnchor() {
- if (this.anchors.size() > 0) {
- if (this.anchor) {
- this.href.endLine = this.lines.size() - 1;
- this.href.endOffset = this.offset;
- this.hrefs.addElement(this.href);
- this.href = null;
- }
-
- this.anchor = (Boolean)this.anchors.pop();
- this.popFontColor();
- }
-
- }
-
- protected void pushListButton() {
- this.lists.push(new Integer(this.list));
- this.list = -1;
- }
-
- protected void setColors(Color var1, Color var2, Color var3) {
- if (var1 != null) {
- this.bgColor = var1;
- }
-
- if (var2 != null) {
- this.textColor = var2;
- }
-
- if (var3 != null) {
- this.linkColor = var3;
- }
-
- this.pushFontColor(this.anchor ? this.linkColor : this.textColor);
- }
-
- protected void drawText(String var1) {
- if (this.preformatted > 0) {
- StringTokenizer var5 = new StringTokenizer(var1, "\n", true);
-
- while(var5.hasMoreTokens()) {
- String var6 = var5.nextToken();
- if (var6.equals("\n")) {
- this.drawNewLine(false);
- this.prevLineEmpty = false;
- } else {
- this.addItem(new HtmlPagerItem(this.fontColor, this.font, var6));
- this.offset += this.metrics.stringWidth(var6);
- }
- }
-
- } else {
- if (this.offset > this.leftMargin) {
- this.offset += this.spaceWidth;
- }
-
- StringTokenizer var2;
- int var4;
- for(var2 = new StringTokenizer(var1); var2.hasMoreTokens(); this.offset += var4 + this.spaceWidth) {
- String var3 = var2.nextToken();
- var4 = this.metrics.stringWidth(var3);
- this.drawNewLine(var4);
- this.addItem(new HtmlPagerItem(this.fontColor, this.font, var3));
- }
-
- if (var2.countTokens() > 0) {
- this.offset -= this.spaceWidth;
- }
-
- }
- }
-
- protected void drawRule() {
- this.drawNewLine(false);
- this.addItem(new HtmlPagerItem(this.fontColor, this.rightMargin - this.leftMargin));
- this.drawNewLine(false);
- }
- }
-