home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / JDesignerPro / Jdp3_0.exe / data1.cab / Program_Files / JDPPopupMenu.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-09  |  8.5 KB  |  530 lines

  1. import java.awt.Color;
  2. import java.awt.Component;
  3. import java.awt.Container;
  4. import java.awt.Event;
  5. import java.awt.Font;
  6. import java.awt.FontMetrics;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.Panel;
  10. import java.awt.Rectangle;
  11. import java.awt.image.ImageObserver;
  12. import java.util.Vector;
  13.  
  14. public class JDPPopupMenu extends Panel {
  15.    JDPUser user;
  16.    Panel targetPanel;
  17.    Image offscreen;
  18.    Rectangle offscreensize;
  19.    // $FF: renamed from: gr java.awt.Graphics
  20.    Graphics field_0;
  21.    JDPPopupMenu droppanel;
  22.    JDPPopupMenu parent;
  23.    int dropindex;
  24.    int xinitpos;
  25.    int yinitpos;
  26.    JDPTreeBranch treeRoot;
  27.    JDPTreeBranch thisBranch;
  28.    int[] icons;
  29.    int xOffset;
  30.    int yOffset;
  31.    int currheight;
  32.    int currxpoint = 10;
  33.    int currypoint = 10;
  34.    int lastxpoint = 10;
  35.    int lastypoint = 10;
  36.    Rectangle Bounds;
  37.    int[] widths;
  38.    Font lastFont;
  39.    // $FF: renamed from: fm java.awt.FontMetrics
  40.    FontMetrics field_1;
  41.    int maxWidth;
  42.    int maxHeight;
  43.    int maxXwidth;
  44.    int currentIndex = -1;
  45.    String[] currentBranch;
  46.    int currentBranchLvl = -1;
  47.    Event thisEvent;
  48.    Color textHighlightText;
  49.    Color textHighlight;
  50.    Color fore;
  51.    Color back;
  52.  
  53.    public String getSelectedMenu(int var1) {
  54.       return var1 < this.currentBranch.length ? this.currentBranch[var1] : null;
  55.    }
  56.  
  57.    public void paint(Graphics var1) {
  58.       this.update(var1);
  59.    }
  60.  
  61.    void drawEntry(JDPTreeBranch var1) {
  62.       int var2 = this.lastxpoint;
  63.       int var3 = this.lastypoint;
  64.       this.lastxpoint = this.currxpoint;
  65.       this.lastypoint = this.currypoint;
  66.       byte var4 = 0;
  67.       var2 = this.currxpoint;
  68.       var3 = this.currypoint;
  69.       this.field_0.setColor(this.fore);
  70.       int var5 = this.user.u.StringWidth(this.field_0, var1.name);
  71.       int var6 = this.currheight + 2;
  72.       if (var1.name != null) {
  73.          if (var1.name.equals("")) {
  74.             this.field_0.setColor(JDPUtils.darker(this.back));
  75.             this.field_0.drawLine(3, var3 - 1, this.Bounds.width - 4, var3 - 1);
  76.             this.field_0.setColor(JDPUtils.brighter(this.back));
  77.             this.field_0.drawLine(3, var3, this.Bounds.width - 4, var3);
  78.             var6 = 5;
  79.          } else {
  80.             if (var1.selected) {
  81.                this.field_0.setColor(this.textHighlight);
  82.                if (var1.name.length() > 0) {
  83.                   this.field_0.fillRect(2, var3 - 3, this.Bounds.width - 4, this.currheight + 3);
  84.                }
  85.  
  86.                this.field_0.setColor(this.textHighlightText);
  87.             }
  88.  
  89.             this.field_0.drawString(var1.name, var2 + 36, var3 + 9);
  90.             var1.textRect = new Rectangle(2, var3 - 3, this.Bounds.width - 4, this.currheight + 3);
  91.          }
  92.       }
  93.  
  94.       if (var1.leaves != null && var1.leaves.size() > 0) {
  95.          int var7 = this.Bounds.width - 11;
  96.          int var8 = var3 - 9;
  97.          int[] var9 = new int[]{var7, var7 + 4, var7, var7};
  98.          int[] var10 = new int[]{var8 + 9, var8 + 13, var8 + 17, var8 + 9};
  99.          this.field_0.fillPolygon(var9, var10, 3);
  100.       }
  101.  
  102.       int var13 = var2 + 13 + 30 + var5;
  103.       if (var13 + this.xOffset > this.maxWidth) {
  104.          this.maxWidth = var13 + this.xOffset;
  105.       }
  106.  
  107.       this.currypoint += var6;
  108.       this.lastxpoint = this.currxpoint;
  109.       this.lastypoint = var4;
  110.       this.maxHeight = this.currypoint + this.yOffset;
  111.    }
  112.  
  113.    int[] getWidths() {
  114.       this.field_1 = this.field_0.getFontMetrics();
  115.       this.widths = this.field_1.getWidths();
  116.       return this.widths;
  117.    }
  118.  
  119.    public void hideUpperMenu() {
  120.       if (this.droppanel != null && this.droppanel.isVisible()) {
  121.          this.droppanel.hideUpperMenu();
  122.       }
  123.  
  124.       ((Component)this).hide();
  125.    }
  126.  
  127.    Vector getBranch(JDPTreeBranch var1, String[] var2, int var3) {
  128.       if (!var2[var2.length - 1].equals("") && var1.leaves != null) {
  129.          for(int var4 = 0; var4 < var1.leaves.size(); ++var4) {
  130.             JDPTreeBranch var5 = (JDPTreeBranch)var1.leaves.elementAt(var4);
  131.             if (var5.name.equals(var2[var3])) {
  132.                if (var3 + 1 != var2.length && var2[var3 + 1] != null) {
  133.                   return this.getBranch(var5, var2, var3 + 1);
  134.                }
  135.  
  136.                return null;
  137.             }
  138.          }
  139.       }
  140.  
  141.       Vector var6 = new Vector();
  142.       var6.addElement(var1);
  143.       var6.addElement(Integer.toString(var3));
  144.       return var6;
  145.    }
  146.  
  147.    JDPTreeBranch setRoot(String var1, boolean var2) {
  148.       this.treeRoot = new JDPTreeBranch();
  149.       this.treeRoot.name = var1;
  150.       this.treeRoot.expanded = var2;
  151.       this.treeRoot.selected = false;
  152.       this.treeRoot.leaves = new Vector();
  153.       if (this.icons != null) {
  154.          this.treeRoot.icon = this.icons[0];
  155.       }
  156.  
  157.       this.xOffset = 0;
  158.       this.yOffset = 0;
  159.       this.thisBranch = this.treeRoot;
  160.       return this.treeRoot;
  161.    }
  162.  
  163.    public String[] getSelectedBranch() {
  164.       return this.currentBranch;
  165.    }
  166.  
  167.    public JDPTreeBranch getMenuTree() {
  168.       return this.treeRoot;
  169.    }
  170.  
  171.    public void setMenuTree(JDPTreeBranch var1) {
  172.       this.setRoot("", false);
  173.       this.treeRoot = var1;
  174.       this.thisBranch = this.treeRoot;
  175.    }
  176.  
  177.    public void update(Graphics var1) {
  178.       Rectangle var2 = ((Component)this).bounds();
  179.       if (this.offscreen == null || var2.width != this.offscreensize.width || var2.height != this.offscreensize.height) {
  180.          this.offscreen = ((Component)this).createImage(var2.width, var2.height);
  181.          this.offscreensize = var2;
  182.          this.field_0 = this.offscreen.getGraphics();
  183.          this.field_0.setFont(((Component)this).getFont());
  184.       }
  185.  
  186.       this.resetRectangles(this.thisBranch);
  187.       this.Bounds = ((Component)this).bounds();
  188.       if (this.maxWidth > 0 && this.xOffset > this.maxWidth + 20 - this.Bounds.width) {
  189.          this.xOffset = this.maxWidth + 20 - this.Bounds.width;
  190.       }
  191.  
  192.       if (this.xOffset < 0) {
  193.          this.xOffset = 0;
  194.       }
  195.  
  196.       if (this.maxHeight > 0 && this.yOffset > this.maxHeight + 20 - this.Bounds.height) {
  197.          this.yOffset = this.maxHeight + 20 - this.Bounds.height;
  198.       }
  199.  
  200.       if (this.yOffset < 0) {
  201.          this.yOffset = 0;
  202.       }
  203.  
  204.       this.currxpoint = -25 - this.xOffset;
  205.       this.currypoint = 6 - this.yOffset;
  206.       this.lastxpoint = this.currxpoint;
  207.       this.lastypoint = this.currypoint;
  208.       this.maxWidth = this.xOffset;
  209.       this.maxHeight = 0;
  210.       if (this.parent != null) {
  211.          this.fore = this.parent.getForeground();
  212.          this.back = this.parent.getBackground();
  213.       } else {
  214.          this.fore = ((Component)this).getForeground();
  215.          this.back = ((Component)this).getBackground();
  216.       }
  217.  
  218.       this.field_0.setColor(this.back);
  219.       this.field_0.fillRect(2, 2, this.Bounds.width - 4, this.Bounds.height - 2);
  220.       this.field_0.setColor(this.fore);
  221.       this.currheight = this.StringHeight();
  222.  
  223.       for(int var3 = 0; var3 < this.thisBranch.leaves.size(); ++var3) {
  224.          JDPTreeBranch var4 = (JDPTreeBranch)this.thisBranch.leaves.elementAt(var3);
  225.          this.drawEntry(var4);
  226.       }
  227.  
  228.       this.field_0.setColor(this.back);
  229.       this.field_0.drawLine(0, 0, this.Bounds.width, 0);
  230.       this.field_0.drawLine(0, 0, 0, this.Bounds.height - 2);
  231.       this.field_0.setColor(JDPUtils.brighter(this.back));
  232.       this.field_0.drawLine(1, 1, this.Bounds.width - 1, 1);
  233.       this.field_0.drawLine(1, 1, 1, this.Bounds.height - 1);
  234.       this.field_0.setColor(JDPUtils.darker(this.back));
  235.       this.field_0.drawLine(this.Bounds.width - 2, 1, this.Bounds.width - 2, this.Bounds.height - 2);
  236.       this.field_0.setColor(JDPUtils.darker(JDPUtils.darker(this.back)));
  237.       this.field_0.drawLine(this.Bounds.width - 1, 0, this.Bounds.width - 1, this.Bounds.height - 1);
  238.       this.field_0.setColor(JDPUtils.darker(this.back));
  239.       this.field_0.drawLine(1, this.Bounds.height - 2, this.Bounds.width - 2, this.Bounds.height - 2);
  240.       this.field_0.setColor(JDPUtils.darker(JDPUtils.darker(this.back)));
  241.       this.field_0.drawLine(0, this.Bounds.height - 1, this.Bounds.width - 1, this.Bounds.height - 1);
  242.       var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
  243.    }
  244.  
  245.    JDPTreeBranch addItem(JDPTreeBranch var1, String var2, int var3, boolean var4) {
  246.       JDPTreeBranch var5 = new JDPTreeBranch();
  247.       var1.leaves.addElement(var5);
  248.       var5.name = var2;
  249.       var5.icon = var3;
  250.       var5.expanded = var4;
  251.       var5.selected = false;
  252.       var5.leaves = new Vector();
  253.       return var5;
  254.    }
  255.  
  256.    public JDPPopupMenu(JDPUser var1, Panel var2) {
  257.       this.createMenu(var1, var2, (JDPPopupMenu)null, 0);
  258.       this.setRoot("", true);
  259.    }
  260.  
  261.    public JDPPopupMenu(JDPUser var1, Panel var2, JDPPopupMenu var3, int var4) {
  262.       this.createMenu(var1, var2, var3, var4);
  263.    }
  264.  
  265.    public int getCurrentMenuLvl() {
  266.       return this.currentBranchLvl;
  267.    }
  268.  
  269.    public void resetSelections(JDPTreeBranch var1) {
  270.       if (var1.selected && var1.textRect != null) {
  271.          ((Component)this).repaint();
  272.       }
  273.  
  274.       var1.selected = false;
  275.       if (var1.leaves != null) {
  276.          for(int var2 = 0; var2 < var1.leaves.size(); ++var2) {
  277.             this.resetSelections((JDPTreeBranch)var1.leaves.elementAt(var2));
  278.          }
  279.       }
  280.  
  281.    }
  282.  
  283.    boolean checkMouseClick(Event var1) {
  284.       int var2 = 0;
  285.  
  286.       for(int var3 = 0; var3 < this.thisBranch.leaves.size(); ++var3) {
  287.          JDPTreeBranch var4 = (JDPTreeBranch)this.thisBranch.leaves.elementAt(var3);
  288.          if (var4.name.equals("")) {
  289.             var2 += 5;
  290.          } else {
  291.             var2 += this.StringHeight() + 2;
  292.          }
  293.  
  294.          if (var4.textRect != null && var4.textRect.inside(var1.x, var1.y)) {
  295.             this.resetSelections(this.thisBranch);
  296.             var4.selected = true;
  297.             this.parent.currentBranch[this.dropindex] = var4.name;
  298.             if (var4.leaves != null && var4.leaves.size() != 0) {
  299.                if (this.droppanel != null && var1.id != 502) {
  300.                   this.droppanel.thisBranch = var4;
  301.                   this.droppanel.display(this.xinitpos + this.maxXwidth + 20, this.yinitpos + var2 - 15);
  302.                }
  303.  
  304.                ((Component)this).repaint();
  305.                return true;
  306.             }
  307.  
  308.             this.parent.currentBranchLvl = this.dropindex;
  309.             if (this.droppanel != null) {
  310.                this.droppanel.hideUpperMenu();
  311.             }
  312.  
  313.             if (var1.id == 502) {
  314.                this.hideMenu();
  315.                this.thisEvent = new Event(this.parent, 1001, "JDPPopupMenu");
  316.                this.targetPanel.postEvent(this.thisEvent);
  317.             }
  318.  
  319.             ((Component)this).repaint();
  320.             return true;
  321.          }
  322.       }
  323.  
  324.       return false;
  325.    }
  326.  
  327.    int StringHeight() {
  328.       if (this.field_0 == null) {
  329.          return 0;
  330.       } else {
  331.          if (this.field_0.getFont() != this.lastFont) {
  332.             this.getWidths();
  333.             this.lastFont = this.field_0.getFont();
  334.          }
  335.  
  336.          return this.field_1.getHeight();
  337.       }
  338.    }
  339.  
  340.    public void clear() {
  341.       this.setRoot("", false);
  342.    }
  343.  
  344.    void resetRectangles(JDPTreeBranch var1) {
  345.       var1.expandRect = null;
  346.       var1.textRect = null;
  347.       if (var1.leaves != null) {
  348.          for(int var2 = 0; var2 < var1.leaves.size(); ++var2) {
  349.             this.resetRectangles((JDPTreeBranch)var1.leaves.elementAt(var2));
  350.          }
  351.       }
  352.  
  353.    }
  354.  
  355.    public void display(int var1, int var2) {
  356.       this.xinitpos = var1;
  357.       this.yinitpos = var2;
  358.       Rectangle var3 = ((Component)this).bounds();
  359.       if (this.offscreen == null) {
  360.          this.offscreen = ((Component)this).createImage(10, 10);
  361.          this.offscreensize = var3;
  362.          if (this.offscreen == null) {
  363.             this.field_0 = ((Component)this).getParent().getGraphics();
  364.          } else {
  365.             this.field_0 = this.offscreen.getGraphics();
  366.          }
  367.  
  368.          this.field_0.setFont(((Component)this).getFont());
  369.       }
  370.  
  371.       this.maxXwidth = 60;
  372.       int var5 = 7;
  373.       this.currheight = this.StringHeight();
  374.  
  375.       for(int var4 = 0; var4 < this.thisBranch.leaves.size(); ++var4) {
  376.          JDPTreeBranch var6 = (JDPTreeBranch)this.thisBranch.leaves.elementAt(var4);
  377.          var6.selected = false;
  378.          int var7 = this.user.u.StringWidth(this.field_0, var6.name) + 15;
  379.          if (var7 > this.maxXwidth) {
  380.             this.maxXwidth = var7;
  381.          }
  382.  
  383.          if (var6.name != null && !var6.name.equals("")) {
  384.             var5 = var5 + this.currheight + 2;
  385.          } else {
  386.             var5 += 5;
  387.          }
  388.       }
  389.  
  390.       Panel var9 = (Panel)((Component)this).getParent();
  391.       Rectangle var10 = ((Component)var9).bounds();
  392.  
  393.       for(int var8 = var1 - 10 + this.maxXwidth + 20; var8 > var10.width; var8 = var1 - 10 + this.maxXwidth + 20) {
  394.          var1 -= 5;
  395.       }
  396.  
  397.       for(int var11 = var2 - 10 + var5; var11 > var10.height; var11 = var2 - 10 + var5) {
  398.          var2 -= 5;
  399.       }
  400.  
  401.       if (var1 < 10) {
  402.          var1 = 10;
  403.       }
  404.  
  405.       if (var2 < 10) {
  406.          var2 = 10;
  407.       }
  408.  
  409.       ((Component)this).reshape(var1 - 10, var2 - 10, this.maxXwidth + 20, var5);
  410.       ((Component)this).repaint();
  411.       ((Component)this).show();
  412.       if (System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("os.name").equals("SunOS")) {
  413.          ((Container)var9).remove(this);
  414.          ((Container)var9).add(this);
  415.          ((Component)this).show();
  416.       }
  417.  
  418.       if (this.dropindex == 0) {
  419.          ((Component)this).requestFocus();
  420.       }
  421.  
  422.    }
  423.  
  424.    public boolean addEntry(String var1) {
  425.       String[] var2 = new String[]{var1};
  426.       return this.addEntry(var2);
  427.    }
  428.  
  429.    public boolean addEntry(String[] var1) {
  430.       Vector var2 = this.getBranch(this.treeRoot, var1, 0);
  431.       if (var2 != null) {
  432.          JDPTreeBranch var3 = (JDPTreeBranch)var2.elementAt(0);
  433.          int var4 = Integer.parseInt((String)var2.elementAt(1));
  434.  
  435.          for(int var5 = var4; var5 < var1.length; ++var5) {
  436.             byte var6 = 0;
  437.             if (var1[var5] != null) {
  438.                var3 = this.addItem(var3, var1[var5], var6, false);
  439.             }
  440.          }
  441.  
  442.          return false;
  443.       } else {
  444.          return true;
  445.       }
  446.    }
  447.  
  448.    public void layout() {
  449.       ((Component)this).repaint();
  450.    }
  451.  
  452.    public boolean handleEvent(Event var1) {
  453.       switch (var1.id) {
  454.          case 202:
  455.          case 205:
  456.             ((Component)this).repaint();
  457.             return true;
  458.          case 502:
  459.             this.hideMenu();
  460.          case 501:
  461.          case 503:
  462.          case 506:
  463.             int var2 = this.currentIndex;
  464.             this.currentIndex = -1;
  465.             if (this.thisBranch.leaves != null && this.thisBranch.leaves.size() != 0 && this.checkMouseClick(var1)) {
  466.                return true;
  467.             }
  468.  
  469.             this.currentIndex = var2;
  470.             ((Component)this).repaint();
  471.             return true;
  472.          case 1005:
  473.             this.hideMenu();
  474.             return false;
  475.          default:
  476.             if (this.user.jdpMainWindow != null) {
  477.                if (this.user.jdpMainWindow.getCursorType() == 3) {
  478.                   return false;
  479.                }
  480.  
  481.                this.user.jdpMainWindow.setCursor(0);
  482.             }
  483.  
  484.             return false;
  485.       }
  486.    }
  487.  
  488.    void createMenu(JDPUser var1, Panel var2, JDPPopupMenu var3, int var4) {
  489.       this.user = var1;
  490.       this.targetPanel = var2;
  491.       this.dropindex = var4;
  492.       this.textHighlightText = JDPUtils.getTextHighlightText();
  493.       this.textHighlight = JDPUtils.getTextHighlight();
  494.       ((Component)this).setFont(var1.plainFont);
  495.       if (!JDPUser.classactivated) {
  496.          System.out.println("Software Violation - this class may only be used in conjunction with JDesignerPro.");
  497.       } else {
  498.          if (var3 != null) {
  499.             this.treeRoot = var3.treeRoot;
  500.             this.parent = var3;
  501.          }
  502.  
  503.          if (var4 < 10) {
  504.             ++var4;
  505.             if (var3 == null) {
  506.                this.parent = this;
  507.                this.currentBranch = new String[10];
  508.             }
  509.  
  510.             this.droppanel = new JDPPopupMenu(var1, var2, this.parent, var4);
  511.             ((Container)var2).add(this.droppanel);
  512.          }
  513.  
  514.          ((Component)this).hide();
  515.       }
  516.    }
  517.  
  518.    public void hideMenu() {
  519.       ((Component)this).hide();
  520.       if (this.droppanel != null && this.droppanel.isVisible()) {
  521.          this.droppanel.hideMenu();
  522.       }
  523.  
  524.       if (this.parent != null && this.parent.isVisible()) {
  525.          this.parent.hideMenu();
  526.       }
  527.  
  528.    }
  529. }
  530.