use of net.miginfocom.layout.CC in project Terasology by MovingBlocks.
the class MigLayout method addWidget.
@Override
public void addWidget(UIWidget element, CCHint hint) {
final ComponentWrapper cw = getWrapper(element);
final String cStr = ConstraintParser.prepare(hint != null ? hint.cc : "");
CC constraint = AccessController.doPrivileged((PrivilegedAction<CC>) () -> ConstraintParser.parseComponentConstraint(cStr));
ccMap.put(cw, constraint);
wrappers.put(element, cw);
children.add(cw);
dirty = true;
}
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;
}
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();
}
use of net.miginfocom.layout.CC in project cuba by cuba-platform.
the class MigBoxLayoutAdapter method getCaptionConstraints.
@Override
public Object getCaptionConstraints(com.haulmont.cuba.gui.components.Component component) {
CC cc = new CC();
cc.split(2);
cc.width("min!");
cc.height("min!");
MigLayoutHelper.applyAlignment(cc, component.getAlignment());
return cc;
}
use of net.miginfocom.layout.CC in project cuba by cuba-platform.
the class MigLayoutHelper method getConstraints.
public static CC getConstraints(Component component) {
boolean expandX = false;
boolean expandY = false;
// for latter comparing with AutoExpanding
if (component instanceof AbstractFrame) {
component = (Component) ((AbstractFrame) component).getComponent();
}
if (component instanceof AutoExpanding) {
expandX = ((AutoExpanding) component).expandsWidth();
expandY = ((AutoExpanding) component).expandsHeight();
}
int width = (int) component.getWidth();
SizeUnit widthUnits = component.getWidthSizeUnit();
int height = (int) component.getHeight();
SizeUnit heightUnits = component.getHeightSizeUnit();
CC cc = new CC();
applyWidth(cc, width, widthUnits, expandX);
applyHeight(cc, height, heightUnits, expandY);
applyAlignment(cc, component.getAlignment());
return cc;
}
Aggregations