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

📄 feature.java

📁 SIP 1.5.0源代码
💻 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/>. *  */package vocal.userEditor;import vocal.comm.VPPException;import javax.swing.*;import javax.swing.border.*;import javax.swing.event.ChangeListener;import javax.swing.event.ChangeEvent;import javax.swing.table.DefaultTableModel;import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.Component;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.InputEvent;import java.util.StringTokenizer;import java.io.IOException;import org.xml.sax.SAXException;public abstract class Feature extends JPanel implements DataEditor{  protected JComboBox featureGroups;  protected JCheckBox adminEnabled;  protected boolean adminEnabledChanged = false;  protected JPanel adminLayout = new JPanel();  protected JPanel userLayout = new JPanel();  private boolean showAdmin = false;  private boolean showUser = true;  private PServerInterface psInterface;  private String featureName;  protected static final int COLUMN_WIDTH = 200;  protected Feature(String[] newGroups, String name, PServerInterface psInt)  {    setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));    featureName = name;    featureGroups = new JComboBox(newGroups);    featureGroups.setToolTipText("group of Feature servers that run this feature");    adminEnabled = new JCheckBox("Enabled");    adminEnabled.setToolTipText("select to allow the user access to this feature");    adminEnabled.setSelected(false);    adminEnabled.setPreferredSize(new Dimension(COLUMN_WIDTH,             adminEnabled.getHeight()));         // bit of a hack to get the spacing right    addAdminEnabledChangeListener();    // The admin-controlled gui elements go in the first panel    adminLayout.setLayout(new BoxLayout(this.adminLayout, BoxLayout.Y_AXIS));    JPanel temp = new JPanel();    temp.setLayout(new BoxLayout(temp, BoxLayout.X_AXIS));    temp.add(adminEnabled);    temp.add(featureGroups);    adminLayout.add(temp, 0);   // add this at the top    // The user-controlled gui elements go in the second panel    userLayout.setLayout(new BoxLayout(userLayout, BoxLayout.Y_AXIS));    psInterface = psInt;    // Whenever the feature group is changed, check to make shure there is at    // least one feature server defined for the currently selected group.    featureGroups.addActionListener(new ActionListener()    {      public void actionPerformed(ActionEvent e)      {        checkFeatureServer();      }    });  }  /**   * Factory method creates a concrete class to represent the appropriate type   * of feature as requested by the featureType parameter   */  public static Feature createFeature(String featureType, String[] groups,           PServerInterface psInterface)  {    // Add the "blank" group to the begining of the given groups. The purpose    // of this is that when it is selected in the group combo box, the group    // is considered to be "not edited". This functionality is of intrest when    // editing multiple users at a time.    String[] newGroups = new String[groups.length + 1];    newGroups[0] = "";    for (int i = 1; i < newGroups.length; i++)    {      newGroups[i] = groups[i - 1];    }    Feature feature = null;    if (featureType.equalsIgnoreCase("ForwardAllCalls"))    {      feature = new FeatureForwardAllCalls(newGroups, featureType,               psInterface);      feature.setBorder(new TitledBorder("Forward All Calls"));    }    else if (featureType.equalsIgnoreCase("ForwardNoAnswerBusy"))    {      feature = new FeatureForwardNoAnswerBusy(newGroups, featureType,               psInterface);      feature.setBorder(new TitledBorder("Forward Busy or Unanswered Calls"));    }    else if (featureType.equalsIgnoreCase("CallBlocking"))    {      feature = new FeatureCallBlocking(newGroups, featureType, psInterface);      feature.setBorder(new TitledBorder("Block Long Distance or 900/976 Outgoing Calls"));    }    else if (featureType.equalsIgnoreCase("CallScreening"))    {      feature = new FeatureCallScreening(newGroups, featureType, psInterface);      feature.setBorder(new TitledBorder("Screen Incoming Calls"));    }    else if (featureType.equalsIgnoreCase("CallReturn"))    {      feature = new FeatureCallReturn(newGroups, featureType, psInterface);      feature.setBorder(new TitledBorder("Return Calls"));    }    else if (featureType.equalsIgnoreCase("CallerIdBlocking"))    {      feature = new FeatureCallerIdBlocking(newGroups, featureType,               psInterface);      feature.setBorder(new TitledBorder("Block Phone Number Display"));    }    return feature;  }  private void addAdminEnabledChangeListener()  {    adminEnabled.addChangeListener(new ChangeListener()    {      public void stateChanged(ChangeEvent e)      {        Feature.this.adminEnabledChanged = true;      }    });  }  private void addSelectedComponents()  {    remove(adminLayout);    remove(userLayout);    if (showAdmin)    {      add(adminLayout);    }    if (showUser)    {      add(userLayout);    }  }  public void setShowAdmin(boolean show)  {    showAdmin = show;    addSelectedComponents();  }  public void setShowUser(boolean show)  {    showUser = show;    addSelectedComponents();  }  public void clear()  {    clearFeatureSpecificFields();    featureGroups.setSelectedIndex(0);    adminEnabled.setSelected(false);    adminEnabledChanged = false;  }  /**   * Find out whether there is a feature server defined for this feature and   * the currently selected group.   */  private boolean hasServer()  {    String featureGroup = (String) featureGroups.getSelectedItem();    try    {      return psInterface.hasServer(featureName, featureGroup);    }    catch (SAXException e)    {      JOptionPane.showMessageDialog(this.getTopLevelAncestor(),               "Could not determine whether there is a server defined \nfor the "               + featureName + " feature and " + featureGroup               + " group because:\n\n" + e);    }    catch (IOException e)    {      JOptionPane.showMessageDialog(this.getTopLevelAncestor(),               "Could not determine whether there is a server defined \nfor the "               + featureName + " feature and " + featureGroup               + " group because:\n\n" + e);    }    catch (VPPException e)    {      JOptionPane.showMessageDialog(this.getTopLevelAncestor(),               "Could not determine whether there is a server defined \nfor the "               + featureName + " feature and " + featureGroup               + " group because:\n\n" + e);    }    return false;  }  /**   * Enable or disable the gui elements in this feature if there is no feature   * server configured for the currently selected feature group.   */  public void checkFeatureServer()  {    if (!hasServer())                   // if no feature server exists    {      adminEnabled.setSelected(false);  // the feature is disabled      adminEnabled.setEnabled(false);   // so don't mess with it      disableFeature();                 // or anything else in this feature    }    else                                // there is at least one feature server for this feature/group    {      adminEnabled.setEnabled(true);      enableFeature();    }  }  /**   * Sub-classes which implement concrete features need to override this method   * to clear their own editor fields and reset any associated flags.   */  public abstract void clearFeatureSpecificFields();  /**   * Remember to add change listeners to all the check boxes and combo boxes in   * the concrete class in order to determine when they have been edited by the   * user.   */  protected abstract void addChangeListener();  /**   * This would be called if the feature did not have any server associated   * with the currently selected group. The intention is to disable all the   * gui components for this feature so that they may not be changed and also   * to set the "setfeat" (or equivalent) fields to "OFF" so that the feature   * is not run. The "admin enabled" checkbox is disabled in this class and the   * feature-specific fields should be disabled in the implementation of this   * method in the concrete classes.   */  protected abstract void disableFeature();  /**   * Enable the feature. This is the counterpart to the disableFeature method.   * It would be called if the currently selected group had at least one feature   * server associated with it. In that case, all the gui components should be   * enabled (editable). The "admin enabled" checkbox is enabled in this class   * and the feature-specific fields should be ensabled in the implementation of   * this method in the concrete classes.   */  protected abstract void enableFeature();}

⌨️ 快捷键说明

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