⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 generalizedtimeeditor.java

📁 JAVA开源LDAP浏览器jxplorer的源码!
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
package com.ca.directory.jxplorer.editor;

import com.ca.commons.cbutil.*;
import com.ca.directory.jxplorer.HelpIDs;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
import javax.swing.text.PlainDocument;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Locale;
import java.util.logging.Logger;
import java.util.logging.Level;

/**
 * The GeneralizedTimeEditor is used for editing generalizedTime attributes within the
 * directory.  It is initiated when the user clicks on a generalizedTime attribute in
 * the Table Editor of JXplorer or when the user selects a generalizedTime attribute in
 * the search dialog.
 * <p/>
 * The GeneralizedTimeEditor  displays a date/time dialog with combo boxes for the following:
 * <p/>
 * Milli seconds 				(possible values: 0-999).
 * Seconds of the minute		(possible values: 0-59).
 * Minutes of the hour			(possible values: 0-59).
 * Hour of the day				(possible values: 0-23).
 * Day of the month 			(possible values: --, 1-31).
 * Month of the year			(possible values: --, January - Decemeber inclusive).
 * <p/>
 * Note: it is possible to enter the following generalizedTime 000000000000, this is why a value of -- (0) is
 * included in day of the month and month of the year combos.
 * <p/>
 * The year is displayed and edited through a restricted (whole number) field.  Year can only be of 4 characters.
 * The UTC (or GTM or zulu) is selected via a check box.
 * <p/>
 * This class follows the generalizedTime format of year-month-day-hour-minute (yyyymmddhhmm) as manditory.
 * Optional values in the generalizedTime are second-millisecond-UTC (ss.mmmZ).  Milliseconds require seconds
 * to be added.  Examples of a correct generalizeTime are
 * <P>
 * 20011231235959.999Z
 * 20011231235959.999
 * 20011231235959.99Z
 * 20011231235959.99
 * 20011231235959.9Z
 * 20011231235959.9
 * 19960229235959
 * 19960229235959Z
 * 199702282359
 * 199702282359Z
 * <p/>
 * The dialog has a 'Now' button for displaying the current date/time of the user's machine.
 * <p/>
 * The dialog enforces date constraints such as leap years.  For example if a leap year is entered in the
 * year field and february is selected, the days displayed will be 0-29.  The correct days for the month that
 * is selected will be displayed also.  For example if April is selected the days will be 0-30.
 * @author Trudi.
 */
