package main;
import javax.swing.text.PlainDocument;
import javax.swing.text.*;
import javax.swing.*;
public class PMMCCapitalcode extends PlainDocument
{
private int iMaxStrLen=0;
private int[] inlimChars;
private boolean onlylimitChar = false;
private boolean canlowkey = false;
public static final char[] NUMBERCHARS=new char[]{
'1','2','3',
'4','5','6',
'7','8','9',
'0','.','-'};
public static final char[] TIMECHARS=new char[]{
'1','2','3',
'4','5','6',
'7','8','9',
'0',':'};
public int col = -1;
public int row = -1;
public PMMCCapitalcode()
{
}
public void setcanlowkey(boolean canlowkey){
this.canlowkey = canlowkey;
}
public PMMCCapitalcode(int iMaxStrLen)
{
this.iMaxStrLen=iMaxStrLen;
}
public PMMCCapitalcode(int iMaxStrLen, char[] limChars,int row,int col)
{
this.iMaxStrLen=iMaxStrLen;
this.inlimChars = new int[limChars.length];
this.row = row;
this.col = col;
for (int i = 0 ; i < inlimChars.length ; i++){
inlimChars[i] = (int)limChars[i];
}
}
public PMMCCapitalcode(int iMaxStrLen, char[] limChars,int settrue)
{ this.onlylimitChar = true;
this.iMaxStrLen=iMaxStrLen;
this.inlimChars = new int[limChars.length];
for (int i = 0 ; i < inlimChars.length ; i++){
inlimChars[i] = (int)limChars[i];
}
}
public void insertString(int offs,String str,AttributeSet a)
throws BadLocationException
{
// System.out.println("Now Insert String This");
if(getLength()>iMaxStrLen-1)
{
return;
}
if (!canlowkey)
str=str.toUpperCase();
for (int i=0; i<str.length(); i++){
if (this.onlylimitChar){
if (!PBSUIBaseSetupFrame.isIntInInteger((int)str.charAt(i),this.inlimChars))
return;
}
if (this.inlimChars == null){
if (!((int)str.charAt(i)>64 && (int)str.charAt(i)<91) &&
!((int)str.charAt(i)>47 && (int)str.charAt(i)<58)){
if (!(this.canlowkey && ((int)str.charAt(i)>96 && (int)str.charAt(i)<121)))
return;
}
}
else {
if (!((int)str.charAt(i)>64 && (int)str.charAt(i)<91) &&
!((int)str.charAt(i)>47 && (int)str.charAt(i)<58) && !PBSUIBaseSetupFrame.isIntInInteger((int)str.charAt(i),this.inlimChars)){
if (!(this.canlowkey && ((int)str.charAt(i)>96 && (int)str.charAt(i)<123)))
return;
}
}
}
// System.out.print("Now Set the Value at row "+ row + " col :" + col);
// System.out.println(" Value is :" +str);
super.insertString(offs,str,a);
}
public static void main(String[] args){
JFrame test = new JFrame("test");
test.setSize(400,300);
JTextField ff = new JTextField();
ff.setPreferredSize(new java.awt.Dimension(100,22));
char[] kkk = {'_','[',']'};
ff.setDocument(new PMMCCapitalcode(10,kkk,-1,-1));
test.getContentPane().setLayout(new java.awt.GridBagLayout());
test.getContentPane().add(ff);
test.show();
}
}