home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.Graphics;
- import java.awt.GridLayout;
- import java.awt.Image;
- import java.awt.LayoutManager;
- import java.awt.MediaTracker;
- import java.awt.Panel;
- import java.net.URL;
-
- public class DynaButtons extends Applet {
- protected int orientation;
- protected static final int VERT = 0;
- protected static final int HORIZ = 1;
- protected int textJustification;
- protected int textAlignment;
- protected Image buttonImage;
- protected Image highliteImage;
- protected Color backgroundColor;
- protected Image backgroundImage;
- protected Color fontColor;
- protected Color highliteFontColor;
- protected Font buttonFont;
- protected int numButtons;
- protected String documentBase;
- protected int BUTTON_WIDTH;
- protected int BUTTON_HEIGHT;
- Panel subPanel;
- boolean subPanelUp;
- private int currentButtonNum = -1;
- protected int xOffset;
- protected int yOffset;
-
- protected void getTextJustification() {
- this.textJustification = Integer.parseInt(((Applet)this).getParameter("TextJustification"));
- }
-
- private void getButtonImages() {
- String imageName = this.modifyStringContext(((Applet)this).getParameter("ButtonImage"));
- String highliteName = this.modifyStringContext(((Applet)this).getParameter("HighliteImage"));
-
- try {
- this.buttonImage = ((Applet)this).getImage(new URL(imageName));
- this.highliteImage = ((Applet)this).getImage(new URL(highliteName));
- MediaTracker tracker = new MediaTracker(this);
- tracker.addImage(this.buttonImage, 0);
- tracker.addImage(this.highliteImage, 1);
-
- try {
- tracker.waitForID(0);
- tracker.waitForID(1);
- } catch (InterruptedException var6) {
- return;
- } catch (Exception var7) {
- System.out.println("Error in tracker: " + var7);
- }
-
- this.BUTTON_WIDTH = this.buttonImage.getWidth(this);
- this.BUTTON_HEIGHT = this.buttonImage.getHeight(this);
- } catch (Exception var8) {
- System.out.println("Error loading Button Images: " + var8);
- }
-
- }
-
- protected void getBackgroundImage() {
- String backgroundimage = this.modifyStringContext(((Applet)this).getParameter("BackgroundImage"));
-
- try {
- this.backgroundImage = ((Applet)this).getImage(new URL(backgroundimage));
- } catch (Exception var6) {
- System.out.println("Error forming URL for background image");
- return;
- }
-
- MediaTracker tracker = new MediaTracker(this);
- tracker.addImage(this.backgroundImage, 0);
-
- try {
- tracker.waitForID(0);
- } catch (InterruptedException var5) {
- System.out.println("Background image loading interrupted");
- }
- }
-
- protected void actionMouseDown(PopObject popObject) {
- URL curURL = popObject.getButtonURL();
- String target = popObject.getButtonTarget();
- if (curURL != null) {
- if (target != null) {
- ((Applet)this).getAppletContext().showDocument(curURL, target);
- } else {
- ((Applet)this).getAppletContext().showDocument(curURL);
- }
-
- } else {
- if (!this.subPanelUp) {
- String[] stringList = popObject.getStringList();
- this.subPanel = new Panel();
- this.subPanel.setLayout(new GridLayout(stringList.length, 1));
- int buttonNum = popObject.getButtonNum();
-
- for(int i = 0; i < stringList.length; ++i) {
- URL buttonURL = popObject.getURLList()[i];
- String buttonTarget = popObject.getTargetList()[i];
- PopObject po = new PopObject(-1, buttonURL, buttonTarget, (URL[])null, (String[])null, (String[])null);
- if (this.backgroundColor != null) {
- this.subPanel.add(new PopButton(this, po, stringList[i], this.fontColor, this.highliteFontColor, this.buttonFont, this.textJustification, this.textAlignment, this.buttonImage, this.highliteImage, this.backgroundColor));
- } else {
- this.subPanel.add(new PopButton(this, po, stringList[i], this.fontColor, this.highliteFontColor, this.buttonFont, this.textJustification, this.textAlignment, this.buttonImage, this.highliteImage, this.backgroundImage));
- }
- }
-
- if (this.orientation == 0) {
- this.subPanel.reshape(this.BUTTON_WIDTH, buttonNum * this.BUTTON_HEIGHT, this.BUTTON_WIDTH, this.BUTTON_HEIGHT * stringList.length);
- } else {
- this.subPanel.reshape(buttonNum * this.BUTTON_WIDTH, this.BUTTON_HEIGHT, this.BUTTON_WIDTH, this.BUTTON_HEIGHT * stringList.length);
- }
-
- ((Container)this).add(this.subPanel);
- ((Container)this).validate();
- this.subPanelUp = true;
- this.currentButtonNum = buttonNum;
- } else {
- ((Container)this).remove(this.subPanel);
- this.subPanelUp = false;
- if (popObject.getButtonNum() == this.currentButtonNum) {
- this.subPanel = new Panel();
- ((Container)this).add(this.subPanel);
- ((Container)this).validate();
- this.currentButtonNum = -1;
- } else {
- this.actionMouseDown(popObject);
- }
- }
-
- }
- }
-
- protected int countSubEntries(int buttonNum) {
- int subCount;
- for(subCount = 0; ((Applet)this).getParameter("ButtonText" + buttonNum + "_" + subCount) != null; ++subCount) {
- }
-
- return subCount;
- }
-
- protected void getTextAlignment() {
- this.textAlignment = Integer.parseInt(((Applet)this).getParameter("TextAlignment"));
- }
-
- public void paint(Graphics g) {
- if (this.backgroundImage != null) {
- int imHeight = this.backgroundImage.getHeight(this);
- int imWidth = this.backgroundImage.getWidth(this);
- Dimension d = ((Component)this).size();
- int x = (d.width + this.xOffset) / imWidth + 1;
- int y = (d.height + this.yOffset) / imHeight + 1;
-
- for(int i = 0; i < y; ++i) {
- for(int j = 0; j < x; ++j) {
- g.drawImage(this.backgroundImage, j * imWidth - this.xOffset, i * imHeight - this.yOffset, this);
- }
- }
- }
-
- }
-
- private String modifyStringContext(String param) {
- if (param.startsWith(".")) {
- param = param.replace('\\', '/');
- param = this.documentBase + "/" + param;
- } else if (param.startsWith("#")) {
- param = ((Applet)this).getDocumentBase().toString() + param;
- } else if (!param.startsWith("cid:") && !param.startsWith("lifn:") && !param.startsWith("java:") && !param.startsWith("irc:") && !param.startsWith("IOR:") && !param.startsWith("ilu:") && !param.startsWith("https:") && !param.startsWith("http:") && !param.startsWith("hdl:") && !param.startsWith("gopher:") && !param.startsWith("ftp:") && !param.startsWith("finger:") && !param.startsWith("file:") && !param.startsWith("data:") && !param.startsWith("clsid:") && !param.startsWith("md5:") && !param.startsWith("mailserver:") && !param.startsWith("mailto:") && !param.startsWith("mid:") && !param.startsWith("news:") && !param.startsWith("nntp:") && !param.startsWith("path:") && !param.startsWith("prospero:") && !param.startsWith("service:") && !param.startsWith("shttp") && !param.startsWith("snews") && !param.startsWith("STANF:") && !param.startsWith("telnet:") && !param.startsWith("vemmi:") && !param.startsWith("wais:") && !param.startsWith("whois++:") && !param.startsWith("javascript:")) {
- param = "http://" + param;
- }
-
- return param;
- }
-
- private void getNumButtons() {
- int i;
- for(i = 0; ((Applet)this).getParameter("ButtonText" + i) != null; ++i) {
- }
-
- this.numButtons = i;
- }
-
- private void parseDocumentBase() {
- String fullBase = ((Applet)this).getDocumentBase().toString();
- this.documentBase = fullBase.substring(0, fullBase.lastIndexOf(47));
- }
-
- protected URL[] getURLList(int buttonNum) {
- int subCount = this.countSubEntries(buttonNum);
- URL[] URLList = new URL[subCount];
-
- for(int i = 0; i < subCount; ++i) {
- String theUrl = this.modifyStringContext(((Applet)this).getParameter("URL" + buttonNum + "_" + i));
-
- try {
- URLList[i] = new URL(theUrl);
- } catch (Exception var8) {
- URLList[i] = null;
- }
- }
-
- return URLList;
- }
-
- protected String[] getTargetList(int buttonNum) {
- int subCount = this.countSubEntries(buttonNum);
- String[] targetList = new String[subCount];
-
- for(int i = 0; i < subCount; ++i) {
- targetList[i] = ((Applet)this).getParameter("Target" + buttonNum + "_" + i);
- }
-
- return targetList;
- }
-
- protected void setCorrectLayout() {
- ((Container)this).setLayout((LayoutManager)null);
- }
-
- public void actionMouseExit(PopObject message) {
- }
-
- protected String[] getStringList(int buttonNum) {
- int subCount = this.countSubEntries(buttonNum);
- String[] stringList = new String[subCount];
-
- for(int i = 0; i < subCount; ++i) {
- String param = ((Applet)this).getParameter("ButtonText" + buttonNum + "_" + i);
- stringList[i] = param != null ? param : " ";
- }
-
- return stringList;
- }
-
- protected void getBackgroundColor() {
- int backgroundcolor = Integer.parseInt(((Applet)this).getParameter("BackgroundColor"));
- backgroundcolor = this.convertBGRtoRGB(backgroundcolor);
- this.backgroundColor = new Color(backgroundcolor);
- }
-
- private void setBackgroundMode() {
- if (this.backgroundColor != null) {
- ((Component)this).setBackground(this.backgroundColor);
- }
-
- }
-
- private void getBackgroundMode() {
- if (((Applet)this).getParameter("backgroundColor") != null) {
- this.getBackgroundColor();
- } else if (((Applet)this).getParameter("backgroundImage") != null) {
- this.getBackgroundImage();
- }
-
- }
-
- protected void getFontColor() {
- int fontcolor = Integer.parseInt(((Applet)this).getParameter("FontColor"));
- fontcolor = this.convertBGRtoRGB(fontcolor);
- this.fontColor = new Color(fontcolor);
- int highlitefontcolor = Integer.parseInt(((Applet)this).getParameter("HighliteFontColor"));
- highlitefontcolor = this.convertBGRtoRGB(highlitefontcolor);
- this.highliteFontColor = new Color(highlitefontcolor);
- }
-
- protected void initButtonInfo() {
- this.getNumButtons();
- this.getButtonImages();
- this.getButtonFont();
- this.getFontColor();
- this.getTextJustification();
- this.getTextAlignment();
- }
-
- private void initAppletInfo() {
- this.parseDocumentBase();
- this.getOrientation();
- this.getBackgroundMode();
- this.setBackgroundMode();
- this.setCorrectLayout();
- }
-
- public void actionMouseEnter(PopObject message) {
- }
-
- protected void action(PopObject message) {
- switch (message.getMessageType()) {
- case 0:
- this.actionMouseExit(message);
- break;
- case 1:
- this.actionMouseEnter(message);
- break;
- case 2:
- this.actionMouseDown(message);
- }
-
- }
-
- private int convertBGRtoRGB(int BGRColor) {
- int r = (BGRColor & 255) << 16;
- int g = BGRColor & '\uff00';
- int b = (BGRColor & 16711680) >> 16;
- return r + g + b;
- }
-
- protected URL getButtonURL(int buttonNum) {
- URL url;
- try {
- String param = this.modifyStringContext(((Applet)this).getParameter("URL" + buttonNum));
- url = new URL(param);
- } catch (Exception var5) {
- url = null;
- }
-
- return url;
- }
-
- public void init() {
- this.xOffset = Integer.parseInt(((Applet)this).getParameter("X Position"));
- this.yOffset = Integer.parseInt(((Applet)this).getParameter("Y Position"));
- this.initAppletInfo();
- this.initButtonInfo();
-
- for(int i = 0; i < this.numButtons; ++i) {
- String param = ((Applet)this).getParameter("ButtonText" + i);
- String targetParam = ((Applet)this).getParameter("Target" + i);
- String buttonText = param != null ? param : " ";
- URL buttonURL = this.getButtonURL(i);
- URL[] URLList = this.getURLList(i);
- String[] stringList = this.getStringList(i);
- String[] theTargetList = this.getTargetList(i);
- PopObject popObject = new PopObject(i, buttonURL, targetParam, URLList, theTargetList, stringList);
- PopButton aButton;
- if (this.backgroundColor != null) {
- aButton = new PopButton(this, popObject, buttonText, this.fontColor, this.highliteFontColor, this.buttonFont, this.textJustification, this.textAlignment, this.buttonImage, this.highliteImage, this.backgroundColor);
- } else {
- aButton = new PopButton(this, popObject, buttonText, this.fontColor, this.highliteFontColor, this.buttonFont, this.textJustification, this.textAlignment, this.buttonImage, this.highliteImage, this.backgroundImage);
- }
-
- if (this.orientation == 0) {
- ((Component)aButton).reshape(0, i * this.BUTTON_HEIGHT, this.BUTTON_WIDTH, this.BUTTON_HEIGHT);
- } else {
- ((Component)aButton).reshape(i * this.BUTTON_WIDTH, 0, this.BUTTON_WIDTH, this.BUTTON_HEIGHT);
- }
-
- ((Container)this).add(aButton);
- }
-
- }
-
- protected void getButtonFont() {
- int fontSize = Integer.parseInt(((Applet)this).getParameter("FontSize"));
- String buttonfont = ((Applet)this).getParameter("ButtonFont");
- int fontStyle = 0;
- if (((Applet)this).getParameter("Bold") != null && ((Applet)this).getParameter("Italic") != null) {
- fontStyle = 3;
- } else if (((Applet)this).getParameter("Bold") != null) {
- fontStyle = 1;
- } else if (((Applet)this).getParameter("Italic") != null) {
- fontStyle = 2;
- }
-
- fontSize += 3;
- this.buttonFont = new Font(buttonfont, fontStyle, fontSize);
- }
-
- private void getOrientation() {
- if (((Applet)this).getParameter("Orientation").equals("Horizontal")) {
- this.orientation = 1;
- } else {
- this.orientation = 0;
- }
-
- }
- }
-