Save This Page
Home » openjdk-7 » net » sf » bloof » browser » [javadoc | source]
    1   /*
    2       Bloof - visualize the evolution of your software project
    3       Copyright ( C ) 2003  Lukasz Pekacki <lukasz@pekacki.de>
    4       http://bloof.sf.net/
    5       
    6       This program is free software; you can redistribute it and/or modify it
    7       under the terms of the GNU General Public License.
    8       
    9       This program is distributed in the hope that it will be useful,
   10       but WITHOUT ANY WARRANTY; without even the implied warranty of
   11       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12       GNU General Public License for more details.
   13       
   14       You should have received a copy of the GNU General Public License along with
   15       this program; if not, write to the Free Software Foundation, Inc., 
   16       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
   17   
   18       $RCSfile: DialogTimespan.java,v $ 
   19       Created on $Date: 2003/06/12 11:09:02 $ 
   20   */
   21   package net.sf.bloof.browser;
   22   
   23   import java.awt.BorderLayout;
   24   import java.awt.Frame;
   25   import java.awt.event.ActionEvent;
   26   import java.sql.SQLException;
   27   import java.util.Calendar;
   28   import java.util.Date;
   29   
   30   import javax.swing.JButton;
   31   import javax.swing.JDialog;
   32   import javax.swing.JPanel;
   33   import javax.swing.JSpinner;
   34   import javax.swing.JTextField;
   35   import javax.swing.SpinnerDateModel;
   36   
   37   import net.sf.bloof.Bloof;
   38   import net.sf.bloof.browser.Main;
   39   import net.sf.bloof.metrics.TimeInterval;
   40   import net.sf.bloof.browser.intl.Messages;
   41   import net.sf.bloof.browser.intl.Text;
   42   
   43   /**
   44    * Dialog for specifying a time span
   45    * @author Lukasz Pekacki <pekacki@users.sourceforge.net>
   46    * @version $Id: DialogTimespan.java,v 1.1 2003/06/12 11:09:02 pekacki Exp $
   47    */
   48   public class DialogTimespan extends JDialog {
   49       /**
   50        * Standard constructor
   51        * @param aFrame parent frame
   52        * @param aTitle title of the dialog
   53        * @param aModal isModel
   54        * @throws SQLException on database access error
   55        */
   56       public DialogTimespan(Frame aFrame, String aTitle, boolean aModal) throws SQLException {
   57           super(aFrame, aTitle, aModal);
   58           initFrame();
   59           pack();
   60       }
   61   
   62       /**
   63        * Returns the timespan that was specified in the dialog
   64        * @return the timespan that was specified in the dialog
   65        */
   66       public TimeInterval getTimespan() {
   67           return mTimespan;
   68       }
   69   
   70       private void cancelButtonActionPerformed(ActionEvent aE) {
   71           Main.getGuiControl().processUselessEvent(aE);
   72           this.dispose();
   73       }
   74   
   75       private void initFrame() throws SQLException {
   76           /* init root pannel */
   77           JPanel rootPanel = new JPanel(new BorderLayout());
   78           JPanel inputPanel = new JPanel(new BorderLayout());
   79   
   80           /* input Panel*/
   81           JPanel namePanel = new JPanel();
   82           String name = Main.getGuiControl().getListIdent("Time span");
   83           mName.setText(name);
   84   
   85           TimeInterval wholeTimespan = Bloof.getDatabase().getWholeTimespan();
   86           Calendar fromDate = Calendar.getInstance();
   87           fromDate.setTime(wholeTimespan.getFrom());
   88           fromDate.add(Calendar.DATE, 1);
   89   
   90           JPanel fromPanel = new JPanel(new BorderLayout());
   91           fromPanel.add(Main.getGuiControl().createLabel("From"), BorderLayout.NORTH);
   92           SpinnerDateModel fromModel =
   93               new SpinnerDateModel(
   94                   fromDate.getTime(),
   95                   wholeTimespan.getFrom(),
   96                   wholeTimespan.getTo(),
   97                   Calendar.DAY_OF_WEEK);
   98           mFromDate = new JSpinner(fromModel);
   99           JSpinner.DateEditor fromEditor =
  100               new JSpinner.DateEditor(mFromDate, Messages.getString(Text.DATE_FORMAT));
  101           mFromDate.setEditor(fromEditor);
  102           fromPanel.add(mFromDate, BorderLayout.CENTER);
  103   
  104           JPanel toPanel = new JPanel(new BorderLayout());
  105           toPanel.add(Main.getGuiControl().createLabel("To"), BorderLayout.NORTH);
  106           SpinnerDateModel toModel =
  107               new SpinnerDateModel(
  108                   wholeTimespan.getTo(),
  109                   wholeTimespan.getFrom(),
  110                   wholeTimespan.getTo(),
  111                   Calendar.DAY_OF_WEEK);
  112           mToDate = new JSpinner(toModel);
  113           JSpinner.DateEditor toEditor =
  114               new JSpinner.DateEditor(mToDate, Messages.getString(Text.DATE_FORMAT));
  115           mToDate.setEditor(toEditor);
  116           toPanel.add(mToDate, BorderLayout.CENTER);
  117   
  118           JPanel timePanel = new JPanel();
  119           timePanel.add(fromPanel);
  120           timePanel.add(toPanel);
  121           /* init buttons panel */
  122           JPanel buttonsPanel = new JPanel();
  123           JButton cancelButton = new JButton("Cancel");
  124           cancelButton.addActionListener(new java.awt.event.ActionListener() {
  125               public void actionPerformed(ActionEvent aE) {
  126                   cancelButtonActionPerformed(aE);
  127               }
  128           });
  129           JButton okButton = new JButton("OK");
  130           okButton.addActionListener(new java.awt.event.ActionListener() {
  131               public void actionPerformed(ActionEvent aE) {
  132                   okButtonActionPerformed(aE);
  133               }
  134           });
  135           buttonsPanel.add(okButton);
  136           buttonsPanel.add(cancelButton);
  137           /* construct input panel */
  138           namePanel.add(Main.getGuiControl().createLabel("Name"));
  139           namePanel.add(mName);
  140   
  141           inputPanel.add(namePanel, BorderLayout.NORTH);
  142           inputPanel.add(timePanel, BorderLayout.CENTER);
  143   
  144           /* construct main panel */
  145           rootPanel.add(inputPanel, BorderLayout.CENTER);
  146           rootPanel.add(buttonsPanel, BorderLayout.SOUTH);
  147           getContentPane().add(rootPanel);
  148   
  149       }
  150   
  151       private void okButtonActionPerformed(ActionEvent aE) {
  152           Main.getGuiControl().processUselessEvent(aE);
  153           mTimespan =
  154               new TimeInterval(
  155                   mName.getText(),
  156                   (Date) mFromDate.getModel().getValue(),
  157                   (Date) mToDate.getModel().getValue());
  158           this.dispose();
  159       }
  160       private JSpinner mFromDate;
  161       private TimeInterval mTimespan;
  162       /* data objects */
  163       private JTextField mName = new JTextField(20);
  164       private JSpinner mToDate;
  165   
  166   }

Save This Page
Home » openjdk-7 » net » sf » bloof » browser » [javadoc | source]