public CompleteWordList(
      View view,
      String word,
      Vector completions,
      Point location,
      String noWordSep,
      boolean isGlobalSearch) {
    super(view);
    this.isGlobalSearch = isGlobalSearch;
    this.noWordSep = noWordSep;

    setContentPane(
        new JPanel(new BorderLayout()) {
          /**
           * Returns if this component can be traversed by pressing the Tab key. This returns false.
           */
          public boolean isManagingFocus() {
            return false;
          }

          /** Makes the tab key work in Java 1.4. */
          public boolean getFocusTraversalKeysEnabled() {
            return false;
          }
        });

    this.view = view;
    this.textArea = view.getTextArea();
    this.buffer = view.getBuffer();
    this.word = word;

    words = new JList(completions);

    words.setVisibleRowCount(Math.min(completions.size(), 8));

    words.addMouseListener(new MouseHandler());
    words.setSelectedIndex(0);
    words.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    words.setCellRenderer(new Renderer());

    // stupid scrollbar policy is an attempt to work around
    // bugs people have been seeing with IBM's JDK -- 7 Sep 2000
    JScrollPane scroller =
        new JScrollPane(
            words, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);

    getContentPane().add(scroller, BorderLayout.CENTER);

    GUIUtilities.requestFocus(this, words);

    pack();
    setLocation(location);
    show();

    KeyHandler keyHandler = new KeyHandler();
    addKeyListener(keyHandler);
    words.addKeyListener(keyHandler);
    view.setKeyEventInterceptor(keyHandler);
  }
Example #2
0
    CompletionPopup(String[] actions) {
      super(view);

      setContentPane(
          new JPanel(new BorderLayout()) {

            public boolean isManagingFocus() {
              return false;
            }

            public boolean getFocusTraversalKeysEnabled() {
              return false;
            }
          });

      list = new CompletionList(actions);
      list.setVisibleRowCount(8);
      list.addMouseListener(new MouseHandler());
      list.setSelectedIndex(0);
      list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

      JScrollPane scroller =
          new JScrollPane(
              list,
              ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
              ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

      getContentPane().add(scroller, BorderLayout.CENTER);

      GUIUtilities.requestFocus(this, list);

      pack();
      Point p = new Point(0, -getHeight());
      SwingUtilities.convertPointToScreen(p, action);
      setLocation(p);
      setVisible(true);

      KeyHandler keyHandler = new KeyHandler();
      addKeyListener(keyHandler);
      list.addKeyListener(keyHandler);
    }