Monday, August 17, 2009

Let them eat cake.

Late last week it was suggested that when you are placing a new object on our network schematic editor the cursor should change to a thumbnail of the object you are placing.

"This is good" I say, "Let me create an enhancement request and today when I am working on the network schematic editor I will add a code change to produce said cursor enhancement". This is met with great applause and encouragement from all in the team (those of you who work in software development will know exactly what I mean here), and I left to create the enhancement request.

Later that day I created the enhancement request and it was good.

Anyway, after about an hour, I manage to produce code which dynamically processes the thumbnail image from the selection pallet and adds it to a generated image to produce a small thumbnail image surrounded in a dashed red line box and lovely black cursor arrow in the top left.

Now it is important at this stage to understand that this was no ordinary arrow and I don't think that "lovely" quite does it justice. This arrow is and will remain a masterpiece of creativity and engineering.

The process of producing such a perfectly shaped cursor arrow is a long and involved one; taking up far too much time to explain than I have to write. If I was to spend one tenth of the time and energy spent developing the said "lovely arrow" on writing about how to develop it, you would die of old age before you had a chance to read one fifth of what I had written (Well, that may be a slight exaggeration as I don't really understand how fractions work, but you get the idea).

Anyway, within about one second of the product manager seeing the final result, he says "Errr, don't like that arrow, how about you change it back to a crosshair?".


........... a crosshair.

Seriously, a crosshair.

Anyway, so here is the code change:

customCursorBack = gc.createCompatibleImage(
32,
32,
Transparency.TRANSLUCENT);

Graphics2D g2=(Graphics2D)customCursorBack.getGraphics();

Stroke standardStroke = g2.getStroke();
g2.setColor(Color.red);
g2.setStroke(getCustomCursorStroke());
g2.drawRect(11, 11, 18, 18);

GeneralPath cursorShape = new GeneralPath();
// // Draw a perfectly lovely Arrow
// cursorShape.moveTo(0,0);
// cursorShape.lineTo(11, 11);
// cursorShape.lineTo(6, 11);
// cursorShape.lineTo(9, 17);
// cursorShape.lineTo(7, 18);
// cursorShape.lineTo(4, 12);
// cursorShape.lineTo(0, 16);
// cursorShape.lineTo(0, 0);

// Draw crosshair (seriously, a crosshair)
cursorShape.moveTo(8, 0);
cursorShape.lineTo(8, 16);
cursorShape.moveTo(0, 8);
cursorShape.lineTo(16, 8);

g2.setColor(Color.black);
g2.setStroke(standardStroke);
g2.draw(cursorShape);


If you are ever looking for the code for a perfectly lovely black arrow cursor here it is, albeit in comments alone.
If you are ever looking for a example of how to break a man's heart and destroy the hope and dreams which he holds for his creation, here too you will find it.

No comments: