Skip to content

Commit

Permalink
Various minor re-orderings and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
GenieTim committed Sep 30, 2024
1 parent 32b9ab8 commit 0a91e2d
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
30 changes: 29 additions & 1 deletion src/main/java/edu/harvard/mcz/imagecapture/SpecimenBrowser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,6 +39,7 @@
import javax.swing.table.TableRowSorter;
import java.awt.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Map;

/**
Expand Down Expand Up @@ -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<Object>() {
@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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void start() {

SpecimenLifeCycle sls = new SpecimenLifeCycle();
Singleton.getSingletonInstance().getMainFrame().setCount(
sls.findSpecimenCount());
sls.findSpecimenCount(", "));

done();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,16 +555,20 @@ private String[] loadStringsBySQL(ArrayList<String> 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);
}
return "";
}

public String findSpecimenCountThrows() throws ConnectionException {
return findSpecimenCountThrows(", ");
}

public String findSpecimenCountThrows(String delimiter) throws ConnectionException {
StringBuilder result = new StringBuilder();
try {
String sql =
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
});

Expand Down Expand Up @@ -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);
};
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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");
Expand All @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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);
// }
// }
// });
}

/**
Expand Down

0 comments on commit 0a91e2d

Please sign in to comment.