use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class NoLabelForInspection method checkComponentProperties.
@Override
protected void checkComponentProperties(final Module module, final IComponent component, FormErrorCollector collector) {
ComponentItem item = Palette.getInstance(module.getProject()).getItem(component.getComponentClassName());
if (item != null && item.isCanAttachLabel()) {
IComponent root = component;
while (root.getParentContainer() != null) {
root = root.getParentContainer();
}
final Ref<Boolean> found = new Ref<>(Boolean.FALSE);
final Ref<RadComponent> candidateLabel = new Ref<>();
final List<RadComponent> allLabels = new ArrayList<>();
FormEditingUtil.iterate(root, new FormEditingUtil.ComponentVisitor() {
@Override
public boolean visit(final IComponent c2) {
if (FormInspectionUtil.isComponentClass(module, c2, JLabel.class)) {
IProperty prop = FormInspectionUtil.findProperty(c2, SwingProperties.LABEL_FOR);
if (prop != null && component.getId().equals(prop.getPropertyValue(c2))) {
found.set(Boolean.TRUE);
return false;
} else if (component instanceof RadComponent && (prop == null || StringUtil.isEmpty((String) prop.getPropertyValue(c2)))) {
RadComponent radComponent = (RadComponent) component;
final RadComponent radComponent2 = (RadComponent) c2;
allLabels.add(radComponent2);
if (radComponent.getParent() == radComponent2.getParent() && radComponent.getParent().getLayoutManager().isGrid()) {
GridConstraints gc1 = radComponent.getConstraints();
GridConstraints gc2 = radComponent2.getConstraints();
int nextColumn = FormEditingUtil.nextCol(radComponent.getParent(), gc2.getColumn());
int nextRow = FormEditingUtil.nextRow(radComponent.getParent(), gc2.getRow());
if (gc1.getRow() == gc2.getRow() && nextColumn == gc1.getColumn() || gc1.getColumn() == gc2.getColumn() && nextRow == gc1.getRow()) {
candidateLabel.set(radComponent2);
}
}
}
}
return true;
}
});
if (!found.get().booleanValue()) {
if (!candidateLabel.isNull()) {
allLabels.clear();
allLabels.add(candidateLabel.get());
}
EditorQuickFixProvider[] quickFixProviders = new EditorQuickFixProvider[allLabels.size()];
for (int i = 0; i < quickFixProviders.length; i++) {
final RadComponent label = allLabels.get(i);
quickFixProviders[i] = new EditorQuickFixProvider() {
@Override
public QuickFix createQuickFix(GuiEditor editor, RadComponent component) {
return new MyQuickFix(editor, component, label);
}
};
}
collector.addError(getID(), component, null, UIDesignerBundle.message("inspection.no.label.for.error"), quickFixProviders);
}
}
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GridReplaceDropLocation method processDrop.
@Override
public void processDrop(final GuiEditor editor, final RadComponent[] components, final GridConstraints[] constraintsToAdjust, final ComponentDragObject dragObject) {
RadComponent c = myContainer.getComponentAtGrid(myRow, myColumn);
if (c != null) {
FormEditingUtil.deleteComponents(Collections.singletonList(c), false);
}
super.processDrop(editor, components, constraintsToAdjust, dragObject);
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GroupSelectionProcessor method processMouseEvent.
protected void processMouseEvent(final MouseEvent e) {
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
myStartPoint = e.getPoint();
myEditor.getDragLayer().add(myRectangePainter);
} else if (e.getID() == MouseEvent.MOUSE_DRAGGED) {
final Rectangle rectangle = getRectangle(e);
myRectangePainter.setBounds(rectangle);
myEditor.getDragLayer().repaint();
} else if (e.getID() == MouseEvent.MOUSE_RELEASED) {
final Rectangle rectangle = getRectangle(e);
if (e.isShiftDown() && rectangle.width <= 3 && rectangle.height <= 3) {
RadComponent component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
if (component != null) {
RadComponent anchor = myEditor.getSelectionAnchor();
if (anchor == null || anchor.getParent() != component.getParent() || anchor.getParent() == null || !anchor.getParent().getLayoutManager().isGrid()) {
component.setSelected(!component.isSelected());
} else {
selectComponentsInRange(component, anchor);
myEditor.setSelectionLead(component);
}
}
}
markRectangle(myEditor.getRootContainer(), rectangle, e.getComponent());
final JComponent dragLayer = myEditor.getDragLayer();
dragLayer.remove(myRectangePainter);
dragLayer.repaint();
myStartPoint = null;
}
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GroupSelectionProcessor method markRectangle.
private void markRectangle(final RadComponent component, final Rectangle rectangle, final Component coordinateOriginComponent) {
if (!(component instanceof RadRootContainer) && !component.equals(myComponent)) {
final Rectangle bounds = component.getBounds();
final Point point = SwingUtilities.convertPoint(component.getDelegee().getParent(), bounds.x, bounds.y, coordinateOriginComponent);
bounds.setLocation(point);
if (rectangle.intersects(bounds)) {
component.setSelected(true);
return;
}
}
if (component instanceof RadContainer) {
final RadContainer container = (RadContainer) component;
// [anton] it is very important to iterate through a STORED array because setSelected can
// change order of components so iteration via getComponent(i) is incorrect
final RadComponent[] components = container.getComponents();
for (RadComponent component1 : components) {
markRectangle(component1, rectangle, coordinateOriginComponent);
}
}
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class GroupSelectionProcessor method selectComponentsInRange.
private static void selectComponentsInRange(final RadComponent component, final RadComponent anchor) {
final GridConstraints c1 = component.getConstraints();
final GridConstraints c2 = anchor.getConstraints();
int startRow = Math.min(c1.getRow(), c2.getRow());
int startCol = Math.min(c1.getColumn(), c2.getColumn());
int endRow = Math.max(c1.getRow() + c1.getRowSpan(), c2.getRow() + c2.getRowSpan());
int endCol = Math.max(c1.getColumn() + c1.getColSpan(), c2.getColumn() + c2.getColSpan());
for (int row = startRow; row < endRow; row++) {
for (int col = startCol; col < endCol; col++) {
RadComponent c = anchor.getParent().getComponentAtGrid(row, col);
if (c != null) {
c.setSelected(true);
}
}
}
}
Aggregations