DateTimeDialog.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 1999-2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/**
* This class creates a dialog box that helps the user enter date and
* time with mouse clicks. The dialog box need only be created
* once. The Ok and Cancel buttons merely call setVisible with an
* argument of false.
*/
// The layout will consist of 3 panels: topPanel contains the
// different labels and fields. middlePanel contains the buttons
// midnight and now. bottomPanel contains the buttons ok, cancel and
// help. The last two panels are separated by a LineSeparator.
public class DateTimeDialog extends Dialog {
private boolean save;
private DCPanel dateDCPanel;
private DCPanel yearDCPanel;
private DCPanel hourDCPanel;
private DCPanel minuteDCPanel;
private DCPanel secondDCPanel;
private DCCircularTextField date;
private DCCircularTextField hour;
private DCCircularTextField second;
private DCCircularTextField minute;
private DCTextField year;
private Panel middlePanel;
private Panel bottomPanel;
31, 30, 31, 30, 31};
private static DateFormat df =
// For I18N
private static ResourceBundle rb =
private static ResourceBundle hrb =
/**
* Constructor that lays out the componeents and sets the different
* event handlers.
*/
setLayout(new GridBagLayout());
addLabels();
addDCPanels();
addButtons();
setResizable(false);
addWindowListener(new DCWindowListener());
// initializeFocusOnTextField();
}
/**
* Adds the labels only
*/
private void addLabels() {
}
/**
* Adds the fields that will store the month, year, date, hour,
* minute and second.
*/
// Remaining fields are in topPanel
}
// Adds the panels with the +/- buttons for each DCField
private void addDCPanels() {
dateDCPanel = new DCPanel();
yearDCPanel = new DCPanel();
hourDCPanel = new DCPanel();
minuteDCPanel = new DCPanel();
secondDCPanel = new DCPanel();
}
/**
* Sets the strings in the month pull-down menu. Also adds a listener
* that will modify the maximum date allowed depending on the month.
*/
private void initializeMonth() {
}
}
// Adds all the buttons
private void addButtons() {
middlePanel = new Panel();
bottomPanel = new Panel();
}
/**
* Adds a listener to all the text fields so that when they go out
* of focus (by tab or clicking), their values are checked for
* errors.
*/
private void addFocusListeners() {
}
/**
* Closes (hides) the dialog box when the user is done
* @param save true if the box is being dismissed by clicking on
* "ok" and the user wants to retain the modified value, false
* otherwise.
*/
private void dateTimeDialogClose(boolean save) {
if (save == true) {
if (!updateFromGui())
return;
}
setVisible(false);
}
/**
* Checks to see is all text fields contain valid values.
* @return true if all are valid, false otherwise.
*/
private boolean updateFromGui() {
}
/**
* Checks the value stored as text in the field and sets its numeric
* value to that if it is legitimate.
* @return true if the value was legitimate and got set, false
* otherwise.
*/
int i = 0;
boolean errorState = false;
try {
} catch (NumberFormatException e2) {
errorState = true;
}
if (errorState) {
}
else
return !errorState;
}
/**
* Checks if the user requested that the value in this
* DateTimeDialog be used e.g., by clicking on "Ok" instead of
* "Cancel."
* @return true if the user wants to save the value in the
* DateTimeDialog, false otherwise.
*/
public boolean isSaved() {
return save;
}
/**
* Sets the date and time in fields to the current date and time.
*/
public void setCurrentTime() {
}
/**
* Sets the current date of the DateTimeDialog and updates the gui
* components to reflect that.
* @param date the Date to set it to.
*/
calendar = new GregorianCalendar();
// update gui components now
// Make sure the date is in the valid range for the given month
fixDateField();
}
/**
* Set the time fields to midnight, i.e., clears them.
*/
private void setMidnight() {
}
/**
* Make sure the date does not exceed the maximum allowable value
* for the currently selected month.
*/
private void fixDateField() {
}
// * **********************************************
// I N N E R C L A S S E S F O L L O W
// ***********************************************
/**
* Listener for closing the dialog box through the window close
* menu.
*/
private class DCWindowListener extends WindowAdapter {
public void windowClosing(WindowEvent e) {
dateTimeDialogClose(false);
}
}
/**
* Listener for any change in the month selected through the
* pull down menu
*/
private class DCMonthChangeListener implements ItemListener {
public void itemStateChanged(ItemEvent e) {
fixDateField();
}
}
/**
* Listener for all the buttons. The listener is shared for the sake
* of reducing the number of overall listeners.
* TBD: I18N the help
*/
private class DCButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
DateTimeDialog.this.dateTimeDialogClose(true);
}
else
DateTimeDialog.this.dateTimeDialogClose(false);
}
else
DateTimeDialog.this.setCurrentTime();
}
else
DateTimeDialog.this.setMidnight();
}
else
else {
hd = new
getString("Help for Date and Time Dialog"), false);
hd.setVisible(true);
}
}
} // actionPerformed
}
/**
* Listener for any change in focus with respect to the text
* fields. When a text field is going out of focus, it detemines if the
* text value in it is valid. If not, it returns focus to that text
* field.
*/
private class DCFocusListener extends FocusAdapter {
public void focusLost(FocusEvent e) {
}
}
/**
* The string representation of the dialog box.
* @return a String which contians the date and time in locale
* default format, but to MEDIUM length formatting style.
*/
}
/**
* Call rb.getString(), but catch exception and return English
* key so that small spelling errors don't cripple the GUI
*
*/
}
try {
return res;
} catch (MissingResourceException e) {
return key;
}
}
/*
public static final void main(String args[]) {
Frame f = new Frame();
// while (true){
DateTimeDialog d = new DateTimeDialog(f, Color.white, Color.black);
d.setVisible(true);
System.out.println(d.toString());
// }
}
*/
}