KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > ui > MultiOptionWidget


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 package ca.mcgill.sable.soot.ui;
21
22 import org.eclipse.swt.widgets.*;
23 import org.eclipse.swt.*;
24 import org.eclipse.swt.layout.*;
25 import java.util.*;
26
27 public class MultiOptionWidget implements ISootOptionWidget {
28     private String JavaDoc alias;
29     private OptionData [] dataVals;
30     private String JavaDoc [] values;
31     private String JavaDoc [] aliases;
32     private Button [] buttons;
33
34     
35     /**
36      * Constructor for MultiOptionWidget.
37      * @param parent
38      * @param style
39      */

40     public MultiOptionWidget(Composite parent, int style,
41         OptionData [] dataVals, OptionData data) {
42     
43         setAlias(data.getRealAlias());
44         
45         Group multi = new Group(parent, SWT.NONE);
46         GridLayout gl = new GridLayout();
47         gl.numColumns = 2;
48         
49         multi.setLayout(gl);
50         
51         GridData gridData2 = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
52         gridData2.horizontalSpan = 2;
53         multi.setLayoutData(gridData2);
54         
55         GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
56
57
58         GridData gd = new GridData(GridData.CENTER );
59         gd.horizontalSpan = 4;
60         Label label = new Label(multi, SWT.NONE);
61         label.setText(data.getText());
62         label.setLayoutData(gd);
63         label.setToolTipText(data.getTooltip().trim());
64         
65         setButtons(new Button [dataVals.length]);
66         setDataVals(dataVals);
67
68                 
69         for (int i = 0; i < dataVals.length; i++) {
70             buttons[i] = new Button(multi, SWT.RADIO);
71             buttons[i].setText(dataVals[i].getText());
72             buttons[i].setToolTipText(dataVals[i].getTooltip().trim());
73
74             if (dataVals[i].isDefaultVal()) {
75                 buttons[i].setSelection(true);
76             }
77         }
78         
79         
80     }
81     
82     public ArrayList getControls(){
83         ArrayList controls = new ArrayList();
84         for (int i = 0; i < getDataVals().length; i++){
85             controls.add(buttons[i]);
86         }
87         return controls;
88     }
89     
90     public String JavaDoc getId(){
91         return getAlias();
92     }
93         
94     public void setDef(String JavaDoc id) {
95         for (int i = 0; i < buttons.length; i++) {
96             if (dataVals[i].getAlias().equals(id)) {
97                 buttons[i].setSelection(true);
98             }
99             else {
100                 buttons[i].setSelection(false);
101             }
102         }
103     }
104     
105     public String JavaDoc getSelectedAlias() {
106         for (int i = 0; i < buttons.length; i++) {
107             if (buttons[i].getSelection()) {
108                 return dataVals[i].getAlias();
109             }
110         }
111         return "";
112     }
113
114     /**
115      * Returns the alias.
116      * @return String
117      */

118     public String JavaDoc getAlias() {
119         return alias;
120     }
121
122     /**
123      * Sets the alias.
124      * @param alias The alias to set
125      */

126     public void setAlias(String JavaDoc alias) {
127         this.alias = alias;
128     }
129
130     /**
131      * Returns the aliases.
132      * @return String[]
133      */

134     public String JavaDoc[] getAliases() {
135         return aliases;
136     }
137
138     /**
139      * Returns the buttons.
140      * @return Button[]
141      */

142     public Button[] getButtons() {
143         return buttons;
144     }
145
146     /**
147      * Returns the values.
148      * @return String[]
149      */

150     public String JavaDoc[] getValues() {
151         return values;
152     }
153
154     /**
155      * Sets the aliases.
156      * @param aliases The aliases to set
157      */

158     public void setAliases(String JavaDoc[] aliases) {
159         this.aliases = aliases;
160     }
161
162     /**
163      * Sets the buttons.
164      * @param buttons The buttons to set
165      */

166     public void setButtons(Button[] buttons) {
167         this.buttons = buttons;
168     }
169
170     /**
171      * Sets the values.
172      * @param values The values to set
173      */

174     public void setValues(String JavaDoc[] values) {
175         this.values = values;
176     }
177
178     /**
179      * Returns the dataVals.
180      * @return OptionData[]
181      */

182     public OptionData[] getDataVals() {
183         return dataVals;
184     }
185
186     /**
187      * Sets the dataVals.
188      * @param dataVals The dataVals to set
189      */

190     public void setDataVals(OptionData[] dataVals) {
191         this.dataVals = dataVals;
192     }
193
194 }
195
Popular Tags