Search in sources :

Example 6 with CC

use of net.miginfocom.layout.CC in project cuba by cuba-platform.

the class DesktopWindow method updateComponent.

@Override
public void updateComponent(Component child) {
    boolean componentReAdded = false;
    if (DesktopContainerHelper.mayHaveExternalCaption(child) || DesktopContainerHelper.mayHaveExternalContextHelp(child)) {
        if (captions.containsKey(child) && !DesktopContainerHelper.hasExternalCaption(child) && !DesktopContainerHelper.hasExternalContextHelp(child)) {
            reAddChild(child);
            componentReAdded = true;
        } else if (!captions.containsKey(child) && (DesktopContainerHelper.hasExternalCaption(child) || DesktopContainerHelper.hasExternalContextHelp(child))) {
            reAddChild(child);
            componentReAdded = true;
        } else if (captions.containsKey(child)) {
            ComponentCaption caption = captions.get(child);
            caption.update();
            BoxLayoutAdapter adapterForCaption = layoutAdapter;
            if (wrappers.containsKey(child)) {
                adapterForCaption = wrappers.get(child).getSecond();
            }
            adapterForCaption.updateConstraints(caption, adapterForCaption.getCaptionConstraints(child));
        }
    }
    if (!componentReAdded) {
        JComponent composition;
        if (wrappers.containsKey(child)) {
            composition = wrappers.get(child).getFirst();
            CC constraints = MigLayoutHelper.getConstraints(child);
            if (child.getHeight() == -1.0) {
                MigLayoutHelper.applyHeight(constraints, -1, UNITS_PIXELS, false);
            } else {
                MigLayoutHelper.applyHeight(constraints, 100, UNITS_PERCENTAGE, false);
            }
            if (child.getWidth() == -1.0) {
                MigLayoutHelper.applyWidth(constraints, -1, UNITS_PIXELS, false);
            } else {
                MigLayoutHelper.applyWidth(constraints, 100, UNITS_PERCENTAGE, false);
            }
            BoxLayoutAdapter adapter = wrappers.get(child).getSecond();
            adapter.updateConstraints(DesktopComponentsHelper.getComposition(child), constraints);
        } else {
            composition = DesktopComponentsHelper.getComposition(child);
        }
        layoutAdapter.updateConstraints(composition, layoutAdapter.getConstraints(child));
    }
    requestRepaint();
}
Also used : CC(net.miginfocom.layout.CC) BoxLayoutAdapter(com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter)

Example 7 with CC

use of net.miginfocom.layout.CC in project cuba by cuba-platform.

the class DesktopFieldGroup method getCellComponent.

public DesktopAbstractComponent getCellComponent(int colIndex, int rowIndex) {
    if (colIndex < 0 || colIndex >= getColumns()) {
        throw new IllegalArgumentException(String.format("Illegal column number %s, available amount of columns is %s", colIndex, getColumns()));
    }
    List<FieldConfig> colFields = columnFieldMapping.get(colIndex);
    if (rowIndex < 0 || rowIndex > colFields.size()) {
        throw new IllegalArgumentException(String.format("Illegal column number %s, available amount of columns is %s", colIndex, getColumns()));
    }
    for (FieldConfig fieldConfig : fields.values()) {
        DesktopAbstractComponent composition = ((FieldConfigImpl) fieldConfig).getComposition();
        if (composition != null) {
            JComponent jComponent = composition.getComposition();
            Object componentConstraints = layout.getComponentConstraints(jComponent);
            if (componentConstraints instanceof CC) {
                CC cc = (CC) componentConstraints;
                if (cc.getCellY() == rowIndex) {
                    int ccColIndex = (cc.getCellX() - 1) / 3;
                    if (colIndex == ccColIndex) {
                        return composition;
                    }
                }
            }
        }
    }
    return null;
}
Also used : CC(net.miginfocom.layout.CC)

Example 8 with CC

use of net.miginfocom.layout.CC in project cuba by cuba-platform.

the class DesktopGridLayout method reAddChild.

protected void reAddChild(Component child) {
    CC childCC = (CC) layoutAdapter.getConstraints(child);
    int col1 = childCC.getCellX();
    int row1 = childCC.getCellY();
    int spanX = childCC.getSpanX();
    int spanY = childCC.getSpanY();
    // readd component
    int col2 = spanX - 1 + col1;
    int row2 = spanY - 1 + row1;
    remove(child);
    add(child, col1, row1, col2, row2);
}
Also used : CC(net.miginfocom.layout.CC)

Example 9 with CC

use of net.miginfocom.layout.CC in project cuba by cuba-platform.

the class DesktopGridLayout method add.

