|
@@ -1,22 +1,20 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.aokeyhole.swing; |
3 |
3 |
|
|
4 |
|
- |
import java.awt.*; |
5 |
|
- |
import java.util.*; |
6 |
|
- |
import javax.swing.*; |
7 |
|
- |
import javax.swing.event.*; |
8 |
|
- |
|
9 |
4 |
|
import org.litesoft.aokeyhole.objects.*; |
10 |
5 |
|
import org.litesoft.aokeyhole.objects.attributes.*; |
11 |
6 |
|
import org.litesoft.aokeyhole.swing.simplecomponents.*; |
12 |
7 |
|
|
13 |
|
- |
public class AttributeTypeSelectorJPanel extends JPanelPlus implements ChangeListener |
14 |
|
- |
{ |
|
8 |
+ |
import javax.swing.*; |
|
9 |
+ |
import javax.swing.event.*; |
|
10 |
+ |
import java.awt.*; |
|
11 |
+ |
import java.util.*; |
|
12 |
+ |
|
|
13 |
+ |
public class AttributeTypeSelectorJPanel extends JPanelPlus implements ChangeListener { |
15 |
14 |
|
private TopBottom mDerived, mRegular, mVirtual; |
16 |
15 |
|
private CardedJPanel mCards = new CardedJPanel(); |
17 |
16 |
|
|
18 |
|
- |
public AttributeTypeSelectorJPanel( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) |
19 |
|
- |
{ |
|
17 |
+ |
public AttributeTypeSelectorJPanel( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) { |
20 |
18 |
|
super( new BorderLayout() ); |
21 |
19 |
|
|
22 |
20 |
|
boolean zDerivedOK = pObjectSet.acceptableAttributeType( A_Derived.TYPE ); |
|
@@ -34,8 +32,7 @@ |
34 |
32 |
|
mVirtual = addCard( new TopBottom( this, "Virtual", zSelectVirtual, zVirtualOptions ) ); |
35 |
33 |
|
|
36 |
34 |
|
JComponent zTopOptions = createTopOptions( mDerived, mVirtual, mRegular ); // Order for GUI |
37 |
|
- |
if ( zTopOptions != null ) |
38 |
|
- |
{ |
|
35 |
+ |
if ( zTopOptions != null ) { |
39 |
36 |
|
add( zTopOptions, BorderLayout.NORTH ); |
40 |
37 |
|
} |
41 |
38 |
|
add( mCards, BorderLayout.CENTER ); |
|
@@ -43,174 +40,139 @@ |
43 |
40 |
|
showAppropriateCard(); |
44 |
41 |
|
} |
45 |
42 |
|
|
46 |
|
- |
private JComponent createTopOptions( TopBottom... pTBs ) |
47 |
|
- |
{ |
|
43 |
+ |
private JComponent createTopOptions( TopBottom... pTBs ) { |
48 |
44 |
|
ArrayList<JRadioButton> zOptions = new ArrayList<JRadioButton>(); |
49 |
45 |
|
ButtonGroup group = new ButtonGroup(); |
50 |
|
- |
for ( TopBottom zTB : pTBs ) |
51 |
|
- |
{ |
52 |
|
- |
if ( !zTB.getOptions().isEmpty() ) |
53 |
|
- |
{ |
|
46 |
+ |
for ( TopBottom zTB : pTBs ) { |
|
47 |
+ |
if ( !zTB.getOptions().isEmpty() ) { |
54 |
48 |
|
JRadioButton zButton = zTB.getTop(); |
55 |
49 |
|
group.add( zButton ); |
56 |
50 |
|
zOptions.add( zButton ); |
57 |
51 |
|
} |
58 |
52 |
|
} |
59 |
|
- |
if ( zOptions.size() < 2 ) |
60 |
|
- |
{ |
|
53 |
+ |
if ( zOptions.size() < 2 ) { |
61 |
54 |
|
return null; |
62 |
55 |
|
} |
63 |
56 |
|
JPanel rv = new JPanel( new GridLayout( 2, zOptions.size() ) ); |
64 |
57 |
|
// Populate Left (Spacers) |
65 |
58 |
|
//noinspection ForLoopReplaceableByForEach |
66 |
|
- |
for ( int i = 0; i < zOptions.size(); i++ ) |
67 |
|
- |
{ |
|
59 |
+ |
for ( int i = 0; i < zOptions.size(); i++ ) { |
68 |
60 |
|
rv.add( new JLabel( " " ) ); |
69 |
61 |
|
} |
70 |
62 |
|
// Populate Right (Options) |
71 |
|
- |
for ( JRadioButton zOption : zOptions ) |
72 |
|
- |
{ |
|
63 |
+ |
for ( JRadioButton zOption : zOptions ) { |
73 |
64 |
|
rv.add( zOption ); |
74 |
65 |
|
} |
75 |
66 |
|
return rv; |
76 |
67 |
|
} |
77 |
68 |
|
|
78 |
69 |
|
@Override |
79 |
|
- |
public void stateChanged( ChangeEvent e ) |
80 |
|
- |
{ |
|
70 |
+ |
public void stateChanged( ChangeEvent e ) { |
81 |
71 |
|
showAppropriateCard(); |
82 |
72 |
|
} |
83 |
73 |
|
|
84 |
|
- |
private boolean showAppropriateCard() |
85 |
|
- |
{ |
|
74 |
+ |
private boolean showAppropriateCard() { |
86 |
75 |
|
// Left To Right |
87 |
76 |
|
return showCard( mDerived ) || showCard( mVirtual ) || showCard( mRegular ); |
88 |
77 |
|
} |
89 |
78 |
|
|
90 |
|
- |
private boolean showCard( TopBottom pTB ) |
91 |
|
- |
{ |
92 |
|
- |
if ( pTB.getTop().isSelected() ) |
93 |
|
- |
{ |
|
79 |
+ |
private boolean showCard( TopBottom pTB ) { |
|
80 |
+ |
if ( pTB.getTop().isSelected() ) { |
94 |
81 |
|
mCards.showOption( pTB.getTop().getText() ); |
95 |
82 |
|
return true; |
96 |
83 |
|
} |
97 |
84 |
|
return false; |
98 |
85 |
|
} |
99 |
86 |
|
|
100 |
|
- |
private TopBottom addCard( TopBottom pTB ) |
101 |
|
- |
{ |
|
87 |
+ |
private TopBottom addCard( TopBottom pTB ) { |
102 |
88 |
|
mCards.addOption( centered( pTB ), pTB.getTop().getText() ); |
103 |
89 |
|
return pTB; |
104 |
90 |
|
} |
105 |
91 |
|
|
106 |
|
- |
private Options createDerivedOptions( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) |
107 |
|
- |
{ |
|
92 |
+ |
private Options createDerivedOptions( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) { |
108 |
93 |
|
Options zOptions = new Options(); |
109 |
|
- |
for ( AttributeSet zSet : pAttributeSets ) |
110 |
|
- |
{ |
111 |
|
- |
if ( A_Derived.TYPE.equals( zSet.getType() ) ) |
112 |
|
- |
{ |
|
94 |
+ |
for ( AttributeSet zSet : pAttributeSets ) { |
|
95 |
+ |
if ( A_Derived.TYPE.equals( zSet.getType() ) ) { |
113 |
96 |
|
zOptions.add( pObjectSet, zSet ); |
114 |
97 |
|
} |
115 |
98 |
|
} |
116 |
99 |
|
return zOptions; |
117 |
100 |
|
} |
118 |
101 |
|
|
119 |
|
- |
private Options createVirtualOptions( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) |
120 |
|
- |
{ |
|
102 |
+ |
private Options createVirtualOptions( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) { |
121 |
103 |
|
Options zOptions = new Options(); |
122 |
|
- |
for ( AttributeSet zSet : pAttributeSets ) |
123 |
|
- |
{ |
124 |
|
- |
if ( !A_Derived.TYPE.equals( zSet.getType() ) && (zSet.getVirtual() != null) ) |
125 |
|
- |
{ |
|
104 |
+ |
for ( AttributeSet zSet : pAttributeSets ) { |
|
105 |
+ |
if ( !A_Derived.TYPE.equals( zSet.getType() ) && (zSet.getVirtual() != null) ) { |
126 |
106 |
|
zOptions.add( pObjectSet, zSet ); |
127 |
107 |
|
} |
128 |
108 |
|
} |
129 |
109 |
|
return zOptions; |
130 |
110 |
|
} |
131 |
111 |
|
|
132 |
|
- |
private Options createRegularOptions( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) |
133 |
|
- |
{ |
|
112 |
+ |
private Options createRegularOptions( ObjectSet pObjectSet, AttributeSet[] pAttributeSets ) { |
134 |
113 |
|
Options zOptions = new Options(); |
135 |
|
- |
for ( AttributeSet zSet : pAttributeSets ) |
136 |
|
- |
{ |
137 |
|
- |
if ( !A_Derived.TYPE.equals( zSet.getType() ) && (zSet.getPersisted() != null) ) |
138 |
|
- |
{ |
|
114 |
+ |
for ( AttributeSet zSet : pAttributeSets ) { |
|
115 |
+ |
if ( !A_Derived.TYPE.equals( zSet.getType() ) && (zSet.getPersisted() != null) ) { |
139 |
116 |
|
zOptions.add( pObjectSet, zSet ); |
140 |
117 |
|
} |
141 |
118 |
|
} |
142 |
119 |
|
return zOptions; |
143 |
120 |
|
} |
144 |
121 |
|
|
145 |
|
- |
public boolean isVirtual() |
146 |
|
- |
{ |
|
122 |
+ |
public boolean isVirtual() { |
147 |
123 |
|
return mVirtual.isSelected(); |
148 |
124 |
|
} |
149 |
125 |
|
|
150 |
|
- |
public AttributeSet determineSelectedAttributeSet() |
151 |
|
- |
{ |
152 |
|
- |
if ( mDerived.isSelected() ) |
153 |
|
- |
{ |
|
126 |
+ |
public AttributeSet determineSelectedAttributeSet() { |
|
127 |
+ |
if ( mDerived.isSelected() ) { |
154 |
128 |
|
return determineSelectedAttributeSet( mDerived ); |
155 |
129 |
|
} |
156 |
|
- |
if ( mRegular.isSelected() ) |
157 |
|
- |
{ |
|
130 |
+ |
if ( mRegular.isSelected() ) { |
158 |
131 |
|
return determineSelectedAttributeSet( mRegular ); |
159 |
132 |
|
} |
160 |
133 |
|
return determineSelectedAttributeSet( mVirtual ); |
161 |
134 |
|
} |
162 |
135 |
|
|
163 |
|
- |
private AttributeSet determineSelectedAttributeSet( TopBottom pTB ) |
164 |
|
- |
{ |
|
136 |
+ |
private AttributeSet determineSelectedAttributeSet( TopBottom pTB ) { |
165 |
137 |
|
Options zOptions = pTB.getOptions(); |
166 |
|
- |
for ( int i = zOptions.size(); --i > 0; ) |
167 |
|
- |
{ |
|
138 |
+ |
for ( int i = zOptions.size(); --i > 0; ) { |
168 |
139 |
|
OurRadioButton zButton = zOptions.get( i ); |
169 |
|
- |
if ( zButton.isSelected() ) |
170 |
|
- |
{ |
|
140 |
+ |
if ( zButton.isSelected() ) { |
171 |
141 |
|
return zButton.getAttributeSet(); |
172 |
142 |
|
} |
173 |
143 |
|
} |
174 |
144 |
|
return zOptions.get( 0 ).getAttributeSet(); |
175 |
145 |
|
} |
176 |
146 |
|
|
177 |
|
- |
private static class OurRadioButton extends JRadioButton |
178 |
|
- |
{ |
|
147 |
+ |
private static class OurRadioButton extends JRadioButton { |
179 |
148 |
|
private AttributeSet mAttributeSet; |
180 |
149 |
|
|
181 |
|
- |
public OurRadioButton( AttributeSet pAttributeSet, boolean selected ) |
182 |
|
- |
{ |
|
150 |
+ |
public OurRadioButton( AttributeSet pAttributeSet, boolean selected ) { |
183 |
151 |
|
super( pAttributeSet.getType().toString(), selected ); |
184 |
152 |
|
mAttributeSet = pAttributeSet; |
185 |
153 |
|
} |
186 |
154 |
|
|
187 |
|
- |
public AttributeSet getAttributeSet() |
188 |
|
- |
{ |
|
155 |
+ |
public AttributeSet getAttributeSet() { |
189 |
156 |
|
return mAttributeSet; |
190 |
157 |
|
} |
191 |
158 |
|
} |
192 |
159 |
|
|
193 |
|
- |
private static class Options extends ArrayList<OurRadioButton> |
194 |
|
- |
{ |
|
160 |
+ |
private static class Options extends ArrayList<OurRadioButton> { |
195 |
161 |
|
private boolean mSelected = true; |
196 |
162 |
|
|
197 |
|
- |
public void add( ObjectSet pObjectSet, AttributeSet pAttributeSet ) |
198 |
|
- |
{ |
199 |
|
- |
if ( (pAttributeSet instanceof UiCRUDpSet) && pObjectSet.acceptableAttributeType( pAttributeSet.getType() ) ) |
200 |
|
- |
{ |
|
163 |
+ |
public void add( ObjectSet pObjectSet, AttributeSet pAttributeSet ) { |
|
164 |
+ |
if ( (pAttributeSet instanceof UiCRUDpSet) && pObjectSet.acceptableAttributeType( pAttributeSet.getType() ) ) { |
201 |
165 |
|
super.add( new OurRadioButton( pAttributeSet, mSelected ) ); |
202 |
166 |
|
mSelected = false; |
203 |
167 |
|
} |
204 |
168 |
|
} |
205 |
169 |
|
} |
206 |
170 |
|
|
207 |
|
- |
private static class TopBottom extends JPanel |
208 |
|
- |
{ |
|
171 |
+ |
private static class TopBottom extends JPanel { |
209 |
172 |
|
private JRadioButton mTop; |
210 |
173 |
|
private Options mOptions = new Options(); |
211 |
174 |
|
|
212 |
|
- |
private TopBottom( ChangeListener pChangeListener, String pTopText, boolean pTopSelected, Options pOptions ) |
213 |
|
- |
{ |
|
175 |
+ |
private TopBottom( ChangeListener pChangeListener, String pTopText, boolean pTopSelected, Options pOptions ) { |
214 |
176 |
|
super( new BorderLayout() ); |
215 |
177 |
|
(mTop = new JRadioButton( pTopText, pTopSelected )).addChangeListener( pChangeListener ); |
216 |
178 |
|
mOptions = pOptions; |
|
@@ -218,34 +180,28 @@ |
218 |
180 |
|
add( centered( createGUI( pOptions ) ), BorderLayout.CENTER ); |
219 |
181 |
|
} |
220 |
182 |
|
|
221 |
|
- |
public JRadioButton getTop() |
222 |
|
- |
{ |
|
183 |
+ |
public JRadioButton getTop() { |
223 |
184 |
|
return mTop; |
224 |
185 |
|
} |
225 |
186 |
|
|
226 |
|
- |
public Options getOptions() |
227 |
|
- |
{ |
|
187 |
+ |
public Options getOptions() { |
228 |
188 |
|
return mOptions; |
229 |
189 |
|
} |
230 |
190 |
|
|
231 |
|
- |
private static JComponent createGUI( Options pOptions ) |
232 |
|
- |
{ |
233 |
|
- |
if ( pOptions.size() < 2 ) |
234 |
|
- |
{ |
|
191 |
+ |
private static JComponent createGUI( Options pOptions ) { |
|
192 |
+ |
if ( pOptions.size() < 2 ) { |
235 |
193 |
|
return new JLabel( " " ); |
236 |
194 |
|
} |
237 |
195 |
|
ButtonGroup group = new ButtonGroup(); |
238 |
196 |
|
JPanel rv = new JPanel( new GridLayout( pOptions.size(), 1 ) ); |
239 |
|
- |
for ( OurRadioButton zButton : pOptions ) |
240 |
|
- |
{ |
|
197 |
+ |
for ( OurRadioButton zButton : pOptions ) { |
241 |
198 |
|
rv.add( zButton ); |
242 |
199 |
|
group.add( zButton ); |
243 |
200 |
|
} |
244 |
201 |
|
return rv; |
245 |
202 |
|
} |
246 |
203 |
|
|
247 |
|
- |
public boolean isSelected() |
248 |
|
- |
{ |
|
204 |
+ |
public boolean isSelected() { |
249 |
205 |
|
return mTop.isSelected(); |
250 |
206 |
|
} |
251 |
207 |
|
} |