The ModemCapabilities.java file sets the encoding and decoding capabilities of a modem.
Listing 6-7 shows the ModemCapabilities.java file:
Listing 6-7: The ModemCapabilities.java File
/*Imports required java.util.Vector class*/ import java.util.Vector; /* class ModemCapabilities - This class is the main class of the application. This class initializes the interface and loads all components like the menubar, textareas, and buttons before displaying the result. Constructor: ModemCapabilities - This constructor initializes various modem parameters Methods: encodeCapabilities - This method is called to ecode modem capabilities decodeCapabilitiesClass2 - Find modem capabilities of class2 type. decodeCapabilities - Find modem capabilities of class1 type. */ public class ModemCapabilities { public String vRate; public String recRate; public boolean t4; public int resolution; public int rate; public int length; public int width; public int huffman; public int scanTime; public int errorCorrection; public boolean binaryTransfer; private static int itemlength = 0; private static int itemsize = 1; private static int seconditemsize = 2; private static int thirditemsize = 3; private static int forthitemsize = 4; private static int fifthitemsize = 5; private static int sixthitemsize = 6; private static int seventhitemsize = 7; public ModemCapabilities() { t4 = true; resolution = 0; rate = 96; vRate = "V29"; recRate = ""; length = 0; width = 1728; huffman = 1; scanTime = 0; errorCorrection = 0; binaryTransfer = false; } /* encodeCapabilities - This method is called to ecode modem capabilities Parameters: NA Return Value: byte[] */ public byte[] encodeCapabilities() { byte bi[] = new byte[3]; bi[0] = 0; bi[1] = 0; bi[2] = 0; bi[1] = 64; byte tmp = 0; if(rate == 145 && vRate.compareTo("V17") == 0) tmp = 4; if(rate == 145 && vRate.compareTo("V33") == 0) tmp = 8; if(rate == 121 && vRate.compareTo("V17") == 0) tmp = 20; if(rate == 121 && vRate.compareTo("V33") == 0) tmp = 24; if(rate == 96 && vRate.compareTo("V17") == 0) tmp = 36; if(rate == 72 && vRate.compareTo("V17") == 0) tmp = 52; if(rate == 72 && vRate.compareTo("V33") == 0) tmp = 48; if(rate == 72 && vRate.compareTo("V29") == 0) tmp = 48; if(rate == 96 && vRate.compareTo("V29") == 0) tmp = 32; if(rate == 48) tmp = 16; if(rate == 24) tmp = 0; tmp &= 0xff; bi[1] = (byte)(bi[1] | tmp); if(resolution == 1) bi[1] = (byte)(bi[1] | 2); if(huffman == 2) bi[1] = (byte)(bi[1] | 1); tmp = 0; if(width == 1728) tmp = 0; if(width == 2432) tmp = 64; if(width == 2048) tmp = -128; tmp &= 0xff; bi[2] = (byte)(bi[2] | tmp); tmp = 0; if(length == 2) tmp = 16; if(length == 1) tmp = 32; tmp &= 0xff; bi[2] = (byte)(bi[2] | tmp); tmp = 0; if(scanTime == 20) tmp = 0; if(scanTime == 40) tmp = 2; if(scanTime == 10) tmp = 4; if(scanTime == 5) tmp = 8; if(scanTime == 0) tmp = 14; tmp &= 0xff; bi[2] = (byte)(bi[2] | tmp); return bi; } /* decodeCapabilitiesClass2 - This method is called to decode capabilities of class2 type mode Parameters: ae - an ActionEvent object containing details of the event. Return Value:boolean */ public boolean decodeCapabilitiesClass2(String str) { Vector items = new Vector(); String item = ""; for(int p = str.indexOf(","); p >= 0; p = str.indexOf(",")) { item = ""; if(p > 0) item = str.substring(0, p); str = str.substring(p + 1, str.length()); items.addElement(item); } if(items.size() > itemlength) { item = (String)items.elementAt(itemlength); if(item.trim().equals("0")) resolution = 0; if(item.trim().equals("1")) resolution = 1; } if(items.size() > itemsize) { item = (String)items.elementAt(itemsize); if(item.trim().equals("0")) { rate = 24; vRate = "V27"; } if(item.trim().equals("1")) { rate = 48; vRate = "V27"; } if(item.trim().equals("2")) { rate = 72; vRate = "V29"; } if(item.trim().equals("3")) { rate = 96; vRate = "V29"; } if(item.trim().equals("4")) { rate = 121; vRate = "V17"; } if(item.trim().equals("5")) { rate = 145; vRate = "V17"; } } if(items.size() > seconditemsize) { item = (String)items.elementAt(seconditemsize); width = 1728; if(item.trim().equals("0")) width = 1728; if(item.trim().equals("1")) width = 2048; if(item.trim().equals("2")) width = 2432; } if(items.size() > thirditemsize) { item = (String)items.elementAt(thirditemsize); if(item.trim().equals("0")) length = 0; if(item.trim().equals("1")) length = 1; if(item.trim().equals("2")) length = 2; } if(items.size() > forthitemsize) { item = (String)items.elementAt(forthitemsize); huffman = 2; if(item.trim().equals("0")) huffman = 1; } if(items.size() > fifthitemsize) { item = (String)items.elementAt(fifthitemsize); errorCorrection = 0; if(item.trim().equals("1")) errorCorrection = 1; if(item.trim().equals("2")) errorCorrection = 2; } if(items.size() > sixthitemsize) { item = (String)items.elementAt(sixthitemsize); binaryTransfer = false; if(item.trim().equals("1")) binaryTransfer = true; } if(items.size() > seventhitemsize) { item = (String)items.elementAt(seventhitemsize); if(resolution == 0) { if(item.trim().equals("0")) scanTime = 0; if(item.trim().equals("1")) scanTime = 5; if(item.trim().equals("2")) scanTime = 10; if(item.trim().equals("3")) scanTime = 20; if(item.trim().equals("4")) scanTime = 20; if(item.trim().equals("5")) scanTime = 20; if(item.trim().equals("6")) scanTime = 40; if(item.trim().equals("7")) scanTime = 40; } else { if(item.trim().equals("0")) scanTime = 0; if(item.trim().equals("1")) scanTime = 5; if(item.trim().equals("2")) scanTime = 10; if(item.trim().equals("3")) scanTime = 10; if(item.trim().equals("4")) scanTime = 10; if(item.trim().equals("5")) scanTime = 20; if(item.trim().equals("6")) scanTime = 20; if(item.trim().equals("7")) scanTime = 40; } } return true; } /* decodeCapabilities - This method is called to decode capabilities of class1 type mode Parameters: ae - an ActionEvent object containing details of the event. Return Value:boolean */ public boolean decodeCapabilities(byte bi[]) { int b = bi[1]; b &= 0x40; if(b == 64) t4 = true; else t4 = false; b = bi[1]; b &= 0x3c; rate = 96; vRate = "V29"; if(b == 56) { rate = 96; vRate = "V33"; } if(b == 52) { rate = 145; vRate = "V17"; } if(b == 48) { rate = 72; vRate = "V29"; } if(b == 32) { rate = 96; vRate = "V29"; } if(b == 16) { rate = 48; vRate = "V17"; } if(b == 0) { rate = 24; vRate = "V27FB"; } b = bi[1]; b &= 2; if(b == 2) resolution = 1; b = bi[1]; b &= 1; if(b == 1) huffman = 2; b = bi[2]; b &= 0xc0; if(b == 0) width = 1728; if(b == 64) width = 2432; if(b == 128) width = 2048; if(b == 192) width = 2432; b = bi[2]; b &= 0x30; if(b == 0) length = 0; if(b == 16) length = 2; if(b == 32) length = 1; b = bi[2]; b &= 0xe; if(b == 0) scanTime = 20; if(b == 2) scanTime = 40; if(b == 4) scanTime = 10; if(b == 6) scanTime = 10; if(b == 8) scanTime = 5; if(b == 14) scanTime = 0; if(b == 10) scanTime = 40; if(b == 12) scanTime = 20; return true; } }
Download this listing.
In the above listing, the ModemCapabilities class sets the encoding and decoding capabilities of a modem, such as time to scan the document and transfer rate to send the fax. The various methods defined in the Capabilities class are:
encodeCapabilities():Sets the encoding capabilities of a modem.
decodeCapabilitiesClass2():Sets the decoding capabilities of a class 2 modem.
decodeCapabilities():Sets the decoding capabilities of a modem.