jdk/src/java.desktop/share/classes/javax/swing/JOptionPane.java
changeset 26037 508779ce6619
parent 26001 991e1be0b235
parent 25859 3317bb8137f4
child 28231 b608ffcaed74
equal deleted inserted replaced
25992:e9b05e933ddd 26037:508779ce6619
    41 import java.awt.event.WindowAdapter;
    41 import java.awt.event.WindowAdapter;
    42 import java.awt.event.WindowEvent;
    42 import java.awt.event.WindowEvent;
    43 import java.awt.event.ComponentAdapter;
    43 import java.awt.event.ComponentAdapter;
    44 import java.awt.event.ComponentEvent;
    44 import java.awt.event.ComponentEvent;
    45 import java.io.IOException;
    45 import java.io.IOException;
       
    46 import java.io.InvalidObjectException;
    46 import java.io.ObjectInputStream;
    47 import java.io.ObjectInputStream;
    47 import java.io.ObjectOutputStream;
    48 import java.io.ObjectOutputStream;
    48 import java.io.Serializable;
    49 import java.io.Serializable;
    49 import java.lang.reflect.Method;
       
    50 import java.lang.reflect.InvocationTargetException;
       
    51 import java.security.AccessController;
       
    52 import java.security.PrivilegedAction;
       
    53 import java.util.Vector;
    50 import java.util.Vector;
    54 import javax.swing.plaf.OptionPaneUI;
    51 import javax.swing.plaf.OptionPaneUI;
    55 import javax.swing.event.InternalFrameEvent;
    52 import javax.swing.event.InternalFrameEvent;
    56 import javax.swing.event.InternalFrameAdapter;
    53 import javax.swing.event.InternalFrameAdapter;
    57 import javax.accessibility.*;
    54 import javax.accessibility.*;
  2053      *   preferred: true
  2050      *   preferred: true
  2054      *       bound: true
  2051      *       bound: true
  2055      * description: The option pane's message type.
  2052      * description: The option pane's message type.
  2056      */
  2053      */
  2057     public void setMessageType(int newType) {
  2054     public void setMessageType(int newType) {
       
  2055         checkMessageType(newType);
       
  2056         int           oldType = messageType;
       
  2057         messageType = newType;
       
  2058         firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType);
       
  2059     }
       
  2060 
       
  2061     private static void checkMessageType(int newType){
  2058         if(newType != ERROR_MESSAGE && newType != INFORMATION_MESSAGE &&
  2062         if(newType != ERROR_MESSAGE && newType != INFORMATION_MESSAGE &&
  2059            newType != WARNING_MESSAGE && newType != QUESTION_MESSAGE &&
  2063            newType != WARNING_MESSAGE && newType != QUESTION_MESSAGE &&
  2060            newType != PLAIN_MESSAGE)
  2064            newType != PLAIN_MESSAGE)
  2061             throw new RuntimeException("JOptionPane: type must be one of JOptionPane.ERROR_MESSAGE, JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.QUESTION_MESSAGE or JOptionPane.PLAIN_MESSAGE");
  2065             throw new RuntimeException("JOptionPane: type must be one of"
  2062 
  2066                     + " JOptionPane.ERROR_MESSAGE,"
  2063         int           oldType = messageType;
  2067                     + " JOptionPane.INFORMATION_MESSAGE,"
  2064 
  2068                     + " JOptionPane.WARNING_MESSAGE,"
  2065         messageType = newType;
  2069                     + " JOptionPane.QUESTION_MESSAGE"
  2066         firePropertyChange(MESSAGE_TYPE_PROPERTY, oldType, messageType);
  2070                     + " or JOptionPane.PLAIN_MESSAGE");
  2067     }
  2071     }
  2068 
  2072 
  2069     /**
  2073     /**
  2070      * Returns the message type.
  2074      * Returns the message type.
  2071      *
  2075      *
  2095      *   preferred: true
  2099      *   preferred: true
  2096      *       bound: true
  2100      *       bound: true
  2097      * description: The option pane's option type.
  2101      * description: The option pane's option type.
  2098       */
  2102       */
  2099     public void setOptionType(int newType) {
  2103     public void setOptionType(int newType) {
  2100         if(newType != DEFAULT_OPTION && newType != YES_NO_OPTION &&
  2104         checkOptionType(newType);
  2101            newType != YES_NO_CANCEL_OPTION && newType != OK_CANCEL_OPTION)
       
  2102             throw new RuntimeException("JOptionPane: option type must be one of JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION, JOptionPane.YES_NO_CANCEL_OPTION or JOptionPane.OK_CANCEL_OPTION");
       
  2103 
       
  2104         int            oldType = optionType;
  2105         int            oldType = optionType;
  2105 
       
  2106         optionType = newType;
  2106         optionType = newType;
  2107         firePropertyChange(OPTION_TYPE_PROPERTY, oldType, optionType);
  2107         firePropertyChange(OPTION_TYPE_PROPERTY, oldType, optionType);
       
  2108     }
       
  2109 
       
  2110     private static void checkOptionType(int newType) {
       
  2111         if (newType != DEFAULT_OPTION && newType != YES_NO_OPTION
       
  2112                 && newType != YES_NO_CANCEL_OPTION
       
  2113                 && newType != OK_CANCEL_OPTION) {
       
  2114             throw new RuntimeException("JOptionPane: option type must be one of"
       
  2115                     + " JOptionPane.DEFAULT_OPTION, JOptionPane.YES_NO_OPTION,"
       
  2116                     + " JOptionPane.YES_NO_CANCEL_OPTION"
       
  2117                     + " or JOptionPane.OK_CANCEL_OPTION");
       
  2118         }
  2108     }
  2119     }
  2109 
  2120 
  2110     /**
  2121     /**
  2111      * Returns the type of options that are displayed.
  2122      * Returns the type of options that are displayed.
  2112      *
  2123      *
  2383         s.writeObject(values);
  2394         s.writeObject(values);
  2384     }
  2395     }
  2385 
  2396 
  2386     private void readObject(ObjectInputStream s)
  2397     private void readObject(ObjectInputStream s)
  2387         throws IOException, ClassNotFoundException {
  2398         throws IOException, ClassNotFoundException {
  2388         s.defaultReadObject();
  2399         ObjectInputStream.GetField f = s.readFields();
       
  2400 
       
  2401         int newMessageType = f.get("messageType", 0);
       
  2402         checkMessageType(newMessageType);
       
  2403         messageType = newMessageType;
       
  2404         int newOptionType = f.get("optionType", 0);
       
  2405         checkOptionType(newOptionType);
       
  2406         optionType = newOptionType;
       
  2407         wantsInput = f.get("wantsInput", false);
  2389 
  2408 
  2390         Vector<?>       values = (Vector)s.readObject();
  2409         Vector<?>       values = (Vector)s.readObject();
  2391         int             indexCounter = 0;
  2410         int             indexCounter = 0;
  2392         int             maxCounter = values.size();
  2411         int             maxCounter = values.size();
  2393 
  2412