public static Icon getEvenIcon(Icon icon) { LayeredIcon layeredIcon = new LayeredIcon(2); layeredIcon.setIcon(EMPTY_ICON, 0); if (icon != null && icon.getIconHeight() <= EMPTY_ICON.getIconHeight() && icon.getIconWidth() <= EMPTY_ICON.getIconWidth()) { layeredIcon.setIcon( icon, 1, (-icon.getIconWidth() + EMPTY_ICON.getIconWidth()) / 2, (EMPTY_ICON.getIconHeight() - icon.getIconHeight()) / 2); } return layeredIcon; }
public static Icon augmentIcon(@Nullable Icon icon, @NotNull Icon standard) { if (icon == null) { return standard; } if (icon.getIconHeight() < standard.getIconHeight() || icon.getIconWidth() < standard.getIconWidth()) { final LayeredIcon layeredIcon = new LayeredIcon(2); layeredIcon.setIcon(icon, 0, 0, (standard.getIconHeight() - icon.getIconHeight()) / 2); layeredIcon.setIcon(standard, 1); return layeredIcon; } return icon; }
int updateMaximumWidth(final LookupElementPresentation p, LookupElement item) { final Icon icon = p.getIcon(); if (icon != null && (icon.getIconWidth() > myEmptyIcon.getIconWidth() || icon.getIconHeight() > myEmptyIcon.getIconHeight())) { myEmptyIcon = new EmptyIcon( Math.max(icon.getIconWidth(), myEmptyIcon.getIconWidth()), Math.max(icon.getIconHeight(), myEmptyIcon.getIconHeight())); } return RealLookupElementPresentation.calculateWidth( p, getRealFontMetrics(item, false), getRealFontMetrics(item, true)) + AFTER_TAIL + AFTER_TYPE; }
private JComponent createActionPanel() { JPanel actions = new NonOpaquePanel(); actions.setBorder(JBUI.Borders.emptyLeft(10)); actions.setLayout(new BoxLayout(actions, BoxLayout.Y_AXIS)); ActionManager actionManager = ActionManager.getInstance(); ActionGroup quickStart = (ActionGroup) actionManager.getAction(IdeActions.GROUP_WELCOME_SCREEN_QUICKSTART); DefaultActionGroup group = new DefaultActionGroup(); collectAllActions(group, quickStart); for (AnAction action : group.getChildren(null)) { JPanel button = new JPanel(new BorderLayout()); button.setOpaque(false); button.setBorder(JBUI.Borders.empty(8, 20)); AnActionEvent e = AnActionEvent.createFromAnAction( action, null, ActionPlaces.WELCOME_SCREEN, DataManager.getInstance().getDataContext(this)); action.update(e); Presentation presentation = e.getPresentation(); if (presentation.isVisible()) { String text = presentation.getText(); if (text != null && text.endsWith("...")) { text = text.substring(0, text.length() - 3); } Icon icon = presentation.getIcon(); if (icon.getIconHeight() != JBUI.scale(16) || icon.getIconWidth() != JBUI.scale(16)) { icon = JBUI.emptyIcon(16); } action = wrapGroups(action); ActionLink link = new ActionLink(text, icon, action, createUsageTracker(action)); link.setPaintUnderline(false); link.setNormalColor(getLinkNormalColor()); button.add(link); if (action instanceof WelcomePopupAction) { button.add(createArrow(link), BorderLayout.EAST); } installFocusable(button, action, KeyEvent.VK_UP, KeyEvent.VK_DOWN, true); actions.add(button); } } WelcomeScreenActionsPanel panel = new WelcomeScreenActionsPanel(); panel.actions.add(actions); return panel.root; }
private int setTypeTextLabel( LookupElement item, final Color background, Color foreground, final LookupElementPresentation presentation, int allowedWidth, boolean selected, boolean nonFocusedSelection, FontMetrics normalMetrics) { final String givenText = presentation.getTypeText(); final String labelText = trimLabelText( StringUtil.isEmpty(givenText) ? "" : " " + givenText, allowedWidth, normalMetrics); int used = RealLookupElementPresentation.getStringWidth(labelText, normalMetrics); final Icon icon = presentation.getTypeIcon(); if (icon != null) { myTypeLabel.setIcon(icon); used += icon.getIconWidth(); } Color sampleBackground = background; Object o = item.isValid() ? item.getObject() : null; //noinspection deprecation if (o instanceof LookupValueWithUIHint && StringUtil.isEmpty(labelText)) { //noinspection deprecation Color proposedBackground = ((LookupValueWithUIHint) o).getColorHint(); if (proposedBackground != null) { sampleBackground = proposedBackground; } myTypeLabel.append(" "); used += normalMetrics.stringWidth("WW"); } else { myTypeLabel.append(labelText); } myTypeLabel.setBackground(sampleBackground); myTypeLabel.setForeground( getTypeTextColor(item, foreground, presentation, selected, nonFocusedSelection)); return used; }
public RegistryUi() { myContent.setLayout(new BorderLayout(UIUtil.DEFAULT_HGAP, UIUtil.DEFAULT_VGAP)); myModel = new MyTableModel(); myTable = new JBTable(myModel); myTable.setCellSelectionEnabled(true); myTable.setEnableAntialiasing(true); final MyRenderer r = new MyRenderer(); final TableColumn c0 = myTable.getColumnModel().getColumn(0); c0.setCellRenderer(r); c0.setMaxWidth(RESTART_ICON.getIconWidth() + 12); c0.setMinWidth(RESTART_ICON.getIconWidth() + 12); c0.setHeaderValue(null); final TableColumn c1 = myTable.getColumnModel().getColumn(1); c1.setCellRenderer(r); c1.setHeaderValue("Key"); final TableColumn c2 = myTable.getColumnModel().getColumn(2); c2.setCellRenderer(r); c2.setHeaderValue("Value"); c2.setCellEditor(new MyEditor()); myTable.setStriped(true); myDescriptionLabel = new JTextArea(3, 50); myDescriptionLabel.setEditable(false); final JScrollPane label = ScrollPaneFactory.createScrollPane(myDescriptionLabel); final JPanel descriptionPanel = new JPanel(new BorderLayout()); descriptionPanel.add(label, BorderLayout.CENTER); descriptionPanel.setBorder( IdeBorderFactory.createTitledBorder("Description", false, false, true)); myContent.add(ScrollPaneFactory.createScrollPane(myTable), BorderLayout.CENTER); myContent.add(descriptionPanel, BorderLayout.SOUTH); myTable .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; final int selected = myTable.getSelectedRow(); if (selected != -1) { final RegistryValue value = myModel.getRegistryValue(selected); String desc = value.getDescription(); if (value.isRestartRequired()) { String required = "Requires IDE restart."; if (desc.endsWith(".")) { desc += required; } else { desc += (". " + required); } } myDescriptionLabel.setText(desc); } else { myDescriptionLabel.setText(null); } } }); myRestoreDefaultsAction = new RestoreDefaultsAction(); final DefaultActionGroup tbGroup = new DefaultActionGroup(); tbGroup.add(new EditAction()); tbGroup.add(new RevertAction()); final ActionToolbar tb = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, tbGroup, true); tb.setTargetComponent(myTable); myContent.add(tb.getComponent(), BorderLayout.NORTH); new TableSpeedSearch(myTable).setComparator(new SpeedSearchComparator(false)); }
public int getIconIndent() { return myNameComponent.getIconTextGap() + myEmptyIcon.getIconWidth(); }