public class generalizedtimeeditor extends CBDialog
        implements abstractstringeditor
{
    /**
     * Index of feb.
     */
    private static final int FEBRUARY = 2;

    /**
     * List of months (first element is '--').
     */
    private String months[] = {CBIntText.get("--"), CBIntText.get("January"), CBIntText.get("February"),
                       CBIntText.get("March"), CBIntText.get("April"), CBIntText.get("May"),
                       CBIntText.get("June"), CBIntText.get("July"), CBIntText.get("August"),
                       CBIntText.get("September"), CBIntText.get("October"),
                       CBIntText.get("November"), CBIntText.get("December")};

    /**
     * Max days in a month, in order of months.
     */
    private int daysInMonth[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    /**
     * The date and time right now.
     */
    private Calendar rightNow = Calendar.getInstance();

    /**
     * The time value (from the directory).
     */
    private editablestring editableString = null;

    /**
     * The Button that when clicked loads the current date and time into the display.
     */
    private CBButton btnNow = new CBButton(CBIntText.get("Now"), CBIntText.get("Display the present date & time."));

    /**
     * If checked will add a 'Z' to the generalized time (20010918235959.999Z).
     */
    private JCheckBox checkBox = new JCheckBox(CBIntText.get("UTC"));

    /**
     * Year label.
     */
    private JLabel yearLabel = new JLabel(CBIntText.get("Year:"));

    /**
     * Year field.
     */
    private WholeNumberField yearTextField = new WholeNumberField(2001, 4);   // was 5 columns? -CB

    /**
     * Month label.
     */
    private JLabel monthLabel = new JLabel(CBIntText.get("Month:"));

    /**
     * Month combo box.
     */
    private CBJComboBox monthCombo = new CBJComboBox();

    /**
     * Day label.
     */
    private JLabel dayLabel = new JLabel(CBIntText.get("Day:"));

    /**
     * Day combo box.
     */
    private CBJComboBox dayCombo = new CBJComboBox();

    /**
     * Hour label.
     */
    private JLabel hourLabel = new JLabel(CBIntText.get("Hour:"));

    /**
     * Hour combo box.
     */
    private CBJComboBox hourCombo = new CBJComboBox();

    /**
     * Minute label.
     */
    private JLabel minuteLabel = new JLabel(CBIntText.get("Minute:"));

    /**
     * Minuet combo box.
     */
    private CBJComboBox minuteCombo = new CBJComboBox();

    /**
     * Second label.
     */
    private JLabel secondLabel = new JLabel(CBIntText.get("Second:"));

    /**
     * Second combo box.
     */
    private CBJComboBox secondCombo = new CBJComboBox();

    /**
     * Millisecond label.
     */
    private JLabel milliSecondLabel = new JLabel(CBIntText.get("Millisecond:"));

    /**
     * Millisecond combo box.
     */
    private CBJComboBox milliSecondCombo = new CBJComboBox();

    /**
     * Month as entered by the user.
     * Possible values: 0-12.
     */
    private int userMonth;

    /**
     * Year as entered by the user.
     * Example: 2001.
     */
    private int userYear;

    /**
     * Date as entered by the user.
     * Possible values: 0-31.
     */
    private int userDay;

    /**
     * Hour as entered by the user.
     * Possible values: 0-23.
     */
    private int userHour;

    /**
     * Minute as entered by the user.
     * Possible values: 0-59.
     */
    private int userMinute;

    /**
     * Second as entered by the user.
     * Possible values: 0-59.
     */
    private int userSecond;

    /**
     * Millisecond as entered by the user.
     * Possible values: 0-999.
     */
    private int userMilliSecond;

    /**
     * Number of days in month.
     * Possible values: 0, 28, 29, 30 or 31.
     */
    private int numDays = 0;

    /**
     * A backup of the selected index in the date combo.
     */
    private int dateIndexBackup = 0;

    /**
     * Attribute value as a string.
     */
    private String value = null;

    /**
     * This class is normally used by the table editor.  If used elsewhere
     * set this to false and get the time value from the getTime() method.
     */
    private boolean isTableEditor = true;

    /**
     * Used if isTableEditor = false to return the set time via getTime().
     */
    private String time = "";


    private final static Logger log = Logger.getLogger(generalizedtimeeditor.class.getName());

    /**
     * Sets up the dialog components, displaying the supplied attribute value.  If there is
     * no value to display, the fields are all set to zero.
     * @param owner the parent frame, usually JXplorer.
     * @param value the value of the generalized time attribute.
     * @param isTableEditor this class is normally used by the table editor.
     * If used elsewhere set this to false and get the time value from the getTime() method.
     */
    public generalizedtimeeditor(Frame owner, String value, boolean isTableEditor)
    {
        super(owner, CBIntText.get("Generalized Time"), HelpIDs.ATTR_TIME);

        this.isTableEditor = isTableEditor;
        this.value = value;

        // Padding at top...
        display.addln(new JLabel(" "));
        display.makeLight();

        // Initiate the date and time (integer) variables with the
        // attribute values (or 0 if value is not present)...
        initDateTimeVariables();

        // Populate the combos...
        initMilliSeconds();
        initSeconds();
        initMinutes();
        initHours();
        initDays(31);
        initMonths();

        // Sets the state of the check box & sets the tooltip of the check box...
        if (value.indexOf("Z") != -1)
            checkBox.setSelected(true);
        checkBox.setToolTipText(CBIntText.get("Adds a 'Z' to the end of the generalized time."));

        // Adds an action listener to the 'Now' button...
        btnNow.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                displayCurrent();
            }
        });

        /**
         * Listener for month changes. Updates the day combo depending on month selected.
         */
        monthCombo.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                updateDayCombo();
            }
        });

        // Adds a document listener on the year field to do a leap year
        // check if feb is selected in month combo...
        MyDocumentListener myDocumentListener = new MyDocumentListener();
        yearTextField.getDocument().addDocumentListener(myDocumentListener);

        // New panel for drop down boxes...
        CBPanel dateTimePanel = new CBPanel();

        // Add DAY components...
        dateTimePanel.add(dayLabel);
        dateTimePanel.add(dayCombo);

        // Add MONTH components...
        dateTimePanel.add(monthLabel);
        dateTimePanel.addWide(monthCombo, 2);

        // Add YEAR components...
        dateTimePanel.add(yearLabel);
        dateTimePanel.addWide(yearTextField, 2);
        dateTimePanel.addln(new JLabel(" "));
        dateTimePanel.addln(new JLabel(" "));
        dateTimePanel.newLine();

        // Add HOUR components...
        dateTimePanel.add(hourLabel);
        dateTimePanel.add(hourCombo);

        // Add MINUTE components...
        dateTimePanel.add(minuteLabel);
        dateTimePanel.add(minuteCombo);
        dateTimePanel.add(new JLabel(" "));

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -