Update of /cvsroot/tn5250j/tn5250j/src/org/tn5250j
In directory sc8-pr-cvs1:/tmp/cvs-serv19951/src/org/tn5250j
Modified Files:
Connect.java
Added Files:
OptionAccess.java
Log Message:
Update related to enable/disable features in tn5250j
--- NEW FILE: OptionAccess.java ---
/**
* Title: OptionAccess.java
* Copyright: Copyright (c) 2001, 2002, 2003
* Company:
* @author Kenneth J. Pouncey
* @version 0.1
*
* Description:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
* Boston, MA 02111-1307 USA
*
*/
package org.tn5250j;
import java.util.Collections;
import java.util.StringTokenizer;
import java.util.Vector;
import org.tn5250j.interfaces.ConfigureFactory;
import org.tn5250j.interfaces.OptionAccessFactory;
import org.tn5250j.tools.LangTool;
/**
* Utility class for referencing the global options allowed for access
* of which at most one instance can exist per VM.
*
* Use OptionAccessFactory.instance() to access this instance.
*/
public class OptionAccess extends OptionAccessFactory implements TN5250jConstants {
/**
* A handle to the unique OptionAccess class
*/
static private OptionAccess _instance;
/**
* A handle to non valid options.
*/
static private Vector restricted = new Vector();
/**
* The constructor is made protected to allow overriding.
*/
public OptionAccess() {
if (_instance == null) {
// initialize the settings information
initialize();
// set our instance to this one.
_instance = this;
}
}
/**
*
* @return The unique instance of this class.
*/
static public OptionAccess instance() {
if (_instance == null) {
_instance = new OptionAccess();
}
return _instance;
}
/**
* Initialize the properties registry for use later.
*
*/
private void initialize() {
loadOptions();
}
/**
* Load a list of available options
*/
private void loadOptions() {
restricted.clear();
String restrictedProp =
ConfigureFactory.getInstance().getProperties(
GlobalConfigure.SESSIONS).getProperty("emul.restricted");
if (restrictedProp != null) {
int x = 0;
StringTokenizer tokenizer = new StringTokenizer(restrictedProp, ";");
while (tokenizer.hasMoreTokens()) {
restricted.add(tokenizer.nextToken());
}
}
}
public Vector getOptions() {
Vector v = new Vector(mnemonicData.length);
for (int x = 0; x < mnemonicData.length; x++) {
v.add(mnemonicData[x]);
}
Collections.sort(v);
return v;
}
public Vector getOptionDescriptions() {
Vector v = new Vector(mnemonicData.length);
for (int x = 0; x < mnemonicData.length; x++) {
v.add(LangTool.getString("key."+mnemonicData[x]));
}
Collections.sort(v);
return v;
}
public boolean isValidOption(String option) {
return !restricted.contains(option);
}
public boolean isRestrictedOption(String option) {
return restricted.contains(option);
}
public int getNumberOfRestrictedOptions() {
return restricted.size();
}
public void reload() {
loadOptions();
}
}
Index: Connect.java
===================================================================
RCS file: /cvsroot/tn5250j/tn5250j/src/org/tn5250j/Connect.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** Connect.java 2 Dec 2003 13:14:47 -0000 1.14
--- Connect.java 3 Dec 2003 09:21:28 -0000 1.15
***************
*** 78,81 ****
--- 78,83 ----
import javax.swing.event.ListSelectionListener;
import javax.swing.table.AbstractTableModel;
+ import javax.swing.JPasswordField;
+ import javax.swing.text.*;
import org.tn5250j.gui.JSortTable;
***************
*** 85,88 ****
--- 87,91 ----
import org.tn5250j.gui.TN5250jMultiSelectList;
import org.tn5250j.interfaces.OptionAccessFactory;
+ import org.tn5250j.tools.DESSHA1;
public class Connect
***************
*** 133,136 ****
--- 136,142 ----
TN5250jMultiSelectList accessOptions;
+ // password protection field for access to options list
+ JPasswordField password;
+ JButton setPassButton;
// Selection value for connection
***************
*** 451,454 ****
--- 457,463 ----
accessOptions = new TN5250jMultiSelectList();
+ if (props.getProperty("emul.accessDigest") != null)
+ accessOptions.setEnabled(false);
+
Vector options = OptionAccessFactory.getInstance().getOptions();
***************
*** 476,481 ****
accessOptions.setSelectedIndices(si);
- // accessOptions.setSourceColumnHeader("Active");
- // accessOptions.setSelectionColumnHeader("In Active");
accessOptions.setSourceHeader(LangTool.getString("ss.labelActive"));
--- 485,488 ----
***************
*** 487,490 ****
--- 494,550 ----
accessPanel.add(accessOptions,BorderLayout.CENTER);
+ JPanel passPanel = new JPanel();
+
+ Action action = new AbstractAction(LangTool.getString("ss.labelSetPass")) {
+ public void actionPerformed(ActionEvent e) {
+ if (password.getPassword().length > 0) {
+ try {
+ DESSHA1 sha = new DESSHA1();
+ props.setProperty("emul.accessDigest",
+ sha.digest(new String(password.getPassword()),"tn5205j"));
+ }
+ catch (Exception ex) {}
+ }
+ }
+ };
+
+ setPassButton = new JButton(action);
+
+ if (props.getProperty("emul.accessDigest") != null)
+ setPassButton.setEnabled(false);
+
+ passPanel.add(setPassButton);
+
+ password = new JPasswordField(20);
+ password.setDocument(new CheckPasswordDocument());
+
+ passPanel.add(password);
+
+ accessPanel.add(passPanel,BorderLayout.NORTH);
+
+ }
+
+ private void doSomethingEntered() {
+
+ if (props.getProperty("emul.accessDigest") != null) {
+ try {
+ DESSHA1 sha = new DESSHA1();
+ // System.out.println(props.getProperty("emul.accessDigest")
+ // + " -> " + sha.digest(new String(password.getPassword()),"tn5205j"));
+ if (props.getProperty("emul.accessDigest").equals(
+ sha.digest(new String(password.getPassword()),"tn5205j"))) {
+ accessOptions.setEnabled(true);
+ setPassButton.setEnabled(true);
+ }
+ }
+ catch (Exception ex) {
+ System.out.println(ex.getMessage());
+ }
+ }
+ }
+
+ private void doNothingEntered() {
+
+
}
***************
*** 523,527 ****
button.setEnabled(enabled);
button.setActionCommand(ac);
! button.setPreferredSize(new Dimension(140, 28));
// we check if there was mnemonic specified and if there was then we
--- 583,587 ----
button.setEnabled(enabled);
button.setActionCommand(ac);
! button.setPreferredSize(new Dimension(140, 28));
// we check if there was mnemonic specified and if there was then we
***************
*** 687,690 ****
--- 747,767 ----
}
+
+ public class CheckPasswordDocument extends PlainDocument {
+
+ public void insertString(int offs, String str, AttributeSet a)
+ throws BadLocationException {
+
+ super.insertString(offs, str, a);
+ if (getText(0, getLength()).length() > 0)
+ doSomethingEntered();
+ }
+
+ public void remove(int offs, int len) throws BadLocationException {
+ super.remove(offs, len);
+ if (getText(0, getLength()).length() == 0)
+ doNothingEntered();
+ }
+ }
class ConfigureTableModel
-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.