Skip to content

Commit

Permalink
Merge pull request #406 from AAVSO/issue-405-custom-axis-titles
Browse files Browse the repository at this point in the history
Issue 405 custom axis titles
  • Loading branch information
dbenn authored Mar 3, 2024
2 parents 73724dc + 3b29d36 commit 93b0d9b
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 16 deletions.
Binary file modified plugin/doc/FlexibleTextFileFormat Plug-In.docx
Binary file not shown.
Binary file modified plugin/doc/FlexibleTextFileFormat Plug-In.odt
Binary file not shown.
Binary file modified plugin/doc/FlexibleTextFileFormat Plug-In.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
// This pligin reads text files having the following format:
//
// #NAME=(object name). May appear in any line.
// #TITLEX=(axis title). May appear in any line.
// #TITLEY=(axis title). May appear in any line.
// #DATE=(date column type: JD or HJD or BJD, default: JD). May appear before observations only.
// #DELIM=(delimiter, default: comma). May appear in any line (i.e. to change delimiter)
// #FILTER=(default value, if not specified in FILTER column). May appear in any line (i.e. to change filter)
Expand Down Expand Up @@ -216,6 +218,8 @@ class FlexibleTextFileFormatRetriever extends AbstractObservationRetriever {
private String defFilter = "";
private String defObsCode = "";
private String filterVeLa = "";
private String titleX = "";
private String titleY = "";
private double magShift = 0.0;
private double dateAdd = 0.0;
private boolean ignoreValidationErrors = false;
Expand Down Expand Up @@ -495,6 +499,10 @@ else if ("Y".equalsIgnoreCase(pair[1]))
initFieldMap(pair[1].toUpperCase());
if (timeColumn < 0 || magColumn < 0)
return "#FIELDS directive must specify at least Time and Mag fields!";
} else if ("#TITLEX".equals(pair[0])) {
titleX = pair[1];
} else if ("#TITLEY".equals(pair[0])) {
titleY = pair[1];
}

}
Expand Down Expand Up @@ -849,7 +857,7 @@ public String getSourceName() {

@Override
public String getSourceType() {
return "Flexible Text Format File V1.0";
return "Flexible Text Format File V1.1";
}

@Override
Expand All @@ -863,6 +871,16 @@ public StarInfo getStarInfo() {

return new StarInfo(this, name);
}

@Override
public String getDomainTitle() {
return titleX;
}

@Override
public String getRangeTitle() {
return titleY;
}

private boolean isEmpty(String str) {
return str != null && "".equals(str.trim());
Expand Down
84 changes: 78 additions & 6 deletions plugin/src/org/aavso/tools/vstar/external/plugin/VeLaObSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import org.aavso.tools.vstar.ui.dialog.IntegerField;
import org.aavso.tools.vstar.ui.dialog.MessageBox;
import org.aavso.tools.vstar.ui.dialog.NumberFieldBase;
import org.aavso.tools.vstar.ui.dialog.TextField;
import org.aavso.tools.vstar.ui.mediator.StarInfo;
import org.aavso.tools.vstar.util.Pair;
import org.aavso.tools.vstar.util.help.Help;
Expand Down Expand Up @@ -108,6 +109,9 @@ public class VeLaObSource extends ObservationSourcePluginBase {
private int points = 0;
private JDflavour jDflavour = JDflavour.UNKNOWN;
private String veLaCode = null;
private String titleX = null;
private String titleY = null;
private String objectName = null;

private static ParameterDialog paramDialog;

Expand Down Expand Up @@ -157,10 +161,16 @@ public AbstractObservationRetriever getObservationRetriever() {
points = paramDialog.getPoints();
jDflavour = paramDialog.getJDflavour();
veLaCode = paramDialog.getCode();
titleX = paramDialog.getTitleX();
titleY = paramDialog.getTitleY();
objectName = paramDialog.getObjectName();

isAdditive = paramDialog.isAdditive();

inputName = OBJ_NAME;
if (objectName == null || "".equals(objectName.trim()))
inputName = OBJ_NAME;
else
inputName = objectName;

seriesNameAndDescription = getSeriesNameAndDescription();

Expand Down Expand Up @@ -318,17 +328,24 @@ public String getSourceType() {

@Override
public StarInfo getStarInfo() {
String name = OBJ_NAME;
if (name == null || "".equals(name)) {
name = getSourceName();
}
String name = getSourceName();
return new StarInfo(this, name);
}

@Override
public Integer getNumberOfRecords() throws ObservationReadError {
return points;
}

@Override
public String getDomainTitle() {
return titleX;
}

@Override
public String getRangeTitle() {
return titleY;
}

}

Expand All @@ -343,6 +360,9 @@ private class ParameterDialog extends AbstractOkCancelDialog {
private JComboBox<String> jDflavour;
private JTextArea codeArea;
private JCheckBox addToCurrent;
private TextField titleXfield;
private TextField titleYfield;
private TextField objectNameField;
private JButton clearButton;
private JButton testButton;
private JButton loadButton;
Expand All @@ -368,6 +388,18 @@ public String getCode() {
return codeArea.getText();
}

public String getTitleX() {
return titleXfield.getValue();
}

public String getTitleY() {
return titleYfield.getValue();
}

public String getObjectName() {
return objectNameField.getValue();
}

public JDflavour getJDflavour() {
switch (jDflavour.getSelectedIndex()) {
case 0: return JDflavour.JD;
Expand Down Expand Up @@ -423,6 +455,8 @@ public ParameterDialog() {
topPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

topPane.add(createControlPane());
topPane.add(createControlPane2());

topPane.add(createCodePane());
//topPane.add(createFileControlPane());

Expand Down Expand Up @@ -475,6 +509,24 @@ private JPanel createControlPane() {
return panel;
}

private JPanel createControlPane2() {
JPanel panel = new JPanel(new FlowLayout());

titleXfield = new TextField("Domain Axis Title");
((JTextField)(titleXfield.getUIComponent())).setColumns(30);
panel.add(titleXfield.getUIComponent());

titleYfield = new TextField("Range Axis Title");
((JTextField)(titleYfield.getUIComponent())).setColumns(30);
panel.add(titleYfield.getUIComponent());

objectNameField = new TextField("Object Name");
((JTextField)(objectNameField.getUIComponent())).setColumns(30);
panel.add(objectNameField.getUIComponent());

return panel;
}

private JPanel createCodePane() {
JPanel panel = new JPanel();
panel.setLayout((LayoutManager) new BoxLayout(panel, BoxLayout.PAGE_AXIS));
Expand Down Expand Up @@ -575,6 +627,9 @@ private void clearInput() {
points.setValue(null);
jDflavour.setSelectedIndex(dateTypeToSelectedIndex("HJD"));
codeArea.setText("");
titleXfield.setValue("");
titleYfield.setValue("");
objectNameField.setValue("");
}

private void testInput() {
Expand All @@ -596,7 +651,9 @@ private void testInput() {
" - 0.004698206584795 * cos(2*PI*(5/period)*(t-zeroPoint)) - 0.000039671630067 * sin(2*PI*(4/period)*(t-zeroPoint))\n" +
" + 0.003549883073703 * cos(2*PI*(6/period)*(t-zeroPoint)) + 0.000022578051393 * sin(2*PI*(6/period)*(t-zeroPoint))\n" +
"}\n");

titleXfield.setValue("");
titleYfield.setValue("");
objectNameField.setValue("");
}

private void readVelaXML() {
Expand Down Expand Up @@ -649,6 +706,9 @@ private void processXMLbytes(byte[] xml) throws Exception {
((JTextField)(maxJD.getUIComponent())).setText(getNodeTextContent(element, "maxJD"));
((JTextField)(points.getUIComponent())).setText(getNodeTextContent(element, "points"));
jDflavour.setSelectedIndex(dateTypeToSelectedIndex(getNodeTextContent(element, "datetype")));
((JTextField)(titleXfield.getUIComponent())).setText(getNodeTextContent(element, "domainTitle"));
((JTextField)(titleYfield.getUIComponent())).setText(getNodeTextContent(element, "rangeTitle"));
((JTextField)(objectNameField.getUIComponent())).setText(getNodeTextContent(element, "objectName"));
} else {
throw new Exception("The document root is not VELA_MODEL");
}
Expand Down Expand Up @@ -712,6 +772,18 @@ private Document getVelaXML() throws ParserConfigurationException {
element.appendChild(doc.createTextNode(jDflavourToString(getJDflavour())));
root.appendChild(element);

element = doc.createElement("domainTitle");
element.appendChild(doc.createTextNode(titleXfield.getStringValue()));
root.appendChild(element);

element = doc.createElement("rangeTitle");
element.appendChild(doc.createTextNode(titleYfield.getStringValue()));
root.appendChild(element);

element = doc.createElement("objectName");
element.appendChild(doc.createTextNode(objectNameField.getStringValue()));
root.appendChild(element);

element = doc.createElement("code");
element.appendChild(doc.createTextNode(codeArea.getText()));
root.appendChild(element);
Expand Down
18 changes: 18 additions & 0 deletions src/org/aavso/tools/vstar/input/AbstractObservationRetriever.java
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,24 @@ public String getBrightnessUnits() {
return MAGNITUDE;
}

/**
* Returns the custom domain title.
*
* @return The custom domain title.
*/
public String getDomainTitle() {
return null;
}

/**
* Returns the custom range title.
*
* @return The custom range title.
*/
public String getRangeTitle() {
return null;
}

/**
* Set the VeLa filter string.
*
Expand Down
12 changes: 11 additions & 1 deletion src/org/aavso/tools/vstar/ui/mediator/Mediator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1270,8 +1270,15 @@ public void createNewStarObservationArtefacts(NewStarType newStarType, StarInfo
getDocumentManager().addStatsInfo("Confidence Interval",
"Mean error bars denote 95% Confidence Interval (twice Standard Error)");

String plotName;
String designation = starInfo.getDesignation();
// If star's designation starts with '^', do not prefix it with "Light Curve for"
if (designation != null && designation.length() > 0 && "^".equals(designation.substring(0, 1)))
plotName = designation.substring(1);
else
plotName = LocaleProps.get("LIGHT_CURVE") + " " + LocaleProps.get("FOR") + " " + designation;
obsAndMeanChartPane = createObservationAndMeanPlotPane(
LocaleProps.get("LIGHT_CURVE") + " " + LocaleProps.get("FOR") + " " + starInfo.getDesignation(),
plotName,
null, obsAndMeanPlotModel, starInfo.getRetriever());

obsAndMeanPlotModel.getMeansChangeNotifier()
Expand Down Expand Up @@ -1572,6 +1579,9 @@ public AnalysisTypeChangeMessage createPhasePlotArtefacts(double period, double

obsAndMeanPlotModel2.getMeansChangeNotifier().addListener(meanObsTableModel);

// If star's name starts with '^', remove the first char (see "LIGHT_CURVE")
if (objName != null && objName.length() > 0 && "^".equals(objName.substring(0, 1)))
objName = objName.substring(1);
PhaseAndMeanPlotPane obsAndMeanChartPane = createPhaseAndMeanPlotPane(
LocaleProps.get("PHASE_PLOT") + " " + LocaleProps.get("FOR") + " " + objName, subTitle,
obsAndMeanPlotModel1, obsAndMeanPlotModel2, epoch, period,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,15 +492,27 @@ public void chartMouseClicked(ChartMouseEvent event) {
/**
* @return The time axis label.
*/
protected static String getTimeAxisLabel(String units) {
return String.format(LocaleProps.get("TIME"));
protected static String getTimeAxisLabel(AbstractObservationRetriever retriever) {
// Custom axis title
String axis_title;
axis_title = retriever.getDomainTitle();
if (axis_title != null && !"".equals(axis_title))
return axis_title;
else
return String.format(LocaleProps.get("TIME"));
}

/**
* @return The brightness axis label.
*/
protected static String getBrightnessAxisLabel(String units) {
return String.format("%s (%s)", LocaleProps.get("BRIGHTNESS"), units);
protected static String getBrightnessAxisLabel(AbstractObservationRetriever retriever) {
// Custom axis title
String axis_title;
axis_title = retriever.getRangeTitle();
if (axis_title != null && !"".equals(axis_title))
return axis_title;
else
return String.format("%s (%s)", LocaleProps.get("BRIGHTNESS"), retriever.getBrightnessUnits());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ public ObservationAndMeanPlotPane(String title, String subTitle, String domainTi
public ObservationAndMeanPlotPane(String title, String subTitle, ObservationAndMeanPlotModel obsAndMeanModel,
Dimension bounds, AbstractObservationRetriever retriever) {

this(title, subTitle, getTimeAxisLabel(retriever.getTimeUnits()),
getBrightnessAxisLabel(retriever.getBrightnessUnits()), obsAndMeanModel, bounds, retriever);
this(title, subTitle, getTimeAxisLabel(retriever),
getBrightnessAxisLabel(retriever), obsAndMeanModel, bounds, retriever);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,7 @@ public PhaseAndMeanPlotPane(String title, String subTitle,
AbstractObservationRetriever retriever,
PhasedObservationAndMeanPlotModel... obsAndMeanModels) {

super(title, subTitle, PHASE, getBrightnessAxisLabel(retriever
.getBrightnessUnits()), obsAndMeanModels[0], bounds, retriever);
super(title, subTitle, PHASE, getBrightnessAxisLabel(retriever), obsAndMeanModels[0], bounds, retriever);

this.epoch = epoch;
this.period = period;
Expand Down

0 comments on commit 93b0d9b

Please sign in to comment.