-
Notifications
You must be signed in to change notification settings - Fork 0
/
InsertForm.java
271 lines (240 loc) · 12.7 KB
/
InsertForm.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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/**
* @author Yannis Exidaridis <[email protected]>
*
*/
package albums;
import java.sql.SQLException;
import java.sql.ResultSet;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.time.Year;
import javax.swing.JOptionPane;
/**
*
* @author yannis
*/
public class InsertForm extends javax.swing.JFrame {
/**
* Creates new form InsertForm
*/
public InsertForm() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
buttonGroupVariousOST = new javax.swing.ButtonGroup();
jLabelTitle = new javax.swing.JLabel();
jTextFieldTitle = new javax.swing.JTextField();
jLabelArtist = new javax.swing.JLabel();
jTextFieldArtist = new javax.swing.JTextField();
jLabelYear = new javax.swing.JLabel();
jLabelLabel = new javax.swing.JLabel();
jTextFieldLabel = new javax.swing.JTextField();
jLabelComments = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextAreaComments = new javax.swing.JTextArea();
jButtonInsert = new javax.swing.JButton();
jButtonCancel = new javax.swing.JButton();
jLabelFormat = new javax.swing.JLabel();
jComboBoxFormat = new javax.swing.JComboBox();
jSpinnerYear = new javax.swing.JSpinner();
jRadioButtonVarious = new javax.swing.JRadioButton();
jRadioButtonOST = new javax.swing.JRadioButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("New Album");
setLocation(new java.awt.Point(300, 200));
jLabelTitle.setText("Title");
jLabelArtist.setText("Artist");
jLabelYear.setText("Year");
jLabelLabel.setText("Label");
jLabelComments.setText("Comments");
jTextAreaComments.setColumns(20);
jTextAreaComments.setRows(5);
jScrollPane1.setViewportView(jTextAreaComments);
jButtonInsert.setText("Insert");
jButtonInsert.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonInsertActionPerformed(evt);
}
});
jButtonCancel.setText("Cancel");
jButtonCancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonCancelActionPerformed(evt);
}
});
jLabelFormat.setText("Format");
jComboBoxFormat.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "CD", "2CD", "CDs", "CDR", "LP", "2LP", "EP", "S", "MC", "2MC" }));
Year currentYear = Year.now();
jSpinnerYear.setModel(new javax.swing.SpinnerNumberModel(currentYear.getValue(), 1955, 2040, 1));
jSpinnerYear.setToolTipText("");
jSpinnerYear.setFocusCycleRoot(true);
jSpinnerYear.setValue(2022);
jRadioButtonVarious.setText("Various");
jRadioButtonVarious.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButtonVariousActionPerformed(evt);
}
});
jRadioButtonOST.setText("O.S.T.");
jRadioButtonOST.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jRadioButtonOSTActionPerformed(evt);
}
});
buttonGroupVariousOST.add(jRadioButtonVarious);
buttonGroupVariousOST.add(jRadioButtonOST);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelTitle)
.addComponent(jLabelArtist)
.addComponent(jLabelYear)
.addComponent(jLabelLabel)
.addComponent(jLabelComments)
.addComponent(jLabelFormat))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 91, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jRadioButtonVarious)
.addGap(69, 69, 69)
.addComponent(jRadioButtonOST))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(jButtonInsert)
.addGap(39, 39, 39)
.addComponent(jButtonCancel))
.addComponent(jTextFieldTitle)
.addComponent(jTextFieldArtist, javax.swing.GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
.addComponent(jTextFieldLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 244, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jComboBoxFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jSpinnerYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGap(19, 19, 19))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(39, 39, 39)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelTitle)
.addComponent(jTextFieldTitle, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelArtist)
.addComponent(jTextFieldArtist, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jRadioButtonVarious)
.addComponent(jRadioButtonOST))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelFormat)
.addComponent(jComboBoxFormat, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelYear)
.addComponent(jSpinnerYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabelLabel)
.addComponent(jTextFieldLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(30, 30, 30)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelComments)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(28, 28, 28)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButtonInsert)
.addComponent(jButtonCancel))
.addGap(51, 51, 51))
);
pack();
}// </editor-fold>
private void jButtonInsertActionPerformed(java.awt.event.ActionEvent evt) {
String Artist = "";
Integer NumberOfArtist = 0;
String Title = jTextFieldTitle.getText();
// get artist
if (jRadioButtonVarious.isSelected()) {
Artist = "Various";
} else if (jRadioButtonOST.isSelected()) {
Artist = "O.S.T.";
} else {
Artist = jTextFieldArtist.getText();
}
// ------------
String Format = (String) jComboBoxFormat.getSelectedItem();
Integer Year = Integer.parseInt(jSpinnerYear.getValue().toString());
String Label = jTextFieldLabel.getText();
String Comments = jTextAreaComments.getText();
String SortArtistName = Artist;
// insert album in db
Database db = new Database();
try {
NumberOfArtist = db.NumberOfArtists(Artist);
} catch (SQLException ex) {
Logger.getLogger(InsertForm.class.getName()).log(Level.SEVERE, null, ex);
}
if (db.InsertAlbum(Title, Artist, Format, Year, Label, Comments, SortArtistName)) {
JOptionPane.showMessageDialog(null, "Album inserted successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);
if (NumberOfArtist == 0) { // new artist ?
SortArtistName = (String) JOptionPane.showInputDialog(null, "Enter (sortable) artist name", "Search", JOptionPane.INFORMATION_MESSAGE, null, null, Artist);
if (db.UpdateArtistSortName(Artist, SortArtistName)) { // if yes, update it with `sort` name
JOptionPane.showMessageDialog(null, "Album updated successfully!", "Success", JOptionPane.INFORMATION_MESSAGE);
}
} else {
ResultSet rs = db.GetArtistSortName(Artist);
try {
rs.next();
SortArtistName = rs.getString(1);
} catch (SQLException ex) {
Logger.getLogger(InsertForm.class.getName()).log(Level.SEVERE, null, ex);
}
db.UpdateArtistSortName(Artist, SortArtistName);
}
}
dispose();
}
private void jButtonCancelActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void jRadioButtonVariousActionPerformed(java.awt.event.ActionEvent evt) {
if (jRadioButtonVarious.isSelected()) {
jTextFieldArtist.setEnabled(false);
}
}
private void jRadioButtonOSTActionPerformed(java.awt.event.ActionEvent evt) {
if (jRadioButtonOST.isSelected()) {
jTextFieldArtist.setEnabled(false);
}
}
private javax.swing.ButtonGroup buttonGroupVariousOST;
private javax.swing.JButton jButtonCancel;
private javax.swing.JButton jButtonInsert;
private javax.swing.JComboBox jComboBoxFormat;
private javax.swing.JLabel jLabelArtist;
private javax.swing.JLabel jLabelComments;
private javax.swing.JLabel jLabelFormat;
private javax.swing.JLabel jLabelLabel;
private javax.swing.JLabel jLabelTitle;
private javax.swing.JLabel jLabelYear;
private javax.swing.JRadioButton jRadioButtonOST;
private javax.swing.JRadioButton jRadioButtonVarious;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JSpinner jSpinnerYear;
private javax.swing.JTextArea jTextAreaComments;
private javax.swing.JTextField jTextFieldArtist;
private javax.swing.JTextField jTextFieldLabel;
private javax.swing.JTextField jTextFieldTitle;
}