org/objectweb/proactive/ext/scilab/gui/DialogTask.java

00001 /* 
00002  * ################################################################
00003  * 
00004  * ProActive: The Java(TM) library for Parallel, Distributed, 
00005  *            Concurrent computing with Security and Mobility
00006  * 
00007  * Copyright (C) 1997-2007 INRIA/University of Nice-Sophia Antipolis
00008  * Contact: proactive@objectweb.org
00009  * 
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2.1 of the License, or any later version.
00014  *  
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Lesser General Public License for more details.
00019  * 
00020  * You should have received a copy of the GNU Lesser General Public
00021  * License along with this library; if not, write to the Free Software
00022  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00023  * USA
00024  *  
00025  *  Initial developer(s):               The ProActive Team
00026  *                        http://www.inria.fr/oasis/ProActive/contacts.html
00027  *  Contributor(s): 
00028  * 
00029  * ################################################################
00030  */ 
00031 package org.objectweb.proactive.ext.scilab.gui;
00032 import java.awt.BorderLayout;
00033 import java.awt.FlowLayout;
00034 import java.awt.event.ActionEvent;
00035 import java.awt.event.ActionListener;
00036 import java.awt.event.WindowAdapter;
00037 import java.awt.event.WindowEvent;
00038 import java.io.File;
00039 
00040 import javax.swing.BorderFactory;
00041 import javax.swing.ComboBoxModel;
00042 import javax.swing.DefaultComboBoxModel;
00043 import javax.swing.JButton;
00044 import javax.swing.JComboBox;
00045 import javax.swing.JFileChooser;
00046 import javax.swing.JFrame;
00047 import javax.swing.JLabel;
00048 import javax.swing.JPanel;
00049 import javax.swing.JScrollPane;
00050 import javax.swing.JTextArea;
00051 import javax.swing.JTextField;
00052 import javax.swing.filechooser.FileFilter;
00053 
00054 public class DialogTask extends javax.swing.JDialog {
00055         private JPanel pnlPath;
00056         private JLabel lblPath;
00057         private JTextField txtOutParam;
00058         private JTextField txtPath;
00059         private JLabel lblPriority;
00060         private JLabel lblOutParam;
00061         private JComboBox cmbPriority;
00062         private JPanel pnlTaskPriority;
00063         private JPanel pnlPathSouth;
00064         private JPanel pnlPathNorth;
00065         private JFileChooser chooserScript;
00066         private JButton btnCancel;
00067         private JButton btnStart;
00068         private JTextArea txtInit;
00069         private JScrollPane scrollInit;
00070         private JPanel pnlValid;
00071         private JPanel pnlTask;
00072         private JPanel pnlMain;
00073         private JButton btnPath;
00074         private JPanel pnlTaskSouth;
00075         private JPanel pnlInit;
00076 
00077         public static final int VALIDATE = 1,
00078         CANCEL = 0;
00079 
00080         private int state;
00081 
00082         public DialogTask(JFrame frame) {
00083                 super(frame);
00084                 initGUI();
00085         }
00086         
00087         private void initGUI() {
00088                 try {
00089                         {
00090                                 chooserScript = new JFileChooser();
00091                                 FileFilter filter = new FileFilter(){
00092                                         public boolean accept(File f){
00093                                                 
00094                                                 if(f == null){
00095                                                         return false;
00096                                                 }
00097                                                 
00098                                                 if (f.isDirectory()) {
00099                                                  return true;
00100                                              }
00101                                                 
00102                                              return f.getName().endsWith(".sci") || f.getName().endsWith(".sce");
00103                                         }
00104                                         
00105                                         public String getDescription() {
00106                                                 return "Scilab Filter";
00107                                          }
00108                                 }; 
00109                                 
00110                                 chooserScript.setFileFilter(filter);
00111                         }
00112                 
00113                         {
00114                                 pnlMain = (JPanel) getContentPane();
00115                                 BorderLayout pnlMainLayout = new BorderLayout();
00116                                 pnlMain.setLayout(pnlMainLayout);
00117                                 
00118                                 pnlMain.setPreferredSize(new java.awt.Dimension(510, 330));
00119                                 {
00120                                         pnlTask = new JPanel();
00121                                         BorderLayout pnlTaskLayout = new BorderLayout();
00122                                         pnlTask.setLayout(pnlTaskLayout);
00123                                         pnlMain.add(pnlTask, BorderLayout.CENTER);
00124                                         {
00125                                                 pnlInit = new JPanel();
00126                                                 pnlTask.add(pnlInit, BorderLayout.CENTER);
00127                                                 BorderLayout pnlInitLayout = new BorderLayout();
00128                                                 pnlInit.setLayout(pnlInitLayout);
00129                                                 pnlInit.setPreferredSize(new java.awt.Dimension(396, 228));
00130                                                 pnlInit.setSize(393, 23);
00131                                                 pnlInit.setBorder(BorderFactory.createTitledBorder("Initialize Script"));
00132                                                 {
00133                                                         scrollInit = new JScrollPane();
00134                                                         pnlInit.add(scrollInit, BorderLayout.CENTER);
00135                                                         scrollInit.setPreferredSize(new java.awt.Dimension(
00136                                                                 502,
00137                                                                 203));
00138                                                         {
00139                                                                 txtInit = new JTextArea();
00140                                                                 scrollInit.setViewportView(txtInit);
00141                                                         }
00142                                                 }
00143                                         }
00144                                         {
00145                                                 pnlTaskSouth = new JPanel();
00146                                                 pnlTask.add(pnlTaskSouth, BorderLayout.SOUTH);
00147                                                 BorderLayout pnlOutParamLayout = new BorderLayout();
00148                                                 pnlOutParamLayout.setHgap(5);
00149                                                 pnlTaskSouth.setLayout(pnlOutParamLayout);
00150                                                 pnlTaskSouth.setPreferredSize(new java.awt.Dimension(512, 31));
00151                                                 pnlTaskSouth.setBorder(BorderFactory.createTitledBorder(""));
00152                                                 {
00153                                                         txtOutParam = new JTextField();
00154                                                         pnlTaskSouth.add(txtOutParam, BorderLayout.CENTER);
00155                                                         txtOutParam.setPreferredSize(new java.awt.Dimension(213, 15));
00156                                                 }
00157                                                 {
00158                                                         pnlTaskPriority = new JPanel();
00159                                                         BorderLayout pnlTaskPriorityLayout = new BorderLayout();
00160                                                         pnlTaskPriorityLayout.setHgap(5);
00161                                                         pnlTaskPriority.setLayout(pnlTaskPriorityLayout);
00162                                                         pnlTaskSouth.add(pnlTaskPriority, BorderLayout.EAST);
00163                                                         {
00164                                                                 lblPriority = new JLabel();
00165                                                                 pnlTaskPriority.add(lblPriority, BorderLayout.WEST);
00166                                                                 lblPriority.setText("Priority Task:");
00167                                                                 lblPriority.setPreferredSize(new java.awt.Dimension(84, 16));
00168                                                         }
00169                                                         {
00170                                                                 ComboBoxModel cmbPriorityModel = new DefaultComboBoxModel(
00171                                                                         new String[] { "Low", "Normal", "High" });
00172                                                                 cmbPriority = new JComboBox();
00173                                                                 pnlTaskPriority.add(cmbPriority, BorderLayout.CENTER);
00174                                                                 cmbPriority.setModel(cmbPriorityModel);
00175                                                                 cmbPriority.setPreferredSize(new java.awt.Dimension(79, 19));
00176                                                                 cmbPriority.setSelectedIndex(1);
00177                                                         }
00178                                                 }
00179                                                 {
00180                                                         lblOutParam = new JLabel();
00181                                                         pnlTaskSouth.add(lblOutParam, BorderLayout.WEST);
00182                                                         lblOutParam.setText("Out Parameters:");
00183                                                         lblOutParam
00184                                                                 .setPreferredSize(new java.awt.Dimension(
00185                                                                         111,
00186                                                                         17));
00187                                                 }
00188                                         }
00189                                         {
00190                                                 pnlPath = new JPanel();
00191                                                 pnlTask.add(pnlPath, BorderLayout.NORTH);
00192                                                 BorderLayout pnlPathLayout = new BorderLayout();
00193                                                 pnlPathLayout.setHgap(5);
00194                                                 pnlPath.setLayout(pnlPathLayout);
00195                                                 pnlPath.setPreferredSize(new java.awt.Dimension(512, 40));
00196                                                 {
00197                                                         lblPath = new JLabel();
00198                                                         pnlPath.add(lblPath, BorderLayout.WEST);
00199                                                         lblPath.setText("Select Script:");
00200                                                         lblPath.setPreferredSize(new java.awt.Dimension(81, 14));
00201                                                 }
00202                                                 {
00203                                                         txtPath = new JTextField();
00204                                                         pnlPath.add(txtPath, BorderLayout.CENTER);
00205                                                         txtPath.setPreferredSize(new java.awt.Dimension(325, 22));
00206                                                         txtPath.setSize(72, 22);
00207                                                 }
00208                                                 {
00209                                                         btnPath = new JButton();
00210                                                         pnlPath.add(btnPath, BorderLayout.EAST);
00211                                                         btnPath.setText("Browse");
00212                                                         btnPath.setPreferredSize(new java.awt.Dimension(85, 22));
00213                                                         btnPath.setSize(72, 22);
00214                                                         btnPath.addActionListener(new ActionListener() {
00215                                                                 public void actionPerformed(ActionEvent evt) {
00216                                                                         btnPathActionPerformed(evt);
00217                                                                 }
00218                                                         });
00219                                                 }
00220                                                 {
00221                                                         pnlPathNorth = new JPanel();
00222                                                         pnlPath.add(pnlPathNorth, BorderLayout.NORTH);
00223                                                 }
00224                                                 {
00225                                                         pnlPathSouth = new JPanel();
00226                                                         pnlPath.add(pnlPathSouth, BorderLayout.SOUTH);
00227                                                 }
00228                                         }
00229                                 }
00230                                 {
00231                                         pnlValid = new JPanel();
00232                                         FlowLayout pnlValidLayout = new FlowLayout();
00233                                         pnlValidLayout.setAlignment(FlowLayout.RIGHT);
00234                                         pnlValid.setLayout(pnlValidLayout);
00235                                         pnlMain.add(pnlValid, BorderLayout.SOUTH);
00236                                         pnlValid.setPreferredSize(new java.awt.Dimension(512, 33));
00237                                         {
00238                                                 btnCancel = new JButton();
00239                                                 pnlValid.add(btnCancel);
00240                                                 btnCancel.setText("Cancel");
00241                                                 btnCancel.setPreferredSize(new java.awt.Dimension(
00242                                                         75,
00243                                                         22));
00244                                                 btnCancel.addActionListener(new ActionListener() {
00245                                                         public void actionPerformed(ActionEvent evt) {
00246                                                                 btnCancelActionPerformed(evt);
00247                                                         }
00248                                                 });
00249                                         }
00250                                         {
00251                                                 btnStart = new JButton();
00252                                                 pnlValid.add(btnStart);
00253                                                 btnStart.setText("Start");
00254                                                 btnStart
00255                                                         .setPreferredSize(new java.awt.Dimension(75, 22));
00256                                                 btnStart.setToolTipText("Create et launch the defined task");
00257                                                 btnStart.addActionListener(new ActionListener() {
00258                                                         public void actionPerformed(ActionEvent evt) {
00259                                                                 btnStartActionPerformed(evt);
00260                                                         }
00261                                                 });
00262                                         }
00263                                 }
00264                         }
00265                         
00266                         this.addWindowListener(new WindowAdapter() {
00267                                 public void windowClosing(WindowEvent e) {
00268                                         state = DialogTask.CANCEL;
00269                                 }
00270                         });
00271                         
00272                         this.setTitle("Open Scilab Task");
00273                         this.setSize(520, 354);
00274                 } catch (Exception e) {
00275                         e.printStackTrace();
00276                 }
00277         }
00278         
00279         private void btnPathActionPerformed(ActionEvent evt) {
00280                 
00281                 if (this.chooserScript.showOpenDialog(this) != JFileChooser.APPROVE_OPTION) {
00282                         return;
00283                 }
00284                         
00285                 this.txtPath.setText(this.chooserScript.getSelectedFile().getAbsolutePath());
00286         }
00287         
00288         private void btnCancelActionPerformed(ActionEvent evt) {
00289                 
00290                 this.state = DialogTask.CANCEL;
00291                 this.setVisible(false);
00292         }
00293 
00294         private void btnStartActionPerformed(ActionEvent evt) {
00295                 state = DialogTask.VALIDATE;
00296                 this.setVisible(false);
00297         }
00298 
00299         public int getState() {
00300                 return state;
00301         }
00302         
00303         public String getPath(){
00304                 return this.txtPath.getText();
00305         }
00306         
00307         public String getJobInit(){
00308                 return  this.txtInit.getText();
00309         }
00310         
00311         public String[] getDataOut(){
00312                 return this.txtOutParam.getText().split(";");
00313         }
00314 
00315         public void setState(int state) {
00316                 this.state = state;
00317         }
00318         
00319         public String getTaskPriority(){
00320                 return (String) this.cmbPriority.getSelectedItem();
00321         }
00322 }

Generated on Mon Jan 22 15:16:10 2007 for ProActive by  doxygen 1.5.1