import WebFlow.FileBrowser.*; import java.util.*; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import java.awt.GridLayout; import java.awt.event.WindowListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Enumeration; import java.awt.*; import java.awt.event.*; import java.lang.*; import java.util.*; import java.io.*; import java.net.*; import org.omg.CORBA.*; public class FileBrowserCtr extends JInternalFrame implements ActionListener { public FileBrowser fileBrowser; private FileBrowserListener listener = null; public static String FILESEPARATOR = "/"; int sbh=2; private String CurrentFile,CurrentFileName,CurrentDirectory; public FileBrowserCtr (String directory, FileBrowser file_browser) { super("FileBrowser", true, true, true, true); fileBrowser = file_browser; FILESEPARATOR = file_browser.getFileSeparator(); FBFileTreeModel root = new FBFileTreeModel(directory, this); refreshFileBrowser(root, directory); System.out.println("FileBrowserCtr is constructed"); } public FileBrowserCtr (String directory, FileBrowser file_browser, FileBrowserListener aListener) { super("FileBrowser", true, true, true, true); fileBrowser = file_browser; FILESEPARATOR = file_browser.getFileSeparator(); listener = aListener; FBFileTreeModel root = new FBFileTreeModel(directory, this); refreshFileBrowser(root, directory); System.out.println("FileBrowserCtr is constructed"); } public void refreshFileBrowser(FBFileTreeModel root,String rootName) { //remove all the components inside the Panel removeAll(); GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints c = new GridBagConstraints(); setLayout(gridbag); FBselectedFile file_field = new FBselectedFile("", 15, "file", this); FBDirTree tree = new FBDirTree(root); //!!!,this); JScrollPane scrollPane = new JScrollPane(tree); tree.addMouseListener(file_field); tree.addTreeExpansionListener(root); root.addTreeModelListener(tree); JLabel label = new JLabel("Enter Path and Folder Name :"); //Row 0 addComponent(this,label,0,0,GridBagConstraints.REMAINDER,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0); final FBselectedFile directory_field=new FBselectedFile(rootName,15, "directory",this); tree.addMouseListener(directory_field); directory_field.addActionListener(root); // Row 1 addComponent(this,directory_field,0,1,GridBagConstraints.REMAINDER,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0); // Row 2 scrollPane.setSize(150,300); addComponent(this,scrollPane,0,2,GridBagConstraints.REMAINDER, sbh, GridBagConstraints.BOTH, GridBagConstraints.CENTER,1); // Row 3 label = new JLabel("Enter File Name :"); addComponent(this,label,0,sbh+2,GridBagConstraints.REMAINDER,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0); // Row 4 addComponent(this,file_field,0,sbh+3,GridBagConstraints.REMAINDER,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.CENTER,0); //Erol modifications directory_field.addActionListener(file_field); tree.addTreeExpansionListener(directory_field); tree.addTreeExpansionListener(file_field); //Erol // Row 5 JButton button = new JButton("OK"); button.addActionListener(file_field); addComponent(this, button,0,sbh+4,1,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.EAST,0); button = new JButton("View"); button.addActionListener(this); addComponent(this,button,1,sbh+4,1,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.WEST,0); button = new JButton("ULoad"); button.addActionListener(this); addComponent(this,button,0,sbh+5,1,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.WEST,0); button = new JButton("DLoad"); button.addActionListener(this); addComponent(this,button,1,sbh+5,1,1, GridBagConstraints.HORIZONTAL,GridBagConstraints.WEST,0); } public FileBrowser getFileBrowser() { return fileBrowser; }; protected void addComponent(java.awt.Container container, Component component, int gridx, int gridy, int gridwidth, int gridheight, int fill, int anchor, int weight) { LayoutManager lm =container.getLayout(); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = gridx; gbc.gridy = gridy; gbc.gridwidth = gridwidth; gbc.gridheight = gridheight; gbc.fill = fill; gbc.anchor = anchor; if(weight>0) { gbc.weightx=1.0; gbc.weighty=1.0; } container.add(component,gbc); } public static String getIORFromURL(String url) { System.out.println("Slave WebFlow is getting IOR from url:"+url); String masterServerIOR=""; String thisLine=null; try { URL u = new URL(url); DataInputStream theHTML = new DataInputStream(u.openStream()); while ((thisLine = theHTML.readLine()) != null) masterServerIOR += thisLine; } catch (MalformedURLException e) { System.out.println("FileBrowserCtr" + url + " is not a parseable URL"); System.out.println("FileBrowserCtr" + e); } catch (Exception e) { System.out.println("FileBrowserCtr" + e); } return masterServerIOR; } public String getCurrentFile(){ return CurrentFile; } public void setCurrentFile(String x){ CurrentFile = x; int i = x.lastIndexOf(FILESEPARATOR); CurrentFileName = x.substring(i + 1); CurrentDirectory = x.substring(0, i); System.out.println("file name: "+CurrentFileName); System.out.println("dir name : "+CurrentDirectory); System.out.println("file : "+CurrentFile); } private String getFileName(String msg) { JFrame frame = new JFrame(); FileDialog dial = new FileDialog(frame, "Select name of the file", FileDialog.LOAD); dial.show(); return dial.getDirectory() + dial.getFile(); /* JMDialog dial = new JMDialog("Input file name", msg); if(dial.show_modal()) return dial.getFileName(); throw new RuntimeException(); */ } public void actionPerformed(ActionEvent e) { if(listener == null) return; try { if(((JButton)e.getSource()).getLabel().equals("View")) { System.out.println("current file is "+CurrentFile); listener.view(CurrentFile, CurrentFileName); } if(((JButton)e.getSource()).getLabel().equals("ULoad")) { String remote_file = CurrentFile; String local_file = getFileName("Input source name"); System.out.println("local file = " + local_file + ", remote file = " + remote_file); listener.upload(remote_file, local_file); } if(((JButton)e.getSource()).getLabel().equals("DLoad")) { String remote_file = CurrentFile; String local_file = getFileName("Input destination name"); System.out.println("remote file = "+remote_file + ", local file = " + local_file); listener.download(local_file, remote_file); } } catch(RuntimeException ex) {}; } } class JMDialog extends JDialog implements ActionListener { private boolean isOk = false; private JTextField text_field; JMDialog(String title, String msg){ super((Frame)null, title, true); setBounds(200, 200, 400, 70); getContentPane().setLayout(new BorderLayout()); text_field = new JTextField(); getContentPane().add(text_field, BorderLayout.CENTER); JButton button = new JButton("Ok"); button.addActionListener(this); getContentPane().add(button, BorderLayout.EAST); getContentPane().add(new JLabel(msg), BorderLayout.NORTH); } public void actionPerformed(ActionEvent e) { isOk = true; hide(); } boolean show_modal() { show(); return isOk; } String getFileName() { return text_field.getText(); } public Dimension getPreferredSize() { return new Dimension(70, 200); } }