Skip to content

Commit d6a3676

Browse files
Merge pull request #70 from EatSleepProgramRepeat/69-make-a-musicbrainzfinalizedrelease-class
69-make-a-musicbrainzfinalizedrelease-class
2 parents 767846b + a7c2d7c commit d6a3676

3 files changed

Lines changed: 91 additions & 4 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* CDPrintable: A program that prints labels with track listings for your CD cases.
3+
* Copyright (C) 2025 Alexander McLean
4+
*
5+
* This source code is licensed under the GNU General Public License v3.0
6+
* found in the LICENSE file in the root directory of this source tree.
7+
*
8+
* This class represents the final album data that will be used to print the CD label.
9+
*/
10+
11+
package com.CDPrintable.MusicBrainzResources;
12+
13+
public class MusicBrainzFinalizedRelease {
14+
private String title;
15+
private String artist;
16+
private MusicBrainzTrack[] tracks;
17+
18+
public MusicBrainzFinalizedRelease(String title, String artist, MusicBrainzTrack[] tracks) {
19+
this.title = title;
20+
this.artist = artist;
21+
this.tracks = tracks;
22+
}
23+
24+
25+
public String getTitle() {
26+
return title;
27+
}
28+
29+
public void setTitle(String title) {
30+
this.title = title;
31+
}
32+
33+
public String getArtist() {
34+
return artist;
35+
}
36+
37+
public void setArtist(String artist) {
38+
this.artist = artist;
39+
}
40+
41+
public MusicBrainzTrack[] getTracks() {
42+
return tracks;
43+
}
44+
45+
public void setTracks(MusicBrainzTrack[] tracks) {
46+
this.tracks = tracks;
47+
}
48+
49+
@Override
50+
public String toString() {
51+
StringBuilder sb = new StringBuilder();
52+
sb.append("Title: ").append(title).append("\n");
53+
sb.append("Artist: ").append(artist).append("\n");
54+
sb.append("Tracks: \n");
55+
for (MusicBrainzTrack track : tracks) {
56+
sb.append(track.getTrackNumber()).append(" ").append(track.getTitle()).append("\n");
57+
}
58+
return sb.toString();
59+
}
60+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* CDPrintable: A program that prints labels with track listings for your CD cases.
3+
* Copyright (C) 2025 Alexander McLean
4+
*
5+
* This source code is licensed under the GNU General Public License v3.0
6+
* found in the LICENSE file in the root directory of this source tree.
7+
*
8+
* This class renders the final labels for the CD cases.
9+
*/
10+
11+
package com.CDPrintable.MusicBrainzResources;
12+
13+
import java.util.ArrayList;
14+
15+
public class MusicBrainzLabelGenerator {
16+
private ArrayList<MusicBrainzFinalizedRelease> finalizedReleaseList;
17+
18+
public MusicBrainzLabelGenerator() {
19+
finalizedReleaseList = new ArrayList<>();
20+
}
21+
22+
public void addRelease(MusicBrainzFinalizedRelease release) {
23+
finalizedReleaseList.add(release);
24+
}
25+
}

src/main/java/com/CDPrintable/ProgramWindow.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class ProgramWindow {
3030
private final JPanel cdSearchPanel = new JPanel();
3131
private final JLabel searchStatusLabel = new JLabel("Status: Nothing's going on.");
3232
private static final ArrayList<String> idList = new ArrayList<>();
33+
private final MusicBrainzLabelGenerator labelGenerator = new MusicBrainzLabelGenerator();
3334

3435
/**
3536
* Creates a new ProgramWindow and sets up the GUI.
@@ -402,10 +403,11 @@ private void clickSearch(int row, int col, JTable table) {
402403
if (col == 0) {
403404
response = sendRequest(typeOfTable.equals("Disc Name") ? "tracks" : "release", idList.get(row), true);
404405
MusicBrainzJSONReader reader = new MusicBrainzJSONReader(response);
405-
model = reader.getTracksAsTableModel(typeOfTable.equals("Disc Name") ? reader.getTracks() : reader.getReleaseTracks());
406+
MusicBrainzTrack[] tracks = typeOfTable.equals("Disc Name") ? reader.getTracks() : reader.getReleaseTracks();
407+
model = reader.getTracksAsTableModel(tracks);
406408
String date = typeOfTable.equals("Release Name") ? table.getValueAt(row, 3).toString() : null;
407409
createTrackDialog(table.getValueAt(row, 0).toString(), table.getValueAt(row, 1).toString(),
408-
Integer.parseInt(table.getValueAt(row, 2).toString()), date, model);
410+
Integer.parseInt(table.getValueAt(row, 2).toString()), date, model, tracks);
409411
} else if (col == 1) {
410412
response = sendRequest("artist", table.getValueAt(row, 1).toString(), false);
411413
MusicBrainzJSONReader reader = new MusicBrainzJSONReader(response);
@@ -428,7 +430,7 @@ private void clickSearch(int row, int col, JTable table) {
428430
* @param date The date of the release. CDStubs typically do not have a date.
429431
* @param model The table model to use for the track list.
430432
*/
431-
private void createTrackDialog(String title, String artist, int trackCount, String date, DefaultTableModel model) {
433+
private void createTrackDialog(String title, String artist, int trackCount, String date, DefaultTableModel model, MusicBrainzTrack[] tracks) {
432434
// Set up panels
433435
JPanel mainPanel = new JPanel(new BorderLayout());
434436
JPanel panel = new JPanel();
@@ -455,7 +457,7 @@ private void createTrackDialog(String title, String artist, int trackCount, Stri
455457
// Show dialog
456458
int result = JOptionPane.showConfirmDialog(null, mainPanel, "Tracks", JOptionPane.YES_NO_OPTION);
457459
if (result == JOptionPane.YES_OPTION) {
458-
System.out.println("ask her out");
460+
labelGenerator.addRelease(new MusicBrainzFinalizedRelease(title, artist, tracks));
459461
} else if (result == JOptionPane.NO_OPTION) {
460462
System.out.println("she rejected you...");
461463
}

0 commit comments

Comments
 (0)