Skip to content

Commit

Permalink
This branch addresses Issues #381, #382.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpyat2 committed Nov 18, 2023
1 parent 2f5c4b5 commit e82819f
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -74,6 +72,8 @@ public class PeriodAnalysis2DChartPane extends JPanel implements
private Listener<PeriodAnalysisSelectionMessage> periodAnalysisSelectionListener;
private Listener<PeriodAnalysisRefinementMessage> periodAnalysisRefinementListener;
private Listener<HarmonicSearchResultMessage> harmonicSearchListener;

private String chartPaneID = null;

/**
* Constructor
Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -252,6 +261,8 @@ protected Listener<PeriodAnalysisSelectionMessage> createPeriodAnalysisListener(
return new Listener<PeriodAnalysisSelectionMessage>() {
@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());
Expand All @@ -276,6 +287,8 @@ private Listener<PeriodAnalysisRefinementMessage> createRefinementListener() {
return new Listener<PeriodAnalysisRefinementMessage>() {
@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() ==
Expand All @@ -302,7 +315,12 @@ private Listener<HarmonicSearchResultMessage> createHarmonicSearchListener() {
return new Listener<HarmonicSearchResultMessage>() {
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ private JTabbedPane createTabs() {
plotPanes = new ArrayList<PeriodAnalysis2DChartPane>();

// Add plots.
int n = 0;
for (PeriodAnalysis2DPlotModel model : plotModels) {
boolean permitlogarithmic = model.getRangeType() == PeriodAnalysisCoordinateType.POWER;

Expand Down Expand Up @@ -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.
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -239,6 +244,8 @@ protected void findHarmonicsButtonAction() {
private Listener<PeriodAnalysisSelectionMessage> createPeriodAnalysisListener() {
return new Listener<PeriodAnalysisSelectionMessage>() {
public void update(PeriodAnalysisSelectionMessage info) {
if (!Mediator.isMsgForDialog(PeriodAnalysis2DResultDialog.this, info))
return;
setNewPhasePlotButtonState(true);
setFindHarmonicsButtonState(true);
selectedDataPoint = info.getDataPoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public class PeriodAnalysisDataTablePane extends JPanel implements ListSelection
protected Listener<HarmonicSearchResultMessage> harmonicSearchResultListener;
protected Listener<PeriodAnalysisSelectionMessage> periodAnalysisSelectionListener;

private boolean valueChangedDisabled = false;

/**
* Constructor
*
Expand Down Expand Up @@ -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();

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -202,6 +208,8 @@ protected Listener<HarmonicSearchResultMessage> createHarmonicSearchResultListen
return new Listener<HarmonicSearchResultMessage>() {
@Override
public void update(HarmonicSearchResultMessage info) {
if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysisDataTablePane.this), info))
return;
freqToHarmonicsMap.put(info.getDataPoint().getFrequency(), info.getHarmonics());
}

Expand All @@ -222,6 +230,8 @@ protected Listener<PeriodAnalysisSelectionMessage> createPeriodAnalysisListener(
return new Listener<PeriodAnalysisSelectionMessage>() {
@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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public class PeriodAnalysisTopHitsTablePane extends PeriodAnalysisDataTablePane
private JButton refineButton;

private Listener<PeriodAnalysisRefinementMessage> periodAnalysisRefinementListener;

private boolean valueChangedDisabled = false;

/**
* Constructor.
Expand Down Expand Up @@ -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);
Expand All @@ -197,6 +199,8 @@ protected Listener<PeriodAnalysisSelectionMessage> createPeriodAnalysisListener(
return new Listener<PeriodAnalysisSelectionMessage>() {
@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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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?
Expand All @@ -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);
}
Expand All @@ -282,6 +295,8 @@ private Listener<PeriodAnalysisRefinementMessage> createRefinementListener() {
return new Listener<PeriodAnalysisRefinementMessage>() {
@Override
public void update(PeriodAnalysisRefinementMessage info) {
if (!Mediator.isMsgForDialog(Mediator.getParentDialog(PeriodAnalysisTopHitsTablePane.this), info))
return;
resultantDataPoints.addAll(info.getNewTopHits());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -173,6 +174,8 @@ protected Listener<PeriodAnalysisSelectionMessage> createPeriodAnalysisListener(
return new Listener<PeriodAnalysisSelectionMessage>() {
@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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -163,6 +164,8 @@ protected Listener<PeriodAnalysisSelectionMessage> createPeriodAnalysisListener(
return new Listener<PeriodAnalysisSelectionMessage>() {
@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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -196,6 +197,7 @@ protected void findHarmonicsButtonAction() {
.getFrequency());
HarmonicSearchResultMessage msg = new HarmonicSearchResultMessage(this,
harmonics, selectedDataPoint);
msg.setName(this.getName());
Mediator.getInstance().getHarmonicSearchNotifier().notifyListeners(msg);
}

Expand Down Expand Up @@ -227,6 +229,8 @@ protected List<Harmonic> findHarmonicsFromWWZStats(double freq) {
private Listener<PeriodAnalysisSelectionMessage> createPeriodAnalysisListener() {
return new Listener<PeriodAnalysisSelectionMessage>() {
public void update(PeriodAnalysisSelectionMessage info) {
if (!Mediator.isMsgForDialog(Mediator.getParentDialog(WeightedWaveletZTransformResultDialog.this), info))
return;
setNewPhasePlotButtonState(true);
selectedDataPoint = info.getDataPoint();
}
Expand Down
27 changes: 27 additions & 0 deletions src/org/aavso/tools/vstar/ui/mediator/Mediator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

}
10 changes: 10 additions & 0 deletions src/org/aavso/tools/vstar/ui/mediator/message/MessageBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
*/
public class MessageBase {

private String name;

protected Object source;

public MessageBase(Object source) {
Expand All @@ -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;
}
}

0 comments on commit e82819f

Please sign in to comment.