Search in sources :

Example 1 with LayoutManager

use of java.awt.LayoutManager in project intellij-community by JetBrains.

the class RadCardLayoutManager method addSnapshotComponent.

@SuppressWarnings({ "UseOfObsoleteCollectionType" })
@Override
public void addSnapshotComponent(final JComponent parent, final JComponent child, final RadContainer container, final RadComponent component) {
    // unfortunately card can be extracted only through reflection
    String cardName = null;
    try {
        final LayoutManager layout = parent.getLayout();
        Field vectorField = layout.getClass().getDeclaredField("vector");
        vectorField.setAccessible(true);
        Vector vector = (Vector) vectorField.get(parent.getLayout());
        for (Object card : vector) {
            Field nameField = card.getClass().getDeclaredField("name");
            nameField.setAccessible(true);
            Field compField = card.getClass().getDeclaredField("comp");
            compField.setAccessible(true);
            if (compField.get(card) == child) {
                cardName = (String) nameField.get(card);
                break;
            }
        }
    } catch (Exception e) {
    // ignore
    }
    if (cardName != null) {
        component.setCustomLayoutConstraints(cardName);
        container.addComponent(component);
    }
}
Also used : Field(java.lang.reflect.Field) LayoutManager(java.awt.LayoutManager) ComponentDragObject(com.intellij.uiDesigner.designSurface.ComponentDragObject) Vector(java.util.Vector) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 2 with LayoutManager

use of java.awt.LayoutManager in project intellij-community by JetBrains.

the class GridDropLocation method dropIntoGrid.

protected static void dropIntoGrid(final RadContainer container, final RadComponent[] components, int row, int column, final ComponentDragObject dragObject) {
    assert components.length > 0;
    for (int i = 0; i < components.length; i++) {
        RadComponent c = components[i];
        if (c instanceof RadContainer) {
            final LayoutManager layout = ((RadContainer) c).getLayout();
            if (layout instanceof XYLayoutManager) {
                ((XYLayoutManager) layout).setPreferredSize(c.getSize());
            }
        }
        int relativeCol = dragObject.getRelativeCol(i);
        int relativeRow = dragObject.getRelativeRow(i);
        LOG.debug("dropIntoGrid: relativeRow=" + relativeRow + ", relativeCol=" + relativeCol);
        int colSpan = dragObject.getColSpan(i);
        int rowSpan = dragObject.getRowSpan(i);
        assert row + relativeRow >= 0;
        assert column + relativeCol >= 0;
        if (rowSpan > 1 || colSpan > 1) {
            if ((row + relativeRow + rowSpan > container.getGridRowCount() && rowSpan > 1) || (column + relativeCol + colSpan > container.getGridColumnCount() && colSpan > 1) || container.findComponentInRect(row + relativeRow, column + relativeCol, rowSpan, colSpan) != null) {
                rowSpan = 1;
                colSpan = 1;
            }
        }
        if (!container.getGridLayoutManager().isGridDefinedByComponents()) {
            assert relativeRow + rowSpan <= container.getGridRowCount();
            assert relativeCol + colSpan <= container.getGridColumnCount();
        }
        RadComponent old = container.findComponentInRect(row + relativeRow, column + relativeCol, rowSpan, colSpan);
        if (old != null) {
            LOG.error("Drop rectangle not empty: (" + (row + relativeRow) + ", " + (column + relativeCol) + ", " + rowSpan + ", " + colSpan + "), component ID=" + old.getId());
        }
        final GridConstraints constraints = c.getConstraints();
        constraints.setRow(row + relativeRow);
        constraints.setColumn(column + relativeCol);
        constraints.setRowSpan(rowSpan);
        constraints.setColSpan(colSpan);
        LOG.info("GridDropLocation.dropIntoGrid() constraints=" + constraints);
        container.addComponent(c);
        // Fill DropInfo
        c.revalidate();
    }
    container.revalidate();
    LOG.info("GridDropLocation.dropIntoGrid() done");
}
Also used : LayoutManager(java.awt.LayoutManager) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) XYLayoutManager(com.intellij.uiDesigner.shared.XYLayoutManager) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Example 3 with LayoutManager

