home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-09-10 | 12.9 KB | 377 lines |
- /************************************************************************
- * NewDlg (by John W. Gibbs)
- *
- * Copyright (c) 1997 Microsoft Corporation, All Rights Reserved.
- ***********************************************************************/
-
- import java.awt.*;
- import java.util.*;
- import com.ms.com.*;
- import com.ms.ui.*;
- import rend.*;
- import sdpblb.*;
- import NewCtrls;
-
-
- /////////////////////////////////////////////////////////////////////////
- // CLASS: NewDlg
- //
- // PURPOSE: Supporting class to JT3Conf
- // DATE: July 24, 1997
- //
- // DESCRIPTION:
- // Dialog that allows the user to enter specifications for a
- // conference and then create it using the Rendezvous Controls.
- //
- /////////////////////////////////////////////////////////////////////////
-
- public class NewDlg extends Dialog
- {
- // Dialog title.
- public static final String DLG_TITLE = "New Conference";
-
- // Button ids.
- public static final int NONE = 0;
- public static final int CREATE = 1;
- public static final int CANCEL = 2;
-
- // Resource Wizard generated UI.
- private final NewCtrls ctrls = new NewCtrls(this);
-
- // Parent frame of the dlg.
- private Frame m_ParentFrame = null;
-
- // The conference directory component.
- private ITConferenceDirectory m_Directory = null;
-
- // The conference that is created.
- private ITConference m_Conference = null;
-
- // The button that was use to close the dialog.
- private int m_ButtonId = NONE;
-
- // Conference data fields.
- public String m_strConfName = "";
- public String m_strDesc = "";
- public String m_strUserName = "";
-
- public short m_nStartYear = 1997;
- public byte m_nStartMonth = 7;
- public byte m_nStartDay = 1;
- public byte m_nStartHour = 8;
- public byte m_nStartMinute = 0;
-
- public short m_nStopYear = 2000;
- public byte m_nStopMonth = 7;
- public byte m_nStopDay = 1;
- public byte m_nStopHour = 8;
- public byte m_nStopMinute= 0;
-
-
- /////////////////////////////////////////////////////////////////////
- // Constructor
- /////////////////////////////////////////////////////////////////////
- public NewDlg(Frame parent, ITConferenceDirectory directory)
- {
- super(parent, DLG_TITLE, true);
-
- // select a font to use (ctrls needs this)
- Font font = new Font("Dialog", Font.PLAIN, 8);
- this.setFont(font);
-
- // create the UI generated by the Resource Wizard
- ctrls.CreateControls();
-
- // initialize controls
- ctrls.cmbStartMonth.addItem("January");
- ctrls.cmbStartMonth.addItem("February");
- ctrls.cmbStartMonth.addItem("March");
- ctrls.cmbStartMonth.addItem("April");
- ctrls.cmbStartMonth.addItem("May");
- ctrls.cmbStartMonth.addItem("June");
- ctrls.cmbStartMonth.addItem("July");
- ctrls.cmbStartMonth.addItem("August");
- ctrls.cmbStartMonth.addItem("September");
- ctrls.cmbStartMonth.addItem("October");
- ctrls.cmbStartMonth.addItem("November");
- ctrls.cmbStartMonth.addItem("December");
-
- ctrls.cmbStopMonth.addItem("January");
- ctrls.cmbStopMonth.addItem("February");
- ctrls.cmbStopMonth.addItem("March");
- ctrls.cmbStopMonth.addItem("April");
- ctrls.cmbStopMonth.addItem("May");
- ctrls.cmbStopMonth.addItem("June");
- ctrls.cmbStopMonth.addItem("July");
- ctrls.cmbStopMonth.addItem("August");
- ctrls.cmbStopMonth.addItem("September");
- ctrls.cmbStopMonth.addItem("October");
- ctrls.cmbStopMonth.addItem("November");
- ctrls.cmbStopMonth.addItem("December");
-
- UpdateData(true);
-
- // get parent frame to use for message boxes
- m_ParentFrame = parent;
-
- // save conference directory
- m_Directory = directory;
- }
-
- /////////////////////////////////////////////////////////////////////
- // action
- //
- // Event.ACTION_EVENT event handler.
- /////////////////////////////////////////////////////////////////////
- public boolean action(Event evt, Object arg)
- {
- if (arg.equals("Create")) {
- // create button pressed
- UpdateData(false);
- if (ValidateData()) {
- m_Conference = CreateTheConference();
- m_ButtonId = CREATE;
- this.dispose();
- }
- }
- else if (arg.equals("Cancel")) {
- // cancel button pressed
- m_ButtonId = CANCEL;
- this.dispose();
- }
- else
- return super.action(evt, arg);
- return true;
- }
-
- /////////////////////////////////////////////////////////////////////
- // GetConference
- //
- // Returns the conference that was created or null if a conference
- // was not created.
- /////////////////////////////////////////////////////////////////////
- public ITConference GetConference()
- {
- if (m_ButtonId == CREATE)
- return m_Conference;
- else
- return null;
- }
-
- /////////////////////////////////////////////////////////////////////
- // GetButtonId
- //
- // Returns the id of the button that was used to close the dialog.
- // May be NONE if the dialog is closed using the system menu, etc.
- /////////////////////////////////////////////////////////////////////
- public int GetButtonId()
- {
- return m_ButtonId;
- }
-
- /////////////////////////////////////////////////////////////////////
- // UpdateData
- //
- // If toControls is true, the values in the conference data fields
- // are put into the UI controls. If toControls is false, data from
- // the dialog controls is collected and stored into the conference
- // data fields.
- /////////////////////////////////////////////////////////////////////
- public void UpdateData(boolean toControls)
- {
- if (toControls) {
- ctrls.tfConfName.setText(m_strConfName);
- ctrls.taDesc.setText(m_strDesc);
- ctrls.tfUserName.setText(m_strUserName);
-
- ctrls.tfStartYear.setText(m_nStartYear + "");
- ctrls.cmbStartMonth.select(m_nStartMonth - 1);
- ctrls.tfStartDay.setText(m_nStartDay + "");
- ctrls.tfStartHour.setText(m_nStartHour + "");
- ctrls.tfStartMinute.setText(m_nStartMinute + "");
-
- ctrls.tfStopYear.setText(m_nStopYear + "");
- ctrls.cmbStopMonth.select(m_nStopMonth - 1);
- ctrls.tfStopDay.setText(m_nStopDay + "");
- ctrls.tfStopHour.setText(m_nStopHour + "");
- ctrls.tfStopMinute.setText(m_nStopMinute + "");
- }
- else {
- m_strConfName = ctrls.tfConfName.getText().trim();
- m_strDesc = ctrls.taDesc.getText().trim();
- m_strUserName = ctrls.tfUserName.getText().trim();
-
- m_nStartYear = Short.parseShort(ctrls.tfStartYear.getText().trim());
- m_nStartMonth = (byte) (ctrls.cmbStartMonth.getSelectedIndex() + 1);
- m_nStartDay = Byte.parseByte(ctrls.tfStartDay.getText().trim());
- m_nStartHour = Byte.parseByte(ctrls.tfStartHour.getText().trim());
- m_nStartMinute = Byte.parseByte(ctrls.tfStartMinute.getText().trim());
-
- m_nStopYear = Short.parseShort(ctrls.tfStopYear.getText().trim());
- m_nStopMonth = (byte) (ctrls.cmbStopMonth.getSelectedIndex() + 1);
- m_nStopDay = Byte.parseByte(ctrls.tfStopDay.getText().trim());
- m_nStopHour = Byte.parseByte(ctrls.tfStopHour.getText().trim());
- m_nStopMinute = Byte.parseByte(ctrls.tfStopMinute.getText().trim());
- }
- }
-
- /////////////////////////////////////////////////////////////////////
- // ValidateData
- //
- // Returns true if the conference data fields contain valid data.
- // If any of the fields are incorrect, a message is displayed to the
- // user.
- /////////////////////////////////////////////////////////////////////
- public boolean ValidateData()
- {
- if (m_strConfName.equals("")) {
- DoMessage("The Conference Name field may not be blank");
- return false;
- }
-
- if (m_strDesc.equals("")) {
- DoMessage("The Description field may not be blank");
- return false;
- }
-
- if (m_strUserName.equals("")) {
- DoMessage("The User Name field may not be blank");
- return false;
- }
-
- if (m_nStartYear < 1970 || m_nStartYear > 3000) {
- DoMessage("The Start Year field must be from 1970 to 3000");
- return false;
- }
-
- if (m_nStartDay < 1 || m_nStartDay > DaysInMonth(m_nStartMonth)) {
- DoMessage("The Start Day field must be from 1 to " + DaysInMonth(m_nStartMonth));
- return false;
- }
-
- if (m_nStartHour < 1 || m_nStartHour > 23) {
- DoMessage("The Start Hour field must be from 1 to 23");
- return false;
- }
-
- if (m_nStartMinute < 0 || m_nStartMinute > 59) {
- DoMessage("The Start Minutes field must be from 0 to 59");
- return false;
- }
-
- if (m_nStopYear < 1970 || m_nStopYear > 3000) {
- DoMessage("The Stop Year field must be from 1900 to 3000");
- return false;
- }
-
- if (m_nStopDay < 1 || m_nStopDay > DaysInMonth(m_nStopMonth)) {
- DoMessage("The Stop Day field must be from 1 to " + DaysInMonth(m_nStopMonth));
- return false;
- }
-
- if (m_nStopHour < 1 || m_nStopHour > 23) {
- DoMessage("The Stop Hour field must be from 1 to 23");
- return false;
- }
-
- if (m_nStopMinute < 0 || m_nStopMinute > 59) {
- DoMessage("The Stop Minutes field must be from 0 to 59");
- return false;
- }
-
- return true;
- }
-
- /////////////////////////////////////////////////////////////////////
- // CreateTheConference
- //
- // Creates a conference using the data entered into the conference
- // data fields. Returns the created conference or null if there
- // was an error.
- /////////////////////////////////////////////////////////////////////
- private ITConference CreateTheConference()
- {
- ITConference conf;
- ITConferenceBlob confBlob;
-
- try {
- // create the conference
- conf = m_Directory.CreateConference(m_strConfName);
-
- // modify its attributes
- conf.putOriginator(m_strUserName);
- conf.putDescription(m_strDesc);
- conf.SetStartTime(
- m_nStartYear,
- m_nStartMonth,
- m_nStartDay,
- m_nStartHour,
- m_nStartMinute
- );
- conf.SetStopTime(
- m_nStopYear,
- m_nStopMonth,
- m_nStopDay,
- m_nStopHour,
- m_nStopMinute
- );
-
- // commit the conference info to the ILS server
- confBlob = (ITConferenceBlob) conf;
- confBlob.CommitBlob();
-
- return conf;
- }
- catch (ComException e) {
- e.printStackTrace();
- return null;
- }
- }
-
- /////////////////////////////////////////////////////////////////////
- // DaysInMonth
- //
- // Returns the number of days in the given month, where January is
- // month 0 and so on. Does not account for leap-years.
- /////////////////////////////////////////////////////////////////////
- private int DaysInMonth(int month)
- {
- switch (month)
- {
- case 0:
- case 2:
- case 4:
- case 6:
- case 7:
- case 9:
- case 11:
- return 31;
- case 1:
- return 28; // leap-years not included!
- case 3:
- case 5:
- case 8:
- case 10:
- return 30;
- default:
- return 0;
- }
- }
-
- /////////////////////////////////////////////////////////////////////
- // DoMessage
- //
- // Displays messages in a message box.
- /////////////////////////////////////////////////////////////////////
- private void DoMessage(String msg)
- {
- AwtUIMessageBox msgbox = new AwtUIMessageBox(
- m_ParentFrame,
- DLG_TITLE,
- msg,
- AwtUIMessageBox.EXCLAMATION,
- UIButtonBar.OK
- );
- msgbox.doModal();
- }
- }