|
1
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
package org.ejtools.graph.dialog;
|
|
8
|
|
|
|
9
|
|
import java.awt.Component;
|
|
10
|
|
import java.awt.GridBagConstraints;
|
|
11
|
|
import java.awt.GridBagLayout;
|
|
12
|
|
import java.awt.GridLayout;
|
|
13
|
|
import java.awt.Insets;
|
|
14
|
|
import java.awt.event.ActionEvent;
|
|
15
|
|
import java.awt.event.ActionListener;
|
|
16
|
|
import java.util.ResourceBundle;
|
|
17
|
|
|
|
18
|
|
import javax.swing.JButton;
|
|
19
|
|
import javax.swing.JComboBox;
|
|
20
|
|
import javax.swing.JDialog;
|
|
21
|
|
import javax.swing.JLabel;
|
|
22
|
|
import javax.swing.JPanel;
|
|
23
|
|
|
|
24
|
|
|
|
25
|
|
|
|
26
|
|
|
|
27
|
|
|
|
28
|
|
public class SelectGraphDialog extends JDialog
|
|
29
|
|
{
|
|
30
|
|
|
|
31
|
|
protected JComboBox choices;
|
|
32
|
|
|
|
33
|
|
protected Object initialSelectionValue;
|
|
34
|
|
|
|
35
|
|
protected Object selectedValue = null;
|
|
36
|
|
|
|
37
|
|
private static ResourceBundle resources = ResourceBundle.getBundle("org.ejtools.graph.GraphService");
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
|
43
|
|
|
|
44
|
|
|
|
45
|
|
|
|
46
|
|
|
|
47
|
0
|
public SelectGraphDialog(Component parentComponent, Object[] selectionValues, Object initialSelectionValue)
|
|
48
|
|
{
|
|
49
|
0
|
super();
|
|
50
|
0
|
this.setModal(true);
|
|
51
|
0
|
this.setTitle(resources.getString("graph.dialog.title"));
|
|
52
|
|
|
|
53
|
0
|
JPanel main = new JPanel(new GridBagLayout());
|
|
54
|
0
|
GridBagConstraints constraints = new GridBagConstraints();
|
|
55
|
0
|
constraints.insets = new Insets(5, 5, 5, 5);
|
|
56
|
|
|
|
57
|
0
|
constraints.gridwidth = GridBagConstraints.REMAINDER;
|
|
58
|
0
|
constraints.weightx = 1.0;
|
|
59
|
0
|
constraints.fill = GridBagConstraints.HORIZONTAL;
|
|
60
|
0
|
constraints.anchor = GridBagConstraints.WEST;
|
|
61
|
0
|
JLabel messageLabel = new JLabel(resources.getString("graph.dialog.text.description"));
|
|
62
|
0
|
main.add(messageLabel, constraints);
|
|
63
|
|
|
|
64
|
0
|
this.initialSelectionValue = initialSelectionValue;
|
|
65
|
|
|
|
66
|
0
|
this.choices = new JComboBox(selectionValues);
|
|
67
|
0
|
this.choices.setSelectedItem(this.initialSelectionValue);
|
|
68
|
0
|
this.choices.setEditable(true);
|
|
69
|
0
|
if (selectionValues.length == 0)
|
|
70
|
|
{
|
|
71
|
0
|
choices.getEditor().setItem(this.initialSelectionValue);
|
|
72
|
|
}
|
|
73
|
|
|
|
74
|
0
|
main.add(choices, constraints);
|
|
75
|
|
|
|
76
|
0
|
JPanel buttons = new JPanel(new GridLayout(1, 2, 2, 2));
|
|
77
|
|
|
|
78
|
0
|
JButton buttonSelect = new JButton(resources.getString("graph.dialog.button.select"));
|
|
79
|
0
|
buttons.add(buttonSelect);
|
|
80
|
0
|
buttonSelect.addActionListener(
|
|
81
|
|
new ActionListener()
|
|
82
|
|
{
|
|
83
|
|
|
|
84
|
|
|
|
85
|
|
|
|
86
|
0
|
public void actionPerformed(ActionEvent e)
|
|
87
|
|
{
|
|
88
|
0
|
select();
|
|
89
|
0
|
dispose();
|
|
90
|
|
}
|
|
91
|
|
});
|
|
92
|
|
|
|
93
|
0
|
JButton buttonCancel = new JButton(resources.getString("graph.dialog.button.cancel"));
|
|
94
|
0
|
buttons.add(buttonCancel);
|
|
95
|
0
|
buttonCancel.addActionListener(
|
|
96
|
|
new ActionListener()
|
|
97
|
|
{
|
|
98
|
|
|
|
99
|
|
|
|
100
|
|
|
|
101
|
0
|
public void actionPerformed(ActionEvent e)
|
|
102
|
|
{
|
|
103
|
0
|
selectedValue = null;
|
|
104
|
0
|
dispose();
|
|
105
|
|
}
|
|
106
|
|
});
|
|
107
|
|
|
|
108
|
0
|
constraints.fill = GridBagConstraints.NONE;
|
|
109
|
0
|
constraints.anchor = GridBagConstraints.SOUTH;
|
|
110
|
0
|
main.add(buttons, constraints);
|
|
111
|
|
|
|
112
|
0
|
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
|
113
|
0
|
this.getContentPane().add(main);
|
|
114
|
0
|
this.pack();
|
|
115
|
0
|
this.setLocationRelativeTo(parentComponent);
|
|
116
|
|
}
|
|
117
|
|
|
|
118
|
|
|
|
119
|
|
|
|
120
|
|
|
|
121
|
|
|
|
122
|
|
|
|
123
|
|
|
|
124
|
0
|
public Object getSelectedValue()
|
|
125
|
|
{
|
|
126
|
0
|
return selectedValue;
|
|
127
|
|
}
|
|
128
|
|
|
|
129
|
|
|
|
130
|
|
|
|
131
|
0
|
private void select()
|
|
132
|
|
{
|
|
133
|
0
|
boolean found = false;
|
|
134
|
|
|
|
135
|
0
|
Object choice = this.choices.getSelectedItem();
|
|
136
|
0
|
Object text = this.choices.getEditor().getItem();
|
|
137
|
|
|
|
138
|
0
|
for (int i = 0; i < this.choices.getModel().getSize(); i++)
|
|
139
|
|
{
|
|
140
|
0
|
choice = this.choices.getModel().getElementAt(i);
|
|
141
|
0
|
if (choice.toString().equals(text.toString()))
|
|
142
|
|
{
|
|
143
|
0
|
found = true;
|
|
144
|
0
|
break;
|
|
145
|
|
}
|
|
146
|
|
}
|
|
147
|
0
|
if (!found)
|
|
148
|
|
{
|
|
149
|
0
|
choice = text;
|
|
150
|
|
}
|
|
151
|
|
|
|
152
|
0
|
this.selectedValue = choice;
|
|
153
|
|
}
|
|
154
|
|
}
|
|
155
|
|
|