Search in sources :

Example 11 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class DesignDropTargetListener method dragEnter.

public void dragEnter(DropTargetDragEvent dtde) {
    try {
        DraggedComponentList dcl = DraggedComponentList.fromTransferable(dtde.getTransferable());
        if (dcl != null) {
            myDraggedComponentList = dcl;
            myComponentDragObject = dcl;
            processDragEnter(dcl, dtde.getLocation(), dtde.getDropAction());
            dtde.acceptDrag(dtde.getDropAction());
            myLastPoint = dtde.getLocation();
        } else {
            ComponentItem componentItem = SimpleTransferable.getData(dtde.getTransferable(), ComponentItem.class);
            if (componentItem != null) {
                myComponentDragObject = new ComponentItemDragObject(componentItem);
                dtde.acceptDrag(dtde.getDropAction());
                myLastPoint = dtde.getLocation();
            }
        }
    } catch (Exception e) {
        LOG.error(e);
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem)

Example 12 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class DesignDropTargetListener method drop.

public void drop(final DropTargetDropEvent dtde) {
    try {
        ComponentTree componentTree = DesignerToolWindowManager.getInstance(myEditor).getComponentTree();
        if (componentTree != null) {
            componentTree.setDropTargetComponent(null);
        }
        final DraggedComponentList dcl = DraggedComponentList.fromTransferable(dtde.getTransferable());
        if (dcl != null) {
            CommandProcessor.getInstance().executeCommand(myEditor.getProject(), () -> {
                if (processDrop(dcl, dtde.getLocation(), dtde.getDropAction())) {
                    myEditor.refreshAndSave(true);
                }
            }, UIDesignerBundle.message("command.drop.components"), null);
        } else {
            ComponentItem componentItem = SimpleTransferable.getData(dtde.getTransferable(), ComponentItem.class);
            if (componentItem != null) {
                myEditor.getMainProcessor().setInsertFeedbackEnabled(false);
                new InsertComponentProcessor(myEditor).processComponentInsert(dtde.getLocation(), componentItem);
                ApplicationManager.getApplication().invokeLater(() -> {
                    PaletteToolWindowManager.getInstance(myEditor).clearActiveItem();
                    myEditor.getActiveDecorationLayer().removeFeedback();
                    myEditor.getLayeredPane().setCursor(null);
                    IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                        IdeFocusManager.getGlobalInstance().requestFocus(myEditor.getGlassLayer(), true);
                    });
                    myEditor.getMainProcessor().setInsertFeedbackEnabled(true);
                });
            }
        }
        myDraggedComponentsCopy = null;
        myEditor.repaintLayeredPane();
    } catch (Exception e) {
        LOG.error(e);
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) ComponentTree(com.intellij.uiDesigner.componentTree.ComponentTree)

Example 13 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class FormPropertyTableCellRenderer method customizeCellRenderer.

protected void customizeCellRenderer(final JTable table, final Object value, final boolean selected, final boolean hasFocus, final int row, final int column) {
    if (value == null) {
        return;
    }
    final FormProperty property = (FormProperty) value;
    final LwComponent component = property.getLwComponent();
    // Icon
    final Icon icon;
    final String fqClassName = component.getComponentClassName();
    final ComponentItem item = myPalette.getItem(fqClassName);
    if (item != null) {
        icon = item.getSmallIcon();
    } else {
        icon = UIDesignerIcons.Unknown_small;
    }
    setIcon(icon);
    // Binding
    append(component.getBinding(), myAttrs1);
    // Component class name and package
    final String shortClassName;
    final String packageName;
    final int lastDotIndex = fqClassName.lastIndexOf('.');
    if (lastDotIndex != -1) {
        shortClassName = fqClassName.substring(lastDotIndex + 1);
        packageName = fqClassName.substring(0, lastDotIndex);
    } else {
        // default package
        shortClassName = fqClassName;
        packageName = null;
    }
    LOG.assertTrue(shortClassName.length() > 0);
    append(" ", myAttrs2);
    /*small gap between icon and class name*/
    append(shortClassName, myAttrs2);
    if (packageName != null) {
        append(" (", myAttrs3);
        append(packageName, myAttrs3);
        append(")", myAttrs3);
    }
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) LwComponent(com.intellij.uiDesigner.lw.LwComponent)

Example 14 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class InsertComponentProcessor method replaceAnyComponentItem.

