Skip to content

Commit

Permalink
Merge pull request #432 from AAVSO/431-plot-control-checkboxes-someti…
Browse files Browse the repository at this point in the history
…mes-go-out-of-sync

431 plot control checkboxes sometimes go out of sync
  • Loading branch information
dbenn authored Jun 24, 2024
2 parents bdd87b4 + e865cc7 commit e85e2c6
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 58 deletions.
124 changes: 68 additions & 56 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 @@ -371,26 +403,6 @@ public boolean canBeRemoved() {
};
}

/**
* Return a new star listener that clears the maps.
*/
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;
}
};
}

/**
* 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.
Expand Down
5 changes: 3 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,6 @@ public DocumentManager getDocumentManager() {
if (documentManager == null) {
documentManager = new DocumentManager();
phaseChangeNotifier.addListener(documentManager.createPhaseChangeListener(), true);
newStarNotifier.addListener(documentManager.createNewStarListener(), true);
}

return documentManager;
Expand Down Expand Up @@ -1174,7 +1173,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 +1191,8 @@ public void createNewStarObservationArtefacts(NewStarType newStarType, StarInfo
break;
}
}
} else {
getDocumentManager().init();
}

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

0 comments on commit e85e2c6

Please sign in to comment.