Source Code Cross Referenced for AddBookmarks.java in  » Net » j-ftp » net » sf » jftp » gui » tasks » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » j ftp » net.sf.jftp.gui.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * This program is free software; you can redistribute it and/or
003:         * modify it under the terms of the GNU General Public License
004:         * as published by the Free Software Foundation; either version 2
005:         * of the License, or (at your option) any later version.
006:         *
007:         * This program is distributed in the hope that it will be useful,
008:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         * GNU General Public License for more details.
011:
012:         * You should have received a copy of the GNU General Public License
013:         * along with this program; if not, write to the Free Software
014:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
015:         */
016:
017:        //NOTE TO SELF: use setModal here somewhere?
018:        package net.sf.jftp.gui.tasks;
019:
020:        import net.sf.jftp.*;
021:        import net.sf.jftp.config.*;
022:        import net.sf.jftp.gui.framework.*;
023:        import net.sf.jftp.net.*;
024:        import net.sf.jftp.system.StringUtils;
025:        import net.sf.jftp.util.*;
026:
027:        import java.awt.*;
028:        import java.awt.event.*;
029:
030:        import java.io.*;
031:
032:        import javax.swing.*;
033:
034:        public class AddBookmarks extends HFrame implements  ActionListener,
035:                WindowListener {
036:            private static JFtp jftp;
037:            private HButton add = new HButton("Add Bookmark");
038:            private HButton addAndConnect = new HButton(
039:                    "Add Bookmark and Connect to Server");
040:
041:            //public JComboBox protocols = new JComboBox();
042:            public HComboBox protocols = new HComboBox("Protocol:");
043:            public HTextField host = new HTextField("Hostname:", "localhost");
044:            public HTextField user = new HTextField("Username:", "anonymous");
045:            public HPasswordField pass = new HPasswordField("Password:",
046:                    "none@nowhere.no");
047:            public HTextField port = new HTextField("Port:    ", "21");
048:            public HTextField dirOrDom = new HTextField(
049:                    "Directory/Domain:    ", "");
050:
051:            //public JComboBox isLocal = new JComboBox();
052:            public HComboBox isLocal = new HComboBox("Local Connection:");
053:
054:            //private ActionListener protocolListener = new ActionListener();
055:            //private FlowLayout fl = new FlowLayout(FlowLayout.RIGHT, 10, 5);
056:            public AddBookmarks(ComponentListener l, JFtp jftp) {
057:                //listener = l;
058:                this .jftp = jftp;
059:                init();
060:            }
061:
062:            public AddBookmarks(JFtp jftp) {
063:                this .jftp = jftp;
064:                init();
065:            }
066:
067:            public void init() {
068:                setSize(650, 400);
069:                setLocation(50, 150);
070:                setTitle("Add Bookmarks...");
071:
072:                //setBackground(okP.getBackground());   
073:                getContentPane().setLayout(new GridLayout(8, 1));
074:
075:                getContentPane().add(protocols);
076:                getContentPane().add(host);
077:                getContentPane().add(port);
078:
079:                getContentPane().add(user);
080:                getContentPane().add(pass);
081:
082:                getContentPane().add(dirOrDom);
083:
084:                getContentPane().add(isLocal);
085:
086:                //getContentPane().add(new FlowLayout(FlowLayout.RIGHT, 10, 5));
087:                //getContentPane().add(fl);
088:                //fl.add(add);
089:                Panel buttonPanel = new Panel(new FlowLayout(FlowLayout.CENTER,
090:                        5, 20));
091:
092:                getContentPane().add(buttonPanel);
093:                buttonPanel.add(add);
094:                buttonPanel.add(addAndConnect);
095:
096:                /*
097:                getContentPane().add(add);
098:                getContentPane().add(addAndConnect);
099:                 */
100:                add.addActionListener(this );
101:                addAndConnect.addActionListener(this );
102:
103:                //port.setEnabled(false);
104:                protocols.setEditable(false);
105:                protocols.addItem("FTP");
106:                protocols.addItem("SFTP");
107:                protocols.addItem("SMB");
108:                protocols.addItem("NFS");
109:
110:                protocols.addActionListener(this );
111:
112:                //protocols.addActionListener();
113:                isLocal.setEditable(false);
114:                isLocal.addItem("No");
115:                isLocal.addItem("Yes");
116:            }
117:
118:            public void update() {
119:                setVisible(true);
120:                toFront();
121:            }
122:
123:            public void windowClosing(WindowEvent e) {
124:                //System.exit(0);
125:                this .dispose();
126:            }
127:
128:            public void windowClosed(WindowEvent e) {
129:            }
130:
131:            public void windowActivated(WindowEvent e) {
132:            }
133:
134:            public void windowDeactivated(WindowEvent e) {
135:            }
136:
137:            public void windowIconified(WindowEvent e) {
138:            }
139:
140:            public void windowDeiconified(WindowEvent e) {
141:            }
142:
143:            public void windowOpened(WindowEvent e) {
144:            }
145:
146:            public void actionPerformed(ActionEvent e) {
147:                if (e.getSource() == add) {
148:                    getData(false);
149:                }
150:
151:                else if (e.getSource() == addAndConnect) {
152:                    getData(true);
153:                }
154:
155:                //FOR NOW: only other possible event is update of the protocol ComboBox
156:                else {
157:                    String s = new String("");
158:
159:                    //s = (String) protocols.getSelectedItem()
160:                    s = protocols.getSelectedItem().toString();
161:                    System.out.println(s);
162:
163:                    //need to put information on what each protocol accepts 
164:                    //elsewhere to make it universally accessible to all routines 
165:                    //that need this info?
166:                    if (s.equals("FTP")) {
167:                        port.setEnabled(true);
168:                        user.setEnabled(true);
169:                        pass.setEnabled(true);
170:                        dirOrDom.setEnabled(true);
171:                    } else if (s.equals("SFTP")) {
172:                        port.setEnabled(true);
173:                        user.setEnabled(true);
174:                        pass.setEnabled(true);
175:                        dirOrDom.setEnabled(false);
176:                    }
177:
178:                    else if (s.equals("SMB")) {
179:                        port.setEnabled(false);
180:                        user.setEnabled(true);
181:                        pass.setEnabled(true);
182:                        dirOrDom.setEnabled(true);
183:                    }
184:
185:                    //can assume this is NFS for now
186:                    else {
187:                        port.setEnabled(false);
188:                        user.setEnabled(true);
189:                        pass.setEnabled(true);
190:                        dirOrDom.setEnabled(false);
191:                    }
192:
193:                    //System.out.println("yes!");
194:                }
195:
196:                //OK event
197:            }
198:
199:            //actionPerformed
200:            private void getData(boolean andConnect) {
201:                String protocoltmp = new String("");
202:
203:                //here, get the selected protocol
204:                //s = (String) protocols.getSelectedItem()
205:                protocoltmp = protocols.getSelectedItem().toString();
206:
207:                //System.out.println(s);
208:                System.out.println("test");
209:
210:                //what happens next: get data on protocol, and based on the data
211:                //for the protocol, get what's needed for each field.
212:                //the data extraction from each field can actually be put in a 
213:                //separate private method which could also be accessed if the
214:                //connection is to be initiated here
215:                //then, need a routine to open the bookmark file, then append it
216:                //to the end (add a blank line, then the data, separated by the
217:                //hash/sharp (#) comment) (and should it be here, or should only
218:                //one class know about it. Or maybe it can just refer to the config
219:                //file
220:                //don't need to get  all this, it depends on the protocol
221:                //***IMPORTANT NOTE!!!!: LAN BROWSING SHOULD BE SPEAPRTE PROTOCOL! 
222:                //ALSO IMPORTANT: can refer to JFtp.hostinfo.hostname, for current
223:                //hostname, JFtp.hostinfo.type for prortocol, etc... refer to 
224:                //code in HostChooser.java that says this, but might not be the
225:                //case for SFTP
226:                //FTP: get all of it
227:                //SFTP: All but dirOrDom? (SFTP doesn;t seem to support that at this time)
228:                //SMB: Don't get port
229:                //NFS: Don;t get port or dirOrDom
230:                //FOR NOW: just get all data
231:
232:                /*
233:                String htmp = StringUtils.cut(host.getText(), " ");
234:                String utmp = StringUtils.cut(user.getText(), " ");
235:                String ptmp = StringUtils.cut(pass.getText(), " ");
236:                String potmp = StringUtils.cut(port.getText(), " ");
237:
238:                String dirOrDomtmp = StringUtils.cut(dirOrDom.getText(), " ");
239:                 */
240:                String htmp = checkIfEmpty(StringUtils.cut(host.getText(), " "));
241:                String utmp = checkIfEmpty(StringUtils.cut(user.getText(), " "));
242:                String ptmp = checkIfEmpty(StringUtils.cut(pass.getText(), " "));
243:                String potmp = checkIfEmpty(StringUtils
244:                        .cut(port.getText(), " "));
245:
246:                String dirOrDomtmp = checkIfEmpty(StringUtils.cut(dirOrDom
247:                        .getText(), " "));
248:
249:                String local = new String("");
250:
251:                Integer potmpInt = new Integer(potmp);
252:                int potmpint = potmpInt.intValue();
253:
254:                local = isLocal.getSelectedItem().toString();
255:
256:                String localString = new String("");
257:
258:                boolean localtmp = false;
259:
260:                if (local.equals("true")) {
261:                    localtmp = true;
262:                    localString = "true";
263:                } else {
264:                    localtmp = false;
265:                    localString = "false";
266:                }
267:
268:                //first, build the string which is to be appended to end
269:                //of bookmark file
270:                // protocol#host#user#password#port#dir/domain#local
271:                String addedString = new String("");
272:
273:                addedString += (protocoltmp + "#");
274:                addedString += (htmp + "#");
275:                addedString += (utmp + "#");
276:
277:                addedString += (ptmp + "#");
278:                addedString += (potmp + "#");
279:                addedString += (dirOrDomtmp + "#");
280:                addedString += localString;
281:
282:                //here, start the routine for appending the line to the bookmark
283:                //file (SHOULD IT BE IN A SEPARATE ROUTINE?)
284:                try {
285:                    FileOutputStream fos;
286:                    PrintStream out;
287:
288:                    fos = new FileOutputStream(Settings.bookmarks, true);
289:                    out = new PrintStream(fos);
290:
291:                    //commented out, just for now
292:                    out.println(addedString);
293:                    out.println("");
294:
295:                    //if it worked, update the menu
296:                    jftp.menuBar.loadBookmarks();
297:                } catch (Exception e) {
298:                    e.printStackTrace();
299:                }
300:
301:                if (andConnect) {
302:                    if (protocoltmp.equals("FTP")) {
303:                        StartConnection.startFtpCon(htmp, utmp, ptmp, potmpint,
304:                                dirOrDomtmp, localtmp);
305:                    } else {
306:                        StartConnection.startCon(protocoltmp, htmp, utmp, ptmp,
307:                                potmpint, dirOrDomtmp, localtmp);
308:                    }
309:                }
310:
311:                //else {
312:                //}
313:                this .dispose();
314:
315:                //this.setVisible(false);
316:                JFtp.mainFrame.setVisible(true);
317:                JFtp.mainFrame.toFront();
318:            }
319:
320:            //getData
321:            private String checkIfEmpty(String value) {
322:                String retVal = new String("0");
323:
324:                if (value.equals("")) {
325:                    return retVal;
326:                } else {
327:                    return value;
328:                }
329:            }
330:
331:            //checkIfEmpty
332:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.