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

📄 workspacegui.java

📁 基于jxta的局域网P2P文件共享,可以实现局域网中的文件p2p共享,实现文件快速传输及交流
💻 JAVA
字号:
package connex.app.wsUI;

import java.awt.*;

import javax.swing.*;
import javax.swing.border.Border;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.Vector;



import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;

import connex.core.WS.*;
import java.io.File;

public class WorkSpaceGUI extends JFrame  {
    final ImageIcon User_ICON = new ImageIcon("resources"+File.separator +"images"+File.separator +"user2.png");
    final ImageIcon HOME_ICON = new ImageIcon("resources"+File.separator +"images"+File.separator +"home2.png");
    final ImageIcon WS_ICON = new ImageIcon("resources"+File.separator +"images"+File.separator +"cube2.png");

    final ImageIcon SEARCH_ICON = new ImageIcon("resources"+File.separator +"images"+File.separator +"search2.png");
    final ImageIcon BACKGROUND = new ImageIcon("resources"+File.separator +"images"+File.separator +"back1.png");
    final ImageIcon WS_SMALL = new ImageIcon("resources"+File.separator +"images"+File.separator +"cube3.png");

    private BorderLayout borderLayout1 = new BorderLayout();
    private JPanel jPanel1 = new JPanel();
    private JPanel jPanel2 = new JPanel();
    private JTabbedPane jTabbedPane1 = new JTabbedPane();
    //JPanel jPanel5 = new JPanel();
    private JLabel jPanel5 = new JLabel();
    private JLabel jLabel1 = new JLabel();

    private JButton jLabel2 = new JButton();
    private JButton jLabel3 = new JButton();


    private Border border3 = BorderFactory.createEtchedBorder(SystemColor.
            inactiveCaption, new Color(178, 178, 178));
  /*  private DropShadowBorder shadow = new DropShadowBorder(Color.black, 1, 7,
            .7f, 12, false, true, true, true);*/
    private JPanel jPanel3 = new JPanel();
    private BorderLayout borderLayout2 = new BorderLayout();
    private JPanel jPanel4 = new JPanel();
    private BorderLayout borderLayout3 = new BorderLayout();
    private JLabel jLabel4 = new JLabel();
    private JScrollPane jScrollPane1 = new JScrollPane();
    private DefaultListModel data = new DefaultListModel();

    private JList jList1 = new JList(data);

    private ListRenderer rend = new ListRenderer(this.WS_SMALL);
    private JLabel jLabel5 = new JLabel();
    private JPanel jPanel6 = new JPanel();
    private JButton jButton1 = new JButton();
    private BorderLayout borderLayout4 = new BorderLayout();
    private JPanel jPanel7 = new JPanel();
    private JPanel jPanel8 = new JPanel();
    private BorderLayout borderLayout5 = new BorderLayout();
    private JPanel jPanel9 = new JPanel();
    private BorderLayout borderLayout6 = new BorderLayout();
    private Vector logData;
    private boolean mode;
    /****************************/
    private SearchWorkspaceDialog searchUI = null;
    private CreatWorkspaceDialog createUI = null;
    private JoinWorkspaceDialog joinUI;
    /****************************************/
    public WorkSpaceGUI() {
        try {
            jbInit();
        } catch (Exception exception) {
           // exception.printStackTrace();
        }
    }

