Skip to content

Commit

Permalink
#431: fix for out of sync plot control dialog by improved document ma…
Browse files Browse the repository at this point in the history
…nager init/reset
  • Loading branch information
dbenn committed Jun 20, 2024
1 parent e089c61 commit 4b82dcb
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 55 deletions.
136 changes: 83 additions & 53 deletions src/org/aavso/tools/vstar/ui/mediator/DocumentManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,42 +73,7 @@ public class DocumentManager {
public DocumentManager() {
mediator = Mediator.getInstance();

rawDataModelComponents = new HashMap<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();
phasedModelComponents = new HashMap<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();

rawDataResidualComponents = new HashMap<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();
phasedResidualComponents = new HashMap<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();

phasePlotExists = false;
epoch = 0;
period = 0;

showErrorBars = new HashMap<AnalysisType, Boolean>() {{
put(AnalysisType.RAW_DATA, true);
put(AnalysisType.PHASE_PLOT, true);
}};

showCrossHairs = new HashMap<AnalysisType, Boolean>() {{
put(AnalysisType.RAW_DATA, true);
put(AnalysisType.PHASE_PLOT, true);
}};

invertRange = new HashMap<AnalysisType, Boolean>() {{
put(AnalysisType.RAW_DATA, true);
put(AnalysisType.PHASE_PLOT, true);
}};

invertSeriesOrder = new HashMap<AnalysisType, Boolean>() {{
put(AnalysisType.RAW_DATA, true);
put(AnalysisType.PHASE_PLOT, true);
}};

joinMeans = new HashMap<AnalysisType, Boolean>() {{
put(AnalysisType.RAW_DATA, true);
put(AnalysisType.PHASE_PLOT, true);
}};

statsInfo = new TreeMap<String, String>();
init();
}

// ** phase, epoch, period methods **
Expand Down Expand Up @@ -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<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();
}
rawDataModelComponents.clear();

if (phasedModelComponents == null) {
phasedModelComponents = new HashMap<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();
}
phasedModelComponents.clear();

if (rawDataResidualComponents == null) {
rawDataResidualComponents = new HashMap<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();
}
rawDataResidualComponents.clear();

if (phasedResidualComponents == null) {
phasedResidualComponents = new HashMap<String, SyntheticObservationListPane<AbstractModelObservationTableModel>>();
}
phasedResidualComponents.clear();

// Boolean maps
if (showErrorBars == null) {
showErrorBars = new HashMap<AnalysisType, Boolean>();
}
showErrorBars.put(AnalysisType.RAW_DATA, true);
showErrorBars.put(AnalysisType.PHASE_PLOT, true);

if (showCrossHairs == null) {
showCrossHairs = new HashMap<AnalysisType, Boolean>();
}
showCrossHairs.put(AnalysisType.RAW_DATA, true);
showCrossHairs.put(AnalysisType.PHASE_PLOT, true);

if (invertRange == null) {
invertRange = new HashMap<AnalysisType, Boolean>();
}
invertRange.put(AnalysisType.RAW_DATA, true);
invertRange.put(AnalysisType.PHASE_PLOT, true);

if (invertSeriesOrder == null) {
invertSeriesOrder = new HashMap<AnalysisType, Boolean>();
}
invertSeriesOrder.put(AnalysisType.RAW_DATA, true);
invertSeriesOrder.put(AnalysisType.PHASE_PLOT, true);

if (joinMeans == null) {
joinMeans = new HashMap<AnalysisType, Boolean>();
}
joinMeans.put(AnalysisType.RAW_DATA, true);
joinMeans.put(AnalysisType.PHASE_PLOT, true);

// stats info map
if (statsInfo == null) {
statsInfo = new TreeMap<String, String>();
}
statsInfo.clear();
}

/**
* Return a phase change listener that updates epoch and period information
* in preparation for creating or retrieving phase plot components.<br/>
Expand All @@ -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<NewStarMessage> createNewStarListener() {
return new Listener<NewStarMessage>() {
@Override
public void update(NewStarMessage info) {
rawDataModelComponents.clear();
rawDataResidualComponents.clear();
phasedModelComponents.clear();
phasedResidualComponents.clear();
}

@Override
public boolean canBeRemoved() {
return false;
}
};
}
// public Listener<NewStarMessage> createNewStarListener() {
// return new Listener<NewStarMessage>() {
// @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
Expand Down
6 changes: 4 additions & 2 deletions src/org/aavso/tools/vstar/ui/mediator/Mediator.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -1192,6 +1192,8 @@ public void createNewStarObservationArtefacts(NewStarType newStarType, StarInfo
break;
}
}
} else {
getDocumentManager().init();
}

List<ValidObservation> validObsList = starInfo.getRetriever().getValidObservations();
Expand Down

0 comments on commit 4b82dcb

Please sign in to comment.