Skip to content

Commit

Permalink
Integrate New Time Filter
Browse files Browse the repository at this point in the history
  • Loading branch information
AvocadoMoon committed Oct 21, 2024
1 parent f941014 commit 912e033
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@ public class ControlButtonsPanel extends JPanel implements ActionListener {
private final JButton useN5Link;
private final JButton questionMark;
private final JButton openInMemory;
private final JCheckBox includeExampleExports;
private final JCheckBox todayInterval;
private final JCheckBox monthInterval;
private final JCheckBox yearlyInterval;
private final JCheckBox anyInterval;
private final JPanel timeFilter;

private N5ExportTable n5ExportTable;
private RemoteFileSelection remoteFileSelection;
Expand All @@ -37,8 +31,6 @@ public ControlButtonsPanel(){
questionMark.setPreferredSize(new Dimension(20, 20));
openInMemory = new JButton("Open In Memory");
openInMemory.setSelected(false);
includeExampleExports = new JCheckBox("Show Example Exports");
includeExampleExports.setSelected(!N5ImageHandler.exportedDataExists());

GridBagConstraints gridBagConstraints = new GridBagConstraints();

Expand Down Expand Up @@ -72,53 +64,26 @@ public ControlButtonsPanel(){
// buttonsPanel.add(questionMark);


todayInterval = new JCheckBox("Past 24 Hours");
monthInterval = new JCheckBox("Past Month");
yearlyInterval = new JCheckBox("Past Year");
anyInterval = new JCheckBox("Any Time");
anyInterval.setSelected(true);

ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(todayInterval);
buttonGroup.add(monthInterval);
buttonGroup.add(yearlyInterval);
buttonGroup.add(anyInterval);

JPanel filters = new JPanel();
filters.setLayout(new BorderLayout());
timeFilter = new JPanel(new GridBagLayout());
timeFilter.add(anyInterval);
timeFilter.add(todayInterval);
timeFilter.add(monthInterval);
timeFilter.add(yearlyInterval);
// timeFilter.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Time "));
filters.add(timeFilter, BorderLayout.NORTH);
filters.add(includeExampleExports, BorderLayout.SOUTH);
Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
filters.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Filters "));



int paneWidth = 800;
this.setPreferredSize(new Dimension(paneWidth, 100));
this.setLayout(new BorderLayout());
// topBar.add(openLocal);
Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
this.add(userButtonsPanel, BorderLayout.EAST);
this.add(filters, BorderLayout.WEST);
this.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " User Options "));


openOrCancel.addActionListener(this);
copyLink.addActionListener(this);
questionMark.addActionListener(this);
useN5Link.addActionListener(this);
includeExampleExports.addActionListener(this);
// openLocal.addActionListener(this);
openInMemory.addActionListener(this);

Enumeration<AbstractButton> b = buttonGroup.getElements();
while (b.hasMoreElements()){
b.nextElement().addActionListener(this);
}


openOrCancel.setEnabled(false);
copyLink.setEnabled(false);
Expand All @@ -144,34 +109,7 @@ public void actionPerformed(ActionEvent e) {
new HelpExplanation().displayHelpMenu();
} else if (e.getSource().equals(useN5Link)) {
remoteFileSelection.setVisible(true);
} else if (e.getSource().equals(includeExampleExports)){
if(includeExampleExports.isSelected()){
n5ExportTable.updateExampleExportsToTable();
return;
}
n5ExportTable.updateTableData();
} else if (e.getSource().equals(anyInterval) || e.getSource().equals(todayInterval)
|| e.getSource().equals(monthInterval) || e.getSource().equals(yearlyInterval)) {
if(includeExampleExports.isSelected()){
n5ExportTable.updateExampleExportsToTable();
return;
}
n5ExportTable.updateTableData();
}
}

