org/objectweb/proactive/ext/scilab/gui/DialogResult.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 
00033 import java.awt.BorderLayout;
00034 import java.awt.FlowLayout;
00035 import java.awt.event.ActionEvent;
00036 import java.awt.event.ActionListener;
00037 import java.io.File;
00038 import java.io.FileWriter;
00039 import java.io.IOException;
00040 
00041 import javax.swing.BorderFactory;
00042 import javax.swing.JButton;
00043 import javax.swing.JFileChooser;
00044 import javax.swing.JFrame;
00045 import javax.swing.JLabel;
00046 import javax.swing.JPanel;
00047 import javax.swing.JScrollPane;
00048 import javax.swing.JTextArea;
00049 import javax.swing.JTextField;
00050 
00063 public class DialogResult extends javax.swing.JDialog {
00064         private JPanel pnlMain;
00065         private JLabel lblPath;
00066         private JPanel pnlPath;
00067         private JPanel pnlOutParam;
00068         private JScrollPane scrollInit;
00069         private JTextField txtPath;
00070         private JPanel pnlPathSouth;
00071         private JPanel pnlPathNorth;
00072         private JTextArea txtInit;
00073         private JFileChooser chooserSave;
00074         private JButton btnQuit;
00075         private JButton btnSave;
00076         private JTextArea txtOutParam;
00077         private JScrollPane scrollOutParam;
00078         private JPanel pnlQuit;
00079         private JPanel pnlInit;
00080         private JPanel pnlTask;
00081 
00082         public DialogResult(JFrame frame) {
00083                 super(frame);
00084                  initGUI();
00085         }
00086         
00087         private void initGUI() {
00088                 try {
00089                         {
00090                                 chooserSave = new JFileChooser();
00091                                 chooserSave.setDialogTitle("Save Scilab Result");       
00092                         }
00093                         {
00094                                 pnlMain = (JPanel) getContentPane();
00095                                 BorderLayout pnlMainLayout = new BorderLayout();
00096                                 pnlMain.setLayout(pnlMainLayout);
00097                                 pnlMain.setSize(new java.awt.Dimension(510, 560));
00098                                 {
00099                                         pnlTask = new JPanel();
00100                                         BorderLayout pnlTaskLayout = new BorderLayout();
00101                                         pnlMain.add(pnlTask, BorderLayout.CENTER);
00102                                         pnlTask.setLayout(pnlTaskLayout);
00103                                         pnlTask.setSize(new java.awt.Dimension(510, 635));
00104                                         {
00105                                                 pnlInit = new JPanel();
00106                                                 BorderLayout pnlInitLayout = new BorderLayout();
00107                                                 pnlTask.add(pnlInit, BorderLayout.NORTH);
00108                                                 
00109                                                 pnlInit.setLayout(pnlInitLayout);
00110                                                 pnlInit.setSize(570, 235);
00111                                                 pnlInit.setBorder(BorderFactory.createTitledBorder("Initialize Script"));
00112                                                 {
00113                                                         scrollInit = new JScrollPane();
00114                                                         pnlInit.add(scrollInit, BorderLayout.CENTER);
00115                                                         scrollInit.setPreferredSize(new java.awt.Dimension(500, 210));
00116                                                         scrollInit.setSize(500, 210);
00117                                                         {
00118                                                                 txtInit = new JTextArea();
00119                                                                 scrollInit.setViewportView(txtInit);
00120                                                                 txtInit.setEditable(false);
00121                                                                 txtInit.setEnabled(false);
00122                                                         }
00123                                                 }
00124                                         }
00125                                         {
00126                                                 pnlOutParam = new JPanel();
00127                                                 BorderLayout pnlOutParamLayout = new BorderLayout();
00128                                                 pnlTask.add(pnlOutParam, BorderLayout.CENTER);
00129                                                 pnlOutParam.setLayout(pnlOutParamLayout);
00130                                                 pnlOutParam.setBorder(BorderFactory.createTitledBorder("Out Parameters"));
00131                                                 {
00132                                                         
00133                                                         {
00134                                                                 scrollOutParam = new JScrollPane();
00135                                                                 pnlOutParam.add(scrollOutParam, BorderLayout.CENTER);
00136                                                                 scrollOutParam.setPreferredSize(new java.awt.Dimension(553, 256));
00137                                                                 scrollOutParam.setSize(500, 210);
00138 
00139                                                                 {
00140                                                                         txtOutParam = new JTextArea();
00141                                                                         scrollOutParam.setViewportView(txtOutParam);
00142                                                                         txtOutParam.setEditable(false);
00143                                                                 }
00144                                                         }
00145                                                 }
00146                                         }
00147                                 }
00148                                 {
00149                                         pnlQuit = new JPanel();
00150                                         FlowLayout pnlQuitLayout = new FlowLayout();
00151                                         pnlQuitLayout.setAlignment(FlowLayout.RIGHT);
00152                                         pnlMain.add(pnlQuit, BorderLayout.SOUTH);
00153                                         pnlQuit.setLayout(pnlQuitLayout);
00154                                         pnlQuit.setPreferredSize(new java.awt.Dimension(571, 32));
00155                                         {
00156                                                 btnSave = new JButton();
00157                                                 pnlQuit.add(btnSave);
00158                                                 btnSave.setText("Save");
00159                                                 btnSave.addActionListener(new ActionListener() {
00160                                                         public void actionPerformed(ActionEvent evt) {
00161                                                                 btnSaveActionPerformed(evt);
00162                                                         }
00163                                                 });
00164                                         }
00165                                         {
00166                                                 btnQuit = new JButton();
00167                                                 pnlQuit.add(btnQuit);
00168                                                 btnQuit.setText("Quit");
00169                                                 btnQuit.addActionListener(new ActionListener() {
00170                                                         public void actionPerformed(ActionEvent evt) {
00171                                                                 btnQuitActionPerformed(evt);
00172                                                         }
00173                                                 });
00174                                         }
00175                                 }
00176                                 {
00177                                         pnlPath = new JPanel();
00178                                         pnlMain.add(pnlPath, BorderLayout.NORTH);
00179                                         BorderLayout pnlPathLayout = new BorderLayout();
00180                                         pnlPathLayout.setHgap(5);
00181                                         pnlPath.setLayout(pnlPathLayout);
00182                                         
00183 
00184                                         {
00185                                                 lblPath = new JLabel();
00186                                                 lblPath.setLayout(null);
00187                                                 pnlPath.add(lblPath, BorderLayout.WEST);
00188                                                 lblPath.setText("Select Script:");
00189                                                 lblPath.setSize(new java.awt.Dimension(90, 14));
00190                                                 lblPath.setPreferredSize(new java.awt.Dimension(81, 23));
00191                                                 
00192                                         }
00193                                         {
00194                                                 txtPath = new JTextField();
00195                                                 pnlPath.add(txtPath, BorderLayout.CENTER);
00196                                                 txtPath.setEditable(false);
00197                                                 txtPath.setEnabled(false);
00198                                                 txtPath.setSize(380, 15);
00199                                                 txtPath
00200                                                         .setPreferredSize(new java.awt.Dimension(494, 15));
00201                                         }
00202                                         {
00203                                                 pnlPathNorth = new JPanel();
00204                                                 pnlPath.add(pnlPathNorth, BorderLayout.NORTH);
00205                                         }
00206                                         {
00207                                                 pnlPathSouth = new JPanel();
00208                                                 pnlPath.add(pnlPathSouth, BorderLayout.SOUTH);
00209                                         }
00210                                 }
00211                         }
00212                         
00213                         this.setTitle("Display Scilab Result");
00214                         this.setSize(579, 614);
00215                 } catch (Exception e) {
00216                         e.printStackTrace();
00217                 }
00218         }
00219         
00220         private void btnSaveActionPerformed(ActionEvent evt) {
00221                 
00222                 if (this.chooserSave.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) {
00223                         return;
00224                 }
00225                 
00226                 File f = this.chooserSave.getSelectedFile().getAbsoluteFile();
00227                 if(f.exists() && !f.canWrite()){
00228                         return;
00229                 }
00230         
00231                 try{
00232                         FileWriter fw = new FileWriter(f);
00233                         fw.write(this.txtOutParam.getText());
00234                         fw.close();
00235                         
00236                 }catch(IOException e){
00237                         e.printStackTrace();
00238                 }
00239         
00240         }
00241         
00242         public void setSaveEnable(boolean isEnable){
00243                 this.btnSave.setEnabled(isEnable);
00244         }
00245         
00246         private void btnQuitActionPerformed(ActionEvent evt) {
00247                 this.setVisible(false);
00248         }
00249         
00250         public void setPathScript(String pathScript){
00251                 this.txtPath.setText(pathScript);
00252         }
00253         
00254         public void setJobInit(String jobInit){
00255                 this.txtInit.setText(jobInit);
00256         }
00257         
00258         public void setDataOut(String dataOut){
00259                 this.txtOutParam.setText(dataOut);
00260         }
00261 
00262 }

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