Source Code Cross Referenced for SmbHostChooser.java in  » Net » j-ftp » net » sf » jftp » gui » hostchooser » 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.hostchooser 
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:        package net.sf.jftp.gui.hostchooser;
017:
018:        import net.sf.jftp.*;
019:        import net.sf.jftp.config.*;
020:        import net.sf.jftp.gui.framework.*;
021:        import net.sf.jftp.net.*;
022:        import net.sf.jftp.system.logging.Log;
023:        import net.sf.jftp.util.*;
024:
025:        import java.awt.*;
026:        import java.awt.event.*;
027:
028:        import java.io.*;
029:
030:        import java.net.*;
031:
032:        import java.util.*;
033:
034:        import javax.swing.*;
035:
036:        public class SmbHostChooser extends HFrame implements  ActionListener,
037:                WindowListener {
038:            public static HTextField host = new HTextField("URL:",
039:                    "smb://localhost/");
040:            public static HTextField user = new HTextField("Username:", "guest");
041:
042:            //public static HTextField pass = new HTextField("Password:","none@nowhere.no");
043:            public static HPasswordField pass = new HPasswordField("Password:",
044:                    "nopasswd");
045:            JCheckBox lan = new JCheckBox("Browse LAN", true);
046:            public HTextField domain = new HTextField("Domain:    ",
047:                    "WORKGROUP");
048:            public HTextField broadcast = new HTextField("Broadcast IP:    ",
049:                    "AUTO");
050:            public HTextField wins = new HTextField("WINS Server IP:    ",
051:                    "NONE");
052:
053:            //public HTextField ip = new HTextField("Local IP:    ","<default>");
054:            public JComboBox ip = new JComboBox();
055:            private HPanel okP = new HPanel();
056:            private HButton ok = new HButton("Connect");
057:            private ComponentListener listener = null;
058:            private boolean useLocal = false;
059:
060:            public SmbHostChooser(ComponentListener l, boolean local) {
061:                listener = l;
062:                useLocal = local;
063:                init();
064:            }
065:
066:            public SmbHostChooser(ComponentListener l) {
067:                listener = l;
068:                init();
069:            }
070:
071:            public SmbHostChooser() {
072:                init();
073:            }
074:
075:            public void init() {
076:                //setSize(500, 320);
077:                setLocation(100, 150);
078:                setTitle("Smb Connection...");
079:                setBackground(okP.getBackground());
080:                getContentPane().setLayout(new GridLayout(5, 2, 5, 3));
081:
082:                //*** MY CHANGES
083:                try {
084:                    File f = new File(Settings.appHomeDir);
085:                    f.mkdir();
086:
087:                    File f1 = new File(Settings.login);
088:                    f1.createNewFile();
089:
090:                    File f2 = new File(Settings.login_def_smb);
091:                    f2.createNewFile();
092:                } catch (IOException ex) {
093:                    ex.printStackTrace();
094:                }
095:
096:                String[] login = LoadSet.loadSet(Settings.login_def_smb);
097:
098:                if ((login[0] != null) && (login.length > 1)) {
099:                    host.setText(login[0]);
100:                    user.setText(login[1]);
101:
102:                    //if (login[3] != null)
103:                    //lan.setText(login[3]);
104:                    //if (login[4] != null)
105:                    //ip.setText(login[4]);
106:                    //if (login[5] != null)
107:                    domain.setText(login[5]);
108:                }
109:
110:                /*
111:                else {
112:                        host.setText("smb://localhost/");
113:                        user.setText("guest");
114:                        domain.setText("WORKGROUP");
115:                }
116:                 */
117:                if (Settings.getStorePasswords()) {
118:                    if ((login != null) && (login.length > 2)
119:                            && (login[2] != null)) {
120:                        pass.setText(login[2]);
121:                    }
122:                } else {
123:                    pass.setText("");
124:                }
125:
126:                //***end of my changes (for this section)
127:                ip.setEditable(true);
128:
129:                getContentPane().add(host);
130:                getContentPane().add(lan);
131:                getContentPane().add(user);
132:                getContentPane().add(pass);
133:
134:                getContentPane().add(ip);
135:                getContentPane().add(domain);
136:
137:                getContentPane().add(broadcast);
138:                getContentPane().add(okP);
139:
140:                getContentPane().add(wins);
141:
142:                JTextArea t = new JTextArea();
143:                t.setLineWrap(true);
144:                t.setText("Note: URL is in form \"smb://host/\"\n"
145:                        + "and most people do not need WINS.");
146:
147:                getContentPane().add(t);
148:
149:                okP.add(ok);
150:                ok.addActionListener(this );
151:
152:                host.setEnabled(!lan.isSelected());
153:                setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
154:
155:                lan.addActionListener(this );
156:                pass.text.addActionListener(this );
157:
158:                setModal(false);
159:                setVisible(false);
160:                addWindowListener(this );
161:
162:                ip.addItem("<default>");
163:
164:                try {
165:                    Enumeration e = NetworkInterface.getNetworkInterfaces();
166:
167:                    while (e.hasMoreElements()) {
168:                        Enumeration f = ((NetworkInterface) e.nextElement())
169:                                .getInetAddresses();
170:
171:                        while (f.hasMoreElements()) {
172:                            ;
173:                            ip.addItem(((InetAddress) f.nextElement())
174:                                    .getHostAddress());
175:                        }
176:                    }
177:                } catch (Exception ex) {
178:                    Log.debug("Error determining default network interface: "
179:                            + ex);
180:
181:                    //ex.printStackTrace();
182:                }
183:
184:                //setBCast();
185:                domain.setEnabled(false);
186:                broadcast.setEnabled(false);
187:                wins.setEnabled(false);
188:
189:                ip.addActionListener(this );
190:
191:                pack();
192:                setVisible(true);
193:            }
194:
195:            private void setBCast() {
196:                try {
197:                    String tmp = ((String) ip.getSelectedItem()).trim();
198:                    String x = tmp.substring(0, tmp.lastIndexOf(".") + 1)
199:                            + "255";
200:                    broadcast.setText(x);
201:                } catch (Exception ex) {
202:                    Log.out("Error (SMBHostChooser): " + ex);
203:                }
204:            }
205:
206:            public void update() {
207:                fixLocation();
208:                setVisible(true);
209:                toFront();
210:                host.requestFocus();
211:            }
212:
213:            public void actionPerformed(ActionEvent e) {
214:                if (e.getSource() == lan) {
215:                    host.setEnabled(!lan.isSelected());
216:                } else if (e.getSource() == ip) {
217:                    if (ip.getSelectedItem().equals("<default>")) {
218:                        domain.setEnabled(false);
219:                        broadcast.setEnabled(false);
220:                        wins.setEnabled(false);
221:                    } else {
222:                        domain.setEnabled(true);
223:                        broadcast.setEnabled(true);
224:                        wins.setEnabled(true);
225:                        setBCast();
226:                    }
227:                } else if ((e.getSource() == ok)
228:                        || (e.getSource() == pass.text)) {
229:                    // Switch windows
230:                    //this.setVisible(false);
231:                    setCursor(new Cursor(Cursor.WAIT_CURSOR));
232:
233:                    SmbConnection con = null;
234:
235:                    //System.out.println(jcifs.Config.getProperty("jcifs.smb.client.laddr"));
236:                    String tmp = ((String) ip.getSelectedItem()).trim();
237:
238:                    if (!tmp.equals("") && !tmp.equals("<default>")) {
239:                        String x = tmp.trim().substring(0,
240:                                tmp.lastIndexOf(".") + 1)
241:                                + "255";
242:                        String bcast = broadcast.getText().trim();
243:
244:                        if (!bcast.equals("AUTO")) {
245:                            x = bcast;
246:                        }
247:
248:                        Log.debug("Setting LAN interface to: " + tmp + "/" + x);
249:                        jcifs.Config.setProperty("jcifs.netbios.laddr", tmp);
250:                        jcifs.Config.setProperty("jcifs.smb.client.laddr", tmp);
251:                        jcifs.Config.setProperty("jcifs.netbios.baddr", x);
252:
253:                        String y = wins.getText().trim();
254:
255:                        if (!y.equals("NONE")) {
256:                            Log.debug("Setting WINS server IP to: " + y);
257:                            jcifs.Config.setProperty("jcifs.netbios.wins", y);
258:                        }
259:                    }
260:
261:                    //System.out.println(jcifs.Config.getProperty("jcifs.smb.client.laddr"));
262:                    //JFtp.setHost(host.getText());
263:                    String htmp = host.getText().trim();
264:                    String utmp = user.getText().trim();
265:                    String ptmp = pass.getText();
266:                    String dtmp = domain.getText().trim();
267:
268:                    //***
269:                    //if(dtmp.equals("")) dtmp = null;
270:                    if (dtmp.equals("")) {
271:                        dtmp = "NONE";
272:                    }
273:
274:                    //if(lan.isSelected()) htmp = null;
275:                    if (lan.isSelected()) {
276:                        htmp = "(LAN)";
277:                    }
278:
279:                    //***save the set of selected data
280:                    SaveSet s = new SaveSet(Settings.login_def_smb, htmp, utmp,
281:                            ptmp, "", "", dtmp);
282:
283:                    //*** Now make the function call to the methos for starting 
284:                    //connections
285:                    boolean status;
286:                    int potmp = 0; //*** port number: unlikely to be needed in the future
287:
288:                    status = StartConnection.startCon("SMB", htmp, utmp, ptmp,
289:                            potmp, dtmp, useLocal);
290:
291:                    /*
292:                    try
293:                    {
294:                     con = new SmbConnection(htmp,dtmp,utmp,ptmp, ((ConnectionListener)JFtp.remoteDir));
295:
296:                     //JFtp.statusP.jftp.addConnection(htmp, con);
297:                     if(useLocal)
298:                     {
299:                             JFtp.statusP.jftp.addLocalConnection(htmp, con);
300:                        JFtp.localDir.fresh();
301:                     }
302:                     else
303:                     {
304:                              JFtp.statusP.jftp.addConnection(htmp, con);
305:                        JFtp.remoteDir.fresh();
306:                     }
307:
308:                    //JFtp.remoteDir.setCon(con);
309:                    //con.setLocalPath(JFtp.localDir.getCon().getPWD());
310:                    //con.addConnectionListener((ConnectionListener) JFtp.localDir);
311:                    //con.addConnectionListener((ConnectionListener) JFtp.remoteDir);
312:                    //JFtp.remoteDir.fresh();
313:                    }
314:                    catch(Exception ex)
315:                    {
316:                            Log.debug("Could not create SMBConnection, does this distribution come with jcifs?");
317:                    } */
318:                    setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
319:                    this .dispose();
320:                    JFtp.mainFrame.setVisible(true);
321:                    JFtp.mainFrame.toFront();
322:
323:                    if (listener != null) {
324:                        listener.componentResized(new ComponentEvent(this , 0));
325:                    }
326:                }
327:            }
328:
329:            public void windowClosing(WindowEvent e) {
330:                //System.exit(0);
331:                this .dispose();
332:            }
333:
334:            public void windowClosed(WindowEvent e) {
335:            }
336:
337:            public void windowActivated(WindowEvent e) {
338:            }
339:
340:            public void windowDeactivated(WindowEvent e) {
341:            }
342:
343:            public void windowIconified(WindowEvent e) {
344:            }
345:
346:            public void windowDeiconified(WindowEvent e) {
347:            }
348:
349:            public void windowOpened(WindowEvent e) {
350:            }
351:
352:            public Insets getInsets() {
353:                Insets std = super .getInsets();
354:
355:                return new Insets(std.top + 10, std.left + 10, std.bottom + 10,
356:                        std.right + 10);
357:            }
358:
359:            public void pause(int time) {
360:                try {
361:                    Thread.sleep(time);
362:                } catch (Exception ex) {
363:                }
364:            }
365:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.