use of javax.swing.border.Border in project intellij-community by JetBrains.
the class LeftHandScrollbarLayout method preferredLayoutSize.
/**
* The preferred size of a <code>ScrollPane</code> is the size of the insets,
* plus the preferred size of the viewport, plus the preferred size of
* the visible headers, plus the preferred size of the scrollbars
* that will appear given the current view and the current
* scrollbar displayPolicies.
* <p>Note that the rowHeader is calculated as part of the preferred width
* and the colHeader is calculated as part of the preferred size.
*
* @param parent the <code>Container</code> that will be laid out
* @return a <code>Dimension</code> object specifying the preferred size of the
* viewport and any scrollbars
* @see ViewportLayout
* @see LayoutManager
*/
@Override
public Dimension preferredLayoutSize(Container parent) {
/* Sync the (now obsolete) policy fields with the
* JScrollPane.
*/
JScrollPane scrollPane = (JScrollPane) parent;
vsbPolicy = scrollPane.getVerticalScrollBarPolicy();
hsbPolicy = scrollPane.getHorizontalScrollBarPolicy();
Insets insets = parent.getInsets();
int prefWidth = insets.left + insets.right;
int prefHeight = insets.top + insets.bottom;
/* Note that viewport.getViewSize() is equivalent to
* viewport.getView().getPreferredSize() modulo a null
* view or a view whose size was explicitly set.
*/
Dimension extentSize = null;
Dimension viewSize = null;
Component view = null;
if (viewport != null) {
extentSize = viewport.getPreferredSize();
viewSize = viewport.getViewSize();
view = viewport.getView();
}
if (extentSize != null) {
prefWidth += extentSize.width;
prefHeight += extentSize.height;
}
/* If there's a JScrollPane.viewportBorder, add its insets.
*/
Border viewportBorder = scrollPane.getViewportBorder();
if (viewportBorder != null) {
Insets vpbInsets = viewportBorder.getBorderInsets(parent);
prefWidth += vpbInsets.left + vpbInsets.right;
prefHeight += vpbInsets.top + vpbInsets.bottom;
}
if ((rowHead != null) && rowHead.isVisible()) {
prefWidth += rowHead.getPreferredSize().width;
}
if ((colHead != null) && colHead.isVisible()) {
prefHeight += colHead.getPreferredSize().height;
}
if ((vsb != null) && (vsbPolicy != VERTICAL_SCROLLBAR_NEVER)) {
if (vsbPolicy == VERTICAL_SCROLLBAR_ALWAYS) {
prefWidth += vsb.getPreferredSize().width;
} else if ((viewSize != null) && (extentSize != null)) {
boolean canScroll = true;
if (view instanceof Scrollable) {
canScroll = !((Scrollable) view).getScrollableTracksViewportHeight();
}
if (canScroll && (viewSize.height > extentSize.height)) {
prefWidth += vsb.getPreferredSize().width;
}
}
}
if ((hsb != null) && (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)) {
if (hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
prefHeight += hsb.getPreferredSize().height;
} else if ((viewSize != null) && (extentSize != null)) {
boolean canScroll = true;
if (view instanceof Scrollable) {
canScroll = !((Scrollable) view).getScrollableTracksViewportWidth();
}
if (canScroll && (viewSize.width > extentSize.width)) {
prefHeight += hsb.getPreferredSize().height;
}
}
}
return new Dimension(prefWidth, prefHeight);
}
use of javax.swing.border.Border in project intellij-community by JetBrains.
the class TextFieldAction method createCustomComponent.
@Override
public JComponent createCustomComponent(Presentation presentation) {
// honestly borrowed from SearchTextField
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(myIcon);
label.setOpaque(true);
label.setBackground(myField.getBackground());
myField.setOpaque(true);
panel.add(myField, BorderLayout.WEST);
panel.add(label, BorderLayout.EAST);
myField.setToolTipText(myDescription);
label.setToolTipText(myDescription);
final Border originalBorder;
if (SystemInfo.isMac) {
originalBorder = BorderFactory.createLoweredBevelBorder();
} else {
originalBorder = myField.getBorder();
}
panel.setBorder(new CompoundBorder(IdeBorderFactory.createEmptyBorder(4, 0, 4, 0), originalBorder));
myField.setOpaque(true);
myField.setBorder(IdeBorderFactory.createEmptyBorder(0, 5, 0, 5));
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent e, int clickCount) {
actionPerformed(null);
return true;
}
}.installOn(label);
return panel;
}
use of javax.swing.border.Border in project intellij-community by JetBrains.
the class SearchUtil method traverseComponentsTree.
private static boolean traverseComponentsTree(SearchableConfigurable configurable, GlassPanel glassPanel, JComponent rootComponent, String option, boolean force) {
rootComponent.putClientProperty(HIGHLIGHT_WITH_BORDER, null);
if (option == null || option.trim().length() == 0)
return false;
boolean highlight = false;
if (rootComponent instanceof JCheckBox) {
final JCheckBox checkBox = ((JCheckBox) rootComponent);
if (isComponentHighlighted(checkBox.getText(), option, force, configurable)) {
highlight = true;
glassPanel.addSpotlight(checkBox);
}
} else if (rootComponent instanceof JRadioButton) {
final JRadioButton radioButton = ((JRadioButton) rootComponent);
if (isComponentHighlighted(radioButton.getText(), option, force, configurable)) {
highlight = true;
glassPanel.addSpotlight(radioButton);
}
} else if (rootComponent instanceof JLabel) {
final JLabel label = ((JLabel) rootComponent);
if (isComponentHighlighted(label.getText(), option, force, configurable)) {
highlight = true;
glassPanel.addSpotlight(label);
}
} else if (rootComponent instanceof JButton) {
final JButton button = ((JButton) rootComponent);
if (isComponentHighlighted(button.getText(), option, force, configurable)) {
highlight = true;
glassPanel.addSpotlight(button);
}
} else if (rootComponent instanceof JTabbedPane) {
final JTabbedPane tabbedPane = (JTabbedPane) rootComponent;
final String path = SearchableOptionsRegistrar.getInstance().getInnerPath(configurable, option);
if (path != null) {
final int index = getSelection(path, tabbedPane);
if (index > -1 && index < tabbedPane.getTabCount()) {
if (tabbedPane.getTabComponentAt(index) instanceof JComponent) {
glassPanel.addSpotlight((JComponent) tabbedPane.getTabComponentAt(index));
}
}
}
} else if (rootComponent instanceof TabbedPaneWrapper.TabbedPaneHolder) {
final TabbedPaneWrapper tabbedPaneWrapper = ((TabbedPaneWrapper.TabbedPaneHolder) rootComponent).getTabbedPaneWrapper();
final String path = SearchableOptionsRegistrar.getInstance().getInnerPath(configurable, option);
if (path != null) {
final int index = getSelection(path, tabbedPaneWrapper);
if (index > -1 && index < tabbedPaneWrapper.getTabCount()) {
glassPanel.addSpotlight((JComponent) tabbedPaneWrapper.getTabComponentAt(index));
}
}
}
final Component[] components = rootComponent.getComponents();
for (Component component : components) {
if (component instanceof JComponent) {
final boolean innerHighlight = traverseComponentsTree(configurable, glassPanel, (JComponent) component, option, force);
if (!highlight && !innerHighlight) {
final Border border = rootComponent.getBorder();
if (border instanceof TitledBorder) {
final String title = ((TitledBorder) border).getTitle();
if (isComponentHighlighted(title, option, force, configurable)) {
highlight = true;
glassPanel.addSpotlight(rootComponent);
rootComponent.putClientProperty(HIGHLIGHT_WITH_BORDER, Boolean.TRUE);
}
}
}
if (innerHighlight) {
highlight = true;
}
}
}
return highlight;
}
use of javax.swing.border.Border in project intellij-community by JetBrains.
the class StripeButton method init.
private void init() {
setFocusable(false);
setBackground(ourBackgroundColor);
final Border border = JBUI.Borders.empty(5, 5, 0, 5);
setBorder(border);
updatePresentation();
apply(myDecorator.getWindowInfo());
addActionListener(this);
addMouseListener(new MyPopupHandler());
setRolloverEnabled(true);
setOpaque(false);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(final MouseEvent e) {
processDrag(e);
}
});
KeymapManager.getInstance().addKeymapManagerListener(myKeymapListener, this);
}
use of javax.swing.border.Border 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();
}
Aggregations