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.tasks;
017:
018: import net.sf.jftp.*;
019: import net.sf.jftp.config.*;
020: import net.sf.jftp.gui.framework.*;
021: import net.sf.jftp.system.logging.Log;
022: import net.sf.jftp.util.*;
023:
024: import java.awt.*;
025: import java.awt.event.*;
026:
027: import java.io.*;
028:
029: import javax.swing.*;
030:
031: public class BookmarkManager extends JInternalFrame implements
032: ActionListener {
033: private JTextArea info = new JTextArea(25, 50);
034: private JButton save = new JButton("Save and close");
035: private JButton close = new JButton("Close");
036:
037: public BookmarkManager() {
038: super ("Manage Bookmarks", true, true, true, true);
039: setLocation(50, 50);
040: setSize(600, 540);
041: getContentPane().setLayout(new BorderLayout());
042:
043: load(Settings.bookmarks);
044:
045: JScrollPane jsp = new JScrollPane(info);
046: getContentPane().add("Center", jsp);
047:
048: HPanel closeP = new HPanel();
049: closeP.setLayout(new FlowLayout(FlowLayout.CENTER));
050:
051: //closeP.add(close);
052: closeP.add(save);
053:
054: close.addActionListener(this );
055: save.addActionListener(this );
056:
057: getContentPane().add("South", closeP);
058:
059: info.setCaretPosition(0);
060: pack();
061: setVisible(true);
062: }
063:
064: public void actionPerformed(ActionEvent e) {
065: if (e.getSource() == close) {
066: this .dispose();
067: } else {
068: save(Settings.bookmarks);
069: JFtp.menuBar.loadBookmarks();
070: this .dispose();
071: }
072: }
073:
074: private void setDefaultText() {
075: info.setText("");
076: info.append("# JFtp Bookmark Configuration file\n");
077: info.append("#\n");
078: info
079: .append("# Syntax: protocol#host#user#password#port#dir/domain#local\n");
080: info.append("#\n");
081: info
082: .append("# Note: not all values are used by every connection, but all fields must contain at least\n");
083: info.append("# one character.\n");
084: info
085: .append("Use \"<%hidden%>\" for password fields you don't want to fill out.");
086: info.append("#\n");
087: info.append("# protocol: FTP, SFTP, SMB or NFS (uppercase)\n");
088: info
089: .append("# host: hostname or ip for ftp + sftp, valid url for smb + nfs (\"(LAN)\" for smb lan browsing)\n");
090: info.append("# user, password: the login data\n");
091: info
092: .append("# port: this must be a number (even if it is not used for smb+nfs, set it in the url for nfs)\n");
093: info
094: .append("# dir/domain: inital directory for the connection, domainname for smb\n");
095: info
096: .append("# local: \"true\" if connection should be opened in local tab, \"false\" otherwise\n");
097: info
098: .append("# directories must be included in <dir></dir> tags and can be ended"
099: + " using a single\n# <enddir> tag");
100: info.append("#\n");
101: info.append("#\n");
102: info.append("\n<dir>JFtp</dir>\n");
103: info
104: .append("FTP#upload.sourceforge.net#anonymous#j-ftp@sf.net#21#/incoming#false\n");
105: info.append("<enddir>\n");
106: info.append("\n");
107: info
108: .append("FTP#ftp.kernel.org#anonymous#j-ftp@sf.net#21#/pub/linux/kernel/v2.6#false\n");
109: info.append("\n");
110: info.append("SMB#(LAN)#guest#guest#-1#-#false\n\n");
111: }
112:
113: private void load(String file) {
114: String data = "";
115: String now = "";
116:
117: try {
118: DataInput in = new DataInputStream(new BufferedInputStream(
119: new FileInputStream(file)));
120:
121: while ((data = in.readLine()) != null) {
122: now = now + data + "\n";
123: }
124: } catch (IOException e) {
125: Log.debug("No bookmarks.txt found, using defaults.");
126:
127: setDefaultText();
128:
129: return;
130: }
131:
132: info.setText(now);
133: }
134:
135: private void save(String file) {
136: try {
137: PrintStream out = new PrintStream(new BufferedOutputStream(
138: new FileOutputStream(file)));
139:
140: out.println(info.getText());
141: out.flush();
142: out.close();
143: } catch (IOException e) {
144: Log.debug(e + " @BookmarkManager.save()");
145: }
146: }
147:
148: public Insets getInsets() {
149: Insets std = super .getInsets();
150:
151: return new Insets(std.top + 5, std.left + 5, std.bottom + 5,
152: std.right + 5);
153: }
154: }
|