use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class InplaceEditingLayer method startEditing.
public void startEditing(@Nullable InplaceContext inplaceContext) {
try {
List<RadComponent> selection = myDesigner.getSurfaceArea().getSelection();
if (selection.size() != 1) {
return;
}
myRadComponent = selection.get(0);
myProperties = myRadComponent.getInplaceProperties();
if (myProperties.isEmpty()) {
myRadComponent = null;
myProperties = null;
return;
}
myInplaceComponent = new JPanel(new GridLayoutManager(myProperties.size(), 2));
myInplaceComponent.setBorder(new LineMarginBorder(5, 5, 5, 5));
new AnAction() {
@Override
public void actionPerformed(AnActionEvent e) {
finishEditing(false);
}
}.registerCustomShortcutSet(CommonShortcuts.ESCAPE, myInplaceComponent);
myEditors = new ArrayList<>();
JComponent componentToFocus = null;
Font font = null;
if (inplaceContext == null) {
inplaceContext = new InplaceContext();
}
int row = 0;
for (Property property : myProperties) {
JLabel label = new JLabel(property.getName() + ":");
if (font == null) {
font = label.getFont().deriveFont(Font.BOLD);
}
label.setFont(font);
myInplaceComponent.add(label, new GridConstraints(row, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, 0, 0, null, null, null));
PropertyEditor editor = property.getEditor();
myEditors.add(editor);
JComponent component = editor.getComponent(myRadComponent, myDesigner, property.getValue(myRadComponent), inplaceContext);
myInplaceComponent.add(component, new GridConstraints(row++, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_GROW, 0, null, null, null));
if (componentToFocus == null) {
componentToFocus = editor.getPreferredFocusedComponent();
}
}
for (PropertyEditor editor : myEditors) {
editor.addPropertyEditorListener(myEditorListener);
}
Rectangle bounds = myRadComponent.getBounds(this);
Dimension size = myInplaceComponent.getPreferredSize();
myPreferredWidth = Math.max(size.width, bounds.width);
myInplaceComponent.setBounds(bounds.x, bounds.y, myPreferredWidth, size.height);
add(myInplaceComponent);
myDesigner.getSurfaceArea().addSelectionListener(mySelectionListener);
if (componentToFocus == null) {
componentToFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(myInplaceComponent);
}
if (componentToFocus == null) {
componentToFocus = myInplaceComponent;
}
if (componentToFocus.requestFocusInWindow()) {
myFocusWatcher.install(myInplaceComponent);
} else {
grabFocus();
final JComponent finalComponentToFocus = componentToFocus;
ApplicationManager.getApplication().invokeLater(() -> {
finalComponentToFocus.requestFocusInWindow();
myFocusWatcher.install(myInplaceComponent);
});
}
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
repaint();
} catch (Throwable e) {
LOG.error(e);
}
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class PyUniversalTestForm method addCustomOptions.
private void addCustomOptions(@NotNull final CustomOption... customOptions) {
if (customOptions.length == 0) {
return;
}
final Map<String, JBTextField> optionValueFields = new HashMap<>();
for (final CustomOption option : customOptions) {
final JBTextField textField = new JBTextField();
optionValueFields.put(option.myName, textField);
}
myCustomOptionsPanel.setLayout(new GridLayoutManager(customOptions.length, 2));
for (int i = 0; i < customOptions.length; i++) {
final CustomOption option = customOptions[i];
final JBTextField textField = optionValueFields.get(option.myName);
final GridConstraints labelConstraints = new GridConstraints();
labelConstraints.setFill(GridConstraints.FILL_VERTICAL);
labelConstraints.setRow(i);
labelConstraints.setColumn(0);
labelConstraints.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_SHRINK);
final JLabel label = new JLabel(StringUtil.capitalize(CAPITAL_LETTER.matcher(option.myName).replaceAll(" ")));
label.setHorizontalAlignment(SwingConstants.LEFT);
myCustomOptionsPanel.add(label, labelConstraints);
final GridConstraints textConstraints = new GridConstraints();
textConstraints.setFill(GridConstraints.FILL_BOTH);
textConstraints.setRow(i);
textConstraints.setColumn(1);
textConstraints.setHSizePolicy(GridConstraints.SIZEPOLICY_CAN_GROW);
myCustomOptionsPanel.add(textField, textConstraints);
myCustomOptions.put(option.myName, new OptionHolder(option, label, textField));
}
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class AbstractGridLayoutProperty method setValueImpl.
protected void setValueImpl(final RadContainer component, final Boolean value) throws Exception {
final AbstractLayout layoutManager = (AbstractLayout) component.getLayout();
if (!(layoutManager instanceof GridLayoutManager)) {
throw new IllegalArgumentException("grid layout expected: " + layoutManager);
}
final GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
setGridLayoutPropertyValue(gridLayoutManager, value.booleanValue());
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class RadBoxLayoutManager method createSnapshotLayout.
@Override
public void createSnapshotLayout(final SnapshotContext context, final JComponent parent, final RadContainer container, final LayoutManager layout) {
int rowCount = 1;
int colCount = 1;
boolean hasFiller = false;
// workaround for lack of BoxLayout.getAxis()
if (parent.getComponentCount() > 1) {
for (Component component : parent.getComponents()) {
if (component instanceof Box.Filler) {
hasFiller = true;
}
}
Rectangle bounds1 = parent.getComponent(0).getBounds();
Rectangle bounds2 = parent.getComponent(1).getBounds();
if (bounds2.x >= bounds1.x + bounds1.width) {
colCount = parent.getComponentCount();
if (!hasFiller)
colCount++;
myHorizontal = true;
} else {
rowCount = parent.getComponentCount();
if (!hasFiller)
rowCount++;
}
}
container.setLayout(new GridLayoutManager(rowCount, colCount));
if (!hasFiller) {
if (myHorizontal) {
container.addComponent(new RadHSpacer(context.newId(), colCount - 1));
} else {
container.addComponent(new RadVSpacer(context.newId(), rowCount - 1));
}
}
}
use of com.intellij.uiDesigner.core.GridLayoutManager in project intellij-community by JetBrains.
the class RadGridLayoutManager method copyLayout.
@Override
public LayoutManager copyLayout(LayoutManager layout, int rowDelta, int columnDelta) {
GridLayoutManager oldLayout = (GridLayoutManager) layout;
final GridLayoutManager newLayout = new GridLayoutManager(oldLayout.getRowCount() + rowDelta, oldLayout.getColumnCount() + columnDelta);
newLayout.setMargin(oldLayout.getMargin());
newLayout.setHGap(oldLayout.getHGap());
newLayout.setVGap(oldLayout.getVGap());
return newLayout;
}
Aggregations