use of com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter in project cuba by cuba-platform.
the class DesktopWindow 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 JPanel();
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"));
}
getContainer().add(wrapper, layoutAdapter.getConstraints(component), index);
wrappers.put(component, new Pair<>(wrapper, adapter));
} else {
getContainer().add(composition, layoutAdapter.getConstraints(component), index);
}
if (component.getId() != null) {
componentByIds.put(component.getId(), component);
}
if (component instanceof BelongToFrame && ((BelongToFrame) component).getFrame() == null) {
((BelongToFrame) component).setFrame(this);
} else {
registerComponent(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 && !isEnabled()) {
((DesktopAbstractComponent) component).setParentEnabled(false);
}
component.setParent(this);
requestRepaint();
}
use of com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter 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 com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter in project cuba by cuba-platform.
the class DesktopDateField method initComponentParts.
protected void initComponentParts() {
BoxLayoutAdapter adapter = new MigBoxLayoutAdapter(impl);
adapter.setSpacing(false);
adapter.setFlowDirection(BoxLayoutAdapter.FlowDirection.X);
adapter.setExpandLayout(true);
impl.setLayout(adapter.getLayout());
datePicker = new FlushableDatePicker();
Dimension size = getDefaultDimension();
datePicker.setPreferredSize(size);
datePicker.setMinimumSize(size);
timeField = new DesktopTimeField();
timeField.addValueChangeListener(e -> {
if (!checkRange(constructDate())) {
return;
}
if (!updateTimeFieldResolution) {
updateInstance();
}
});
datePicker.addPropertyChangeListener(evt -> {
if ("date".equals(evt.getPropertyName())) {
if (!checkRange(constructDate())) {
return;
}
updateInstance();
updateMissingValueState();
}
});
}
use of com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter 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 com.haulmont.cuba.desktop.sys.layout.BoxLayoutAdapter 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