public NavBarItem(NavBarPanel panel, Object object, int idx, Disposable parent) { // count++; // System.out.println(count); myPanel = panel; myUI = panel.getNavBarUI(); myObject = object; myIndex = idx; isPopupElement = idx == -1; if (object != null) { final NavBarPresentation presentation = myPanel.getPresentation(); myText = presentation.getPresentableText(object); Icon icon = presentation.getIcon(object); myIcon = icon != null ? icon : EmptyIcon.create(5); myAttributes = presentation.getTextAttributes(object, false); } else { myText = "Sample"; myIcon = PlatformIcons.DIRECTORY_CLOSED_ICON; myAttributes = SimpleTextAttributes.REGULAR_ATTRIBUTES; } Disposer.register(parent == null ? panel : parent, this); setOpaque(false); setIpad(myUI.getElementIpad(isPopupElement)); if (!isPopupElement) { setMyBorder(null); setBorder(null); setPaintFocusBorder(false); } update(); }
@NotNull @Override public Dimension getPreferredSize() { final Dimension size = super.getPreferredSize(); final Dimension offsets = myUI.getOffsets(this); return new Dimension(size.width + offsets.width, size.height + offsets.height); }
@Override protected void doPaint(Graphics2D g) { if (isPopupElement) { super.doPaint(g); } else { myUI.doPaintNavBarItem(g, this, myPanel); } }
void update() { clear(); setIcon(myIcon); final boolean focused = isFocusedOrPopupElement(); final boolean selected = isSelected(); setFocusBorderAroundIcon(false); setBackground(myUI.getBackground(selected, focused)); Color fg = myUI.getForeground(selected, focused, isInactive()); if (fg == null) fg = myAttributes.getFgColor(); final Color bg = getBackground(); append( myText, new SimpleTextAttributes(bg, fg, myAttributes.getWaveColor(), myAttributes.getStyle())); // repaint(); }
@Override public Font getFont() { return myUI == null ? super.getFont() : myUI.getElementFont(this); }
@Override protected boolean shouldDrawMacShadow() { return myUI.isDrawMacShadow(isSelected(), isFocused()); }