Пример #1
1
    public void run() {
      SearchTOCItem tocitem;
      Vector nodes = new Vector();

      // Add all the children of the topnode to the Vector of nodes.
      Enumeration children = topNode.children();
      while (children.hasMoreElements()) {
        DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();
        nodes.addElement(node);
      }

      debug("items found");
      HelpModel helpmodel = searchnav.getModel();
      HelpSet hs = helpmodel.getHelpSet();
      debug("hs:" + hs.toString());
      Map map = hs.getCombinedMap();
      Enumeration itemEnum = e.getSearchItems();
      while (itemEnum.hasMoreElements()) {
        SearchItem item = (SearchItem) itemEnum.nextElement();
        debug("  item: " + item);
        URL url;
        try {
          url = new URL(item.getBase(), item.getFilename());
        } catch (MalformedURLException me) {
          System.err.println(
              "Failed to create URL from " + item.getBase() + "|" + item.getFilename());
          continue;
        }
        boolean foundNode = false;
        DefaultMutableTreeNode node = null;
        Enumeration nodesEnum = nodes.elements();
        while (nodesEnum.hasMoreElements()) {
          node = (DefaultMutableTreeNode) nodesEnum.nextElement();
          tocitem = (SearchTOCItem) node.getUserObject();
          URL testURL = tocitem.getURL();
          if (testURL != null && url != null && url.sameFile(testURL)) {
            tocitem = (SearchTOCItem) node.getUserObject();
            tocitem.addSearchHit(
                new SearchHit(item.getConfidence(), item.getBegin(), item.getEnd()));
            foundNode = true;
            break;
          }
        }
        if (!foundNode) {
          tocitem = new SearchTOCItem(item);
          node = new DefaultMutableTreeNode(tocitem);
          nodes.addElement(node);
        }
      }
      reorder(nodes);
      ((DefaultTreeModel) tree.getModel()).reload();
    }
Пример #2
0
  /** A value has changed. This is used as a TreeSelectionListener. */
  public void valueChanged(TreeSelectionEvent e) {

    JHelpNavigator navigator = getHelpNavigator();
    HelpModel helpmodel = navigator.getModel();

    debug("ValueChanged: " + e);
    debug("  model: " + helpmodel);

    // send selected items into navigator
    TreeItem[] items = null;
    TreePath[] paths = tree.getSelectionPaths();
    if (paths != null) {
      items = new TreeItem[paths.length];
      for (int i = 0; i < paths.length; i++) {
        if (paths[i] != null) {
          DefaultMutableTreeNode node = (DefaultMutableTreeNode) paths[i].getLastPathComponent();
          items[i] = (TreeItem) node.getUserObject();
        }
      }
    }
    navigator.setSelectedItems(items);

    // change current id only if one items is selected
    if (items != null && items.length == 1) {
      SearchTOCItem item = (SearchTOCItem) items[0];
      if (item != null) {
        if (item.getID() != null) {
          try {
            // navigator.setCurrentID(item.getID());
            helpmodel.setCurrentID(item.getID(), item.getName(), navigator);
          } catch (InvalidHelpSetContextException ex) {
            System.err.println("BadID: " + item.getID());
            return;
          }
        } else if (item.getURL() != null) {
          // navigator.setCurrentURL(item.getURL());
          helpmodel.setCurrentURL(item.getURL(), item.getName(), navigator);
        } else {
          // no ID, no URL
          return;
        }
        if (helpmodel instanceof TextHelpModel) {
          DefaultHighlight h[] = new DefaultHighlight[item.hitCount()];
          int i = 0;
          Enumeration enum1 = item.getSearchHits();
          while (enum1.hasMoreElements()) {
            SearchHit info = (SearchHit) enum1.nextElement();
            h[i] = new DefaultHighlight(info.getBegin(), info.getEnd());
            i++;
          }
          // using setHighlights() instead of removeAll + add
          // avoids one highlighting event
          ((TextHelpModel) helpmodel).setHighlights(h);
        }
      }
    }
  }
Пример #3
0
 /** Indicates that there is new search data to use. */
 private void reloadData() {
   helpsearch = null;
   setCellRenderer(searchnav.getNavigatorView(), tree);
   // add all subhelpsets
   HelpModel model = searchnav.getModel();
   if (model != null) {
     addSubHelpSets(model.getHelpSet());
   }
 }
Пример #4
0
  public void uninstallUI(JComponent c) {
    HelpModel helpmodel = searchnav.getModel();

    searchnav.removeComponentListener(this);
    searchnav.removePropertyChangeListener(this);
    TreeSelectionModel tsm = tree.getSelectionModel();
    tsm.removeTreeSelectionListener(this);
    searchnav.setLayout(null);
    searchnav.removeAll();

    if (helpmodel != null) {
      helpmodel.removeHelpModelListener(this);
    }
    searchnav = null;
  }
Пример #5
0
  /**
   * Reloads data from new model, creates new search engine to search in new model if model contains
   * view with the same name
   */
  private void reloadData(HelpModel model) {
    debug("reloadData using new model");
    helpsearch = null;
    SearchView view = null;

    newHelpSet = model.getHelpSet();
    SearchView oldView = (SearchView) searchnav.getNavigatorView();
    String oldName = oldView.getName();
    NavigatorView[] navViews = newHelpSet.getNavigatorViews();
    for (int i = 0; i < navViews.length; i++) {
      if ((navViews[i].getName()).equals(oldName)) {
        NavigatorView tempView = navViews[i];
        if (tempView instanceof SearchView) {
          view = (SearchView) tempView;
          break;
        }
      }
    }

    if (view == null) return;

    topNode.removeAllChildren();
    searchnav.setSearchEngine(new MergingSearchEngine(view));

    setCellRenderer(view, tree);
    // add all subhelpsets
    addSubHelpSets(newHelpSet);
  }
Пример #6
0
  public void installUI(JComponent c) {
    searchnav = (JHelpSearchNavigator) c;
    HelpModel helpmodel = searchnav.getModel();

    searchnav.setLayout(new BorderLayout());
    searchnav.addPropertyChangeListener(this);
    searchnav.addComponentListener(this);
    if (helpmodel != null) {
      helpmodel.addHelpModelListener(this);
    }

    JLabel search =
        new JLabel(HelpUtilities.getString(HelpUtilities.getLocale(c), "search.findLabel"));
    searchparams = new JTextField("", 20);
    search.setLabelFor(searchparams);
    searchparams.addActionListener(searchAction);

    JPanel box = new JPanel();
    box.setLayout(new BoxLayout(box, BoxLayout.X_AXIS));
    box.add(search);
    box.add(searchparams);

    searchnav.add("North", box);
    topNode = new DefaultMutableTreeNode();
    lastTOCnode = null;
    tree = new JTree(topNode);
    // public String convertValueToText(Object val
    TreeSelectionModel tsm = tree.getSelectionModel();
    tsm.addTreeSelectionListener(this);
    tree.setShowsRootHandles(false);
    tree.setRootVisible(false);
    sp = new JScrollPane();
    sp.getViewport().add(tree);
    searchnav.add("Center", sp);
    reloadData();
  }