Improve Foudations Improve Technologies Improve Community Improve Institute

Custom Widget TelnetSWT

Description

This wigdet is based on JTA (Version 2.6), a Swing stand alone application which is a Telnet Client. I have used a SWT_AWT bridge to create my own Custom SWT widget named TelnetSWT. TelnetSWT extends Composite(), all Composite’s methods are available.

Download TelnetConsole

:moni:demos:swt-telnet_console.png

How to use it

Build Path

The custom widget TelnetSWT is available in TelnetConsole_V1.0.0.jar. You just have to include it into the Build path of your SWT application. (Eclipse:Configure build path–>add externals jar)

Configuration file

Host url and menus can be set in configConsoleTelnet.xml. TelnetConsole_V1.0.0.jar includes a sample file, you just have to put such a file in your SWT project folder.

Config file :

<config>
	<url>127.0.0.1</url> 
	<menu>
		<showFile>true</showFile>
		<showEdit>true</showEdit>
		<showTerminal>true</showTerminal>
		<showHelp>true</showHelp>
	</menu>	
</config>
  • If you don’t set the IP adress, the Console will start with offline mode, to connect use the menu : File > Connect.
  • You can hide or show all the items in the menu with a boolean indicator
Your code

To display the Telnet Console into your SWT application, you have to set a Layout in your shell and create a console as following

TelnetSWT myConsole = new TelnetSWT (shell,SWT.NULL | SWT.EMBEDDED);

Here you find a snippet showing how to include a Telnet Console in your SWT application :

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
 
import fr.improve.telnet.TelnetSWT;
 
public class TutoTestWidget {
 
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		 Display display = new Display();
		 Shell shell = new Shell(display);
		 shell.setText("Telnet SWT ");
		
		 shell.setLayout(new FillLayout());
		 try {
			TelnetSWT maConsole = new TelnetSWT (shell,SWT.NULL | SWT.EMBEDDED);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		shell.open();
		
		while(!shell.isDisposed()) {
			if (!display.readAndDispatch()) display.sleep();
		}
		display.dispose();
	}
 
}

Cedric KERMORGANT 2006/10/08 14:11

 
moni/projets/swtwidget/telnetswt.txt · Last modified: 2006/11/09 13:55 by ckermorgant