Search in sources :

Example 41 with JBLabel

use of com.intellij.ui.components.JBLabel in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoImportPackageQuickFix method perform.

private void perform(@NotNull List<String> packagesToImport, @NotNull PsiFile file, @Nullable Editor editor) {
    LOG.assertTrue(editor != null || packagesToImport.size() == 1, "Cannot invoke fix with ambiguous imports on null editor");
    if (packagesToImport.size() > 1 && editor != null) {
        JBList list = new JBList(packagesToImport);
        list.installCellRenderer(o -> {
            JBLabel label = new JBLabel(o.toString(), GoIcons.PACKAGE, SwingConstants.LEFT);
            label.setBorder(IdeBorderFactory.createEmptyBorder(2, 4, 2, 4));
            return label;
        });
        PopupChooserBuilder builder = JBPopupFactory.getInstance().createListPopupBuilder(list).setRequestFocus(true).setTitle("Package to import").setItemChoosenCallback(() -> {
            int i = list.getSelectedIndex();
            if (i < 0)
                return;
            perform(file, packagesToImport.get(i));
        }).setFilteringEnabled(o -> o instanceof String ? (String) o : o.toString());
        JBPopup popup = builder.createPopup();
        builder.getScrollPane().setBorder(null);
        builder.getScrollPane().setViewportBorder(null);
        popup.showInBestPositionFor(editor);
    } else if (packagesToImport.size() == 1) {
        perform(file, getFirstItem(packagesToImport));
    } else {
        String packages = StringUtil.join(packagesToImport, ",");
        throw new IncorrectOperationException("Cannot invoke fix with ambiguous imports on editor ()" + editor + ". Packages: " + packages);
    }
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) JBList(com.intellij.ui.components.JBList) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PopupChooserBuilder(com.intellij.openapi.ui.popup.PopupChooserBuilder) JBPopup(com.intellij.openapi.ui.popup.JBPopup)

Example 42 with JBLabel

use of com.intellij.ui.components.JBLabel in project intellij-leiningen-plugin by derkork.

the class LeiningenSettings method createComponent.

public JComponent createComponent() {
    JPanel outerPanel = new JPanel(new BorderLayout());
    JPanel leinPanel = new JPanel(new FormLayout("80dlu, fill:80dlu:grow, 20dlu, 80dlu", "p,p,p"));
    CellConstraints c = new CellConstraints();
    int row = 1;
    leinPanel.add(new JBLabel("Leiningen executable:"), c.xy(1, row));
    this.leinBinSelectorField = new TextFieldWithBrowseButton();
    leinBinSelectorField.addBrowseFolderListener("Select the Leiningen executable", "'lein' on Linux/MacOS, 'lein.bat' on Windows. ", null, new FileChooserDescriptor(true, false, false, false, false, false));
    leinPanel.add(leinBinSelectorField, c.xy(2, row));
    row++;
    leinPanel.add(new JBLabel("Leiningen Home:"), c.xy(1, row));
    this.leinHomeSelectorField = new TextFieldWithBrowseButton();
    leinHomeSelectorField.addBrowseFolderListener("Select the Leiningen home directory", "usually at $USER_HOME/.lein", null, new FileChooserDescriptor(false, true, false, false, false, false));
    leinPanel.add(leinHomeSelectorField, c.xy(2, row));
    this.overrideLeinHome = new JBCheckBox();
    leinPanel.add(overrideLeinHome, c.xy(3, row));
    leinPanel.add(new JBLabel("Override"), c.xy(4, row));
    row++;
    leinPanel.add(new JBLabel("Leiningen Jar:"), c.xy(1, row));
    this.leinJarSelectorField = new TextFieldWithBrowseButton();
    leinJarSelectorField.addBrowseFolderListener("Select the Leiningen Jar", "usually at $USER_HOME/.lein/self-installs/leinigen-VERSION-standalone.jar", null, new FileChooserDescriptor(true, false, true, true, false, false));
    leinPanel.add(leinJarSelectorField, c.xy(2, row));
    this.overrideLeinJar = new JBCheckBox();
    leinPanel.add(overrideLeinJar, c.xy(3, row));
    leinPanel.add(new JBLabel("Override"), c.xy(4, row));
    outerPanel.add(leinPanel, BorderLayout.NORTH);
    myWatcher = new UserActivityWatcher();
    myWatcher.register(outerPanel);
    myWatcher.addUserActivityListener(new UserActivityListener() {

        public void stateChanged() {
            changed = true;
            leinJarSelectorField.setEnabled(overrideLeinJar.isSelected());
            leinHomeSelectorField.setEnabled(overrideLeinHome.isSelected());
        }
    });
    return outerPanel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) JBLabel(com.intellij.ui.components.JBLabel) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) UserActivityWatcher(com.intellij.ui.UserActivityWatcher) UserActivityListener(com.intellij.ui.UserActivityListener) CellConstraints(com.jgoodies.forms.layout.CellConstraints) JBCheckBox(com.intellij.ui.components.JBCheckBox)

Example 43 with JBLabel

use of com.intellij.ui.components.JBLabel in project android by JetBrains.

the class ResourceTablePanel method createUIComponents.

