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