|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun * Microsystems, Inc. All Rights Reserved. */ package org.openide.explorer.propertysheet.editors; import java.util.ResourceBundle; import javax.swing.*; import org.openide.*; import org.openide.util.NbBundle; /** * Panel for editing the arrays of any kind of Object. * This is an abstract class which should be subclassed * for the specified types of arrays (e.g. Identifier[], * MethodParameter[], ...) * * @author Petr Hamernik */ abstract class ObjectArrayPanel extends javax.swing.JPanel { /** Resource bundle. */ static final ResourceBundle bundle = NbBundle.getBundle(ObjectArrayPanel.class); /** The list model for the edited data. */ protected DefaultListModel model; /** Creates new form ListPanel */ public ObjectArrayPanel() { initComponents (); upButton.setMnemonic(bundle.getString("CTL_MoveUp_Mnemonic").charAt(0)); downButton.setMnemonic(bundle.getString("CTL_MoveDown_Mnemonic").charAt(0)); addButton.setMnemonic(bundle.getString("CTL_Add_Mnemonic").charAt(0)); removeButton.setMnemonic(bundle.getString("CTL_Remove_Mnemonic").charAt(0)); changeButton.setMnemonic(bundle.getString("CTL_Change_Mnemonic").charAt(0)); model = new DefaultListModel(); list.setModel(model); updateButtons(); getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_ObjectArrayPanel")); list.getAccessibleContext().setAccessibleName(bundle.getString("ACS_ObjectArrayPanel_List")); list.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_ObjectArrayPanel_List")); upButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_MoveUp")); downButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_MoveDown")); addButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_Add")); removeButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Remove")); changeButton.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_Change")); } /** 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 FormEditor. */ private void initComponents() {//GEN-BEGIN:initComponents jScrollPane1 = new javax.swing.JScrollPane(); list = new javax.swing.JList(); upButton = new javax.swing.JButton(); downButton = new javax.swing.JButton(); addButton = new javax.swing.JButton(); removeButton = new javax.swing.JButton(); changeButton = new javax.swing.JButton(); setLayout(new java.awt.GridBagLayout()); java.awt.GridBagConstraints gridBagConstraints1; jScrollPane1.setPreferredSize(new java.awt.Dimension(200, 3)); list.setVisibleRowCount(3); list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); list.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { listValueChanged(evt); } }); list.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { listMouseClicked(evt); } }); jScrollPane1.setViewportView(list); gridBagConstraints1 = new java.awt.GridBagConstraints(); gridBagConstraints1.gridheight = 6; gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints1.insets = new java.awt.Insets(12, 12, 0, 11); gridBagConstraints1.weightx = 1.0; gridBagConstraints1.weighty = 1.0; add(jScrollPane1, gridBagConstraints1); upButton.setText(bundle.getString("CTL_MoveUp")); upButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { upButtonActionPerformed(evt); } }); gridBagConstraints1 = new java.awt.GridBagConstraints(); gridBagConstraints1.gridx = 1; gridBagConstraints1.gridy = 3; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets(0, 0, 5, 11); add(upButton, gridBagConstraints1); downButton.setText(bundle.getString("CTL_MoveDown")); downButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { downButtonActionPerformed(evt); } }); gridBagConstraints1 = new java.awt.GridBagConstraints(); gridBagConstraints1.gridx = 1; gridBagConstraints1.gridy = 4; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets(0, 0, 0, 11); add(downButton, gridBagConstraints1); addButton.setText(bundle.getString("CTL_Add")); addButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { addButtonActionPerformed(evt); } }); gridBagConstraints1 = new java.awt.GridBagConstraints(); gridBagConstraints1.gridx = 1; gridBagConstraints1.gridy = 0; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets(12, 0, 5, 11); add(addButton, gridBagConstraints1); removeButton.setText(bundle.getString("CTL_Remove")); removeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { removeButtonActionPerformed(evt); } }); gridBagConstraints1 = new java.awt.GridBagConstraints(); gridBagConstraints1.gridx = 1; gridBagConstraints1.gridy = 2; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets(0, 0, 11, 11); add(removeButton, gridBagConstraints1); changeButton.setText(bundle.getString("CTL_Change")); changeButton.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { changeButtonActionPerformed(evt); } }); gridBagConstraints1 = new java.awt.GridBagConstraints(); gridBagConstraints1.gridx = 1; gridBagConstraints1.gridy = 1; gridBagConstraints1.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints1.insets = new java.awt.Insets(0, 0, 5, 11); add(changeButton, gridBagConstraints1); }//GEN-END:initComponents private void listMouseClicked (java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listMouseClicked if (org.openide.awt.MouseUtils.isDoubleClick(evt)) { int selIndex = list.getSelectedIndex(); if (selIndex != -1) { Object newValue = editValue(model.getElementAt(selIndex)); if (newValue != null) { model.setElementAt(newValue,selIndex); modelChanged(); updateButtons(); } } } }//GEN-LAST:event_listMouseClicked private void listValueChanged (javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listValueChanged updateButtons(); }//GEN-LAST:event_listValueChanged private void downButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downButtonActionPerformed int selIndex = list.getSelectedIndex(); model.set(selIndex + 1, model.set(selIndex, model.getElementAt(selIndex + 1))); list.setSelectedIndex(selIndex + 1); modelChanged(); updateButtons(); }//GEN-LAST:event_downButtonActionPerformed private void upButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_upButtonActionPerformed int selIndex = list.getSelectedIndex(); model.set(selIndex - 1, model.set(selIndex, model.getElementAt(selIndex - 1))); list.setSelectedIndex(selIndex - 1); modelChanged(); updateButtons(); }//GEN-LAST:event_upButtonActionPerformed private void changeButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_changeButtonActionPerformed int selIndex = list.getSelectedIndex(); Object newValue = editValue(model.getElementAt(selIndex)); if (newValue != null) { model.setElementAt(newValue,selIndex); modelChanged(); updateButtons(); } }//GEN-LAST:event_changeButtonActionPerformed private void removeButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed int selIndex = list.getSelectedIndex(); model.remove(selIndex); int size = model.size(); if (size > 0) { selIndex = Math.min(size - 1, selIndex); list.setSelectedIndex(selIndex); } modelChanged(); updateButtons(); }//GEN-LAST:event_removeButtonActionPerformed private void addButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed Object newValue = insertNewValue(); if (newValue != null) { model.addElement(newValue); list.setSelectedIndex(model.size() - 1); modelChanged(); updateButtons(); } }//GEN-LAST:event_addButtonActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JScrollPane jScrollPane1; private javax.swing.JList list; private javax.swing.JButton upButton; private javax.swing.JButton downButton; private javax.swing.JButton addButton; private javax.swing.JButton removeButton; private javax.swing.JButton changeButton; // End of variables declaration//GEN-END:variables /** Method for subclasses. * @return the main JList component in the panel */ protected JList getListComponent() { return list; } /** Updates the 'enable' status of the buttons in the panel. */ private void updateButtons() { boolean isEmpty = model.isEmpty(); int selIndex = list.getSelectedIndex(); boolean isSelected = (selIndex != -1); removeButton.setEnabled(isSelected); changeButton.setEnabled(isSelected); upButton.setEnabled(isSelected && (selIndex > 0)); downButton.setEnabled(isSelected && (selIndex < model.size() - 1)); } /** Ask user for new value. * @return new value or |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.