示例#1
0
  public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() instanceof JComponent && "name".equals(e.getPropertyName())) {
      // Note - most components do NOT fire a property change on
      // setName(), but it is possible for this to be done intentionally
      if (e.getOldValue() instanceof String) {
        if (logger.isLoggable(Level.FINE)) {
          logger.fine(
              "Name of component changed from "
                  + e.getOldValue()
                  + // NOI18N
                  " to "
                  + e.getNewValue()
                  + ".  Removing any values for "
                  + // NOI18N
                  e.getOldValue()
                  + " from the wizard data map"); // NOI18N
        }
        wizardPage.removeFromMap(e.getOldValue());
      }

      if (logger.isLoggable(Level.FINE)) {
        logger.fine(
            "Possibly update map for renamed component "
                + // NOI18N
                e.getSource());
      }

    } else if (e.getSource() instanceof JFormattedTextField
        && "value".equals(e.getPropertyName())) {
      fire(e);
      wizardPage.maybeUpdateMap((JComponent) e.getSource());
    }
  }
示例#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
 public GenericListener(
     WizardPage wizardPage,
     WizardPage.CustomComponentListener l,
     WizardPage.CustomComponentNotifier n) {
   this.extListener = l;
   this.extNotifier = n;
   if ((extListener == null) != (extNotifier == null)) {
     throw new RuntimeException();
   }
   // assert wizardPage != null : "WizardPage may not be null"; // NOI18N
   if (wizardPage == null) {
     throw new IllegalArgumentException("WizardPage may not be null"); // NOI18N)
   }
   this.wizardPage = wizardPage;
   wizardPage.addContainerListener(this);
 }
示例#5
0
 private void fire(Object e) {
   if (!ignoreEvents) {
     setIgnoreEvents(true);
     try {
       // XXX this could be prettier...
       if (logger.isLoggable(Level.FINE)) {
         logger.fine("Event received: " + e); // NOI18N
       }
       if (e instanceof EventObject && ((EventObject) e).getSource() instanceof Component) {
         wizardPage.userInputReceived((Component) ((EventObject) e).getSource(), e);
       } else if (e instanceof TreeSelectionEvent) {
         logger.fine("Looking for a tree for a tree selection event"); // NOI18N
         TreeSelectionModel mdl = (TreeSelectionModel) ((TreeSelectionEvent) e).getSource();
         for (Iterator i = listenedTo.iterator(); i.hasNext(); ) {
           Object o = i.next();
           if (o instanceof JTree && ((JTree) o).getSelectionModel() == mdl) {
             if (logger.isLoggable(Level.FINE)) {
               logger.fine("  found it: " + o); // NOI18N
             }
             wizardPage.userInputReceived((Component) o, e);
             break;
           }
         }
       } else if (e instanceof DocumentEvent) {
         logger.fine("Looking for a JTextComponent for a DocumentEvent"); // NOI18N
         Document document = ((DocumentEvent) e).getDocument();
         for (Iterator i = listenedTo.iterator(); i.hasNext(); ) {
           Object o = i.next();
           if (o instanceof JTextComponent && ((JTextComponent) o).getDocument() == document) {
             if (logger.isLoggable(Level.FINE)) {
               logger.fine("  found it: " + o); // NOI18N
             }
             wizardPage.userInputReceived((Component) o, e);
             break;
           }
         }
       } else if (e instanceof ListSelectionEvent) {
         logger.fine("Looking for a JList or JTable for a ListSelectionEvent"); // NOI18N
         ListSelectionModel model = (ListSelectionModel) ((ListSelectionEvent) e).getSource();
         for (Iterator i = listenedTo.iterator(); i.hasNext(); ) {
           Object o = i.next();
           if (o instanceof JList && ((JList) o).getSelectionModel() == model) {
             if (logger.isLoggable(Level.FINE)) {
               logger.fine("  found it: " + o); // NOI18N
             }
             wizardPage.userInputReceived((Component) o, e);
             break;
           } else if (o instanceof JTable && ((JTable) o).getSelectionModel() == model) {
             if (logger.isLoggable(Level.FINE)) {
               logger.fine("  found it: " + o); // NOI18N
             }
             wizardPage.userInputReceived((Component) o, e);
             break;
           }
         }
       } else {
         wizardPage.userInputReceived(null, e);
       }
     } finally {
       setIgnoreEvents(false);
     }
   }
 }