< prev index next >

## src/java.desktop/share/classes/javax/swing/text/html/FormView.java

Print this page

    rev 48358 : Work in progress for JDK-6303622
    Use generic in Swing components like JComboBox
    1. Added generic return type and parameter type for JComboBox.
    2. Modified JList related classes as well.

     766             return doc.getText(0, doc.getLength());
     767         } catch (BadLocationException e) {
     768             return null;
     769         }
     770     }
     771
     772
     773     /**
     774      * Loads the buffer with the data associated with the Select
     775      * form element.  Basically, only items that are selected
     776      * and have their name attribute set are added to the buffer.
     777      */
     778     private void loadSelectData(AttributeSet attr, StringBuilder buffer) {
     779
     780         String name = (String)attr.getAttribute(HTML.Attribute.NAME);
     781         if (name == null) {
     782             return;
     783         }
     784         Object m = attr.getAttribute(StyleConstants.ModelAttribute);
     785         if (m instanceof OptionListModel) {
     786             @SuppressWarnings("unchecked")
     787             OptionListModel<Option> model = (OptionListModel<Option>) m;
     788
     789             for (int i = 0; i < model.getSize(); i++) {
     790                 if (model.isSelectedIndex(i)) {
     791                     Option option = model.getElementAt(i);
     792                     appendBuffer(buffer, name, option.getValue());
     793                 }
     794             }
     795         } else if (m instanceof ComboBoxModel) {
     796             @SuppressWarnings("unchecked")
     797             ComboBoxModel<?> model = (ComboBoxModel)m;
     798             Option option = (Option)model.getSelectedItem();
     799             if (option != null) {
     800                 appendBuffer(buffer, name, option.getValue());
     801             }
     802         }
     803     }
     804
     805     /**
     806      * Appends name / value pairs into the
     807      * buffer.  Both names and values are encoded using the
     808      * URLEncoder.encode() method before being added to the
     809      * buffer.
     810      */
     811     @SuppressWarnings("deprecation")
     812     private void appendBuffer(StringBuilder buffer, String name, String value) {
     813         if (buffer.length() > 0) {
     814             buffer.append('&');
     815         }
     816         String encodedName = URLEncoder.encode(name);
     817         buffer.append(encodedName);
     818         buffer.append('=');
     885                     Object m = elemAttr.getAttribute(StyleConstants.
     886                                                      ModelAttribute);
     887                     if (m instanceof TextAreaDocument) {
     888                         TextAreaDocument doc = (TextAreaDocument)m;
     889                         doc.reset();
     890                     } else if (m instanceof PlainDocument) {
     891                         try {
     892                             PlainDocument doc =  (PlainDocument)m;
     893                             doc.remove(0, doc.getLength());
     894                             if (HTMLDocument.matchNameAttribute
     895                                              (elemAttr, HTML.Tag.INPUT)) {
     896                                 String value = (String)elemAttr.
     897                                            getAttribute(HTML.Attribute.VALUE);
     898                                 if (value != null) {
     899                                     doc.insertString(0, value, null);
     900                                 }
     901                             }
     902                         } catch (BadLocationException e) {
     903                         }
     904                     } else if (m instanceof OptionListModel) {
     905                         @SuppressWarnings("unchecked")
     906                         OptionListModel<?> model = (OptionListModel) m;
     907                         int size = model.getSize();
     908                         for (int i = 0; i < size; i++) {
     909                             model.removeIndexInterval(i, i);
     910                         }
     911                         BitSet selectionRange = model.getInitialSelection();
     912                         for (int i = 0; i < selectionRange.size(); i++) {
     913                             if (selectionRange.get(i)) {
     914                                 model.addSelectionInterval(i, i);
     915                             }
     916                         }
     917                     } else if (m instanceof OptionComboBoxModel) {
     918                         @SuppressWarnings("unchecked")
     919                         OptionComboBoxModel<?> model = (OptionComboBoxModel) m;
     920                         Option option = model.getInitialSelection();
     921                         if (option != null) {
     922                             model.setSelectedItem(option);
     923                         }
     924                     } else if (m instanceof JToggleButton.ToggleButtonModel) {
     925                         boolean checked = ((String)elemAttr.getAttribute
     926                                            (HTML.Attribute.CHECKED) != null);
     927                         JToggleButton.ToggleButtonModel model =
     928                                         (JToggleButton.ToggleButtonModel)m;
     929                         model.setSelected(checked);
     930                     }
     931                 }
     932             }
     933         }
     934     }
     935
     936
     937     /**
     938      * BrowseFileAction is used for input type == file. When the user
     939      * clicks the button a JFileChooser is brought up allowing the user
     766             return doc.getText(0, doc.getLength());
     767         } catch (BadLocationException e) {
     768             return null;
     769         }
     770     }
     771
     772
     773     /**
     774      * Loads the buffer with the data associated with the Select
     775      * form element.  Basically, only items that are selected
     776      * and have their name attribute set are added to the buffer.
     777      */
     778     private void loadSelectData(AttributeSet attr, StringBuilder buffer) {
     779
     780         String name = (String)attr.getAttribute(HTML.Attribute.NAME);
     781         if (name == null) {
     782             return;
     783         }
     784         Object m = attr.getAttribute(StyleConstants.ModelAttribute);
     785         if (m instanceof OptionListModel) {
     786             OptionListModel model = (OptionListModel) m;

     787
     788             for (int i = 0; i < model.getSize(); i++) {
     789                 if (model.isSelectedIndex(i)) {
     790                     Option option = model.getElementAt(i);
     791                     appendBuffer(buffer, name, option.getValue());
     792                 }
     793             }
     794         } else if (m instanceof ComboBoxModel) {
     795             @SuppressWarnings("unchecked")
     796             ComboBoxModel<Option> model = (ComboBoxModel<Option>)m;
     797             Option option = model.getSelectedItem();
     798             if (option != null) {
     799                 appendBuffer(buffer, name, option.getValue());
     800             }
     801         }
     802     }
     803
     804     /**
     805      * Appends name / value pairs into the
     806      * buffer.  Both names and values are encoded using the
     807      * URLEncoder.encode() method before being added to the
     808      * buffer.
     809      */
     810     @SuppressWarnings("deprecation")
     811     private void appendBuffer(StringBuilder buffer, String name, String value) {
     812         if (buffer.length() > 0) {
     813             buffer.append('&');
     814         }
     815         String encodedName = URLEncoder.encode(name);
     816         buffer.append(encodedName);
     817         buffer.append('=');
     884                     Object m = elemAttr.getAttribute(StyleConstants.
     885                                                      ModelAttribute);
     886                     if (m instanceof TextAreaDocument) {
     887                         TextAreaDocument doc = (TextAreaDocument)m;
     888                         doc.reset();
     889                     } else if (m instanceof PlainDocument) {
     890                         try {
     891                             PlainDocument doc =  (PlainDocument)m;
     892                             doc.remove(0, doc.getLength());
     893                             if (HTMLDocument.matchNameAttribute
     894                                              (elemAttr, HTML.Tag.INPUT)) {
     895                                 String value = (String)elemAttr.
     896                                            getAttribute(HTML.Attribute.VALUE);
     897                                 if (value != null) {
     898                                     doc.insertString(0, value, null);
     899                                 }
     900                             }
     901                         } catch (BadLocationException e) {
     902                         }
     903                     } else if (m instanceof OptionListModel) {
     904                         OptionListModel model = (OptionListModel) m;

     905                         int size = model.getSize();
     906                         for (int i = 0; i < size; i++) {
     907                             model.removeIndexInterval(i, i);
     908                         }
     909                         BitSet selectionRange = model.getInitialSelection();
     910                         for (int i = 0; i < selectionRange.size(); i++) {
     911                             if (selectionRange.get(i)) {
     912                                 model.addSelectionInterval(i, i);
     913                             }
     914                         }
     915                     } else if (m instanceof OptionComboBoxModel) {
     916                         OptionComboBoxModel model = (OptionComboBoxModel) m;

     917                         Option option = model.getInitialSelection();
     918                         if (option != null) {
     919                             model.setSelectedItem(option);
     920                         }
     921                     } else if (m instanceof JToggleButton.ToggleButtonModel) {
     922                         boolean checked = ((String)elemAttr.getAttribute
     923                                            (HTML.Attribute.CHECKED) != null);
     924                         JToggleButton.ToggleButtonModel model =
     925                                         (JToggleButton.ToggleButtonModel)m;
     926                         model.setSelected(checked);
     927                     }
     928                 }
     929             }
     930         }
     931     }
     932
     933
     934     /**
     935      * BrowseFileAction is used for input type == file. When the user
     936      * clicks the button a JFileChooser is brought up allowing the user

< prev index next >