@Override
public void add(Component component, int col, int row, int col2, int row2) {
    if (component.getParent() != null && component.getParent() != this) {
        throw new IllegalStateException("Component already has parent");
    }
    final JComponent composition = DesktopComponentsHelper.getComposition(component);
    boolean hasExternalCaption = DesktopContainerHelper.hasExternalCaption(component);
    if (hasExternalCaption || DesktopContainerHelper.hasExternalContextHelp(component)) {
        ComponentCaption caption = new ComponentCaption(component);
        captions.put(component, caption);
        JPanel wrapper = new LayoutSlot();
        BoxLayoutAdapter adapter = BoxLayoutAdapter.create(wrapper);
        adapter.setExpandLayout(true);
        adapter.setSpacing(false);
        adapter.setMargin(false);
        wrapper.add(composition);
        if (hasExternalCaption) {
            adapter.setFlowDirection(BoxLayoutAdapter.FlowDirection.Y);
            wrapper.add(caption, 0);
        } else {
            wrapper.add(caption, new CC().alignY("top"));
        }
        impl.add(wrapper, layoutAdapter.getConstraints(component, col, row, col2, row2));
        wrappers.put(component, new Pair<>(wrapper, adapter));
    } else {
        impl.add(composition, layoutAdapter.getConstraints(component, col, row, col2, row2));
    }
    if (component.getId() != null) {
        componentByIds.put(component.getId(), component);
    }
    if (frame != null) {
        if (component instanceof BelongToFrame && ((BelongToFrame) component).getFrame() == null) {
            ((BelongToFrame) component).setFrame(frame);
        } else {
            frame.registerComponent(component);
        }
    }
    ownComponents.add(component);
    DesktopContainerHelper.assignContainer(component, this);
    if (component instanceof DesktopAbstractComponent && !isEnabledWithParent()) {
        ((DesktopAbstractComponent) component).setParentEnabled(false);
    }
    component.setParent(this);
    requestRepaint();
}
Also used : CC(net.miginfocom.layout.CC) BoxLayoutAdapter(com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter)

Example 10 with CC

use of net.miginfocom.layout.CC in project cuba by cuba-platform.

the class DesktopAbstractBox method add.

@Override
public void add(Component component, int index) {
    if (component.getParent() != null && component.getParent() != this) {
        throw new IllegalStateException("Component already has parent");
    }
    if (ownComponents.contains(component)) {
        int existingIndex = new ArrayList<>(ownComponents).indexOf(component);
        if (index > existingIndex) {
            index--;
        }
        remove(component);
    }
    JComponent composition = DesktopComponentsHelper.getComposition(component);
    boolean hasExternalCaption = DesktopContainerHelper.hasExternalCaption(component);
    if (hasExternalCaption || DesktopContainerHelper.hasExternalContextHelp(component)) {
        ComponentCaption caption = new ComponentCaption(component);
        captions.put(component, caption);
        JPanel wrapper = new LayoutSlot();
        BoxLayoutAdapter adapter = BoxLayoutAdapter.create(wrapper);
        adapter.setExpandLayout(true);
        adapter.setSpacing(false);
        adapter.setMargin(false);
        wrapper.add(composition);
        if (hasExternalCaption) {
            adapter.setFlowDirection(BoxLayoutAdapter.FlowDirection.Y);
            wrapper.add(caption, 0);
        } else {
            wrapper.add(caption, new CC().alignY("top"));
        }
        impl.add(wrapper, layoutAdapter.getConstraints(component), index);
        wrappers.put(component, new Pair<>(wrapper, adapter));
    } else {
        impl.add(composition, layoutAdapter.getConstraints(component), index);
    }
    if (component.getId() != null) {
        componentByIds.put(component.getId(), component);
    }
    if (frame != null) {
        if (component instanceof BelongToFrame && ((BelongToFrame) component).getFrame() == null) {
            ((BelongToFrame) component).setFrame(frame);
        } else {
            attachToFrame(component);
        }
    }
    if (index == ownComponents.size()) {
        ownComponents.add(component);
    } else {
        List<Component> componentsTempList = new ArrayList<>(ownComponents);
        componentsTempList.add(index, component);
        ownComponents.clear();
        ownComponents.addAll(componentsTempList);
    }
    DesktopContainerHelper.assignContainer(component, this);
    if (component instanceof DesktopAbstractComponent && !isEnabledWithParent()) {
        ((DesktopAbstractComponent) component).setParentEnabled(false);
    }
    component.setParent(this);
    requestContainerUpdate();
    requestRepaint();
}
Also used : CC(net.miginfocom.layout.CC) BoxLayoutAdapter(com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter) Component(com.haulmont.cuba.gui.components.Component)

Aggregations

CC (net.miginfocom.layout.CC)18 BoxLayoutAdapter (com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter)6 Component (com.haulmont.cuba.gui.components.Component)3 MigLayout (net.miginfocom.swing.MigLayout)3 LC (net.miginfocom.layout.LC)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Preconditions.checkNotNullArgument (com.haulmont.bali.util.Preconditions.checkNotNullArgument)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 AppBeans (com.haulmont.cuba.core.global.AppBeans)1 App (com.haulmont.cuba.desktop.App)1 AutoExpanding (com.haulmont.cuba.desktop.gui.components.AutoExpanding)1 LayoutSlot (com.haulmont.cuba.desktop.gui.components.LayoutSlot)1 DesktopToolTipManager (com.haulmont.cuba.desktop.sys.DesktopToolTipManager)1 LayoutAdapter (com.haulmont.cuba.desktop.sys.layout.LayoutAdapter)1 MigLayoutHelper (com.haulmont.cuba.desktop.sys.layout.MigLayoutHelper)1 CollapsiblePanel (com.haulmont.cuba.desktop.sys.vcl.CollapsiblePanel)1 ToolTipButton (com.haulmont.cuba.desktop.sys.vcl.ToolTipButton)1 ComponentsHelper (com.haulmont.cuba.gui.ComponentsHelper)1 UiPermissionDescriptor (com.haulmont.cuba.gui.app.security.role.edit.UiPermissionDescriptor)1