|
@@ -1,83 +1,83 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.aokeyhole.swing; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.aokeyhole.objects.*; |
5 |
|
- |
import org.litesoft.aokeyhole.swing.simplecomponents.*; |
6 |
|
- |
import org.litesoft.aokeyhole.toolkit.*; |
7 |
|
- |
import org.litesoft.aokeyhole.toolkit.editorviewer.*; |
8 |
|
- |
|
9 |
|
- |
import javax.swing.*; |
10 |
|
- |
import java.awt.*; |
11 |
|
- |
import java.util.*; |
12 |
|
- |
import java.util.List; |
13 |
|
- |
|
14 |
|
- |
public class AddNewObjectTypeSelectorJPanel extends JPanelPlus implements ActionsListener { |
15 |
|
- |
private ActionsListener mActionsListener; |
16 |
|
- |
private NewObjectTypeSelectionListener mNewObjectTypeSelectionListener; |
17 |
|
- |
private ArrayList<OurRadioButton> mTypeOptions = new ArrayList<OurRadioButton>(); |
18 |
|
- |
|
19 |
|
- |
public AddNewObjectTypeSelectorJPanel( List<ObjectSet> pObjectSets, ActionsListener pActionsListener, |
20 |
|
- |
NewObjectTypeSelectionListener pNewObjectTypeSelectionListener ) { |
21 |
|
- |
super( new BorderLayout() ); |
22 |
|
- |
|
23 |
|
- |
mActionsListener = pActionsListener; |
24 |
|
- |
mNewObjectTypeSelectionListener = pNewObjectTypeSelectionListener; |
25 |
|
- |
|
26 |
|
- |
boolean zSelected = true; |
27 |
|
- |
for ( ObjectSet zSet : pObjectSets ) { |
28 |
|
- |
mTypeOptions.add( new OurRadioButton( zSet, zSelected ) ); |
29 |
|
- |
zSelected = false; |
30 |
|
- |
} |
31 |
|
- |
|
32 |
|
- |
add( new JLabel( " New Object:" ), BorderLayout.NORTH ); |
33 |
|
- |
add( centered( createOptionPanel() ), BorderLayout.CENTER ); |
34 |
|
- |
add( centered( new ActionsProceedJPanel( this ) ), BorderLayout.SOUTH ); |
35 |
|
- |
} |
36 |
|
- |
|
37 |
|
- |
@Override |
38 |
|
- |
public void actionRequested( String pAction ) { |
39 |
|
- |
if ( ActionsListener.ACTION_CANCEL.equals( pAction ) ) { |
40 |
|
- |
mActionsListener.actionRequested( pAction ); |
41 |
|
- |
return; |
42 |
|
- |
} |
43 |
|
- |
ObjectSet zSet = determineSelectedObjectSet(); |
44 |
|
- |
mNewObjectTypeSelectionListener.newObjectTypeSelected( zSet ); |
45 |
|
- |
} |
46 |
|
- |
|
47 |
|
- |
private ObjectSet determineSelectedObjectSet() { |
48 |
|
- |
for ( int i = mTypeOptions.size(); --i > 0; ) { |
49 |
|
- |
OurRadioButton zButton = mTypeOptions.get( i ); |
50 |
|
- |
if ( zButton.isSelected() ) { |
51 |
|
- |
return zButton.getObjectSet(); |
52 |
|
- |
} |
53 |
|
- |
} |
54 |
|
- |
return mTypeOptions.get( 0 ).getObjectSet(); |
55 |
|
- |
} |
56 |
|
- |
|
57 |
|
- |
private JPanel createOptionPanel() { |
58 |
|
- |
ButtonGroup group = new ButtonGroup(); |
59 |
|
- |
JPanel options = new JPanel( new GridLayout( mTypeOptions.size() + 1, 1 ) ); |
60 |
|
- |
|
61 |
|
- |
options.add( new JLabel( " " ) ); |
62 |
|
- |
|
63 |
|
- |
for ( OurRadioButton zOption : mTypeOptions ) { |
64 |
|
- |
group.add( zOption ); |
65 |
|
- |
options.add( zOption ); |
66 |
|
- |
} |
67 |
|
- |
|
68 |
|
- |
return options; |
69 |
|
- |
} |
70 |
|
- |
|
71 |
|
- |
private class OurRadioButton extends JRadioButton { |
72 |
|
- |
private ObjectSet mObjectSet; |
73 |
|
- |
|
74 |
|
- |
public OurRadioButton( ObjectSet pObjectSet, boolean selected ) { |
75 |
|
- |
super( pObjectSet.getType(), selected ); |
76 |
|
- |
mObjectSet = pObjectSet; |
77 |
|
- |
} |
78 |
|
- |
|
79 |
|
- |
public ObjectSet getObjectSet() { |
80 |
|
- |
return mObjectSet; |
81 |
|
- |
} |
82 |
|
- |
} |
83 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.aokeyhole.swing; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.aokeyhole.objects.*; |
|
5 |
+ |
import org.litesoft.aokeyhole.swing.simplecomponents.*; |
|
6 |
+ |
import org.litesoft.aokeyhole.toolkit.*; |
|
7 |
+ |
import org.litesoft.aokeyhole.toolkit.editorviewer.*; |
|
8 |
+ |
|
|
9 |
+ |
import javax.swing.*; |
|
10 |
+ |
import java.awt.*; |
|
11 |
+ |
import java.util.*; |
|
12 |
+ |
import java.util.List; |
|
13 |
+ |
|
|
14 |
+ |
public class AddNewObjectTypeSelectorJPanel extends JPanelPlus implements ActionsListener { |
|
15 |
+ |
private ActionsListener mActionsListener; |
|
16 |
+ |
private NewObjectTypeSelectionListener mNewObjectTypeSelectionListener; |
|
17 |
+ |
private ArrayList<OurRadioButton> mTypeOptions = new ArrayList<OurRadioButton>(); |
|
18 |
+ |
|
|
19 |
+ |
public AddNewObjectTypeSelectorJPanel( List<ObjectSet> pObjectSets, ActionsListener pActionsListener, |
|
20 |
+ |
NewObjectTypeSelectionListener pNewObjectTypeSelectionListener ) { |
|
21 |
+ |
super( new BorderLayout() ); |
|
22 |
+ |
|
|
23 |
+ |
mActionsListener = pActionsListener; |
|
24 |
+ |
mNewObjectTypeSelectionListener = pNewObjectTypeSelectionListener; |
|
25 |
+ |
|
|
26 |
+ |
boolean zSelected = true; |
|
27 |
+ |
for ( ObjectSet zSet : pObjectSets ) { |
|
28 |
+ |
mTypeOptions.add( new OurRadioButton( zSet, zSelected ) ); |
|
29 |
+ |
zSelected = false; |
|
30 |
+ |
} |
|
31 |
+ |
|
|
32 |
+ |
add( new JLabel( " New Object:" ), BorderLayout.NORTH ); |
|
33 |
+ |
add( centered( createOptionPanel() ), BorderLayout.CENTER ); |
|
34 |
+ |
add( centered( new ActionsProceedJPanel( this ) ), BorderLayout.SOUTH ); |
|
35 |
+ |
} |
|
36 |
+ |
|
|
37 |
+ |
@Override |
|
38 |
+ |
public void actionRequested( String pAction ) { |
|
39 |
+ |
if ( ActionsListener.ACTION_CANCEL.equals( pAction ) ) { |
|
40 |
+ |
mActionsListener.actionRequested( pAction ); |
|
41 |
+ |
return; |
|
42 |
+ |
} |
|
43 |
+ |
ObjectSet zSet = determineSelectedObjectSet(); |
|
44 |
+ |
mNewObjectTypeSelectionListener.newObjectTypeSelected( zSet ); |
|
45 |
+ |
} |
|
46 |
+ |
|
|
47 |
+ |
private ObjectSet determineSelectedObjectSet() { |
|
48 |
+ |
for ( int i = mTypeOptions.size(); --i > 0; ) { |
|
49 |
+ |
OurRadioButton zButton = mTypeOptions.get( i ); |
|
50 |
+ |
if ( zButton.isSelected() ) { |
|
51 |
+ |
return zButton.getObjectSet(); |
|
52 |
+ |
} |
|
53 |
+ |
} |
|
54 |
+ |
return mTypeOptions.get( 0 ).getObjectSet(); |
|
55 |
+ |
} |
|
56 |
+ |
|
|
57 |
+ |
private JPanel createOptionPanel() { |
|
58 |
+ |
ButtonGroup group = new ButtonGroup(); |
|
59 |
+ |
JPanel options = new JPanel( new GridLayout( mTypeOptions.size() + 1, 1 ) ); |
|
60 |
+ |
|
|
61 |
+ |
options.add( new JLabel( " " ) ); |
|
62 |
+ |
|
|
63 |
+ |
for ( OurRadioButton zOption : mTypeOptions ) { |
|
64 |
+ |
group.add( zOption ); |
|
65 |
+ |
options.add( zOption ); |
|
66 |
+ |
} |
|
67 |
+ |
|
|
68 |
+ |
return options; |
|
69 |
+ |
} |
|
70 |
+ |
|
|
71 |
+ |
private class OurRadioButton extends JRadioButton { |
|
72 |
+ |
private ObjectSet mObjectSet; |
|
73 |
+ |
|
|
74 |
+ |
public OurRadioButton( ObjectSet pObjectSet, boolean selected ) { |
|
75 |
+ |
super( pObjectSet.getType(), selected ); |
|
76 |
+ |
mObjectSet = pObjectSet; |
|
77 |
+ |
} |
|
78 |
+ |
|
|
79 |
+ |
public ObjectSet getObjectSet() { |
|
80 |
+ |
return mObjectSet; |
|
81 |
+ |
} |
|
82 |
+ |
} |
|
83 |
+ |
} |