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

📄 gui.java

📁 基于Java技术实现的minipacs系统,可以进行诊断信息登记, 嵌入控件查看DICOM 影像和统计分析等功能.
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                            SimpleDateFormat today = new SimpleDateFormat("h:mm a");                            SimpleDateFormat month = new SimpleDateFormat("d MMM yyyy ");                                                        Calendar calendar = Calendar.getInstance();                            Date date = new Date();                            calendar.setTime(date);                            int hours = calendar.get(Calendar.HOUR);                            int minutes = calendar.get(Calendar.MINUTE);                            int seconds = calendar.get(Calendar.SECOND);                            Date midnight = new Date(hours*60*60*1000+minutes*60*1000+seconds*1000);                            if (isoDate.getTime() > midnight.getTime()) {                                return today.format(isoDate);                            }                            else {                                return month.format(isoDate);                            }                         }                        else {                            return "N/A";                        }                    }                    case 3: {                        if (iso.getISOCreationDate() == null) {                            int progress = (int) (((double) iso.length() / (double) iso.getTotalStudySize()) * 100);                            if (progress > 100) progress = 100;                            return "Creating... (" + progress + "%)";                        }                        else {                            try {                                File tmpDir = File.createTempFile("test", null); //TODO: create smarter method to detect temp dir.                                if ((new File(tmpDir.getParent() + "/" + iso.getName())).exists()) {                                    return "Ready to burn";                                }                                else {                                    return "Ready for download";                                }                            } catch (IOException e) {                                e.printStackTrace();                                return "N/A";                            }                        }                    }                    default: {                        return "ERROR";                    }                }            }            public Class getColumnClass(int c) {                return getValueAt(0, c).getClass();            }            public boolean isCellEditable(int row, int col) {                //Note that the cell's address (row,col) is constant,                //no matter where the cell appears onscreen.                return false;            }            public void setValueAt(BackupIso value, int row) {                isoFiles.setElementAt(value, row);                fireTableRowsUpdated(row, row);            }        }    }    public final class ConfirmPane extends TemplatePane {        JTextField medium;        JTextField label;        JTextField location;        JTextArea description;                public ConfirmPane() {            border.setTitle("Edit Backup Information");                        centerPane.setLayout(new SpringLayout());                        // create input fields            medium = new JTextField(isoToBackup.getMediumType());            label = new JTextField(isoToBackup.getLabel());            location = new JTextField(isoToBackup.getLocation());            description = new JTextArea(isoToBackup.getDescription());                        //Add this panel as a listener to inputfield actions            medium.addActionListener(this);            label.addActionListener(this);            location.addActionListener(this);            centerPane.add(new JLabel("Medium Type"));            centerPane.add(medium);            centerPane.add(new JLabel("Label"));            centerPane.add(label);            centerPane.add(new JLabel("Location"));            centerPane.add(location);            centerPane.add(new JLabel("Description"));            centerPane.add(description);                        SpringUtilities.makeCompactGrid(centerPane,                                            4, 2, //rows, cols                                            5, 5,        //initX, initY                                            5, 5);       //xPad, yPad            leftButton.setVisible(false);            middleButton.setText("Cancel");            rightButton.setText("OK");        }                public void actionPerformed(ActionEvent event) {            Object source = event.getSource();            if (source == medium) {                isoToBackup.setMediumType(medium.getText());            }            else if (source == label) {                isoToBackup.setLabel(label.getText());            }            else if (source == location) {                isoToBackup.setLocation(location.getText());            }            else if (source == rightButton) {                // 'OK' button pressed                isoToBackup.setMediumType(medium.getText());                isoToBackup.setLabel(label.getText());                isoToBackup.setLocation(location.getText());                isoToBackup.setDescription(description.getText());                isoToBackup.setOperator(user.getUsername());                navigate(new MethodPane());            }            else if (source == middleButton) {                // 'Cancel' button pressed                navigate(new FileListPane());            }            }    }        private final class MethodPane extends TemplatePane implements CDRecordListener {        private JComboBox methodSelector = new JComboBox();;        private JComboBox deviceSelector = new JComboBox();;        private Device selectedDevice;        private File tempFile;        private JLabel infoLabel = new JLabel("");        FileTargetImpl ft;        java.util.Timer timer;                ProgressPane progressPane = new ProgressPane();                public MethodPane() {            border.setTitle("Select method");            setMethods();            setDevices();            centerPane.setLayout(new SpringLayout());            centerPane.add(new JLabel("Backup Method"));            centerPane.add(methodSelector);            centerPane.add(new JLabel("Device"));            centerPane.add(deviceSelector);            centerPane.add(infoLabel);            centerPane.add(new JLabel(""));            SpringUtilities.makeCompactGrid(centerPane,                                    3, 2,       //rows, cols                                    5, 5,       //initX, initY                                    5, 5);      //xPad, yPad            leftButton.setVisible(false);            middleButton.setText("Cancel");            rightButton.setText("OK");         }                public void actionPerformed(ActionEvent event) {            Object source = event.getSource();            if (source == rightButton) {                // 'OK' button pressed                //TODO: implement smarter algorithm for determination of which options are supported and how.                selectedDevice = (Device) deviceSelector.getSelectedItem();                System.out.println("Selected device: " + selectedDevice);                if (methodSelector.getSelectedIndex() != 0) {                    JOptionPane.showMessageDialog(this, "The selected method is not supported", "Inane error", JOptionPane.ERROR_MESSAGE);                }                else if (selectedDevice.isCDBurningDevice() == false) {                    JOptionPane.showMessageDialog(this, "The selected device does not support burning of CDs", "Inane error", JOptionPane.ERROR_MESSAGE);                }                else {                    progressPane.setTitle("I don't want to change!!!");                    navigate(progressPane);                    SwingWorker worker = new SwingWorker() {                        public Object construct() {                            if (promptUserToInsertMedium(selectedDevice) == 0) {                                try {                                    while (isoToBackup.getCreatedTime() == null) { // wait until the file has been created on the server                                        int value = (int) (((double) isoToBackup.length() / (double) isoToBackup.getTotalStudySize()) * 100);                                        if (value > 100) value = 100;                                        progressPane.update(value, isoToBackup.getLabel());                                        try {                                            Thread.sleep(1000);                                        } catch (InterruptedException e) {                                            e.printStackTrace();                                        }                                    }                                    transferFile();                                    return new Boolean(true);                                } catch (Exception e) {                                    e.printStackTrace();                                    return new Boolean(false);                                }                            }                            else return false;                        }                        public void finished() {                            if (((Boolean) this.getValue()).booleanValue()) { // if the transfer was succesfull                                timer.cancel(); // stop the timer that polls the FileTarget to update the progressbar.                                progressPane.update(100, "Iso transferred!");                                progressPane.setTitle("Burning file to medium");                                burnFile();                            }                        }                    };                    worker.start();                }            }            else if (source == middleButton) {                // 'Cancel' button pressed                //TODO: change to call gui method 'exit()'                navigate(new FileListPane());            }         }         private void setMethods() {            methodSelector.removeAllItems();            //TODO: Investigate local pc to customize list (e.g. nero can only be on Windows machines, Nero is not always installed.)            String[] methods = {"CDRecords", "Ahead Nero", "Custom method"};            for (String m : methods) {                methodSelector.addItem(m);            }        }                private void setDevices() {            deviceSelector.removeAllItems();            //TODO: use CDRecords to find devices            String[] devices = {"MyDevice"};            for (Device d : CdRecordController.getCdRecord().scanBus()) {                deviceSelector.addItem(d);                if (d.isBurningDevices()) {                    deviceSelector.setSelectedItem(d);                }            }        }        private boolean transferFile() throws RemoteException {            try {                System.out.println("Transferring file... ");                progressPane.setTitle("Transferring File");                pack(); // pack frontpanel again to show new title.                tempFile = isoToBackup.createTempFile(isoToBackup.getLabel(), ".iso");                ft = new FileTargetImpl(tempFile);                timer = new java.util.Timer();                timer.schedule(new TimerTask() {                    public void run() {                        int value = (int) (((double) ft.getFileSize() / (double) isoToBackup.length()) * 100);                        if (value > 100) value = 100;                        progressPane.update(value, "Transferring '" + isoToBackup.getLabel() + "' (" + value + "%)");                    }                }, 0, 1000);                return server.getFile(ft, isoToBackup);            } catch (IOException e) {                e.printStackTrace();                return false;            }        }                public boolean burnFile() {            System.out.println("Starting to burn ISO");            progressPane.update(0, "Starting burn process ... ");            CdRecordController.getCdRecord().addListener(this);            SwingWorker worker = new SwingWorker() {                boolean isoBurned;                public Object construct() {                    promptUserToInsertMedium(selectedDevice);                    try {                        isoBurned = CdRecordController.getCdRecord().burnIso(((Device) deviceSelector.getSelectedItem()), "\"" + tempFile.getCanonicalPath() + "\"");                        return true;                    } catch (IOException e) {                        e.printStackTrace();                        return false;                    }                }                                public void finished() {                    if (isoBurned) {                        try {                            server.confirmBackup(isoToBackup);                            progressPane.middleButton.setVisible(true);                            progressPane.middleButton.setText("Ok");                            progressPane.rightButton.setVisible(false);                            pack();                        } catch (RemoteException e) {                            e.printStackTrace();                            showDialog("An error occurred during the attempt to burn the file!", "Burn failed!", JOptionPane.ERROR_MESSAGE);                            navigate(new FileListPane());                        }                    }                    else {                        showDialog("An error occurred during the attempt to burn the file!", "Burn failed!", JOptionPane.ERROR_MESSAGE);                        navigate(new FileListPane());                    }                }            };            worker.start();                            return true;        }        public void burnProgressUpdated(int burnPercentage, int burnTime, String burnMessage) { // Signal from CdRecordController Event            progressPane.update(burnPercentage, "'" + burnMessage + "' (" + burnPercentage + "%)");        }    }        private final class ProgressPane extends TemplatePane {        JProgressBar progressBar = new JProgressBar();                public ProgressPane() {            System.out.println("ProgressPane: isoToBackup: " + isoToBackup);            border.setTitle("Please wait... ");            progressBar.setPreferredSize(new Dimension(300, 20));            progressBar.setStringPainted(true);            centerPane.add(progressBar);                        leftButton.setVisible(false);            middleButton.setVisible(false);            rightButton.setText("Cancel");                        progressBar.setMaximum(100);        }        public void update(int value, String text) {            progressBar.setValue(value);            progressBar.setString(text);        }                public void actionPerformed(ActionEvent event) {            Object source = event.getSource();            if (source == rightButton) {                // 'Cancel' button pressed                Object[] options = {"Yes",                    "No"};                int option = JOptionPane.showOptionDialog(this,                    "Cancelling will abort the current download/burn process?",                    "Really cancel?",                    JOptionPane.YES_NO_OPTION,                    JOptionPane.WARNING_MESSAGE,                    null,                    options,                    options[1]);                if (option == 0) {                    //TODO: stop the file download or burning process!                    navigate(new FileListPane());                }            }            else if (source == middleButton) {                // 'Ok' button pressed                navigate(new FileListPane());            }        }    }}

⌨️ 快捷键说明

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