use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class CachedGridImage method repaint.
private void repaint(final RadContainer container) {
final int width = container.getWidth();
final int height = container.getHeight();
if (width * height >= 4096 * 4096)
return;
Graphics2D g2d = (Graphics2D) myImage.getGraphics();
try {
g2d.setComposite(AlphaComposite.Clear);
g2d.fillRect(0, 0, width, height);
g2d.setComposite(AlphaComposite.Src);
if (container.isSelected()) {
g2d.setColor(Painter.SELECTED_GRID_COLOR);
} else {
g2d.setColor(Painter.NON_SELECTED_GRID_COLOR);
}
g2d.setStroke(new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 1.0f, ourDashes, 0.0f));
if (myHorzGridLines.length > 0) {
int lastLine = (container.getDelegee().getHeight() - myHorzGridLines[myHorzGridLines.length - 1] > 4) ? myHorzGridLines.length : myHorzGridLines.length - 1;
for (int i = 1; i < lastLine; i++) {
final int y = myHorzGridLines[i];
g2d.drawLine(0, y, width, y);
}
}
if (myVertGridLines.length > 0) {
// Vertical lines
int lastLine = (container.getDelegee().getWidth() - myVertGridLines[myVertGridLines.length - 1] > 4) ? myVertGridLines.length : myVertGridLines.length - 1;
for (int i = 1; i < lastLine; i++) {
final int x = myVertGridLines[i];
g2d.drawLine(x, 0, x, height);
}
}
g2d.setComposite(AlphaComposite.Clear);
g2d.setStroke(new BasicStroke(1.0f));
for (RadComponent childComponent : container.getComponents()) {
final GridConstraints constraints = childComponent.getConstraints();
if (constraints.getColSpan() > 1) {
for (int col = constraints.getColumn() + 1; col < constraints.getColumn() + constraints.getColSpan(); col++) {
drawVertGridLine(g2d, col, constraints.getRow(), constraints.getRowSpan());
}
}
if (constraints.getRowSpan() > 1) {
for (int row = constraints.getRow() + 1; row < constraints.getRow() + constraints.getRowSpan(); row++) {
drawHorzGridLine(g2d, row, constraints.getColumn(), constraints.getColSpan());
}
}
}
} finally {
g2d.dispose();
}
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class DesignDropTargetListener method processDragEnter.
private void processDragEnter(final DraggedComponentList draggedComponentList, final Point location, final int dropAction) {
final List<RadComponent> dragComponents = draggedComponentList.getComponents();
Rectangle allBounds = null;
if (!draggedComponentList.hasDragDelta() || !myUseDragDelta) {
final RadContainer[] originalParents = draggedComponentList.getOriginalParents();
final Rectangle[] originalBounds = draggedComponentList.getOriginalBounds();
for (int i = 0; i < originalParents.length; i++) {
Rectangle rc = SwingUtilities.convertRectangle(originalParents[i].getDelegee(), originalBounds[i], myEditor.getDragLayer());
if (allBounds == null) {
allBounds = rc;
} else {
allBounds = allBounds.union(rc);
}
}
}
// Place selected components to the drag layer.
myDraggedComponentsCopy = CutCopyPasteSupport.copyComponents(myEditor, dragComponents);
for (int i = 0; i < dragComponents.size(); i++) {
myDraggedComponentsCopy.get(i).setSelected(true);
final JComponent delegee = myDraggedComponentsCopy.get(i).getDelegee();
final Point point = SwingUtilities.convertPoint(draggedComponentList.getOriginalParents()[i].getDelegee(), delegee.getLocation(), myEditor.getDragLayer());
if (draggedComponentList.hasDragDelta() && myUseDragDelta) {
delegee.setLocation((int) point.getX() + draggedComponentList.getDragDeltaX(), (int) point.getY() + draggedComponentList.getDragDeltaY());
} else {
assert allBounds != null;
delegee.setLocation((int) (point.getX() - allBounds.getX() + location.getX()), (int) (point.getY() - allBounds.getY() + location.getY()));
}
//myEditor.getDragLayer().add(delegee);
}
for (final RadComponent c : dragComponents) {
if (dropAction != DnDConstants.ACTION_COPY) {
c.setDragBorder(true);
}
c.setSelected(false);
}
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class DesignDropTargetListener method dragOver.
public void dragOver(DropTargetDragEvent dtde) {
try {
if (myComponentDragObject == null) {
dtde.rejectDrag();
return;
}
final int dx = dtde.getLocation().x - myLastPoint.x;
final int dy = dtde.getLocation().y - myLastPoint.y;
if (myDraggedComponentsCopy != null && myDraggedComponentList != null) {
for (RadComponent aMySelection : myDraggedComponentsCopy) {
aMySelection.shift(dx, dy);
}
}
myLastPoint = dtde.getLocation();
myEditor.getDragLayer().repaint();
ComponentDropLocation location = myGridInsertProcessor.processDragEvent(dtde.getLocation(), myComponentDragObject);
ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree();
if (!location.canDrop(myComponentDragObject) || (myDraggedComponentList != null && FormEditingUtil.isDropOnChild(myDraggedComponentList, location))) {
if (componentTree != null) {
componentTree.setDropTargetComponent(null);
}
dtde.rejectDrag();
} else {
if (componentTree != null) {
componentTree.setDropTargetComponent(location.getContainer());
}
dtde.acceptDrag(dtde.getDropAction());
}
} catch (Exception e) {
LOG.error(e);
}
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class DragLayer method paint.
public void paint(final Graphics g) {
((Graphics2D) g).setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.3f));
// Paint passive decoration of dragged components
for (int i = getComponentCount() - 1; i >= 0; i--) {
final Component child = getComponent(i);
if (child instanceof JComponent) {
final Object prop = ((JComponent) child).getClientProperty(RadComponent.CLIENT_PROP_RAD_COMPONENT);
if (prop != null) {
final RadComponent radComponent = (RadComponent) prop;
paintPassiveDecoration(radComponent, g);
}
}
}
// Paint selection rectangle
paintChildren(g);
}
use of com.intellij.uiDesigner.radComponents.RadComponent in project intellij-community by JetBrains.
the class MorphAction method morphComponent.
private static boolean morphComponent(final GuiEditor editor, final RadComponent oldComponent, ComponentItem targetItem) {
targetItem = InsertComponentProcessor.replaceAnyComponentItem(editor, targetItem, "Morph to Non-Palette Component");
if (targetItem == null) {
return false;
}
final RadComponent newComponent = InsertComponentProcessor.createInsertedComponent(editor, targetItem);
if (newComponent == null)
return false;
newComponent.setBinding(oldComponent.getBinding());
newComponent.setCustomLayoutConstraints(oldComponent.getCustomLayoutConstraints());
newComponent.getConstraints().restore(oldComponent.getConstraints());
updateBoundFieldType(editor, oldComponent, targetItem);
final IProperty[] oldProperties = oldComponent.getModifiedProperties();
final Palette palette = Palette.getInstance(editor.getProject());
for (IProperty prop : oldProperties) {
IntrospectedProperty newProp = palette.getIntrospectedProperty(newComponent, prop.getName());
if (newProp == null || !prop.getClass().equals(newProp.getClass()))
continue;
Object oldValue = prop.getPropertyValue(oldComponent);
try {
//noinspection unchecked
newProp.setValue(newComponent, oldValue);
} catch (Exception e) {
// ignore
}
}
retargetComponentProperties(editor, oldComponent, newComponent);
final RadContainer parent = oldComponent.getParent();
int index = parent.indexOfComponent(oldComponent);
parent.removeComponent(oldComponent);
parent.addComponent(newComponent, index);
newComponent.setSelected(true);
if (oldComponent.isDefaultBinding()) {
final String text = FormInspectionUtil.getText(newComponent.getModule(), newComponent);
if (text != null) {
String binding = BindingProperty.suggestBindingFromText(newComponent, text);
if (binding != null) {
new BindingProperty(newComponent.getProject()).setValueEx(newComponent, binding);
}
}
newComponent.setDefaultBinding(true);
}
return true;
}
Aggregations