Look And Feel Matters

Download Podcast

It’s been a long while since I planned to blog on working with third-party pluggable look feels for Swing Applications. As it turned out, today seems to be the day. Anyway one of the scintillating capabilities with the latest addition of Swing components has to be there ability to adapt to any custom look and feel as opposed to AWT where they can only take the native look and feel of the Operating System and few other PLAF’s (Pluggable Look And Feels) that come bundled with JDK makes look all the applications in the same old boring fashion (Which is not to my liking). Because they say “Look And Feel matters“. Here I’ll be using a theme PLAF called Synthetica which is currently at its v2.7.2. You can download a free evaluation copy upon registration on

http://www.javasoft.de/jsf/public/products/synthetica;jsessionid=46B0017CCD5DD3D

27B2E036DFC9587D6

Since Synthetica provides series of themes first I would suggest you to download the core of all which is the Synthetica Standard Look And Feel. Then you can proceed to download any other additional theme(s) as you wish. Here of course I have used the “Synthetica White Vision Look And Feel” so in that case you might also require to download this particular theme as well to have a feel of my Tiny App.

Pre-Requisites

  • SyntheticaStandard Look And Feel
  • SyntheticaWhite Vision Look And Feel
  • Java 1.5 or later (Since it’s a requirement of Synthetica 2.x.x)
  • Eclipse – IDE (Since I’m used to eclipse and probably the favourite of mine at that, I’ll be going ahead with it)

Getting to the business end. Open up your eclipse IDE and select File -> New -> Project -> Java Project. Then name it with whatever name you like and that’s it you have just created an empty project.

Now you can create a new class and name it App (in my case) and then you can right click on your project root to create a new package and name it lib and within that another package called synthetica (Here I’m just following the conventions. Best Practices..!) And just copy and paste your jar files (Synthetica) that you have downloaded.

Then right click on the root of your project in the workspace and select Build Path -> Configure Build Path -> go to the Libraries tab and -> Click on Add External Jar files and just point to both your jar files that now reside in the synthetica package inside the lib package.

That’s it your Environment is now perfectly setup..!

If you have the environment setup properly when you type de. In your App.java, a popup menu should appear showing all the available packages and classes within it (Just for a Verification..!). If you get it well you are all most there.

Below I give you the code which consists a Menu, MenuItem Button and a Table. So it’s just requires copy n paste job here onwards. Now you can Run the App to say your oohs and Ahhs..!

Screenshot of App

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

//Importing the all importatnt Look And Feel classes.
//import de.javasoft.plaf.synthetica.SyntheticaStandardLookAndFeel;
import de.javasoft.plaf.synthetica.SyntheticaWhiteVisionLookAndFeel;

public class App extends JFrame implements ActionListener{

public JMenuBar menuBar;
public JMenu menu;
public JMenu helpMenu;
public JMenuItem item1;
public JMenuItem aboutItem;

//Buttoon Instance
public JButton myButton1;

Object rowData[][] = { { “Dat 1”, “Dat 2”, “Dat 3”},
{ “Dat 4”, “Dat 5”, “Dat 6”} };
Object columnNames[] = { “Column 1”, “Column 2”, “Column 3”};

public App(){

/**
* Note: If you are to call super explicitely make sure
* That it is the first statement
*/
super(“Look And Feel Observation”);
this.setSize(400,300);

menuBar = new JMenuBar();
menu = new JMenu(“File”);
item1 = new JMenuItem(“Exit”);
menu.add(item1);

helpMenu = new JMenu(“Help”);
aboutItem = new JMenuItem(“About”);
helpMenu.add(aboutItem);

menuBar.add(menu);
menuBar.add(helpMenu);


//Sets the MenuBar
this.setJMenuBar(menuBar);

//No need for a Layout Manger
this.getContentPane().setLayout(null);

myButton1 = new JButton(“Click Here”);

//Both item1 and myButton1 implments ActionListener
item1.addActionListener(this);
myButton1.addActionListener(this);

//uses set bounds to place the components on the ContentPane
myButton1.setBounds(20, 20, 100, 100);
this.getContentPane().add(myButton1);
this.getContentPane().setBackground(Color.orange);

try {
UIManager.setLookAndFeel(new SyntheticaWhiteVisionLookAndFeel());
SwingUtilities.updateComponentTreeUI(this);

}
catch (Exception e) {
e.printStackTrace();
}

drawTable();
this.setDefaultCloseOperation(1);
setVisible(true);

}

/**
* Populating the table
* in a pretty static fashion
*/
public void drawTable(){
JTable table = new JTable(rowData, columnNames);
table.setBounds(140, 20, 200, 100);
getContentPane().add(table);
}

/**
* Implmenting the actionPerformed method
* in ActionListener Interface
*/
public void actionPerformed(ActionEvent evt){

if(evt.getActionCommand() == “Click Here”){
JOptionPane.showMessageDialog(this,”Help Protect Green.”, “About”, 1);
System.out.println(“You have just clicked on the button”);
}
if(evt.getActionCommand() == “Exit”){
System.exit(0);
}

if(evt.getActionCommand() == “About”){
System.out.println(“About”); }

}

public static void main(String [] argc){

//Creates an instance of App.
new App();

}

}

