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

📄 newfiledialog.java

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

        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(2));
        ht.put("DirPath",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();
        }
    }

    public void setText(String st){
        choicetext.setText(st);
    }

    public synchronized void clickListItems(String curName,boolean isdir){
        int count = choice1.getItemCount();
        String curPath = "";
        for(int i=0;i<count;i++){
            if(i ==0) ;   //  curPath = choice1.getItem(i);
            else curPath = curPath + java.io.File.separator + choice1.getItem(i);
        }
        curPath = curPath + java.io.File.separator + curName;
        if(isdir){
            try{
                listview.listitems.Clear();
            }catch(Exception e){
                e.printStackTrace();
            }
            getCurrentDirFileName(curPath);
            listview.setCurrentListIndex();
            listview.repaint();
            choice1.addItem(curName);
            choice1.select(curName);

        }else{ //xiaoping.
            isok = true;
            setVisible(false);
        }

    }

 public void windowActivated(WindowEvent e){}
 public void windowClosed(WindowEvent e){}
 public void windowClosing(WindowEvent e){
    setVisible(false);
    }
 public void windowDeactivated(WindowEvent e){}
 public void windowDeiconified(WindowEvent e){}
 public void windowIconified(WindowEvent e){}
 public void windowOpened(WindowEvent e){}

 public void itemStateChanged(ItemEvent e){

    int index = choice1.getSelectedIndex();
    int count = choice1.getItemCount();
    String pathSt = "";
    for(int i=0;i<=index;i++){
        if(i ==0) ;   //  curPath = choice1.getItem(i);
        else pathSt = pathSt + java.io.File.separator + choice1.getItem(i);
    }
    if(count>index){
        for(int i=count-1;i>index;i--){
            choice1.remove(i);
        }
        choice1.select(index);
    }
    try{
        listview.listitems.Clear();
    }catch(Exception ex){
        ex.printStackTrace();
    }
    getCurrentDirFileName(pathSt);
    listview.setCurrentListIndex();
    listview.repaint();
}//huangbin.


public void mouseClicked(MouseEvent e){
        Object obj = e.getSource();

        if (obj.equals(button3)){

            int count = choice1.getItemCount();
            if(count == 1) return;
            String pathSt = "";
            for(int i=0;i<count-1;i++){
                if(i == 0);
                else pathSt = pathSt + java.io.File.separator + choice1.getItem(i);
            }
            if(count >1){
                choice1.remove(count-1);
                choice1.select(count-2);
            }
            try{
               listview.listitems.Clear();
            }catch(Exception ex){
                ex.printStackTrace();
            }
            getCurrentDirFileName(pathSt);
            listview.setCurrentListIndex();
            listview.repaint();
        }//huangbin.

	}

public void mouseEntered(MouseEvent e){}

public void mouseExited(MouseEvent e){
	    if (e.getSource().equals(button3)){
	       button3.setPressState(false);
	       button3.repaint();
	    }else if (e.getSource().equals(button4)){
	       button4.setPressState(false);
	       button4.repaint();
	    }
	}

public void mousePressed(MouseEvent e){
	    Object obj = e.getSource();
	    if (obj.equals(button6)){
	        button5.setPressState(false);
	        button5.repaint();
	    }else if(obj.equals(button5)){
	        button6.setPressState(false);
	        button6.repaint();
	    }
	}

public void mouseReleased(MouseEvent e){
        Object obj = e.getSource();
    	if (obj.equals(button3)){
	        button3.setPressState(false);
	        button3.repaint();
	    }else if (obj.equals(button4)){//chenqimei
	        button4.setPressState(false);
	        button4.repaint();
	        AddFolderDialog addDialog = new AddFolderDialog();
	        addDialog.display();
	        String dirname=addDialog.getText();
	        if(checktext(dirname)) return;
	        boolean state =addDialog.getState();
	        if (state){
    	        listview.listitems.addItem(true,1,"Dir",dirname,1,1,true);
    	        listview.repaint();
    	        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 + dirname;
    	        buildFolder(pathSt);
	        }
	    }
	    else if (obj.equals(button5)){
	        button5.setPressState(true);
	        button5.repaint();
	        listview.view =2;
	        listview.repaint();
	    }
	    else if (obj.equals(button6)){
	        button6.setPressState(true);
	        button6.repaint();
	        listview.view = 3;
	        listview.repaint();
	        }
    }

 public void actionPerformed(ActionEvent e){
    Object obj = e.getSource();
    if(obj == button1){
        if(checktext(choicetext.getText())){
            return;
        }else{
            String filename = choicetext.getText().trim();
            boolean isfind  = false;
            int listcount = listview.listitems.getStoreListItems().size();
            for(int i=0; i<listcount;i++){
                ListItem listitem = (ListItem)listview.listitems.getStoreListItems().elementAt(i);
                if(listitem.getIsDir()&&(listitem.getText().equals(filename))){
                    clickListItems(filename,true);
                    isfind = true;
                    break;
                }
            }
            if(!isfind){
                isok = true;
                setVisible(false);
            }
        }
    }else if(obj == button2){
        isok = false;
        setVisible(false);
    }
    }

 public void keyPressed(KeyEvent e){
    int code = e.getKeyCode();
    Object obj = e.getSource();
    if((code == KeyEvent.VK_ENTER)&&(obj instanceof TextField)){
        if(checktext(choicetext.getText())){
            return;
        }else{
            String filename = choicetext.getText().trim();
            boolean isfind  = false;
            int listcount = listview.listitems.getStoreListItems().size();
            for(int i=0; i<listcount;i++){
                ListItem listitem = (ListItem)listview.listitems.getStoreListItems().elementAt(i);
                if(listitem.getIsDir()&&(listitem.getText().equals(filename))){
                    clickListItems(filename,true);
                    isfind = true;
                    break;
                }
            }
            if(!isfind){
                isok = true;
                setVisible(false);
            }
        }
    }
    }

 public void keyReleased(KeyEvent e){}

 public void keyTyped(KeyEvent e){}


 public void display(){
	Dimension bounds = getToolkit().getScreenSize();
	Rectangle abounds = getBounds();
	setLocation((bounds.width - abounds.width)/ 2,(bounds.height - abounds.height)/2);
	setVisible(true);
 }

