//*********************************************************************************
// class jephem.gui.NewCurveDialog
// Software released under the General Public License (version 2 or later), available at
// http://www.gnu.org/copyleft/gpl.html
//*********************************************************************************
package jephem.gui;
import jephem.gui.UtilsGUI;
import jephem.gui.SaveListener;
import jephem.GlobalVar;
import jephem.tools.AstroPrefs;
import jephem.tools.Ephemeris;
import jephem.astro.AstroContext;
import jephem.astro.solarsystem.SolarSystemConstants;
import jephem.astro.spacetime.Space;
import jephem.astro.spacetime.SpaceConstants;
import jephem.astro.spacetime.Time;
import jephem.astro.spacetime.TimeConstants;
import jephem.astro.spacetime.Units;
import jephem.astro.spacetime.UnitsConstants;
import jephem.astro.AstroException;
import jephem.util.Debug;
import tig.GeneralConstants;
import tig.Strings;
import tig.Integers;
import tig.Dates;
import tig.TigBundle;
import tig.TigProperties;
import tig.DateFormatException;
import tig.HourFormatException;
import tig.swing.JTextField2;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;
import java.util.Vector;
import java.util.Calendar;
/******************************************************************
Modal dialog displayed when a new Curve is asked by the user.
@see jephem.tools.Curve
@see jephem.gui.CurveViewer
@author Thierry Graff
@history sep 10 2002 : Creation
@todo handle
*****************************************************************/
public class NewCurveDialog extends JDialog
implements GeneralConstants, SolarSystemConstants, SpaceConstants, UnitsConstants{
//=================================================================================
// INSTANCE VARIABLES
//=================================================================================
//=================================================================================
// RESSOURCE BUNDLES (STATIC VARIABLES)
//=================================================================================
// ***** Ressource bundles. ******
private static TigBundle _myBundle, _galBundle, _astroBundle, _timeBundle;
static{
_galBundle = GlobalVar.getBundle(GlobalVar.BUNDLE_GENERAL);
_astroBundle = GlobalVar.getBundle(GlobalVar.BUNDLE_ASTRO);
try{
_myBundle = new TigBundle(GlobalVar.getDirectory(GlobalVar.DIR_LANG) + FS + "NewEphemerisDialog.lang",
GlobalVar.getLocale());
_timeBundle = new TigBundle(GlobalVar.getDirectory(GlobalVar.DIR_LANG) + FS + "Time.lang",
GlobalVar.getLocale());
}
catch (IOException ioe){
Debug.traceError(ioe);
}
};
//=================================================================================
// VARIABLES FOR LAST VALUES (static + constants)
//=================================================================================
/* Variable containing data of last values. */
private static TigProperties _lastValues;
/** Indicates if the last values have already been lodaed*/
private static boolean _lastValuesLoaded = false;
/** File in which last values are stored. */
private static final File LAST_VALUES_FILE =
new File(GlobalVar.getDirectory(GlobalVar.DIR_PREFS) + FS + "jephem" + FS + "gui" + FS + "NewEphemerisDialog.last");
/** Comment line at the beginning of last values file. */
private static final String LAST_VALUES_HEADER =
"Last values entered by the user in NewEphemerisDialog";
private static final String LAST_SELECTED_TAB_KEY = "lastSelectedTab";
private static final int LAST_SELECTED_TAB_DEFAULT = 0;
private static final String LAST_PLANETS_KEY = "lastPlanets";
private static final int[] LAST_PLANETS_DEFAULT = new int[]{0, 1, 2, 3, 4, 5, 6, 7, 8};
private static final String LAST_PRECISION_KEY = "lastPrecision";
private static final String LAST_PRECISION_DEFAULT = "1";
private static final String LAST_ASTROENGINE_KEY = "lastAstroEngine";
private static final String LAST_ASTROENGINE_DEFAULT = AstroContext.JEPHEM;
private static final String LAST_USE_SYMBOLS_KEY = "lastUseSymbols";
private static final boolean LAST_USE_SYMBOLS_DEFAULT = false;
private static final String LAST_INSTANTS_IN_ROWCOL_KEY = "lastInstantsInRowCol";
private static final int LAST_INSTANTS_IN_ROWCOL_DEFAULT = Ephemeris.INSTANTS_IN_ROWS;
private static final String LAST_DISPLAY_ERROR_MESSAGE_KEY = "lastDisplayErrorMsg";
private static final boolean LAST_DISPLAY_ERROR_MESSAGE_DEFAULT = false;
private static final String LAST_BEGIN_DATE_KEY = "lastBeginDate";
// private static final String LAST_BEGIN_DATE_DEFAULT = "01/01/2000";
private static final String LAST_BEGIN_HOUR_KEY = "lastBeginHour";
// private static final String LAST_BEGIN_HOUR_DEFAULT = "00h00m00s";
private static final String LAST_TXT_DISPLAY_EVERY_KEY = "lastTxtDisplayEvery";
private static final String LAST_TXT_DISPLAY_EVERY_DEFAULT = "1";
private static final String LAST_LST_DISPLAY_EVERY_KEY = "lastLstDisplayEvery";
private static final int LAST_LST_DISPLAY_EVERY_DEFAULT = 3;
private static final String LAST_DISPLAY_DATE_JDS_KEY = "lastDisplayDateJDs";
private static final int LAST_DISPLAY_DATE_JDS_DEFAULT = Ephemeris.DISPLAY_DATES;
private static final String LAST_TIME_FRAME_KEY = "lastTimeFrame";
private static final int LAST_TIME_FRAME_DEFAULT = TimeConstants.UTC;
private static final String LAST_SPECIFY_NB_DATES_KEY = "lastSpecifyNbDates";
private static final boolean LAST_SPECIFY_NB_DATES_DEFAULT = true;
private static final String LAST_NB_DATES_KEY = "lastNbDates";
private static final String LAST_NB_DATES_DEFAULT = "10";
private static final String LAST_END_DATE_KEY = "lastEndDate";
private static final String LAST_END_DATE_DEFAULT = BLANK;
private static final String LAST_END_HOUR_KEY = "lastEndHour";
private static final String LAST_END_HOUR_DEFAULT = BLANK;
private static final String LAST_FRAME_KEY = "lastFrame";
private static final int LAST_FRAME_DEFAULT = FRAME_THEORY ;
private static final String LAST_SELECTED_COORDS_KEY = "lastSelectedCoords";
private static final int[] LAST_SELECTED_COORDS_DEFAULT = new int[]{0, 1, 2};
private static final String LAST_UNITS_KEY = "lastUnits";
private static final int[] LAST_UNITS_DEFAULT = new int[]{0, 0, 0, 0, 0, 0};
private static final String LAST_COORD_EXPR_KEY = "lastCoordExpr";
private static final int LAST_COORD_EXPR_DEFAULT = SPHERICAL;
private static final String LAST_DEGREE_EXPR_KEY = "lastDegreeExpr";
private static final int LAST_DEGREE_EXPR_DEFAULT = Units.DEGREES_DECIMAL;
//=================================================================================
// CONSTANTS
//=================================================================================
// Index of panels within the tabbed pane.
private static final int GENERAL_PANEL_INDEX = 0;
private static final int DATE_PANEL_INDEX = 1;
private static final int COORD_PANEL_INDEX = 2;
// just used for more readable code
private static final int NB_COORD = 3;
//=================================================================================
// CONSTRUCT0RS
//=================================================================================
/** Unique constructor */
public NewCurveDialog() throws Exception {
super(GlobalVar.getMainFrame(), _myBundle.getString("Dialog.Title"), true);
//System.out.println("NewEphemerisDialog.constructor()");
// GUI is initialized with last values in initFields()
try{
Container contentPane = this.getContentPane();
JButton btnOK = new JButton("OK");
btnOK.addActionListener(new OKListener());
JPanel buttonPanel = new JPanel();
buttonPanel.add(btnOK);
contentPane.add(buttonPanel, BorderLayout.SOUTH);
this.pack();
// center on its parent
Dimension d1 = this.getParent().getSize();
Dimension d2 = this.getSize();
int x = Math.max(0, ((d1.width - d2.width) / 2));
int y = Math.max(0, ((d1.height - d2.height) / 2));
// int x = (d1.width - d2.width) / 2;
// int y = (d1.height - d2.height) / 2;
this.setLocation(x, y);
//this.initFields();
}
catch(Exception e){
throw e;
}
}//end NewCurveDialog()
//=================================================================================
// AUXILIARY METHODS
//=================================================================================
//=================================================================================
// INNER CLASSES
//=================================================================================
//*****************************************************************
// EVENT LISTENNERS
//*****************************************************************
//*****************************************************************
/** Contains validity checking and building of an Ephemeris object.*/
class OKListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
try{
////////////// SIMULATION TEST x, x2, Vx //////////////
// double[][] data = new double[4][20];
// for (int i = 0; i < 20; i++) {
// double d = (double)i;
// data[0][i] = d;
// data[1][i] = d; // y = x
// data[2][i] = d*d;
// data[3][i] = Math.sqrt(d);
// }
////////////// SIMULATION TEST //////////////
final int NB_VALUES = 151;
int theBody = VENUS;
int[] bodyIndexes = {URANUS, NEPTUNE};
// double jd0 = 2452275.5;
double jd0 = 2448622.5;
int interval = 50;
double[] jds = new double[NB_VALUES];
for(int i = 0; i < jds.length; i++){
jds[i] = jd0 + (double)(i*interval);
}
int[] whichCoords = {COORD_X1, COORD_X2};
int[] coordUnits = UNITGROUP_AU_DEG_DEG;
jephem.tools.Ephemeris eph = new jephem.tools.Ephemeris(bodyIndexes,
jds,
TimeConstants.UTC,
whichCoords,
coordUnits,
FRAME_ECLIPTIC,
SPHERICAL,
1,
jephem.astro.AstroContext.SWISS_EPHEMERIS,
false);
double[][] data = new double[3][NB_VALUES];
data[0] = jds;
double[][][] ephData = eph.getData();
for (int i = 0; i < ephData.length; i++) {
// data[0][i] = ephData[i][0][0];
data[1][i] = ephData[i][0][1];
data[2][i] = ephData[i][1][1];
//data[1] = eph.getCoords(theBody, COORD_X1);
}
// Add a 'Modify' menuItem
// Save current state of the dialog for restoration
NewCurveDialog.this.dispose();
JPanel centralPanel = GlobalVar.getMainFrame().getCentralPanel();
CurveViewer cv = new CurveViewer();
cv.getCurve().setData(data);
centralPanel.removeAll();
centralPanel.add(cv, BorderLayout.CENTER);
centralPanel.invalidate();
centralPanel.repaint();
centralPanel.validate();
}
catch(Exception je){
Debug.traceError(je);
}
} // end actionPerformed
} // end class OKListener
//*****************************************************************
class CancelListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
dispose();
} // end actionPerformed
} // end class CancelListener
}// end class NewCurveDialog