ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends ProjectFileFilter.java SwingUI.java
Date Thu, 30 May 2002 06:22:53 GMT
donaldp     02/05/29 23:22:53

  Modified:    container/src/java/org/apache/myrmidon/frontends
                        SwingUI.java
  Added:       container/src/java/org/apache/myrmidon/frontends
                        ProjectFileFilter.java
  Log:
  Add a browse button
  
  Revision  Changes    Path
  1.2       +207 -29   jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/SwingUI.java
  
  Index: SwingUI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/SwingUI.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SwingUI.java	28 May 2002 07:05:05 -0000	1.1
  +++ SwingUI.java	30 May 2002 06:22:53 -0000	1.2
  @@ -8,22 +8,40 @@
   package org.apache.myrmidon.frontends;
   
   import java.awt.Container;
  +import java.awt.Dimension;
   import java.awt.Font;
   import java.awt.Frame;
  +import java.awt.GridBagConstraints;
  +import java.awt.GridBagLayout;
  +import java.awt.GridLayout;
  +import java.awt.Insets;
   import java.awt.TextField;
  +import java.awt.Toolkit;
   import java.awt.event.ActionEvent;
   import java.awt.event.ActionListener;
   import java.awt.event.TextEvent;
   import java.awt.event.TextListener;
  -import javax.swing.BoxLayout;
  +import java.io.File;
  +import java.io.IOException;
   import javax.swing.JButton;
   import javax.swing.JCheckBox;
  +import javax.swing.JComponent;
   import javax.swing.JDialog;
  +import javax.swing.JFileChooser;
   import javax.swing.JPanel;
   import javax.swing.JProgressBar;
  +import javax.swing.JSplitPane;
  +import javax.swing.JTextArea;
  +import javax.swing.JTree;
   import javax.swing.SwingUtilities;
  +import javax.swing.JOptionPane;
  +import javax.swing.event.ChangeEvent;
  +import javax.swing.event.ChangeListener;
   import org.apache.myrmidon.Constants;
   
  +/**
  + * A basic GUI for executing Ant Build files.
  + */
   class SwingUI
       extends JDialog
   {
  @@ -34,56 +52,133 @@
       private TextField m_fileField;
       private JCheckBox m_reloadLibsCheckBox;
       private JCheckBox m_reloadFileCheckBox;
  +    private JFileChooser m_chooser;
  +    private File m_oldFile;
   
       public SwingUI()
       {
           super( (Frame)null, Constants.BUILD_BANNER, true );
           final Container contentPane = getContentPane();
  -        final BoxLayout layout = new BoxLayout( contentPane, BoxLayout.Y_AXIS );
  +        final GridBagLayout layout = new GridBagLayout();
           contentPane.setLayout( layout );
   
  -        final JPanel entryPanel = createEntryPanel();
  -        final JPanel statusPanel = createStatusPanel();
  -        final JPanel resultsPanel = createResultsPanel();
  -
  -        contentPane.add( entryPanel );
  -        contentPane.add( statusPanel );
  -        contentPane.add( resultsPanel );
  +        final JComponent entryPanel = createEntryPanel();
  +        final JComponent statusPanel = createStatusPanel();
  +        final JComponent resultsPanel = createResultsPanel();
  +
  +        GridBagConstraints gbc = null;
  +
  +        gbc = new GridBagConstraints();
  +        gbc.gridx = 0;
  +        gbc.gridy = 0;
  +        gbc.gridwidth = 1;
  +        gbc.gridheight = 1;
  +        gbc.fill = GridBagConstraints.BOTH;
  +        gbc.anchor = GridBagConstraints.CENTER;
  +        gbc.insets = new Insets( 2, 2, 2, 2 );
  +        gbc.ipadx = 5;
  +        gbc.ipady = 5;
  +        gbc.weightx = 1.0;
  +        gbc.weighty = 0.0;
  +        contentPane.add( entryPanel, gbc );
  +
  +        gbc = new GridBagConstraints();
  +        gbc.gridx = 0;
  +        gbc.gridy = 1;
  +        gbc.gridwidth = 1;
  +        gbc.gridheight = 1;
  +        gbc.fill = GridBagConstraints.BOTH;
  +        gbc.anchor = GridBagConstraints.CENTER;
  +        gbc.insets = new Insets( 2, 2, 2, 2 );
  +        gbc.ipadx = 5;
  +        gbc.ipady = 5;
  +        gbc.weightx = 1.0;
  +        gbc.weighty = 0.0;
  +        contentPane.add( statusPanel, gbc );
  +
  +        gbc = new GridBagConstraints();
  +        gbc.gridx = 0;
  +        gbc.gridy = 2;
  +        gbc.gridwidth = 1;
  +        gbc.gridheight = 1;
  +        gbc.fill = GridBagConstraints.BOTH;
  +        gbc.anchor = GridBagConstraints.CENTER;
  +        gbc.insets = new Insets( 2, 2, 2, 2 );
  +        gbc.ipadx = 5;
  +        gbc.ipady = 5;
  +        gbc.weightx = 1.0;
  +        gbc.weighty = 1.0;
  +        contentPane.add( resultsPanel, gbc );
   
           pack();
           validate();
           doLayout();
  +
  +        m_chooser = createChooser();
       }
   
  -    private JPanel createResultsPanel()
  +    private JComponent createResultsPanel()
       {
  -        final JPanel panel = new JPanel();
  -        return panel;
  +        final Dimension size = new Dimension( 300, 140 );
  +        final JTree top = new JTree();
  +        top.setSize( size );
  +        top.setPreferredSize( size );
  +        final JTextArea bottom = new JTextArea( "Text output will go here." );
  +        bottom.setEditable( false );
  +        bottom.setSize( size );
  +        bottom.setPreferredSize( size );
  +        return new JSplitPane( JSplitPane.VERTICAL_SPLIT, top, bottom );
       }
   
       private JPanel createStatusPanel()
       {
           final JPanel panel = new JPanel();
           m_progressBar = new JProgressBar( 0, 300 );
  +        m_progressBar.setStringPainted( true );
  +        m_progressBar.setBorderPainted( true );
  +        m_progressBar.setValue( 200 );
           panel.add( m_progressBar );
           return panel;
       }
   
       private JPanel createEntryPanel()
       {
  -        final JPanel panel = new JPanel();
  +        final JPanel panel = new JPanel( new GridLayout( 2, 1 ) );
  +        final JButton browseButton = createBrowseButton();
           m_buildButton = createBuildButton();
           m_fileField = createFileField();
  -        m_reloadLibsCheckBox = new JCheckBox( "Reload Libraries", true );
           m_reloadFileCheckBox = new JCheckBox( "Reload Build File", true );
  +        m_reloadLibsCheckBox = createLibsCheckBox();
  +
  +        final JPanel top = new JPanel();
  +        top.add( m_fileField );
  +        top.add( browseButton );
  +        top.add( m_buildButton );
  +
  +        final JPanel bottom = new JPanel();
  +        bottom.add( m_reloadLibsCheckBox );
  +        bottom.add( m_reloadFileCheckBox );
  +
  +        panel.add( top );
  +        panel.add( bottom );
   
  -        panel.add( m_fileField );
  -        panel.add( m_buildButton );
  -        panel.add( m_reloadLibsCheckBox );
  -        panel.add( m_reloadFileCheckBox );
           return panel;
       }
   
  +    private JCheckBox createLibsCheckBox()
  +    {
  +        final JCheckBox reloadLibsCheckBox = new JCheckBox( "Reload Libraries", true );
  +        final ChangeListener changeListener = new ChangeListener()
  +        {
  +            public void stateChanged( final ChangeEvent event )
  +            {
  +                m_reloadFileCheckBox.setEnabled( reloadLibsCheckBox.isSelected() );
  +            }
  +        };
  +        reloadLibsCheckBox.addChangeListener( changeListener );
  +        return reloadLibsCheckBox;
  +    }
  +
       private TextField createFileField()
       {
           final TextField fileField = new TextField( "" );
  @@ -113,6 +208,23 @@
           return fileField;
       }
   
  +    private JButton createBrowseButton()
  +    {
  +        final JButton button = new JButton( "..." );
  +        button.setToolTipText( "Browse For Project File" );
  +
  +        final ActionListener actionListener = new ActionListener()
  +        {
  +            public void actionPerformed( final ActionEvent action )
  +            {
  +                action_browse();
  +            }
  +        };
  +        button.addActionListener( actionListener );
  +
  +        return button;
  +    }
  +
       private JButton createBuildButton()
       {
           final JButton button = new JButton( "Build" );
  @@ -130,6 +242,36 @@
           return button;
       }
   
  +    private void action_browse()
  +    {
  +        final int result = m_chooser.showDialog( this, null );
  +        if( JFileChooser.APPROVE_OPTION != result )
  +        {
  +            return;
  +        }
  +
  +        final File file = m_chooser.getSelectedFile();
  +        if( null == file )
  +        {
  +            Toolkit.getDefaultToolkit().beep();
  +            return;
  +        }
  +
  +        m_fileField.setText( file.getAbsolutePath() );
  +    }
  +
  +    private JFileChooser createChooser()
  +    {
  +        final JFileChooser chooser = new JFileChooser();
  +        chooser.setDialogTitle( "Select Build File" );
  +        chooser.setApproveButtonText( "OK" );
  +        chooser.setCurrentDirectory( new File( "." ) );
  +        chooser.setDialogType( JFileChooser.OPEN_DIALOG );
  +        chooser.setMultiSelectionEnabled( false );
  +        chooser.setFileFilter( new ProjectFileFilter() );
  +        return chooser;
  +    }
  +
       private void action_build()
       {
           m_buildButton.setEnabled( false );
  @@ -150,26 +292,62 @@
       {
           System.out.println( "SwingUI.doBuild" );
   
  -//        final boolean reloadLibs = m_reloadLibsCheckBox.isSelected();
  -//        if( reloadLibs )
  -//        {
  -//            //rebuild workspace/module
  -//        }
  +        final boolean reloadLibs = m_reloadLibsCheckBox.isSelected();
  +        if( reloadLibs )
  +        {
  +            //rebuild workspace/module
  +            System.out.println( "Reloading Workspace" );
  +        }
   
           final String buildFilename = m_fileField.getText();
  -        final boolean reloadFile =
  -            m_reloadFileCheckBox.isSelected();
  +        final File file = resolveFile( buildFilename );
  +
  +        if( !file.exists() )
  +        {
  +            final String message = "File " + file + "does not exist.";
  +            final String title = "Missing File";
  +            JOptionPane.showMessageDialog( this,
  +                                           message,
  +                                           title,
  +                                           JOptionPane.WARNING_MESSAGE );
  +            return;
  +        }
   
  -//        if( buildFilename.equals( m_oldBuildFile ) || reloadFile || reloadLibs )
  -//        {
  -//            //reload build file here
  -//        }
  +        final boolean reloadFile = m_reloadFileCheckBox.isSelected() || reloadLibs;
  +        if( null != m_oldFile && file.equals( m_oldFile ) || reloadFile )
  +        {
  +            //reload build file here
  +            System.out.println( "Reloading Build file: " + file );
  +        }
  +        m_oldFile = file;
   
           //Hook up event listener here
   
           //Process Module here
   
  +        //Temporary sleep
  +        try
  +        {
  +            Thread.sleep( 2000 );
  +        }
  +        catch( InterruptedException e )
  +        {
  +        }
  +
           m_buildButton.setEnabled( true );
  +    }
  +
  +    private File resolveFile( final String buildFilename )
  +    {
  +        final File file = new File( buildFilename );
  +        try
  +        {
  +            return file.getCanonicalFile();
  +        }
  +        catch( IOException e )
  +        {
  +            return file.getAbsoluteFile();
  +        }
       }
   
       private void file_textChanged()
  
  
  
  1.1                  jakarta-ant-myrmidon/container/src/java/org/apache/myrmidon/frontends/ProjectFileFilter.java
  
  Index: ProjectFileFilter.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.myrmidon.frontends;
  
  import javax.swing.filechooser.FileFilter;
  import javax.swing.filechooser.FileView;
  import java.io.File;
  
  /**
   * A basic file filter for Ant project files.
   */
  public class ProjectFileFilter
      extends FileFilter
  {
      /**
       * Whether the given file is accepted by this filter.
       */
      public boolean accept( final File file )
      {
          final String name = file.getName();
          return name.endsWith( ".xml" ) || name.endsWith( ".ant" );
      }
  
      /**
       * The description of this filter. For example: "JPG and GIF Images"
       * @see FileView#getName
       */
      public String getDescription()
      {
          return "Ant Project Files";
      }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message