source: release-kits/shared/ant-installer/src/org/tp23/antinstaller/renderer/swing/SelectInputRenderer.java@ 17818

Last change on this file since 17818 was 17818, checked in by oranfry, 15 years ago

made the chinese language prompt work

File size: 4.3 KB
Line 
1/*
2 * Copyright 2005 Paul Hinds
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.tp23.antinstaller.renderer.swing;
17
18import java.awt.BorderLayout;
19import javax.swing.BoxLayout;
20import java.awt.event.ItemEvent;
21import java.awt.event.ItemListener;
22import java.util.Enumeration;
23import java.util.ResourceBundle;
24
25import javax.swing.ButtonGroup;
26import javax.swing.JLabel;
27import javax.swing.JPanel;
28import javax.swing.JRadioButton;
29
30import org.tp23.antinstaller.input.OutputField;
31import org.tp23.antinstaller.input.SelectInput;
32import org.tp23.gui.GBCF;
33
34public class SelectInputRenderer
35 extends SwingOutputFieldRenderer {
36
37 protected SelectInput inputField;
38
39 protected JLabel fieldLabel = new AILabel();
40 protected ButtonGroup optionGroup = new ButtonGroup();
41
42 public SelectInputRenderer() {
43 }
44 public void initComponent(JPanel parent){
45 try {
46 jbInit();
47 }
48 catch(Exception e) {
49 ctx.log(e.getMessage());
50 if(ctx.getInstaller().isVerbose()) {
51 ctx.log(e);
52 }
53 }
54 }
55
56
57
58 public void setOutputField(OutputField inputField) {
59 this.inputField = (SelectInput)inputField;
60 }
61 public void updateInputField(){
62 Enumeration enumumeration = optionGroup.getElements();
63 int i = 0;
64 for(; enumumeration.hasMoreElements(); i++){
65 JRadioButton o = (JRadioButton)enumumeration.nextElement();
66 if(o.isSelected()) {
67 inputField.setValue(inputField.getOptions()[i].value);
68 break;
69 }
70 }
71 if(i > inputField.getOptions().length) {
72 inputField.setValue(inputField.getDefaultValue());
73 }
74 }
75 public void updateDefaultValue() {
76 if(!inputField.isEditted()) {
77 String newDefault = inputField.getDefaultValue();
78 Enumeration enumeration = optionGroup.getElements();
79 for(int i = 0; enumeration.hasMoreElements(); i++){
80 if(newDefault.equals(inputField.getOptions()[i].value)) {
81 JRadioButton jrb = (JRadioButton) enumeration.nextElement();
82 jrb.setSelected(true);
83 // @todo should break?
84 } else {
85 enumeration.nextElement();
86 }
87 }
88 }
89 }
90
91 private void jbInit() throws Exception {
92 fieldLabel.setText( "<html>" + inputField.getDisplayText() + "</html>" );
93 SelectInput.Option[] options = inputField.getOptions();
94
95 for (int i = 0; i < options.length; i++) {
96 JRadioButton jrb = new AIRadioButton( "<html><font size=+0>" + options[i].getText() + "</font></html>" );
97 optionGroup.add(jrb);
98 if(options[i].value.equals(inputField.getDefaultValue())){
99 jrb.setSelected(true);
100 }
101 jrb.addItemListener(new ItemListener(){
102 public void itemStateChanged(ItemEvent e) {
103 inputField.setEditted(true);
104 }
105 });
106 }
107 }
108 public int addSelf(JPanel content,GBCF cf, int row,boolean overflow) {
109
110 JPanel superContainer = new JPanel(new BorderLayout());
111
112 JPanel container = new JPanel();
113 container.setLayout(new BoxLayout(container, BoxLayout.Y_AXIS));
114
115 if ( !fieldLabel.getText().equals("") ) {
116 container.add(fieldLabel);
117 }
118
119 Enumeration enumeration = optionGroup.getElements();
120 // there should be at least two
121 enumeration.hasMoreElements();
122 AIRadioButton jrb = (AIRadioButton)enumeration.nextElement();
123 container.add(jrb);
124 if( overflow ) {
125 jrb.setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
126 }
127 JPanel empty = new JPanel();
128 while(enumeration.hasMoreElements()){
129 jrb = (AIRadioButton)enumeration.nextElement();
130 //content.add(empty,cf.getCell(row, 0));
131 container.add(jrb);
132 if(overflow) {
133 jrb.setOverflow(SizeConstants.OVERFLOW_FIELD_SIZE);
134 }
135 }
136 container.add(empty);
137 superContainer.add(BorderLayout.WEST,container);
138 content.add(superContainer);
139
140 return row;
141 }
142
143 /**
144 * renderError
145 */
146 public void renderError() {
147 ctx.getMessageRenderer().printMessage(org.tp23.antinstaller.Installer.langPack.getString("notValidSelection"));
148 // fixed BUG:1295944 ctx.getMessageRenderer().printMessage("Not a valid selection");
149 //optionGroup.requestFocus();
150 }
151}
Note: See TracBrowser for help on using the repository browser.