public boolean getState(){
    return isok;
}

public String getFile() {

    if (isok) {
        String pathSt = getCurrentPath();
        pathSt = rootPath  + pathSt+ File.separator+ choicetext.getText();
        return pathSt;
    }else{
        return null;
    }
}

public String getUrlFile() {
    if (isok) {
        String pathSt = getCurrentPath();
        pathSt = pathSt+ File.separator+ choicetext.getText().trim();
        return pathSt;
    }else{
        return null;
    }
}

private String getCurrentPath(){
    int count = choice1.getItemCount();
    String pathSt = "";
    for(int i=0;i<count;i++){
        if(i == 0) ;
        else pathSt = pathSt + java.io.File.separator + choice1.getItem(i);
    }
    return pathSt;
}

}



//drawChoice and TextField.
class ChoiceText {
    TextField       tf;
    Choice          choice;
    Panel           panel1;
    NewFileDialog   openfile1;

    public ChoiceText(NewFileDialog openfile1){

    this.openfile1 = openfile1;
    panel1 = new Panel();
    panel1.setBounds(0,0,440,40);

    panel1.setLayout(null);

    tf = new TextField();
    tf.addKeyListener(openfile1);
    tf.addTextListener(openfile1);
    tf.setBounds(10,10,334,25);
    panel1.add(tf);

    choice = new Choice();
    choice.setBounds(10,10,350,20);
    panel1.add(choice);
    }

    public void setText(String st){ //xiaoping.
        tf.setText(st);
    }

    public String getText(){ //xiaoping.
        return tf.getText();
    }
}

//drawButton3~6.

class myButton extends java.awt.Canvas implements MouseListener{
    java.awt.Image img;
	boolean pressState = false;

	public myButton(){
		super();
		addMouseListener(this);
	}

    public void setImage(java.awt.Image img) {
        this.img = img;
        repaint();
    }
    public void paint(Graphics g) {
		super.paint(g);
		boolean press = this.pressState;

		drawrect(img,press,1,1,getSize().width - 2,getSize().height - 2,g);

    }
    public void setPressState(boolean b){
        pressState = b;
    }

	private void drawrect(java.awt.Image img,boolean press,int left,int top,int right,int bottom,Graphics g)
	{
		g.setColor(Color.lightGray);
        g.fillRect(left+1,top+1,right-left-1,bottom-top-1);
        if (! press)
        {
        if (img != null){
            try{
                java.awt.MediaTracker tracker = new java.awt.MediaTracker(this);
                tracker.addImage(img, 0);
                tracker.waitForID(0);
    	    }catch(Exception e){}
    	    g.drawImage(img, 5, 5, getSize().width-10, getSize().height-10, this);
        }
          g.setColor(Color.white);
          g.drawLine(left,top,right,top);
          g.drawLine(left,top,left,bottom);
          g.setColor(Color.lightGray);
          g.drawLine(left+1,top+1,right-1,top+1);
          g.drawLine(left+1,top+1,left+1,bottom-1);
          g.setColor(Color.black);
          g.drawLine(left,bottom,right,bottom);
          g.drawLine(right,bottom,right,top);
          g.setColor(Color.gray);
          g.drawLine(left+1,bottom-1,right-1,bottom-1);
          g.drawLine(right-1,bottom-1,right-1,top+1);

         }
         else
         {
          g.setColor(Color.white);
          g.fillRect(left+1,top+1,right-left-1,bottom-top-1);
         if (img != null){
            try{
                java.awt.MediaTracker tracker = new java.awt.MediaTracker(this);
                tracker.addImage(img, 0);
                tracker.waitForID(0);
    		}catch(Exception e){}
    	    g.drawImage(img, 5, 5, getSize().width-10, getSize().height-10, this);
		 }

           g.setColor(Color.black);
           g.drawLine(left,top,right,top);
           g.drawLine(left,top,left,bottom);
           g.setColor(Color.gray);
           g.drawLine(left+1,top+1,right-1,top+1);
           g.drawLine(left+1,top+1,left+1,bottom-1);

           g.setColor(Color.white);
           g.drawLine(left,bottom,right,bottom);
           g.drawLine(right,bottom,right,top);
           g.setColor(Color.lightGray);
           g.drawLine(left+1,bottom-1,right-1,bottom-1);
           g.drawLine(right-1,bottom-1,right-1,top+1);

           }
	}

	public void mouseClicked(MouseEvent e){

	}

	public void mouseEntered(MouseEvent e){
	}

	public void mouseExited(MouseEvent e){
	}

	public void mousePressed(MouseEvent e){
		pressState = true;
		repaint();
	}

    public void   mouseReleased(MouseEvent e){
        pressState = false;
        repaint();
    }
}

⌨️ 快捷键说明

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