View Javadoc

1   package org.xmlhammer.gui.wizard;
2   
3   import java.awt.event.ItemEvent;
4   import java.awt.event.ItemListener;
5   import java.util.List;
6   
7   import javax.swing.ButtonGroup;
8   import javax.swing.JRadioButton;
9   import javax.swing.SwingUtilities;
10  import javax.swing.border.EmptyBorder;
11  
12  import org.bounce.FormLayout;
13  import org.bounce.wizard.WizardPage;
14  import org.xmlhammer.gui.util.wizard.HelpEnabledWizardPage;
15  import org.xmlhammer.model.tools.xslt.OutputProperties;
16  import org.xmlhammer.model.tools.xslt.OutputProperty;
17  
18  public class OutputPropertiesSelectionPage extends HelpEnabledWizardPage {
19  
20      private static final long serialVersionUID = -1909903213579390495L;
21      
22      private XMLOutputPropertiesPage xmlOutputPropertiesPage = null;
23      private HTMLOutputPropertiesPage htmlOutputPropertiesPage = null;
24      private TextOutputPropertiesPage textOutputPropertiesPage = null;
25      private OtherOutputPropertiesPage otherOutputPropertiesPage = null;
26  
27      private JRadioButton selectDefaultProperties = null;
28      private JRadioButton selectXMLProperties = null;
29      private JRadioButton selectHTMLProperties = null;
30      private JRadioButton selectTextProperties = null;
31      private JRadioButton selectOtherProperties = null;
32  
33      public OutputPropertiesSelectionPage(String helpID, XMLOutputPropertiesPage xmlOutputPropertiesPage, HTMLOutputPropertiesPage htmlOutputPropertiesPage, TextOutputPropertiesPage textOutputPropertiesPage, OtherOutputPropertiesPage otherOutputPropertiesPage) {
34          super(new FormLayout(11, 5), helpID);
35          
36          setBorder(new EmptyBorder(20, 50, 10, 10));
37  
38          this.xmlOutputPropertiesPage = xmlOutputPropertiesPage;
39          this.htmlOutputPropertiesPage = htmlOutputPropertiesPage;
40          this.textOutputPropertiesPage = textOutputPropertiesPage;
41          this.otherOutputPropertiesPage = otherOutputPropertiesPage;
42          
43          selectDefaultProperties = new JRadioButton("Use default output properties");
44          selectXMLProperties = new JRadioButton("Specify XML output properties");
45          selectHTMLProperties = new JRadioButton("Specify HTML output properties");
46          selectTextProperties = new JRadioButton("Specify Text output properties");
47          selectOtherProperties = new JRadioButton("Specify other output properties");
48          
49          ButtonGroup group = new ButtonGroup();
50          group.add(selectDefaultProperties);
51          group.add(selectXMLProperties);
52          group.add(selectHTMLProperties);
53          group.add(selectTextProperties);
54          group.add(selectOtherProperties);
55          
56          selectDefaultProperties.setSelected(true);
57          
58          selectDefaultProperties.addItemListener(new ItemListener() {
59              public void itemStateChanged(ItemEvent event) {
60                  // make sure another radio button has been selected 
61                  // before firing the event.
62                  SwingUtilities.invokeLater(new Runnable() {
63                      public void run() {
64                          firePageChanged();
65                      }
66                  });
67              }
68          });
69          
70          add(selectDefaultProperties, FormLayout.FULL);
71          add(selectXMLProperties, FormLayout.FULL);
72          add(selectHTMLProperties, FormLayout.FULL);
73          add(selectTextProperties, FormLayout.FULL);
74          add(selectOtherProperties, FormLayout.FULL);
75      }
76      
77      public boolean isDefaultPropertiesSelected() {
78          return selectDefaultProperties.isSelected();
79      }
80      
81      // @unittest
82      public void selectDefaultProperties() {
83          selectDefaultProperties.setSelected(true);
84      }
85      
86      // @unittest
87      public void selectXMLProperties() {
88          selectXMLProperties.setSelected(true);
89      }
90  
91      // @unittest
92      public boolean isXMLPropertiesSelected() {
93          return selectXMLProperties.isSelected();
94      }
95  
96      // @unittest
97      public void selectHTMLProperties() {
98          selectHTMLProperties.setSelected(true);
99      }
100 
101     // @unittest
102     public boolean isHTMLPropertiesSelected() {
103         return selectHTMLProperties.isSelected();
104     }
105 
106     // @unittest
107     public void selectTextProperties() {
108         selectTextProperties.setSelected(true);
109     }
110 
111     // @unittest
112     public boolean isTextPropertiesSelected() {
113         return selectTextProperties.isSelected();
114     }
115 
116     // @unittest
117     public void selectOtherProperties() {
118         selectOtherProperties.setSelected(true);
119     }
120 
121     // @unittest
122     public boolean isOtherPropertiesSelected() {
123         return selectOtherProperties.isSelected();
124     }
125 
126     @Override
127     public String getTitle() {
128         return "Select Output Method";
129     }
130 
131     @Override
132     public String getDescription() {
133         return "Define the output method to use";
134     }
135     
136     public OutputProperties getOutputProperties() {
137         OutputProperties outputProperties = new OutputProperties();
138         
139         List<OutputProperty> properties = null;
140 
141         if (isXMLPropertiesSelected()) {
142             properties = xmlOutputPropertiesPage.getProperties();
143             
144             OutputProperty property = new OutputProperty();
145             property.setName("method");
146             property.setValue("xml");
147             properties.add(property);
148         } else if (isHTMLPropertiesSelected()) {
149             properties = htmlOutputPropertiesPage.getProperties();
150 
151             OutputProperty property = new OutputProperty();
152             property.setName("method");
153             property.setValue("html");
154             properties.add(property);
155         } else if (isTextPropertiesSelected()) {
156             properties = textOutputPropertiesPage.getProperties();
157 
158             OutputProperty property = new OutputProperty();
159             property.setName("method");
160             property.setValue("text");
161             properties.add(property);
162         } else if (isOtherPropertiesSelected()) {
163             properties = otherOutputPropertiesPage.getProperties();
164         }
165 
166         if (properties != null) {
167             for (OutputProperty property : properties) {
168                 outputProperties.getOutputProperty().add(property);
169             }
170         }
171         
172         return outputProperties;
173     }
174 
175     @Override
176     public WizardPage getNext() {
177         if (isXMLPropertiesSelected()) {
178             return xmlOutputPropertiesPage;
179         } else if (isHTMLPropertiesSelected()) {
180             return htmlOutputPropertiesPage;
181         } else if (isTextPropertiesSelected()) {
182             return textOutputPropertiesPage;
183         } else if (isOtherPropertiesSelected()) {
184             return otherOutputPropertiesPage;
185         } else {
186             return null;
187         }
188     }
189 }