Search in sources :

Example 46 with JBLabel

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

the class FormScalingUtil method scaleComponent.

private void scaleComponent(Component c) {
    if (c instanceof Container) {
        Container container = (Container) c;
        scaleLayoutManager(container.getLayout());
    }
    if (c instanceof JTable) {
        JTable table = (JTable) c;
        Dimension size = table.getPreferredScrollableViewportSize();
        if (size != null) {
            table.setPreferredScrollableViewportSize(scale(size, "preferredScrollableViewportSize"));
        }
    }
    if (c instanceof JSlider) {
        JSlider slider = (JSlider) c;
        // force the default size to be computed. It will then be scaled in this method below.
        if (!slider.isPreferredSizeSet()) {
            slider.setPreferredSize(slider.getPreferredSize());
        }
    }
    if (c instanceof JBLabel) {
        JBLabel label = (JBLabel) c;
        label.setIconTextGap(scale(label.getIconTextGap(), "IconTextGap"));
    }
    if (c instanceof JComponent) {
        JComponent component = (JComponent) c;
        Border scaledBorder = getScaledBorder(component, component.getBorder());
        if (scaledBorder != null) {
            component.setBorder(scaledBorder);
        }
    }
    if (c.isFontSet()) {
        // Special case: If we have a font smaller than the threshold for the given
        // scale factor, scale the font size.
        // This heuristics only handle a subset of font sizing, where the intent was
        // do set the font size to "small" in the .form file.
        float fontSize = c.getFont().getSize2D();
        // We assume a size < 9 would be too small at any dpi setting.
        float minFontSize = 9f * myScaleFactor;
        if (fontSize <= minFontSize) {
            c.setFont(c.getFont().deriveFont(scale(fontSize, "FontSize")));
        }
    }
    scaleMinimumSize(c);
    scaleMaximumSize(c);
    scalePreferredSize(c);
    if (c.getParent() != null && c.getParent().getLayout() != null && c.getParent().getLayout() instanceof AbstractLayout) {
        AbstractLayout abstractLayout = (AbstractLayout) c.getParent().getLayout();
        GridConstraints constraint = abstractLayout.getConstraintsForComponent(c);
        constraint.myPreferredSize.width = scale(constraint.myPreferredSize.width, "constraint.myPreferredSize.width");
        constraint.myPreferredSize.height = scale(constraint.myPreferredSize.height, "constraint.myPreferredSize.height");
        constraint.myMinimumSize.width = scale(constraint.myMinimumSize.width, "constraint.myMinimumSize.width");
        constraint.myMinimumSize.height = scale(constraint.myMinimumSize.height, "constraint.myMinimumSize.height");
        constraint.myMaximumSize.width = scale(constraint.myMaximumSize.width, "constraint.myMaximumSize.width");
        constraint.myMaximumSize.height = scale(constraint.myMaximumSize.height, "constraint.myMaximumSize.height");
    }
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) AbstractLayout(com.intellij.uiDesigner.core.AbstractLayout) EmptyBorder(javax.swing.border.EmptyBorder) TitledBorder(javax.swing.border.TitledBorder) Border(javax.swing.border.Border)

Example 47 with JBLabel

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

the class NlPropertyInspectorFixture method findProperty.

@Nullable
public NlPropertyFixture findProperty(final String name) {
    JBLabel label = waitUntilFound(robot(), myPanel, new GenericTypeMatcher<JBLabel>(JBLabel.class) {

        @Override
        protected boolean isMatching(@NotNull JBLabel label) {
            return name.equals(label.getText()) && label.getIcon() == null;
        }
    });
    Container parent = label.getParent();
    Component[] components = parent.getComponents();
    for (int i = 0; i < components.length; i++) {
        if (label == components[i]) {
            return new NlPropertyFixture(robot(), (JPanel) components[i + 1]);
        }
    }
    return null;
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) Nullable(com.android.annotations.Nullable)

Example 48 with JBLabel

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

the class FormFactorSdkControls method init.

/**
   * @param state The ScopedStateStore in which to store our selections
   * @param downloadSuccess A Runnable that will be run if any valid items were found for this form factor.
   * @param downloadFailed A Runnable that will be run if no valid items were found for this form factor.
   */