use of java.awt.LayoutManager in project jdk8u_jdk by JetBrains.

the class JToolBar method setLayout.

public void setLayout(LayoutManager mgr) {
    LayoutManager oldMgr = getLayout();
    if (oldMgr instanceof PropertyChangeListener) {
        removePropertyChangeListener((PropertyChangeListener) oldMgr);
    }
    super.setLayout(mgr);
}
Also used : LayoutManager(java.awt.LayoutManager)

Example 4 with LayoutManager

use of java.awt.LayoutManager in project jdk8u_jdk by JetBrains.

the class MotifPopupMenuUI method getPreferredSize.

/* This has to deal with the fact that the title may be wider than
       the widest child component.
       */
public Dimension getPreferredSize(JComponent c) {
    LayoutManager layout = c.getLayout();
    Dimension d = layout.preferredLayoutSize(c);
    String title = ((JPopupMenu) c).getLabel();
    if (titleFont == null) {
        UIDefaults table = UIManager.getLookAndFeelDefaults();
        titleFont = table.getFont("PopupMenu.font");
    }
    FontMetrics fm = c.getFontMetrics(titleFont);
    int stringWidth = 0;
    if (title != null) {
        stringWidth += SwingUtilities2.stringWidth(c, fm, title);
    }
    if (d.width < stringWidth) {
        d.width = stringWidth + 8;
        Insets i = c.getInsets();
        if (i != null) {
            d.width += i.left + i.right;
        }
        if (border != null) {
            i = border.getBorderInsets(c);
            d.width += i.left + i.right;
        }
        return d;
    }
    return null;
}
Also used : Insets(java.awt.Insets) LayoutManager(java.awt.LayoutManager) FontMetrics(java.awt.FontMetrics) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 5 with LayoutManager

use of java.awt.LayoutManager in project intellij-community by JetBrains.

the class GridChangeUtilTest method test_margins_and_gaps.

public void test_margins_and_gaps() {
    final Insets margin = new Insets(11, 12, 13, 14);
    final int hGap = 15;
    final int vGap = 16;
    final RadContainer grid = createGrid(2, 3, margin, hGap, vGap);
    {
        final LayoutManager oldLayout = grid.getLayout();
        GridChangeUtil.insertRowOrColumn(grid, 1, false, false);
        final GridLayoutManager newLayout = (GridLayoutManager) grid.getLayout();
        assertGridDimensions(grid, 2, 4);
        assertTrue(oldLayout != newLayout);
        assertTrue(margin != newLayout.getMargin());
        assertEquals(margin, newLayout.getMargin());
        assertEquals(hGap, newLayout.getHGap());
        assertEquals(vGap, newLayout.getVGap());
    }
    {
        final LayoutManager oldLayout = grid.getLayout();
        GridChangeUtil.splitRow(grid, 1);
        final GridLayoutManager newLayout = (GridLayoutManager) grid.getLayout();
        assertGridDimensions(grid, 3, 4);
        assertTrue(oldLayout != newLayout);
        assertTrue(margin != newLayout.getMargin());
        assertEquals(margin, newLayout.getMargin());
        assertEquals(hGap, newLayout.getHGap());
        assertEquals(vGap, newLayout.getVGap());
    }
}
Also used : Insets(java.awt.Insets) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) LayoutManager(java.awt.LayoutManager) RadContainer(com.intellij.uiDesigner.radComponents.RadContainer)

Aggregations

LayoutManager (java.awt.LayoutManager)6 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)2 Insets (java.awt.Insets)2 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)1 ComponentDragObject (com.intellij.uiDesigner.designSurface.ComponentDragObject)1 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)1 XYLayoutManager (com.intellij.uiDesigner.shared.XYLayoutManager)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 FontMetrics (java.awt.FontMetrics)1 Point (java.awt.Point)1 Field (java.lang.reflect.Field)1 Vector (java.util.Vector)1