/** Color chooser popup */
  private void showColorChooserPopup() {
    // Checking that component is eligable for focus request
    if (!requestFocusInWindow() && !isFocusOwner()) {
      // Cancel operation if component is not eligable for focus yet
      // This might occur if some other component input verifier holds the focus or in some other
      // rare cases
      return;
    }

    // Update date from field if it was changed
    updateColorFromField();

    // Create popup if it doesn't exist
    if (popup == null || colorChooserPanel == null) {
      final Window ancestor = SwingUtils.getWindowAncestor(this);

      // Color chooser
      colorChooserPanel = new WebColorChooserPanel(true);
      colorChooserPanel.setColor(color);
      colorChooserPanel.setUndecorated(false);
      colorChooserPanel.setPaintFocus(false);
      colorChooserPanel.setRound(StyleConstants.smallRound);
      colorChooserPanel.setShadeWidth(0);

      // Popup window
      popup = new WebWindow(ancestor);
      popup.setLayout(new BorderLayout());
      popup.setCloseOnFocusLoss(true);
      popup.setWindowOpaque(false);
      popup.add(colorChooserPanel);
      popup.pack();

      // Correct popup positioning
      updatePopupLocation();
      ancestor.addComponentListener(
          new ComponentAdapter() {
            @Override
            public void componentMoved(final ComponentEvent e) {
              if (popup.isShowing()) {
                updatePopupLocation();
              }
            }

            @Override
            public void componentResized(final ComponentEvent e) {
              if (popup.isShowing()) {
                updatePopupLocation();
              }
            }
          });
      ancestor.addPropertyChangeListener(
          WebLookAndFeel.ORIENTATION_PROPERTY,
          new PropertyChangeListener() {
            @Override
            public void propertyChange(final PropertyChangeEvent evt) {
              if (popup.isShowing()) {
                updatePopupLocation();
              }
            }
          });

      colorChooserPanel.addColorChooserListener(
          new ColorChooserListener() {
            @Override
            public void okPressed(final ActionEvent e) {
              setColor(colorChooserPanel.getColor());
              popup.setVisible(false);
            }

            @Override
            public void resetPressed(final ActionEvent e) {}

            @Override
            public void cancelPressed(final ActionEvent e) {
              popup.setVisible(false);
            }
          });
    } else {
      // Updating window location
      updatePopupLocation();

      // Updating color
      colorChooserPanel.setColor(color);
    }

    // Applying orientation to popup
    SwingUtils.copyOrientation(WebColorChooserField.this, popup);

    // Showing popup and changing focus
    popup.setVisible(true);
    colorChooserPanel.requestFocusInWindow();
  }
Beispiel #2
0
  private void updateHints() {
    String text = classSearchField.getText().trim();

    // Ignore empty text
    if (text.trim().length() == 0) {
      hideHints();
      return;
    }

    // Updating hints window if needed
    if (!CompareUtils.equals(lastSearchedText, text)) {
      // Saving old selection
      Object oldSelection = classSearchHintsList.getSelectedValue();

      // Clearing list
      DefaultListModel model = (DefaultListModel) classSearchHintsList.getModel();
      model.clear();

      // Look for classes
      List<JarEntry> found =
          jarStructure.findSimilarEntries(
              text,
              new Filter<JarEntry>() {
                @Override
                public boolean accept(JarEntry object) {
                  return object.getType().equals(JarEntryType.javaEntry);
                }
              });
      if (found.size() > 0) {
        classSearchField.setForeground(Color.BLACK);

        // Filling list with results
        for (JarEntry entry : found) {
          model.addElement(entry);
        }

        // Updating visible rows
        classSearchHintsList.setVisibleRowCount(Math.min(model.size(), 10));

        // Restoring selection if possible
        int index = oldSelection != null ? model.indexOf(oldSelection) : 0;
        classSearchHintsList.setSelectedIndex(index != -1 ? index : 0);

        // Packing popup
        classSearchHintsPopup.pack();

        // Displaying hints window
        if (!classSearchHintsPopup.isVisible()) {
          classSearchHintsPopup.setVisible(true);
        }
      } else {
        classSearchField.setForeground(Color.RED);

        // Hiding hints window
        if (classSearchHintsPopup.isVisible()) {
          classSearchHintsPopup.setVisible(false);
        }
      }

      lastSearchedText = text;
    }
  }