public void init(final ScopedStateStore state, final Runnable loadComplete) {
    myBinder.register(myInclusionKey, myInclusionCheckBox);
    myHelpMeChooseLink.addHyperlinkListener(new HyperlinkAdapter() {

        @Override
        protected void hyperlinkActivated(HyperlinkEvent e) {
            Integer minApiLevel = state.get(getMinApiLevelKey(MOBILE));
            ChooseApiLevelDialog chooseApiLevelDialog = new ChooseApiLevelDialog(null, minApiLevel == null ? 0 : minApiLevel);
            Disposer.register(myDisposable, chooseApiLevelDialog.getDisposable());
            if (chooseApiLevelDialog.showAndGet()) {
                int selectedApiLevel = chooseApiLevelDialog.getSelectedApiLevel();
                ScopedDataBinder.setSelectedItem(myMinSdkCombobox, Integer.toString(selectedApiLevel));
            }
        }
    });
    // (that is, Mobile).
    if (myStatsPanel.isVisible()) {
        myBinder.register(API_FEEDBACK_KEY, myHelpMeChooseLabel2, new ScopedDataBinder.ComponentBinding<String, JBLabel>() {

            @Override
            public void setValue(@Nullable String newValue, @NotNull JBLabel label) {
                final JBLabel referenceLabel = label;
                final String referenceString = newValue;
                ApplicationManager.getApplication().invokeLater(() -> referenceLabel.setText(referenceString));
            }
        });
        myBinder.registerValueDeriver(API_FEEDBACK_KEY, new ScopedDataBinder.ValueDeriver<String>() {

            @Nullable
            @Override
            public Set<ScopedStateStore.Key<?>> getTriggerKeys() {
                return makeSetOf(getTargetComboBoxKey(MOBILE));
            }

            @Nullable
            @Override
            public String deriveValue(@NotNull ScopedStateStore state, ScopedStateStore.Key changedKey, @Nullable String currentValue) {
                FormFactorApiComboBox.AndroidTargetComboBoxItem selectedItem = state.get(getTargetComboBoxKey(MOBILE));
                String name = Integer.toString(selectedItem == null ? 0 : selectedItem.getApiLevel());
                if (selectedItem != null && selectedItem.target != null) {
                    name = selectedItem.target.getVersion().getApiString();
                }
                return getApiHelpText(selectedItem == null || !myStatsPanel.isVisible() ? 0 : selectedItem.getApiLevel(), name);
            }
        });
    }
    myMinSdkCombobox.init(myFormFactor, myMinApi, loadComplete, () -> {
        myInclusionCheckBox.setEnabled(true);
        myLabel.setEnabled(true);
        myMinSdkCombobox.setEnabled(true);
    }, () -> {
        myInclusionCheckBox.setSelected(false);
        myNotAvailableLabel.setVisible(true);
    });
    myMinSdkCombobox.registerWith(myBinder);
    myMinSdkCombobox.loadSavedApi();
    if (myStatsPanel.isVisible()) {
        DistributionService.getInstance().refresh(() -> ApplicationManager.getApplication().invokeLater(() -> {
            ((CardLayout) myStatsPanel.getLayout()).show(myStatsPanel, "stats");
            myBinder.invokeUpdate(getTargetComboBoxKey(MOBILE));
        }), () -> ApplicationManager.getApplication().invokeLater(() -> {
            ((CardLayout) myStatsPanel.getLayout()).show(myStatsPanel, "stats");
            myBinder.invokeUpdate(getTargetComboBoxKey(MOBILE));
            myStatsLoadFailedLabel.setVisible(true);
        }));
    }
    if (myFormFactor.equals(MOBILE) && state.getNotNull(WH_SDK_ENABLED_KEY, false)) {
        myBinder.register(IS_INSTANT_APP_KEY, myInstantAppCheckbox);
        myInstantAppCheckbox.setVisible(true);
    }
}
Also used : HyperlinkEvent(javax.swing.event.HyperlinkEvent) Set(java.util.Set) ScopedStateStore(com.android.tools.idea.wizard.dynamic.ScopedStateStore) JBLabel(com.intellij.ui.components.JBLabel) ScopedDataBinder(com.android.tools.idea.wizard.dynamic.ScopedDataBinder) Nullable(org.jetbrains.annotations.Nullable) HyperlinkAdapter(com.intellij.ui.HyperlinkAdapter)

