Wednesday, April 28, 2010

Suppress specific characters in a GWT Textbox

Some times we need to suppress specific characters in our GWT text box. Suppose you want only numbers to be allowed in your text box then you need to suppress all the alphabets in that text box. This you can do by attaching a key board listener to the text box and the method onKeyPress should do the required processing for suppressing. Below is the code for a text box which allows only numbers.

TextBox t = new TextBox();
t.addKeyPressHandler(new KeyPressHandler(){
public void onKeyPress(KeyPressEvent event) {
char keyCode = event.getCharCode();
if(!(keyCode > '0' && keyCode <'9') ) {
t.cancelKey();
}
}
});


Similarly, you can limit the number of characters a text box can take


TextBox t = new TextBox();
t.addKeyPressHandler(new KeyPressHandler(){
public void onKeyPress(KeyPressEvent event) {
if(t.getText().length() >= 5 ) {
t.cancelKey();
}
}
});


PS: For the syntax highlight of your code in a post, follow this link http://pleasemakeanote.blogspot.com/2008/06/posting-source-code-in-blogger.html

Friday, February 19, 2010

iptux - an intranet communication tool for linux


People Using a windows machine and connected to a LAN might be familiar with an intranet communication manager called IP Messenger. This is useful for messaging and transferring files from one machine to other machine over LAN. Once installed in your machine, it will automatically detect and show you a list of all the other machines which have this messenger running. You can choose any one on the list and start messaging or file transfer. You can google for IP Messenger and download it for Windows machines.





For Linux users also we have similar application called Gnome IP messenger. I have a previous post here which tells you how to install it. But it has some problem with transfering folders. This is a serious concern. To overcome this problem we have one more similar application called iptux . This is really very cool application. You have lot of features with this application and it has very rich UI. Ubuntu Users can directly get it through Synaptic manger. Just searc for iptux in your Synaptic manager. Alternatively you can download it from Ubuntu Repository and install it. There is different pakage file for different version of ubuntu. Please keep this in mind while downloading. For other flavours of linux users, you can download the tar file from google code page and follow these standard instructions for installing
  1. Untar the file and in terminal go to that folder
  2. run ./configure and if it fails, it means that something is missing in your OS for compiling the source. You can google with the error it gives and find the solution. Once you are successfull with this step move to next step.
  3. run make
  4. run make install -- after this you are ready to use your newly installed iptux
  5. run make clean -- this step is optional.
  6. To start iptux, open and termial and type iptux and enjoy intranet messaging and file transfers.