Two statement tht I would like note in this class will be the following..

UIManager.setLookAndFeel(new SyntheticaWhiteVisionLookAndFeel());

SwingUtilities.updateComponentTreeUI(this);

Test Automation using RFT

Still I’m in ma early  days of ma work at virtusa, I’m working on a IBM Project and to start with I have been asked to write test scripts to automate IBM Information Server using RFT (Rational Functional Tester). Which really is an intersting frame work. As usual I have been playing around with it for almost two or three days just to get the grip over it. And now I think I’m in the driving seat.

The frame work can be used to test any web page or any software’s GUI(Graphical User Interface). I really don’t know the possibility of checking CLI’s with it. So it’s upto you to check on and if inform me if there’s a possibility to do that as well.

At the heart of RFT is three main components namely appobjects, tasks and test cases. Where as tasks can be further sub devided into two important catagories UIChecker and UIOperations.

As a starting point I thought of using ony appobjects and do a simple automation that will open up your browser, go to google and perform a search operation on it to automatically fetch you the results.

If you are too interested buddy in this like me, first thing would be to download IBM RFT of which you should be able download a trial copy free of charge, cool..! and then launch your RFT which will look quite the same as an eclipse IDE if you have worked on it. Now all wot you need to do now is to start your new Project and write click on your root folder and select Add Empty Script. which will give you the file you gonna work with. below I will share my first code that does what I have mentioned above.

But before you do that you have to capture the search button object on the google website. Which you can do by double clicking on Private Test Object Map on the right side panel of your RFT workspace. And select Insert Object in the resulting window. You just need to drag the hand marked button and point the button on the google site at this point please note that same applies to the text input field as well. Then you right click on the object and select add to TestScript.YourProject. That’s it now back to businees end of life..

package appobjects;

import resources.appobjects.GoogleProjectHelper;

import com.rational.test.ft.*;
import com.rational.test.ft.object.interfaces.*;
import com.rational.test.ft.object.interfaces.SAP.*;
import com.rational.test.ft.object.interfaces.siebel.*;
import com.rational.test.ft.script.*;
import com.rational.test.ft.value.*;
import com.rational.test.ft.vp.*;

/**
 * Description   : Functional Test Script
 * @author HHameem
 */
public class GoogleProject extends GoogleProjectHelper
{
 /**
  * Script Name   : <b>GoogleProject</b>
  * Generated     : <b>Jul 11, 2008 6:03:08 PM</b>
  * Description   : Functional Test Script
  * Original Host : WinNT Version 5.1  Build 2600 (S)
  *
  * @since  2008/07/11
  * @author HHameem
  */
 public void testMain(Object[] args)
 {
  startBrowser(“http://www.google.com“);
  text_q().setText(“Lonely Coder”);
  button_googleSearchsubmit().click();
 }
}

Now you will be getting the same results page exactly as the one you get when you search “Lonely Coder” on google(Which is obviously my favourite search criteria on Google) manually. Hope you will find it interesting.