public LocalDateTime oldestTimeAllowed(){
LocalDateTime pastTime = LocalDateTime.now();
if (todayInterval.isSelected()){
pastTime = pastTime.minusDays(1);
} else if (monthInterval.isSelected()) {
pastTime = pastTime.minusMonths(1);
} else if (yearlyInterval.isSelected()) {
pastTime = pastTime.minusYears(1);
} else {
pastTime = pastTime.minusYears(10); //Max date back is 10 years
}
return pastTime;
}

public void allowCancel(boolean allow){
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.vcell.N5.UI.Filters;

import org.vcell.N5.N5ImageHandler;
import org.vcell.N5.UI.MainPanel;
import org.vcell.N5.UI.N5ExportTable;

import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.time.LocalDateTime;
import java.util.Enumeration;


public class TimeFilter extends JPanel implements ActionListener {
private final JCheckBox todayInterval;
private final JCheckBox monthInterval;
private final JCheckBox yearlyInterval;
private final JCheckBox anyInterval;
private final JPanel timeFilter;
private final JCheckBox includeExampleExports;

private final N5ExportTable n5ExportTable;


public TimeFilter(){
includeExampleExports = new JCheckBox("Show Example Exports");
includeExampleExports.setSelected(!N5ImageHandler.exportedDataExists());
n5ExportTable = MainPanel.n5ExportTable;

todayInterval = new JCheckBox("Past 24 Hours");
monthInterval = new JCheckBox("Past Month");
yearlyInterval = new JCheckBox("Past Year");
anyInterval = new JCheckBox("Any Time");
anyInterval.setSelected(true);

ButtonGroup buttonGroup = new ButtonGroup();
buttonGroup.add(todayInterval);
buttonGroup.add(monthInterval);
buttonGroup.add(yearlyInterval);
buttonGroup.add(anyInterval);

this.setLayout(new BorderLayout());
timeFilter = new JPanel(new GridBagLayout());
timeFilter.add(anyInterval);
timeFilter.add(todayInterval);
timeFilter.add(monthInterval);
timeFilter.add(yearlyInterval);
// timeFilter.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Time "));
this.add(timeFilter, BorderLayout.NORTH);
this.add(includeExampleExports, BorderLayout.SOUTH);
Border lowerEtchedBorder = BorderFactory.createEtchedBorder(EtchedBorder.LOWERED);
this.setBorder(BorderFactory.createTitledBorder(lowerEtchedBorder, " Filters "));

Enumeration<AbstractButton> b = buttonGroup.getElements();
while (b.hasMoreElements()){
b.nextElement().addActionListener(this);
}
includeExampleExports.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(anyInterval) || e.getSource().equals(todayInterval)
|| e.getSource().equals(monthInterval) || e.getSource().equals(yearlyInterval)) {
if(includeExampleExports.isSelected()){
n5ExportTable.updateExampleExportsToTable();
return;
}
n5ExportTable.updateTableData();
} else if (e.getSource().equals(includeExampleExports)){
if(includeExampleExports.isSelected()){
n5ExportTable.updateExampleExportsToTable();
return;
}
n5ExportTable.updateTableData();
}
}

public LocalDateTime oldestTimeAllowed(){
LocalDateTime pastTime = LocalDateTime.now();
if (todayInterval.isSelected()){
pastTime = pastTime.minusDays(1);
} else if (monthInterval.isSelected()) {
pastTime = pastTime.minusMonths(1);
} else if (yearlyInterval.isSelected()) {
pastTime = pastTime.minusYears(1);
} else {
pastTime = pastTime.minusYears(10); //Max date back is 10 years
}
return pastTime;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.vcell.N5.UI;

import org.vcell.N5.UI.Filters.TimeFilter;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableColumn;
Expand All @@ -11,21 +13,26 @@ public class MainPanel {
private final int paneWidth = 800;

public final static ControlButtonsPanel controlButtonsPanel = new ControlButtonsPanel();
public final N5ExportTable n5ExportTable = new N5ExportTable();
public final static N5ExportTable n5ExportTable = new N5ExportTable();
public final ExportDetailsPanel exportDetailsPanel = new ExportDetailsPanel();
public final RemoteFileSelection remoteFileSelection = new RemoteFileSelection();
public final TimeFilter timeFilter = new TimeFilter();


public MainPanel(){
JPanel parentPanel = new JPanel();


n5ExportTable.initialize(controlButtonsPanel, exportDetailsPanel);
n5ExportTable.initialize(controlButtonsPanel, exportDetailsPanel, timeFilter);
controlButtonsPanel.initialize(n5ExportTable, remoteFileSelection);

JPanel bottomPortion = new JPanel(new BorderLayout());
bottomPortion.add(timeFilter, BorderLayout.NORTH);
bottomPortion.add(exportDetailsPanel, BorderLayout.SOUTH);

parentPanel.setLayout(new BorderLayout());
parentPanel.add(controlButtonsPanel, BorderLayout.NORTH);
JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, n5ExportTable, exportDetailsPanel);
JSplitPane jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, n5ExportTable, bottomPortion);
jSplitPane.setContinuousLayout(true);
parentPanel.add(jSplitPane, BorderLayout.CENTER);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.scijava.log.Logger;
import org.vcell.N5.ExportDataRepresentation;
import org.vcell.N5.N5ImageHandler;
import org.vcell.N5.UI.Filters.TimeFilter;
import org.vcell.N5.retrieving.SimLoadingListener;
import org.vcell.N5.retrieving.SimResultsLoader;

Expand Down Expand Up @@ -33,15 +34,18 @@ public class N5ExportTable extends JScrollPane implements ListSelectionListener,

private ControlButtonsPanel controlPanel;
private ExportDetailsPanel exportDetailsPanel;
private TimeFilter timeFilter;


private final Logger logger = N5ImageHandler.getLogger(N5ExportTable.class);

public N5ExportTable(){}

public void initialize(ControlButtonsPanel controlButtonsPanel, ExportDetailsPanel exportDetailsPanel){
public void initialize(ControlButtonsPanel controlButtonsPanel, ExportDetailsPanel exportDetailsPanel,
TimeFilter timeFilter){
this.controlPanel = controlButtonsPanel;
this.exportDetailsPanel = exportDetailsPanel;
this.timeFilter = timeFilter;
N5ImageHandler.loadingManager.addSimLoadingListener(this);
n5ExportTableModel = new N5ExportTableModel();
exportListTable = new JTable(n5ExportTableModel);
Expand Down Expand Up @@ -81,12 +85,12 @@ public Component getTableCellRendererComponent(JTable table, Object value, boole
automaticRefresh();
}

void updateTableData(){
public void updateTableData(){
// when initializing it is null
if (controlPanel == null){
updateTableData(LocalDateTime.now().minusYears(10));
} else {
updateTableData(controlPanel.oldestTimeAllowed());
updateTableData(timeFilter.oldestTimeAllowed());
}
}

Expand All @@ -111,12 +115,12 @@ void updateTableData(LocalDateTime oldestTimeAllowed){
}
}

void updateExampleExportsToTable(){
public void updateExampleExportsToTable(){
// when initializing it is null
if (controlPanel == null){
updateExampleExportsToTable(LocalDateTime.now().minusYears(10));
} else {
updateExampleExportsToTable(controlPanel.oldestTimeAllowed());
updateExampleExportsToTable(timeFilter.oldestTimeAllowed());
}
}

Expand Down Expand Up @@ -155,7 +159,7 @@ private void automaticRefresh(){
|| !formatExportData.simulationDataMap.containsKey(mostRecentTableEntry.jobID))){
break;
}
isUpdated = n5ExportTableModel.prependRowData(formatExportData.simulationDataMap.get(currentJob), controlPanel.oldestTimeAllowed());
isUpdated = n5ExportTableModel.prependRowData(formatExportData.simulationDataMap.get(currentJob), timeFilter.oldestTimeAllowed());
}
if(isUpdated){
n5ExportTableModel.fireTableDataChanged();
Expand Down

0 comments on commit 912e033

Please sign in to comment.