Skip to content

Commit

Permalink
'Help' implementation for several plug-ins with dialogs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpyat2 committed Nov 11, 2023
1 parent c63f9d0 commit a3ac5d7
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ private Optional<Double> requestTimeTolerance() {
List<ITextComponent<?>> fields = new ArrayList<ITextComponent<?>>();
fields.add(timeToleranceField);

MultiEntryComponentDialog dlg = new MultiEntryComponentDialog("B,V Time Delta", fields,
Optional.of(velaFilterFieldAndPanel.second));
MultiEntryComponentDialog dlg = new MultiEntryComponentDialog("B,V Time Delta", getDocName(),
fields, Optional.of(velaFilterFieldAndPanel.second));

Optional<Double> value = Optional.of(timeToleranceField.getValue());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.aavso.tools.vstar.data.ValidObservation;
import org.aavso.tools.vstar.plugin.ModelCreatorPluginBase;
Expand Down Expand Up @@ -66,7 +67,7 @@ public IModel getModel(List<ValidObservation> obs) {
// Catch all possible errors: getHarmonics() may generate an error if one of frequencies < 0, etc.
IntegerField numPeriodField = new IntegerField("Number of Periods", 0, null, 1);
MultiEntryComponentDialog numPeriodsDialog = new MultiEntryComponentDialog(
"Period Count", numPeriodField);
"Period Count", getDocName(), numPeriodField);

if (!numPeriodsDialog.isCancelled()) {
int numPeriods = numPeriodField.getValue();
Expand All @@ -80,7 +81,7 @@ public IModel getModel(List<ValidObservation> obs) {

HarmonicInputDialog dialog = new HarmonicInputDialog(
DocumentManager.findActiveWindow(), userSelectedFreqs,
freqToHarmonicsMap);
freqToHarmonicsMap, getDocName());

if (!dialog.isCancelled()) {
List<Harmonic> harmonics = dialog.getHarmonics();
Expand Down
84 changes: 84 additions & 0 deletions plugin/src/org/aavso/tools/vstar/external/plugin/HJDConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@
*/
package org.aavso.tools.vstar.external.plugin;

import java.awt.Container;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;

import org.aavso.tools.vstar.data.ValidObservation;
import org.aavso.tools.vstar.data.ValidObservation.JDflavour;
import org.aavso.tools.vstar.plugin.ObservationToolPluginBase;
import org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog;
import org.aavso.tools.vstar.ui.dialog.MessageBox;
import org.aavso.tools.vstar.ui.mediator.AnalysisType;
import org.aavso.tools.vstar.ui.mediator.Mediator;
Expand Down Expand Up @@ -78,8 +87,12 @@ public void invoke(ISeriesInfoProvider seriesInfo) {
"No observations with Julian Date");
return;
}
/*
if (!MessageBox.showConfirmDialog("Non-Heliocentric Observations", count + " Julian Date observations found. Convert them to HJD?"))
return;
*/
if (!showConfirmDialog2("Non-Heliocentric Observations", count + " Julian Date observations found. Convert them to HJD?", getDocName()))
return;
Pair<RAInfo, DecInfo> coords = getCoordinates(msg.getStarInfo());
if (coords != null) {
count = Mediator.getInstance().convertObsToHJD(obs, coords.first, coords.second);
Expand All @@ -100,6 +113,77 @@ public void invoke(ISeriesInfoProvider seriesInfo) {
}
}

private boolean showConfirmDialog2(String title, String msg, String helpTopic) {
ConfirmDialogWithHelp dlg = new ConfirmDialogWithHelp(title, msg, helpTopic);
return !dlg.isCancelled();
}

@SuppressWarnings("serial")
private class ConfirmDialogWithHelp extends AbstractOkCancelDialog {

String helpTopic;

ConfirmDialogWithHelp(String title, String msg, String helpTopic) {
super(title);

this.helpTopic = helpTopic;

Container contentPane = this.getContentPane();

JPanel topPane = new JPanel();
topPane.setLayout(new BoxLayout(topPane, BoxLayout.PAGE_AXIS));
topPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

topPane.add(createMessagePane(msg));

// OK, Cancel, Help
JPanel buttonPane = createButtonPane2();
topPane.add(buttonPane);
this.helpTopic = helpTopic;

contentPane.add(topPane);

this.pack();
setLocationRelativeTo(Mediator.getUI().getContentPane());
okButton.requestFocusInWindow();
this.setVisible(true);

}

private JPanel createMessagePane(String msg) {
JPanel panel = new JPanel();
JLabel labelMsg = new JLabel(msg);
panel.add(labelMsg);
return panel;
}

/**
* @see org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog#helpAction()
*/
@Override
protected void helpAction() {
Mediator.openPluginHelp(helpTopic);
}

/**
* @see org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog#cancelAction()
*/
@Override
protected void cancelAction() {
// Nothing to do.
}

/**
* @see org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog#okAction()
*/
@Override
protected void okAction() {
cancelled = false;
setVisible(false);
dispose();
}
}

/**
* Return RA and Dec. First look for coordinates in any of our loaded
* datasets. Use the first coordinates found. We are making the simplifying
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ private class ParameterDialog extends AbstractOkCancelDialog {
private JTextArea codeArea;
private JCheckBox addToCurrent;
private JButton clearButton;
private JButton testButton;
private JButton loadButton;
private JButton saveButton;

Expand Down Expand Up @@ -491,6 +492,11 @@ private JPanel createFileControlPane() {
panel.add(clearButton);
clearButton.addActionListener(createClearButtonActionListener());

// to-do: localize
testButton = new JButton("Test");
panel.add(testButton);
testButton.addActionListener(createTestButtonActionListener());

loadButton = new JButton(LocaleProps.get("LOAD_BUTTON"));
panel.add(loadButton);
loadButton.addActionListener(createLoadButtonActionListener());
Expand Down Expand Up @@ -535,7 +541,16 @@ public void actionPerformed(ActionEvent arg0) {
}
};
}


ActionListener createTestButtonActionListener() {
return new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
testInput();
}
};
}

private ActionListener createLoadButtonActionListener() {
return new ActionListener() {
@Override
Expand All @@ -562,6 +577,28 @@ private void clearInput() {
codeArea.setText("");
}

private void testInput() {
minJD.setValue(2457504.8);
maxJD.setValue(2457505.0);
points.setValue(501);
jDflavour.setSelectedIndex(dateTypeToSelectedIndex("HJD"));
codeArea.setText(
"# test model\n\n" +
"zeroPoint is 2457504.93 # time zero point\n" +
"magZeroPoint is 13.69\n" +
"period is 0.0850674\n\n" +
"f(t: real): real {\n" +
" magZeroPoint\n" +
" + 0.091481685488957 * cos(2*PI*(1/period)*(t-zeroPoint)) + 0.114900355450183 * sin(2*PI*(1/period)*(t-zeroPoint))\n" +
" - 0.031986371275697 * cos(2*PI*(2/period)*(t-zeroPoint)) - 0.029782272061918 * sin(2*PI*(2/period)*(t-zeroPoint))\n" +
" - 0.005402185898561 * cos(2*PI*(3/period)*(t-zeroPoint)) + 0.001484256405225 * sin(2*PI*(3/period)*(t-zeroPoint))\n" +
" + 0.006091217702922 * cos(2*PI*(4/period)*(t-zeroPoint)) + 0.001654399074451 * sin(2*PI*(4/period)*(t-zeroPoint))\n" +
" - 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");

}

private void readVelaXML() {
try {
Pair<byte[], String> content = Mediator.getInstance().getVelaXMLloadDialog().readFileAsBytes(ParameterDialog.this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,10 @@ public AAVSOPhotometryURLSearchParameterDialog() {
topPane.add(createAdditiveLoadCheckboxPane());

// OK, Cancel
topPane.add(createButtonPane());
//topPane.add(createButtonPane());

// OK, Cancel, Help
topPane.add(createButtonPane2());

contentPane.add(topPane);

Expand Down Expand Up @@ -581,6 +584,14 @@ public String getVelaFilterStr() {
return velaFilterFieldPanelPair.first.getValue().trim();
}

/**
* @see org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog#helpAction()
*/
@Override
protected void helpAction() {
Mediator.openPluginHelp(getDocName());
}

/**
* @see org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog#cancelAction()
*/
Expand Down
58 changes: 55 additions & 3 deletions src/org/aavso/tools/vstar/ui/dialog/MultiEntryComponentDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,26 @@
public class MultiEntryComponentDialog extends AbstractOkCancelDialog {

private List<ITextComponent<?>> fields;

private String helpTopic = null;

/**
* Constructor
*
* @param title
* Title for the dialog.
* @param helpTopic
* The help topic: an absolute URL or a plug-in doc name.
* @param fields
* The list of fields.
* @param additionalUIComponent
* An optional addition UI component.
*/
public MultiEntryComponentDialog(String title,
String helpTopic,
List<ITextComponent<?>> fields,
Optional<JComponent> additionalUIComponent) {
Optional<JComponent> additionalUIComponent
) {
super(title);
this.fields = fields;

Expand All @@ -70,15 +76,39 @@ public MultiEntryComponentDialog(String title,
topPane.add(additionalUIComponent.get());
}

// OK, Cancel
topPane.add(createButtonPane());
if (helpTopic == null || "".equals(helpTopic)) {
// OK, Cancel
topPane.add(createButtonPane());
} else {
// OK, Cancel, Help
topPane.add(createButtonPane2());
this.helpTopic = helpTopic;
}

contentPane.add(topPane);

this.pack();
setLocationRelativeTo(Mediator.getUI().getContentPane());
this.setVisible(true);
}

/**
* Constructor
*
* @param title
* Title for the dialog.
* @param fields
* The list of fields.
* @param additionalUIComponent
* An optional addition UI component.
* @param helpTopic
* The help topic: an absolute URL or a plug-in doc name.
*/
public MultiEntryComponentDialog(String title,
List<ITextComponent<?>> fields,
Optional<JComponent> additionalUIComponent) {
this(title, null, fields, additionalUIComponent);
}

/**
* Constructor
Expand All @@ -105,6 +135,20 @@ public MultiEntryComponentDialog(String title, ITextComponent<?>... fields) {
this(title, Arrays.asList(fields), Optional.empty());
}

/**
* Constructor
*
* @param title
* Title for the dialog.
* @param fields
* The variable list of fields.
* @param helpTopic
* The help topic: an absolute URL or a plug-in doc name.
*/
public MultiEntryComponentDialog(String title, String helpTopic, ITextComponent<?>... fields) {
this(title, helpTopic, Arrays.asList(fields), Optional.empty());
}

// Add the fields.
private JPanel createParameterPane() {
JPanel panel = new JPanel();
Expand All @@ -119,6 +163,14 @@ private JPanel createParameterPane() {
return panel;
}

/**
* @see org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog#helpAction()
*/
@Override
protected void helpAction() {
Mediator.openPluginHelp(helpTopic);
}

/**
* @see org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialog#cancelAction()
*/
Expand Down
Loading

0 comments on commit a3ac5d7

Please sign in to comment.