Monday, November 29, 2010

JSplitButton

A simple implementation of the split button control in Java. This control raises two events
  1. buttonClicked(e) 
  2. splitButtonClicked(e)
 The buttonClicked event is raised when the button is clicked, the left part, which will not trigger the dropdown menu. Whereas the splitButtonClicked event is raised when the split part of the button is clicked and displays a popup menu.
To handle these events you need to subscribe to SplitButtonActionListener.

Screenshots:




Friday, November 12, 2010

Simple Swing Validation using InputVerifier

There are many frameworks available out there for swing validation, like Simple Validation and JGoodies Validation and both being open source. But it looked to me, using these frameworks would require me to change a lot of my existing GUI code. And being a NetBeans user this looked tedious to me(as most of the GUI code is generated by the IDE). Then I came across Michael Urban's post - "Building a Swing Validation Package with InputVerifier". I have just extended his implementation to suit my needs, like instead of showing a popup for the error message, I wanted an icon painted right in the textfield like in netbeans.


P.S. The GTK Look and Feel does'nt allow a custom background in the JTextField. If you run this application under a different look and feel you could see the background color changing as well.

Monday, October 18, 2010

Display XML in JTree with DnD Support

This brief tutorial will explain how to use Java to display a tree view of XML using JTree with drag n drop support ,custom TreeCellRenderer to display different icons for different type of nodes and a popup.




Tuesday, August 24, 2010

File Scrubber

File Scrubber is a secure data removal java class. It allows you to securely delete files/directories from your hard drive by overwriting it random data 'n' number of times.

Usage:


FileScrubber scrubber= new FileScrubber();
   try
   {
//overwrites the given directory 5 times
       scrubber.scrub(new File("C:\\fileOrDir\\to\\delete"), 5);
   }
   catch(Exception ex)
   {
       System.err.println(ex.getMessage());
   } 
 

Wednesday, August 4, 2010

Displaying Numbers in Native Scripts C#

For one of my web app i had to display numbers in native script, arabic in my case. After googling around, i found these two useful websites

UTF8Encoding.GetDecoder Method (MSDN)
JavaScript Unicode Charts

Navigate to the JavaScript Unicode Charts page, then select your preferred script from the dropdown menu(i'll follow the example for arabic). Then you'll be shown a Unicode script chart of your selected langauge.



The highlighted row in the above screenshot is the arabic numerals and D9A0 is the utf-8 encoding value for the arabic number 0, D9A5 will be the arabic number 5.


Friday, July 2, 2010

GridView like control for PHP

PHP class for generating an HTML table from a given MySQL query. The class can render the table columns with result column data using custom formats, with links and check boxes. The table listing may have pagination links.The presentation of the table and link styles are configurable using CSS.

Screenshot:

Usage:


<?php
$conn = mysql_connect("localhost", "username", "password");
mysql_select_db ("mysql_db");
if (!$conn) 
    {
        die('Could not connect: ' . mysql_error());
    }
//check the source code for detailed phpDoc style comments
$gridview = new GridView($conn, "SELECT * FROM sample");
$gridview->setAllowPaging(TRUE, "pg_class",2,"2,4,6,8,10");
$gridview->setAllowSorting(true);
$gridview->setAllowSearch(true,"LastName");
$gridview->setGridCaption("Grid Caption");
$gridProperties = array(
       array("ID","id",Type::Label,""),
       array("FN","FirstName",Type::Link,"www.{0}{1}.com:LastName,FirstName:{FirstName}"),
       array("LN","LastName",Type::Label,""),
       array("email","email",Type::Label,""),
       array("phone","phone",Type::Label,""),
       array("blog","blog",Type::Link,"::myblog"),
       array("comments","comments",Type::Label,""),
       array("yes/no","bool",Type::CheckBox,"")
       );
$gridview->setStyleID("gridView");
$gridview->setGridProperties($gridProperties);
$gridview->show();
?>

The source for this class can be downloaded from phpclasses

Sunday, June 6, 2010

Java Native Interface

The Java Native Interface (JNI) is a programming framework that allows Java code running in a Java Virtual Machine (JVM) to call and to be called by native applications and libraries written in other languages, such as C, C++. (Wikipedia)

In this example we will be using win32 apis like FindWindow, SetForegroundWindow, GetWindowText, GetWindow, IsWindowVisible & GetDesktopWindow in a Java application using JNI.


Sunday, May 2, 2010

Steganography in Java

Steganography is the art and science of writing hidden messages in such a way that no one, apart from the sender and intended recipient, suspects the existence of the message, a form of security through obscurity. (Source: Wikipedia)

The image into which the message is to be hidden is known as the Carrier Image and the message or the file to be hiden is known as the payload.Each bit of the payload is hidden in the Least Significant Bit of either Red, Green and Blue for each pixel.That means we can hide 3 bits of payload per pixel.

Example:

In this example we will hide the letter 'A' (in binary 01000001)

Assume the three carrier pixels in RGB

R: 0011100 0
G: 0110100 1
B: 0000111 1

R: 0011010 0
G: 1000100 1
B: 0010001 0

R: 0011110 0
G: 1000010 0
B: 0011111 0

Here, we change the least significant bits (01101000) to our payload (01000001).
After this, our carrier pixels will be changed to

R: 0011100 0
G: 0110100 1
B: 0000111 0

R: 0011010 0
G: 1000100 0
B: 0010001 0

R: 0011110 0
G: 1000010 1
B: 0011111 0

The difference between 00001111 and  00001110 in the value for blue intensity is likely to be undetectable by the human eye.