 |
Home | Changes | Index | Search | Go
- Can it align components across other components? For example, can it both left and right align the 'phone' text field with the 'city' text field on the other side of the two address fields?
- Yes. ZoneLayout is grid based so components will align across other components if they have the same coordinates.
- Does your manager know about platform specific gaps and spacing among components. Just curious.
- No. ZoneLayout is a pixel based layout engine, but there's nothing stopping you from including components that have sizes relative to platform. For example, you could override the preset components in the layout with spacer components that determine their size based on platform (from JGoodies for example). If there's enough interest in this, I could integrate this into the library.
- Can the text fields, labels, etc grow and shrink when the text is localized?
- Yes. ZoneLayout uses the component sizes (min, pref) for sizing requirements, so when they change during localization, the layout will adapt.
- Just how much code do I have to write? Java code? Declarative XML?
- This is ZoneLayout's differentiating feature. Along with some Java code, you write some code using a custom 2D regular expression like syntax that "draws" your layout in your source code. Don't let the regular expression like syntax throw you off as the language is very simple. Because all your layout code is contained within a few lines of code and you can "see" what it looks like, changing the layout becomes quite easy.
- Can I nest panels?
- Yes. ZoneLayout makes most layouts doable without resorting to nesting panels, but it doesn't restrict you from doing so. When you need to size and orient components independent of the current layout, nested panels are a necessary and valuable resource.
- Can it align components along a baseline. For example, the new GroupLayout? can align labels and text fields along the text baseline...that's nice.
- No. Integrating this would be possible.
- What's the licensing?
- LGPL, although Attic Labs is willing to work with anyone that needs more flexibility.
- Will this work for bi-directional locales? How difficult would it be to mirror the layout for a right-to-left locale?
- No. Mirroring layouts would be a challenge. With ZoneLayout, It'd be easier to have multiple layouts based on locale, especially since the layout code is so succinct.
Below is the code to render the Address Book Panel in John O'Connor's layout manager showdown. A couple of notes:
- Two sub-panels are used, one for the button bar and one for the email label and field.
- It was necessary to create a sub-panel for the email label and field because they are not aligned with all of the other labels and fields in those columns in the base panel.
- There is no code to size all of the buttons to the same Dimensions
- Templates were used in the layout to cut down on duplication since many of the rows use the same layout
- Note how Zone 'a' spans across the templates. This necessitated the mostly empty first and last rows in the layout.
// Button bar and email sub-panels
ZoneLayout btnBarLayout = ZoneLayoutFactory.newZoneLayout();
btnBarLayout.addRow("a2b2c2d2e");
JPanel buttonPanel = new JPanel(btnBarLayout);
buttonPanel.add(new JButton("New"), "a");
buttonPanel.add(new JButton("Delete"), "b");
buttonPanel.add(new JButton("Edit"), "c");
buttonPanel.add(new JButton("Save"), "d");
buttonPanel.add(new JButton("Cancel"), "e");
ZoneLayout emailLayout = ZoneLayoutFactory.newZoneLayout();
emailLayout.addRow("a2b~-b");
JPanel emailPanel = new JPanel(emailLayout);
emailPanel.add(new JLabel("Email"), "a");
emailPanel.add(emailTxt, "b");
ZoneLayout layout = ZoneLayoutFactory.newZoneLayout();
layout.addRow("a..3...................");
layout.addRow("....b>b2c-~c2d<..d2e-~e", "doubleRow");
layout.addRow("....6..................", "doubleRow");
layout.addRow("....i>i2j-~j2k......-~k", "emailRow");
layout.addRow("....6..................", "emailRow");
layout.addRow("+*..f>f2g-~...........g", "singleRow");
layout.addRow("....6..................", "singleRow");
layout.addRow("....h.................h", "buttonBar");
layout.addRow("..a.!..................");
JPanel basePanel = new JPanel((layout));
basePanel.add(nameList, "a");
layout.insertTemplate("doubleRow");
basePanel.add(new JLabel("Last Name"), "b");
basePanel.add(lastNameTxt, "c");
basePanel.add(new JLabel("First Name"), "d");
basePanel.add(firstNameTxt, "e");
layout.insertTemplate("emailRow");
basePanel.add(new JLabel("Phone"), "i");
basePanel.add(phoneTxt, "j");
basePanel.add(emailPanel, "k");
layout.insertTemplate("singleRow");
basePanel.add(new JLabel("Address 1"), "f");
basePanel.add(addr1Txt, "g");
layout.insertTemplate("singleRow");
basePanel.add(new JLabel("Address 2"), "f");
basePanel.add(addr2Txt, "g");
layout.insertTemplate("doubleRow");
basePanel.add(new JLabel("City"), "b");
basePanel.add(cityTxt, "c");
layout.insertTemplate("doubleRow");
basePanel.add(new JLabel("State"), "b");
basePanel.add(stateTxt, "c");
basePanel.add(new JLabel("Postal Code"), "d");
basePanel.add(postalTxt, "e");
layout.insertTemplate("doubleRow");
basePanel.add(new JLabel("Country"), "b");
basePanel.add(countryTxt, "c");
layout.insertTemplate("buttonBar");
basePanel.add(buttonPanel, "h");
|