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

📄 juploadpanel.java

📁 [linux.rar] - 嵌入式linux开发教程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    /**
     * Reaction to a click on the remove button. This method actually removes
     * the selected files in the file list.
     */
    public void doRemove() {
        this.filePanel.removeSelected();
        if (0 >= this.filePanel.getFilesLength()) {
            this.removeButton.setEnabled(false);
            this.removeAllButton.setEnabled(false);
            this.uploadButton.setEnabled(false);
        }
    }

    /**
     * Reaction to a click on the removeAll button. This method actually removes
     * all the files in the file list.
     */
    public void doRemoveAll() {
        this.filePanel.removeAll();
        this.removeButton.setEnabled(false);
        this.removeAllButton.setEnabled(false);
        this.uploadButton.setEnabled(false);
    }

    /**
     * Reaction to a click on the upload button. This method can be called from
     * outside to start the upload.
     */
    public void doStartUpload() {
        // Check that the upload is ready (we ask the uploadPolicy. Then,
        // we'll call beforeUpload for each
        // FileData instance, that exists in allFiles[].

        // ///////////////////////////////////////////////////////////////////////////////////////////////
        // IMPORTANT: It's up to the UploadPolicy to explain to the user
        // that the upload is not ready!
        // ///////////////////////////////////////////////////////////////////////////////////////////////
        try {
            if (this.uploadPolicy.isUploadReady()) {
                // The FileUploadManagerThread will manage everything around
                // upload, including GUI part.
                this.fileUploadManagerThread = new FileUploadManagerThread(
                        this.uploadPolicy);
                this.fileUploadManagerThread.start();
            } // if isIploadReady()
        } catch (Exception e) {
            // If an exception occurs here, it fails silently. The exception is
            // thrown to the AWT event dispatcher.
            this.uploadPolicy.displayErr(e.getClass().getName()
                    + " in JUploadPanel.doStartUpload()", e);
        }
    }

    /**
     * Reaction to a click on the stop button. This stops the running on upload.
     * This method can be called from outside to start the upload.
     */
    public void doStopUpload() {
        this.fileUploadManagerThread.stopUpload();
    }

    // ///////////////////////////////////////////////////////////////////////////////
    // ///////////////// Implementation of the ActionListener
    // ///////////////////////////////////////////////////////////////////////////////

    /**
     * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
     */
    public void actionPerformed(ActionEvent e) {
        // Let's log some info.
        this.uploadPolicy.displayDebug("Action : " + e.getActionCommand(), 1);

        final String actionPaste = (String) TransferHandler.getPasteAction()
                .getValue(Action.NAME);

        if (e.getActionCommand().equals(actionPaste)) {
            Action a = getActionMap().get(actionPaste);
            if (a != null) {
                a.actionPerformed(new ActionEvent(this.filePanel,
                        ActionEvent.ACTION_PERFORMED, null));
            }
        } else if (e.getActionCommand() == this.browseButton.getActionCommand()) {
            doBrowse();
        } else if (e.getActionCommand() == this.removeButton.getActionCommand()) {
            // Remove clicked
            doRemove();
        } else if (e.getActionCommand() == this.removeAllButton
                .getActionCommand()) {
            // Remove All clicked
            doRemoveAll();
        } else if (e.getActionCommand() == this.uploadButton.getActionCommand()) {
            // Upload clicked
            doStartUpload();
        } else if (e.getActionCommand() == this.stopButton.getActionCommand()) {
            // We request the thread to stop its job.
            doStopUpload();
        }
        // focus the table. This is necessary in order to enable mouse
        // events
        // for triggering tooltips.
        this.filePanel.focusTable();
    }

    // ///////////////////////////////////////////////////////////////////////////////
    // ///////////////// Implementation of the MouseListener
    // ///////////////////////////////////////////////////////////////////////////////

    /**
     * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
     */
    public void mouseClicked(MouseEvent mouseEvent) {
        maybeOpenPopupMenu(mouseEvent);
    }

    /**
     * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
     */
    public void mouseEntered(MouseEvent mouseEvent) {
        maybeOpenPopupMenu(mouseEvent);
    }

    /**
     * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
     */
    public void mouseExited(MouseEvent mouseEvent) {
        maybeOpenPopupMenu(mouseEvent);
    }

    /**
     * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
     */
    public void mousePressed(MouseEvent mouseEvent) {
        maybeOpenPopupMenu(mouseEvent);
    }

    /**
     * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
     */
    public void mouseReleased(MouseEvent mouseEvent) {
        if (mouseEvent.getClickCount() == 2) {
            // We have a double-click. Let's tell it to the current upload
            // policy...
            this.uploadPolicy.onFileDoubleClicked(this.filePanel
                    .getFileDataAt(mouseEvent.getPoint()));
        } else {
            maybeOpenPopupMenu(mouseEvent);
        }
    }

    /**
     * This method opens the popup menu, if the mouseEvent is relevant. In this
     * case it returns true. Otherwise, it does nothing and returns false.
     * 
     * @param mouseEvent The triggered mouse event.
     * @return true if the popup menu was opened, false otherwise.
     */
    public boolean maybeOpenPopupMenu(MouseEvent mouseEvent) {
        // Should we open one out of the numerous (2!) popup menus ?
        if (mouseEvent.isPopupTrigger()) {
            if ((mouseEvent.getModifiersEx() & InputEvent.CTRL_DOWN_MASK) == InputEvent.CTRL_DOWN_MASK) {
                // We open the debug menu
                if (this.jUploadDebugPopupMenu != null) {
                    this.jUploadDebugPopupMenu.show(mouseEvent.getComponent(),
                            mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
            } else {
                // Let's open the main popup menu
                if (this.jUploadMainPopupMenu != null) {
                    this.jUploadMainPopupMenu.show(mouseEvent.getComponent(),
                            mouseEvent.getX(), mouseEvent.getY());
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Select or unselect the applet buttons
     */
    public void updateButtonState() {
        if (this.fileUploadManagerThread != null
                && this.fileUploadManagerThread.isAlive()
                && !this.fileUploadManagerThread.isUploadFinished()) {
            // An upload is running on.
            this.browseButton.setEnabled(false);
            this.removeButton.setEnabled(false);
            this.removeAllButton.setEnabled(false);
            this.uploadButton.setEnabled(false);
            this.stopButton.setEnabled(true);
        } else {
            // No upload running on.
            this.browseButton.setEnabled(true);
            this.stopButton.setEnabled(false);

            boolean enabled = (this.filePanel.getFilesLength() > 0);
            this.removeButton.setEnabled(enabled);
            this.removeAllButton.setEnabled(enabled);
            this.uploadButton.setEnabled(enabled);
        }

    }

    /** Clear the current log window content. */
    public void clearLogWindow() {
        this.logWindow.setText("");
    }

    /**
     * Copy the log window content into the clipboard. Allows easy access to the
     * debug output.
     * 
     */
    public void copyLogWindow() {
        this.logWindow.selectAll();
        this.logWindow.copy();
    }

    /**
     * @return the browseButton
     */
    public JButton getBrowseButton() {
        return this.browseButton;
    }

    /**
     * @return the dndListener
     */
    public DnDListener getDndListener() {
        return this.dndListener;
    }

    /**
     * @return the filePanel
     */
    public FilePanel getFilePanel() {
        return this.filePanel;
    }

    /**
     * The component that contains the log window. It is used to display the
     * content of the log window, with the relevant scroll bars.
     * 
     * @return the jLogWindowPane
     */
    public JScrollPane getJLogWindowPane() {
        return this.jLogWindowPane;
    }

    /**
     * Get the log window, that is: the component where messages (debug, info,
     * error...) are written. You should not use this component directly, but:
     * <UL>
     * <LI>To display messages: use the UploadPolicy.displayXxx methods.
     * <LI>To place this component on the applet, when overriding the
     * {@link UploadPolicy#addComponentsToJUploadPanel(JUploadPanel)} method:
     * use the {@link #getJLogWindowPane()} method instead. The
     * {@link #logWindow} is embbeded in it.
     * </UL>
     * 
     * @return the logWindow
     */
    protected JUploadTextArea getLogWindow() {
        return this.logWindow;
    }

    /**
     * @return the preparationProgressBar
     */
    public JProgressBar getPreparationProgressBar() {
        return this.preparationProgressBar;
    }

    /**
     * @return the uploadProgressBar
     */
    public JProgressBar getUploadProgressBar() {
        return this.uploadProgressBar;
    }

    /**
     * @return the removeAllButton
     */
    public JButton getRemoveAllButton() {
        return this.removeAllButton;
    }

    /**
     * @return the removeButton
     */
    public JButton getRemoveButton() {
        return this.removeButton;
    }

    /**
     * @return the statusLabel
     */
    public JLabel getStatusLabel() {
        return this.statusLabel;
    }

    /**
     * @return the stopButton
     */
    public JButton getStopButton() {
        return this.stopButton;
    }

    /**
     * @return the uploadButton
     */
    public JButton getUploadButton() {
        return this.uploadButton;
    }

    /**
     * Standard setter for filePanel.
     * 
     * @param filePanel
     */
    public void setFilePanel(FilePanel filePanel) {
        this.filePanel = filePanel;
    }

}

⌨️ 快捷键说明

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