< prev index next >

## src/java.desktop/share/classes/javax/swing/text/html/HTMLDocument.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.

    3591                     /*
    3592                      * if type is not defined the default is
    3593                      * assumed to be text.
    3594                      */
    3595                     if (type == null) {
    3596                         type = "text";
    3597                         attr.addAttribute(HTML.Attribute.TYPE, "text");
    3598                     }
    3599                     setModel(type, attr);
    3600                 } else if (t == HTML.Tag.TEXTAREA) {
    3601                     inTextArea = true;
    3602                     textAreaDocument = new TextAreaDocument();
    3603                     attr.addAttribute(StyleConstants.ModelAttribute,
    3604                                       textAreaDocument);
    3605                 } else if (t == HTML.Tag.SELECT) {
    3606                     int size = HTML.getIntegerAttributeValue(attr,
    3607                                                              HTML.Attribute.SIZE,
    3608                                                              1);
    3609                     boolean multiple = attr.getAttribute(HTML.Attribute.MULTIPLE) != null;
    3610                     if ((size > 1) || multiple) {
    3611                         OptionListModel<Option> m = new OptionListModel<Option>();
    3612                         if (multiple) {
    3613                             m.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    3614                         }
    3615                         selectModel = m;
    3616                     } else {
    3617                         selectModel = new OptionComboBoxModel<Option>();
    3618                     }
    3619                     attr.addAttribute(StyleConstants.ModelAttribute,
    3620                                       selectModel);
    3621
    3622                 }
    3623
    3624                 // build the element, unless this is an option.
    3625                 if (t == HTML.Tag.OPTION) {
    3626                     option = new Option(attr);
    3627
    3628                     if (selectModel instanceof OptionListModel) {
    3629                         @SuppressWarnings("unchecked")
    3630                         OptionListModel<Option> m = (OptionListModel<Option>) selectModel;
    3631                         m.addElement(option);
    3632                         if (option.isSelected()) {
    3633                             m.addSelectionInterval(optionCount, optionCount);
    3634                             m.setInitialSelection(optionCount);
    3635                         }
    3636                     } else if (selectModel instanceof OptionComboBoxModel) {
    3637                         @SuppressWarnings("unchecked")
    3638                         OptionComboBoxModel<Option> m = (OptionComboBoxModel<Option>) selectModel;
    3639                         m.addElement(option);
    3640                         if (option.isSelected()) {
    3641                             m.setSelectedItem(option);
    3642                             m.setInitialSelection(option);
    3643                         }
    3644                     }
    3645                     optionCount++;
    3646                 } else {
    3647                     super.start(t, attr);
    3648                 }
    3649             }
    3650
    3651             public void end(HTML.Tag t) {
    3652                 if (t == HTML.Tag.OPTION) {
    3653                     option = null;
    3654                 } else {
    3655                     if (t == HTML.Tag.SELECT) {
    3656                         selectModel = null;
    3657                         optionCount = 0;
    3658                     } else if (t == HTML.Tag.TEXTAREA) {
    3591                     /*
    3592                      * if type is not defined the default is
    3593                      * assumed to be text.
    3594                      */
    3595                     if (type == null) {
    3596                         type = "text";
    3597                         attr.addAttribute(HTML.Attribute.TYPE, "text");
    3598                     }
    3599                     setModel(type, attr);
    3600                 } else if (t == HTML.Tag.TEXTAREA) {
    3601                     inTextArea = true;
    3602                     textAreaDocument = new TextAreaDocument();
    3603                     attr.addAttribute(StyleConstants.ModelAttribute,
    3604                                       textAreaDocument);
    3605                 } else if (t == HTML.Tag.SELECT) {
    3606                     int size = HTML.getIntegerAttributeValue(attr,
    3607                                                              HTML.Attribute.SIZE,
    3608                                                              1);
    3609                     boolean multiple = attr.getAttribute(HTML.Attribute.MULTIPLE) != null;
    3610                     if ((size > 1) || multiple) {
    3611                         OptionListModel m = new OptionListModel();
    3612                         if (multiple) {
    3613                             m.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    3614                         }
    3615                         selectModel = m;
    3616                     } else {
    3617                         selectModel = new OptionComboBoxModel();
    3618                     }
    3619                     attr.addAttribute(StyleConstants.ModelAttribute,
    3620                                       selectModel);
    3621
    3622                 }
    3623
    3624                 // build the element, unless this is an option.
    3625                 if (t == HTML.Tag.OPTION) {
    3626                     option = new Option(attr);
    3627
    3628                     if (selectModel instanceof OptionListModel) {
    3629                         OptionListModel m = (OptionListModel) selectModel;

    3630                         m.addElement(option);
    3631                         if (option.isSelected()) {
    3632                             m.addSelectionInterval(optionCount, optionCount);
    3633                             m.setInitialSelection(optionCount);
    3634                         }
    3635                     } else if (selectModel instanceof OptionComboBoxModel) {
    3636                         OptionComboBoxModel m = (OptionComboBoxModel) selectModel;

    3637                         m.addElement(option);
    3638                         if (option.isSelected()) {
    3639                             m.setSelectedItem(option);
    3640                             m.setInitialSelection(option);
    3641                         }
    3642                     }
    3643                     optionCount++;
    3644                 } else {
    3645                     super.start(t, attr);
    3646                 }
    3647             }
    3648
    3649             public void end(HTML.Tag t) {
    3650                 if (t == HTML.Tag.OPTION) {
    3651                     option = null;
    3652                 } else {
    3653                     if (t == HTML.Tag.SELECT) {
    3654                         selectModel = null;
    3655                         optionCount = 0;
    3656                     } else if (t == HTML.Tag.TEXTAREA) {

< prev index next >