예제 #1
0
    //
    // PropertyChangeListener
    //
    public void propertyChange(PropertyChangeEvent e) {
      if (e.getSource() == optionPane) {
        // Option Pane Auditory Cue Activation
        // only respond to "ancestor" changes
        // the idea being that a JOptionPane gets a JDialog when it is
        // set to appear and loses it's JDialog when it is dismissed.
        if ("ancestor" == e.getPropertyName()) {
          JOptionPane op = (JOptionPane) e.getSource();
          boolean isComingUp;

          // if the old value is null, then the JOptionPane is being
          // created since it didn't previously have an ancestor.
          if (e.getOldValue() == null) {
            isComingUp = true;
          } else {
            isComingUp = false;
          }

          // figure out what to do based on the message type
          switch (op.getMessageType()) {
            case JOptionPane.PLAIN_MESSAGE:
              if (isComingUp) {
                BasicLookAndFeel.playSound(optionPane, "OptionPane.informationSound");
              }
              break;
            case JOptionPane.QUESTION_MESSAGE:
              if (isComingUp) {
                BasicLookAndFeel.playSound(optionPane, "OptionPane.questionSound");
              }
              break;
            case JOptionPane.INFORMATION_MESSAGE:
              if (isComingUp) {
                BasicLookAndFeel.playSound(optionPane, "OptionPane.informationSound");
              }
              break;
            case JOptionPane.WARNING_MESSAGE:
              if (isComingUp) {
                BasicLookAndFeel.playSound(optionPane, "OptionPane.warningSound");
              }
              break;
            case JOptionPane.ERROR_MESSAGE:
              if (isComingUp) {
                BasicLookAndFeel.playSound(optionPane, "OptionPane.errorSound");
              }
              break;
            default:
              System.err.println("Undefined JOptionPane type: " + op.getMessageType());
              break;
          }
        }
        // Visual activity
        String changeName = e.getPropertyName();

        if (changeName == JOptionPane.OPTIONS_PROPERTY
            || changeName == JOptionPane.INITIAL_VALUE_PROPERTY
            || changeName == JOptionPane.ICON_PROPERTY
            || changeName == JOptionPane.MESSAGE_TYPE_PROPERTY
            || changeName == JOptionPane.OPTION_TYPE_PROPERTY
            || changeName == JOptionPane.MESSAGE_PROPERTY
            || changeName == JOptionPane.SELECTION_VALUES_PROPERTY
            || changeName == JOptionPane.INITIAL_SELECTION_VALUE_PROPERTY
            || changeName == JOptionPane.WANTS_INPUT_PROPERTY) {
          uninstallComponents();
          installComponents();
          optionPane.validate();
        } else if (changeName == "componentOrientation") {
          ComponentOrientation o = (ComponentOrientation) e.getNewValue();
          JOptionPane op = (JOptionPane) e.getSource();
          if (o != e.getOldValue()) {
            op.applyComponentOrientation(o);
          }
        }
      }
    }
예제 #2
0
 static void loadActionMap(LazyActionMap map) {
   map.put(new Actions(Actions.CLOSE));
   BasicLookAndFeel.installAudioActionMap(map);
 }