Пример #1
0
 public void componentRemoved(ContainerEvent e) {
   if (extListener != null && extListener.accept(e.getChild())) {
     extListener.stopListeningTo(e.getChild());
     listenedTo.remove(e.getChild());
   } else if (accept(e.getChild())) {
     detachFrom(e.getChild());
   }
 }
Пример #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
    }
  }
Пример #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
    }
  }
Пример #4
0
 protected boolean accept(Component jc) {
   if (extListener != null && extListener.accept(jc)) {
     return true;
   }
   if (!(jc instanceof JComponent)) {
     return false;
   }
   if (jc instanceof TableCellEditor
       || jc instanceof TreeCellEditor
       || SwingUtilities.getAncestorOfClass(JTable.class, jc) != null
       || SwingUtilities.getAncestorOfClass(JTree.class, jc) != null
       || SwingUtilities.getAncestorOfClass(JList.class, jc) != null) {
     // Don't listen to cell editors, we can end up listening to them
     // multiple times, and the tree/table model will give us the event
     // we need
     return false;
   }
   return isProbablyAContainer(jc)
       || jc instanceof JList
       || jc instanceof JComboBox
       || jc instanceof JTree
       || jc instanceof JToggleButton
       || // covers toggle, radio, checkbox
       jc instanceof JTextComponent
       || jc instanceof JColorChooser
       || jc instanceof JSpinner
       || jc instanceof JSlider;
 }
Пример #5
0
 /**
  * Return true if the given component is likely to be a container such the each component within
  * the container should be be considered as a user input.
  *
  * @param c
  * @return true if the component children should have this listener added.
  */
 protected boolean isProbablyAContainer(Component c) {
   boolean result = extListener != null ? extListener.isContainer(c) : false;
   if (!result) {
     boolean isSwing = isSwingClass(c);
     if (isSwing) {
       result =
           c instanceof JPanel
               || c instanceof JSplitPane
               || c instanceof JToolBar
               || c instanceof JViewport
               || c instanceof JScrollPane
               || c instanceof JFrame
               || c instanceof JRootPane
               || c instanceof Window
               || c instanceof Frame
               || c instanceof Dialog
               || c instanceof JTabbedPane
               || c instanceof JInternalFrame
               || c instanceof JDesktopPane
               || c instanceof JLayeredPane
               || c instanceof Box;
     } else {
       result = c instanceof Container;
     }
   }
   return result;
 }