use of net.miginfocom.layout.LC in project cuba by cuba-platform.
the class MigBoxLayoutAdapter method updateLayoutConstraints.
private void updateLayoutConstraints(boolean resetExpanded) {
LC lc = new LC();
// Invisible components will not participate in the layout at all and it will for instance not take up a grid cell
lc.hideMode(2);
// always give all space to components, otherwise align doesn't work
lc.fill();
AC rowConstr = new AC();
AC colConstr = new AC();
if (direction.equals(FlowDirection.X)) {
rowConstr.align("top");
lc.flowX();
if (expandedComponent != null || resetExpanded) {
adjustExpanding(lc, colConstr);
}
} else {
lc.flowY();
if (expandedComponent != null || resetExpanded) {
adjustExpanding(lc, rowConstr);
}
}
lc.setInsets(MigLayoutHelper.makeInsets(margins));
if (!spacing) {
if (direction.equals(FlowDirection.X)) {
lc.gridGapX("0");
} else {
lc.gridGapY("0");
}
}
if (isDebug())
lc.debug(1000);
layout.setLayoutConstraints(lc);
layout.setRowConstraints(rowConstr);
layout.setColumnConstraints(colConstr);
}
use of net.miginfocom.layout.LC in project cuba by cuba-platform.
the class DesktopWindowManager method showOptionDialog.
protected void showOptionDialog(final String title, final String message, @Nullable MessageType messageType, final Icon icon, boolean alwaysModal, final Action[] actions, String debugName) {
final DialogWindow dialog = new DialogWindow(frame, title);
if (App.getInstance().isTestMode()) {
dialog.setName(debugName);
}
dialog.setModal(false);
if (actions.length > 1) {
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
}
int width = 500;
SizeUnit unit = null;
if (messageType != null && messageType.getWidth() != null) {
width = messageType.getWidth().intValue();
unit = messageType.getWidthUnit();
}
LC lc = new LC();
lc.insets("10");
MigLayout layout = new MigLayout(lc);
final JPanel panel = new JPanel(layout);
if (icon != null) {
JLabel iconLabel = new JLabel(icon);
panel.add(iconLabel, "aligny top");
}
JLabel msgLabel = new JLabel(message);
if (width != AUTO_SIZE_PX) {
panel.add(msgLabel, "width 100%, wrap, growy 0");
} else {
panel.add(msgLabel, "wrap");
}
if (icon != null) {
panel.add(new JLabel(" "));
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
dialog.requestFocus();
}
});
final JPanel buttonsPanel = createButtonsPanel(actions, dialog);
panel.add(buttonsPanel, "alignx right");
if (width != AUTO_SIZE_PX) {
if (unit != null && unit != SizeUnit.PIXELS) {
throw new UnsupportedOperationException("Dialog size can be set only in pixels");
}
dialog.setLayout(new MigLayout(new LC().insets("0").width(width + "px")));
dialog.setFixedWidth(width);
dialog.add(panel, "width 100%, growy 0");
} else {
dialog.add(panel);
}
assignDialogShortcuts(dialog, panel, actions);
dialog.pack();
dialog.setResizable(false);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
panel.revalidate();
panel.repaint();
java.awt.Container container = panel.getTopLevelAncestor();
if (container instanceof JDialog) {
JDialog dialog = (JDialog) container;
dialog.pack();
}
}
});
dialog.setLocationRelativeTo(frame);
boolean modal = true;
if (!alwaysModal) {
if (!hasModalWindow()) {
if (messageType != null && messageType.getModal() != null) {
modal = messageType.getModal();
} else if (dialogParams.getModal() != null) {
modal = dialogParams.getModal();
}
}
} else {
if (messageType != null && messageType.getModal() != null) {
log.warn("MessageType.modal is not supported for showOptionDialog");
}
}
if (modal) {
DialogWindow lastDialogWindow = getLastDialogWindow();
if (lastDialogWindow == null) {
frame.deactivate(null);
} else {
lastDialogWindow.disableWindow(null);
}
}
dialog.setVisible(true);
}
use of net.miginfocom.layout.LC in project cuba by cuba-platform.
the class VclTestApp method createAlignTab.
private Component createAlignTab() {
JPanel box = new JPanel();
box.setFocusable(false);
MigLayout boxLayout = new MigLayout("debug 1000, fill");
box.setLayout(boxLayout);
JPanel panel = new JPanel();
MigLayout layout = new MigLayout("debug 1000, fill");
panel.setLayout(layout);
JLabel label = new JLabel("Label");
CC cc = new CC();
cc.alignX("right").alignY("50%");
panel.add(label);
layout.setComponentConstraints(label, cc);
LC lc = new LC();
// The size of an invisible component will be set to 0, 0 and the gaps will also be set to 0 around it.
lc.hideMode(2);
lc.debug(1000);
AC rowConstr = new AC();
AC colConstr = new AC();
lc.fillX();
lc.flowY();
lc.gridGapY("0");
layout.setLayoutConstraints(lc);
layout.setRowConstraints(rowConstr);
layout.setColumnConstraints(colConstr);
box.add(panel, "height 100px, width 100px");
layout.setComponentConstraints(label, cc);
return box;
}
use of net.miginfocom.layout.LC in project cuba by cuba-platform.
the class MigGridLayoutAdapter method update.
@Override
protected void update() {
LC lc = new LC();
lc.setWrapAfter(getColumns());
// The size of an invisible component will be set to 0, 0 and the gaps will also be set to 0 around it.
lc.hideMode(2);
lc.fill();
lc.setInsets(MigLayoutHelper.makeInsets(margins));
if (!spacing) {
lc.gridGap("0", "0");
}
if (isDebug())
lc.debug(1000);
layout.setLayoutConstraints(lc);
AC rowConstr = new AC();
// left-top align by default
rowConstr.align("top");
layout.setRowConstraints(rowConstr);
AC colConstr = new AC();
for (int i = 0; i < colCount; i++) {
float ratio = columnRatio[i];
colConstr.grow(ratio, i);
colConstr.shrink(ratio != 0 ? (float) Math.sqrt(1.0f / ratio) : 100.0f, i);
}
layout.setColumnConstraints(colConstr);
}