KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > lucane > applications > sendfile > SendFileDialog


1 /*
2  * Lucane - a collaborative platform
3  * Copyright (C) 2004 Vincent Fiack <vfiack@mail15.com>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19 package org.lucane.applications.sendfile;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Dimension JavaDoc;
23 import java.awt.GridLayout JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26
27 import javax.swing.*;
28
29 import org.lucane.client.Client;
30 import org.lucane.client.widgets.HTMLEditor;
31 import org.lucane.client.widgets.ManagedWindow;
32
33 public class SendFileDialog extends ManagedWindow
34 implements ActionListener JavaDoc
35 {
36     private SendFile plugin;
37     private boolean start;
38     
39     private JTextField filePath;
40     private HTMLEditor comment;
41
42     //sender
43
private JButton btnSend;
44     private JButton btnCancel;
45     private JButton btnSelect;
46     
47     //receiver
48
private JButton btnSave;
49     private JButton btnOpen;
50     private JButton btnOpenOther;
51     private JButton btnReject;
52     
53     public SendFileDialog(SendFile plugin, String JavaDoc title, boolean start)
54     {
55         super(plugin, title);
56         this.plugin = plugin;
57         this.start = start;
58         
59         initComponents();
60         setPreferredSize(new Dimension JavaDoc(500, 300));
61         setName("dialog");
62     }
63     
64     private void initComponents()
65     {
66         getContentPane().setLayout(new BorderLayout JavaDoc());
67         
68         //file selection panel
69
JPanel filePanel = new JPanel(new BorderLayout JavaDoc());
70         filePanel.add(new JLabel(plugin.tr("lbl.file")), BorderLayout.WEST);
71         filePath = new JTextField("");
72         filePath.setEditable(false);
73         filePanel.add(filePath, BorderLayout.CENTER);
74         if(start)
75         {
76             btnSelect = new JButton(plugin.tr("btn.select"));
77             btnSelect.addActionListener(this);
78             filePanel.add(btnSelect, BorderLayout.EAST);
79         }
80         getContentPane().add(filePanel, BorderLayout.NORTH);
81
82         //comment zone
83
comment = new HTMLEditor();
84         comment.setBorder(BorderFactory.createTitledBorder(plugin.tr("lbl.comment")));
85         if(!start)
86         {
87             comment.setEditable(false);
88             comment.setToolbarVisible(false);
89         }
90         getContentPane().add(comment, BorderLayout.CENTER);
91         
92         //button pannel
93
JPanel buttonPanel = new JPanel(new BorderLayout JavaDoc());
94         JPanel buttons = null;
95         if(start)
96         {
97             buttons = new JPanel(new GridLayout JavaDoc(1, 2));
98             btnSend = new JButton(plugin.tr("btn.send"), Client.getImageIcon("ok.png"));
99             btnCancel = new JButton(plugin.tr("btn.cancel"), Client.getImageIcon("cancel.png"));
100             btnSend.addActionListener(this);
101             btnCancel.addActionListener(this);
102             buttons.add(btnSend);
103             buttons.add(btnCancel);
104         }
105         else
106         {
107             String JavaDoc command = plugin.getShortCommand();
108             
109             buttons = new JPanel(new GridLayout JavaDoc(1, 0));
110             btnSave = new JButton(plugin.tr("btn.save"), Client.getImageIcon("ok.png"));
111             btnSave.addActionListener(this);
112             buttons.add(btnSave);
113             
114             if(command != null)
115             {
116                 btnOpen = new JButton(command, Client.getImageIcon("open.png"));
117                 btnOpen.setToolTipText(plugin.getCommand());
118                 btnOpen.addActionListener(this);
119                 buttons.add(btnOpen);
120             }
121             
122             btnOpenOther = new JButton(plugin.tr("btn.open"), Client.getImageIcon("open.png"));
123             btnOpenOther.addActionListener(this);
124             buttons.add(btnOpenOther);
125
126             btnReject = new JButton(plugin.tr("btn.reject"), Client.getImageIcon("cancel.png"));
127             btnReject.addActionListener(this);
128             buttons.add(btnReject);
129         }
130         buttonPanel.add(buttons, BorderLayout.EAST);
131         getContentPane().add(buttonPanel, BorderLayout.SOUTH);
132     }
133     
134     public void setFilePath(String JavaDoc filePath)
135     {
136         this.filePath.setText(filePath);
137     }
138     
139     public String JavaDoc getFilePath()
140     {
141         return this.filePath.getText();
142     }
143     
144     public void setComment(String JavaDoc html)
145     {
146         this.comment.setText(html);
147     }
148     
149     public String JavaDoc getComment()
150     {
151         return this.comment.getText();
152     }
153     
154     public void actionPerformed(ActionEvent JavaDoc ae)
155     {
156         if(ae.getSource() == btnCancel)
157             dispose();
158         else if(ae.getSource() == btnReject)
159             plugin.rejectFile();
160         else if(ae.getSource() == btnSave)
161         {
162             Runnable JavaDoc r = new Runnable JavaDoc() {
163                 public void run() {
164                     plugin.saveFile();
165                 }
166             };
167             new Thread JavaDoc(r).start();
168         }
169         else if(ae.getSource() == btnOpen)
170         {
171             Runnable JavaDoc r = new Runnable JavaDoc() {
172                 public void run() {
173                     plugin.openFile();
174                 }
175             };
176             new Thread JavaDoc(r).start();
177         }
178         else if(ae.getSource() == btnOpenOther)
179         {
180             if(plugin.selectCommand() != null)
181             {
182                 Runnable JavaDoc r = new Runnable JavaDoc() {
183                     public void run() {
184                         plugin.openFile();
185                     }
186                 };
187                 new Thread JavaDoc(r).start();
188             }
189         }
190         else if(ae.getSource() == btnSelect)
191             plugin.selectFile(this);
192         else if(ae.getSource() == btnSend)
193         {
194             Runnable JavaDoc r = new Runnable JavaDoc() {
195                 public void run() {
196                     plugin.askForAccept(getFilePath(), getComment());
197                 }
198             };
199             new Thread JavaDoc(r).start();
200         }
201     }
202 }
Popular Tags