private void createUIComponents() {
    JBLabel label = new JBLabel("Resource Types");
    myTypesList = new JBList();
    JPanel resourceTypesPanel = new JPanel(new BorderLayout());
    resourceTypesPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    resourceTypesPanel.add(label, BorderLayout.NORTH);
    resourceTypesPanel.add(ScrollPaneFactory.createScrollPane(myTypesList), BorderLayout.CENTER);
    myResourceTypeTable = new JBTable();
    myResourceTypeTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    myResourceTypeTable.getEmptyText().setText("No resource type selected.");
    myResourceTableHeader = new SimpleColoredComponent();
    JPanel resourceTablePanel = new JPanel(new BorderLayout());
    resourceTablePanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    resourceTablePanel.add(myResourceTableHeader, BorderLayout.NORTH);
    resourceTablePanel.add(ScrollPaneFactory.createScrollPane(myResourceTypeTable), BorderLayout.CENTER);
    mySplitter = new OnePixelSplitter(false, 0.2f);
    mySplitter.setFirstComponent(resourceTypesPanel);
    mySplitter.setSecondComponent(resourceTablePanel);
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) JBList(com.intellij.ui.components.JBList) JBTable(com.intellij.ui.table.JBTable)

Example 44 with JBLabel

use of com.intellij.ui.components.JBLabel in project android by JetBrains.

the class KeyValuePane method init.

public void init(GradleBuildFile gradleBuildFile, Collection<BuildFileKey> properties) {
    GridLayoutManager layout = new GridLayoutManager(properties.size() + 1, 2);
    setLayout(layout);
    GridConstraints constraints = new GridConstraints();
    constraints.setAnchor(GridConstraints.ANCHOR_WEST);
    constraints.setVSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
    for (BuildFileKey property : properties) {
        constraints.setColumn(0);
        constraints.setFill(GridConstraints.FILL_NONE);
        constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
        JBLabel label = new JBLabel(property.getDisplayName());
        add(label, constraints);
        constraints.setColumn(1);
        constraints.setFill(GridConstraints.FILL_HORIZONTAL);
        constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_WANT_GROW);
        JComponent component;
        switch(property.getType()) {
            case BOOLEAN:
                {
                    constraints.setFill(GridConstraints.FILL_NONE);
                    ComboBox comboBox = createComboBox(false);
                    comboBox.addItem("");
                    comboBox.addItem("true");
                    comboBox.addItem("false");
                    comboBox.setPrototypeDisplayValue("(false) ");
                    component = comboBox;
                    break;
                }
            case FILE:
            case FILE_AS_STRING:
                {
                    JBTextField textField = new JBTextField();
                    TextFieldWithBrowseButton fileField = new TextFieldWithBrowseButton(textField);
                    FileChooserDescriptor d = new FileChooserDescriptor(true, false, false, true, false, false);
                    d.setShowFileSystemRoots(true);
                    fileField.addBrowseFolderListener(new TextBrowseFolderListener(d));
                    fileField.getTextField().getDocument().addDocumentListener(this);
                    component = fileField;
                    break;
                }
            case REFERENCE:
                {
                    constraints.setFill(GridConstraints.FILL_NONE);
                    ComboBox comboBox = createComboBox(true);
                    if (hasKnownValues(property)) {
                        for (String s : myKeysWithKnownValues.get(property).values()) {
                            comboBox.addItem(s);
                        }
                    }
                    // If there are no hardcoded values, the combo box's values will get populated later when the panel for the container reference
                    // type wakes up and notifies us of its current values.
                    component = comboBox;
                    break;
                }
            case CLOSURE:
            case STRING:
            case INTEGER:
            default:
                {
                    if (hasKnownValues(property)) {
                        constraints.setFill(GridConstraints.FILL_NONE);
                        ComboBox comboBox = createComboBox(true);
                        for (String s : myKeysWithKnownValues.get(property).values()) {
                            comboBox.addItem(s);
                        }
                        component = comboBox;
                    } else {
                        JBTextField textField = new JBTextField();
                        textField.getDocument().addDocumentListener(this);
                        component = textField;
                    }
                    break;
                }
        }
        add(component, constraints);
        label.setLabelFor(component);
        myProperties.put(property, component);
        constraints.setRow(constraints.getRow() + 1);
    }
    constraints.setColumn(0);
    constraints.setVSizePolicy(GridConstraints.FILL_VERTICAL);
    constraints.setHSizePolicy(GridConstraints.SIZEPOLICY_FIXED);
    add(new JBLabel(""), constraints);
    updateUiFromCurrentObject();
}
Also used : TextFieldWithBrowseButton(com.intellij.openapi.ui.TextFieldWithBrowseButton) GridLayoutManager(com.intellij.uiDesigner.core.GridLayoutManager) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) JBLabel(com.intellij.ui.components.JBLabel) ComboBox(com.intellij.openapi.ui.ComboBox) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) TextBrowseFolderListener(com.intellij.openapi.ui.TextBrowseFolderListener) JBTextField(com.intellij.ui.components.JBTextField) AndroidTargetHash.getAddonHashString(com.android.sdklib.AndroidTargetHash.getAddonHashString) BuildFileKey(com.android.tools.idea.gradle.parser.BuildFileKey)

