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

📄 abstracteditcvdialog.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     AbstractEditCVDialog.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.util.gui;import mpi.util.ControlledVocabulary;import java.awt.Component;import java.awt.Frame;import java.awt.GridBagConstraints;import java.awt.GridBagLayout;import java.awt.GridLayout;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.event.KeyEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;import java.util.List;import javax.swing.AbstractAction;import javax.swing.ActionMap;import javax.swing.InputMap;import javax.swing.JButton;import javax.swing.JComboBox;import javax.swing.JComponent;import javax.swing.JDialog;import javax.swing.JLabel;import javax.swing.JOptionPane;import javax.swing.JPanel;import javax.swing.JScrollPane;import javax.swing.JTextArea;import javax.swing.JTextField;import javax.swing.KeyStroke;import javax.swing.WindowConstants;/** * DOCUMENT ME! * $Id: jalopy_gnu_src_dist.xml,v 1.3 2007/02/06 13:30:33 hasloe Exp $ * @author $Author: hasloe $ * @version $Revision: 1.3 $ */public abstract class AbstractEditCVDialog extends JDialog    implements ActionListener, ItemListener {    /** Holds value of property DOCUMENT ME! */    private static final int DEFAULT_MINIMUM_HEIGHT = 500;    /** Holds value of property DOCUMENT ME! */    private static final int DEFAULT_MINIMUM_WIDTH = 550;    /** Holds value of property DOCUMENT ME! */    protected EditCVPanel cvEditorPanel;    /** Holds value of property DOCUMENT ME! */    protected JButton addCVButton;    /** Holds value of property DOCUMENT ME! */    protected JButton changeCVButton;    /** Holds value of property DOCUMENT ME! */    protected JButton closeDialogButton;    /** Holds value of property DOCUMENT ME! */    protected JButton deleteCVButton;    /** Holds value of property DOCUMENT ME! */    protected JComboBox cvComboBox;    /** Holds value of property DOCUMENT ME! */    protected JLabel currentCVLabel;    /** Holds value of property DOCUMENT ME! */    protected JLabel cvDescLabel;    /** Holds value of property DOCUMENT ME! */    protected JLabel cvNameLabel;    /** Holds value of property DOCUMENT ME! */    protected JLabel titleLabel;    /** Holds value of property DOCUMENT ME! */    protected JPanel cvButtonPanel;    /** Holds value of property DOCUMENT ME! */    protected JPanel cvPanel;    /** Holds value of property DOCUMENT ME! */    protected JTextArea cvDescArea;    /** Holds value of property DOCUMENT ME! */    protected JTextField cvNameTextField;    /** Holds value of property DOCUMENT ME! */    protected String cvContainsEntriesMessage = "contains entries.";    /** Holds value of property DOCUMENT ME! */    protected String cvInvalidNameMessage = "Invalid name.";    /** Holds value of property DOCUMENT ME! */    protected String cvNameExistsMessage = "Name exists already.";    /** Holds value of property DOCUMENT ME! */    protected String deleteQuestion = "delete anyway?";    /** Holds value of property DOCUMENT ME! */    protected String oldCVDesc;    // internal caching fields    /** Holds value of property DOCUMENT ME! */    protected String oldCVName;    /** Holds value of property DOCUMENT ME! */    protected int minimumHeight;    /** Holds value of property DOCUMENT ME! */    protected int minimumWidth;    /** Holds value of property DOCUMENT ME! */    private final boolean multipleCVs;    /**     * Constructor with standard EditCVPanel     * @param parent parent window     * @param modal modality     * @param multipleCVs if true, user can edit more than one CV     */    public AbstractEditCVDialog(Frame parent, boolean modal, boolean multipleCVs) {        this(parent, modal, multipleCVs, new EditCVPanel());    }    /**     *     * @param parent parent window     * @param modal modality     * @param multipleCVs if true, user can edit more than one CV     * @param cvEditorPanel panel which might have already controlled vocabulary     */    public AbstractEditCVDialog(Frame parent, boolean modal,        boolean multipleCVs, EditCVPanel cvEditorPanel) {        super(parent, modal);        this.cvEditorPanel = cvEditorPanel;        this.multipleCVs = multipleCVs;        minimumHeight = DEFAULT_MINIMUM_HEIGHT;        minimumWidth = DEFAULT_MINIMUM_WIDTH;        makeLayout();    }    /**     * The button actions.     *     * @param actionEvent the actionEvent     */    public void actionPerformed(ActionEvent actionEvent) {        Object source = actionEvent.getSource();        // check source equality        if (source == closeDialogButton) {            closeDialog();        } else if (source == addCVButton) {            addCV();        } else if (source == changeCVButton) {            changeCV();        } else if (source == deleteCVButton) {            deleteCV();        }    }    /**     * Handles a change in the cv selection.     *     * @param ie the item event     */    public void itemStateChanged(ItemEvent ie) {        if (ie.getSource() == cvComboBox) {            if (ie.getStateChange() == ItemEvent.SELECTED) {                cvEditorPanel.setControlledVocabulary((ControlledVocabulary) cvComboBox.getSelectedItem());            }            updateCVButtons();        }    }    /**     * test method with an cv list of size 0     * @param args no arguments needed     */    public static void main(String[] args) {        javax.swing.JFrame frame = new javax.swing.JFrame();        AbstractEditCVDialog dialog = new AbstractEditCVDialog(frame, false,                false) {                protected List getCVList() {                    return new java.util.ArrayList();                }            };        dialog.updateComboBox();        dialog.pack();        dialog.setVisible(true);    }    /**     * DOCUMENT ME!     *     * @return DOCUMENT ME!     */    protected abstract List getCVList();    /**     * Pack, size and set location.     */    protected void setPosition() {        pack();        setSize(Math.max(getSize().width, DEFAULT_MINIMUM_WIDTH),            Math.max(getSize().height, DEFAULT_MINIMUM_HEIGHT));        setLocationRelativeTo(getParent());    }    /**     * check if name is valid     *     */    protected void addCV() {        String name = cvNameTextField.getText();        name = name.trim();        if (name.length() == 0) {            showWarningDialog(cvInvalidNameMessage);            return;        }        if (cvExists(name)) {            // cv with that name already exists, warn            showWarningDialog(cvNameExistsMessage);            return;        }        addCV(name);    }    /**     * Creates a new ControlledVocabulary when there isn't already one with the     * same name and adds it to the List.     *     * @param name name of new CV     */    protected void addCV(String name) {        ControlledVocabulary cv = new ControlledVocabulary(name, "");        cvComboBox.addItem(cv);        cvEditorPanel.setControlledVocabulary(cv);    }    /**     * Checks whether name is valid and unique.     */    protected void changeCV() {        ControlledVocabulary cv = (ControlledVocabulary) cvComboBox.getSelectedItem();        if (cv == null) {            return;        }        String name = cvNameTextField.getText();        String desc = cvDescArea.getText();        if (name != null) {            name = name.trim();            if (name.length() < 1) {                showWarningDialog(cvInvalidNameMessage);                cvNameTextField.setText(oldCVName);                return;            }        }        if ((oldCVName != null) && !oldCVName.equals(name)) {            // check if there is already a cv with the new name            if (cvExists(name)) {                // cv with that name already exists, warn                showWarningDialog(cvNameExistsMessage);                return;            }            changeCV(cv, name, desc);        } else if (((oldCVDesc == null) && (desc != null) &&                (desc.length() > 0)) ||                ((oldCVDesc != null) &&                ((desc == null) || (desc.length() == 0))) ||                (!oldCVDesc.equals(desc))) {            changeCV(cv, null, desc);        }    }    /**     * changes name and description in specified ControlledVocabulary     * @param cv ControlledVocabulary to be changed     * @param name new name (may be null -> no change of name!)     * @param description new description     */    protected void changeCV(ControlledVocabulary cv, String name,        String description) {        cv.setDescription(description);        if (name != null) {            cv.setName(name);            cvEditorPanel.setControlledVocabulary(cv);        }    }    /**    * Closes the dialog    */    protected void closeDialog() {

⌨️ 快捷键说明

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