From: Iain A. <ia...@co...> - 2005-03-07 22:05:11
|
Stewart wrote: >I haven't investigated the feasibility of this, and its a few years since I >last dabbled in Swing, but I recall that layout managers can be nested, and >though complex, GridBagLayout is a *very* powerful layout manager. > >Given that the stock chart itself is basically just a collection of square, >numeric fields, would it not be possible to use a JTextField for each "box" >and control the layout with nested layout mangers. Switching on borders to >get the grid effect is relatively simple. Yes, this is the right thing to do. If you regarc a hexagonal gird as a rectangular one with alternate rows (or columns, depending on the grain direction) offset by half a cell, you can do that too. You can use a JPanel for cell, and then drop JLabels in for things like the price, and even for the tokens. You should be able to set borders and background colours without too much difficulty. > >The tokens will still have to be drawn using Java 2D, but this approach >might be a lot less work overall. You can assign a gif icon to a JLabel, although that gives a rectangular component, there are ways to pretty that up in the short term. I'd concentrate on getting something functional first, and then worrying about pretty rendering with Graphics 2D later. >I agree that the map and hex grid will have to be drawn with Java 2D. The >tiles can be pre-drawn images - including all of the static elements of the >map. This allows the "blank" map to be generic with size and coordinate >systems the varying element. "Hex grid math" is a little different to >"rectangular coordinate math", but it"s all been worked out before for >numerous computer wargame play aids, and will need an internal, consistent >coordinate system to make it easy. I haven't looked at the Graphics-2D API yet, I've produced sufficient with Swing for what I've done to date. My original 18xx map rendering was done with AWT rendering, since I wrote it pre-Swing: you can see it on my home page: http://www.cosgor.demon.co.uk . <aside>The 1998 (c) refers to the last modification, which was the water symbol rendering, the original Java code was late 1996 or early 1997 (and the original C code even older than that).</aside> ISTR some of this code is not how I would write it now, but I should be able to dig up the source for the applet if it's of interest. Iain. |