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

📄 accessibledialog.java

📁 SWING的界面UI包 SWING的界面UI包
💻 JAVA
字号:
/* * AccessibleDialog.java * * Created on 2007年9月1日, 上午10:49 */package dyno.swing.designer.properties.editors.accessibles;import dyno.swing.designer.beans.Util;import dyno.swing.designer.properties.ValidationException;import dyno.swing.designer.properties.types.Item;import java.awt.CardLayout;import java.awt.Component;import java.awt.Frame;import javax.swing.DefaultComboBoxModel;import javax.swing.JPanel;import javax.swing.event.ChangeListener;/** * * @author  William Chen */public class AccessibleDialog extends javax.swing.JDialog implements AccessibleEditor {    protected Object value;    protected boolean OK;    public boolean isOK() {        return OK;    }    /** Creates new form AccessibleDialog */    public AccessibleDialog(Frame parent, boolean modal) {        super(parent, modal);        initComponents();        Item[] items = getAccessibleItems();        if (items != null) {            DefaultComboBoxModel model = new DefaultComboBoxModel();            for (Item item : items) {                model.addElement(item);                Component component = (Component) item.getValue();                String name = item.getName();                if (component == null) {                    component = new JPanel();                }                pAccessibles.add(component, name);            }            cmbTypes.setModel(model);        }    }    protected Item[] getAccessibleItems() {        return null;    }    /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents    private void initComponents() {        jLabel1 = new javax.swing.JLabel();        cmbTypes = new javax.swing.JComboBox();        pAccessibles = new javax.swing.JPanel();        btnCancel = new javax.swing.JButton();        btnOK = new javax.swing.JButton();        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);        jLabel1.setText("Type:");        cmbTypes.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                cmbTypesActionPerformed(evt);            }        });        pAccessibles.setLayout(new java.awt.CardLayout());        btnCancel.setText("Cancel");        btnCancel.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                btnCancelActionPerformed(evt);            }        });        btnOK.setText("OK");        btnOK.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                btnOKActionPerformed(evt);            }        });        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());        getContentPane().setLayout(layout);        layout.setHorizontalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)                    .addComponent(pAccessibles, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 356, Short.MAX_VALUE)                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()                        .addComponent(jLabel1)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(cmbTypes, 0, 322, Short.MAX_VALUE))                    .addGroup(layout.createSequentialGroup()                        .addComponent(btnOK)                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                        .addComponent(btnCancel)))                .addContainerGap())        );        layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {btnCancel, btnOK});        layout.setVerticalGroup(            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)            .addGroup(layout.createSequentialGroup()                .addContainerGap()                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(jLabel1)                    .addComponent(cmbTypes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addComponent(pAccessibles, javax.swing.GroupLayout.DEFAULT_SIZE, 189, Short.MAX_VALUE)                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)                    .addComponent(btnCancel)                    .addComponent(btnOK))                .addContainerGap())        );        pack();    }// </editor-fold>//GEN-END:initComponents    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed        OK = false;        dispose();    }//GEN-LAST:event_btnCancelActionPerformed    private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed        Item item = (Item) cmbTypes.getSelectedItem();        AccessibleEditor accessible = (AccessibleEditor) item.getValue();        if (accessible != null) {            try {                accessible.validateValue();            } catch (ValidationException ve) {                Util.showMessage(ve.getMessage(), this);                return;            }            value = accessible.getValue();        }        OK = true;        dispose();    }//GEN-LAST:event_btnOKActionPerformed    private void cmbTypesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmbTypesActionPerformed        Item item = (Item) cmbTypes.getSelectedItem();        CardLayout layout = (CardLayout) pAccessibles.getLayout();        String name = item.getName();        layout.show(pAccessibles, name);    }//GEN-LAST:event_cmbTypesActionPerformed    /**     * @param args the command line arguments     */    public static void main(String[] args) {        java.awt.EventQueue.invokeLater(new Runnable() {            public void run() {                AccessibleDialog dialog = new AccessibleDialog(new javax.swing.JFrame(), true);                dialog.addWindowListener(new java.awt.event.WindowAdapter() {                    public void windowClosing(java.awt.event.WindowEvent e) {                        System.exit(0);                    }                });                dialog.setVisible(true);            }        });    }    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JButton btnCancel;    private javax.swing.JButton btnOK;    private javax.swing.JComboBox cmbTypes;    private javax.swing.JLabel jLabel1;    private javax.swing.JPanel pAccessibles;    // End of variables declaration//GEN-END:variables    public void validateValue() throws ValidationException {        Item item = (Item) cmbTypes.getSelectedItem();        Component component = (Component) item.getValue();        if (component != null && component instanceof AccessibleEditor) {            AccessibleEditor accessible = (AccessibleEditor) component;            accessible.validateValue();        }    }    public Object getValue() {        return value;    }    public void setValue(Object v) {        this.value = v;    }    protected void selectItem(int index) {        cmbTypes.setSelectedIndex(index);    }    public Component getEditor() {        return this;    }    public void addChangeListener(ChangeListener l) {    }    public void removeChangeListener(ChangeListener l) {    }}

⌨️ 快捷键说明

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