use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.
the class InsertComponentProcessor method processKeyEvent.
protected void processKeyEvent(final KeyEvent e) {
if (e.getID() == KeyEvent.KEY_PRESSED) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
if (myLastLocation != null) {
myEditor.getMainProcessor().stopCurrentProcessor();
processComponentInsert(getComponentToInsert(), myLastLocation);
}
} else {
ComponentItem componentToInsert = getComponentToInsert();
if (componentToInsert == null) {
cancelOperation();
} else {
myLastLocation = moveDropLocation(myEditor, myLastLocation, new ComponentItemDragObject(componentToInsert), e);
}
}
}
}
use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.
the class InsertComponentProcessor method setLastLocation.
public void setLastLocation(final ComponentDropLocation location) {
final ComponentItem componentToInsert = getComponentToInsert();
assert componentToInsert != null;
ComponentItemDragObject dragObject = new ComponentItemDragObject(componentToInsert);
if (location.canDrop(dragObject)) {
myLastLocation = location;
} else {
ComponentDropLocation locationToRight = location.getAdjacentLocation(ComponentDropLocation.Direction.RIGHT);
ComponentDropLocation locationToBottom = location.getAdjacentLocation(ComponentDropLocation.Direction.DOWN);
if (locationToRight != null && locationToRight.canDrop(dragObject)) {
myLastLocation = locationToRight;
} else if (locationToBottom != null && locationToBottom.canDrop(dragObject)) {
myLastLocation = locationToBottom;
} else {
myLastLocation = location;
}
}
if (myLastLocation.canDrop(dragObject)) {
myLastLocation.placeFeedback(myEditor.getActiveDecorationLayer(), dragObject);
}
}
use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.
the class FormEditingUtil method getDefaultConstraints.
public static GridConstraints getDefaultConstraints(final RadComponent component) {
final Palette palette = Palette.getInstance(component.getProject());
final ComponentItem item = palette.getItem(component.getComponentClassName());
if (item != null) {
return item.getDefaultConstraints();
}
return new GridConstraints();
}
use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.
the class GridBuildUtil method convertToGridImpl.
private static void convertToGridImpl(final GuiEditor editor, final int gridType) {
final boolean createNewContainer;
final RadContainer parent;
final RadComponent[] componentsToConvert;
{
final ArrayList<RadComponent> selection = FormEditingUtil.getSelectedComponents(editor);
if (selection.size() == 0) {
// root container selected
final RadRootContainer rootContainer = editor.getRootContainer();
if (rootContainer.getComponentCount() < 2) {
// nothing to convert
return;
}
componentsToConvert = new RadComponent[rootContainer.getComponentCount()];
for (int i = 0; i < componentsToConvert.length; i++) {
componentsToConvert[i] = rootContainer.getComponent(i);
}
parent = rootContainer;
createNewContainer = true;
} else if (selection.size() == 1 && selection.get(0) instanceof RadContainer) {
parent = (RadContainer) selection.get(0);
componentsToConvert = new RadComponent[parent.getComponentCount()];
for (int i = 0; i < componentsToConvert.length; i++) {
componentsToConvert[i] = parent.getComponent(i);
}
createNewContainer = false;
} else {
componentsToConvert = selection.toArray(new RadComponent[selection.size()]);
parent = selection.get(0).getParent();
createNewContainer = true;
}
}
if (!parent.isXY()) {
// only components in XY can be layed out in grid
return;
}
for (int i = 1; i < componentsToConvert.length; i++) {
final RadComponent component = componentsToConvert[i];
if (component.getParent() != parent) {
return;
}
}
final GridLayoutManager gridLayoutManager;
if (componentsToConvert.length == 0) {
// we convert empty XY panel to grid
gridLayoutManager = new GridLayoutManager(1, 1);
} else {
if (gridType == VERTICAL_GRID) {
gridLayoutManager = createOneDimensionGrid(componentsToConvert, true);
} else if (gridType == HORIZONTAL_GRID) {
gridLayoutManager = createOneDimensionGrid(componentsToConvert, false);
} else if (gridType == GRID) {
gridLayoutManager = createTwoDimensionGrid(componentsToConvert);
} else {
throw new IllegalArgumentException("invalid grid type: " + gridType);
}
}
for (final RadComponent component : componentsToConvert) {
if (component instanceof RadContainer) {
final LayoutManager layout = ((RadContainer) component).getLayout();
if (layout instanceof XYLayoutManager) {
((XYLayoutManager) layout).setPreferredSize(component.getSize());
}
}
}
if (createNewContainer) {
// we should create a new panel
final Module module = editor.getModule();
final ComponentItem panelItem = Palette.getInstance(editor.getProject()).getPanelItem();
final RadContainer newContainer = new RadContainer(editor, FormEditingUtil.generateId(editor.getRootContainer()));
newContainer.setLayout(gridLayoutManager);
newContainer.init(editor, panelItem);
for (RadComponent componentToConvert : componentsToConvert) {
newContainer.addComponent(componentToConvert);
}
final Point topLeftPoint = getTopLeftPoint(componentsToConvert);
newContainer.setLocation(topLeftPoint);
final Point bottomRightPoint = getBottomRightPoint(componentsToConvert);
final Dimension size = new Dimension(bottomRightPoint.x - topLeftPoint.x, bottomRightPoint.y - topLeftPoint.y);
Util.adjustSize(newContainer.getDelegee(), newContainer.getConstraints(), size);
newContainer.getDelegee().setSize(size);
parent.addComponent(newContainer);
FormEditingUtil.clearSelection(editor.getRootContainer());
newContainer.setSelected(true);
// restore binding of main component
{
final String mainComponentBinding = editor.getRootContainer().getMainComponentBinding();
if (mainComponentBinding != null && parent instanceof RadRootContainer) {
newContainer.setBinding(mainComponentBinding);
editor.getRootContainer().setMainComponentBinding(null);
}
}
} else {
// convert entire 'parent' to grid
parent.setLayout(gridLayoutManager);
FormEditingUtil.clearSelection(editor.getRootContainer());
parent.setSelected(true);
}
editor.refreshAndSave(true);
}
use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.
the class CreateComponentAction method actionPerformed.
protected void actionPerformed(final GuiEditor editor, final List<RadComponent> selection, final AnActionEvent e) {
Processor<ComponentItem> processor = selectedValue -> {
if (selectedValue != null) {
myLastCreatedComponent = selectedValue;
editor.getMainProcessor().startInsertProcessor(selectedValue, getCreateLocation(editor, selection));
}
return true;
};
PaletteListPopupStep step = new PaletteListPopupStep(editor, myLastCreatedComponent, processor, UIDesignerBundle.message("create.component.title"));
final ListPopup listPopup = JBPopupFactory.getInstance().createListPopup(step);
if (selection.size() > 0) {
FormEditingUtil.showPopupUnderComponent(listPopup, selection.get(0));
} else {
listPopup.showInCenterOf(editor.getRootContainer().getDelegee());
}
}
Aggregations