private void installListeners() { if (myWindow != null) { myWindowListener = createWindowListener(); myWindow.addWindowListener(myWindowListener); myPropertyChangeListener = createWindowPropertyChangeListener(); myWindow.addPropertyChangeListener(myPropertyChangeListener); } }
/** 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(); }