Example 49 with JBLabel

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

the class ResourceDrawablePanel method updateResolutionChain.

private void updateResolutionChain(@NotNull ResourceChooserItem item) {
    // Resource resolver
    myResolvedPanel.removeAll();
    ResourceValue resourceValue = item.getResourceValue();
    Configuration configuration = myDialog.getConfiguration();
    ResourceRepository frameworkResources = configuration.getFrameworkResources();
    if (frameworkResources != null) {
        AppResourceRepository appResources = AppResourceRepository.getAppResources(myDialog.geFacet(), true);
        ResourceItemResolver resolver = new ResourceItemResolver(configuration.getFullConfig(), frameworkResources, appResources, null);
        List<ResourceValue> lookupChain = Lists.newArrayList();
        lookupChain.add(resourceValue);
        resolver.setLookupChainList(lookupChain);
        resolver.resolveResValue(resourceValue);
        String prev = null;
        int indent = 0;
        if (lookupChain.size() >= 2) {
            for (ResourceValue element : lookupChain) {
                if (element == null) {
                    continue;
                }
                String value = element.getValue();
                if (value == null) {
                    continue;
                }
                String text = value;
                if (text.equals(prev)) {
                    continue;
                }
                // Strip paths
                if (!(text.startsWith(PREFIX_THEME_REF) || text.startsWith(PREFIX_RESOURCE_REF))) {
                    if (indent == 0) {
                        break;
                    }
                    int end = Math.max(text.lastIndexOf('/'), text.lastIndexOf('\\'));
                    if (end != -1) {
                        text = text.substring(end + 1);
                    }
                }
                if (indent > 0) {
                    // 21D2: Rightwards arrow
                    text = "⇒ " + text;
                }
                JBLabel label = new JBLabel(text);
                label.setBorder(IdeBorderFactory.createEmptyBorder(0, JBUI.scale(indent * 12), 0, 0));
                myResolvedPanel.add(label);
                indent++;
                prev = value;
            }
        }
    }
}
Also used : FolderConfiguration(com.android.ide.common.resources.configuration.FolderConfiguration) Configuration(com.android.tools.idea.configurations.Configuration) JBLabel(com.intellij.ui.components.JBLabel) ResourceValue(com.android.ide.common.rendering.api.ResourceValue) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceItemResolver(com.android.ide.common.resources.ResourceItemResolver) AppResourceRepository(com.android.tools.idea.res.AppResourceRepository) ResourceRepository(com.android.ide.common.resources.ResourceRepository)

Example 50 with JBLabel

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

the class ChooseResourceDialog method createToolbar.

@NotNull
private JComponent createToolbar() {
    JComponent toolbar = Box.createHorizontalBox();
    toolbar.add(mySearchField);
    toolbar.add(Box.createHorizontalStrut(JBUI.scale(20)));
    toolbar.add(myViewOption);
    toolbar.add(Box.createHorizontalGlue());
    JBLabel addNew = new JBLabel("Add new resource");
    addNew.setIcon(PlatformIcons.COMBOBOX_ARROW_ICON);
    addNew.setHorizontalTextPosition(SwingConstants.LEFT);
    addNew.setIconTextGap(0);
    if (ScreenReader.isActive()) {
        addNew.setFocusable(true);
    }
    toolbar.add(addNew);
    MyAddNewResourceLabelListener listener = new MyAddNewResourceLabelListener();
    addNew.addMouseListener(listener);
    addNew.addKeyListener(listener);
    toolbar.setBorder(new CompoundBorder(JBUI.Borders.customLine(OnePixelDivider.BACKGROUND, 0, 0, 1, 0), JBUI.Borders.empty(8)));
    return toolbar;
}
Also used : JBLabel(com.intellij.ui.components.JBLabel) CompoundBorder(javax.swing.border.CompoundBorder) NotNull(org.jetbrains.annotations.NotNull)

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