📄 dialplandialog.java
字号:
/* * ==================================================================== * The Vovida Software License, Version 1.0 * * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The names "VOCAL", "Vovida Open Communication Application Library", * and "Vovida Open Communication Application Library (VOCAL)" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact vocal@vovida.org. * * 4. Products derived from this software may not be called "VOCAL", nor * may "VOCAL" appear in their name, without prior written * permission of Vovida Networks, Inc. * * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by Vovida * Networks, Inc. and many individuals on behalf of Vovida Networks, * Inc. For more information on Vovida Networks, Inc., please see * <http://www.vovida.org/>. * *//** * Title: <p> * Description: <p> * Copyright: Copyright (c) <p> * Company: <p> * @author * @version 1.0 */package vocal.ui;import java.awt.event.ActionListener;import java.util.Vector;import java.awt.event.ActionEvent;import javax.swing.*;import java.awt.*;import vocal.ui.BasicTableModel;import javax.swing.table.TableColumn;import javax.swing.border.*;public class DialPlanDialog extends JDialog{ DialPlanScreen tableParent; BasicTableModel tableModel = new BasicTableModel(); TableColumn tableColumn = new TableColumn(); protected int testCounter = 0; protected int oldIndex = 0; protected OkButtonListener okButtonActionListener = null; protected JPanel northPanel = new JPanel(); protected JPanel centerPanel = new JPanel(); JPanel southPanel = new JPanel(); JButton okButton = new JButton(); FlowLayout flowLayout2 = new FlowLayout(); GridLayout gridLayout1 = new GridLayout(); JPanel buttonGridLayout = new JPanel(); JPanel buttonFlowPanel = new JPanel(); JButton cancelButton = new JButton(); FlowLayout flowLayout3 = new FlowLayout(); JPanel eastPanel = new JPanel(); BorderLayout borderLayout1 = new BorderLayout(); JPanel addDeleteGridPanel = new JPanel(); GridLayout gridLayout2 = new GridLayout(); JButton addButton = new JButton(); JButton deleteButton = new JButton(); JComboBox indexComboBox = new JComboBox(); JPanel indexPanel = new JPanel(); JLabel indexLabel = new JLabel(); FlowLayout flowLayout4 = new FlowLayout(); JLabel keyLabel = new JLabel(); InternalClipboardField keyTextField = new InternalClipboardField(); JLabel contactLabel = new JLabel(); JPanel tablePanel = new JPanel(); JScrollPane jScrollPane1 = new JScrollPane(); FlowLayout flowLayout1 = new FlowLayout(); JTable dialPlanTable = new JTable(); Component keyStrut; Component indexStrut; Border border1; public DialPlanDialog(DialPlanScreen parent, int maxIndexChoice) { super(); tableParent = parent; String indexChoices[] = new String[maxIndexChoice]; for (int i = 0; i < maxIndexChoice; i++) { indexChoices[i] = Integer.toString(i); } indexComboBox = new JComboBox(indexChoices); try { jbInit(); } catch (Exception e) { e.printStackTrace(); } init(); okButtonActionListener.setNewEntry(true); tableModel.addNewEntry(new String("")); tableModel.fireTableRowsInserted(0, 0); pack(); } public DialPlanDialog(DialPlanScreen parent, int maxIndex, String keyValue, Vector contacts, int currentIndex) { this(parent, maxIndex); okButtonActionListener.setNewEntry(false); tableModel.deleteRow(0); oldIndex = currentIndex; keyTextField.setText(keyValue); for (int i = contacts.size() - 1; i >= 0; i--) { tableModel.addNewEntry((String) contacts.elementAt(i)); tableModel.fireTableRowsInserted(0, 0); } indexComboBox.setSelectedIndex(currentIndex); } private void jbInit() throws Exception { keyStrut = Box.createHorizontalStrut(30); indexStrut = Box.createHorizontalStrut(40); border1 = BorderFactory.createEmptyBorder(10, 0, 20, 5); this.setTitle("Index:"); this.setModal(true); okButton.setText("Ok"); buttonGridLayout.setLayout(gridLayout1); buttonFlowPanel.setLayout(flowLayout2); cancelButton.setText("Cancel"); northPanel.setLayout(flowLayout3); gridLayout1.setHgap(3); eastPanel.setLayout(borderLayout1); addDeleteGridPanel.setLayout(gridLayout2); gridLayout2.setColumns(1); gridLayout2.setRows(2); gridLayout2.setVgap(5); addButton.setText("Add Contact"); deleteButton.setText("Delete Contact"); indexLabel.setForeground(Color.black); indexLabel.setText("Index:"); flowLayout3.setAlignment(FlowLayout.LEFT); flowLayout3.setHgap(8); flowLayout3.setVgap(3); eastPanel.setBorder(border1); centerPanel.setLayout(flowLayout4); flowLayout4.setAlignment(FlowLayout.LEFT); keyLabel.setForeground(Color.black); keyLabel.setText("Key:"); keyTextField.setPreferredSize(new Dimension(150, 17)); contactLabel.setForeground(Color.black); contactLabel.setText("Contacts:"); tablePanel.setLayout(flowLayout1); flowLayout1.setAlignment(FlowLayout.LEFT); this.getContentPane().add(northPanel, BorderLayout.NORTH); northPanel.add(keyStrut, null); northPanel.add(keyLabel, null); northPanel.add(keyTextField, null); northPanel.add(indexStrut, null); northPanel.add(indexPanel, null); indexPanel.add(indexLabel, null); indexPanel.add(indexComboBox, null); this.getContentPane().add(centerPanel, BorderLayout.CENTER); centerPanel.add(contactLabel, null); centerPanel.add(tablePanel, null); tablePanel.add(jScrollPane1, null); jScrollPane1.getViewport().add(dialPlanTable, null); this.getContentPane().add(southPanel, BorderLayout.SOUTH); southPanel.add(buttonFlowPanel, null); buttonFlowPanel.add(buttonGridLayout, null); buttonGridLayout.add(okButton, null); buttonGridLayout.add(cancelButton, null); this.getContentPane().add(eastPanel, BorderLayout.EAST); eastPanel.add(addDeleteGridPanel, BorderLayout.CENTER); addDeleteGridPanel.add(addButton, null); addDeleteGridPanel.add(deleteButton, null); } private void init() { dialPlanTable.setModel(tableModel); tableColumn.setPreferredWidth(180); tableColumn.setCellEditor(new DefaultCellEditor(new InternalClipboardField())); dialPlanTable.addColumn(tableColumn); dialPlanTable.setCellSelectionEnabled(true); dialPlanTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); dialPlanTable.setPreferredScrollableViewportSize(new Dimension(300, 50)); addButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { CellEditor cellEditor = dialPlanTable.getCellEditor(); if (cellEditor != null) { cellEditor.stopCellEditing(); } tableModel.addNewEntry(new String("")); tableModel.fireTableRowsInserted(0, 0); } }); deleteButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int selectedRow = dialPlanTable.getSelectedRow(); if (selectedRow > -1) { tableModel.deleteRow(selectedRow); tableModel.fireTableRowsDeleted(selectedRow, selectedRow); } } }); okButtonActionListener = new OkButtonListener(); okButton.addActionListener(okButtonActionListener); cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { dispose(); } }); } public void show() { if (testCounter > 0) { // strange thing: this keeps getting called in a loop. return; } testCounter++; super.show(); setVisible(true); } // we have two possible behaviors of the Ok button action listener. class OkButtonListener implements ActionListener { private boolean isNewEntry = true; void setNewEntry(boolean newValue) { isNewEntry = newValue; } public void actionPerformed(ActionEvent e) { CellEditor cellEditor = dialPlanTable.getCellEditor(); if (cellEditor != null) { cellEditor.stopCellEditing(); } String keyContents = keyTextField.getText(); if (keyContents.equals("")) { JOptionPane.showMessageDialog(DialPlanDialog.this, "cannot save an empty keyfield"); return; } Vector contacts = tableModel.getTableData(); if (contacts.size() < 1) { JOptionPane.showMessageDialog(DialPlanDialog.this, "cannot save an empty contact list"); return; } if (!isNewEntry) { tableParent.removeEntry(oldIndex); } int index = 0; try { index = Integer.parseInt((String) indexComboBox.getSelectedItem()); } catch (NumberFormatException e1) { e1.printStackTrace(); } tableParent.addEntry(keyContents, contacts, index); dispose(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -