home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Cursor;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.MediaTracker;
- import java.net.URL;
- import java.util.Enumeration;
- import java.util.Hashtable;
- import netscape.javascript.JSObject;
-
- public class Outline extends Applet {
- private static final Font theFont = new Font("Helvetica", 0, 11);
- private transient Hashtable leafAtRow = new Hashtable();
- private int selectedRow = -1;
- private transient boolean jdk10 = true;
- private String dataFile;
- // $FF: renamed from: fd FolderData
- private FolderData field_0;
- private String iconFile;
- private String target = "_self";
- private boolean useWarnings = false;
- private String jsFunction = "";
- private Color colBack;
- private Color colFore;
- private Color colText;
- private Color colLink;
- private Color colSelect;
- private transient int rowNo;
- private transient long timeLastClicked;
- private transient int lastRowClicked;
- private transient Image imgGraphics;
- private transient int iconHeight;
- private transient int iconWidth;
-
- public Outline() {
- this.colBack = Color.white;
- this.colFore = Color.gray;
- this.colText = Color.black;
- this.colLink = new Color(0, 0, 128);
- this.colSelect = new Color(0, 0, 128);
- this.timeLastClicked = 0L;
- this.lastRowClicked = -1;
- this.iconHeight = 16;
- this.iconWidth = 16;
- if (!System.getProperty("java.version").substring(0, 3).equals("1.0")) {
- try {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
- this.jdk10 = false;
- } catch (Exception var2) {
- this.jdk10 = true;
- }
- } else {
- this.jdk10 = true;
- }
-
- }
-
- public String getAppletInfo() {
- return "Name:\t\tOutline Tree Control\r\nAuthor:\t\tDavid Griffiths\r\nAvailable from:\thttp://www.demon.co.uk/davidg\r\nCreated with Sun JDK 1.1";
- }
-
- public String getDataFile() {
- return this.dataFile;
- }
-
- public void setDataFile(String dataFile) {
- this.dataFile = dataFile;
- if (this.getIconFile() != null) {
- this.field_0 = new FolderData(this.getDataFile(), this.getIcon(this.getIconFile(), 3), this.getIcon(this.getIconFile(), 2), this.getIcon(this.getIconFile(), 0), this.getIcon(this.getIconFile(), 1), this.getTarget(), this);
- }
-
- }
-
- public String getIconFile() {
- return this.iconFile;
- }
-
- public void setIconFile(String iconFile) {
- this.iconFile = iconFile;
- if (this.getDataFile() != null) {
- this.field_0 = new FolderData(this.getDataFile(), this.getIcon(this.getIconFile(), 3), this.getIcon(this.getIconFile(), 2), this.getIcon(this.getIconFile(), 0), this.getIcon(this.getIconFile(), 1), this.getTarget(), this);
- }
-
- }
-
- public String getTarget() {
- return this.target;
- }
-
- public void setTarget(String target) {
- this.target = target;
- }
-
- public void setWarnings(String warnings) {
- warnings = warnings.toLowerCase();
- if (!warnings.equals("true") && !warnings.equals("on") && !warnings.equals("1") && !warnings.equals("yes")) {
- this.setWarnings(false);
- } else {
- this.setWarnings(true);
- }
-
- }
-
- public void setWarnings(boolean useWarnings) {
- this.useWarnings = useWarnings;
- }
-
- public void toggleWarnings() {
- this.useWarnings = !this.useWarnings;
- }
-
- public boolean getWarnings() {
- return this.useWarnings;
- }
-
- public void setJSFunction(String jsFunction) {
- this.jsFunction = jsFunction;
- if (jsFunction.equals("")) {
- this.setWarnings(false);
- }
-
- }
-
- public String getJSFunction() {
- return this.jsFunction;
- }
-
- public boolean callWarning(URL href, String frame, String warning) {
- String sHref = href.toString();
- return this.callWarning(sHref, frame, warning);
- }
-
- public boolean callWarning(String href, String frame, String warning) {
- try {
- JSObject window = JSObject.getWindow(this);
- Object[] args = new Object[]{href, frame, warning};
- window.call(this.getJSFunction(), args);
- boolean var6 = true;
- return var6;
- } catch (Exception e) {
- ((Throwable)e).printStackTrace();
- boolean args = false;
- return args;
- }
- }
-
- private void setColBack(Color colBack) {
- this.colBack = colBack;
- ((Component)this).setBackground(this.colBack);
- }
-
- private void setColBackValue(String col) {
- this.setColBack(this.strToCol(col));
- }
-
- private Color getColBack() {
- return this.colBack;
- }
-
- private void setColFore(Color colFore) {
- this.colFore = colFore;
- ((Component)this).setForeground(this.colFore);
- }
-
- private void setColForeValue(String col) {
- this.setColFore(this.strToCol(col));
- }
-
- private Color strToCol(String c) {
- Color strToCol = null;
- if (c != null) {
- strToCol = new Color(Integer.parseInt(c.substring(1), 16));
- }
-
- return strToCol;
- }
-
- private Color getColFore() {
- return this.colFore;
- }
-
- private void setColText(Color colText) {
- this.colText = colText;
- }
-
- private void setColTextValue(String col) {
- this.setColText(this.strToCol(col));
- }
-
- private Color getColText() {
- return this.colText;
- }
-
- private void setColLink(Color colLink) {
- this.colLink = colLink;
- }
-
- private void setColLinkValue(String col) {
- this.setColLink(this.strToCol(col));
- }
-
- private Color getColLink() {
- return this.colLink;
- }
-
- private void setColSelect(Color colSelect) {
- this.colSelect = colSelect;
- }
-
- private void setColSelectValue(String col) {
- this.setColSelect(this.strToCol(col));
- }
-
- private Color getColSelect() {
- return this.colSelect;
- }
-
- public void init() {
- this.setColBackValue(this.getParam("BGCOLOR", "#FFFFFF"));
- this.setColForeValue(this.getParam("FORECOLOR", "#808080"));
- this.setColTextValue(this.getParam("TEXTCOLOR", "#000000"));
- this.setColLinkValue(this.getParam("LINKCOLOR", "#0000C0"));
- this.setColSelectValue(this.getParam("SELECTCOLOR", "#0000C0"));
- this.setTarget(this.getParam("TARGET", "_self"));
- this.setWarnings(this.getParam("WARNINGS", "false"));
- this.setJSFunction(this.getParam("WARNFUNC", ""));
- this.setIconFile(this.getParam("ICONFILE", "icons.gif"));
- this.setDataFile(this.getParam("DATAFILE", "data.xml"));
- System.out.println(this.getAppletInfo());
- }
-
- private String getParam(String name, String dflt) {
- String s = ((Applet)this).getParameter(name);
- if (s == null) {
- s = dflt;
- }
-
- return s;
- }
-
- private void repaintRow(int row) {
- ((Component)this).repaint(0, row * this.iconHeight - 3, ((Component)this).size().width, this.iconHeight + 6);
- }
-
- public void paint(Graphics g) {
- this.drawTree(g);
- }
-
- private void drawTree(Graphics g) {
- this.rowNo = 0;
- this.leafAtRow.clear();
- this.drawBranch(g, this.field_0.getRootFolder());
- }
-
- private void drawBranch(Graphics g, Folder parent) {
- int lastRow = -1;
- Folder f = null;
- int childNo = 0;
- lastRow = this.rowNo;
- this.drawRow(g, parent, this.rowNo++);
- if (parent.hasChildren()) {
- Enumeration children = parent.getSubFolders().elements();
- int count = parent.getSubFolders().size();
- if (parent.isOpen() && count > 0) {
- while(children.hasMoreElements()) {
- f = (Folder)children.nextElement();
- lastRow = this.rowNo;
- if (f.hasChildren() && f.isOpen()) {
- this.drawBranch(g, f);
- } else {
- this.drawRow(g, f, this.rowNo++);
- }
- }
-
- g.setColor(this.getColBack());
- if (!f.hasChildren()) {
- g.drawLine(19 * f.level - 9, (this.rowNo - 1) * this.iconHeight + 11, 19 * f.level - 9, (this.rowNo - 1) * this.iconHeight + 15);
- }
-
- if (lastRow != this.rowNo && f.isOpen()) {
- g.drawLine(19 * f.level - 9, (lastRow + 1) * this.iconHeight, 19 * f.level - 9, this.rowNo * this.iconHeight);
- }
- }
- }
-
- }
-
- public void drawRow(Graphics g, Folder folder, int row) {
- this.leafAtRow.put(String.valueOf("").concat(String.valueOf(row)), folder);
- this.drawConnectors(g, folder, row);
- this.drawIcon(g, folder, row);
- this.drawCaption(g, folder, row);
- }
-
- private void drawCaption(Graphics g, Folder folder, int row) {
- String caption = folder.getText();
- g.setFont(theFont);
- FontMetrics fm = g.getFontMetrics();
- int textHeight = fm.getHeight();
- int textWidth = fm.stringWidth(caption);
- int descent = fm.getDescent();
- if (row == this.selectedRow) {
- g.setColor(this.getColSelect());
- g.fillRect(19 * (folder.level + 1) + 6 - descent, row * this.iconHeight + fm.getDescent(), textWidth + (descent << 1), textHeight);
- g.setColor(this.getColBack());
- } else {
- g.setColor(this.getColBack());
- if (folder.getHRef() != null) {
- g.setColor(this.getColLink());
- } else {
- g.setColor(this.getColText());
- }
- }
-
- g.drawString(caption, 19 * (folder.level + 1) + 6, row * this.iconHeight + textHeight - 1);
- if (folder.getHRef() != null) {
- g.drawLine(19 * (folder.level + 1) + 6, row * this.iconHeight + textHeight + 1, 19 * (folder.level + 1) + 6 + fm.stringWidth(caption), row * this.iconHeight + textHeight + 1);
- }
-
- }
-
- private void drawConnectors(Graphics g, Folder folder, int row) {
- g.setColor(this.getColFore());
-
- for(int i = 0; i < folder.level - 1; ++i) {
- for(int j = row * this.iconHeight; j < (row + 1) * this.iconHeight; j += 2) {
- g.drawLine(19 * i + 10, j, 19 * i + 10, j);
- }
- }
-
- if (folder.isOpen() && folder.hasChildren()) {
- for(int j = row * this.iconHeight; j < row * this.iconHeight + 8; j += 2) {
- g.drawLine(19 * folder.level - 9, j, 19 * folder.level - 9, j);
- }
- } else {
- for(int j = row * this.iconHeight; j < (row + 1) * this.iconHeight; j += 2) {
- g.drawLine(19 * folder.level - 9, j, 19 * folder.level - 9, j);
- }
- }
-
- if (folder.level > 0) {
- for(int i = 19 * folder.level - 7; i < 19 * folder.level + 2; i += 2) {
- g.drawLine(i, row * this.iconHeight + 10, i, row * this.iconHeight + 10);
- }
- }
-
- }
-
- private void drawIcon(Graphics g, Folder folder, int row) {
- if (folder.hasChildren()) {
- g.setColor(this.getColFore());
- g.drawRect(19 * folder.level - 13, row * this.iconHeight + 6, 8, 8);
- g.setColor(this.getColText());
- g.drawLine(19 * folder.level - 11, row * this.iconHeight + 10, 19 * folder.level - 7, row * this.iconHeight + 10);
- if (!folder.isOpen()) {
- g.drawLine(19 * folder.level - 9, row * this.iconHeight + 8, 19 * folder.level - 9, row * this.iconHeight + 12);
- }
- }
-
- g.drawImage(folder.getIcon(), 19 * (folder.level + 1) - 17, row * this.iconHeight, this);
- }
-
- public boolean mouseUp(Event event, int i, int j) {
- int row = j / this.iconHeight;
- int col = i / 19;
- int oldSelectedRow = this.selectedRow;
- if (row == this.lastRowClicked && System.currentTimeMillis() - this.timeLastClicked < (long)300) {
- this.timeLastClicked = 0L;
- } else {
- this.timeLastClicked = System.currentTimeMillis();
- this.lastRowClicked = row;
- if (this.leafAtRow.containsKey(String.valueOf("").concat(String.valueOf(row)))) {
- Folder f = (Folder)this.leafAtRow.get(String.valueOf("").concat(String.valueOf(row)));
- int indentLevel = f.level;
- boolean clickedPlusMinus = col == indentLevel - 2;
- if (!clickedPlusMinus) {
- this.selectedRow = row;
- }
-
- this.repaintRow(oldSelectedRow);
- if ((clickedPlusMinus || this.selectedRow == row) && f.hasChildren()) {
- f.toggleOpen();
- ((Component)this).repaint(0, row * this.iconHeight - 3, ((Component)this).size().width, ((Component)this).size().height);
- } else {
- this.repaintRow(this.selectedRow);
- }
-
- if (f.getHRef() != null && !clickedPlusMinus) {
- if (this.getWarnings() && f.getWarning() != null) {
- if (!this.callWarning(f.getHRef(), f.getTarget(), f.getWarning())) {
- ((Applet)this).getAppletContext().showDocument(f.getHRef(), f.getTarget());
- }
- } else {
- ((Applet)this).getAppletContext().showDocument(f.getHRef(), f.getTarget());
- }
- }
- }
- }
-
- return true;
- }
-
- public boolean mouseMove(Event event, int i, int j) {
- if (!this.jdk10) {
- int row = j / this.iconHeight;
- if (this.leafAtRow.containsKey(String.valueOf("").concat(String.valueOf(row)))) {
- Folder f = (Folder)this.leafAtRow.get(String.valueOf("").concat(String.valueOf(row)));
- if (f.getHRef() != null) {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(12));
- ((Applet)this).showStatus(String.valueOf("").concat(String.valueOf(f.getHRef())));
- } else {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
- ((Applet)this).showStatus("");
- }
- } else {
- ((Component)this).setCursor(Cursor.getPredefinedCursor(0));
- ((Applet)this).showStatus("");
- }
- }
-
- return true;
- }
-
- private Image initIcons(String iconFile) {
- Image getIcon = null;
-
- try {
- getIcon = ((Applet)this).getImage(((Applet)this).getCodeBase(), iconFile);
- MediaTracker mt = new MediaTracker(this);
- mt.addImage(getIcon, 0);
- mt.waitForID(0);
- this.iconHeight = getIcon.getHeight(this) / 4;
- this.iconWidth = getIcon.getWidth(this);
- } catch (InterruptedException var4) {
- ((Applet)this).showStatus(String.valueOf(String.valueOf("Error occurred whilst loading ").concat(String.valueOf(this.getIconFile()))).concat(String.valueOf(" file")));
- }
-
- return getIcon;
- }
-
- private Image getIcon(String iconFile, int icon) {
- if (this.imgGraphics == null) {
- this.imgGraphics = this.initIcons(iconFile);
- }
-
- Image getIcon = ((Component)this).createImage(this.iconWidth, this.iconHeight);
- Graphics gDec = getIcon.getGraphics();
- gDec.setColor(this.getColBack());
- gDec.fillRect(0, 0, this.iconWidth, this.iconHeight);
- gDec.drawImage(this.imgGraphics, 0, -this.iconHeight * icon, this);
- return getIcon;
- }
- }
-