home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / Share / Java / JDesignerPro / Jdp3_0.exe / data1.cab / Program_Files / JDPMain.jar / JDPDragItem.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-29  |  9.6 KB  |  548 lines

  1. import java.awt.Button;
  2. import java.awt.Choice;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Event;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.LayoutManager;
  12. import java.awt.Panel;
  13. import java.awt.Rectangle;
  14. import java.awt.image.ImageObserver;
  15. import java.util.Date;
  16. import java.util.Vector;
  17.  
  18. public class JDPDragItem extends Panel {
  19.    JDPUser user;
  20.    Panel targetPanel;
  21.    Image offscreen;
  22.    Rectangle offscreensize;
  23.    // $FF: renamed from: gr java.awt.Graphics
  24.    Graphics field_0;
  25.    Panel parent;
  26.    Image thisImage;
  27.    Component thisDrawComponent;
  28.    Rectangle thisRectangle;
  29.    Object thisDropKey;
  30.    Rectangle Bounds;
  31.    Vector dropRects;
  32.    int[] widths;
  33.    Font lastFont;
  34.    // $FF: renamed from: fm java.awt.FontMetrics
  35.    FontMetrics field_1;
  36.    int maxXwidth;
  37.    Vector activeAreas;
  38.    String prevMessage;
  39.    String popupMessage;
  40.    String statusBarMessage;
  41.    boolean alreadyDragging;
  42.    Event thisEvent;
  43.    int startElement = -1;
  44.    int endElement = -1;
  45.    Rectangle startRectangle;
  46.    Rectangle endRectangle;
  47.    Component startComponent;
  48.    Component endComponent;
  49.    boolean firstDrag = true;
  50.    int xoffset;
  51.    int yoffset;
  52.    Panel lastParent;
  53.    JDPTreePicker lastDropTree;
  54.    JDPTreeBranch lastSelectedBranch;
  55.    Color textHighlight;
  56.    Color backColor;
  57.  
  58.    void position(int var1, int var2) {
  59.       ((Component)this).reshape(var1, var2, this.thisRectangle.width + 1, this.thisRectangle.height + 1);
  60.    }
  61.  
  62.    public void removeDropComponents(Component var1) {
  63.       for(int var2 = 0; var2 < this.activeAreas.size(); ++var2) {
  64.          Vector var3 = (Vector)this.activeAreas.elementAt(var2);
  65.          Component var4 = (Component)var3.elementAt(2);
  66.          String var5 = (String)var3.elementAt(3);
  67.          if (var4 == var1 && var5.equals("Drop")) {
  68.             this.activeAreas.removeElementAt(var2);
  69.             Object var6 = null;
  70.             --var2;
  71.          }
  72.       }
  73.  
  74.    }
  75.  
  76.    public void setTarget(Panel var1) {
  77.       this.targetPanel = var1;
  78.    }
  79.  
  80.    public void addDropComponent(Component var1, Container var2, Object var3, String var4) {
  81.       this.addComponent(var1, var2, "Drop", var3, var4);
  82.    }
  83.  
  84.    public void addDropComponent(Component var1, Panel var2, Object var3, String var4) {
  85.       this.addComponent(var1, (Container)var2, "Drop", var3, var4);
  86.    }
  87.  
  88.    void addComponent(Component var1, Container var2, String var3, Object var4, String var5) {
  89.       Vector var6 = new Vector();
  90.       var6.addElement(var1);
  91.       if (var1 instanceof JDPButton) {
  92.          JDPButton var7 = new JDPButton(((JDPButton)var1).getLabel());
  93.          var6.addElement(var7);
  94.       } else if (var1 instanceof Button) {
  95.          Button var8 = new Button(((Button)var1).getLabel());
  96.          var6.addElement(var8);
  97.       } else if (var1 instanceof Choice) {
  98.          Choice var9 = new Choice();
  99.          var9.addItem(((Choice)var1).getSelectedItem());
  100.          var6.addElement(var9);
  101.       } else if (var1 instanceof JDPChoice) {
  102.          Choice var10 = new Choice();
  103.          var10.addItem(((Choice)var1).getSelectedItem());
  104.          var6.addElement(var10);
  105.       } else {
  106.          var6.addElement(var1);
  107.       }
  108.  
  109.       var6.addElement(var2);
  110.       var6.addElement(var3);
  111.       var6.addElement(var4);
  112.       var6.addElement((Object)null);
  113.       var6.addElement(var5);
  114.       this.activeAreas.addElement(var6);
  115.    }
  116.  
  117.    public void paint(Graphics var1) {
  118.       this.update(var1);
  119.    }
  120.  
  121.    public void addDragRectangle(Rectangle var1, Image var2, Panel var3, Object var4) {
  122.       this.addRectangle(var1, var2, var3, "Drag", var4, (String)null, (JDPTreeBranch)null);
  123.    }
  124.  
  125.    public void addDragRectangle(Rectangle var1, Image var2, Panel var3, Object var4, JDPTreeBranch var5) {
  126.       this.addRectangle(var1, var2, var3, "Drag", var4, (String)null, var5);
  127.    }
  128.  
  129.    public JDPTreeBranch[] getDraggedBranch(JDPTreePicker var1) {
  130.       Rectangle var2 = this.getDragRectangle();
  131.       if (var2 == null) {
  132.          return null;
  133.       } else {
  134.          Rectangle var3 = new Rectangle(var2.x, var2.y, var2.width, var2.height);
  135.          var3.x -= var1.xOffset - var1.dragXoffset;
  136.          var3.y -= var1.yOffset - var1.dragYoffset;
  137.          return var1.getTreeBranch(var3);
  138.       }
  139.    }
  140.  
  141.    public JDPTreeBranch[] getDroppedBranch(JDPTreePicker var1) {
  142.       return var1.getTreeBranch(this.getDropRectangle());
  143.    }
  144.  
  145.    public void update(Graphics var1) {
  146.       Rectangle var2 = ((Component)this).bounds();
  147.       if (this.offscreen != null && var2.width == this.offscreensize.width && var2.height == this.offscreensize.height) {
  148.          var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
  149.       } else {
  150.          if (var2.width < 10) {
  151.             var2.width = 10;
  152.          }
  153.  
  154.          if (var2.height < 10) {
  155.             var2.height = 10;
  156.          }
  157.  
  158.          this.offscreen = ((Component)this).createImage(var2.width, var2.height);
  159.          this.offscreensize = var2;
  160.          this.field_0 = this.offscreen.getGraphics();
  161.          this.Bounds = ((Component)this).bounds();
  162.          if (this.thisImage != null) {
  163.             this.field_0.drawImage(this.thisImage, 0, 0, (ImageObserver)null);
  164.             this.field_0.setColor(Color.black);
  165.             this.field_0.drawRect(0, 0, this.Bounds.width - 3, this.Bounds.height - 3);
  166.             this.field_0.setColor(this.backColor);
  167.             this.field_0.drawLine(0, this.Bounds.height - 2, 0, this.Bounds.height - 2);
  168.             this.field_0.drawLine(0, this.Bounds.height - 1, 1, this.Bounds.height - 2);
  169.             this.field_0.drawLine(this.Bounds.width - 2, 0, this.Bounds.width - 2, 0);
  170.             this.field_0.drawLine(this.Bounds.width - 1, 0, this.Bounds.width - 1, 1);
  171.             this.field_0.setColor(JDPUtils.darker(JDPUtils.darker(this.backColor)));
  172.             this.field_0.drawLine(1, this.Bounds.height - 2, this.Bounds.width - 2, this.Bounds.height - 2);
  173.             this.field_0.drawLine(this.Bounds.width - 2, 1, this.Bounds.width - 2, this.Bounds.height - 2);
  174.             this.field_0.setColor(JDPUtils.darker(this.backColor));
  175.             this.field_0.drawLine(2, this.Bounds.height - 1, this.Bounds.width - 1, this.Bounds.height - 1);
  176.             this.field_0.drawLine(this.Bounds.width - 1, 2, this.Bounds.width - 1, this.Bounds.height - 1);
  177.          }
  178.  
  179.          var1.drawImage(this.offscreen, 0, 0, (ImageObserver)null);
  180.       }
  181.    }
  182.  
  183.    public JDPDragItem(JDPUser var1, Panel var2) {
  184.       this.user = var1;
  185.       this.targetPanel = var2;
  186.       this.textHighlight = JDPUtils.getTextHighlight();
  187.       this.backColor = JDPUtils.getControlColor();
  188.       ((Component)this).setFont(var1.plainFont);
  189.       ((Container)this).setLayout((LayoutManager)null);
  190.       ((Component)this).setBackground(Color.white);
  191.       if (!JDPUser.classactivated) {
  192.          System.out.println("Software Violation - this class may only be used in conjunction with JDesignerPro.");
  193.       } else {
  194.          this.removeAllComponents();
  195.          ((Component)this).hide();
  196.          this.offscreen = ((Component)this).createImage(10, 10);
  197.       }
  198.    }
  199.  
  200.    public void addDropRectangle(Rectangle var1, Panel var2, Object var3, String var4) {
  201.       this.addRectangle(var1, (Image)null, var2, "Drop", var3, var4, (JDPTreeBranch)null);
  202.    }
  203.  
  204.    public void addDropRectangle(Rectangle var1, Panel var2, Object var3, String var4, JDPTreeBranch var5) {
  205.       this.addRectangle(var1, (Image)null, var2, "Drop", var3, var4, var5);
  206.    }
  207.  
  208.    void addRectangle(Rectangle var1, Image var2, Panel var3, String var4, Object var5, String var6, JDPTreeBranch var7) {
  209.       Rectangle var8 = new Rectangle(var1.x, var1.y, var1.width, var1.height);
  210.       Object var9 = (Component)var3;
  211.       Rectangle var10 = ((Component)var9).bounds();
  212.  
  213.       while(var9 != null && !var9.equals(this.targetPanel)) {
  214.          var10 = ((Component)var9).bounds();
  215.          var8.x += var10.x;
  216.          var8.y += var10.y;
  217.          var9 = ((Component)var9).getParent();
  218.          if (var9 == null) {
  219.             var8.x += 2000;
  220.          }
  221.       }
  222.  
  223.       Vector var11 = new Vector();
  224.       var11.addElement(var8);
  225.       var11.addElement(var2);
  226.       var11.addElement(var3);
  227.       var11.addElement(var4);
  228.       var11.addElement(var5);
  229.       var11.addElement(var1);
  230.       var11.addElement(var6);
  231.       var11.addElement(var7);
  232.       this.activeAreas.addElement(var11);
  233.    }
  234.  
  235.    public void removeAllComponents() {
  236.       this.activeAreas = null;
  237.       this.activeAreas = new Vector();
  238.    }
  239.  
  240.    public void removeAllComponents(Component var1) {
  241.       for(int var2 = 0; var2 < this.activeAreas.size(); ++var2) {
  242.          Vector var3 = (Vector)this.activeAreas.elementAt(var2);
  243.          Component var4 = (Component)var3.elementAt(2);
  244.          if (var4.equals(var1)) {
  245.             this.activeAreas.removeElementAt(var2);
  246.             Object var5 = null;
  247.             --var2;
  248.          }
  249.       }
  250.  
  251.    }
  252.  
  253.    public void addDragComponent(Component var1, Panel var2, Object var3) {
  254.       this.addComponent(var1, var2, "Drag", var3, (String)null);
  255.    }
  256.  
  257.    public void removeComponent(Component var1) {
  258.       for(int var2 = 0; var2 < this.activeAreas.size(); ++var2) {
  259.          Vector var3 = (Vector)this.activeAreas.elementAt(var2);
  260.          if (var1.equals((Component)var3.elementAt(0))) {
  261.             this.activeAreas.removeElementAt(var2);
  262.             return;
  263.          }
  264.       }
  265.  
  266.    }
  267.  
  268.    public Component getDraggedComponent() {
  269.       return this.startComponent;
  270.    }
  271.  
  272.    public Component getDroppedComponent() {
  273.       return this.endComponent;
  274.    }
  275.  
  276.    void display(int var1, int var2) {
  277.       this.startElement = -1;
  278.       this.endElement = -1;
  279.       this.startRectangle = null;
  280.       this.endRectangle = null;
  281.       this.startComponent = null;
  282.       this.endComponent = null;
  283.       ((Container)this).removeAll();
  284.       this.position(var1, var2);
  285.       if (this.thisDrawComponent != null) {
  286.          ((Container)this).add(this.thisDrawComponent);
  287.          this.thisDrawComponent.reshape(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
  288.       } else {
  289.          ((Component)this).repaint();
  290.       }
  291.  
  292.       if (!this.alreadyDragging) {
  293.          ((Component)this).show();
  294.       }
  295.  
  296.       if (!this.alreadyDragging && System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("os.name").equals("SunOS")) {
  297.          Container var3 = ((Component)this).getParent();
  298.          var3.remove(this);
  299.          var3.add(this);
  300.          ((Component)this).show();
  301.       }
  302.  
  303.       this.alreadyDragging = true;
  304.       ((Component)this).requestFocus();
  305.    }
  306.  
  307.    public void layout() {
  308.       ((Component)this).repaint();
  309.    }
  310.  
  311.    public boolean handleEvent(Event var1) {
  312.       this.endElement = -1;
  313.       switch (var1.id) {
  314.          case 501:
  315.             this.alreadyDragging = false;
  316.             this.dropRects = null;
  317.             this.firstDrag = true;
  318.             return true;
  319.          case 502:
  320.             if (this.dropRects != null) {
  321.                for(int var12 = this.dropRects.size() - 1; var12 >= 0; --var12) {
  322.                   Vector var16 = (Vector)this.dropRects.elementAt(var12);
  323.                   Rectangle var19 = (Rectangle)var16.elementAt(0);
  324.                   Object var22 = var16.elementAt(2);
  325.                   if (var22 instanceof JDPTreePicker && var19.intersects(this.Bounds)) {
  326.                      Rectangle var26 = (Rectangle)var16.elementAt(4);
  327.                      this.endElement = var12;
  328.                      this.endRectangle = new Rectangle(var26.x, var26.y, var26.width, var26.height);
  329.                      break;
  330.                   }
  331.                }
  332.  
  333.                if (this.endElement < 0) {
  334.                   for(int var13 = 0; var13 < this.dropRects.size(); ++var13) {
  335.                      Vector var17 = (Vector)this.dropRects.elementAt(var13);
  336.                      Rectangle var20 = (Rectangle)var17.elementAt(0);
  337.                      Object var23 = var17.elementAt(3);
  338.                      if (var23 instanceof Component && var20.inside(var1.x, var1.y)) {
  339.                         this.endElement = var13;
  340.                         this.endComponent = (Component)var23;
  341.                         break;
  342.                      }
  343.                   }
  344.                }
  345.             }
  346.  
  347.             this.alreadyDragging = false;
  348.             this.firstDrag = true;
  349.             this.dropRects = null;
  350.             ((Component)this).hide();
  351.             this.offscreen = null;
  352.             if (this.endElement >= 0) {
  353.                Event var14 = new Event(this, (new Date()).getTime(), 1001, var1.x, var1.y, var1.key, var1.modifiers, "JDPDragItem");
  354.                var14.modifiers = var1.modifiers;
  355.                var14.target = this;
  356.                if (this.lastParent != null) {
  357.                   this.lastParent.postEvent(var14);
  358.                }
  359.  
  360.                this.targetPanel.postEvent(var14);
  361.             }
  362.  
  363.             return true;
  364.          case 503:
  365.          case 504:
  366.             return true;
  367.          case 505:
  368.          default:
  369.             this.firstDrag = true;
  370.             return false;
  371.          case 506:
  372.             this.lastParent = null;
  373.             if (((Component)this).isVisible() && !this.firstDrag) {
  374.                this.alreadyDragging = true;
  375.             }
  376.  
  377.             if (this.alreadyDragging && var1.id == 506) {
  378.                ((Component)this).move(var1.x - this.xoffset, var1.y - this.yoffset);
  379.                this.Bounds = ((Component)this).bounds();
  380.                if (this.dropRects != null) {
  381.                   for(int var11 = this.dropRects.size() - 1; var11 >= 0; --var11) {
  382.                      Vector var15 = (Vector)this.dropRects.elementAt(var11);
  383.                      Rectangle var18 = (Rectangle)var15.elementAt(0);
  384.                      if (var18.intersects(this.Bounds)) {
  385.                         Object var21 = var15.elementAt(2);
  386.                         if (var21 instanceof JDPTreePicker) {
  387.                            JDPTreePicker var25 = (JDPTreePicker)var21;
  388.                            this.lastDropTree = var25;
  389.                            if (!var25.allowChangeOrder) {
  390.                               JDPTreeBranch var28 = (JDPTreeBranch)var15.elementAt(3);
  391.                               if (!var28.selected) {
  392.                                  if (this.lastSelectedBranch == null) {
  393.                                     var25.resetSelections();
  394.                                  } else {
  395.                                     this.lastSelectedBranch.selected = false;
  396.                                  }
  397.  
  398.                                  var28.selected = true;
  399.                                  this.lastSelectedBranch = var28;
  400.                                  ((Component)var25).requestFocus();
  401.                                  var25.reDraw();
  402.                                  String var30 = (String)var15.elementAt(1);
  403.                                  this.user.mainmsg.setStatusMsg(var30, 0, 0, (Component)null);
  404.                                  return true;
  405.                               }
  406.                            }
  407.  
  408.                            return true;
  409.                         }
  410.                      }
  411.                   }
  412.  
  413.                   if (this.lastDropTree != null) {
  414.                      if (this.lastSelectedBranch == null) {
  415.                         this.lastDropTree.resetSelections();
  416.                      } else {
  417.                         this.lastSelectedBranch.selected = false;
  418.                         this.lastDropTree.reDraw();
  419.                      }
  420.  
  421.                      this.lastDropTree = null;
  422.                      this.lastSelectedBranch = null;
  423.                   }
  424.  
  425.                   if (this.user.mainmsg.isStatusMsg()) {
  426.                      this.user.mainmsg.clearPopupMsg();
  427.                   }
  428.  
  429.                   return true;
  430.                }
  431.             }
  432.  
  433.             this.Bounds = ((Component)this).bounds();
  434.             this.user.mainmsg.clearPopupMsg();
  435.             if (this.firstDrag && var1.id == 506) {
  436.                this.firstDrag = false;
  437.                return true;
  438.             } else {
  439.                if (this.dropRects == null && var1.id == 506) {
  440.                   this.dropRects = new Vector();
  441.                }
  442.  
  443.                if (!var1.target.equals(this) && this.targetPanel != null && this.activeAreas != null && this.activeAreas.size() > 0 && var1.id == 506) {
  444.                   for(int var2 = this.activeAreas.size() - 1; var2 >= 0; --var2) {
  445.                      Vector var3 = (Vector)this.activeAreas.elementAt(var2);
  446.                      String var4 = (String)var3.elementAt(3);
  447.                      Object var5 = var3.elementAt(4);
  448.                      if (var4.equals("Drag") && !this.alreadyDragging || var4.equals("Drop") && this.alreadyDragging && this.thisDropKey.equals(var5)) {
  449.                         if (var3.elementAt(0) instanceof Rectangle) {
  450.                            Rectangle var24 = (Rectangle)var3.elementAt(0);
  451.                            Rectangle var27 = (Rectangle)var3.elementAt(5);
  452.                            Panel var29 = (Panel)var3.elementAt(2);
  453.                            this.lastParent = var29;
  454.                            if (((Component)var29).isShowing() && this.alreadyDragging && var4.equals("Drop")) {
  455.                               Vector var33 = new Vector();
  456.                               var33.addElement(var24);
  457.                               var33.addElement(var3.elementAt(6));
  458.                               var33.addElement(var3.elementAt(2));
  459.                               var33.addElement(var3.elementAt(7));
  460.                               var33.addElement(var3.elementAt(5));
  461.                               this.dropRects.addElement(var33);
  462.                            } else if (var24.inside(var1.x, var1.y) && ((Component)var29).isShowing()) {
  463.                               if (!this.alreadyDragging && var1.target.equals(var29)) {
  464.                                  this.thisRectangle = new Rectangle(var27.x - 2, var27.y - 2, var27.width + 2, var27.height + 2);
  465.                                  Image var32 = (Image)var3.elementAt(1);
  466.                                  this.thisImage = ((Component)this).createImage(var27.width + 4, var27.height + 4);
  467.                                  Graphics var34 = this.thisImage.getGraphics();
  468.                                  var34.drawImage(var32, -var27.x - 100, -var27.y, (ImageObserver)null);
  469.                                  this.thisDrawComponent = null;
  470.                                  this.xoffset = var1.x - var24.x;
  471.                                  this.yoffset = var1.y - var24.y;
  472.                                  this.display(var1.x - this.xoffset, var1.y - this.yoffset);
  473.                                  this.startElement = var2;
  474.                                  this.thisDropKey = var3.elementAt(4);
  475.                                  this.startRectangle = new Rectangle(var27.x, var27.y, var27.width, var27.height);
  476.                                  this.dropRects = null;
  477.                                  return true;
  478.                               }
  479.  
  480.                               this.endElement = var2;
  481.                               this.endRectangle = new Rectangle(var27.x, var27.y, var27.width, var27.height);
  482.                               break;
  483.                            }
  484.                         } else if (var3.elementAt(0) instanceof Component) {
  485.                            Component var6 = (Component)var3.elementAt(0);
  486.                            if (var6 != null && var6.isVisible()) {
  487.                               Rectangle var7 = var6.bounds();
  488.                               Container var8 = var6.getParent();
  489.                               if (var8 != null && ((Component)var8).isVisible()) {
  490.                                  Rectangle var9 = ((Component)var8).bounds();
  491.  
  492.                                  while(var8 != null && !var8.equals(this.targetPanel)) {
  493.                                     var9 = ((Component)var8).bounds();
  494.                                     var7.x += var9.x;
  495.                                     var7.y += var9.y;
  496.                                     var8 = ((Component)var8).getParent();
  497.                                     if (var8 == null || !((Component)var8).isVisible()) {
  498.                                        var7.x += 1000;
  499.                                     }
  500.                                  }
  501.  
  502.                                  if (this.alreadyDragging && var4.equals("Drop")) {
  503.                                     Vector var10 = new Vector();
  504.                                     var10.addElement(var7);
  505.                                     var10.addElement(var3.elementAt(6));
  506.                                     var10.addElement(var3.elementAt(2));
  507.                                     var10.addElement(var3.elementAt(0));
  508.                                     this.dropRects.addElement(var10);
  509.                                  } else if (var7.inside(var1.x, var1.y)) {
  510.                                     if (!this.alreadyDragging) {
  511.                                        this.thisDrawComponent = (Component)var3.elementAt(1);
  512.                                        this.thisImage = null;
  513.                                        this.thisRectangle = var7;
  514.                                        this.xoffset = var1.x - var7.x;
  515.                                        this.yoffset = var1.y - var7.y;
  516.                                        this.display(var1.x - this.xoffset, var1.y - this.yoffset);
  517.                                        this.startElement = var2;
  518.                                        this.thisDropKey = var3.elementAt(4);
  519.                                        this.startComponent = var6;
  520.                                        this.dropRects = null;
  521.                                        return true;
  522.                                     }
  523.  
  524.                                     this.endElement = var2;
  525.                                     this.endComponent = var6;
  526.                                     return true;
  527.                                  }
  528.                               }
  529.                            }
  530.                         }
  531.                      }
  532.                   }
  533.                }
  534.  
  535.                return true;
  536.             }
  537.       }
  538.    }
  539.  
  540.    public Rectangle getDragRectangle() {
  541.       return this.startRectangle;
  542.    }
  543.  
  544.    public Rectangle getDropRectangle() {
  545.       return this.endRectangle;
  546.    }
  547. }
  548.