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

📄 dialplanscreen.java

📁 这是一个用java和xml编写的流媒体服务器管理软件
💻 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 vocal.data.*;import java.awt.*;import javax.swing.*;import javax.swing.event.ListSelectionListener;import javax.swing.event.ListSelectionEvent;import javax.swing.table.*;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.util.Vector;import javax.swing.border.*;import java.lang.Integer;import java.lang.reflect.Method;/** * $RCSfile: DialPlanScreen.java,v $ *  * @author $Author: bko $, $Date: 2002/12/12 02:27:08 $ * @version $Revision: 1.16 $ */public class DialPlanScreen extends FormPanelScreen implements ActionListener{  private static final int DEFAULT_ROW_HEIGHT = 16;  private static Method setRowHeightIntInt = null;  private ConfigureServers mainScreen;  private String typeString = null;  private DialPlanData dataManager;  private DialPlanTableModel tableModel;  private ConfigTree configTree;  private TableColumn column0, column1, column2;  BorderLayout borderLayout2 = new BorderLayout();  JPanel titlePanel = new JPanel();  FlowLayout flowLayout1 = new FlowLayout();  JLabel titleLabel = new JLabel();  JPanel tablePanel = new JPanel();  JScrollPane tableScrollPane = new JScrollPane();  BorderLayout borderLayout1 = new BorderLayout();  JPanel labelPanel = new JPanel();  JPanel buttonGridPanel = new JPanel();  GridLayout gridLayout1 = new GridLayout();  JButton addButton = new JButton();  JButton deleteButton = new JButton();  JButton editButton = new JButton();  Border border1;  JTable dialPlanTable = new JTable();  FlowLayout flowLayout2 = new FlowLayout();  // Class memeber initialization  static  {    // use reflection to see if the method setRowHeight(int, int)    // exists.  Basically a test to see if we are running java1.2    // or java 1.3.    try    {      // throws exception if does not exist      setRowHeightIntInt = JTable.class.getMethod("setRowHeight", new Class[]      {        Integer.TYPE, Integer.TYPE      });    }    catch (Exception e)    {      // normal program flow.  table.setRowHeight(int, int) does not exist.    }  }  public DialPlanScreen(ConfigureServers screen, String type)  {    mainScreen = screen;    typeString = type;    configTree = mainScreen.getConfigTree();    // the index column    column0 = new TableColumn(0, 40);    column0.setMaxWidth(40);    column0.setHeaderValue(new String("index"));    // the keys column    column1 = new TableColumn(1, 80);    column1.setHeaderValue(new String("key"));    // the contact column    column1.setCellEditor(new DefaultCellEditor(new InternalClipboardField()));    column2 = new TableColumn(2, 300);    column2.setHeaderValue(new String("contact"));    column2.setCellEditor(new DefaultCellEditor(new InternalClipboardField()));    column2.setCellRenderer(new VectorCellRenderer());    tableModel = new DialPlanTableModel();    dialPlanTable.setPreferredScrollableViewportSize(new Dimension(400, 200));    addButton.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        mainScreen.disableTree();        DialPlanDialog dialog = new DialPlanDialog(DialPlanScreen.this,                 tableModel.getRowCount() + 1);        dialog.show();      }    });    deleteButton.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        mainScreen.disableTree();        int selectedRow = dialPlanTable.getSelectedRow();        if (selectedRow == -1)        {          JOptionPane.showMessageDialog(DialPlanScreen.this,                   "Please select a Dial Plan Entry to delete");          return;        }        String indexString = (String) tableModel.getValueAt(selectedRow, 0);        String keyString = (String) tableModel.getValueAt(selectedRow, 1);        int confirmChoice = JOptionPane.showConfirmDialog(DialPlanScreen.this,                 "Are you sure you want to delete " + keyString                 + "\nat index " + indexString + "?");        if (confirmChoice == JOptionPane.YES_OPTION)        {          removeEntry(selectedRow);          dialPlanTable.clearSelection();        }      }    });    editButton.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        mainScreen.disableTree();        int selectedRow = dialPlanTable.getSelectedRow();        if (selectedRow == -1)        {          JOptionPane.showMessageDialog(DialPlanScreen.this,                   "Please select a Dial Plan Entry to edit");          return;        }        DialPlanDialog dialog = new DialPlanDialog(DialPlanScreen.this,                 tableModel.getRowCount(),                 (String) tableModel.getValueAt(selectedRow, 1),                 (Vector) tableModel.getValueAt(selectedRow, 2), selectedRow);        dialog.show();      }    });    try    {      jbInit();    }    catch (Exception e)    {      e.printStackTrace();    }    initTable();    dialPlanTable.revalidate();  }  public void activate()  {    dataManager = configTree.getDialPlanData();    tableModel.setData(dataManager.getDialPlanData());    ensureCorrectRowHeight();  }  /**   * Remove an entry from the Dial Plan table.   * @param index the entry at this index will be removed   */  protected void removeEntry(int index)  {    int numContacts = ((Vector) tableModel.getValueAt(index, 2)).size();    tableModel.deleteEntry(index);    // If setRowHeightIntInt is not null we can just exit, otherwise we might    // have to adjust the heights of all the table rows.    if (setRowHeightIntInt == null)    {      if ((numContacts > 1)           && (dialPlanTable.getRowHeight()               == numContacts * DEFAULT_ROW_HEIGHT))      {        ensureCorrectRowHeight();        if (index > tableModel.getRowCount())        {          index--;        }        if (index >= 0)        {          dialPlanTable.scrollRectToVisible(dialPlanTable.getCellRect(index,                   0, false));        }      }    }  }  /**   * Add an entry to the Dial Plan table.   * @param key the value of the key Element   * @param contacts a value for each contact Element   * @param index the index at which this new Element   * will be inserted   */  protected void addEntry(String key, Vector contacts, int index)  {    tableModel.addNewEntry(key, contacts, index);    dialPlanTable.setRowSelectionInterval(index, index);    ensureCorrectRowHeight(index, contacts.size());  }  /**   * Travels through all the the table rows to ensure that the row height   * is optimal ie. no larger or smaller than needed.   */  private void ensureCorrectRowHeight()  {    // check all rows    // If setRowHeightIntInt is not null, use to to set the individual row    // heights, otherwise execute setRowHeight(int)    boolean invokeFailed = false;    if (setRowHeightIntInt != null)    {      try      {        Integer[] intArgs = new Integer[2];        int numContacts;        for (int i = 0; i < tableModel.getRowCount(); i++)        {          numContacts = ((Vector) tableModel.getValueAt(i, 2)).size();          intArgs[0] = new Integer(i);          intArgs[1] = new Integer(numContacts * DEFAULT_ROW_HEIGHT);          setRowHeightIntInt.invoke(dialPlanTable, intArgs);        }      }      catch (Exception e)      {        e.printStackTrace();        invokeFailed = true;      }    }    if (setRowHeightIntInt == null || invokeFailed)    {      int maxNumContacts = 1;      Vector contactVector;      for (int i = 0; i < tableModel.getRowCount(); i++)      {        contactVector = (Vector) tableModel.getValueAt(i, 2);        if (contactVector.size() > maxNumContacts)        {          maxNumContacts = contactVector.size();        }      }      dialPlanTable.setRowHeight(maxNumContacts * DEFAULT_ROW_HEIGHT);    }  }  /**   * Makes sure the row height is optimal.   * @param row the row to use as a prototype height   * @param numContacts the number of contacts in <I>row</I>   */  private void ensureCorrectRowHeight(int row, int numContacts)  {    // If setRowHeightIntInt is not null, execute it, otherwise    // execute setRowHeight(int)    boolean invokeFailed = false;    if (setRowHeightIntInt != null)    {      try      {        Integer[] intArgs =         {          new Integer(row), new Integer(numContacts * DEFAULT_ROW_HEIGHT)        };        setRowHeightIntInt.invoke(dialPlanTable, intArgs);      }      catch (Exception e)      {        e.printStackTrace();        invokeFailed = true;      }    }    if (setRowHeightIntInt == null || invokeFailed)    {      int height = numContacts * DEFAULT_ROW_HEIGHT;      if (dialPlanTable.getRowHeight() < height)      {        dialPlanTable.setRowHeight(height);        dialPlanTable.scrollRectToVisible(dialPlanTable.getCellRect(row, 0,                 false));      }    }  }  private void jbInit() throws Exception  {    border1 = BorderFactory.createEmptyBorder(3, 3, 3, 3);    this.setLayout(borderLayout2);    titlePanel.setLayout(flowLayout1);    titleLabel.setForeground(Color.black);    titleLabel.setText("Dial Plan");    flowLayout1.setVgap(20);    tablePanel.setLayout(borderLayout1);    labelPanel.setLayout(flowLayout2);    buttonGridPanel.setLayout(gridLayout1);    gridLayout1.setColumns(3);    gridLayout1.setHgap(3);    gridLayout1.setVgap(5);    addButton.setText("Add");    deleteButton.setText("Delete");    editButton.setText("Edit");    buttonGridPanel.setBorder(BorderFactory.createCompoundBorder(new TitledBorder(BorderFactory.createLineBorder(Color.gray, 1), "Dial Plan Entries"),             BorderFactory.createEmptyBorder(5, 5, 5, 5)));    this.add(titlePanel, BorderLayout.NORTH);    titlePanel.add(titleLabel, null);    this.add(tablePanel, BorderLayout.CENTER);    tablePanel.add(tableScrollPane, BorderLayout.CENTER);    tableScrollPane.getViewport().add(dialPlanTable, null);    tablePanel.add(labelPanel, BorderLayout.SOUTH);    labelPanel.add(buttonGridPanel, null);    buttonGridPanel.add(addButton, null);    buttonGridPanel.add(editButton, null);    buttonGridPanel.add(deleteButton, null);  }  private void initTable()  {    titleLabel.setText(typeString + " " + titleLabel.getText());    dialPlanTable.setModel(tableModel);    dialPlanTable.addColumn(column0);    dialPlanTable.addColumn(column1);    dialPlanTable.addColumn(column2);    // dialPlanTable.setCellSelectionEnabled(true);    dialPlanTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);    ListSelectionModel rowSM = dialPlanTable.getSelectionModel();    rowSM.addListSelectionListener(new ListSelectionListener()    {      public void valueChanged(ListSelectionEvent e)      {        if (e.getValueIsAdjusting())        {          return;        }        repaint();        // dialPlanTable.repaint();      }    });  }  public void paint(Graphics g)  {    g.setPaintMode();    super.paint(g);  }  protected void getData()  {    if (dataManager != null)    {      dataManager.setDialPlanData(tableModel.getData());    }  }  /**   * Method called when Cancel button is pressed for this screen   */  protected void cancelCalled()  {    tableModel.revertData();    dialPlanTable.clearSelection();  }  /**   * Method called when Ok button is pressed for this screen   */  public void actionPerformed(ActionEvent e)  {    if (!checkValidated())    {	return;    }    getData();        if (dataManager != null)    {      try      {        dataManager.saveData();      }      catch (InvalidRequestException e1)      {        e1.printStackTrace();      }      tableModel.dataSaved();      dataManager = configTree.getDialPlanData();      mainScreen.enableTree();    }  }}

⌨️ 快捷键说明

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