📄 featureaccr.java
字号:
/*
* ====================================================================
* The Vovida Software License, Version 1.0
*
*/
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 FeatureAccr 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 PServerAccrInterface psInterface;
private String featureName;
protected static final int COLUMN_WIDTH = 200;
protected FeatureAccr(String[] newGroups, String name, PServerAccrInterface 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));
addSelectedComponents();
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 FeatureAccr createFeature(String featureType, String[] groups,
PServerAccrInterface 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];
}
FeatureAccr feature = null;
if (featureType.equalsIgnoreCase("ForwardAllCalls"))
{
feature = new FeatureAccrForwardAllCalls(newGroups, featureType,
psInterface);
feature.setBorder(new TitledBorder("Forward All Calls"));
}
else if (featureType.equalsIgnoreCase("ForwardNoAnswerBusy"))
{
feature = new FeatureAccrForwardNoAnswerBusy(newGroups, featureType,
psInterface);
feature.setBorder(new TitledBorder("Forward Busy or Unanswered Calls"));
}
else if (featureType.equalsIgnoreCase("CallBlocking"))
{
feature = new FeatureAccrCallBlocking(newGroups, featureType, psInterface);
feature.setBorder(new TitledBorder("Block Long Distance or 900/976 Outgoing Calls"));
}
else if (featureType.equalsIgnoreCase("CallScreening"))
{
feature = new FeatureAccrCallScreening(newGroups, featureType, psInterface);
feature.setBorder(new TitledBorder("Screen Incoming Calls"));
}
else if (featureType.equalsIgnoreCase("CallReturn"))
{
feature = new FeatureAccrCallReturn(newGroups, featureType, psInterface);
feature.setBorder(new TitledBorder("Return Calls"));
}
else if (featureType.equalsIgnoreCase("CallerIdBlocking"))
{
feature = new FeatureAccrCallerIdBlocking(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)
{
FeatureAccr.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();
//System.out.println(featureGroup);
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 + -