Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ public MusicBrainzTrack[] getReleaseTracks() {
List<MusicBrainzTrack> trackList = new ArrayList<>();

JsonArray mediaArray = json.getAsJsonArray("media");
if (mediaArray == null) {
JOptionPane.showMessageDialog(null, "No media found in JSON.", "Error", JOptionPane.ERROR_MESSAGE);
return new MusicBrainzTrack[0];
}
for (JsonElement mediaElement : mediaArray) {
JsonObject mediaObject = mediaElement.getAsJsonObject(); // Cast each element to JsonObject
JsonArray trackArray = mediaObject.getAsJsonArray("tracks");
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/com/CDPrintable/ProgramWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import java.awt.*;
Expand Down Expand Up @@ -132,9 +133,11 @@ public void mouseClicked(MouseEvent e) {
clearIdList();
String finalSelectedItem = selectedItem;
Constants.THREAD_MANAGER.submit(() -> {
int[] columnsToHighlight = null;
MusicBrainzJSONReader reader = new MusicBrainzJSONReader(sendRequest(finalSelectedItem.toLowerCase(Locale.ROOT), searchField.getText(), false));
switch (finalSelectedItem) {
case "CDStub" -> {
columnsToHighlight = new int[]{0, 1};
// Get CDStubs and set the table model
MusicBrainzCDStub[] cdStubs = reader.getCDStubs();
for (MusicBrainzCDStub cdStub : cdStubs) {
Expand All @@ -153,6 +156,7 @@ public void mouseClicked(MouseEvent e) {
searchTable.setModel(reader.getArtistsAsTableModel(artists));
}
case "Release" -> {
columnsToHighlight = new int[]{0, 1};
// Get Releases and set the table model
MusicBrainzRelease[] releases = reader.getReleases();
for (MusicBrainzRelease release : releases) {
Expand All @@ -163,8 +167,12 @@ public void mouseClicked(MouseEvent e) {
}
default -> JOptionPane.showMessageDialog(panel, "Please select a search type.");
}
if (columnsToHighlight != null) {
for (int column : columnsToHighlight) {
searchTable.getColumnModel().getColumn(column).setCellRenderer(new LightBlueColumnRenderer());
}
}
});

resizeColumnWidths(searchTable);
});

Expand All @@ -176,6 +184,9 @@ public void mouseClicked(MouseEvent e) {
// Add the CD Search panel to the main panel
panel.add(cdSearchPanel, BorderLayout.SOUTH);

// Add a label that informs the user about ClickSearch.
panel.add(new JLabel("Click a row in a column that is highlighted in light blue to search or add something to the final label."), BorderLayout.NORTH);

return panel;
}

Expand Down Expand Up @@ -402,7 +413,7 @@ private void clickSearch(int row, int col, JTable table) {

try {
if (col == 0) {
response = sendRequest(typeOfTable.equals("Disc Name") ? "tracks" : "release", idList.get(row), typeOfTable.equals("Disc Name"));
response = sendRequest(typeOfTable.equals("Disc Name") ? "tracks" : "release", idList.get(row), true);
MusicBrainzJSONReader reader = new MusicBrainzJSONReader(response);
model = reader.getTracksAsTableModel(typeOfTable.equals("Disc Name") ? reader.getTracks() : reader.getReleaseTracks());
String date = typeOfTable.equals("Release Name") ? table.getValueAt(row, 3).toString() : null;
Expand All @@ -415,7 +426,7 @@ private void clickSearch(int row, int col, JTable table) {
createArtistDialog(model);
}
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "An error occurred while processing the request.", "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(null, "An error occurred while processing the request. More info: " + e, "Error", JOptionPane.ERROR_MESSAGE);
setSearchStatus("Error", "red");
}
});
Expand Down Expand Up @@ -480,4 +491,17 @@ private void createArtistDialog(DefaultTableModel model) {
dialog.pack();
dialog.setVisible(true);
}

/**
* A custom table cell renderer that sets the background color of the cell to light blue.
* Used for columns that support ClickSearch.
*/
static class LightBlueColumnRenderer extends DefaultTableCellRenderer {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
cell.setBackground(new Color(173, 216, 230)); // Light blue color
return cell;
}
}
}
2 changes: 1 addition & 1 deletion src/main/resources/version.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Application version.

# MAJOR MINOR PATCH
version=1.10.6
version=1.10.7