From 4b82dcbb608bb2a808f0fcf8666d510da1852fbc Mon Sep 17 00:00:00 2001 From: David Benn Date: Fri, 21 Jun 2024 07:44:10 +0930 Subject: [PATCH 1/2] #431: fix for out of sync plot control dialog by improved document manager init/reset --- .../vstar/ui/mediator/DocumentManager.java | 136 +++++++++++------- .../tools/vstar/ui/mediator/Mediator.java | 6 +- 2 files changed, 87 insertions(+), 55 deletions(-) diff --git a/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java b/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java index 486fce70..55d564c0 100644 --- a/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java +++ b/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java @@ -73,42 +73,7 @@ public class DocumentManager { public DocumentManager() { mediator = Mediator.getInstance(); - rawDataModelComponents = new HashMap>(); - phasedModelComponents = new HashMap>(); - - rawDataResidualComponents = new HashMap>(); - phasedResidualComponents = new HashMap>(); - - phasePlotExists = false; - epoch = 0; - period = 0; - - showErrorBars = new HashMap() {{ - put(AnalysisType.RAW_DATA, true); - put(AnalysisType.PHASE_PLOT, true); - }}; - - showCrossHairs = new HashMap() {{ - put(AnalysisType.RAW_DATA, true); - put(AnalysisType.PHASE_PLOT, true); - }}; - - invertRange = new HashMap() {{ - put(AnalysisType.RAW_DATA, true); - put(AnalysisType.PHASE_PLOT, true); - }}; - - invertSeriesOrder = new HashMap() {{ - put(AnalysisType.RAW_DATA, true); - put(AnalysisType.PHASE_PLOT, true); - }}; - - joinMeans = new HashMap() {{ - put(AnalysisType.RAW_DATA, true); - put(AnalysisType.PHASE_PLOT, true); - }}; - - statsInfo = new TreeMap(); + init(); } // ** phase, epoch, period methods ** @@ -348,6 +313,73 @@ private String getPhasedModelKey(IModel model) { period); } + /** + * Initialise (or reset) data members + */ + public void init() { + phasePlotExists = false; + epoch = 0; + period = 0; + + // model maps + if (rawDataModelComponents == null) { + rawDataModelComponents = new HashMap>(); + } + rawDataModelComponents.clear(); + + if (phasedModelComponents == null) { + phasedModelComponents = new HashMap>(); + } + phasedModelComponents.clear(); + + if (rawDataResidualComponents == null) { + rawDataResidualComponents = new HashMap>(); + } + rawDataResidualComponents.clear(); + + if (phasedResidualComponents == null) { + phasedResidualComponents = new HashMap>(); + } + phasedResidualComponents.clear(); + + // Boolean maps + if (showErrorBars == null) { + showErrorBars = new HashMap(); + } + showErrorBars.put(AnalysisType.RAW_DATA, true); + showErrorBars.put(AnalysisType.PHASE_PLOT, true); + + if (showCrossHairs == null) { + showCrossHairs = new HashMap(); + } + showCrossHairs.put(AnalysisType.RAW_DATA, true); + showCrossHairs.put(AnalysisType.PHASE_PLOT, true); + + if (invertRange == null) { + invertRange = new HashMap(); + } + invertRange.put(AnalysisType.RAW_DATA, true); + invertRange.put(AnalysisType.PHASE_PLOT, true); + + if (invertSeriesOrder == null) { + invertSeriesOrder = new HashMap(); + } + invertSeriesOrder.put(AnalysisType.RAW_DATA, true); + invertSeriesOrder.put(AnalysisType.PHASE_PLOT, true); + + if (joinMeans == null) { + joinMeans = new HashMap(); + } + joinMeans.put(AnalysisType.RAW_DATA, true); + joinMeans.put(AnalysisType.PHASE_PLOT, true); + + // stats info map + if (statsInfo == null) { + statsInfo = new TreeMap(); + } + statsInfo.clear(); + } + /** * Return a phase change listener that updates epoch and period information * in preparation for creating or retrieving phase plot components.
@@ -372,24 +404,22 @@ public boolean canBeRemoved() { } /** - * Return a new star listener that clears the maps. + * Return a new star listener that initialises the maps. + * TODO: prob don't need this now! */ - public Listener createNewStarListener() { - return new Listener() { - @Override - public void update(NewStarMessage info) { - rawDataModelComponents.clear(); - rawDataResidualComponents.clear(); - phasedModelComponents.clear(); - phasedResidualComponents.clear(); - } - - @Override - public boolean canBeRemoved() { - return false; - } - }; - } +// public Listener createNewStarListener() { +// return new Listener() { +// @Override +// public void update(NewStarMessage info) { +// init(); +// } +// +// @Override +// public boolean canBeRemoved() { +// return false; +// } +// }; +// } /** * Find and return the active window or null if one does not exist, e.g. the diff --git a/src/org/aavso/tools/vstar/ui/mediator/Mediator.java b/src/org/aavso/tools/vstar/ui/mediator/Mediator.java index a3510e1a..6ad769fb 100644 --- a/src/org/aavso/tools/vstar/ui/mediator/Mediator.java +++ b/src/org/aavso/tools/vstar/ui/mediator/Mediator.java @@ -956,7 +956,7 @@ public DocumentManager getDocumentManager() { if (documentManager == null) { documentManager = new DocumentManager(); phaseChangeNotifier.addListener(documentManager.createPhaseChangeListener(), true); - newStarNotifier.addListener(documentManager.createNewStarListener(), true); +// newStarNotifier.addListener(documentManager.createNewStarListener(), true); } return documentManager; @@ -1174,7 +1174,7 @@ public void createNewStarObservationArtefacts(NewStarType newStarType, StarInfo // table and plot models, along with corresponding GUI components. // Handle additive load if requested and observations are already - // loaded. + // loaded, otherwise, initialise the document manager. if (addObs && getLatestNewStarMessage() != null) { // convertObsToHJD(starInfo); @@ -1192,6 +1192,8 @@ public void createNewStarObservationArtefacts(NewStarType newStarType, StarInfo break; } } + } else { + getDocumentManager().init(); } List validObsList = starInfo.getRetriever().getValidObservations(); From e865cc7e80e2484f36dc93ba2bfdc686c14a6fdc Mon Sep 17 00:00:00 2001 From: David Benn Date: Fri, 21 Jun 2024 17:59:15 +0930 Subject: [PATCH 2/2] #431: removed unused code --- .../vstar/ui/mediator/DocumentManager.java | 18 ------------------ .../tools/vstar/ui/mediator/Mediator.java | 1 - 2 files changed, 19 deletions(-) diff --git a/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java b/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java index 55d564c0..56c9d51f 100644 --- a/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java +++ b/src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java @@ -403,24 +403,6 @@ public boolean canBeRemoved() { }; } - /** - * Return a new star listener that initialises the maps. - * TODO: prob don't need this now! - */ -// public Listener createNewStarListener() { -// return new Listener() { -// @Override -// public void update(NewStarMessage info) { -// init(); -// } -// -// @Override -// public boolean canBeRemoved() { -// return false; -// } -// }; -// } - /** * Find and return the active window or null if one does not exist, e.g. the * case where the UI is that of an applet. diff --git a/src/org/aavso/tools/vstar/ui/mediator/Mediator.java b/src/org/aavso/tools/vstar/ui/mediator/Mediator.java index 6ad769fb..5fa90c09 100644 --- a/src/org/aavso/tools/vstar/ui/mediator/Mediator.java +++ b/src/org/aavso/tools/vstar/ui/mediator/Mediator.java @@ -956,7 +956,6 @@ public DocumentManager getDocumentManager() { if (documentManager == null) { documentManager = new DocumentManager(); phaseChangeNotifier.addListener(documentManager.createPhaseChangeListener(), true); -// newStarNotifier.addListener(documentManager.createNewStarListener(), true); } return documentManager;