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