-
Notifications
You must be signed in to change notification settings - Fork 0
/
AlbumArchiver.java
455 lines (394 loc) · 20.1 KB
/
AlbumArchiver.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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
/**
* @brief Main application class
* @author Yannis Exidaridis <[email protected]>
*/
package albums;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class AlbumArchiver extends javax.swing.JFrame {
private final String VERSION = "1.3";
/**
* Creates new form main
*/
public AlbumArchiver () {
initComponents();
Config config = new Config();
if (!config.ReadConfig()) {
Object[] options = { "Install", "Cancel" };
int choice = JOptionPane.showOptionDialog(null, "Config file not found! Click Install to create Database.",
"Warning", JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE,
null,
options,
options[0]);
if (choice == JOptionPane.YES_OPTION) {
new Install().setVisible(true); // install
} else {
System.exit(0); // exit
}
}
}
/**
* 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">//GEN-BEGIN:initComponents
private void initComponents() {
jLabelBackgroundImage = new javax.swing.JLabel();
jMenuBarMain = new javax.swing.JMenuBar();
jMenuActions = new javax.swing.JMenu();
jMenuItemNew = new javax.swing.JMenuItem();
jMenuItemSearch = new javax.swing.JMenuItem();
jMenuItemDisplayCompilations = new javax.swing.JMenuItem();
jMenuItemDisplaySoundtrack = new javax.swing.JMenuItem();
jMenuItemEditArtist = new javax.swing.JMenuItem();
jSeparatorActions = new javax.swing.JPopupMenu.Separator();
jMenuItemExit = new javax.swing.JMenuItem();
jMenuReportToPDF = new javax.swing.JMenu();
jMenuItemExportPdf = new javax.swing.JMenuItem();
jMenuItemExportSQL = new javax.swing.JMenuItem();
jMenuItemExportHTML = new javax.swing.JMenuItem();
jMenuItemExportEpub = new javax.swing.JMenuItem();
jMenuInfo = new javax.swing.JMenu();
jMenuItemStat = new javax.swing.JMenuItem();
jMenuItemAbout = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Music Archiver");
setBackground(new java.awt.Color(255, 255, 255));
setLocation(new java.awt.Point(300, 200));
setResizable(false);
jLabelBackgroundImage.setIcon(new javax.swing.ImageIcon(getClass().getResource("/albums/cover.jpg"))); // NOI18N
jMenuActions.setText("Actions");
jMenuItemNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I, java.awt.event.InputEvent.CTRL_DOWN_MASK));
jMenuItemNew.setText("Insert");
jMenuItemNew.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemNewActionPerformed(evt);
}
});
jMenuActions.add(jMenuItemNew);
jMenuItemSearch.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_DOWN_MASK));
jMenuItemSearch.setText("Search Artist");
jMenuItemSearch.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemSearchActionPerformed(evt);
}
});
jMenuActions.add(jMenuItemSearch);
jMenuItemDisplayCompilations.setText("Display Compilations");
jMenuItemDisplayCompilations.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemCompilationsActionPerformed(evt);
}
});
jMenuActions.add(jMenuItemDisplayCompilations);
jMenuItemDisplaySoundtrack.setText("Display Soundtracks");
jMenuItemDisplaySoundtrack.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemDisplaySoundtrackActionPerformed(evt);
}
});
jMenuActions.add(jMenuItemDisplaySoundtrack);
jMenuItemEditArtist.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_E, java.awt.event.InputEvent.CTRL_DOWN_MASK));
jMenuItemEditArtist.setText("Artist Edit ");
jMenuItemEditArtist.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemEditArtistActionPerformed(evt);
}
});
jMenuActions.add(jMenuItemEditArtist);
jMenuActions.add(jSeparatorActions);
jMenuItemExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_DOWN_MASK));
jMenuItemExit.setText("Exit");
jMenuItemExit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemExitActionPerformed(evt);
}
});
jMenuActions.add(jMenuItemExit);
jMenuBarMain.add(jMenuActions);
jMenuReportToPDF.setText("Export to..");
jMenuItemExportPdf.setText("pdf format");
jMenuItemExportPdf.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemExportPdfActionPerformed(evt);
}
});
jMenuReportToPDF.add(jMenuItemExportPdf);
jMenuItemExportSQL.setText("sql format");
jMenuItemExportSQL.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemExportSQLActionPerformed(evt);
}
});
jMenuReportToPDF.add(jMenuItemExportSQL);
jMenuItemExportHTML.setText("html format");
jMenuItemExportHTML.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemExportHTMLActionPerformed(evt);
}
});
jMenuReportToPDF.add(jMenuItemExportHTML);
jMenuItemExportEpub.setText("epub format");
jMenuItemExportEpub.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemExportEpubActionPerformed(evt);
}
});
jMenuReportToPDF.add(jMenuItemExportEpub);
jMenuBarMain.add(jMenuReportToPDF);
jMenuInfo.setText("Info");
jMenuInfo.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuInfoActionPerformed(evt);
}
});
jMenuItemStat.setText("Statistics");
jMenuItemStat.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemStatActionPerformed(evt);
}
});
jMenuInfo.add(jMenuItemStat);
jMenuItemAbout.setText("About");
jMenuItemAbout.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItemAboutActionPerformed(evt);
}
});
jMenuInfo.add(jMenuItemAbout);
jMenuBarMain.add(jMenuInfo);
setJMenuBar(jMenuBarMain);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelBackgroundImage)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabelBackgroundImage)
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void jMenuItemNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemNewActionPerformed
new InsertForm().setVisible(true);
}//GEN-LAST:event_jMenuItemNewActionPerformed
private void jMenuItemSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemSearchActionPerformed
Database db = new Database();
Integer numOfAlbums = 0;
String SearchName = JOptionPane.showInputDialog(null, "Enter Artist name", "Search", JOptionPane.INFORMATION_MESSAGE);
if (SearchName != null) {
try {
numOfAlbums = db.NumberOfAlbums(SearchName);
} catch (SQLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
if (numOfAlbums == 0) { // no results
JOptionPane.showMessageDialog(null, "There are no albums", "Search", JOptionPane.WARNING_MESSAGE);
} else { try {
// display search results
new DisplayArtistAlbumsForm(SearchName.trim(), numOfAlbums).setVisible(true);
} catch (MalformedURLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}//GEN-LAST:event_jMenuItemSearchActionPerformed
private void jMenuItemExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExitActionPerformed
System.exit(0);
}//GEN-LAST:event_jMenuItemExitActionPerformed
/**
* @brief export to pdf
* @param evt
*/
private void jMenuItemExportPdfActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExportPdfActionPerformed
Report pdfreport;
try {
pdfreport = new Report();
try {
pdfreport.CreateReport(); // report
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "File could not be created!", "Error", JOptionPane.ERROR_MESSAGE);
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (FileNotFoundException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
JOptionPane.showMessageDialog(null, "Output created in file albums.pdf", "Success", JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_jMenuItemExportPdfActionPerformed
private void jMenuItemEditArtistActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemEditArtistActionPerformed
Database db = new Database();
Integer numOfArtists = 0;
String SearchArtistName = JOptionPane.showInputDialog(null, "Enter Artist Name", "Search", JOptionPane.INFORMATION_MESSAGE);
if (SearchArtistName != null) {
try {
numOfArtists = db.NumberOfArtists(SearchArtistName);
} catch (SQLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
if (numOfArtists == 0) { // no results
JOptionPane.showMessageDialog(null, "There are no artists", "Search", JOptionPane.WARNING_MESSAGE);
} else { // display search results
new DisplayArtistsForm(SearchArtistName.trim(), numOfArtists).setVisible(true);
}
}
}//GEN-LAST:event_jMenuItemEditArtistActionPerformed
/**
* @brief export to sql
* @param evt
*/
private void jMenuItemExportSQLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExportSQLActionPerformed
SqlExport export;
export = new SqlExport();
if (export.CreateSqlExport()) {
JOptionPane.showMessageDialog(null, "Output created in file albums.sql", "Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "File could not be created!", "Error", JOptionPane.WARNING_MESSAGE);
}
}//GEN-LAST:event_jMenuItemExportSQLActionPerformed
/**
* brief export to html
* @param evt
*/
private void jMenuItemExportHTMLActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExportHTMLActionPerformed
HtmlExport export;
export = new HtmlExport();
try {
export.CreateExport();
JOptionPane.showMessageDialog(null, "Output created in file albums.html", "Success", JOptionPane.INFORMATION_MESSAGE);
} catch (IOException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
}//GEN-LAST:event_jMenuItemExportHTMLActionPerformed
/**
* @brief export to epub
* @param evt
*/
private void jMenuItemExportEpubActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemExportEpubActionPerformed
EpubExport export;
export = new EpubExport();
if (export.CreateEpubExport()) {
JOptionPane.showMessageDialog(null, "Output created in file albums.epub", "Success", JOptionPane.INFORMATION_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, "File could not be created!", "Error", JOptionPane.WARNING_MESSAGE);
}
}//GEN-LAST:event_jMenuItemExportEpubActionPerformed
private void jMenuInfoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuInfoActionPerformed
}//GEN-LAST:event_jMenuInfoActionPerformed
private void jMenuItemAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAboutActionPerformed
JOptionPane.showMessageDialog(null, "Version "+VERSION, "About", JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_jMenuItemAboutActionPerformed
private void jMenuItemStatActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemStatActionPerformed
Database db = new Database();
String AlbumSum = "You have";
try {
AlbumSum += System.lineSeparator()+db.getFormattedCountAlbum();
} catch (SQLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
JOptionPane.showMessageDialog(null, AlbumSum, "Statistics", JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_jMenuItemStatActionPerformed
private void jMenuItemCompilationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCompilationsActionPerformed
Database db = new Database();
Integer numOfAlbums = 0;
String SearchName = "Various"; // display only `various` albums
try {
numOfAlbums = db.NumberOfAlbums(SearchName);
} catch (SQLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
if (numOfAlbums == 0) { // no results
JOptionPane.showMessageDialog(null, "There are no albums", "Search", JOptionPane.WARNING_MESSAGE);
} else { try {
// display search results
new DisplayArtistAlbumsForm(SearchName.trim(), numOfAlbums).setVisible(true);
} catch (MalformedURLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuItemCompilationsActionPerformed
private void jMenuItemDisplaySoundtrackActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemDisplaySoundtrackActionPerformed
Database db = new Database();
Integer numOfAlbums = 0;
String SearchName = "O.S.T."; // display only soundtracks
try {
numOfAlbums = db.NumberOfAlbums(SearchName);
} catch (SQLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
if (numOfAlbums == 0) { // no results
JOptionPane.showMessageDialog(null, "There are no albums", "Search", JOptionPane.WARNING_MESSAGE);
} else { try {
// display search results
new DisplayArtistAlbumsForm(SearchName.trim(), numOfAlbums).setVisible(true);
} catch (MalformedURLException ex) {
Logger.getLogger(AlbumArchiver.class.getName()).log(Level.SEVERE, null, ex);
}
}
}//GEN-LAST:event_jMenuItemDisplaySoundtrackActionPerformed
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(AlbumArchiver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(AlbumArchiver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(AlbumArchiver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(AlbumArchiver.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
//</editor-fold>
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
new AlbumArchiver().setVisible(true);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabelBackgroundImage;
private javax.swing.JMenu jMenuActions;
private javax.swing.JMenuBar jMenuBarMain;
private javax.swing.JMenu jMenuInfo;
private javax.swing.JMenuItem jMenuItemAbout;
private javax.swing.JMenuItem jMenuItemDisplayCompilations;
private javax.swing.JMenuItem jMenuItemDisplaySoundtrack;
private javax.swing.JMenuItem jMenuItemEditArtist;
private javax.swing.JMenuItem jMenuItemExit;
private javax.swing.JMenuItem jMenuItemExportEpub;
private javax.swing.JMenuItem jMenuItemExportHTML;
private javax.swing.JMenuItem jMenuItemExportPdf;
private javax.swing.JMenuItem jMenuItemExportSQL;
private javax.swing.JMenuItem jMenuItemNew;
private javax.swing.JMenuItem jMenuItemSearch;
private javax.swing.JMenuItem jMenuItemStat;
private javax.swing.JMenu jMenuReportToPDF;
private javax.swing.JPopupMenu.Separator jSeparatorActions;
// End of variables declaration//GEN-END:variables
}