MiGLayout DSL mode

Swing Designer allows you to quickly create the frames, panels, dialogs, applets and other UI elements that comprise Java Swing applications.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

MiGLayout DSL mode

Postby Andrei.Pozolotin » Tue Oct 12, 2010 8:46 am

by default, MIG support in WB uses "text language";

Code: Select all
JPanel panel = new JPanel(new MigLayout());
    panel.add(firstNameLabel);
    panel.add(firstNameTextField);
    panel.add(lastNameLabel,       "gap unrelated");
    panel.add(lastNameTextField,   "wrap");
    panel.add(addressLabel);
    panel.add(addressTextField,    "span, grow");


is there any way to switch WB into DSL mode (method chaining):
http://en.wikipedia.org/wiki/Domain-specific_language:

Code: Select all
panel.add(comp, new CC().grow().width("20px")) // Component constraint
Andrei.Pozolotin
 
Posts: 55
Joined: Wed Sep 22, 2010 5:35 am

Re: MiGLayout DSL mode

Postby Andrei.Pozolotin » Tue Oct 12, 2010 9:10 am

when I try to run the form below in WB, I am not able to select some components;
such as new JLabel("General"); am I missing something obvious again?

Code: Select all
package test;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

import net.miginfocom.swing.MigLayout;

public class TestFrameMig2 extends JFrame {

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    TestFrameMig2 frame = new TestFrameMig2();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    private JPanel p;

    public TestFrameMig2() {
        initGUI();
    }

    private void initGUI() {

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);

        p = new JPanel(new MigLayout("", "[right]"));
        p.setBorder(new EmptyBorder(5, 5, 5, 5));

        p.add(new JLabel("General"), "split, span, gaptop 10");
        p.add(new JSeparator(), "growx, wrap, gaptop 10");

        p.add(new JLabel("Company"), "gap 10");
        p.add(new JTextField(""), "span, growx");
        p.add(new JLabel("Contact"), "gap 10");
        p.add(new JTextField(""), "span, growx, wrap");

        p.add(new JLabel("Propeller"), "split, span, gaptop 10");
        p.add(new JSeparator(), "growx, wrap, gaptop 10");

        p.add(new JLabel("PTI/kW"), "gap 10");
        p.add(new JTextField(10), "");
        p.add(new JLabel("Power/kW"), "gap 10");
        p.add(new JTextField(10), "wrap");
        p.add(new JLabel("R/mm"), "gap 10");
        p.add(new JTextField(10), "wrap");
        p.add(new JLabel("D/mm"), "gap 10");
        p.add(new JTextField(10));

        add(p);

    }

}
Andrei.Pozolotin
 
Posts: 55
Joined: Wed Sep 22, 2010 5:35 am

Re: MiGLayout DSL mode

Postby Andrei.Pozolotin » Tue Oct 12, 2010 9:44 am

trying to add anything to the form above kills the layout;
it seems WB is OK only with some subset of MIG layout keywords?
Andrei.Pozolotin
 
Posts: 55
Joined: Wed Sep 22, 2010 5:35 am

Re: MiGLayout DSL mode

Postby Andrei.Pozolotin » Tue Oct 12, 2010 11:35 am

Eric:

thanks for moving this into separate thread;

I basically tried to edit in WB several examples that come with MIG:
http://www.migcalendar.com/miglayout/swingdemoapp.jnlp

so far WB breaks them all;

Andrei
Andrei.Pozolotin
 
Posts: 55
Joined: Wed Sep 22, 2010 5:35 am

Re: MiGLayout DSL mode

Postby Eric Clayberg » Thu Oct 14, 2010 6:15 pm

Give this a try using the latest WindowBuilder build...

http://code.google.com/webtoolkit/tools ... -beta.html

Andrei.Pozolotin wrote:by default, MIG support in WB uses "text language";
is there any way to switch WB into DSL mode (method chaining)

WB should be able to parse and render code using DSL mode, but it will only generate code using MiG text/cell mode.

Andrei.Pozolotin wrote:when I try to run the form below in WB, I am not able to select some components;
such as new JLabel("General"); am I missing something obvious again?

This was caused by a bug in MiGLayout triggered by using the "span" keyword.

We have added a work around in the latest build that will allow all of these components to be selectable.

Andrei.Pozolotin wrote:trying to add anything to the form above kills the layout;
it seems WB is OK only with some subset of MIG layout keywords?

This was caused by the same MiG bug described above and should be addressed by the same work around.

Andrei.Pozolotin wrote:I basically tried to edit in WB several examples that come with MIG:
http://www.migcalendar.com/miglayout/swingdemoapp.jnlp
so far WB breaks them all;

Try them again. Any that were broken because of the bug with "span" should now work.
Eric Clayberg
Software Engineering Manager
Google
http://code.google.com/webtoolkit/download.html

Author: "Eclipse Plug-ins"
http://www.qualityeclipse.com
Eric Clayberg
Moderator
 
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA


Return to Swing Designer

Who is online

Users browsing this forum: No registered users and 1 guest

cron