Archive

Archive for July, 2009

Java Swing Contains Vs Intersects

July 28, 2009 Leave a comment

Contains: Is it on the boundary line or not
Intersects: Given point is in side the shape or not. If it is line, this is same as contains.
Even better example is available at http://forums.java.net/jive/thread.jspa?threadID=56250&tstart=60

import java.awt.geom.Ellipse2D;

/**
 * This examples helps to understand contains and intersects concepts.
 * 
 * @author Bhavani P Polimetla
 * @since Jul-28-2009
 * 
 */
public class TestPoint {

	public static void main(String[] args) {
		testContains();
		testIntersects();
	}

	public static void testContains() {
		Ellipse2D.Double circle = new Ellipse2D.Double(230, 277, 7, 7);
		System.out.println(circle.x + " " + circle.y);
		boolean isContains = circle.contains(230.0, 277.0);
		if (isContains)
			System.out.println("Point is on the cicle");
		else
			System.out.println("Point is not on the circle");
	}

	public static void testIntersects() {
		Ellipse2D.Double circle = new Ellipse2D.Double(230, 277, 7, 7);
		System.out.println(circle.x + " " + circle.y);
		int x = 230;
		int y = 278; // Inside point
		boolean isContains = circle.intersects(x, y, x, y);
		if (isContains)
			System.out.println("Point is inside the circle");
		else
			System.out.println("Point is Outside the circle");

		x = 0;
		y = 0; // Outside point
		isContains = circle.intersects(x, y, x, y);
		if (isContains)
			System.out.println("Point is inside the circle");
		else
			System.out.println("Point is Outside the circle");
	}

}

Categories: Swing Tags: ,

Java Swing – Telugu

July 21, 2009 3 comments

Just thought of writing small application in Java to display Telugu fonts. Here is the code for your reference.

Java Telugu Example

Java Telugu Example


import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JTextArea;

/**
* Copy gautami.ttf from windows\fonts to \java_160_10\jre\lib\fonts\
*
* References:
*
* http://unicode.org/charts/PDF/U0C00.pdf
* http://java.sun.com/javase/technologies/core/basic/intl/faq.jsp
* http://java.sun.com/j2se/1.4.2/docs/guide/intl/fontprop.html
*
* Load font from file
* http://www.java2s.com/Code/Java/2D-Graphics-GUI/Loadfontfromttffile.htm
*
* http://www.roseindia.net/java/example/java/swing/graphics2D/font-paint.shtml
*
* How to get unicode for telugu from lekhini? type in lekhini. copy text to
* following location. Get unicode.
*
* http://rishida.net/tools/conversion/
*
* When you type in text area, we will get squares. Use Baraha IME. Then you can
* type in telugu.
*/
public class JavaTeluguDemo extends JFrame {

private static final long serialVersionUID = 123123123L;
private static final Font fontTeluguGautami32 = new Font("gautami",
Font.PLAIN, 32);
private static final Font fontTeluguGautami10 = new Font("gautami",
Font.PLAIN, 22);
private static String telugu = "\u0C05\u0C2E\u0C4D\u0C2E";
private static String teluguHeading = "\u0C1C\u0C3E\u0C35\u0C3E \u0C24\u0C46\u0C32\u0C41\u0C17\u0C41";

public JavaTeluguDemo() {
JTextArea taDisplay = new JTextArea(telugu);
taDisplay.setFont(fontTeluguGautami32);
this.getContentPane().add(taDisplay);
}

public static void main(String[] args) {
// We can't change title font in default system look and feel.
JFrame.setDefaultLookAndFeelDecorated(true);

JFrame frame1 = new JavaTeluguDemo();
frame1.setSize(400, 150);
frame1.setVisible(true);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame1.getLayeredPane().getComponent(1).setFont(fontTeluguGautami10);
frame1.setTitle(teluguHeading);

}

}

Description: Could not locate TransactionManager

July 21, 2009 Leave a comment

Exception:

Chained Exception Object: org.hibernate.HibernateException
Description: Could not locate TransactionManager

Solution:
When we use org.springframework.orm.hibernate3.LocalSessionFactoryBean, the following two properties are not required.

http://docs.codehaus.org/display/BTM/Hibernate13

<!--
<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.TransactionManagerLookup</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>  -->

-o-

Backup personal data

July 16, 2009 Leave a comment

Problem Statement: Having 80GB external disk and using JFileSync to take backup. Now it is going to full soon. Also system hard disk.
When data is increasing, JFileSync is taking too much time to compare and to perform sync after that.

Solution 1:
Buy 1.5 TB internal hard disk. Install as secondary disk.
Buy 1.5 TB USB hard disk
Use backup software to take backup.

Problems: backup time is very high. difficult to maintain over period of time.
Advantages: Internal disk is safe with big tower system. We can store external USB in safe place.

