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();
}
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 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);
}
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();
}
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();
}
Aggregations