Example 45 with JBLabel

use of com.intellij.ui.components.JBLabel in project android by JetBrains.

the class DeviceConfiguratorPanel method createUIComponents.

private void createUIComponents() {
    myQualifierOptionsPanel = new JPanel(new CardLayout());
    final JPanel leftPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
    myAvailableQualifiersList = new JBList();
    myAvailableQualifiersList.setMinimumSize(JBUI.size(10, 10));
    JBLabel label = new JBLabel(AndroidBundle.message("android.layout.preview.edit.configuration.available.qualifiers.label"));
    label.setLabelFor(myAvailableQualifiersList);
    leftPanel.add(label, BorderLayout.NORTH);
    leftPanel.add(new JBScrollPane(myAvailableQualifiersList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
    final JPanel rightPanel = new JPanel(new BorderLayout(JBUI.scale(5), JBUI.scale(5)));
    myChosenQualifiersList = new JBList();
    myChosenQualifiersList.setMinimumSize(JBUI.size(10, 10));
    label = new JBLabel(AndroidBundle.message("android.layout.preview.edit.configuration.choosen.qualifiers.label"));
    label.setLabelFor(myChosenQualifiersList);
    rightPanel.add(label, BorderLayout.NORTH);
    rightPanel.add(new JBScrollPane(myChosenQualifiersList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER), BorderLayout.CENTER);
    final JPanel buttonsPanel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false));
    myAddQualifierButton = new JButton(">>");
    buttonsPanel.add(myAddQualifierButton);
    myRemoveQualifierButton = new JButton("<<");
    buttonsPanel.add(myRemoveQualifierButton);
    final int gap = 5;
    final JPanel listsPanel = new JPanel(new AbstractLayoutManager() {

        @SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext")
        @Override
        public Dimension preferredLayoutSize(Container target) {
            synchronized (target.getTreeLock()) {
                final Dimension leftPref = leftPanel.getPreferredSize();
                final Dimension rightPref = rightPanel.getPreferredSize();
                final Dimension middlePref = buttonsPanel.getPreferredSize();
                final Insets insets = target.getInsets();
                final int width = leftPref.width + middlePref.width + rightPref.width + insets.left + insets.right + gap * 2;
                final int height = Math.max(leftPref.height, Math.max(rightPref.height, middlePref.height)) + insets.top + insets.bottom;
                return new Dimension(width, height);
            }
        }

        @SuppressWarnings("NonPrivateFieldAccessedInSynchronizedContext")
        @Override
        public void layoutContainer(Container target) {
            synchronized (target.getTreeLock()) {
                final Insets insets = target.getInsets();
                int top = insets.top;
                int bottom = target.getHeight() - insets.bottom;
                int left = insets.left;
                int right = target.getWidth() - insets.right;
                final int middleWidth = buttonsPanel.getPreferredSize().width + gap * 2;
                final int listWidth = (right - left - middleWidth) / 2;
                final int height = bottom - top;
                leftPanel.setSize(listWidth, height);
                rightPanel.setSize(listWidth, height);
                buttonsPanel.setSize(middleWidth, height);
                leftPanel.setBounds(left, top, listWidth, height);
                rightPanel.setBounds(right - listWidth, top, listWidth, height);
                buttonsPanel.setBounds(left + listWidth + gap, top, middleWidth - gap * 2, height);
            }
        }
    });
    listsPanel.add(leftPanel);
    listsPanel.add(buttonsPanel);
    listsPanel.add(rightPanel);
    add(listsPanel, BorderLayout.CENTER);
    add(myQualifierOptionsPanel, BorderLayout.EAST);
}
Also used : AbstractLayoutManager(com.intellij.util.ui.AbstractLayoutManager) JBLabel(com.intellij.ui.components.JBLabel) JBList(com.intellij.ui.components.JBList) JBScrollPane(com.intellij.ui.components.JBScrollPane) VerticalFlowLayout(com.intellij.openapi.ui.VerticalFlowLayout)

Aggregations

JBLabel (com.intellij.ui.components.JBLabel)98 Nullable (org.jetbrains.annotations.Nullable)23 NotNull (org.jetbrains.annotations.NotNull)11 JBCheckBox (com.intellij.ui.components.JBCheckBox)10 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ComboBox (com.intellij.openapi.ui.ComboBox)7 VerticalFlowLayout (com.intellij.openapi.ui.VerticalFlowLayout)7 GridBag (com.intellij.util.ui.GridBag)7 List (java.util.List)7 JBList (com.intellij.ui.components.JBList)6 JBTable (com.intellij.ui.table.JBTable)6 JBTextField (com.intellij.ui.components.JBTextField)5 DocumentEvent (javax.swing.event.DocumentEvent)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4 Project (com.intellij.openapi.project.Project)4 TextFieldWithBrowseButton (com.intellij.openapi.ui.TextFieldWithBrowseButton)4 StringUtil (com.intellij.openapi.util.text.StringUtil)4 java.awt (java.awt)4 ArrayList (java.util.ArrayList)4