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

📄 editcvpanel.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        entryListModel = new DefaultListModel();        entryList = new JList(entryListModel);        entryValueLabel = new JLabel();        entryValueTextField = new JTextField();        addEntryButton = new JButton();        addEntryButton.setEnabled(false);        changeEntryButton = new JButton();        changeEntryButton.setEnabled(false);        deleteEntryButton = new JButton();        deleteEntryButton.setEnabled(false);        titleLabel = new JLabel();        entryDescLabel = new JLabel();        entryDescTextField = new JTextField();        moveEntriesPanel = new JPanel();        moveUpButton = new JButton(upIcon);        moveUpButton.setEnabled(false);        moveToTopButton = new JButton(topIcon);        moveToTopButton.setEnabled(false);        moveDownButton = new JButton(downIcon);        moveDownButton.setEnabled(false);        moveToBottomButton = new JButton(bottomIcon);        moveToBottomButton.setEnabled(false);        undoButton = new JButton(undoIcon);        undoButton.setEnabled(false);        redoButton = new JButton(redoIcon);        redoButton.setEnabled(false);        Dimension prefDim = new Dimension(MINIMAL_ENTRY_PANEL_WIDTH,                MOVE_BUTTON_SIZE);        Dimension buttonDimension = new Dimension(MOVE_BUTTON_SIZE,                MOVE_BUTTON_SIZE);        Insets insets = new Insets(2, 6, 2, 6);        // entry sorting buttons        moveEntriesPanel.setLayout(new GridBagLayout());        moveToTopButton.addActionListener(this);        moveToTopButton.setPreferredSize(buttonDimension);        moveToTopButton.setMaximumSize(buttonDimension);        moveToTopButton.setMinimumSize(buttonDimension);        moveUpButton.addActionListener(this);        moveUpButton.setPreferredSize(buttonDimension);        moveUpButton.setMaximumSize(buttonDimension);        moveUpButton.setMinimumSize(buttonDimension);        moveDownButton.addActionListener(this);        moveDownButton.setPreferredSize(buttonDimension);        moveDownButton.setMaximumSize(buttonDimension);        moveDownButton.setMinimumSize(buttonDimension);        moveToBottomButton.addActionListener(this);        moveToBottomButton.setPreferredSize(buttonDimension);        moveToBottomButton.setMaximumSize(buttonDimension);        moveToBottomButton.setMinimumSize(buttonDimension);        undoButton.addActionListener(this);        undoButton.setPreferredSize(buttonDimension);        undoButton.setMaximumSize(buttonDimension);        undoButton.setMinimumSize(buttonDimension);        redoButton.addActionListener(this);        redoButton.setPreferredSize(buttonDimension);        redoButton.setMaximumSize(buttonDimension);        redoButton.setMinimumSize(buttonDimension);        gridBagConstraints = new GridBagConstraints();        gridBagConstraints.gridwidth = 1;        gridBagConstraints.fill = GridBagConstraints.NONE;        gridBagConstraints.anchor = GridBagConstraints.NORTH;        gridBagConstraints.insets = insets;        moveEntriesPanel.add(moveToTopButton, gridBagConstraints);        moveEntriesPanel.add(moveUpButton, gridBagConstraints);        moveEntriesPanel.add(moveDownButton, gridBagConstraints);        moveEntriesPanel.add(moveToBottomButton, gridBagConstraints);        moveEntriesPanel.add(undoButton, gridBagConstraints);        moveEntriesPanel.add(redoButton, gridBagConstraints);        //other subcomponents                JScrollPane entryPane = new JScrollPane(entryList);        entryPane.setPreferredSize(prefDim);        entryPane.setMinimumSize(prefDim);        entryValueTextField.setPreferredSize(prefDim);        entryValueTextField.setMinimumSize(prefDim);        entryDescTextField.setPreferredSize(prefDim);        entryDescTextField.setMinimumSize(prefDim);        //main layout        setLayout(new GridBagLayout());        gridBagConstraints = new GridBagConstraints();        gridBagConstraints.gridx = 0;        gridBagConstraints.gridy = 0;        gridBagConstraints.gridheight = GridBagConstraints.REMAINDER;        gridBagConstraints.fill = GridBagConstraints.BOTH;        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;        gridBagConstraints.insets = insets;        gridBagConstraints.weightx = 0.5;        gridBagConstraints.weighty = 1.0;        add(entryPane, gridBagConstraints);        gridBagConstraints = new GridBagConstraints();        gridBagConstraints.gridx = 1;        gridBagConstraints.gridy = 0;        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;        gridBagConstraints.weightx = 0.5;        gridBagConstraints.insets = insets;        add(entryValueLabel, gridBagConstraints);        gridBagConstraints.gridy = GridBagConstraints.RELATIVE;        add(entryValueTextField, gridBagConstraints);        add(entryDescLabel, gridBagConstraints);        add(entryDescTextField, gridBagConstraints);        add(addEntryButton, gridBagConstraints);        add(changeEntryButton, gridBagConstraints);        add(deleteEntryButton, gridBagConstraints);        add(moveEntriesPanel, gridBagConstraints);        undoButton.setToolTipText(undoManager.getUndoPresentationName());        entryValueTextField.addActionListener(this);        entryDescTextField.addActionListener(this);        addEntryButton.addActionListener(this);        changeEntryButton.addActionListener(this);        deleteEntryButton.addActionListener(this);    }    /**     * Updates some UI fields after a change in the selected CV.     *     */    protected void resetViewer() {        // reset some fields        entryListModel.clear();        if (cv != null) {            CVEntry[] entries = cv.getEntries();            currentEntry = null;            for (int i = 0; i < entries.length; i++) {                entryListModel.addElement(entries[i]);                if (i == 0) {                    entryList.setSelectedIndex(0);                    currentEntry = entries[0];                }            }            addEntryButton.setEnabled(true);        } else {            cv = null;            addEntryButton.setEnabled(false);        }        updateEntryButtons();        updateTextFields();    }    /**     * Since this dialog is meant to be modal a Locale change while this dialog     * is open  is not supposed to happen. This will set the labels etc. using     * the current locale  strings.     */    protected void updateLabels() {        moveToTopButton.setToolTipText("Top");        moveUpButton.setToolTipText("Up");        moveDownButton.setToolTipText("Down");        moveToBottomButton.setToolTipText("Bottom");        deleteEntryButton.setText("Delete");        changeEntryButton.setText("Change");        addEntryButton.setText("Add");        entryDescLabel.setText("Description");        entryValueLabel.setText("Value");        setBorder(new TitledBorder("Entries"));        undoButton.setToolTipText(undoManager.getUndoPresentationName());        redoButton.setToolTipText(undoManager.getRedoPresentationName());    }    /**     * Reextracts the entries from the current CV after an add, change or     * delete entry operation on the CV.     *     */    protected void updateList() {        if (cv != null) {            entryList.removeListSelectionListener(this);            entryListModel.clear();            CVEntry[] entries = cv.getEntries();            for (int i = 0; i < entries.length; i++) {                entryListModel.addElement(entries[i]);            }            entryList.addListSelectionListener(this);        }    }    private void setSelectedEntries(CVEntry[] entries) {        currentEntry = null;        if ((entries != null) && (entries.length > 0)) {            entryList.removeListSelectionListener(this);            for (int i = 0; i < entryListModel.getSize(); i++) {                for (int j = 0; j < entries.length; j++) {                    if (entryListModel.getElementAt(i).equals(entries[j])) {                        entryList.addSelectionInterval(i, i);                    }                }            }            entryList.addListSelectionListener(this);        }        updateEntryButtons();        updateTextFields();    }    private void setSelectedEntry(CVEntry entry) {        if (entry != null) {            setSelectedEntries(new CVEntry[] { entry });        } else {            setSelectedEntries(null);        }    }    /**     * Moves the selected entries to the bottom of the entry list.     * @param the type of the move (up, down, etc.) as defined in BasicControlledVocabulary     */    private void moveEntries(int moveType) {        if (cv == null) {            return;        }        Object[] selEntries = entryList.getSelectedValues();        if (selEntries.length == 0) {            return;        }        CVEntry[] entriesToBeMoved = new CVEntry[selEntries.length];        for (int i = 0; i < selEntries.length; i++) {            entriesToBeMoved[i] = (CVEntry) selEntries[i];        }        cv.moveEntries(entriesToBeMoved, moveType);        updateList();        setSelectedEntries(entriesToBeMoved);    }    /**     * Invokes the redo method of the <code>UndoManager</code>.     */    private void redo() {        try {            undoManager.redo();            updateList();            setSelectedEntry(null);        } catch (CannotRedoException cre) {            //LOG.warning(LogUtil.formatStackTrace(cre));        }        updateUndoRedoButtons();    }    /**     * Shows a warning/error dialog with the specified message string.     *     * @param message the message to display     */    private void showWarningDialog(String message) {        JOptionPane.showMessageDialog(this, message, "Warning",            JOptionPane.WARNING_MESSAGE);    }    /**     * Invokes the undo method of the <code>UndoManager</code>.     */    private void undo() {        try {            undoManager.undo();            updateList();            setSelectedEntry(null);        } catch (CannotUndoException cue) {            // LOG.warning(LogUtil.formatStackTrace(cue));        }        updateUndoRedoButtons();    }    /**    * Enables or disables buttons depending on the selected entries.    */    private void updateEntryButtons() {        if ((entryList == null) || (entryList.getSelectedIndex() == -1)) {            changeEntryButton.setEnabled(false);            deleteEntryButton.setEnabled(false);            moveToTopButton.setEnabled(false);            moveUpButton.setEnabled(false);            moveDownButton.setEnabled(false);            moveToBottomButton.setEnabled(false);            currentEntry = null;        } else {            int firstIndex = entryList.getSelectedIndices()[0];            int numSelected = entryList.getSelectedIndices().length;            int lastIndex = entryList.getSelectedIndices()[numSelected - 1];            changeEntryButton.setEnabled(true);            deleteEntryButton.setEnabled(true);            if (firstIndex > 0) {                moveToTopButton.setEnabled(true);                moveUpButton.setEnabled(true);            } else {                moveToTopButton.setEnabled(false);                moveUpButton.setEnabled(false);            }            if (lastIndex < (entryList.getModel().getSize() - 1)) {                moveDownButton.setEnabled(true);                moveToBottomButton.setEnabled(true);            } else {                moveDownButton.setEnabled(false);                moveToBottomButton.setEnabled(false);            }            currentEntry = (CVEntry) entryList.getSelectedValue();        }    }    private void updateTextFields() {        if (entryList.getSelectedIndex() == -1) {            entryValueTextField.setText(EMPTY);            entryDescTextField.setText(EMPTY);        } else {            //put the first selected entry into text fields            CVEntry selEntry = (CVEntry) entryList.getSelectedValue();            entryValueTextField.setText(selEntry.getValue());            entryDescTextField.setText(selEntry.getDescription());        }        if (entryValueTextField.isEnabled()) {            entryValueTextField.requestFocus();        }    }    /**     * Enables or disables the undo/redo buttons.     */    private void updateUndoRedoButtons() {        undoButton.setEnabled(undoManager.canUndo());        redoButton.setEnabled(undoManager.canRedo());    }}

⌨️ 快捷键说明

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