⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 newfiledialog.java

📁 一个简单的visio程序。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

package webide.itools;

import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.net.*;
import java.util.*;
import java.applet.*;
//import remoteide.ide.*;

public class NewFileDialog extends Dialog
                           implements
                                   KeyListener,
                                   MouseListener,
                                   WindowListener,
                                   ItemListener,
                                   ActionListener,
                                   TextListener{

	private ChoiceText choicetext;
    private Label label1,label2;
    private Choice choice1;
    private ListView listview;
    private Button button1,button2;
    private Panel panel2,panel3;
    private myButton button3,button4,button5,button6;

    private Applet          applet;
    public  Image[]         image     = new Image[2];
    private boolean         isok      = false;
    private String          hostname  = "localhost";
    private int             port      = 8080;
    private String          rootPath  = "";
    private String          protocol  = null;
    public NewFileDialog(Applet mm) {

        this(mm,"File Load");
    }

    public NewFileDialog(Applet mm, String title){

       super(new Frame(), title, true);

       applet = (Applet)mm;
       URL     baseUrl  = applet.getCodeBase();
       this.hostname = baseUrl.getHost();
       this.port     =baseUrl.getPort();
       this.protocol =baseUrl.getProtocol();
       if (port == -1) port = 8080;

       int NumImages = 4;
       int which = 0;
       String str[] = {"Super.gif","New.gif","List.gif","List2.gif"};
       Image img[] = new Image[NumImages];

       for (int i=0;i<NumImages;i++){
         img[i] = getImage(str[i]);  //xiaoping.
       //img[i] = Toolkit.getDefaultToolkit().getImage(str[i]);
       }
       image[0] = getImage("folder1.gif");
       image[1] = getImage("folder.gif");


       choicetext = new ChoiceText(this);
       label1 = new Label("Look in:",Label.CENTER);
       label2 = new Label("File Name:");
       choice1 = new Choice();
       listview = new ListView(this);
       button1 = new Button("    Ok    ");
       button2 = new Button("Cancel");
       panel2 = new Panel();

       panel2.setLayout(new GridLayout(1,4,5,5));

       button3 = new myButton();
       button3.setSize(25,25);
       button3.setImage(img[which]);
       button3.addMouseListener(this);
       panel2.add(button3);

       button4 = new myButton();
       button4.setImage(img[which+1]);
       button4.addMouseListener(this);
       panel2.add(button4);

       button5 = new myButton();
       button5.setImage(img[which+2]);
       button5.addMouseListener(this);
       panel2.add(button5);
       addWindowListener(this);

       button6 = new myButton();
       button6.setImage(img[which+3]);
       button6.setPressState(true);
       button6.addMouseListener(this);
       panel2.add(button6);

       GridBagLayout gridbag = new GridBagLayout();
       GridBagConstraints gridcon = new GridBagConstraints();
       setLayout(gridbag);

       gridcon.gridx = 0;
       gridcon.gridy = 0;
       gridcon.gridwidth = 1;
       gridcon.gridheight = 1;
       gridcon.weightx = 0.0;
       gridcon.weighty = 0.0;
       gridcon.insets = new Insets(10,8,0,10);
       gridcon.fill = GridBagConstraints.NONE;
       gridbag.setConstraints(label1,gridcon);
       add(label1);

       gridcon.gridx = 1;
       gridcon.gridy = 0;
       gridcon.gridwidth = 1;
       gridcon.gridheight = 1;
       gridcon.weightx = 1.0;
       gridcon.weighty =  0.0;
       gridcon.fill = GridBagConstraints.HORIZONTAL;
       gridcon.insets = new Insets(10,0,5,0);
       gridbag.setConstraints(choice1,gridcon);
       add(choice1);
       choice1.addItemListener(this);

       gridcon.gridx = 2;
       gridcon.gridy = 0;
       gridcon.gridwidth = 1;
       gridcon.gridheight = 1;
       gridcon.weightx = 0.0;
       gridcon.weighty = 0.0;
       gridcon.fill = GridBagConstraints.NONE;
       gridcon.insets = new Insets(10,5,5,10);
       gridbag.setConstraints(panel2,gridcon);
       add(panel2);

        gridcon.gridx = 0;
        gridcon.gridy = 1;
        gridcon.gridwidth = 3;
        gridcon.gridheight = 1;
        gridcon.weightx = 1.0;
        gridcon.weighty = 1.0;
        gridcon.insets = new Insets(5,10,0,10);
        gridcon.fill = GridBagConstraints.BOTH;
        gridbag.setConstraints(listview,gridcon);
        add(listview);

        gridcon.gridx = 0;
        gridcon.gridy = 2;
        gridcon.gridwidth = 1;
        gridcon.gridheight = 1;
        gridcon.weightx = 0.0;
        gridcon.weighty = 0.0;
        gridcon.ipadx = 0;
        gridcon.ipady = 0;
        gridcon.insets = new Insets(5,10,10,0);
        gridcon.fill = GridBagConstraints.NONE;
        gridbag.setConstraints(label2,gridcon);
        add(label2);

        gridcon.gridx = 1;
        gridcon.gridy = 2;
        gridcon.gridwidth = 2;
        gridcon.gridheight = 1;
        gridcon.weightx = 1.0;
        gridcon.insets = new Insets(5,0,10,10);
        gridcon.fill = GridBagConstraints.HORIZONTAL;
        gridbag.setConstraints(choicetext.panel1,gridcon);
        add(choicetext.panel1);

        gridcon.gridx = 1;
        gridcon.gridy = 3;
        gridcon.gridwidth = 1;
        gridcon.gridheight = 1;
        gridcon.weightx = 0.0;
        gridcon.weighty = 0.0;
        gridcon.ipadx =30;
        gridcon.ipady = 0;
        gridcon.fill = GridBagConstraints.NONE;
        gridcon.anchor = GridBagConstraints.WEST;
        gridcon.insets = new Insets(0,30,10,0);
        gridbag.setConstraints(button1,gridcon);
        add(button1);
        button1.setEnabled(false);
        button1.addActionListener(this);

       gridcon.gridx = 2;
       gridcon.gridy = 3;
       gridcon.gridwidth = 1;
       gridcon.gridheight = 1;
       gridcon.weightx = 0.0;
       gridcon.weighty = 0.0;
       gridcon.ipadx = 30;
       gridcon.ipady = 0;
       gridcon.fill = GridBagConstraints.NONE;
       gridcon.anchor = GridBagConstraints.WEST;
       gridcon.insets = new Insets(0,20,10,90);
       gridbag.setConstraints(button2,gridcon);
       add(button2);
       button2.addActionListener(this);
       setResizable(false);
       setSize(480,373);
       setBackground(new Color(12632256));

       listview.view = 3;
       getDirFileName();
       listview.repaint();
       choice1.addItem("http://" + hostname + ":" + port);
    }

   public java.awt.Image getImage(String imgName) {

        java.net.URL url = applet.getCodeBase();
        String imgRes = applet.getParameter("imagesource") + "/"  + imgName;
        try {
        url = new URL(url,imgRes);
        }catch(Exception e) {
            e.printStackTrace();
        }
        //System.out.println("url = " + url + ", imgName = " + imgName);
        if (url != null) {
            return applet.getImage(url);
        }else{
            return null;
        }

   }

    public void textValueChanged(TextEvent e){
        if(checktext(choicetext.getText()))    button1.setEnabled(false);
        else    button1.setEnabled(true);
        }

    private boolean checktext(String st){
        int len = st.length();
        for(int i = 0;i<len;i++){
           char code = st.charAt(i);
           if (code != 13 && code != 10 && code != 32) // carriage('\r') 13,  line feed('\n') 10,  space(' ') 32
               return false;
        }
        return true;
     }//end of checktext.

     private boolean checkValid(String st){
        int len = st.length();
        for(int i = 0;i<len;i++){
           char code = st.charAt(i);
           if (code != 13 && code != 10 && code != 32) // carriage('\r') 13,  line feed('\n') 10,  space(' ') 32
               return false;
        }
        return true;
     }

    private void getDirFileName(){

        try{			
        //Socket connect = new Socket(hostname,9099);

        URL url = new URL(protocol + "://" + hostname + ":" + "8080" + "/servlet/servlet.FileDialogServlet");
        URLConnection connect = url.openConnection();
        connect.setUseCaches(false);
        connect.setDoInput(true);
        connect.setDoOutput(true);

		connect.connect();
        OutputStream output = connect.getOutputStream();

        ObjectOutputStream objoutput = new ObjectOutputStream(output);
        Hashtable ht = new Hashtable();

        ht.put("Type",new Integer(0));
        objoutput.writeObject(ht);

        Hashtable table = new Hashtable();
        InputStream input = connect.getInputStream();
        ObjectInputStream objinput = new ObjectInputStream(input);
        table = (Hashtable)objinput.readObject();
        rootPath       = (String)table.get("rootdir");
        Vector vector0 = (Vector)table.get("Dir");
        Vector vector1 = (Vector)table.get("FileName");
        int alllength   = 0;
        int dirlength   = 0;
        int filelength  = 0;		

        if(vector0 != null){
            dirlength = vector0.size();
            for(int i=0;i<dirlength;i++){
                String dirName = (String)vector0.elementAt(i);
                listview.listitems.addItem(true,1,"Dir",dirName,1,1,true);
            }
        }
        if(vector1 != null){
            filelength = vector1.size();
            for(int i=0;i<filelength;i++){
                String fileName = (String)vector1.elementAt(i);
                listview.listitems.addItem(true,1,"FileName",fileName,1,1,false);
            }
       }
       alllength = filelength + dirlength;
       for(int j = 0;j<alllength+2;j++){
            for(int k = 1;k<3;k++){
                try{
                    if(listview.listitems != null && listview.listitems.Item(j) != null)
                    listview.listitems.Item(j).setSubItemsWithIndex(k,"  ");
                }catch(Exception e){
                    //e.printStackTrace();
                }
            }
       }
       addTitle();
       objoutput.close();
       objinput.close();
       //connect.close();
       }catch(Exception e){
            e.printStackTrace();
        }	   
    }

    private void getCurrentDirFileName(String path){

        try{
        //Socket connect = new Socket(hostname,9099);

        URL url = new URL(protocol + "://" + hostname + ":" + "8080" + "/servlet/servlet.FileDialogServlet");
        URLConnection connect = url.openConnection();
        connect.setUseCaches(false);
        connect.setDoInput(true);
        connect.setDoOutput(true);

        OutputStream output = connect.getOutputStream();

        ObjectOutputStream objoutput = new ObjectOutputStream(output);

        Hashtable ht = new Hashtable();
        ht.put("Type",new Integer(1));
        ht.put("Path",path);
        objoutput.writeObject(ht);

        Hashtable table = new Hashtable();
        InputStream input = connect.getInputStream();
        ObjectInputStream objinput = new ObjectInputStream(input);
        table = (Hashtable)objinput.readObject();
        Vector vector0 = (Vector)table.get("Dir");
        Vector vector1 = (Vector)table.get("FileName");
        int alllength   = 0;
        int dirlength   = 0;
        int filelength  = 0;
        if(vector0 != null){
            dirlength = vector0.size();
            for(int i=0;i<dirlength;i++){
                String dirName = (String)vector0.elementAt(i);
                listview.listitems.addItem(true,1,"FileName",dirName,1,1,true);
            }
        }
        if(vector1 != null){
            filelength = vector1.size();
            for(int i=0;i<filelength;i++){
                String fileName = (String)vector1.elementAt(i);
                listview.listitems.addItem(true,1,"FileName",fileName,1,1,false);
            }
        }

        alllength = dirlength + filelength;
        for(int j = 0;j<alllength+2;j++){
            for(int k = 1;k<3;k++){
                try{
                    if(listview.listitems != null && listview.listitems.Item(j) != null)
                    listview.listitems.Item(j).setSubItemsWithIndex(k,"  ");
                }catch(Exception e){
                    //e.printStackTrace();
                }
            }
        }
       // addTitle();
        objoutput.close();
        objinput.close();
        //connect.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

   public void addTitle(){

    String title[]={"Name","Title"};
       for(int i = 0;i<title.length;i++){
            if(i == 0)      listview.columnheaders.addItem(true,1,"key",title[i],150*15,1);
            else    listview.columnheaders.addItem(true,1,"key",title[i],280*15,1);
        }

   }
   public void deleteFile(String fileSt){
        int count = choice1.getItemCount();
        String pathSt = "";

        for(int i=0;i<count;i++){
            if(i ==0) ;   //  curPath = choice1.getItem(i);
            else pathSt = pathSt + java.io.File.separator + choice1.getItem(i);
        }
        pathSt = pathSt + java.io.File.separator + fileSt;
        deleteDirFile(pathSt);
   }

    private void deleteDirFile(String path){

        try{
        //Socket connect = new Socket(hostname,9099);

        URL url = new URL(protocol + "://" + hostname + ":" + "8080" + "/servlet/servlet.FileDialogServlet");
        URLConnection connect = url.openConnection();
        connect.setUseCaches(false);
        connect.setDoInput(true);
        connect.setDoOutput(true);

        OutputStream output = connect.getOutputStream();

        ObjectOutputStream objoutput = new ObjectOutputStream(output);

        Hashtable ht = new Hashtable();
        ht.put("Type",new Integer(3));
        ht.put("PathFile",path);
        objoutput.writeObject(ht);

        Hashtable table = new Hashtable();
        InputStream input = connect.getInputStream();
        ObjectInputStream objinput = new ObjectInputStream(input);

        objoutput.close();
        objinput.close();
        //connect.close();
        }catch(Exception e){
            e.printStackTrace();
        }
    }

    private void buildFolder(String path){

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -