📄 permisldapsetup.java
字号:
grid_cr.fill = GridBagConstraints.BOTH;
permisLayout.add(serverPanel, name = new JTextField(17),grid_bl, grid_cr, 1,0,1,1);
permisLayout.add(serverPanel, port = new JTextField(4),grid_bl, grid_cr, 5,1,1,1);
grid_cr.weightx = 1;
permisLayout.add(serverPanel, server = new JTextField(17),grid_bl, grid_cr, 1,1,1,1);
permisLayout.add(serverPanel, dns = new JTextField(17),grid_bl, grid_cr, 1,2,5,1);
dns.setEditable(true);
ver.setFont(port.getFont());
dns.setFont(port.getFont());
userPanel.setBorder(BorderFactory.createTitledBorder(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_user_info")));
userPanel.setLayout(grid_bl);
grid_cr.fill = GridBagConstraints.NONE;
grid_cr.weightx = 0;
grid_cr.anchor = GridBagConstraints.EAST;
usernameLabel= new JLabel(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_username"));
usernameLabel.setToolTipText(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_username_tt"));
permisLayout.add(userPanel,usernameLabel ,grid_bl, grid_cr, 1,1,1,1);
passLabel =new JLabel(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_pass"));
passLabel.setToolTipText(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_pass_tt"));
permisLayout.add(userPanel,passLabel,grid_bl, grid_cr, 1,2,1,1);
// permisLayout.add(userPanel, new JLabel("Anonymous: "),grid_bl, grid_cr, 1,3,1,1);
grid_cr.weightx =1;
grid_cr.fill = GridBagConstraints.HORIZONTAL;
grid_cr.anchor = GridBagConstraints.WEST;
permisLayout.add(userPanel, user = new JTextField(23),grid_bl, grid_cr, 2,1,1,1);
permisLayout.add(userPanel, password = new JPasswordField(15),grid_bl, grid_cr, 2,2,1,1);
permisLayout.add(userPanel, anyolog = new JCheckBox(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_bind"), true),grid_bl, grid_cr, 2,3,1,1);
anyolog.setToolTipText(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_bind_tt"));
password.setEnabled(false);
password.setBackground(new java.awt.Color(153,153,153));
user.setBackground(new java.awt.Color(153,153,153));
user.setEnabled(false);
//anyolog.setBackground(password.getBackground());
grid_cr.fill = GridBagConstraints.HORIZONTAL;
JPanel buttonPanel = new JPanel();
buttonPanel.add(connectButton = new JButton(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_connect")));
buttonPanel.add(saveButton = new JButton(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("save_label")));
buttonPanel.add(closeButton = new JButton(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("close_label")));
permisLayout.add(pp,serverPanel,grid_bl, grid_cr, 0,1,4,1);
permisLayout.add(pp,userPanel,grid_bl, grid_cr, 0,2,4,1);
//tab
addTabObject(1);
mp.setLayout(new BoxLayout(mp,BoxLayout.Y_AXIS));
mp.add(tab);
// mp.add(py);
mp.add(buttonPanel);
this.getContentPane().add(mp);
ver.setSelectedItem("3");
port.setText("389");
dns.setActionCommand("dn");
dns.addActionListener(this);
anyolog.setActionCommand(ANONYMOUS_ACTION);
anyolog.addActionListener(this);
connectButton.setActionCommand(CONNECT_ACTION);
connectButton.addActionListener(this);
saveButton.setActionCommand(SAVE_ACTION);
saveButton.addActionListener(this);
closeButton.setActionCommand(CANCEL_ACTION);
closeButton.addActionListener(this);
//load the ldap server configuration file
ldapProp = readConfig(FILENAME);
if (ldapProp==null){
ldapProp = new Properties();
ldapProp.put("Kent", getDefaultProperties());
}
//add server nicknames to the listbox
addEntries(ldapProp);
saveButton.setEnabled(false);
connectButton.setEnabled(false);
pack();
permisLayout.center(this);
}
public void addTabObject(int i){
tab.addTab(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory"), ps);
if (i == 2){
tab.addTab(ResourceBundle.getBundle("issrg/editor/gui/Editor_GUI_i18n").
getString("directory_detail"), pp);
}
}
public void actionPerformed(ActionEvent evt) {
String cmd = evt.getActionCommand();
if(cmd.equals(ANONYMOUS_ACTION)){
java.awt.Color bg;
if (anyolog.isSelected()) bg = new java.awt.Color(153,153,153);
else bg = server.getBackground();
password.setEnabled(!anyolog.isSelected());
user.setEnabled(!anyolog.isSelected());
user.setBackground(bg);
password.setBackground(bg);
}else if (cmd.equals(SAVE_ACTION)){
putProperties();
saveConfig(FILENAME, ldapProp);
tab.setSelectedIndex(0);
clearTextFields();
tab.remove(pp);
saveButton.setEnabled(false);
editing=false;
}else if (cmd.equals(CANCEL_ACTION)){
editing=false;
dispose();
}else if (cmd.equals(CONNECT_ACTION)){
String s = getConnectionParameter();
parent.getMenuItems().setLdapParm(s);
parent.getButtonMenu().initLDAP_dit();
parent.getButtonMenu().refreshComponents();
if(parent.getButtonMenu().getLdapCon().getConectionStatus()){
dispose();
}
}else if (cmd.equals(NEW_ACTION)){
newButtonActionPerformed();
}else if (cmd.equals(DELETE_ACTION)){
deleteButtonActionPerformed();
}else if (cmd.equals(EDIT_ACTION)){
editButtonActionPerformed();
}
}
private void putProperties()
{
if(!editing) return;
Properties prop = new Properties();
java.util.Hashtable hash = getDeletedHash();
if (getItem()!=null){
String s =(String) hash.get(getItem());
if(s!=null && !s.equals(server.getText().trim())){ // aha, this is removing the property with the old name
ldapProp.remove(s);
model.removeElement(s);
}
}
prop.put("host", server.getText().trim());
prop.put("basedn", dns.getText().trim());
prop.put("port", port.getText().trim());
if (!anyolog.isSelected()){
prop.put("user", user.getText().trim());
prop.put("password", password.getText().trim());
}else{
prop.put("user", " ");
prop.put("password", " ");
}
prop.put("version", ver.getSelectedItem().toString().trim());
//add this entry to ldap property table
ldapProp.put(name.getText().trim(), prop);
addEntries(ldapProp);
}
public static Properties getDefaultProperties(){
Properties pt = new Properties();
pt.put("name", "Kent");
pt.put("host", "sec.cs.kent.ac.uk");
pt.put("basedn", "c=gb");
pt.put("port", "389");
pt.put("user", "");
pt.put("password", "");
pt.put("version", "3");
return pt;
}
public Properties readConfig(String fname)
{
Properties p, result;
String sp =null ;
String st = null;
String temp = null;
String line =null;
p = new Properties();
result = new Properties();
try{
BufferedReader br = new BufferedReader(new FileReader(fname));
while((line = br.readLine()) != null){
st = line.trim();
if (st.equals(LDAP_ENTRY)){ // read the start of a new section
p=new Properties();
continue;
}
int i = st.indexOf("=");
if(i != -1){
sp = st.substring(0,i);
String sh = i+1<st.length()?st.substring(i+1):"";
if(sp.equals("name")){
result.put(sh, p);
}else{
p.put(sp,sh);
}
}
}
br.close();
}catch(Exception e){
result=null; // nothing has been read
}
return result;
}
public void saveConfig(String fname, Properties config)
{
String s = null;
try{
BufferedWriter fw = new BufferedWriter(new FileWriter(fname));
for (java.util.Enumeration e1 = config.propertyNames(); e1.hasMoreElements();){
s = (String)e1.nextElement();
Properties p = (Properties)config.get(s);
fw.write(LDAP_ENTRY);fw.newLine();
fw.write("name="+s); fw.newLine();
for( java.util.Enumeration e = p.propertyNames(); e.hasMoreElements();){
String key = (String)e.nextElement();
fw.write(key+"="+p.getProperty(key));fw.newLine();
}
}
fw.flush();
fw.close();
}catch(FileNotFoundException e){
//e.printStackTrace(); // shouldn't happen at all
}catch(IOException e){
//e.printStackTrace();
error("Could not save configuration: "+e.getMessage(), e); // I18N internationalise!..
}
}
private void error(String msg, Throwable th){
if (th!=null) th.printStackTrace(System.err);
if (msg==null && th!=null) msg=th.getMessage();
JOptionPane.showMessageDialog(this, msg, "", JOptionPane.ERROR_MESSAGE);
}
public void setEntry(Properties p)
{
name.setText(getItem());
server.setText( p.getProperty("host"));
password.setText(p.getProperty("password"));
port.setText( p.getProperty("port"));
dns.setText(p.getProperty("basedn"));
user.setText( p.getProperty("user"));
}
public void setEntry(String s)
{
setEntry((Properties)ldapProp.get(s));
}
public void clearTextFields()
{
server.setText("");
name.setText("");
dns.setText("");
user.setText("");
password.setText("");
password.setText(password.getText().trim());
}
public void addEntries(Properties p)
{
model.removeAllElements();
for( java.util.Enumeration e = p.propertyNames(); e.hasMoreElements();){
model.addElement(e.nextElement());
}
}
public String getConnectionParameter(){
String s = (String)directoryList.getSelectedValue();
if(s == null){
Enumeration en = ldapProp.propertyNames();
if (en.hasMoreElements()) {
s = en.nextElement().toString();
}
}
// s may still be null, if the list in ldapProp is simply empty
s=s==null?null:getSetupParam((Properties)ldapProp.get(s));
return s;
}
public String getSetupParam(Properties p)
{
String param = null;
String host = p.getProperty("host");
String basedn = p.getProperty("basedn");
String port = p.getProperty("port");
String user = p.getProperty("user");
String password = p.getProperty("password");
if (!host.startsWith("ldap://")){
host = "ldap://"+host;
}
param = host+"/"+basedn;
return param.trim();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -