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

📄 gui.java

📁 基于Java技术实现的minipacs系统,可以进行诊断信息登记, 嵌入控件查看DICOM 影像和统计分析等功能.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * Gui.java * * Created on 24. oktober 2005, 16:12 * * To change this template, choose Tools | Options and locate the template under * the Source Creation and Management node. Right-click the template and choose * Open. You can then make changes to the template in the Source Editor. */package backup.client;import backup.server.Server;import backup.client.Gui;import backup.model.*;import java.text.*;import java.net.*;import java.util.*;import java.rmi.*;import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.table.*;import springutilities.*;import burningtools.Device;import burningtools.CDRecordListener;import burningtools.Medium;import burningtools.CdRecordController;/** * * @author Kim Stenbo Nielsen */public class Gui extends JFrame implements WindowListener  {    private Server server;    private FileClerc user;    public static final String SERVICE_NAME = "backup client";    private File ISORoot = new File("c:/temp");    private Vector<BackupIso> isoFiles= new Vector<BackupIso>();    private BackupIso isoToBackup;    /*    private FileListPane fileListPane;    private ConfirmPane confirmPane;    private MethodPane methodPane;    private ProgressPane progressPane;*/        public Gui(Server s) {        setTitle("miniWebPACS Backup");        this.server = s;                // check to see if CDRTools is present. If not transfer file (CDRTools and the driver).                // center wimdow        Toolkit kit = Toolkit.getDefaultToolkit();        Dimension screenSize = kit.getScreenSize();        int screenWidth = (int) screenSize.getWidth();     // getting Screen width        int screenHeight = (int) screenSize.getHeight();  // getting Screen height        this.setLocation(((screenWidth / 2) - (this.getWidth()/2)), ((screenHeight / 2) - (this.getHeight()/2)));        addWindowListener(this);        setVisible(true);                // navigate to login pane        navigate(new LoginPane());    }    public void navigate(JComponent component) {        if (component != null) {            component.setOpaque(true);            remove(getContentPane());            setContentPane(component);            pack();        }        else {            System.out.print("Error navigating - invalid component. Exiting program!");        }    }        public void windowActivated(WindowEvent e) {            }    public void windowClosed(WindowEvent event) {        System.out.print("Window close event!");            }    public void windowClosing(WindowEvent event) {        Object[] options = {"Yes",                    "No"};        int option = JOptionPane.showOptionDialog(this,            "Are you sure you wish to exit minWebPACS Backup?",            "Exit miniWebPACS Backup?",            JOptionPane.YES_NO_OPTION,            JOptionPane.WARNING_MESSAGE,            null,            options,            options[1]);        if (option == 0) {            try {                System.out.println("System exit (window close)");                System.exit(0);            } catch (Exception e) {                e.printStackTrace();            }        }    }    public void windowDeactivated(WindowEvent e) {            }    public void windowDeiconified(WindowEvent e) {            }        public void windowIconified(WindowEvent e) {            }    public void windowOpened(WindowEvent e) {            }    private void showDialog(String message, String title, int type) {        JOptionPane.showMessageDialog(this, message, title, JOptionPane.ERROR_MESSAGE);    }        private int showYesCancelMessage(String message, String titel) {        Object[] options = {"Yes", "Cancel"};        return JOptionPane.showOptionDialog(this,                message,                titel,                JOptionPane.YES_NO_OPTION,                JOptionPane.ERROR_MESSAGE,                null,                options,                options[0]);    }         public int promptUserToInsertMedium(Device device) {        Medium medium;        int option = 0;        boolean stop = false;        boolean isCD = false;                System.out.println("Checking for inserted medium");        while (stop == false) {            if ((medium = CdRecordController.getCdRecord().getMedium(device)) == null) {                option = showYesCancelMessage("Please insert an empty medium in the selected drive", "No medium in drive");            }            else if (!medium.isCD()) {                option = showYesCancelMessage("The inserted medium is not empty!\nPlease insert an empty medium in the selected drive", "Medium not empty");            }            else {                stop = true;            }        }        return option;    }    public final class LoginPane extends TemplatePane implements KeyListener {            private JPanel userInfoPane;        private JTextField username;        private JPasswordField password;        /**         * Creates a new instance of LoginPane          */        public LoginPane() {            System.out.print(" - Request access: ");            border.setTitle("Login");                        //create subpanel for entering information            userInfoPane = new JPanel(new SpringLayout());                        username = new JTextField(15);            password = new JPasswordField(15);            userInfoPane.add(new JLabel("Username:"));            userInfoPane.add(username);            userInfoPane.add(new JLabel("Password:"));            userInfoPane.add(password);            SpringUtilities.makeCompactGrid(userInfoPane,                                            2, 2, //rows, cols                                            5, 5,        //initX, initY                                            5, 5);       //xPad, yPad            centerPane.add(userInfoPane);                        leftButton.setText("Cancel");            middleButton.setVisible(false);            rightButton.setText("OK");        }        public void actionPerformed(ActionEvent event) {            String username = this.username.getText();            String password = String.valueOf(this.password.getPassword());            String action = event.getActionCommand();            try {                if (action.equals("OK")) {                    if (username.equals("") || password.equals("")) {                        showDialog("Please supply both a username and a password!", "Inane error", JOptionPane.ERROR_MESSAGE);                    }                    else if (server.login(user = new FileClerc(username, password)) == false) {                        JOptionPane.showMessageDialog(this, "The supplied username or password was incorrect!", "Inane error", JOptionPane.ERROR_MESSAGE);                        System.out.println("Access denied!");                        System.out.print("Request access: ");                    }                    else {                        System.out.println("Access granted!");                        System.out.println("Backup Client ready...\n");                        navigate(new FileListPane());                    }                }                else if (action.equals("Cancel")) {                    System.exit(0);                }            } catch (RemoteException e) {                e.printStackTrace();            }        }        public void keyPressed(KeyEvent event) {        }        public void keyReleased(KeyEvent event) {        }        public void keyTyped(KeyEvent event) {        }    }        private class FileListPane extends TemplatePane {        BackupIsoTableModel tableModel;        JTable table;        final java.util.Timer timer = new java.util.Timer();                        public FileListPane() {            //TODO: Add pane that gives information about the server status (number of files etc.)            try {                tableModel = new BackupIsoTableModel();                table = new JTable(tableModel);                table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);                timer.schedule( // schedule new timerTask that polls the server for updates to the iso files.                    new TimerTask() {                        public void run()  {                            int i = 0;                            try {                                Vector<BackupIso> newList = server.getFileList();                                if (!isoFiles.equals(newList)) {                                    isoFiles = newList;                                    tableModel.fireTableDataChanged();                                    //System.out.println("FilePoll: All data changed in model");                                }                                else {                                    //System.out.println("New list length: " + newList.size());                                    for (Object o : newList.toArray()) {                                        BackupIso oldIso = isoFiles.get(i);                                        BackupIso newIso = (BackupIso) o;                                        if (newIso.getCreatedTime() == null) {                                            if ((!(newIso.length() == oldIso.length()))) { // Update table row if iso length or creation date, has been modified                                                //System.out.println("FilePoll: Single file data changed");                                                tableModel.setValueAt(newIso, i);                                            }                                        }                                        else if (oldIso.getCreatedTime() == null) {                                                tableModel.setValueAt(newIso, i);                                        }                                        i++;                                    }                                }                            } catch (RemoteException e) {                                e.printStackTrace();                            }                        }                    }                , 0, 500); // end of schedule method (timer)                                centerPane.add(new JScrollPane(table));                leftButton.setVisible(false);                middleButton.setText("Cancel");                rightButton.setText("OK");            } catch (Exception e) {                e.printStackTrace();            }        }                public void actionPerformed(ActionEvent event) {            Object source = event.getSource();            if (source == rightButton) {                // 'OK' button pressed                // TODO: investigate if the selection is valid (if the file can be downloaded)                int row;                if ((row = table.getSelectedRow()) != -1) {                    isoToBackup = tableModel.getValueAt(row);                    if (isoToBackup.getCreatedTime() != null) { //if the file has a timestamp it has been created!                        timer.cancel();                        navigate(new ConfirmPane());                    }                    else {                        JOptionPane.showMessageDialog(this, "The file has not been created yet!", "Inane error", JOptionPane.ERROR_MESSAGE);                    }                }                   else {                    JOptionPane.showMessageDialog(this, "Please select a file from the list!", "Inane error", JOptionPane.ERROR_MESSAGE);                }            }            else if (source == middleButton) {                // 'Cancel' button pressed                //TODO: change to call gui method 'exit()'                navigate(new LoginPane());            }            }        private class BackupIsoTableModel extends AbstractTableModel {            private String[] columnNames = {"File Name", "Size", "Created", "Status"};            BackupIso iso;            public BackupIsoTableModel() {            }                        public int getColumnCount() {                return columnNames.length;            }            public int getRowCount() {                return isoFiles.size();            }            public String getColumnName(int col) {                return columnNames[col];            }                        public BackupIso getValueAt(int row) {                return isoFiles.get(row);            }                        public Object getValueAt(int row, int col) {                BackupIso iso = isoFiles.get(row);                switch (col) {                    case 0: {                        return iso.getName();                    }                    case 1: {                        DecimalFormat numberInMB = new DecimalFormat("###.## MB");                        DecimalFormat numberInGB = new DecimalFormat("###.# GB");                        if (iso.length() < 1000000000) {                            return numberInMB.format(((double) iso.getTotalStudySize())/1000000);                        }                        else {                            return numberInGB.format(((double) iso.getTotalStudySize())/1000000000);                        }                    }                    case 2: {                        Date isoDate = iso.getISOCreationDate();                        if (isoDate != null) {

⌨️ 快捷键说明

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