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