From 0a91e2d359edeb53f701e9c1d6aa0d2496f82328 Mon Sep 17 00:00:00 2001 From: Tim Bernhard Date: Mon, 30 Sep 2024 22:10:53 +0200 Subject: [PATCH] Various minor re-orderings and improvements --- .../mcz/imagecapture/ImageCaptureApp.java | 2 +- .../mcz/imagecapture/SpecimenBrowser.java | 30 +++++++++++++++- .../jobs/JobAllImageFilesScan.java | 2 +- .../jobs/JobSingleBarcodeScan.java | 2 +- .../lifecycle/SpecimenLifeCycle.java | 10 ++++-- .../ui/component/JTableCellTabbing.java | 2 ++ .../imagecapture/ui/dialog/SearchDialog.java | 16 ++++----- .../mcz/imagecapture/ui/frame/MainFrame.java | 4 +-- .../ui/frame/SpecimenDetailsViewPane.java | 35 ++++++++++++++----- 9 files changed, 77 insertions(+), 26 deletions(-) diff --git a/src/main/java/edu/harvard/mcz/imagecapture/ImageCaptureApp.java b/src/main/java/edu/harvard/mcz/imagecapture/ImageCaptureApp.java index e765105..7937a86 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/ImageCaptureApp.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/ImageCaptureApp.java @@ -190,7 +190,7 @@ public static void main(String[] args) { SpecimenLifeCycle sls = new SpecimenLifeCycle(); try { Singleton.getSingletonInstance().getMainFrame().setCount( - sls.findSpecimenCountThrows()); + sls.findSpecimenCountThrows(", ")); ImageCaptureApp.doStartUp(); } catch (ConnectionException e) { log.error(e.getMessage()); diff --git a/src/main/java/edu/harvard/mcz/imagecapture/SpecimenBrowser.java b/src/main/java/edu/harvard/mcz/imagecapture/SpecimenBrowser.java index 21109c2..8a6b132 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/SpecimenBrowser.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/SpecimenBrowser.java @@ -29,6 +29,7 @@ import edu.harvard.mcz.imagecapture.ui.frame.SpecimenDetailsViewPane; import edu.harvard.mcz.imagecapture.ui.tablemodel.SpecimenListTableModel; import edu.harvard.mcz.imagecapture.ui.tablemodel.TableColumnManager; +import org.apache.commons.lang3.BooleanUtils; import org.hibernate.SessionException; import org.hibernate.TransactionException; import org.slf4j.Logger; @@ -38,6 +39,7 @@ import javax.swing.table.TableRowSorter; import java.awt.*; import java.util.ArrayList; +import java.util.Comparator; import java.util.Map; /** @@ -136,7 +138,33 @@ private JTable getJTable() { jTable.setModel(model); new TableColumnManager(jTable); sorter = new TableRowSorter<>(model); - sorter.toggleSortOrder(SpecimenListTableModel.COL_BARCODE - 1); + int copyPasteOffset = BooleanUtils.toInteger(!SpecimenDetailsViewPane.copyPasteActivated); + sorter.toggleSortOrder(SpecimenListTableModel.COL_BARCODE - copyPasteOffset); + sorter.setComparator(SpecimenListTableModel.COL_COLLECTION_NR - copyPasteOffset, new Comparator() { + @Override + public int compare(Object o1, Object o2) { + if (o1 instanceof String && ((String) o1).trim().equals("")) { + o1 = Double.valueOf(0); + } + if (o2 instanceof String && ((String) o2).trim().equals("")) { + o2 = Double.valueOf(0); + } + if (o1 instanceof String && o2 instanceof String) { + return ((String) o1).compareToIgnoreCase((String) o2); + } + if (o1 instanceof Double && o2 instanceof Double) { + return ((Double) o1).compareTo((Double) o2); + } + if (o1 instanceof Double && o2 instanceof String) { + return -1; + } + if (o2 instanceof Double && o1 instanceof String) { + return 1; + } + log.error("Unexpected type in compare: {} - {}", o1, o2); + return 0; + } + }); jTable.setRowSorter(sorter); jTable.setDefaultRenderer(Specimen.class, new ButtonRenderer()); jTable.setDefaultEditor(Specimen.class, new ButtonEditor()); diff --git a/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobAllImageFilesScan.java b/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobAllImageFilesScan.java index 9ef4c37..ffb92bf 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobAllImageFilesScan.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobAllImageFilesScan.java @@ -272,7 +272,7 @@ public void start() { SpecimenLifeCycle sls = new SpecimenLifeCycle(); Singleton.getSingletonInstance().getMainFrame().setCount( - sls.findSpecimenCount()); + sls.findSpecimenCount(", ")); done(); } diff --git a/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobSingleBarcodeScan.java b/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobSingleBarcodeScan.java index 51a188b..292995b 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobSingleBarcodeScan.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/jobs/JobSingleBarcodeScan.java @@ -159,7 +159,7 @@ public void start() { Singleton.getSingletonInstance().getMainFrame().setStatusMessage(""); SpecimenLifeCycle sls = new SpecimenLifeCycle(); Singleton.getSingletonInstance().getMainFrame().setCount( - sls.findSpecimenCount()); + sls.findSpecimenCount(", ")); Singleton.getSingletonInstance().getJobList().removeJob(this); } diff --git a/src/main/java/edu/harvard/mcz/imagecapture/lifecycle/SpecimenLifeCycle.java b/src/main/java/edu/harvard/mcz/imagecapture/lifecycle/SpecimenLifeCycle.java index 64bd9ff..3336617 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/lifecycle/SpecimenLifeCycle.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/lifecycle/SpecimenLifeCycle.java @@ -555,9 +555,9 @@ private String[] loadStringsBySQL(ArrayList collections, String sql) { return runQueryToGetStrings(collections, sql, log); } - public String findSpecimenCount() { + public String findSpecimenCount(String delimiter) { try { - return findSpecimenCountThrows(); + return findSpecimenCountThrows(delimiter); } catch (ConnectionException e) { log.error(e.getMessage(), e); } @@ -565,6 +565,10 @@ public String findSpecimenCount() { } public String findSpecimenCountThrows() throws ConnectionException { + return findSpecimenCountThrows(", "); + } + + public String findSpecimenCountThrows(String delimiter) throws ConnectionException { StringBuilder result = new StringBuilder(); try { String sql = @@ -583,7 +587,7 @@ public String findSpecimenCountThrows() throws ConnectionException { resultStrings.add(count.toString() + " " + status); } result.append(total + " Specimen records: \n"); - result.append(String.join(", ", resultStrings)); + result.append(String.join(delimiter, resultStrings)); session.getTransaction().commit(); } catch (HibernateException e) { session.getTransaction().rollback(); diff --git a/src/main/java/edu/harvard/mcz/imagecapture/ui/component/JTableCellTabbing.java b/src/main/java/edu/harvard/mcz/imagecapture/ui/component/JTableCellTabbing.java index 75847bd..cc6def5 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/ui/component/JTableCellTabbing.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/ui/component/JTableCellTabbing.java @@ -64,6 +64,7 @@ public void actionPerformed(ActionEvent e) { // Move cell selection theTable.changeSelection(row, col, false, false); theTable.editCellAt(row, col); +// theTable.getCellEditor(row, col).getTableCellEditorComponent(theTable, ).requestFocus(); } }); @@ -93,6 +94,7 @@ public void actionPerformed(ActionEvent e) { // Move cell selection if (theTable.editCellAt(row, col)) { theTable.changeSelection(row, col, false, false); + theTable.editCellAt(row, col); }; } }); diff --git a/src/main/java/edu/harvard/mcz/imagecapture/ui/dialog/SearchDialog.java b/src/main/java/edu/harvard/mcz/imagecapture/ui/dialog/SearchDialog.java index b5ed344..b2a80b2 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/ui/dialog/SearchDialog.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/ui/dialog/SearchDialog.java @@ -337,15 +337,15 @@ private JScrollPane getJPanelWithFields() { "Barcode", "Order", "Family", - "Tribe", "Subfamily", + "Tribe", "Genus", "Species", "Subspecies", - "Verbatim Locality", - "Specific Locality", - "State/Province", "Country", + "State/Province", + "Specific Locality", + "Verbatim Locality", "Collection", "Collection Nr.", "Collector", @@ -366,15 +366,15 @@ private JScrollPane getJPanelWithFields() { this.getBarcodeJTextField(), this.getOrderJTextField(), this.getFamilyJTextField(), - this.getTribeJTextField(), this.getSubfamilyJTextField(), + this.getTribeJTextField(), this.getGenusJTextField(), this.getSpeciesJTextField(), this.getSubspeciesJTextField(), - this.getVerbatimLocalityJTextField(), - this.getSpecificLocalityJComboBox(), - this.getPrimaryDivisionJComboBox(), this.getCountryJComboBox(), + this.getPrimaryDivisionJComboBox(), + this.getSpecificLocalityJComboBox(), + this.getVerbatimLocalityJTextField(), this.getCollectionJComboBox(), this.getCollectionNrJTextField(), this.getCollectorsJComboBox(), diff --git a/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/MainFrame.java b/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/MainFrame.java index ad036f3..e1e3154 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/MainFrame.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/MainFrame.java @@ -423,7 +423,7 @@ private JMenuItem getJMenuItemLogout() { // Force a login dialog by connecting to obtain record count; SpecimenLifeCycle sls = new SpecimenLifeCycle(); try { - setCount(sls.findSpecimenCountThrows()); + setCount(sls.findSpecimenCountThrows(", ")); ImageCaptureApp.doStartUp(); } catch (ConnectionException e1) { log.error(e1.getMessage(), e1); @@ -1580,7 +1580,7 @@ private JMenuItem getJMenuItem() { SpecimenLifeCycle sls = new SpecimenLifeCycle(); JOptionPane.showMessageDialog( Singleton.getSingletonInstance().getMainFrame(), - sls.findSpecimenCount(), "Record counts", + sls.findSpecimenCount(",\n- "), "Record counts", JOptionPane.INFORMATION_MESSAGE); }); } diff --git a/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/SpecimenDetailsViewPane.java b/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/SpecimenDetailsViewPane.java index 244d217..7ed3970 100644 --- a/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/SpecimenDetailsViewPane.java +++ b/src/main/java/edu/harvard/mcz/imagecapture/ui/frame/SpecimenDetailsViewPane.java @@ -564,7 +564,7 @@ private boolean save() { } SpecimenLifeCycle sls = new SpecimenLifeCycle(); Singleton.getSingletonInstance().getMainFrame().setCount( - sls.findSpecimenCount()); + sls.findSpecimenCount(", ")); } catch (OptimisticLockException e) { // Oh, well. Issues with foreign keys already deleting items, which are // not found afterwards. We catch these here and silence them. TODO: @@ -952,10 +952,15 @@ private JPanel getJPanel() { jPanel.add(this.getDetsJButton(), "sizegroup datedet"); // section: family, classification // row + this.addBasicJLabel(jPanel, "Order"); + jPanel.add(this.getOrderJTextField(), "grow"); this.addBasicJLabel(jPanel, "Family"); jPanel.add(this.getFamilyJTextField(), "grow"); + // row this.addBasicJLabel(jPanel, "Subfamily"); jPanel.add(this.getJTextFieldSubfamily(), "grow"); + this.addBasicJLabel(jPanel, "Tribe"); + jPanel.add(this.getJTextFieldTribe(), "grow"); // row this.addBasicJLabel(jPanel, "Genus"); jPanel.add(this.getGenusJTextField(), "grow"); @@ -964,16 +969,11 @@ private JPanel getJPanel() { // row this.addBasicJLabel(jPanel, "Subspecies"); jPanel.add(this.getSubspecifcEpithetJTextField(), "grow"); - this.addBasicJLabel(jPanel, "Tribe"); - jPanel.add(this.getJTextFieldTribe(), "grow"); - // row this.addBasicJLabel(jPanel, "Infrasubspecific Name"); jPanel.add(this.getJTextFieldInfraspecificName(), "grow"); + // row this.addBasicJLabel(jPanel, "Infrasubspecific Rank"); jPanel.add(this.getJTextFieldInfraspecificRank(), "grow"); - // row - this.addBasicJLabel(jPanel, "Author"); - jPanel.add(this.getJTextFieldAuthorship(), "grow"); this.addBasicJLabel(jPanel, "TypeStatus"); jPanel.add(this.getCbTypeStatus()); // section: locale @@ -1013,8 +1013,8 @@ private JPanel getJPanel() { jPanel.add(this.getComboBoxElevUnits(), "sizegroup elevation"); // section: collection // row - this.addBasicJLabel(jPanel, "Order"); - jPanel.add(this.getOrderJTextField(), "grow"); + this.addBasicJLabel(jPanel, "Author"); + jPanel.add(this.getJTextFieldAuthorship(), "grow"); this.addBasicJLabel(jPanel, "Collection"); jPanel.add(this.getJTextFieldCollection(), "grow"); // "span 3" // double row: @@ -1830,6 +1830,23 @@ private void setupNumberJTableRenderer() { DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer.setToolTipText("Click for pick list of number types."); typeColumn.setCellRenderer(renderer); + + // enable tabbing (does not work yet) +// field1.addKeyListener(new KeyAdapter() { +// @Override +// public void keyPressed(KeyEvent e) { +// if (e.getKeyCode() == KeyEvent.VK_TAB) { +// int row = jTableNumbers.getSelectedRow(); +// int col = jTableNumbers.getSelectedColumn(); +// assert( col == 0); +// jTableNumbers.changeSelection(row, 1, false, false); +// jTableNumbers.editCellAt(row, 1); +// jTableNumbers.transferFocus(); +// } else { +// super.keyPressed(e); +// } +// } +// }); } /**