www.pudn.com > htmlsaver.rar > NameGroupLink.java
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class NameGroupLink implements ActionListener
{
protected Vector urls;
protected Vector names;
protected JDialog dialog;
protected JTable table;
protected NameModel model;
protected JButton start;
protected JButton finish;
protected JButton cancel;
protected boolean isFinish;
public NameGroupLink(Vector urls, JFrame owner)
{
this.urls = urls;
names = new Vector();
for (int i = 0; i < this.urls.size(); i++)
names.add(new String(""));
dialog = new JDialog(owner, "Name Group Links", true);
isFinish = false;
initDialog();
}
public NameGroupLink(Vector urls, JDialog owner)
{
this.urls = urls;
names = new Vector();
for (int i = 0; i < this.urls.size(); i++)
names.add(new String(""));
dialog = new JDialog(owner, "Name Group Links", true);
isFinish = false;
initDialog();
}
public Vector getName()
{
if (isFinish)
return names;
else
return null;
}
protected void initDialog()
{
dialog.getContentPane().setLayout(new BorderLayout());
model = new NameModel();
table = new JTable(model);
dialog.getContentPane().add(new JScrollPane(table), BorderLayout.CENTER);
TableColumn column = null;
column = table.getColumnModel().getColumn(0);
column.setPreferredWidth(300);
column = table.getColumnModel().getColumn(1);
column.setPreferredWidth(150);
JPanel panel = new JPanel(new GridLayout(1, 3));
start = new JButton("开始");
start.addActionListener(this);
panel.add(start);
finish = new JButton("完成");
finish.addActionListener(this);
panel.add(finish);
cancel = new JButton("放弃");
cancel.addActionListener(this);
panel.add(cancel);
dialog.getContentPane().add(panel, BorderLayout.SOUTH);
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setSize(500, 300);
dialog.show();
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == start)
{
startName();
}
else if (e.getSource() == finish)
{
isFinish = true;
dialog.hide();
}
else if (e.getSource() == cancel)
{
for (int i = 0; i < names.size(); i++)
names.set(i, new String(""));
dialog.hide();
}
}
class NameModel extends AbstractTableModel
{
String[] columnNames = {"URL", "File Name"};
public String getColumnName(int col) {
return columnNames[col].toString();
}
public int getRowCount() { return urls.size(); }
public int getColumnCount() { return 2; }
public Object getValueAt(int row, int col) {
if (col == 0)
return urls.elementAt(row);
else
return names.elementAt(row);
}
public void refresh()
{
this.fireTableDataChanged();
}
}
protected void startName()
{
int row = table.getSelectedRow();
if (row < 0)
row = 0;
SetFileNameOfURL set = new SetFileNameOfURL(
new GetNameFromURL((String)urls.elementAt(row)), dialog);
if (!set.isFinished())
return;
for (int i = 0; i < urls.size(); i++)
{
String name = set.getNameOf((String)urls.elementAt(i));
names.set(i, name);
}
model.refresh();
}
public static void main(String[] args)
{
Vector link = new Vector();
link.add("http://djxh.tzc.edu.cn/nwk/vcl/vcl1.htm");
link.add("http://djxh.tzc.edu.cn/nwk/vcl/vcl2.htm");
link.add("http://djxh.tzc.edu.cn/nwk/vcl/vcl3.htm");
link.add("http://djxh.tzc.edu.cn/nwk/vcl/vcl4.htm");
new NameGroupLink(link, new JFrame());
}
}