/*****************************************************************************
* $Id: URLDialog.java,v 1.1.1.1 2000/03/29 22:58:15 kkeys Exp $
*
* File: URLDialog.java Name:URLDialog
* Goal: To create a FilenameDialog that works for URLs.
* it list the contains of a url and the allow the user to
* select a given file out of those in the URL of a dir.
*
* Written: Bradley Huffaker
* For: Cooperative Association for Internet Data Analysis
******************************************************************************
******************************************************************************
By accessing this software, URLDIALOG, you are duly informed of and
agree to be bound by the conditions described below in this notice:
This software product, URLDIALOG, is developed by Bradley Huffaker, and
Jaeyeon Jung copyrighted(C) 1998 by the University of California,
San Diego (UCSD), with all rights reserved. UCSD administers the NLANR
Cache grants, NCR-9796082 and NCR-9616602, under which most of this code
was developed.
There is no charge for URLDIALOG software. You can redistribute it and/or
modify it under the terms of the GNU General Public License, v. 2 dated
June 1991 which is incorporated by reference herein. URLDIALOG is
distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use of
it will not infringe on any third party's intellectual property
rights.
You should have received a copy of the GNU GPL along with the URLDIALOG
program. Copies can also be obtained from
http://www.gnu.org/copyleft/gpl.html or by writing to
University of California, San Diego
SDSC/CAIDA/NLANR
9500 Gilman Dr., MS-0505
La Jolla, CA 92093 - 0505 USA
Or contact INFO@NLANR.NET
*****************************************************************************/
package bhuffake.plankton;
import java.awt.*;
import java.io.*;
import java.net.URL;
public class URLDialog extends Dialog
{
// Filter that test for acceptable names.
NameFilter filter = new NameFilter();
// The List that will display and allow for selection of files
List list = new List();
// The List that will display directories
List dirList = new List();
// Holds the file they selected
String file_address = null;
// Holds the url of the directory in which to look
String address = null;
String full_address;
// Displays the current directory
TextField current_dir = new TextField(" ");
String[] dirs = new String[20];
int dir_index = 0;
// Control Buttons
Button Accept = new Button("Accept");
Button Cancel = new Button("Cancel");
// Flags if a error_occured
boolean error_occured = false;
// Flag for accepted or not
boolean accpted = false;
// The number of lines read
int linenum = 0;
FileInterface parent;
public URLDialog(FileInterface parent_input, String address_input)
{
super((Frame)parent_input,"Choose Data File",true);
parent = parent_input;
address = address_input;
resize(250,200);
current_dir.setEditable(false);
Panel buttons = new Panel();
buttons.setLayout(new BorderLayout());
buttons.add("West",Accept);
buttons.add("East",Cancel);
Panel dir_panel = new Panel();
Label dir_label = new Label("Directorys");
dir_panel.setLayout(new BorderLayout());
dir_panel.add("North",dir_label);
dir_panel.add("Center",dirList);
Panel file_panel = new Panel();
Label file_label = new Label("Files");
file_panel.setLayout(new BorderLayout());
file_panel.add("North",file_label);
file_panel.add("Center",list);
setLayout(new BorderLayout());
add("North",current_dir);
add("Center",file_panel);
add("West",dir_panel);
add("South",buttons);
}
public void Show()
{
setUp();
((Window)this).show();
}
protected void setUp()
{
if (list.countItems() > 0)
list.clear();
if (dirList.countItems() > 0)
dirList.clear();
URL url = null;
InputStream is = null;
if (address == null)
{
Error("address is null");
}
else
{
full_address = "";
for(int index=0;index < dir_index;index++)
{
full_address = full_address +"/"
+ dirs[index];
}
current_dir.setText(full_address);
full_address = address + full_address;
try {
url = new URL(full_address);
is = url.openStream();
/*
} catch (MalformedURLException e0) {
Error(e0.toString());
*/
} catch (IOException e1) {
Error(e1.toString());
}
}
if (is == null)
return;
if (dir_index > 0)
dirList.addItem("..");
error_occured = false;
int length = 0;
int current_length = 0;
byte[] bytes = new byte[256];
char[] buffer = new char[256];
boolean working = true;
linenum = 0;
try {
do {
length =is.read(bytes);
//System.err.println("length:" + length + "<>" + bytes.length);
if (length < 0)
{
length = 0;
bytes[length++] = '\n';
working = false;
}
for (int offset=0; offset < length; offset++)
{
if (current_length > buffer.length)
{
char[] temp = new char[(int)(buffer.length*1.1)];
for (int index=0;index < buffer.length;index++)
temp[index] = buffer[index];
buffer = temp;
}
buffer[current_length] = (char) bytes[offset];
if (buffer[current_length] == '\n')
{
ParseString(current_length,buffer);
current_length = 0;
linenum++;
}
else
current_length++;
}
} while (working);
} catch (IOException e1) {
Error(e1.toString());
}
}
public void ParseString(int length, char[] buffer)
{
//System.err.println( "PraseString:"+length);
// Current possition in the string
int index;
// Attempt to find a directory
// a tag for 'alt="[dir]"'
boolean isDir = false;
final char[] DIR= {'a', 'l', 't', '=', '"', '[', 'd', 'i'
,'r' ,']' ,'"'};
index = match(length,buffer,0,DIR);
if (index == length)
{
index = 0;
isDir = false;
}
else
isDir = true;
// Attempt to find the HTMP tag for 0)
list.clear();
list.addItem(msg);
}
public boolean handleEvent (Event event)
{
if (event.id == Event.ACTION_EVENT)
{
if (event.target == dirList)
{
String dir = dirList.getSelectedItem();
if (dir.equals(".."))
{
if (dir_index > 0)
{
dir_index--;
setUp();
}
}
else
{
if (dir_index == dirs.length)
{
String[] temp = new String[
(int)(dirs.length*1.1)];
for(int i=0;iHoME免费一1一级做爰片在线观看
ENTER NUMBET 0018sanfangzhifu.com.cn
lifevane.com.cn
sheou.com.cn
www.cink.com.cn
wxiaov.com.cn
xqvi.com.cn
www.uwsii.com.cn
www.glll.net.cn
gnul.com.cn
ejom.com.cn