views:

248

answers:

4

I am creating an application which has a scrollable and scalable (zoomable) view. Inside this view I want to place other components (most of them customized JPanels and JInternalFrames).

Things such as fonts and borders, and sub-elements such as buttons don't need to be scalable. Only dimensions and position of container components should be.

What do you think, what is a good way to implement scalable components?

EDIT: I'm talking about resizing the entire layout including all components. Please think of something such as a visual UML editor with zoom functionality.

My alternatives are:

  • Create a custom layout manager;
  • Create custom resizeable sub-components;
  • Create a custom container which would take care of resizing its sub-components;
  • Do something else?

Possible problems:

  • Boilerplate code;
  • Necessity to provide access to additional custom properties of components;
  • Not straightforward (inconsistent) representation of components in code.
  • Something else?
A: 

If I look at this problem as visual UML editor then I had to think about single "canvas" component drawing each element as graphical object with base aspect ration and zooming in/out. I can't see reason for list of components aligned within parent container.

Rastislav Komara
I want to use Swing for most components, so I can't just "draw" them in a scaled way (would look ugly).
ivan_ivanovich_ivanoff
We do not understand each other. I was just pointing to your justification for visual UML editor.
Rastislav Komara
+1  A: 

This is why layout managers exist: they tell contained components where and how large they should be.

Since you're talking about a UML editor, are you using contained Swing components to represent the various objects in the diagram (eg, a component for a class)? If yes, then you've got a lot of work ahead of you (although it's not necessarily a bad approach). I'd recommend creating a constraints object that identifies the object's location on a "unit space," then multiplying by the current size.

kdgregory
A: 

I've done that by creating a custom layout manager. Every component (or rather component class) on the frame has a marker whether or not it shall be resized when the container is resized (e.g. tables are resized, buttons are not). Those which are not resized are moved when the container is resized.

This is used to make resizeable forms without any manual setup, i.e. forms are defined by just specifying x/y/length/width for each component (no further alignment info).

ammoQ
A: 

Hi there!

I started a similar solution that works fine without touching the original layout.

It's as easy as this:

// Install scalable layout and CTRL+/CTRL- keys for scaling operations
ScalableLayoutUtils.installScalableLayoutAndKeys(new DefaultScalableLayoutRegistry(),  frame, 0.1);

You can see a short demo here: http://www.fuin.org/utils4swing/examples/scalable-layout-example.swf.html

It's still under work but It will be soon available as part of the next "utils4swing" version.

Cheers, Michael