-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGlossaryDefine.java
192 lines (160 loc) · 4.62 KB
/
GlossaryDefine.java
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.ImageIcon;
import java.awt.Color;
import javax.swing.SwingConstants;
/**
* This class creates a GUI for the user to interact with in
* order to type in a new term and its definition to add
* to their usecase project.
*
* @author Wesley Krug, Gabriel Steponovich,
* Michael Brecker, Halston Raddatz
* @version Winter 2015
*
*/
public class GlossaryDefine extends JDialog implements ActionListener {
/**
* serial Version.
*/
private static final long serialVersionUID = 1L;
/**
* Creates a panel text boxes.
*/
private JPanel panel;
/**
* Creates a panel for buttons.
*/
private JPanel buttonPanel;
/**
* Term text field.
*/
private JTextField word;
/**
* Definition text field.
*/
private JTextPane def;
/**
* OK button.
*/
private JButton oK;
/**
* Creates an object for a glossary term.
*/
private Glossary glossaryTerm;
/**
* Constructor to set up GUI for user interaction.
*/
public GlossaryDefine(final String g, final String s, boolean flag) {
setLocationRelativeTo(null);
if(flag) {
setTitle("Glossary: " + g);
} else {
setTitle("Actor: " + g);
}
setSize(500,250);
panel = new JPanel();
panel.setBounds(0, 0, 484, 211);
buttonPanel = new JPanel();
buttonPanel.setBounds(0, 201, 484, 10);
panel.setLayout(null);
JScrollPane sp = new JScrollPane();
sp.setBackground(Color.BLACK);
sp.setOpaque(false);
sp.setForeground(Color.BLACK);
sp.setViewportBorder(null);
sp.setBounds(107, 100, 259, 66);
sp.getViewport().setOpaque(false);
panel.add(sp);
sp.setBorder(null);
def = new JTextPane();
def.setEditable(false);
def.setText(s);
sp.setViewportView(def);
def.setDisabledTextColor(Color.WHITE);
def.setBorder(null);
def.setOpaque(false);
word = new JTextField(30);
word.setEditable(false);
word.setHorizontalAlignment(SwingConstants.CENTER);
word.setText(g);
word.setBorder(null);
word.setOpaque(false);
word.setBounds(107, 27, 255, 36);
panel.add(word);
getContentPane().setLayout(null);
getContentPane().add(panel);
oK = new JButton("");
oK.setIcon(new ImageIcon(GlossaryWord.class.getResource("/resources/ok.png")));
oK.setBounds(203, 177, 80, 23);
panel.add(oK);
JLabel lblNewLabel = new JLabel("");
lblNewLabel.setIcon(new ImageIcon(GlossaryWord.class.getResource("/resources/glossayword.png")));
lblNewLabel.setBounds(0, 0, 484, 211);
panel.add(lblNewLabel);
//buttonPanel.add(oK);
//buttonPanel.add(cancel);
getContentPane().add(buttonPanel);
oK.addActionListener(this);
glossaryTerm = new Glossary();
setVisible(true);
}
/**
* Adds an ActionListerner to save the term when ok is pressed.
*
* @param listener is an ActionListener
*/
public final void addSaveListener(final ActionListener listener) {
oK.addActionListener(listener);
}
/**
* The action performed method for created a new term in the
* glossary.
*
* @param e is an ActionEvent
*/
public final void actionPerformed(final ActionEvent e) {
if (e.getSource() == oK) {
if (!word.getText().equals("")) {
try {
dispose();
} catch (Exception e1) {
e1.printStackTrace();
}
} else {
JOptionPane.showMessageDialog(null,
"No term entered.\n", "ID ERROR",
JOptionPane.INFORMATION_MESSAGE);
}
}
}
/**
* Gets a glossary item.
*
* @return the object of a term
*/
public final Glossary getGlossaryTerm() {
glossaryTerm.setWord(word.getText());
glossaryTerm.setDefinition(def.getText());
return glossaryTerm;
}
/**
* Sets a Glossary item.
*
* @param glossary is a Glossary class object
*/
public final void setGlossaryTerm(final Glossary glossary) {
word.setText(glossary.getWord());
def.setText(glossary.getDefinition());
}
}