Search in sources :

Example 1 with RadAtomicComponent

use of com.intellij.uiDesigner.radComponents.RadAtomicComponent in project intellij-community by JetBrains.

the class AbstractMoveSelectionAction method actionPerformed.

public final void actionPerformed(final AnActionEvent e) {
    final ArrayList<RadComponent> selectedComponents = FormEditingUtil.getSelectedComponents(myEditor);
    final JComponent rootContainerDelegee = myEditor.getRootContainer().getDelegee();
    if (selectedComponents.size() == 0) {
        moveToFirstComponent(rootContainerDelegee);
        return;
    }
    RadComponent selectedComponent = myEditor.getSelectionLead();
    if (selectedComponent == null || !selectedComponents.contains(selectedComponent)) {
        selectedComponent = selectedComponents.get(0);
    }
    if (moveSelectionByGrid(selectedComponent) || myMoveToLast) {
        return;
    }
    // 1. We need to get coordinates of all editor's component in the same
    // coordinate system. For example, in the RadRootContainer rootContainerDelegee's coordinate system.
    final ArrayList<RadComponent> components = new ArrayList<>();
    final ArrayList<Point> points = new ArrayList<>();
    final RadComponent selectedComponent1 = selectedComponent;
    FormEditingUtil.iterate(myEditor.getRootContainer(), new FormEditingUtil.ComponentVisitor<RadComponent>() {

        public boolean visit(final RadComponent component) {
            if (component instanceof RadAtomicComponent) {
                if (selectedComponent1.equals(component)) {
                    return true;
                }
                if (!FormEditingUtil.isComponentSwitchedInView(component)) {
                    return true;
                }
                components.add(component);
                final JComponent _delegee = component.getDelegee();
                final Point p = SwingUtilities.convertPoint(_delegee, new Point(0, 0), rootContainerDelegee);
                p.x += _delegee.getWidth() / 2;
                p.y += _delegee.getHeight() / 2;
                points.add(p);
            }
            return true;
        }
    });
    if (components.size() == 0) {
        return;
    }
    // 2.
    final Point source = SwingUtilities.convertPoint(selectedComponent.getDelegee(), new Point(0, 0), rootContainerDelegee);
    source.x += selectedComponent.getDelegee().getWidth() / 2;
    source.y += selectedComponent.getDelegee().getHeight() / 2;
    int min = Integer.MAX_VALUE;
    int nextSelectedIndex = -1;
    for (int i = points.size() - 1; i >= 0; i--) {
        final int distance = calcDistance(source, points.get(i));
        if (distance < min) {
            min = distance;
            nextSelectedIndex = i;
        }
    }
    if (min == Integer.MAX_VALUE) {
        return;
    }
    LOG.assertTrue(nextSelectedIndex != -1);
    final RadComponent component = components.get(nextSelectedIndex);
    selectOrExtend(component);
}
Also used : RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) ArrayList(java.util.ArrayList) FormEditingUtil(com.intellij.uiDesigner.FormEditingUtil) RadAtomicComponent(com.intellij.uiDesigner.radComponents.RadAtomicComponent)

Example 2 with RadAtomicComponent

use of com.intellij.uiDesigner.radComponents.RadAtomicComponent in project intellij-community by JetBrains.

the class ComponentItem method getInitialSize.

@NotNull
public Dimension getInitialSize(final JComponent parent, final ClassLoader loader) {
    if (myInitialSize != null) {
        return myInitialSize;
    }
    myInitialSize = new Dimension(myDefaultConstraints.myPreferredSize);
    if (myInitialSize.width <= 0 || myInitialSize.height <= 0) {
        try {
            Class aClass = Class.forName(getClassName(), true, loader);
            RadAtomicComponent component = new RadAtomicComponent(aClass, "", Palette.getInstance(myProject));
            component.initDefaultProperties(this);
            final JComponent delegee = component.getDelegee();
            if (parent != null) {
                final Font font = parent.getFont();
                delegee.setFont(font);
            }
            Dimension prefSize = delegee.getPreferredSize();
            Dimension minSize = delegee.getMinimumSize();
            if (myInitialSize.width <= 0) {
                myInitialSize.width = prefSize.width;
            }
            if (myInitialSize.height <= 0) {
                myInitialSize.height = prefSize.height;
            }
            myInitialSize.width = Math.max(myInitialSize.width, minSize.width);
            myInitialSize.height = Math.max(myInitialSize.height, minSize.height);
        } catch (Exception e) {
            LOG.debug(e);
        }
    }
    return myInitialSize;
}
Also used : RadAtomicComponent(com.intellij.uiDesigner.radComponents.RadAtomicComponent) IOException(java.io.IOException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RadAtomicComponent (com.intellij.uiDesigner.radComponents.RadAtomicComponent)2 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)1 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1