@Nullable
public static ComponentItem replaceAnyComponentItem(GuiEditor editor, ComponentItem item, final String title) {
    if (item.isAnyComponent()) {
        ComponentItem newItem = item.clone();
        ComponentItemDialog dlg = new ComponentItemDialog(editor.getProject(), editor, newItem, true);
        dlg.setTitle(title);
        if (!dlg.showAndGet()) {
            return null;
        }
        return newItem;
    }
    return item;
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) ComponentItemDialog(com.intellij.uiDesigner.palette.ComponentItemDialog) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with ComponentItem

use of com.intellij.uiDesigner.palette.ComponentItem in project intellij-community by JetBrains.

the class MainProcessor method processMousePressed.

private void processMousePressed(final MouseEvent e) {
    if (myCurrentProcessor != null) {
        if (myCurrentProcessor.needMousePressed()) {
            myCurrentProcessor.processMouseEvent(e);
            return;
        }
        // Sun sometimes skips mouse released events...
        myCurrentProcessor.cancelOperation();
        myCurrentProcessor = null;
    }
    RadComponent component = null;
    final RadComponent draggerHost = FormEditingUtil.getDraggerHost(myEditor);
    // Try to understand whether we pressed inside dragger area
    if (draggerHost != null) {
        final JComponent delegee = draggerHost.getDelegee();
        final Point p = SwingUtilities.convertPoint(delegee, 0, 0, e.getComponent());
        if (p.x - MainProcessor.DRAGGER_SIZE <= e.getX() && e.getX() <= p.x && p.y - MainProcessor.DRAGGER_SIZE <= e.getY() && e.getY() <= p.y) {
            component = draggerHost;
        }
    }
    // If user clicked not inside dragger then we have find RadComponent at the click point
    if (component == null) {
        component = FormEditingUtil.getRadComponentAt(myEditor.getRootContainer(), e.getX(), e.getY());
    }
    if (component == null) {
        return;
    }
    final ComponentItem selectedItem = PaletteToolWindowManager.getInstance(myEditor).getActiveItem(ComponentItem.class);
    if (selectedItem != null) {
        myInsertComponentProcessor.setSticky(UIUtil.isControlKeyDown(e));
        myCurrentProcessor = myInsertComponentProcessor;
        return;
    }
    if (!UIUtil.isControlKeyDown(e) && !e.isShiftDown()) {
        if (!component.isSelected() || FormEditingUtil.getSelectedComponents(myEditor).size() != 1) {
            FormEditingUtil.selectSingleComponent(myEditor, component);
        }
    }
    final Point point = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), component.getDelegee());
    final int resizeMask = Painter.getResizeMask(component, point.x, point.y);
    LOG.debug("MainProcessor.processMousePressed: resizeMask at (" + point.x + "," + point.y + ") is " + resizeMask);
    if (resizeMask != 0) {
        if (component.getParent() != null) {
            component = component.getParent().getActionTargetComponent(component);
        }
        myCurrentProcessor = new ResizeProcessor(myEditor, component, resizeMask);
    } else if (component instanceof RadRootContainer || e.isShiftDown()) {
        myCurrentProcessor = new GroupSelectionProcessor(myEditor, component);
    } else if (!e.isShiftDown()) {
        myCurrentProcessor = new DragSelectionProcessor(myEditor);
    }
    updateDragger(e);
}
Also used : ComponentItem(com.intellij.uiDesigner.palette.ComponentItem) RadComponent(com.intellij.uiDesigner.radComponents.RadComponent) RadRootContainer(com.intellij.uiDesigner.radComponents.RadRootContainer)

Aggregations

ComponentItem (com.intellij.uiDesigner.palette.ComponentItem)16 Palette (com.intellij.uiDesigner.palette.Palette)5 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)4 RadComponent (com.intellij.uiDesigner.radComponents.RadComponent)4 FormEditingUtil (com.intellij.uiDesigner.FormEditingUtil)3 ArrayList (java.util.ArrayList)3 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)2 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)2 ListPopup (com.intellij.openapi.ui.popup.ListPopup)2 UIDesignerBundle (com.intellij.uiDesigner.UIDesignerBundle)2 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)2 GuiEditor (com.intellij.uiDesigner.designSurface.GuiEditor)2 IComponent (com.intellij.uiDesigner.lw.IComponent)2 IProperty (com.intellij.uiDesigner.lw.IProperty)2 RadContainer (com.intellij.uiDesigner.radComponents.RadContainer)2 RadRootContainer (com.intellij.uiDesigner.radComponents.RadRootContainer)2 XYLayoutManager (com.intellij.uiDesigner.shared.XYLayoutManager)2 Processor (com.intellij.util.Processor)2 List (java.util.List)2 CommandProcessor (com.intellij.openapi.command.CommandProcessor)1