com.scudata.ide.spl.chart.box.DialogDateChooser Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esproc Show documentation
Show all versions of esproc Show documentation
SPL(Structured Process Language) A programming language specially for structured data computing.
package com.scudata.ide.spl.chart.box;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.GraphicsConfiguration;
import java.util.*;
import javax.swing.*;
import com.scudata.app.common.*;
import com.scudata.common.*;
import com.scudata.ide.common.resources.*;
import com.scudata.ide.common.swing.*;
/**
* ??????????ѡ????
*
* @author Joancy
*
*/
public class DialogDateChooser extends javax.swing.JDialog {
/**
*
*/
private static final long serialVersionUID = 1L;
private MessageManager mm = IdeCommonMessage.get();
private Calendar calendar;
private Calendar retCal;
private String STR_TITLE;
private String STR_DATE;
private String[] STR_ARRAY_MONTH_LIST;
private String STR_ERR1, STR_ERR2;
private void loadLanguageString() {
STR_TITLE = mm.getMessage( "datechooser.selectdate" );
STR_DATE = mm.getMessage( "datechooser.date" );
STR_ARRAY_MONTH_LIST = new Section( mm.getMessage( "datechooser.month" ) ).toStringArray();
STR_ERR1 = mm.getMessage( "datechooser.err1" );
STR_ERR2 = mm.getMessage( "datechooser.err2" );
}
/**
* ȱʡ???캯??
*/
public DialogDateChooser() {
super();
init();
}
/**
* ???캯??
* @param owner ??????
*/
public DialogDateChooser( Dialog owner ) {
super( owner );
init();
}
/**
* ???캯??
* @param owner ??????
* @param modal ģ̬
*/
public DialogDateChooser( Dialog owner, boolean modal ) {
super( owner, modal );
init();
}
/**
* ???캯??
* @param owner ??????
* @param title ???ڱ???
*/
public DialogDateChooser( Dialog owner, String title ) {
super( owner, title );
init();
}
/**
* ???캯??
* @param owner ??????
* @param title ???ڱ???
* @param modal ģ̬
*/
public DialogDateChooser( Dialog owner, String title, boolean modal ) {
super( owner, title, modal );
init();
}
/**
* ???캯??
* @param owner ??????
* @param title ???ڱ???
* @param modal ģ̬
* @param gc ͼ??????
*/
public DialogDateChooser( Dialog owner, String title, boolean modal,
GraphicsConfiguration gc ) {
super( owner, title, modal, gc );
init();
}
/**
* ???캯??
* @param owner ??????
*/
public DialogDateChooser( Frame owner ) {
super( owner );
init();
}
/**
* ???캯??
* @param owner ??????
* @param modal ģ̬
*/
public DialogDateChooser( Frame owner, boolean modal ) {
super( owner, modal );
init();
}
/**
* ???캯??
* @param owner ??????
* @param title ????
*/
public DialogDateChooser( Frame owner, String title ) {
super( owner, title );
init();
}
/**
* ???캯??
* @param owner ??????
* @param title ????
* @param modal ģ̬
*/
public DialogDateChooser( Frame owner, String title, boolean modal ) {
super( owner, title, modal );
init();
}
/**
* ???캯??
* @param owner ??????
* @param title ????
* @param modal ģ̬
* @param gc ͼ??????
*/
public DialogDateChooser( Frame owner, String title, boolean modal,
GraphicsConfiguration gc ) {
super( owner, title, modal, gc );
init();
}
/**
* ??ʼ??????
* @param calendar ????????
*/
public void initDate( Calendar calendar ) {
int m = calendar.get( Calendar.MONTH );
jComboBox1.setSelectedIndex( m );
jSpinner1.setValue( calendar.getTime() );
monthCalendar.setYearMonth( calendar );
timeModel.setValue( calendar.getTime() );
}
private void init() {
loadLanguageString();
initComponents();
//init date
calendar = Calendar.getInstance();
initDate( calendar );
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() { //GEN-BEGIN:initComponents
basePanel = new javax.swing.JPanel();
containerPanel = new javax.swing.JPanel();
controlPanel = new javax.swing.JPanel();
jComboBox1 = new javax.swing.JComboBox();
jSpinner1 = new javax.swing.JSpinner();
viewPanel = new javax.swing.JPanel();
monthCalendar = new MonthlyCalendar() {
protected void dateSelected() {
doSelection();
}
};
setDefaultCloseOperation( javax.swing.WindowConstants.DISPOSE_ON_CLOSE );
setTitle( STR_TITLE );
setResizable( false );
addWindowListener( new java.awt.event.WindowAdapter() {
public void windowClosing( java.awt.event.WindowEvent evt ) {
formWindowClosing( evt );
}
} );
basePanel.setLayout( new java.awt.FlowLayout( java.awt.FlowLayout.CENTER, 10,
10 ) );
basePanel.setBackground( new java.awt.Color( 252, 250, 252 ) );
containerPanel.setLayout( new java.awt.BorderLayout() );
containerPanel.setBorder( new javax.swing.border.TitledBorder( STR_DATE ) );
containerPanel.setOpaque( false );
controlPanel.setLayout( new java.awt.FlowLayout( java.awt.FlowLayout.CENTER,
12, 0 ) );
controlPanel.setBorder( new javax.swing.border.EmptyBorder( new java.awt.
Insets( 5, 0, 10, 0 ) ) );
controlPanel.setOpaque( false );
jComboBox1.setMaximumRowCount( 7 );
jComboBox1.setModel( new javax.swing.DefaultComboBoxModel(
STR_ARRAY_MONTH_LIST ) );
jComboBox1.addItemListener( new java.awt.event.ItemListener() {
public void itemStateChanged( java.awt.event.ItemEvent evt ) {
jComboBox1ItemStateChanged( evt );
}
} );
controlPanel.add( jComboBox1 );
jSpinner1.setModel( new javax.swing.SpinnerDateModel() );
jSpinner1.setEditor( new javax.swing.JSpinner.DateEditor( jSpinner1, "yyyy" ) );
jSpinner1.setPreferredSize( jComboBox1.getPreferredSize() );
jSpinner1.addChangeListener( new javax.swing.event.ChangeListener() {
public void stateChanged( javax.swing.event.ChangeEvent evt ) {
jSpinner1StateChanged( evt );
}
} );
controlPanel.add( jSpinner1 );
containerPanel.add( controlPanel, java.awt.BorderLayout.NORTH );
viewPanel.setLayout( new java.awt.FlowLayout( java.awt.FlowLayout.CENTER, 0,
0 ) );
viewPanel.setBorder( new javax.swing.border.EmptyBorder( new java.awt.Insets(
0, 0, 10, 0 ) ) );
viewPanel.setOpaque( false );
monthCalendar.setBorder( new javax.swing.border.BevelBorder( javax.swing.
border.BevelBorder.LOWERED ) );
viewPanel.add( monthCalendar );
containerPanel.add( viewPanel, java.awt.BorderLayout.CENTER );
basePanel.add( containerPanel );
getContentPane().add( basePanel, java.awt.BorderLayout.CENTER );
JSpinner spinner = new JSpinner( timeModel );
JSpinner.DateEditor editor = new JSpinner.DateEditor( spinner, "HH:mm:ss" );
spinner.setEditor( editor );
getContentPane().add( spinner, java.awt.BorderLayout.SOUTH );
pack();
} //GEN-END:initComponents
private void jSpinner1StateChanged( javax.swing.event.ChangeEvent evt ) { //GEN-FIRST:event_jSpinner1StateChanged
// TODO add your handling code here:
Date date = ( Date ) jSpinner1.getValue();
calendar.setTime( date );
monthCalendar.setYear( calendar.get( Calendar.YEAR ) );
monthCalendar.repaint();
} //GEN-LAST:event_jSpinner1StateChanged
private void jComboBox1ItemStateChanged( java.awt.event.ItemEvent evt ) { //GEN-FIRST:event_jComboBox1ItemStateChanged
// TODO add your handling code here:
if ( evt.getStateChange() == java.awt.event.ItemEvent.DESELECTED ) {
return;
}
monthCalendar.setMonth( jComboBox1.getSelectedIndex() + 1 );
monthCalendar.repaint();
} //GEN-LAST:event_jComboBox1ItemStateChanged
private void formWindowClosing( java.awt.event.WindowEvent evt ) { //GEN-FIRST:event_formWindowClosing
// TODO add your handling code here:
retCal = null;
} //GEN-LAST:event_formWindowClosing
/** Override parent setVisible method to include resetting of highlighted date */
public void setVisible( boolean b ) {
monthCalendar.resetHighlight();
super.setVisible( b );
}
/** Contains handling code for date selection event */
private void doSelection() {
retCal = monthCalendar.getSelectedDate();
super.setVisible( false );
dispose();
}
/**
* User code can call this method to get the selected date as a Calendar object.
* If the DateChooser dialog is closed by clicking the "Close" button, this
* method returns null;
* Else, the DateChooser dialog is closed by selecting a date, and the method
* will return a Calendar object representing that date.
*/
public Calendar getSelectedDate() {
java.util.Date d = (java.util.Date) timeModel.getValue();
GregorianCalendar c = new GregorianCalendar();
c.setTime( d );
if(retCal!=null){
retCal.set( Calendar.HOUR_OF_DAY, c.get( Calendar.HOUR_OF_DAY ) );
retCal.set( Calendar.MINUTE, c.get( Calendar.MINUTE ) );
retCal.set( Calendar.SECOND, c.get( Calendar.SECOND ) );
}
return retCal;
}
/**
* Set the calendar year and month to the specified value.
* Should be called before set the date chooser visible.
*/
public void setYearMonth( int y, int m ) {
if ( y < 1970 ) {
throw new IllegalArgumentException( STR_ERR1 );
}
if ( m < 1 || m > 12 ) {
throw new IllegalArgumentException( STR_ERR2 );
}
jComboBox1.setSelectedIndex( m - 1 );
calendar.set( Calendar.YEAR, y );
jSpinner1.setValue( calendar.getTime() );
monthCalendar.setYearMonth( y, m );
}
/**
* Bean method to set start day of a week.
* Will delegate to MonthlyCalendar.setWeekStartOnSunday(boolean) method.
*/
public void setWeekStartOnSunday( boolean b ) {
monthCalendar.setWeekStartOnSunday( b );
}
/**
* Bean method to get start day of a week.
* Will delegate to MonthlyCalendar.getWeekStartOnSunday method.
*/
public boolean getWeekStartOnSunday() {
return monthCalendar.getWeekStartOnSunday();
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JPanel basePanel;
private javax.swing.JPanel containerPanel;
private javax.swing.JPanel controlPanel;
private javax.swing.JComboBox jComboBox1;
private javax.swing.JSpinner jSpinner1;
private MonthlyCalendar monthCalendar;
private javax.swing.JPanel viewPanel;
private SpinnerDateModel timeModel = new SpinnerDateModel();
// End of variables declaration//GEN-END:variables
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy