Saturday, 20 November 2010

So Java is rubbish for printing

Especially on linux and Mac - and also Windows! Or maybe I'm missing the point. I can print portrait, on all 3 platforms. Trying to go landscape has Mac OS and Linux with the paper rotated but not the drawing, on Windows the whole damn thing is rotated so it looks like portrait but on its side!

I give in!! I will come back to printing later.

Now I'm at the stage I need to write an equivalent of JTextComponent and all the gubbins that surrounds it but for musical notes (well drumming ones anyway) instead of text. I've taken a look at the source code of JTextComponent and the accompanying docs and examples - there's no way I should just subclass it and use embedded components in a StyledDocument. There's just too much to get in the way. Also making the notes into a Font, with glyphs etc for the drawing strokes. Just not flexible enough.

Only one thing for it, an industrial strength JNote class and JScoreComponent, Editor, Pane etc.

One of the big things is this is a drawing program at heart, each note will be placed exactly where the author wants it, not some predetermined space from the previous one. The option exists to write a program which behaves that way, which could in fact be easier for some authors, but the one we're writing here gives all the decisions to the user.

Wish me luck - that bloody printing does bother me but it appears to be a bug in Java.

Tuesday, 9 November 2010

Papering over the cracks

PageFormat, Paper: bah! Slowing down here thanks to my lack of grasp of the printing system. OK so double precision co-ordinates throughout thanks to G2D - need to work that back into the screen co-ords handling but portrait and landscape are throwing me atm. So the user selects landscape, I should just pass the PageFormat to print() and that should be it but no, something screwy going on with the Imageable co-ordinates being wildly out when landscape, especially weird when there's no borders on the paper / printer combo. More severe looking at required!

Saturday, 6 November 2010

Keep it standard pays

The todo list is now vastly reduced for this first baseline app. Going to skip snap to grid for now, the AWT DnD implementation is now becoming a restriction in terms of snap to grid and zoom using AffineTransform. Will implement the rest of the app and ponder hard rewriting the DnD implementation. So still to do:

  • create ability to constrain the component resizing to certain directions only
  • create ability to always retain aspect ratio when resizing a component
  • implement image resizing within image component (retaining aspect ratio)
  • allow drop of images from external sources
  • implement paper size metrics etc, borders / gutter et
  • implement export action, with pdf initially as only target, maybe png too?
  • implement app preferences handling, saving to user dir etc (paper type, fonts blah)
  • implement splashscreen on startup
  • figure out packaging, e.g. jar, mac app etc

Friday, 5 November 2010

Design for drag image

Well had implemented the drag image as supported by DnD but ...
It doesn't work on Windows, and ...
It doesn't allow you to snap to grid on the drop target, essentially as the drop target can't get hold of the image or alter it's location in any way. It may be possible to do the following:
When the drag operation enters a component which has registered itself as a drop target and listener, dragEnter can extract the transferable, get the transfer data, instantiate the object, grab the drag image from it (as thats implemented in my source component), store that ghosted image in the target component, and then as dragMove is called (or whatever the motion listener is), it can paint the image. When dragExit is called it nulls the ghost image and we're back to square 1.
Must remember to null the ghost on successful drop.
This way the overheads of creating the image only happen when the cursor enters the component, not on every move.

Thursday, 4 November 2010

Coding, coding, coding

Implemented the first few requirements from previous post. Got the borders sorted on the PageLevelComponents and the menus etc to toggle to a page layout mode. Decided to make resizable components visible when in page layout mode - they disappear when user goes back to note editing mode.

Implemented the drag images too, shame the JVM on Microsoft Windows doesn't support them! There are workarounds out there using the glass pane etc, more code and a platform specific code branch required so ignored for now. Went seriously down a number of ratholes with that before!