    private void jbInit() throws Exception {

        getContentPane().setLayout(borderLayout1);
        String txt =
                "<html> <FONT  STYLE='font-size:11pt;font-family:Arial'> User@ConneX</A></FONT>";
        String txt2 = "<html><a href=" + "" +
                      "> <FONT  STYLE='font-size:11pt;font-family:Arial'> New Workspace</A></FONT>";
        String txt3 = "<html><a href=" + "" +
                      "> <FONT  STYLE='font-size:11pt;font-family:Arial'> Search Workspace</A></FONT>";
        jLabel1.setPreferredSize(new Dimension(97, 45));
        jLabel1.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel1.setHorizontalTextPosition(SwingConstants.RIGHT);
        jLabel1.setIcon(this.User_ICON);
        jLabel1.setText(txt);
        // jLabel1.setBackground(Color.white );

        jPanel5.setLayout(borderLayout2);
        jPanel5.setBackground(Color.white);
        jPanel5.setBorder(border3);
        jPanel5.setDoubleBuffered(false);
        jPanel5.setOpaque(false);
        jPanel5.setHorizontalAlignment(SwingConstants.TRAILING);
        jLabel2.setBorder(null);
        jLabel2.setContentAreaFilled(false);
        jLabel2.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel2.setHorizontalTextPosition(SwingConstants.RIGHT);
        jLabel2.setIcon(this.SEARCH_ICON);

        jLabel2.setText(txt3);
        jLabel2.setCursor(new Cursor(Cursor.HAND_CURSOR));
        jLabel2.addActionListener(new WorkSpaceGUI_jLabel2_actionAdapter(this));
        jTabbedPane1.setBorder(null);
        jLabel3.setBorder(null);
        jLabel3.setMinimumSize(new Dimension(66, 10));
        jLabel3.setPreferredSize(new Dimension(109, 25));
        jLabel3.setContentAreaFilled(false);
        jLabel3.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel3.setHorizontalTextPosition(SwingConstants.RIGHT);
        jLabel3.setIcon(this.WS_ICON);
        jLabel3.setMargin(new Insets(2, 14, 2, 14));
        jLabel3.setText(txt2);
        jLabel3.setCursor(new Cursor(Cursor.HAND_CURSOR));
        jLabel3.addActionListener(new WorkSpaceGUI_jLabel3_actionAdapter(this));
        jPanel3.setLayout(borderLayout4);
        jPanel4.setLayout(borderLayout3);
        jPanel4.setBorder(null);
        jPanel4.setOpaque(false);
        jPanel3.setOpaque(false);
        jPanel3.setPreferredSize(new Dimension(109, 110));
        jLabel4.setIcon(this.BACKGROUND);
        jPanel5.setIcon(this.BACKGROUND); /////
        jPanel5.setVerticalAlignment(SwingConstants.BOTTOM);
        jLabel4.setText("");
        jScrollPane1.setOpaque(false);
        jScrollPane1.setBorder(null);
        jScrollPane1.getViewport().setOpaque(false);
        jList1.setBackground(Color.lightGray);
        jList1.setAlignmentX((float) 2.0);
        jList1.setAlignmentY((float) 2.0);
        jList1.setOpaque(false);
        jList1.setCellRenderer(rend);
        jList1.setSelectionBackground(Color.white); //new Color(221,234, 255));
        jList1.setSelectionForeground(Color.BLUE);
        jList1.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

        jLabel5.setFont(new java.awt.Font("Dialog", Font.PLAIN, 12));
        jLabel5.setOpaque(false);
        jLabel5.setPreferredSize(new Dimension(92, 40));
        jLabel5.setHorizontalAlignment(SwingConstants.LEFT);
        jLabel5.setText("  Workspases");
        jLabel5.setVerticalAlignment(SwingConstants.CENTER);
        jLabel5.setVerticalTextPosition(SwingConstants.CENTER);
        jPanel6.setOpaque(false);
        jPanel6.setPreferredSize(new Dimension(20, 20));
        jButton1.setText("Join");
        jButton1.addActionListener(new WorkSpaceGUI_jButton1_actionAdapter(this));
        this.getContentPane().setBackground(SystemColor.controlLtHighlight);
        this.setResizable(false);
        this.addWindowListener(new WorkSpaceGUI_this_windowAdapter(this));
        jPanel8.setLayout(borderLayout5);
        jPanel8.setOpaque(false);
        jPanel7.setOpaque(false);
        jPanel7.setPreferredSize(new Dimension(10, 30));
        jPanel9.setLayout(borderLayout6);
        jPanel9.setOpaque(false);
        jPanel1.setOpaque(false);
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
        this.getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);
        this.getContentPane().add(jTabbedPane1, java.awt.BorderLayout.CENTER);
        jTabbedPane1.add(jPanel5, "Home");
       // jPanel5.setBorder(shadow);
        jPanel5.add(jPanel4, java.awt.BorderLayout.CENTER);
        jPanel5.add(jPanel3, java.awt.BorderLayout.NORTH); // jPanel4.add(jLabel4, java.awt.BorderLayout.SOUTH);
        jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);
        jScrollPane1.getViewport().add(jList1);
        jPanel4.add(jPanel6, java.awt.BorderLayout.WEST);
        jPanel4.add(jLabel5, java.awt.BorderLayout.NORTH);
        jPanel4.add(jButton1, java.awt.BorderLayout.SOUTH);
        jPanel3.add(jLabel1, java.awt.BorderLayout.NORTH);
        jPanel3.add(jPanel7, java.awt.BorderLayout.WEST);
        jPanel3.add(jPanel8, java.awt.BorderLayout.CENTER);
        jPanel9.add(jLabel3, java.awt.BorderLayout.CENTER);
        jPanel8.add(jPanel9, java.awt.BorderLayout.NORTH);
        jPanel8.add(jLabel2, java.awt.BorderLayout.CENTER);
        jTabbedPane1.setIconAt(0, this.HOME_ICON);

        setSize(220, 444);
        centerFrame();
       setWorkspaces();

    }

    private void centerFrame() {

        // Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = this.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        this.setLocation((screenSize.width - frameSize.width) / 2,
                         (screenSize.height - frameSize.height) / 2);
        this.setVisible(true);

    }

    public void setWorkspaces() {

        Vector v = (Vector)WorkspaceManager.getWorkspaces();

        for (int i = 0; i < v.size(); i++) {
            data.addElement(v.elementAt(i));
        }
         jList1.updateUI();
        jList1.repaint();
        //jList1.setListData();

    }

    public DefaultListModel getWorkspaces() {
        return data;
    }

    public static void main(String arg[]){
        WorkSpaceGUI w= new WorkSpaceGUI();
        w.setSize(220, 444);
        w.centerFrame();

    }



    public void jLabel2_actionPerformed(ActionEvent e) {

            searchUI = new SearchWorkspaceDialog(this);

        searchUI.setVisible(true);

        searchUI.dispose();
        searchUI=null;

    }

    public void jLabel3_actionPerformed(ActionEvent e) {
        try {
            createUI = new CreatWorkspaceDialog(this);


            if (!createUI.isCanceled()) {
                Workspace newWorkspace = WorkspaceManager.createWorkspace(
                         createUI.getGroupName(), createUI.getDescription(),
                        createUI.getLogInName(), createUI.getPass(), 0, null);


                data.addElement(newWorkspace);
                System.out.println(" new Workspace created " +
                                   newWorkspace.getName());
                jList1.updateUI();
                jList1.repaint();
            }
            createUI.dispose();
        } catch (Exception ex) {
        ex.printStackTrace();
        }

    }

    public void jButton1_actionPerformed(ActionEvent e) {
        Workspace ws = (Workspace) jList1.getSelectedValue();
        if(!WorkspaceUtil.isAuthenticated(ws)){
            joinUI = new JoinWorkspaceDialog(this, ws);
            joinUI.setTitle(ws.getName());

        }
        if (!joinUI.isCanceled()) {

        }

    }

    public void this_windowClosing(WindowEvent e) {
        WorkspaceUtil.saveWorkspaces(data.elements());
        WorkspaceManager.getInstance().close();
    }

}


class WorkSpaceGUI_this_windowAdapter extends WindowAdapter {
    private WorkSpaceGUI adaptee;
    WorkSpaceGUI_this_windowAdapter(WorkSpaceGUI adaptee) {
        this.adaptee = adaptee;
    }

    @Override
    public void windowClosing(WindowEvent e) {
        adaptee.this_windowClosing(e);
    }
}


class WorkSpaceGUI_jButton1_actionAdapter implements ActionListener {
    private WorkSpaceGUI adaptee;
    WorkSpaceGUI_jButton1_actionAdapter(WorkSpaceGUI adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jButton1_actionPerformed(e);
    }
}


class WorkSpaceGUI_jLabel3_actionAdapter implements ActionListener {
    private WorkSpaceGUI adaptee;
    WorkSpaceGUI_jLabel3_actionAdapter(WorkSpaceGUI adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {

        adaptee.jLabel3_actionPerformed(e);
    }
}


class WorkSpaceGUI_jLabel2_actionAdapter implements ActionListener {
    private WorkSpaceGUI adaptee;
    WorkSpaceGUI_jLabel2_actionAdapter(WorkSpaceGUI adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.jLabel2_actionPerformed(e);
    }
}

⌨️ 快捷键说明

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