home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2001 October / PCpro_2001_10.ISO / xml / xmlpro / data1.cab / Program_Executable_FILES / xmlpro.jar / TreeEventHandler.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-09-15  |  5.9 KB  |  200 lines

  1. import java.awt.event.InputEvent;
  2. import java.awt.event.MouseEvent;
  3. import java.awt.event.MouseListener;
  4. import java.util.Enumeration;
  5. import javax.swing.AbstractButton;
  6. import javax.swing.JMenu;
  7. import javax.swing.JMenuItem;
  8. import javax.swing.event.PopupMenuEvent;
  9. import javax.swing.event.PopupMenuListener;
  10. import javax.swing.event.TreeSelectionEvent;
  11. import javax.swing.event.TreeSelectionListener;
  12. import javax.swing.text.JTextComponent;
  13. import org.w3c.dom.Node;
  14.  
  15. public class TreeEventHandler implements TreeSelectionListener, MouseListener, PopupMenuListener {
  16.    JMenu addF;
  17.    JMenu addE;
  18.    XMLPro theApp;
  19.    AttribPanel pan;
  20.    JTextComponent data;
  21.    ElemPanel tree;
  22.    boolean clicked = false;
  23.    ElemNode lastElem;
  24.    static int POPUPLIMIT = 15;
  25.  
  26.    TreeEventHandler(AttribPanel var1, JTextComponent var2, ElemPanel var3, XMLPro var4) {
  27.       this.theApp = var4;
  28.       this.pan = var1;
  29.       this.data = var2;
  30.       this.tree = var3;
  31.    }
  32.  
  33.    public void mouseClicked(MouseEvent var1) {
  34.    }
  35.  
  36.    public void mouseEntered(MouseEvent var1) {
  37.    }
  38.  
  39.    public void mouseExited(MouseEvent var1) {
  40.    }
  41.  
  42.    public void mousePressed(MouseEvent var1) {
  43.    }
  44.  
  45.    public void mouseReleased(MouseEvent var1) {
  46.       if ((var1.isPopupTrigger() || ((InputEvent)var1).getModifiers() == 4) && this.tree.popup != null) {
  47.          this.tree.popup.removeAll();
  48.          PopupSelected var2 = new PopupSelected(this.tree, this.theApp);
  49.          if (this.tree.selectedElem != null && this.tree.selectedElem.e.getNodeType() == 1) {
  50.             this.tree.popup.addPopupMenuListener(this);
  51.             int var4 = 0;
  52.             boolean var5 = false;
  53.             ElemPalette var6 = this.theApp.elemPalette;
  54.             if (var6.model.size() > 0) {
  55.                this.addE = new JMenu(Strings.AddElement);
  56.                ElemSelected var7 = new ElemSelected(this.tree, this.addE);
  57.                this.tree.popup.add(this.addE);
  58.                Enumeration var8 = var6.model.elements();
  59.  
  60.                while(var8.hasMoreElements() && !var5) {
  61.                   String var9 = (String)var8.nextElement();
  62.                   ++var4;
  63.                   JMenuItem var3;
  64.                   this.addE.add(var3 = new JMenuItem(var9));
  65.                   ((AbstractButton)var3).addActionListener(var7);
  66.                   if (this.tooMany(this.addE, var4)) {
  67.                      var5 = true;
  68.                   }
  69.                }
  70.             }
  71.  
  72.             JMenuItem var10;
  73.             this.tree.popup.add(var10 = new JMenuItem(Strings.AddPCDATA));
  74.             ((AbstractButton)var10).addActionListener(var2);
  75.             int var19 = 0;
  76.             if (this.theApp.xmlDocument.entVals != null) {
  77.                this.addF = new JMenu(Strings.AddEntity);
  78.                EntSelected var20 = new EntSelected(this.tree, this.addF, this.theApp);
  79.                this.tree.popup.add(this.addF);
  80.                Enumeration var21 = this.theApp.xmlDocument.entVals.keys();
  81.  
  82.                while(var21.hasMoreElements() && var19++ < POPUPLIMIT) {
  83.                   this.addF.add(var10 = new JMenuItem(var21.nextElement().toString()));
  84.                   ((AbstractButton)var10).addActionListener(var20);
  85.                }
  86.  
  87.                if (var19 >= POPUPLIMIT) {
  88.                   this.addF.addSeparator();
  89.                   this.addF.add(new JMenuItem(Strings.MoreInEntity));
  90.                }
  91.             }
  92.  
  93.             this.tree.popup.add(var10 = new JMenuItem(Strings.AddCDATA));
  94.             ((AbstractButton)var10).addActionListener(var2);
  95.             this.tree.popup.add(var10 = new JMenuItem(Strings.AddComment));
  96.             ((AbstractButton)var10).addActionListener(var2);
  97.          }
  98.  
  99.          JMenuItem var14;
  100.          this.tree.popup.add(var14 = new JMenuItem(Strings.DeleteElement));
  101.          ((AbstractButton)var14).addActionListener(var2);
  102.          this.tree.popup.add(var14 = new JMenuItem(Strings.MoveElementUp));
  103.          ((AbstractButton)var14).addActionListener(var2);
  104.          this.tree.popup.add(var14 = new JMenuItem(Strings.MoveElementDown));
  105.          ((AbstractButton)var14).addActionListener(var2);
  106.          this.tree.popup.add(var14 = new JMenuItem(Strings.ExpandBeneath));
  107.          ((AbstractButton)var14).addActionListener(var2);
  108.          this.tree.popup.add(var14 = new JMenuItem(Strings.CollapseBeneath));
  109.          ((AbstractButton)var14).addActionListener(var2);
  110.          this.tree.popup.show(this.tree.theTree, var1.getX(), var1.getY());
  111.       }
  112.  
  113.    }
  114.  
  115.    public void nodeSelected(ElemNode var1) {
  116.       this.theApp.treeSelected = true;
  117.       Node var2 = var1.e;
  118.       this.tree.selectedElem = var1;
  119.       if (var2.getParentNode() != null) {
  120.          if (var2.getNodeType() == 1) {
  121.             this.pan.editElement(var2);
  122.             this.data.setText("");
  123.             this.data.setEditable(false);
  124.             this.data.repaint();
  125.             if (this.theApp.xmlDocument.entVals != null) {
  126.                this.theApp.entityPalette.curr.setEnabled(true);
  127.             } else {
  128.                this.theApp.entityPalette.curr.setEnabled(false);
  129.             }
  130.          } else if (var2.getNodeType() == 3) {
  131.             this.pan.clear();
  132.             String var3 = var2.getNodeValue();
  133.             var3 = StringUtils.replaceStr(var3, "<", '<');
  134.             this.data.setText(var3);
  135.             this.data.repaint();
  136.             this.data.setEditable(true);
  137.             this.theApp.entityPalette.curr.setEnabled(false);
  138.          } else if (var2.getNodeType() == 4) {
  139.             this.pan.clear();
  140.             String var5 = var2.getNodeValue();
  141.             this.data.setText(var5);
  142.             this.data.repaint();
  143.             this.data.setEditable(true);
  144.             this.theApp.entityPalette.curr.setEnabled(false);
  145.          } else if (var2.getNodeType() == 8) {
  146.             this.pan.clear();
  147.             String var6 = var2.getNodeValue();
  148.             this.data.setText(var6);
  149.             this.data.repaint();
  150.             this.data.setEditable(true);
  151.             this.theApp.entityPalette.curr.setEnabled(false);
  152.          } else if (var2.getNodeType() == 5) {
  153.             this.pan.clear();
  154.             this.data.setText("");
  155.             String var7 = var2.getNodeValue();
  156.             this.data.setText((String)this.theApp.xmlDocument.entVals.get(var2.getNodeName()));
  157.             this.data.repaint();
  158.             this.data.setEditable(false);
  159.             this.theApp.entityPalette.curr.setEnabled(false);
  160.          }
  161.  
  162.          this.theApp.elemPalette.updateElements();
  163.       }
  164.    }
  165.  
  166.    public void popupMenuCanceled(PopupMenuEvent var1) {
  167.       if (this.addE != null) {
  168.          this.addE.setSelected(false);
  169.          this.addE.setPopupMenuVisible(false);
  170.       }
  171.  
  172.       if (this.addF != null) {
  173.          this.addF.setSelected(false);
  174.          this.addF.setPopupMenuVisible(false);
  175.       }
  176.  
  177.    }
  178.  
  179.    public void popupMenuWillBecomeInvisible(PopupMenuEvent var1) {
  180.    }
  181.  
  182.    public void popupMenuWillBecomeVisible(PopupMenuEvent var1) {
  183.    }
  184.  
  185.    public boolean tooMany(JMenu var1, int var2) {
  186.       if (var2 < POPUPLIMIT) {
  187.          return false;
  188.       } else {
  189.          var1.addSeparator();
  190.          var1.add(new JMenuItem(Strings.MoreInElement));
  191.          return true;
  192.       }
  193.    }
  194.  
  195.    public void valueChanged(TreeSelectionEvent var1) {
  196.       ElemNode var2 = (ElemNode)var1.getPath().getLastPathComponent();
  197.       this.nodeSelected(var2);
  198.    }
  199. }
  200.