From e82819ffff58c06bd7a664ac3014025747801577 Mon Sep 17 00:00:00 2001 From: mpyat2 Date: Sat, 18 Nov 2023 18:30:13 +0200 Subject: [PATCH] This branch addresses Issues #381, #382. --- .../period/PeriodAnalysis2DChartPane.java | 24 ++++++++++++++--- .../period/PeriodAnalysis2DResultDialog.java | 7 +++++ .../period/PeriodAnalysisDataTablePane.java | 17 +++++++++++- .../PeriodAnalysisTopHitsTablePane.java | 19 +++++++++++-- .../dialog/period/wwz/WWZDataTablePane.java | 3 +++ .../ui/dialog/period/wwz/WWZPlotPane.java | 3 +++ ...WeightedWaveletZTransformResultDialog.java | 4 +++ .../tools/vstar/ui/mediator/Mediator.java | 27 +++++++++++++++++++ .../ui/mediator/message/MessageBase.java | 10 +++++++ 9 files changed, 108 insertions(+), 6 deletions(-) diff --git a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DChartPane.java b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DChartPane.java index 76647be61..8d4cfc819 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DChartPane.java +++ b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DChartPane.java @@ -38,8 +38,6 @@ import org.aavso.tools.vstar.util.IStartAndCleanup; import org.aavso.tools.vstar.util.locale.LocaleProps; import org.aavso.tools.vstar.util.notification.Listener; -import org.aavso.tools.vstar.util.period.IPeriodAnalysisDatum; -import org.aavso.tools.vstar.util.period.PeriodAnalysisCoordinateType; import org.aavso.tools.vstar.util.period.dcdft.PeriodAnalysisDataPoint; import org.jfree.chart.ChartMouseEvent; import org.jfree.chart.ChartMouseListener; @@ -74,6 +72,8 @@ public class PeriodAnalysis2DChartPane extends JPanel implements private Listener periodAnalysisSelectionListener; private Listener periodAnalysisRefinementListener; private Listener harmonicSearchListener; + + private String chartPaneID = null; /** * Constructor @@ -113,6 +113,14 @@ public Dimension getPreferredSize() { return new Dimension(DEFAULT_CHART_PANEL_WIDTH, DEFAULT_CHART_PANEL_HEIGHT); } + public void setChartPaneID(String chartPaneID) { + this.chartPaneID = chartPaneID; + } + + public String getChartPaneID() { + return chartPaneID; + } + /** * @return the chart */ @@ -204,6 +212,7 @@ public void chartMouseClicked(ChartMouseEvent event) { PeriodAnalysisSelectionMessage message = new PeriodAnalysisSelectionMessage( this, dataPoint, item); if (message != null) { + message.setName(Mediator.getParentDialogName(this)); Mediator.getInstance().getPeriodAnalysisSelectionNotifier() .notifyListeners(message); } @@ -252,6 +261,8 @@ protected Listener createPeriodAnalysisListener( return new Listener() { @Override public void update(PeriodAnalysisSelectionMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysis2DChartPane.this), info)) + return; if (info.getSource() != parent) { double x = info.getDataPoint().getValue(model.getDomainType()); double y = info.getDataPoint().getValue(model.getRangeType()); @@ -276,6 +287,8 @@ private Listener createRefinementListener() { return new Listener() { @Override public void update(PeriodAnalysisRefinementMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysis2DChartPane.this), info)) + return; chart.getXYPlot().clearAnnotations(); for (PeriodAnalysisDataPoint dataPoint : info.getNewTopHits()) { // if (model.getRangeType() == @@ -302,7 +315,12 @@ private Listener createHarmonicSearchListener() { return new Listener() { @Override public void update(HarmonicSearchResultMessage info) { - new HarmonicInfoDialog(info, pane); + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysis2DChartPane.this), info)) + return; + String id = PeriodAnalysis2DChartPane.this.getChartPaneID(); + if (id != null && id.equals("PlotPane0")) { + new HarmonicInfoDialog(info, pane); + } } @Override diff --git a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DResultDialog.java b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DResultDialog.java index 239a870bb..54757bb54 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DResultDialog.java +++ b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DResultDialog.java @@ -159,6 +159,7 @@ private JTabbedPane createTabs() { plotPanes = new ArrayList(); // Add plots. + int n = 0; for (PeriodAnalysis2DPlotModel model : plotModels) { boolean permitlogarithmic = model.getRangeType() == PeriodAnalysisCoordinateType.POWER; @@ -193,7 +194,9 @@ private JTabbedPane createTabs() { + model.getDomainType(); namedComponents.add(new NamedComponent(tabName, plot)); + plot.setChartPaneID("PlotPane" + Integer.toString(n)); plotPanes.add(plot); + n += 1; } // Add data table view. @@ -219,6 +222,7 @@ private JTabbedPane createTabs() { protected void newPhasePlotButtonAction() { PeriodChangeMessage message = new PeriodChangeMessage(this, selectedDataPoint.getPeriod()); + message.setName(this.getName()); Mediator.getInstance().getPeriodChangeNotifier() .notifyListeners(message); } @@ -231,6 +235,7 @@ protected void findHarmonicsButtonAction() { selectedDataPoint.getFrequency(), data); HarmonicSearchResultMessage msg = new HarmonicSearchResultMessage(this, harmonics, selectedDataPoint); + msg.setName(this.getName()); Mediator.getInstance().getHarmonicSearchNotifier().notifyListeners(msg); } @@ -239,6 +244,8 @@ protected void findHarmonicsButtonAction() { private Listener createPeriodAnalysisListener() { return new Listener() { public void update(PeriodAnalysisSelectionMessage info) { + if (!Mediator.isMsgForDialog(PeriodAnalysis2DResultDialog.this, info)) + return; setNewPhasePlotButtonState(true); setFindHarmonicsButtonState(true); selectedDataPoint = info.getDataPoint(); diff --git a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisDataTablePane.java b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisDataTablePane.java index e86bbcc21..5e6689395 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisDataTablePane.java +++ b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisDataTablePane.java @@ -73,6 +73,8 @@ public class PeriodAnalysisDataTablePane extends JPanel implements ListSelection protected Listener harmonicSearchResultListener; protected Listener periodAnalysisSelectionListener; + private boolean valueChangedDisabled = false; + /** * Constructor * @@ -143,6 +145,9 @@ protected JPanel createButtonPanel() { * has "settled". This event could be consumed by other views such as plots. */ public void valueChanged(ListSelectionEvent e) { + if (valueChangedDisabled) + return; + if (e.getSource() == table.getSelectionModel() && table.getRowSelectionAllowed() && !e.getValueIsAdjusting()) { int row = table.getSelectedRow(); @@ -151,6 +156,7 @@ public void valueChanged(ListSelectionEvent e) { PeriodAnalysisSelectionMessage message = new PeriodAnalysisSelectionMessage(this, model.getDataPointFromRow(row), row); + message.setName(Mediator.getParentDialogName(this)); Mediator.getInstance().getPeriodAnalysisSelectionNotifier().notifyListeners(message); } } @@ -202,6 +208,8 @@ protected Listener createHarmonicSearchResultListen return new Listener() { @Override public void update(HarmonicSearchResultMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysisDataTablePane.this), info)) + return; freqToHarmonicsMap.put(info.getDataPoint().getFrequency(), info.getHarmonics()); } @@ -222,6 +230,8 @@ protected Listener createPeriodAnalysisListener( return new Listener() { @Override public void update(PeriodAnalysisSelectionMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysisDataTablePane.this), info)) + return; if (info.getSource() != parent) { // Find data point in table. int row = -1; @@ -251,7 +261,12 @@ public void update(PeriodAnalysisSelectionMessage info) { int rowHeight = table.getRowHeight(row); table.scrollRectToVisible(new Rectangle(colWidth, rowHeight * row, colWidth, rowHeight)); - table.setRowSelectionInterval(row, row); + valueChangedDisabled = true; + try { + table.setRowSelectionInterval(row, row); + } finally { + valueChangedDisabled = false; + } enableButtons(); } } else { diff --git a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisTopHitsTablePane.java b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisTopHitsTablePane.java index a6ad3f3d5..f1d844c31 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisTopHitsTablePane.java +++ b/src/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysisTopHitsTablePane.java @@ -58,6 +58,8 @@ public class PeriodAnalysisTopHitsTablePane extends PeriodAnalysisDataTablePane private JButton refineButton; private Listener periodAnalysisRefinementListener; + + private boolean valueChangedDisabled = false; /** * Constructor. @@ -170,7 +172,7 @@ public void actionPerformed(ActionEvent e) { PeriodAnalysisRefinementMessage msg = new PeriodAnalysisRefinementMessage( this, data, topHits, newTopHits); - + msg.setName(Mediator.getParentDialogName(PeriodAnalysisTopHitsTablePane.this)); Mediator.getInstance() .getPeriodAnalysisRefinementNotifier() .notifyListeners(msg); @@ -197,6 +199,8 @@ protected Listener createPeriodAnalysisListener( return new Listener() { @Override public void update(PeriodAnalysisSelectionMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysisTopHitsTablePane.this), info)) + return; if (info.getSource() != parent) { // Find data point in top hits table. int row = -1; @@ -229,7 +233,12 @@ public void update(PeriodAnalysisSelectionMessage info) { table.scrollRectToVisible(new Rectangle(colWidth, rowHeight * row, colWidth, rowHeight)); - table.setRowSelectionInterval(row, row); + valueChangedDisabled = true; + try { + table.setRowSelectionInterval(row, row); + } finally { + valueChangedDisabled = false; + } enableButtons(); } } else { @@ -260,6 +269,9 @@ protected void enableButtons() { */ @Override public void valueChanged(ListSelectionEvent e) { + if (valueChangedDisabled) + return; + if (e.getSource() == table.getSelectionModel() && table.getRowSelectionAllowed() && !e.getValueIsAdjusting()) { // Which row in the top hits table was selected? @@ -269,6 +281,7 @@ public void valueChanged(ListSelectionEvent e) { row = table.convertRowIndexToModel(row); PeriodAnalysisSelectionMessage message = new PeriodAnalysisSelectionMessage( this, model.getDataPointFromRow(row), row); + message.setName(Mediator.getParentDialogName(this)); Mediator.getInstance().getPeriodAnalysisSelectionNotifier() .notifyListeners(message); } @@ -282,6 +295,8 @@ private Listener createRefinementListener() { return new Listener() { @Override public void update(PeriodAnalysisRefinementMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysisTopHitsTablePane.this), info)) + return; resultantDataPoints.addAll(info.getNewTopHits()); } diff --git a/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZDataTablePane.java b/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZDataTablePane.java index 16dbc96a7..2c1d43622 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZDataTablePane.java +++ b/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZDataTablePane.java @@ -128,6 +128,7 @@ public void valueChanged(ListSelectionEvent e) { PeriodAnalysisSelectionMessage message = new PeriodAnalysisSelectionMessage( this, model.getDataPointFromRow(row), row); + message.setName(Mediator.getParentDialogName(this)); Mediator.getInstance().getPeriodAnalysisSelectionNotifier() .notifyListeners(message); } @@ -173,6 +174,8 @@ protected Listener createPeriodAnalysisListener( return new Listener() { @Override public void update(PeriodAnalysisSelectionMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(WWZDataTablePane.this), info)) + return; if (info.getSource() != parent) { // Find data point in table. int row = -1; diff --git a/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZPlotPane.java b/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZPlotPane.java index 918c13785..6c89cf2e1 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZPlotPane.java +++ b/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WWZPlotPane.java @@ -139,6 +139,7 @@ public void chartMouseClicked(ChartMouseEvent event) { int item = entity.getItem(); PeriodAnalysisSelectionMessage message = new PeriodAnalysisSelectionMessage( this, model.getStats().get(item), item); + message.setName(Mediator.getParentDialogName(this)); Mediator.getInstance().getPeriodAnalysisSelectionNotifier() .notifyListeners(message); } @@ -163,6 +164,8 @@ protected Listener createPeriodAnalysisListener( return new Listener() { @Override public void update(PeriodAnalysisSelectionMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(WWZPlotPane.this), info)) + return; if (info.getSource() != parent) { // Find the datapoint in the model (could be minimal or full // stats). diff --git a/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WeightedWaveletZTransformResultDialog.java b/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WeightedWaveletZTransformResultDialog.java index 00b46c731..b3fff7c3c 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WeightedWaveletZTransformResultDialog.java +++ b/src/org/aavso/tools/vstar/ui/dialog/period/wwz/WeightedWaveletZTransformResultDialog.java @@ -182,6 +182,7 @@ protected JPanel createButtonPanel() { protected void newPhasePlotButtonAction() { PeriodChangeMessage message = new PeriodChangeMessage(this, selectedDataPoint.getPeriod()); + message.setName(this.getName()); Mediator.getInstance().getPeriodChangeNotifier().notifyListeners( message); } @@ -196,6 +197,7 @@ protected void findHarmonicsButtonAction() { .getFrequency()); HarmonicSearchResultMessage msg = new HarmonicSearchResultMessage(this, harmonics, selectedDataPoint); + msg.setName(this.getName()); Mediator.getInstance().getHarmonicSearchNotifier().notifyListeners(msg); } @@ -227,6 +229,8 @@ protected List findHarmonicsFromWWZStats(double freq) { private Listener createPeriodAnalysisListener() { return new Listener() { public void update(PeriodAnalysisSelectionMessage info) { + if (!Mediator.isMsgForDialog(Mediator.getParentDialog(WeightedWaveletZTransformResultDialog.this), info)) + return; setNewPhasePlotButtonState(true); selectedDataPoint = info.getDataPoint(); } diff --git a/src/org/aavso/tools/vstar/ui/mediator/Mediator.java b/src/org/aavso/tools/vstar/ui/mediator/Mediator.java index ac0b65317..39c096b2c 100644 --- a/src/org/aavso/tools/vstar/ui/mediator/Mediator.java +++ b/src/org/aavso/tools/vstar/ui/mediator/Mediator.java @@ -86,6 +86,7 @@ import org.aavso.tools.vstar.ui.mediator.message.FilteredObservationMessage; import org.aavso.tools.vstar.ui.mediator.message.HarmonicSearchResultMessage; import org.aavso.tools.vstar.ui.mediator.message.MeanSourceSeriesChangeMessage; +import org.aavso.tools.vstar.ui.mediator.message.MessageBase; import org.aavso.tools.vstar.ui.mediator.message.ModelCreationMessage; import org.aavso.tools.vstar.ui.mediator.message.ModelSelectionMessage; import org.aavso.tools.vstar.ui.mediator.message.MultipleObservationSelectionMessage; @@ -2350,5 +2351,31 @@ public void quit() { // defer to Mediator. System.exit(0); } + + public static JDialog getParentDialog(Component c) { + while (c != null) { + if (c instanceof JDialog) { + return (JDialog)c; + } + c = c.getParent(); + } + return null; + } + + public static String getParentDialogName(Component c) { + while (c != null) { + if (c instanceof JDialog) { + return c.getName(); + } + c = c.getParent(); + } + return null; + } + + public static boolean isMsgForDialog(JDialog dlg, MessageBase msg) { + if (dlg == null || msg == null || msg.getName() == null) + return false; + return msg.getName().equals(dlg.getName()); + } } diff --git a/src/org/aavso/tools/vstar/ui/mediator/message/MessageBase.java b/src/org/aavso/tools/vstar/ui/mediator/message/MessageBase.java index 2a7040370..4aaef3e08 100644 --- a/src/org/aavso/tools/vstar/ui/mediator/message/MessageBase.java +++ b/src/org/aavso/tools/vstar/ui/mediator/message/MessageBase.java @@ -22,6 +22,8 @@ */ public class MessageBase { + private String name; + protected Object source; public MessageBase(Object source) { @@ -34,4 +36,12 @@ public MessageBase(Object source) { public Object getSource() { return source; } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } } \ No newline at end of file