use of com.intellij.ui.components.JBScrollPane in project intellij-community by JetBrains.
the class MultilineTreeCellRenderer method installRenderer.
public static JScrollPane installRenderer(final JTree tree, final MultilineTreeCellRenderer renderer) {
final TreeCellRenderer defaultRenderer = tree.getCellRenderer();
JScrollPane scrollpane = new JBScrollPane(tree) {
private int myAddRemoveCounter = 0;
private boolean myShouldResetCaches = false;
public void setSize(Dimension d) {
boolean isChanged = getWidth() != d.width || myShouldResetCaches;
super.setSize(d);
if (isChanged)
resetCaches();
}
public void reshape(int x, int y, int w, int h) {
boolean isChanged = w != getWidth() || myShouldResetCaches;
super.reshape(x, y, w, h);
if (isChanged)
resetCaches();
}
private void resetCaches() {
resetHeightCache(tree, defaultRenderer, renderer);
myShouldResetCaches = false;
}
public void addNotify() {
//To change body of overriden methods use Options | File Templates.
super.addNotify();
if (myAddRemoveCounter == 0)
myShouldResetCaches = true;
myAddRemoveCounter++;
}
public void removeNotify() {
//To change body of overriden methods use Options | File Templates.
super.removeNotify();
myAddRemoveCounter--;
}
};
scrollpane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollpane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
tree.setCellRenderer(renderer);
scrollpane.addComponentListener(new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
resetHeightCache(tree, defaultRenderer, renderer);
}
public void componentShown(ComponentEvent e) {
// componentResized not called when adding to opened tool window.
// Seems to be BUG#4765299, however I failed to create same code to reproduce it.
// To reproduce it with IDEA: 1. remove this method, 2. Start any Ant task, 3. Keep message window open 4. start Ant task again.
resetHeightCache(tree, defaultRenderer, renderer);
}
});
return scrollpane;
}
use of com.intellij.ui.components.JBScrollPane in project intellij-community by JetBrains.
the class ShowUIDefaultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final UIDefaults defaults = UIManager.getDefaults();
Enumeration keys = defaults.keys();
final Object[][] data = new Object[defaults.size()][2];
int i = 0;
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
data[i][0] = key;
data[i][1] = defaults.get(key);
i++;
}
Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
final Project project = getEventProject(e);
new DialogWrapper(project) {
{
setTitle("Edit LaF Defaults");
setModal(false);
init();
}
public JBTable myTable;
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return myTable;
}
@Nullable
@Override
protected String getDimensionServiceKey() {
return project == null ? null : "UI.Defaults.Dialog";
}
@Override
protected JComponent createCenterPanel() {
final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 1 && getValueAt(row, column) instanceof Color;
}
}) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (isCellEditable(row, column) && e instanceof MouseEvent) {
final Object color = getValueAt(row, column);
final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
if (newColor != null) {
final ColorUIResource colorUIResource = new ColorUIResource(newColor);
final Object key = getValueAt(row, 0);
UIManager.put(key, colorUIResource);
setValueAt(colorUIResource, row, column);
}
}
return false;
}
};
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(value == null ? "" : value.toString());
panel.add(label, BorderLayout.CENTER);
if (value instanceof Color) {
final Color c = (Color) value;
label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
panel.setBackground(c);
return panel;
} else if (value instanceof Icon) {
try {
final Icon icon = new IconWrap((Icon) value);
if (icon.getIconHeight() <= 20) {
label.setIcon(icon);
}
label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
} catch (Throwable e1) {
//
}
return panel;
} else if (value instanceof Border) {
try {
final Insets i = ((Border) value).getBorderInsets(null);
label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
return panel;
} catch (Exception ignore) {
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
final JBScrollPane pane = new JBScrollPane(table);
new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
table.setShowGrid(false);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
myTable = table;
TableUtil.ensureSelectionExists(myTable);
return panel;
}
}.show();
}
use of com.intellij.ui.components.JBScrollPane in project android by JetBrains.
the class MemoryInstanceView method instanceChanged.
private void instanceChanged() {
if (mySplitter == null || myInstanceObject == myStage.getSelectedInstance()) {
return;
}
myInstanceObject = myStage.getSelectedInstance();
if (myInstanceObject == null) {
mySplitter.setSecondComponent(null);
return;
}
AllocationStack callStack = myInstanceObject.getCallStack();
if (callStack == null || callStack.getStackFramesList().size() == 0) {
return;
}
DefaultListModel<StackTraceElement> model = new DefaultListModel<>();
callStack.getStackFramesList().forEach(frame -> model.addElement(new StackTraceElement(frame.getClassName(), frame.getMethodName(), frame.getFileName(), frame.getLineNumber())));
mySplitter.setSecondComponent(new JBScrollPane(new JBList(model)));
}
use of com.intellij.ui.components.JBScrollPane in project android by JetBrains.
the class ActivityGalleryStep method createGallery.
private JComponent createGallery() {
myGallery = new ASGallery<>();
Dimension thumbnailSize = DEFAULT_GALLERY_THUMBNAIL_SIZE;
myGallery.setThumbnailSize(thumbnailSize);
myGallery.setMinimumSize(new Dimension(thumbnailSize.width * 2 + 1, thumbnailSize.height));
myGallery.setLabelProvider(new Function<Optional<TemplateEntry>, String>() {
@Override
public String apply(Optional<TemplateEntry> template) {
if (template.isPresent()) {
return template.get().getTitle();
} else {
return "Add No Activity";
}
}
});
myGallery.setDefaultAction(new AbstractAction() {
@Override
public void actionPerformed(ActionEvent actionEvent) {
DynamicWizard wizard = getWizard();
assert wizard != null;
wizard.doNextAction();
}
});
myGallery.setImageProvider(new Function<Optional<TemplateEntry>, Image>() {
@Override
public Image apply(Optional<TemplateEntry> input) {
return input.isPresent() ? input.get().getImage() : null;
}
});
myGallery.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
saveState(myGallery);
}
});
myGallery.setName("Templates Gallery");
AccessibleContext accessibleContext = myGallery.getAccessibleContext();
if (accessibleContext != null) {
accessibleContext.setAccessibleDescription(getStepTitle());
}
JPanel panel = new JPanel(new JBCardLayout());
panel.add("only card", new JBScrollPane(myGallery));
return panel;
}
use of com.intellij.ui.components.JBScrollPane in project android by JetBrains.
the class ChooseModuleTypeStep method createGallery.
@NotNull
private JComponent createGallery() {
myFormFactorGallery = new ASGallery<ModuleGalleryEntry>(JBList.createDefaultListModel(), image -> image.getIcon() == null ? null : IconUtil.toImage(image.getIcon()), label -> label == null ? message("android.wizard.gallery.item.none") : label.getName(), DEFAULT_GALLERY_THUMBNAIL_SIZE, null) {
@Override
public Dimension getPreferredScrollableViewportSize() {
// The default implementations assigns a height as tall as the screen.
// When calling setVisibleRowCount(2), the underlying implementation is buggy, and will have a gap on the right and when the user
// resizes, it enters on an adjustment loop at some widths (can't decide to fit 3 or for elements, and loops between the two)
Dimension cellSize = computeCellSize();
int heightInsets = getInsets().top + getInsets().bottom;
int widthInsets = getInsets().left + getInsets().right;
// Don't want to show an exact number of rows, since then it's not obvious there's another row available.
return new Dimension(cellSize.width * 5 + widthInsets, (int) (cellSize.height * 2.2) + heightInsets);
}
};
myFormFactorGallery.setBorder(BorderFactory.createLineBorder(JBColor.border()));
AccessibleContext accessibleContext = myFormFactorGallery.getAccessibleContext();
if (accessibleContext != null) {
accessibleContext.setAccessibleDescription(getTitle());
}
return new JBScrollPane(myFormFactorGallery);
}
Aggregations