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");
}
}
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;
}
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);
}
}
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;
}
}
}
}
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;
}
Aggregations