Exemplo n.º 1
0
 void lookup(String text) {
   NodeList nl = DOMInfoExtractor.locateNodes(document, ".//text()[contains(.,'" + text + "')]");
   System.out.println("find " + nl.getLength() + " items");
   FoundItem[] fis = new FoundItem[nl.getLength()];
   for (int i = 0; i < nl.getLength(); i++) {
     fis[i] = getFoundItem(nl.item(i), text);
   }
   foundList.setListData(fis);
 }
Exemplo n.º 2
0
  protected void attachTo(Component jc) {
    if (extListener != null && extListener.accept(jc)) {
      extListener.startListeningTo(jc, extNotifier);
      listenedTo.add(jc);
      if (wizardPage.getMapKeyFor(jc) != null) {
        wizardPage.maybeUpdateMap(jc);
      }
      return;
    }
    if (isProbablyAContainer(jc)) {
      attachToHierarchyOf((Container) jc);
    } else if (jc instanceof JList) {
      listenedTo.add(jc);
      ((JList) jc).addListSelectionListener(this);
    } else if (jc instanceof JComboBox) {
      ((JComboBox) jc).addActionListener(this);
    } else if (jc instanceof JTree) {
      listenedTo.add(jc);
      ((JTree) jc).getSelectionModel().addTreeSelectionListener(this);
    } else if (jc instanceof JToggleButton) {
      ((AbstractButton) jc).addItemListener(this);
    } else if (jc
        instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent
      jc.addPropertyChangeListener("value", this);
    } else if (jc instanceof JTextComponent) {
      listenedTo.add(jc);
      ((JTextComponent) jc).getDocument().addDocumentListener(this);
    } else if (jc instanceof JColorChooser) {
      listenedTo.add(jc);
      ((JColorChooser) jc).getSelectionModel().addChangeListener(this);
    } else if (jc instanceof JSpinner) {
      ((JSpinner) jc).addChangeListener(this);
    } else if (jc instanceof JSlider) {
      ((JSlider) jc).addChangeListener(this);
    } else if (jc instanceof JTable) {
      listenedTo.add(jc);
      ((JTable) jc).getSelectionModel().addListSelectionListener(this);
    } else {
      if (logger.isLoggable(Level.FINE)) {
        logger.fine(
            "Don't know how to listen to a "
                + // NOI18N
                jc.getClass().getName());
      }
    }

    if (accept(jc) && !(jc instanceof JPanel)) {
      jc.addPropertyChangeListener("name", this);
      if (wizardPage.getMapKeyFor(jc) != null) {
        wizardPage.maybeUpdateMap(jc);
      }
    }

    if (logger.isLoggable(Level.FINE) && accept(jc)) {
      logger.fine("Begin listening to " + jc); // NOI18N
    }
  }
Exemplo n.º 3
0
  protected void detachFrom(Component jc) {
    listenedTo.remove(jc);
    if (extListener != null && extListener.accept(jc)) {
      extListener.stopListeningTo(jc);
    }
    if (isProbablyAContainer(jc)) {
      detachFromHierarchyOf((Container) jc);
    } else if (jc instanceof JList) {
      ((JList) jc).removeListSelectionListener(this);
    } else if (jc instanceof JComboBox) {
      ((JComboBox) jc).removeActionListener(this);
    } else if (jc instanceof JTree) {
      ((JTree) jc).getSelectionModel().removeTreeSelectionListener(this);
    } else if (jc instanceof JToggleButton) {
      ((AbstractButton) jc).removeActionListener(this);
    } else if (jc instanceof JTextComponent) {
    } else if (jc
        instanceof JFormattedTextField) { // JFormattedTextField must be tested before JTextCompoent
      jc.removePropertyChangeListener("value", this);
      ((JTextComponent) jc).getDocument().removeDocumentListener(this);
    } else if (jc instanceof JColorChooser) {
      ((JColorChooser) jc).getSelectionModel().removeChangeListener(this);
    } else if (jc instanceof JSpinner) {
      ((JSpinner) jc).removeChangeListener(this);
    } else if (jc instanceof JSlider) {
      ((JSlider) jc).removeChangeListener(this);
    } else if (jc instanceof JTable) {
      ((JTable) jc).getSelectionModel().removeListSelectionListener(this);
    }

    if (accept(jc) && !(jc instanceof JPanel)) {
      jc.removePropertyChangeListener("name", this);
      Object key = wizardPage.getMapKeyFor(jc);

      if (key != null) {
        if (logger.isLoggable(Level.FINE)) {
          logger.fine(
              "Named component removed from hierarchy: "
                  + // NOI18N
                  key
                  + ".  Removing any corresponding "
                  + // NOI18N
                  "value from the wizard settings map."); // NOI18N
        }

        wizardPage.removeFromMap(key);
      }
    }

    if (logger.isLoggable(Level.FINE) && accept(jc)) {
      logger.fine("Stop listening to " + jc); // NOI18N
    }
  }
