home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Panel;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
- import java.util.Vector;
-
- public class JDPPopupMenu extends Panel {
- JDPUser user;
- Panel targetPanel;
- Image offscreen;
- Rectangle offscreensize;
- // $FF: renamed from: gr java.awt.Graphics
- Graphics field_0;
- JDPPopupMenu droppanel;
- JDPPopupMenu parent;
- int dropindex;
- int xinitpos;
- int yinitpos;
- JDPTreeBranch treeRoot;
- JDPTreeBranch thisBranch;
- int[] icons;
- int xOffset;
- int yOffset;
- int currheight;
- int currxpoint = 10;
- int currypoint = 10;
- int lastxpoint = 10;
- int lastypoint = 10;
- Rectangle Bounds;
- int[] widths;
- Font lastFont;
- // $FF: renamed from: fm java.awt.FontMetrics
- FontMetrics field_1;
- int maxWidth;
- int maxHeight;
- int maxXwidth;
- int currentIndex = -1;
- String[] currentBranch;
- int currentBranchLvl = -1;
- Event thisEvent;
- Color textHighlightText;
- Color textHighlight;
- Color fore;
- Color back;
-
- public String getSelectedMenu(int var1) {
- return var1 < this.currentBranch.length ? this.currentBranch[var1] : null;
- }
-
- public void paint(Graphics var1) {
- this.update(var1);
- }
-
- void drawEntry(JDPTreeBranch var1) {
- int var2 = this.lastxpoint;
- int var3 = this.lastypoint;
- this.lastxpoint = this.currxpoint;
- this.lastypoint = this.currypoint;
- byte var4 = 0;
- var2 = this.currxpoint;
- var3 = this.currypoint;
- this.field_0.setColor(this.fore);
- int var5 = this.user.u.StringWidth(this.field_0, var1.name);
- int var6 = this.currheight + 2;
- if (var1.name != null) {
- if (var1.name.equals("")) {
- this.field_0.setColor(JDPUtils.darker(this.back));
- this.field_0.drawLine(3, var3 - 1, this.Bounds.width - 4, var3 - 1);
- this.field_0.setColor(JDPUtils.brighter(this.back));
- this.field_0.drawLine(3, var3, this.Bounds.width - 4, var3);
- var6 = 5;
- } else {
- if (var1.selected) {
- this.field_0.setColor(this.textHighlight);
- if (var1.name.length() > 0) {
- this.field_0.fillRect(2, var3 - 3, this.Bounds.width - 4, this.currheight + 3);
- }
-
- this.field_0.setColor(this.textHighlightText);
- }
-
- this.field_0.drawString(var1.name, var2 + 36, var3 + 9);
- var1.textRect = new Rectangle(2, var3 - 3, this.Bounds.width - 4, this.currheight + 3);
- }
- }
-
- if (var1.leaves != null && var1.leaves.size() > 0) {
- int var7 = this.Bounds.width - 11;
- int var8 = var3 - 9;
- int[] var9 = new int[]{var7, var7 + 4, var7, var7};
- int[] var10 = new int[]{var8 + 9, var8 + 13, var8 + 17, var8 + 9};
- this.field_0.fillPolygon(var9, var10, 3);
- }
-
- int var13 = var2 + 13 + 30 + var5;
- if (var13 + this.xOffset > this.maxWidth) {
- this.maxWidth = var13 + this.xOffset;
- }
-
- this.currypoint += var6;
- this.lastxpoint = this.currxpoint;
- this.lastypoint = var4;
- this.maxHeight = this.currypoint + this.yOffset;
- }
-
- int[] getWidths() {
- this.field_1 = this.field_0.getFontMetrics();
- this.widths = this.field_1.getWidths();
- return this.widths;
- }
-
- public void hideUpperMenu() {
- if (this.droppanel != null && this.droppanel.isVisible()) {
- this.droppanel.hideUpperMenu();
- }
-
- ((Component)this).hide();
- }
-
- Vector getBranch(JDPTreeBranch var1, String[] var2, int var3) {
- if (!var2[var2.length - 1].equals("") && var1.leaves != null) {
- for(int var4 = 0; var4 < var1.leaves.size(); ++var4) {
- JDPTreeBranch var5 = (JDPTreeBranch)var1.leaves.elementAt(var4);
- if (var5.name.equals(var2[var3])) {
- if (var3 + 1 != var2.length && var2[var3 + 1] != null) {
- return this.getBranch(var5, var2, var3 + 1);
- }
-
- return null;
- }
- }
- }
-
- Vector var6 = new Vector();
- var6.addElement(var1);
- var6.addElement(Integer.toString(var3));
- return var6;
- }
-
- JDPTreeBranch setRoot(String var1, boolean var2) {
- this.treeRoot = new JDPTreeBranch();
- this.treeRoot.name = var1;
- this.treeRoot.expanded = var2;
- this.treeRoot.selected = false;
- this.treeRoot.leaves = new Vector();
- if (this.icons != null) {
- this.treeRoot.icon = this.icons[0];
- }
-
- this.xOffset = 0;
- this.yOffset = 0;
- this.thisBranch = this.treeRoot;
- return this.treeRoot;
- }
-
- public String[] getSelectedBranch() {
- return this.currentBranch;
- }
-
- public JDPTreeBranch getMenuTree() {
- return this.treeRoot;
- }
-
- public void setMenuTree(JDPTreeBranch var1) {
- this.setRoot("", false);
- this.treeRoot = var1;
- this.thisBranch = this.treeRoot;
- }
-
- public void update(Graphics var1) {
- Rectangle var2 = ((Component)this).bounds();
- if (this.offscreen == null || var2.width != this.offscreensize.width || var2.height != this.offscreensize.height) {
- this.offscreen = ((Component)this).createImage(var2.width, var2.height);
- this.offscreensize = var2;
- this.field_0 = this.offscreen.getGraphics();
- this.field_0.setFont(((Component)this).getFont());
- }
-
- this.resetRectangles(this.thisBranch);
- this.Bounds = ((Component)this).bounds();
- if (this.maxWidth > 0 && this.xOffset > this.maxWidth + 20 - this.Bounds.width) {
- this.xOffset = this.maxWidth + 20 - this.Bounds.width;
- }
-
- if (this.xOffset < 0) {
- this.xOffset = 0;
- }
-
- if (this.maxHeight > 0 && this.yOffset > this.maxHeight + 20 - this.Bounds.height) {
- this.yOffset = this.maxHeight + 20 - this.Bounds.height;
- }
-
- if (this.yOffset < 0) {
- this.yOffset = 0;
- }
-
- this.currxpoint = -25 - this.xOffset;
- this.currypoint = 6 - this.yOffset;
- this.lastxpoint = this.currxpoint;
- this.lastypoint = this.currypoint;
- this.maxWidth = this.xOffset;
- this.maxHeight = 0;
- if (this.parent != null) {
- this.fore = this.parent.getForeground();
- this.back = this.parent.getBackground();
- } else {
- this.fore = ((Component)this).getForeground();
- this.back = ((Component)this).getBackground();
- }
-
- this.field_0.setColor(this.back);
- this.field_0.fillRect(2, 2, this.Bounds.width - 4, this.Bounds.height - 2);
- this.field_0.setColor(this.fore);
- this.currheight = this.StringHeight();
-
- for(int var3 = 0; var3 < this.thisBranch.leaves.size(); ++var3) {
- JDPTreeBranch var4 = (JDPTreeBranch)this.thisBranch.leaves.elementAt(var3);
- this.drawEntry(var4);
- }
-
- this.field_0.setColor(this.back);
- this.field_0.drawLine(0, 0, this.Bounds.width, 0);
- this.field_0.drawLine(0, 0, 0, this.Bounds.height - 2);
- this.field_0.setColor(JDPUtils.brighter(this.back));
- this.field_0.drawLine(1, 1, this.Bounds.width - 1, 1);
- this.field_0.drawLine(1, 1, 1, this.Bounds.height - 1);
- this.field_0.setColor(JDPUtils.darker(this.back));
- this.field_0.drawLine(this.Bounds.width - 2, 1, this.Bounds.width - 2, this.Bounds.height - 2);
- this.field_0.setColor(JDPUtils.darker(JDPUtils.darker(this.back)));
- this.field_0.drawLine(this.Bounds.width - 1, 0, this.Bounds.width - 1, this.Bounds.height - 1);
- this.field_0.setColor(JDPUtils.darker(this.back));
- this.field_0.drawLine(1, this.Bounds.height - 2, this.Bounds.width - 2, this.Bounds.height - 2);
- this.field_0.setColor(JDPUtils.darker(JDPUtils.darker(this.back)));
- this.field_0.drawLine(0, this.Bounds.height - 1, this.Bounds.width - 1, this.Bounds.height - 1);
- var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
- }
-
- JDPTreeBranch addItem(JDPTreeBranch var1, String var2, int var3, boolean var4) {
- JDPTreeBranch var5 = new JDPTreeBranch();
- var1.leaves.addElement(var5);
- var5.name = var2;
- var5.icon = var3;
- var5.expanded = var4;
- var5.selected = false;
- var5.leaves = new Vector();
- return var5;
- }
-
- public JDPPopupMenu(JDPUser var1, Panel var2) {
- this.createMenu(var1, var2, (JDPPopupMenu)null, 0);
- this.setRoot("", true);
- }
-
- public JDPPopupMenu(JDPUser var1, Panel var2, JDPPopupMenu var3, int var4) {
- this.createMenu(var1, var2, var3, var4);
- }
-
- public int getCurrentMenuLvl() {
- return this.currentBranchLvl;
- }
-
- public void resetSelections(JDPTreeBranch var1) {
- if (var1.selected && var1.textRect != null) {
- ((Component)this).repaint();
- }
-
- var1.selected = false;
- if (var1.leaves != null) {
- for(int var2 = 0; var2 < var1.leaves.size(); ++var2) {
- this.resetSelections((JDPTreeBranch)var1.leaves.elementAt(var2));
- }
- }
-
- }
-
- boolean checkMouseClick(Event var1) {
- int var2 = 0;
-
- for(int var3 = 0; var3 < this.thisBranch.leaves.size(); ++var3) {
- JDPTreeBranch var4 = (JDPTreeBranch)this.thisBranch.leaves.elementAt(var3);
- if (var4.name.equals("")) {
- var2 += 5;
- } else {
- var2 += this.StringHeight() + 2;
- }
-
- if (var4.textRect != null && var4.textRect.inside(var1.x, var1.y)) {
- this.resetSelections(this.thisBranch);
- var4.selected = true;
- this.parent.currentBranch[this.dropindex] = var4.name;
- if (var4.leaves != null && var4.leaves.size() != 0) {
- if (this.droppanel != null && var1.id != 502) {
- this.droppanel.thisBranch = var4;
- this.droppanel.display(this.xinitpos + this.maxXwidth + 20, this.yinitpos + var2 - 15);
- }
-
- ((Component)this).repaint();
- return true;
- }
-
- this.parent.currentBranchLvl = this.dropindex;
- if (this.droppanel != null) {
- this.droppanel.hideUpperMenu();
- }
-
- if (var1.id == 502) {
- this.hideMenu();
- this.thisEvent = new Event(this.parent, 1001, "JDPPopupMenu");
- this.targetPanel.postEvent(this.thisEvent);
- }
-
- ((Component)this).repaint();
- return true;
- }
- }
-
- return false;
- }
-
- int StringHeight() {
- if (this.field_0 == null) {
- return 0;
- } else {
- if (this.field_0.getFont() != this.lastFont) {
- this.getWidths();
- this.lastFont = this.field_0.getFont();
- }
-
- return this.field_1.getHeight();
- }
- }
-
- public void clear() {
- this.setRoot("", false);
- }
-
- void resetRectangles(JDPTreeBranch var1) {
- var1.expandRect = null;
- var1.textRect = null;
- if (var1.leaves != null) {
- for(int var2 = 0; var2 < var1.leaves.size(); ++var2) {
- this.resetRectangles((JDPTreeBranch)var1.leaves.elementAt(var2));
- }
- }
-
- }
-
- public void display(int var1, int var2) {
- this.xinitpos = var1;
- this.yinitpos = var2;
- Rectangle var3 = ((Component)this).bounds();
- if (this.offscreen == null) {
- this.offscreen = ((Component)this).createImage(10, 10);
- this.offscreensize = var3;
- if (this.offscreen == null) {
- this.field_0 = ((Component)this).getParent().getGraphics();
- } else {
- this.field_0 = this.offscreen.getGraphics();
- }
-
- this.field_0.setFont(((Component)this).getFont());
- }
-
- this.maxXwidth = 60;
- int var5 = 7;
- this.currheight = this.StringHeight();
-
- for(int var4 = 0; var4 < this.thisBranch.leaves.size(); ++var4) {
- JDPTreeBranch var6 = (JDPTreeBranch)this.thisBranch.leaves.elementAt(var4);
- var6.selected = false;
- int var7 = this.user.u.StringWidth(this.field_0, var6.name) + 15;
- if (var7 > this.maxXwidth) {
- this.maxXwidth = var7;
- }
-
- if (var6.name != null && !var6.name.equals("")) {
- var5 = var5 + this.currheight + 2;
- } else {
- var5 += 5;
- }
- }
-
- Panel var9 = (Panel)((Component)this).getParent();
- Rectangle var10 = ((Component)var9).bounds();
-
- for(int var8 = var1 - 10 + this.maxXwidth + 20; var8 > var10.width; var8 = var1 - 10 + this.maxXwidth + 20) {
- var1 -= 5;
- }
-
- for(int var11 = var2 - 10 + var5; var11 > var10.height; var11 = var2 - 10 + var5) {
- var2 -= 5;
- }
-
- if (var1 < 10) {
- var1 = 10;
- }
-
- if (var2 < 10) {
- var2 = 10;
- }
-
- ((Component)this).reshape(var1 - 10, var2 - 10, this.maxXwidth + 20, var5);
- ((Component)this).repaint();
- ((Component)this).show();
- if (System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("os.name").equals("SunOS")) {
- ((Container)var9).remove(this);
- ((Container)var9).add(this);
- ((Component)this).show();
- }
-
- if (this.dropindex == 0) {
- ((Component)this).requestFocus();
- }
-
- }
-
- public boolean addEntry(String var1) {
- String[] var2 = new String[]{var1};
- return this.addEntry(var2);
- }
-
- public boolean addEntry(String[] var1) {
- Vector var2 = this.getBranch(this.treeRoot, var1, 0);
- if (var2 != null) {
- JDPTreeBranch var3 = (JDPTreeBranch)var2.elementAt(0);
- int var4 = Integer.parseInt((String)var2.elementAt(1));
-
- for(int var5 = var4; var5 < var1.length; ++var5) {
- byte var6 = 0;
- if (var1[var5] != null) {
- var3 = this.addItem(var3, var1[var5], var6, false);
- }
- }
-
- return false;
- } else {
- return true;
- }
- }
-
- public void layout() {
- ((Component)this).repaint();
- }
-
- public boolean handleEvent(Event var1) {
- switch (var1.id) {
- case 202:
- case 205:
- ((Component)this).repaint();
- return true;
- case 502:
- this.hideMenu();
- case 501:
- case 503:
- case 506:
- int var2 = this.currentIndex;
- this.currentIndex = -1;
- if (this.thisBranch.leaves != null && this.thisBranch.leaves.size() != 0 && this.checkMouseClick(var1)) {
- return true;
- }
-
- this.currentIndex = var2;
- ((Component)this).repaint();
- return true;
- case 1005:
- this.hideMenu();
- return false;
- default:
- if (this.user.jdpMainWindow != null) {
- if (this.user.jdpMainWindow.getCursorType() == 3) {
- return false;
- }
-
- this.user.jdpMainWindow.setCursor(0);
- }
-
- return false;
- }
- }
-
- void createMenu(JDPUser var1, Panel var2, JDPPopupMenu var3, int var4) {
- this.user = var1;
- this.targetPanel = var2;
- this.dropindex = var4;
- this.textHighlightText = JDPUtils.getTextHighlightText();
- this.textHighlight = JDPUtils.getTextHighlight();
- ((Component)this).setFont(var1.plainFont);
- if (!JDPUser.classactivated) {
- System.out.println("Software Violation - this class may only be used in conjunction with JDesignerPro.");
- } else {
- if (var3 != null) {
- this.treeRoot = var3.treeRoot;
- this.parent = var3;
- }
-
- if (var4 < 10) {
- ++var4;
- if (var3 == null) {
- this.parent = this;
- this.currentBranch = new String[10];
- }
-
- this.droppanel = new JDPPopupMenu(var1, var2, this.parent, var4);
- ((Container)var2).add(this.droppanel);
- }
-
- ((Component)this).hide();
- }
- }
-
- public void hideMenu() {
- ((Component)this).hide();
- if (this.droppanel != null && this.droppanel.isVisible()) {
- this.droppanel.hideMenu();
- }
-
- if (this.parent != null && this.parent.isVisible()) {
- this.parent.hideMenu();
- }
-
- }
- }
-