Olbermann smacks back at O’Reilly

If you know who Bill O’Reilly is, and you don’t hate freedom, this is funny.

Posted in Politics | Leave a comment

Tic Tac Toe

I’ve been working on a simple Tic Tac Toe game. Most things going well, but I’ve been working on the painting of the X’s and O’s within the insets of a given JButton. In the end, the calculation that actually centered it drove me crazy: I had to use 2 * the width of paint stroke.

Anyway, I’m looking for a cleaner way to draw the X and O Icon within a JButton. Here’s the current image; it currently resizes well, but there’s gotta be another way. Any suggestions? Thanks in advance. Here’s the paint code:


	public void paintIcon(Component c, Graphics g, int x, int y) {
		if (!CLEAR_SQUARE.equals(type)) {
			int strokeWidth = calcStrokeWidth(getWidth(), getHeight());

			int strokeWidthX2 = strokeWidth * 2;

			Insets insets = getInsets();
			int width = getWidth() - strokeWidthX2 - insets.left - insets.right;
			int height = getHeight() - strokeWidthX2 - insets.top - insets.bottom;
			int left = insets.left + strokeWidth;
			int right = left + width;
			int top = insets.top + strokeWidth;
			int bottom = top + height;

			Graphics2D g2 = (Graphics2D) g;
			g2.setStroke(getStroke(strokeWidth));
			g2.setColor(getForeground());
			g2.setBackground(getBackground());

			if (X_SQUARE.equals(type)) {
				g2.drawLine(left, top, right, bottom);
				g2.drawLine(left, bottom, right, top);

			} else if (O_SQUARE.equals(type)) {
				g2.drawOval(left, top, width, height);
			}
		}
	}


Posted in Swing | Leave a comment

Apprentice

I’ve seen a few posts saying either that Donald Trump choose the wrong apprentice. These posts have a hint of something other than logic and reason.

If you just went off of productivity, he was the better choice. Let’s take for granted that he is more educated. However, let’s not overlook his experience. He put it exactly right when he said he “runs businesses, while she just writes about them”. Randall is the CEO and founder of BCT Partners (bctpartners.com) a successful small business.

As project manager, Randall won 3 out of 3 tasks. On the other hand, Rebecca has only won 1 out of 3 tasks as a PM. In addition, her one winning task had a good deal to do with Randall being her only teammate.

Also, loyalty is a great thing, but she showed throughout that she would allow it to possibly sabotage her (even bringing Toral back at the end).

In the same vein, I have never seen so many fired contestants praise one person so much. Not to mention, when there was a chance to trade a teammate, time and again, teams always choose Randall.

So, exactly why was Randall the wrong choice?

Lastly, in response to Randall not agreeing to their being a second apprentice: why should he have? In a past season, there was a “close” race between Bill and Kwame (guess who’s the black guy). Kwame was from Goldman Sachs, and had a Harvard MBA. Bill was an entrepreneur who started cigarsaroundtheworld.com. Most people thought it was a tight one, but Kwame had the credentials to take it all the way. Obviously, Trump felt differently. Oh well, it’s seems to have worked out because Trump has extended Bill’s contract. So, why was Randall selfish?

Posted in General | 13 Comments

WebWork-2.2 and Generics

I’m working on a settings screen (using JSP) which iterates over a Map of generic SettingEntries. A SettingEntry is defined as follows:

public class SettingEntry <T> implements Serializable {

private final String key;
private final T defaultValue;
private T value;

// Ctor, getters and setters removed for brevity's sake
}/code>

When a user enters a new value, ideally the form value should be converted to the correct type. For example, “board.size” was created as a SettingEntry <Integer>. Ideally XWork/WebWork's type conversion should set the value as a new Integer. However, this is not the case. Instead, a String[] array (WW's default type for form parameters), of length one is set as the value.

Java's implementation of generics does not create a new class based on a class template. Instances of a generic class have the same run-time class. So, the following lines will both print true:

System.out.println(new HashSet<String>().getClass() == new HashSet<String>().getClass());
System.out.println(new HashSet<String>().getClass() == new HashSet<Integer>().getClass());

Well, after looking through a piece by Gilad Bracha, I made SettingEntry<T> aware of its type, in a generic way. I added a generic instance of the targetClass to SettingEntry, and then I could at least check that the T value being set on the SettingEntry instance is the same Class that the class was initially made with. Now, I can just make a converter which will create new instances based on the targetClass.

Currently, XWork-Tiger allows for a collection’s generic type to be used, rather than the developer defining the element types, and the key for maps in a conversion property file. Although this is a specific use case (iterating over a map of generic settings), I think the new XWork-Tiger module could benefit from this. It should allow for users to define a target Class, which XWork could later use to provide new instances, or at least properly cast existing references.

Posted in Technical stuff | Leave a comment

Context-sensitive menu using WebWork

Looking to build a generic context-sensitive menu using WebWork. Came up with the following requirements:

  • All items described below are menu elements.
  • A menu element has a name attribute.
  • A menu element has a parent menu element.
  • If a menu element does not have a parent, it is the root menu.
  • A menu element is only aware of its structural representation, i.e.: it’s a model.
  • A menu may be composed of other menus.
  • There is only one root menu.
  • The root menu has a default menu set.
  • The default menu is shown if the current use case does not provide a menu.
  • There is a mechanism to change the current menu based on the current use case.
  • A menu may have child menu items.
  • A menu item has an action attribute. The view will rely on this to react to a menu item being selected or clicked. This action may be a URL or script call.

The visual representation of the menu elements above could be as simple (html) or complex (Ajax/DHTML) as the end user wants. As a default, you could use a simple html output. The output would basically output the root menu’s immediate children. While displaying a menu item, the cell/div would be clickable. Its onclick would either send the user to a given URL, or execute a given script call.

