package ch.openech.mj.swing.toolkit;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.event.ActionEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;
import ch.openech.mj.toolkit.FlowField;
import ch.openech.mj.util.StringUtils;


public class SwingFlowField extends JPanel implements FlowField {
	private JLabel lastLabel;
	
	public SwingFlowField() {
		super(new MigLayout("ins 4 1 0 0, gap 0 0, wrap 1"));
	}
	
	@Override
	public void setEnabled(boolean enabled) {
		super.setEnabled(enabled);
	}

	@Override
	public void addAction(Action action) {
		lastLabel = createLinkButton(action);
		add(lastLabel);
	}
	
	static JLabel createLinkButton(final Action action) {
		final JLabel label = new JLabel();
		label.setIcon((Icon) action.getValue(Action.SMALL_ICON));
		label.setText((String) action.getValue(Action.NAME));
		label.setToolTipText((String) action.getValue(Action.SHORT_DESCRIPTION));
		label.setForeground(Color.BLUE);
		label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
		label.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				action.actionPerformed(new ActionEvent(label, 0, null));
			}
		});
        return label;
	}

	@Override
	public void clear() {
		removeAll();
		revalidate();
	}

	@Override
	public void addObject(Object object) {
		if (object != null) {
			lastLabel = new JLabel(object.toString());
			add(lastLabel);
		}
		revalidate();
	}

	@Override
	public void addHtml(String html) {
		if (!StringUtils.isBlank(html)) {
			lastLabel = new JLabel(html);
			add(lastLabel);
		}
		revalidate();
	}

	@Override
	public void addGap() {
		if (lastLabel != null) {
			lastLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 8, 0));
		}
	}
	
}

@@ -855,24 +855,55 @@
 astLabel);%0D%0A
+%09%09repaint();%0D%0A%09%09revalidate();%0D%0A
 %09%7D%0D%0A%09%0D%0A%09stat
@@ -1548,24 +1548,38 @@
 moveAll();%0D%0A
+%09%09repaint();%0D%0A
 %09%09revalidate
@@ -1575,32 +1575,32 @@
 %09revalidate();%0D%0A
-
 %09%7D%0D%0A%0D%0A%09@Override
@@ -1731,32 +1731,46 @@
 stLabel);%0D%0A%09%09%7D%0D%0A
+%09%09repaint();%0D%0A
 %09%09revalidate();%0D
@@ -1912,29 +1912,43 @@
 astLabel);%0D%0A
-
 %09%09%7D%0D%0A
+%09%09repaint();%0D%0A
 %09%09revalidate

Update on added action