A better layout manager in BetterFlowLayout
Thursday 14th of May 2009, 06:00:34 am
Layout management in Java gives me lots of headaches. Especially since I'm writing a custom text annotation tool and there do not seem to be any layout managers that are designed to do what you expect for text-like objects: format as lines and paragraphs.
So I ended up writing my own layout manager, called BetterFlowLayout, which does *almost* the same thing as the normal FlowLayout layout manager but with a crucial difference: you can actually force newlines and line skips. WOW POMS, SO REVOLUTIONARY! I know, there's a few million people on the internet who post on forums asking how to make FlowLayout do linebreaks only to hear people derisively say "that's not what FlowLayout is for".
It damn well should have been, because adding the logic in to make it all work only takes a few hours of programming.
Enjoy. It comes with a main method in it, so you can import it, look at the code (compiled into the jar) and run it to see what it does. It does simple.
JavaDoc is here
What does it look like? Well that's hard to say, since layout managers are responsible for placing components, rather than be visible somehow, but let's imagine we have a large text, chopped up into randomly sized/coloured letters with white backgrounds, and we place them on a dark blue panel. Then we have the BetterFlowLayout manager do its magic with us only saying we want a line spacing of 5px, a paragraph spacing of 15px, and horizontally left justified lines, with the letters vertically bottom aligned (or 'baseline' aligned in the case of text) per line too.
Then we get this:
Unicode strings in java in uString
Sunday 3rd of May 2009, 07:54:12 am
I got fed up with Java's inability to properly handle unicode strings due to it relying on a 16 bit "char" primitive. Unicode (at the time of writing) basically covers a space that requires 4 bytes, and char is only 2 bytes 'wide', so it just ... doesn't work. Strings report the wrong length, substring selection can chop up unicode glyphs mid-byte-sequence, it's a mess.
So I wrote a uString object instead. It's downloadable as a convenient jarchive for use in your own projects (with the source compiled into the jar), and hopefully it will become obsolete soon enough as the java String starts using a variable length encoded character primitive (I'm thinking a 7-bit-with-has-more-bit byte, but who can say what's optimal)
The javadoc can be found here
- Pomax
A walk through the garden in photography
Saturday 18th of April 2009, 05:42:15 am
With the weather being pleasant, I decided to take a stroll through my parents' garden and take a few pictures. The result is actually fairly enjoyable so I figured I'd set up a set for it, starting at this photograph.
Need SQLite 2.8.17? in programming
Friday 10th of April 2009, 04:52:49 am
Need SQLite 2.8.17 but can't find it on sqlite.org? Then fret not, because it's still there, just not linked from the download page.
click http://www.sqlite.org/sqlite-2_8_17.zip to download it, or copy-paste that link if you don't trust direct filelinks (javascript might be making it look like a safe file O_o!)
As always, scan any files you download. Wouldn't want to be one of those millions of people who are responsible for spam, trojans and virusses infecting us all, do you?
Thursday 9th of April 2009, 03:52:16 am
The browser, mind, not the artistic music and singing.
Why? Because as a developer I like to be able to write cross-browser material, and Opera doesn't let me. For instance, have some fun looking at mouse handling in js across different browsers, and notice what Opera allows.
That's right, just one mouse button. I'm sorry, was the internet use moving to online applications, with their own context menus? Well too bad, Opera won't let you use those.
It also doesn't *tell* you it blocks things in its error console.
Thanks, Opera. Thanks to your idiocy I have to figure out some kind of idiotic button bar system now. I hope you fossilise soon (or experience a rebirth as a browser willing to move along with the internet. Even IE's trying, why aren't you?)
Formatting plain text in html? in programming
Thursday 12th of March 2009, 05:55:09 am
What happens when you combine dynamic content distribution with dynamic CSS manipulation?
The simple answer is "whatever you make it do", but the more interesting answer is "the basis for a dynamically adjustable text formatting system", which lets you set up print pages in terms of page dimensions and print dimensions, and have it automatically generate the right number of pages as divs on the page.
Which is exactly what I need for evaluating my book rewrite. Paired with a bit of nifty php processing so my 漢字(ふり) notation becomes
Putting it all together's lead to this, which works in Firefox 3, Webkit (Safari 4 and Chrome 1), Opera (9.5x) and IE7. So consider me quite happy. This was actually really fun to write.
Monday 9th of March 2009, 05:04:37 am
This entry links to my article on personal freedom (elucidated via the crowd-winning technique of using sex as example) and what this actually means in terms of thinking about one's opinion in regards to various freedoms.
Read the article here
Backlog: abortion and the death penalty in Articles
Monday 9th of March 2009, 05:02:11 am
This entry is a backlog entry, linking to an article on the morality of abortion and the death penalty, originally posted November 17h, 2008
Read the article here
Backlog: the division fallacy in Articles
Monday 9th of March 2009, 05:00:46 am
This entry is a backlog entry, linking to an article on fallacious generalisation, originally posted September 11th, 2008
Read the article here
Backlog: timetravel to see the past in Articles
Monday 9th of March 2009, 04:59:04 am
This entry is a backlog entry, linking to an article on a curious alternate form of timetravel to observe the past state of the universe, originally posted October 30th, 2006
Read the article here