Exemplo n.º 4
0
 void lookupByXPath(String xpath) {
   NodeList nl = DOMInfoExtractor.locateNodes(document, xpath);
   System.out.println("lookupByXPath: " + xpath);
   if (nl == null) {
     JOptionPane.showMessageDialog(this, "error xpath: " + xpath);
   }
   System.out.println("find " + nl.getLength() + " items");
   FoundItem[] fis = new FoundItem[nl.getLength()];
   for (int i = 0; i < nl.getLength(); i++) {
     fis[i] = getFoundItem(nl.item(i), null);
   }
   foundList.setListData(fis);
 }
Exemplo n.º 5
0
  public DOMTreeView(Document dom) {
    super("TreeWalkerView ");

    document = dom;
    // jtree  UI setup
    jtree = new DOMTreeFull((Node) document);
    jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);

    // Listen for when the selection changes, call nodeSelected(node)
    jtree.addTreeSelectionListener(
        new TreeSelectionListener() {
          public void valueChanged(TreeSelectionEvent e) {
            TreePath path = (TreePath) e.getPath();
            TreeNode treeNode = (TreeNode) path.getLastPathComponent();
            if (jtree.getSelectionModel().isPathSelected(path)) nodeSelected(treeNode);
          }
        });

    treeScroll = new JScrollPane(jtree);
    treeScroll.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("DOM Tree View"),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));

    JPanel urlPanel = new JPanel();
    JLabel urlLabel = new JLabel("URL:");
    urlTextField = new JTextField(50);
    urlTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == urlTextField) {
              reloadJTree(urlTextField.getText());
            }
          }
        });
    urlPanel.add(urlLabel);
    urlPanel.add(urlTextField);

    JPanel selectedXPathPanel = new JPanel();
    JLabel xpathLabel = new JLabel("XPath: ");
    selectedXPathTextField = new JTextField(50);
    selectedXPathTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == selectedXPathTextField) {
              lookupByXPath(selectedXPathTextField.getText());
            }
          }
        });
    selectedXPathPanel.add(xpathLabel);
    selectedXPathPanel.add(selectedXPathTextField);

    JPanel lookupPanel = new JPanel();
    JLabel lookupLabel = new JLabel("look up:");
    lookupTextField = new JTextField(20);
    lookupTextField.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            Object source = evt.getSource();
            if (source == lookupTextField) {
              lookup(lookupTextField.getText());
            }
          }
        });
    foundList = new JList();
    foundList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    foundList.addListSelectionListener(
        new ListSelectionListener() {
          public void valueChanged(ListSelectionEvent evt) {
            Object source = evt.getSource();
            if (source == foundList) {
              FoundItem fi = (FoundItem) foundList.getSelectedValue();
              if (fi == null) return;
              jtree.setSelectionPath(fi.treePath);
              jtree.scrollPathToVisible(fi.treePath);
            }
          }
        });

    JScrollPane foundScroll = new JScrollPane(foundList);
    foundScroll.setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createTitledBorder("Nodes found"),
            BorderFactory.createEmptyBorder(4, 4, 4, 4)));
    // foundScroll.set
    JPanel queryPanel = new JPanel();
    queryPanel.add(lookupLabel);
    queryPanel.add(lookupTextField);
    lookupPanel.setLayout(new BorderLayout());
    lookupPanel.add(queryPanel, BorderLayout.NORTH);
    lookupPanel.add(foundScroll, BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, treeScroll, lookupPanel);
    splitPane.setContinuousLayout(true);
    splitPane.setOneTouchExpandable(true);

    splitPane.setDividerLocation(400);

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());

    mainPanel.add(urlPanel, BorderLayout.NORTH);
    mainPanel.add(selectedXPathPanel, BorderLayout.SOUTH);
    mainPanel.add(splitPane, BorderLayout.CENTER);
    // mainPanel.add(treeScroll, BorderLayout.CENTER);
    // mainPanel.add(lookupPanel, BorderLayout.EAST);

    getContentPane().add(mainPanel);
  }
Exemplo n.º 6
0
 // -----------------------------------------
 public String[] getSelectedItems() {
   Object[] obj = listWindow.getSelectedValues();
   String[] s = new String[obj.length];
   for (int i = 0; i < obj.length; i++) s[i] = obj[i].toString();
   return s;
 }
Exemplo n.º 7
0
 // -----------------------------------------
 public JawtList(int rows) {
   listContents = new JListData();
   listWindow = new JList(listContents);
   listWindow.setPrototypeCellValue("Abcdefg Hijkmnop");
   getViewport().add(listWindow);
 }