Search in sources :

Example 1 with InplaceContext

use of com.intellij.designer.propertyTable.InplaceContext 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);
    }
}
Also used : RadComponent(com.intellij.designer.model.RadComponent) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) AnAction(com.intellij.openapi.actionSystem.AnAction) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) LineMarginBorder(com.intellij.designer.designSurface.feedbacks.LineMarginBorder) PropertyEditor(com.intellij.designer.propertyTable.PropertyEditor) InplaceContext(com.intellij.designer.propertyTable.InplaceContext) Property(com.intellij.designer.model.Property)

Example 2 with InplaceContext

use of com.intellij.designer.propertyTable.InplaceContext in project intellij-community by JetBrains.

the class SelectionTool method handleKeyTyped.

protected void handleKeyTyped(KeyEvent event) {
    char keyChar = event.getKeyChar();
    switch(keyChar) {
        // Zoom
        case '-':
        case '+':
        case '0':
        case '1':
            ZoomType type;
            if (keyChar == '-') {
                type = ZoomType.OUT;
            } else if (keyChar == '+') {
                type = ZoomType.IN;
            } else if (keyChar == '0') {
                type = ZoomType.FIT;
            } else {
                // '1'
                type = ZoomType.ACTUAL;
            }
            if (myToolProvider.isZoomSupported()) {
                myToolProvider.zoom(type);
                event.consume();
                return;
            }
        // else: fall through
        default:
            if (Character.isLetterOrDigit(keyChar) && (event.getModifiers() & (InputEvent.ALT_MASK | InputEvent.CTRL_MASK | InputEvent.META_MASK)) == 0) {
                myToolProvider.startInplaceEditing(new InplaceContext(keyChar));
            }
    }
}
Also used : ZoomType(com.intellij.designer.designSurface.ZoomType) InplaceContext(com.intellij.designer.propertyTable.InplaceContext)

Aggregations

InplaceContext (com.intellij.designer.propertyTable.InplaceContext)2 ZoomType (com.intellij.designer.designSurface.ZoomType)1 LineMarginBorder (com.intellij.designer.designSurface.feedbacks.LineMarginBorder)1 Property (com.intellij.designer.model.Property)1 RadComponent (com.intellij.designer.model.RadComponent)1 PropertyEditor (com.intellij.designer.propertyTable.PropertyEditor)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 GridConstraints (com.intellij.uiDesigner.core.GridConstraints)1 GridLayoutManager (com.intellij.uiDesigner.core.GridLayoutManager)1