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

📄 editor.java

📁 SIP(Session Initiation Protocol)是由IETF定义
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * ==================================================================== * 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/>. * */package vocal.userEditor;import vocal.comm.VPPTransactionWrapper;import vocal.comm.VPPNoSuchFileException;import java.io.IOException;import java.util.*;import javax.swing.*;import javax.swing.table.*;import javax.swing.event.TableModelEvent;import javax.swing.event.TableColumnModelEvent;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Color;import java.awt.Component;import java.awt.Container;import java.awt.Toolkit;import java.awt.Point;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.ActionListener;import java.awt.event.ActionEvent;import java.awt.event.InputEvent;import java.awt.event.WindowAdapter;import java.awt.event.WindowEvent;/** * This class displays the main table of all users. <p> * * It contains a popup menu which contains actions which allow the the table * to be manipulated. It is possible to delete a user, add a new user, edit * and existing user and view the data for a user. * * It should be possible to edit a single user account at a time or multiple * accounts. When multiple accounts are edited, the UserPanel which serves as * the editor is not loaded with data for any particular user. When the data is * read back from this dialog, only the data which has changed is saved for all * users while all other data remians unchanged. This allows for bulk * provisioning of users. * * In order to edit a user, a UserPanel is instantiated, the pServer is * queried for the user's data, then the UserPanel is instructed to load the * data into all its elements for display. The UserPanel is then dispalyed in * a modal dialog. When the dialog has been dismissed the data is collected from * the UserPanel and saved to the table model and the pServer. */public class Editor extends JPanel{  /**   * Displays the list of users and their configuration   */  private JTable table;  /**   * Contains the internal representation of the account data for all users   */  private UserTableModel data;  /**   * Menu which appears at right click to edit/delete users   */  private JPopupMenu popupMenu;  private JCheckBox showUserColumns;  private JCheckBox showAdminColumns;  private JCheckBox showAliases;  private JDialog userEditorDialog;  private UserPanel userPanel;  private JScrollPane scroller;  private JDialog findDialog;  VPPTransactionWrapper connection;  ColumnModelListener columnListener = new ColumnModelListener();  public Editor(VPPTransactionWrapper conn)  {    setLayout(new BorderLayout());    connection = conn;    table = new JTable();    table.setAutoCreateColumnsFromModel(false);    PServerInterface psInterface = new PServerInterface(conn);    data = new UserTableModel(psInterface);    table.setModel(data);    // configure column widths    ColumnInfo[] columns = data.getColumns();    for (int i = 0; i < columns.length; i++)    {      table.addColumn(columns[i]);    }    table.setDefaultRenderer(String.class, new UserRenderer());    // make the table scrollable and add it to the panel    scroller = new JScrollPane(table);    add(scroller, BorderLayout.CENTER);    createPopupMenu();    createButtons();    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);    // so it scrolls horizontally  }  /**   * Create a new userEditor. This should include re-reading from the pserver   * the provisioning information for the servers in the system (feature,   * marshal). This is here so that it is possible to re-crete the   * user editor dialog if there is any possibility that the server info   * has changed (groups added, etc).   */  public void init()  {    // this needs to be wiped out because it stores the parsed lists of    // feature and marshal servers    PServerInterface psInterface = new PServerInterface(connection);    Component parent = this.getTopLevelAncestor();    try    {      if (JDialog.class.isInstance(parent))      {        userEditorDialog = new JDialog((JDialog) this.getTopLevelAncestor(),                "Edit user", false);      }      else if (JFrame.class.isInstance(parent))      {        userEditorDialog = new JDialog((JFrame) this.getTopLevelAncestor(),                "Edit user", false);      }      userPanel = new UserPanel(psInterface);      // for those people with tiny monitors, as per request, make the user      // editor panel scrollable.      JScrollPane scroller = new JScrollPane(userPanel);      userEditorDialog.setContentPane(scroller);      userEditorDialog.setModal(true);      userEditorDialog.pack();      // This is done so that this      // component is cleared even if the user closed this panel by clicking the      // close icon in the title bar. (Tried an ancestorListener on the user      // panel, but that gets called even if the dialog was dismissed via ok or      // cancel.      userEditorDialog.addWindowListener(userPanel);    }    catch (IOException e)    {      JOptionPane.showMessageDialog(this,              "Could not create user panel because:\n" + e              + "\n\nYou may browse users but you will not be able to add or edit.");    }    catch (VPPNoSuchFileException ex)    {      JOptionPane.showMessageDialog(this,              "Could not create user panel because:\n" + ex              + "\n\nYou may browse users but you will not be able to add or edit.");    }    findDialog = new JDialog();    if (JDialog.class.isInstance(parent))    {      findDialog = new JDialog((JDialog) this.getTopLevelAncestor(),              "Find user", false);    }    else if (JFrame.class.isInstance(parent))    {      findDialog = new JDialog((JFrame) this.getTopLevelAncestor(),              "Find user", false);    }    findDialog.setContentPane(new UserSearchPanel(table, data));    findDialog.setModal(true);    findDialog.pack();    columnListener.actionPerformed(new ActionEvent(showAdminColumns, 0,            null));    columnListener.actionPerformed(new ActionEvent(showUserColumns, 0, null));    showAliases.setSelected(false);  }  private void createPopupMenu()  {    popupMenu = new JPopupMenu();    AbstractAction action = new AbstractAction("View")    {      public void actionPerformed(ActionEvent e)      {        TaskView task = new TaskView(Editor.this);        task.start();      }    };    popupMenu.add(action);    popupMenu.addSeparator();    action = new AbstractAction("Edit")    {      public void actionPerformed(ActionEvent e)      {        if (!showUserColumns.isSelected() &&!showAdminColumns.isSelected())        {          JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(),                  "Select \"Show user data\" and/or \"Show admin data\" to edit an account.");        }        else        {          TaskEdit task = new TaskEdit(Editor.this);          task.start();        }      }    };    popupMenu.add(action);    action = new AbstractAction("Delete")    {      public void actionPerformed(ActionEvent e)      {        TaskDelete task = new TaskDelete(Editor.this);        task.start();      }    };    popupMenu.add(action);    action = new AbstractAction("New")    {      public void actionPerformed(ActionEvent e)      {        if (userPanel == null)        {          return;        }        if (!showUserColumns.isSelected() &&!showAdminColumns.isSelected())        {          JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(),                  "Select \"Show user data\" and/or \"Show admin data\" to create a new account.");          return;        }        userPanel.setMode(UserPanel.ADD_NEW_MODE);        // Load the "default" values into the new user screen        Vector dummyUser = data.getDummyUser();        userPanel.setUserData(dummyUser);        showUserEditorDialog();        if (userPanel.getLastButtonClicked() == UserPanel.BUTTON_OK)        {          Vector newData = userPanel.getUserData();          String newUsername = (String) newData.elementAt(data.USER_NAME);          if (newUsername == null) //they didn't change the name so it must still be the default          {            newUsername = (String)dummyUser.elementAt(UserTableModel.USER_NAME);          }          // Check if another user with the same name exists already          if (data.userExists(newUsername))          {            JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(),                    "The user named " + newUsername                    + " already exists. New user not created.");            return;          }          // Now still need to find out if there is an alias with that name:          if (data.aliasExists(newUsername))          {            JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(),                    "An alias named " + newUsername                    + " already exists. New user not created.");            return;          }          data.addUser(dummyUser);          int userRow = data.getRowCount() - 1;          for (int i = 0; i <= UserTableModel.MAX_COLUMN_ID; i++)          {            String dataElement = (String) newData.elementAt(i);            if (dataElement != null)            {              try              {                data.setValueAt(dataElement, userRow, i);              }              catch (Exception ex)              {                ex.printStackTrace();                JOptionPane.showMessageDialog(Editor.this.getTopLevelAncestor(),

⌨️ 快捷键说明

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