From eaef4e88fa99ec64f34c69c1737a21a273f269e9 Mon Sep 17 00:00:00 2001 From: Philip Leifeld Date: Mon, 26 Aug 2024 17:33:06 +0200 Subject: [PATCH] Fixed #294 (color picker in attribute manager) and a bug in the document batch importer GUI --- dna/src/main/java/dna/Dna.java | 4 +- dna/src/main/java/gui/AttributeManager.java | 6 +-- .../main/java/gui/DocumentBatchImporter.java | 37 +++++++++++++------ rDNA/rDNA/DESCRIPTION | 4 +- 4 files changed, 33 insertions(+), 18 deletions(-) diff --git a/dna/src/main/java/dna/Dna.java b/dna/src/main/java/dna/Dna.java index 20202d8b..664a9fec 100644 --- a/dna/src/main/java/dna/Dna.java +++ b/dna/src/main/java/dna/Dna.java @@ -17,8 +17,8 @@ public class Dna { public static Dna dna; public static Logger logger; public static Sql sql; - public static final String date = "2024-08-20"; - public static final String version = "3.0.11"; + public static final String date = "2024-08-26"; + public static final String version = "3.0.12.1"; public static final String operatingSystem = System.getProperty("os.name"); public static File workingDirectory = null; public static Gui gui; diff --git a/dna/src/main/java/gui/AttributeManager.java b/dna/src/main/java/gui/AttributeManager.java index 36a1ce18..eca06395 100644 --- a/dna/src/main/java/gui/AttributeManager.java +++ b/dna/src/main/java/gui/AttributeManager.java @@ -635,8 +635,8 @@ public void setValueAt(Object aValue, int row, int col) { } } else if (col == 2) { // color try { - Dna.sql.setEntityColor(this.rows.get(row).getId(), (model.Color) aValue); - this.rows.get(row).setColor((model.Color) aValue); + Dna.sql.setEntityColor(this.rows.get(row).getId(), new model.Color(((Color) aValue).getRed(), ((Color) aValue).getGreen(), ((Color) aValue).getBlue())); + this.rows.get(row).setColor(new model.Color(((Color) aValue).getRed(), ((Color) aValue).getGreen(), ((Color) aValue).getBlue())); } catch (SQLException ex) { LogEvent l = new LogEvent(Logger.ERROR, "[SQL] Entity color could not be updated in the database.", @@ -921,7 +921,7 @@ private void changeColor(Color color) { * @param column The column index of the cell. */ public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { - changeColor((Color) value); + changeColor(((model.Color) value).toAWTColor()); panel.setBackground(UIManager.getColor("Table.selectionBackground")); return panel; } diff --git a/dna/src/main/java/gui/DocumentBatchImporter.java b/dna/src/main/java/gui/DocumentBatchImporter.java index 0e587026..eeb2a208 100644 --- a/dna/src/main/java/gui/DocumentBatchImporter.java +++ b/dna/src/main/java/gui/DocumentBatchImporter.java @@ -99,17 +99,32 @@ public void actionPerformed(ActionEvent e) { JButton browseButton = new JButton("Select text files", folderIcon); browseButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - FileChooser fc = new FileChooser(DocumentBatchImporter.this, "Select directory", false, "", "Import directory", true); - if (fc.getFiles() != null) { - files = fc.getFiles(); - listModel.clear(); - Arrays.stream(fc.getFiles()) - .filter(f -> f.isFile()) - .map(f -> f.getName()) - .forEachOrdered(f -> listModel.addElement(f)); - fileList.updateUI(); - if (files.length > 0) { - fileList.setSelectedIndex(0); + FileChooser fc = null; + try { + fc = new FileChooser(DocumentBatchImporter.this, "Select text files", false, "", "Import files", true); + } catch (NullPointerException npe) { + LogEvent l = new LogEvent(Logger.MESSAGE, + "[GUI] Cancelled file selection in batch import window.", + "Cancelled file selection in batch import window. No files were selected."); + Dna.logger.log(l); + } finally { + if (fc != null && fc.getFiles() != null) { + files = fc.getFiles(); + listModel.clear(); + Arrays.stream(fc.getFiles()) + .filter(f -> f.isFile()) + .map(f -> f.getName()) + .forEachOrdered(f -> listModel.addElement(f)); + fileList.updateUI(); + if (files.length > 0) { + fileList.setSelectedIndex(0); + } + } else { + // no files were selected or FileChooser was cancelled + LogEvent l = new LogEvent(Logger.MESSAGE, + "[GUI] No files were selected in the batch import window.", + "File selection was cancelled or no files were selected."); + Dna.logger.log(l); } } } diff --git a/rDNA/rDNA/DESCRIPTION b/rDNA/rDNA/DESCRIPTION index 103e06eb..a82898f7 100755 --- a/rDNA/rDNA/DESCRIPTION +++ b/rDNA/rDNA/DESCRIPTION @@ -1,6 +1,6 @@ Package: rDNA -Version: 3.0.11 -Date: 2024-08-20 +Version: 3.0.12.1 +Date: 2024-08-26 Title: Discourse Network Analysis in R Authors@R: c(person(given = "Philip",