In terms of setting the menu based on the current context, an interceptor requesting the desired root menu seems enough. For example, FooAction would implement MenuProvider. A MenuProvider would return its desired root menu. If FooAction wanted to modify the existing root menu, rather than completely replacing it, it would implement MenuAware. The same aforementioned interceptor would set the root menu on MenuAware classes.

Constructive suggestions appreciated.

Posted in Technical stuff | 1 Comment

Good FEMA.

Yeah, so if you’ve been the news, you know that the government officials charged with mitigating the loss of life didn’t do the best job they could have. OK, fine. Now, when I say government officials, I am referring to Department of Homeland defense, FEMA, Louisiana State and local officials. This is old news.

Well, I was watching the Daily Show, and one of the segments pointed out a diagram on FEMA’s “About Us” page. It’s horrible; notice how after all is said and done, FEMA plans on returning to a state of disaster.

FEMA's idea of problem solving.

Posted in General | 2 Comments

DBDesigner 4

Ok, so I’m starting the domain design section of a project. I usually get the generic attributes and relationships down, and start a real simple domain model using Access. Then import that into Visio. Once in Visio I get a cleaner more detailed version of the domain. Then I write the creates, drops, etc.

This process is a convoluted and I feel takes longer than necessary. If only I had a tool that would give me the ability to not only visually create a detailed domain model, but then export it either into a sql file or a live database (and it has to be inexpensive or free, free is preferred). Well, as it turns out, DBDesigner4 is that tool.

I found it after searching the MySQL developer section. Luckily, they had an ERD tool section. In the blurb, DBDesigner 4 is mentioned as comparable to Oracle’s Designer, IBM’s Rational Rose, CA’s ERwin and theKompany’s DataArchitect. I’ve never used any of those, but I did find this to be very useful. It’s been released under the GPL.

I found two things that were missing or needed some work. Some shortcuts (that do exist and work when you enter them) are missing next to their respective menu items. For example, Ctrl + S is not next to Save, but works just the same. Another issue was the focus: they allow your edit properties of the selected table to change when you double click another table. This allowed me to move from table to table without ever closing the dialog each time I was done. This is fine, but when there was an error of some sort, it seemed that the error dialog was given the main app as the parent. I say this because the error dialog would come up; accompanied by an alert sound, but you could not see it. I moved the edit properties dialog down a bit and saw the error dialog waiting.

Overall, my experience with the tool was actually pretty good. If you’re using MySQL, I’d stronly recommend it.

Posted in Technical stuff | 3 Comments

I love Luxsana

So I decided to purchase a portable infared suana, the LX-001. It’s hot (pun intended). So, an artistic co-worker, Anthony draws me in the sauna. It’s pretty funny.Me in a LX-001

Oh, ignore the person in the sauna, I’m actually tall and slender, with hair… Ok, well at least I have hair. See the post here. Here’s another depiction… Me in a LX-001

Posted in General | Leave a comment

Which OS are you?


Which OS are You?

The only thing it got right was about my cousin Wince…

Posted in Time Waster | Leave a comment

I think Open Source is good, and technology helps makes life easier.

If your interested, no, I could not think of a better title.

Since the late summer of 2003, I’ve been working on a side project. It wasn’t much, simply an apartment rental application. The main features were:

  • Allow a renter/seeker to search for apartments.
  • Allow a manager of a complex to update apartment postings.
  • Allow an administrator to update apartment postings, and update users of the system.

Well, it seemed simple enough, so I thought “why would this take more than couple of months?” Well, I was cocky, overconfident, shortsighted and most importantly, wrong.

I initially projected a demoable version of the application in six months. Yeah, that’s nice. So a year passes, and in comparison to what I had projected, I had actually only completed a fraction. Almost two years later, and I’m just finishing up. Oh yeah, and when I say finishing up, I mean finishing a drastically reduced in scope version. How reduced in scope? Very. For example, there’s no more renter/seeker version of the application. Yeah, and I also removed the manager section. I mean, who needs managers. In the end, I have a really robust Admin section. 😐

Ok, now for something positive: I learned a ton. I started out using JBoss, and Jason C. suggests I try Resin. Not sure if it’s because of some bias, but Resin turned out to be much faster, and easier to deploy using Ant. For the persistence layer, I was using hand written JDBC DAOs to talk to my MySQL database. Jason suggested Hibernate; it was a great move. For the presentation layer, I was using Webwork/XWork, Sitemesh and DisplayTag. Since Jason is a leading member of WebWork, I didn’t hear much about “try this” or “try that” other web framework. Actually, I’ve been a WebWork user for a while, so I was pretty aware of what it could do. I was putting most of my business logic in the Actions, yeah I know: bad idea. So I decided to add a service layer, but I didn’t want to add EJBs to the mix; Jason suggests Spring. Being new to the concepts of AOP, IOC and dependency injection, the learning curve was much higher than expected. Either way, it worked out fine: I didn’t have to add EJBs, and it made deciding to add Acegi (to handle security) much easier.

In the end, the real reasons for me not completing the application include:

  • Concentrating too hard on things like UI aesthetics. e.g., getting the color and size of table headers just right.
  • Not having as much energy as I thought I’d have after a 40+ hr work week.
  • Being one person and not being able to split my self like superman did in that one episode. This was the real killer; damn you reality!

But I’d like to ignore those, and instead blame the open-source community for making great software. Oh yeah, and Jason for suggesting I try these technologies. Damn you all to Hades. If you want see what I spent my free time on for the past 2 years, the code’s available here.

Posted in Technical stuff | 15 Comments