OptionsDialog.java
5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package morfeusz;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.GroupLayout.*;
import pl.sgjp.morfeusz.*;
@SuppressWarnings("serial")
public class OptionsDialog extends JPanel
{
private JDialog dialog;
private JButton acceptButton;
private JButton cancelButton;
private JButton defaultsButton;
private JComboBox<String> agglCombo;
private JComboBox<String> praetCombo;
private JComboBox<String> caseCombo;
private JComboBox<String> spaceCombo;
private JComboBox<String> tokenCombo;
private Morfeusz controller;
private int ret;
public OptionsDialog(Morfeusz controller)
{
super(new BorderLayout());
this.controller = controller;
arrangeComponents();
initiateValues();
}
public void arrangeComponents()
{
JLabel label1, label2, label3, label4, label5;
JPanel paramPanel = new JPanel();
Box bottomPanel = Box.createHorizontalBox();
GroupLayout gl = new GroupLayout(paramPanel);
GroupLayout.SequentialGroup hGroup = gl.createSequentialGroup();
GroupLayout.SequentialGroup vGroup = gl.createSequentialGroup();
Dimension dim;
acceptButton = new JButton("Akceptuj");
cancelButton = new JButton("Anuluj");
defaultsButton = new JButton("Warto\u015Bci domy\u015Blne");
label1 = new JLabel("aggl: ");
label2 = new JLabel("praet: ");
label3 = new JLabel("case-handling: ");
label4 = new JLabel("whitespace-handling: ");
label5 = new JLabel("token-numbering: ");
agglCombo = new JComboBox<String>();
for (String str : controller.getMorfeusz().getAvailableAgglOptions()) agglCombo.addItem(str);
praetCombo = new JComboBox<String>();
for (String str : controller.getMorfeusz().getAvailablePraetOptions()) praetCombo.addItem(str);
caseCombo = new JComboBox<String>();
for (CaseHandling ch : CaseHandling.values()) caseCombo.addItem(ch.name());
spaceCombo = new JComboBox<String>();
for (WhitespaceHandling wh : WhitespaceHandling.values()) spaceCombo.addItem(wh.name());
tokenCombo = new JComboBox<String>();
for (TokenNumbering tn : TokenNumbering.values()) tokenCombo.addItem(tn.name());
if (!Morfeusz.isMacOS()) {
gl.setAutoCreateGaps(true);
gl.setAutoCreateContainerGaps(true);
}
paramPanel.setLayout(gl);
hGroup.addGroup(gl.createParallelGroup().addComponent(label1).
addComponent(label2).addComponent(label3).
addComponent(label4).addComponent(label5));
hGroup.addGroup(gl.createParallelGroup().addComponent(agglCombo).
addComponent(praetCombo).addComponent(caseCombo).
addComponent(spaceCombo).addComponent(tokenCombo));
gl.setHorizontalGroup(hGroup);
vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE).
addComponent(label1).addComponent(agglCombo));
vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE).
addComponent(label2).addComponent(praetCombo));
vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE).
addComponent(label3).addComponent(caseCombo));
vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE).
addComponent(label4).addComponent(spaceCombo));
vGroup.addGroup(gl.createParallelGroup(Alignment.BASELINE).
addComponent(label5).addComponent(tokenCombo));
gl.setVerticalGroup(vGroup);
bottomPanel.setBorder(BorderFactory.createEmptyBorder(16, 0, 0, 0));
bottomPanel.add(defaultsButton);
bottomPanel.add(Box.createHorizontalStrut(8));
bottomPanel.add(Box.createHorizontalGlue());
bottomPanel.add(cancelButton);
bottomPanel.add(Box.createHorizontalStrut(8));
bottomPanel.add(acceptButton);
dim = acceptButton.getPreferredSize();
cancelButton.setPreferredSize(dim);
setBorder(BorderFactory.createEmptyBorder(16, 16, 16, 16));
add(paramPanel, BorderLayout.CENTER);
add(bottomPanel, BorderLayout.SOUTH);
defaultsButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
setDefaults();
}
});
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
dialog.setVisible(false);
}
});
acceptButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event)
{
ret = 1;
dialog.setVisible(false);
}
});
}
public void setDefaults()
{
Preferences prefs = new Preferences();
prefs.setMorfeuszDefaults();
initiateValues(prefs);
}
public void initiateValues()
{
initiateValues(controller.getPreferences());
}
public void initiateValues(Preferences prefs)
{
agglCombo.setSelectedItem(prefs.aggl);
praetCombo.setSelectedItem(prefs.praet);
caseCombo.setSelectedItem(prefs.caseHandling.name());
spaceCombo.setSelectedItem(prefs.whitespaceHandling.name());
tokenCombo.setSelectedItem(prefs.tokenNumbering.name());
}
public void transfer(Preferences prefs)
{
prefs.aggl = (String) agglCombo.getSelectedItem();
prefs.praet = (String) praetCombo.getSelectedItem();
prefs.caseHandling = CaseHandling.values()[caseCombo.getSelectedIndex()];
prefs.whitespaceHandling = WhitespaceHandling.values()[spaceCombo.getSelectedIndex()];
prefs.tokenNumbering = TokenNumbering.values()[tokenCombo.getSelectedIndex()];
}
public int doDialog()
{
ret = 0;
dialog = new JDialog();
dialog.setModal(true);
dialog.setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
dialog.setTitle("Opcje programu");
dialog.setResizable(false);
dialog.getContentPane().add(this);
dialog.pack();
dialog.setLocationRelativeTo(null);
dialog.setVisible(true);
return ret;
}
public void dispose()
{
if (dialog != null) {
dialog.dispose();
dialog = null;
}
}
}