Solution 2:
Buy: D-Link DNS-321 Network Attached Storage Enclosure – 2-Bay SATA, RAID 0/1 from compusa
Buy: Seagate 1.5TB SATA Barracuda 7200.11 Internal Hard Drive – 2-Pack from Dell
Setup RAID. Life will be cool.

Problems:
1. In case of theft, we may lose whole system.
2. We need to configure how to take backup if we add second disk after n days.
3. We need to protect it on internet or add to USB

List of back up software to use.

http://en.wikipedia.org/wiki/List_of_backup_software

Dir Sync Pro: http://directorysync.sourceforge.net/

-o-

GPS Tracking for Man and Machine

July 14, 2009 Leave a comment

మీగడ తరకలు

July 12, 2009 Leave a comment

చాలా రోజుల తరువాత ఒక మంచి తెలుగు సైటు కనిపించింది.

మీగడ తరకలు

http://maganti.org/migadatarakaluindex.html

Categories: Links Tags:

Difference betwen two object arrays

July 10, 2009 Leave a comment

Problem Statement: We have two different sets of objects. We would like to find the objects which are different in given two sets.

Solution: Use Java-Diff from http://www.incava.org/ . I am suspecting issues with its accuracy. Make sure that comparators are working for objects.

-o-

Categories: Core Java Tags:

TestNG for OSGi Bundles

July 8, 2009 1 comment

Problem: We need to test bundles deployed in OSGi.

Solution: Bundle test classes as xyz_tests.jar file. Convert this into bundle and deploy along with main bundle code.
In test bundle activator, programmatic way call TestNG as shown in http://testng.org/doc/documentation-main.html

TestListenerAdapter tla = new TestListenerAdapter();
TestNG testng = new TestNG();
testng.setTestClasses(new Class[] { Run2.class });
testng.addListener(tla);
testng.run();

TestNG opens in its own JVM. Due to this it is not recognizing test classes. We can build OSGi classpath with the help of bundle context. But we dont have option to pass classpath to TestNG programitically. Even though we can pass, it uses jar files in path, But not the bundles.

Conclusion: We can’t use TestNG inside OSGi. Please let me know your experience.

-o-

Categories: OSGi Tags: , ,

Project Management: Fire the Tailor and save money

July 1, 2009 5 comments

Director: Director wants a shirt with two long sleeves and pocket to keep change. It should fit to all characters based on situation.

Producer: I am having only 100$ budget.

Company: Company told that it should follow ISO standards.

Production manager: Asked tailor to prepare plan and submit to stylist.

Stylist: Stylist told that, they have good idea how the shirt looks like. Also told they have standards for all shirts which are going to used by different parties based on time to time. They don’t have budget constraints and according to them final shirt can cost 300$ to get that shirt in desired fashion.

Producer: I have only 100$ budget but if we can do all as told by stylist with in that budget that will be great.

Stylist: Yes we can do it. It is easy to do. We already did this with prototype.
(In reality the prototype is not nearer to real one which needs to be produced.)

Production manager: Guys it is difficult to achieve. Let us start with Plan 1. Later we can add Plan 2 and Plan 3.

Tailor: Hello…here is the shirt as per Plan 1.

Stylist: Without my Plan 2 and Plan 3, it is not the shirt we want you guys to use.

Production manager: I will check with other producers to sponsor this shirt, So that they can also use this for their film. Asked Tailors to take the shirt through plan 2 and plan 3.

(There are three separate tailors who are specialized in stitching according to different plans 1, 2 and 3.)
Tailor: Hello…here is the final shirt which implemented Plan 1, Plan 2 and Plan 3.

Production manager: Hmm…It looks good…we got it what we need.

Stylist: Hmm…it looks great as we thought.

Producer 1 and Producer 2: Shirt looks great, you guys eat 400$ to produce this. This is too much and we are not happy. Still it is missing one more pocket. (This is not part of initial requirement.)

Question: Due to whose fault shirt rate went from 100$ to 400$?

Problems identified:
1. Prototype is not nearer to real one.
2. Stylists falsely convenience management that they can get shirt out with 100$. (If they tell upfront 300$ required, management wont agree.)
3. Instead of putting all plans together, executing three plans in three different time frames needs lot of rework hence hiked the final price.

Politics:
1. Director wants to save his face. So called for a meeting and asked production manager to identify the cost eaters. Production Manager opened his excel sheet and found that Tailors took too much time to stitch. (Everybody forgotten that they are directed to do so.). Management wants to manage themselves for upcoming projects quickly. They kicked the Tailors out and hired new Tailors who can stitch faster than their thoughts.

Poor Tailor back on road with his Scissors and Tape to find his next assignment.

-o-

Follow

Get every new post delivered to your Inbox.