private static int getComboBoxBaselineResizeBehavior(JComboBox cb) { if (cb.isEditable()) { return getBaselineResizeBehavior(cb.getEditor().getEditorComponent()); } ListCellRenderer renderer = cb.getRenderer(); if (renderer == null) { if (brbListCellRenderer == null) { brbListCellRenderer = new DefaultListCellRenderer(); } renderer = brbListCellRenderer; } Object value = null; Object prototypeValue = cb.getPrototypeDisplayValue(); if (prototypeValue != null) { value = prototypeValue; } else if (cb.getModel().getSize() > 0) { value = cb.getModel().getElementAt(0); } if (value != null) { if (brbList == null) { brbList = new JList(); } Component component = renderer.getListCellRendererComponent(brbList, value, -1, false, false); return getBaselineResizeBehavior(component); } return BRB_OTHER; }
@Override public void paint(Graphics g, JComponent comp) { Graphics2D g2 = (Graphics2D) g; g2.setColor(Colors.GRAY); g2.fillRect(0, 0, comp.getWidth(), comp.getHeight()); ListCellRenderer renderer = ((JComboBox) comp).getRenderer(); Component c = renderer.getListCellRendererComponent( this.listBox, ((JComboBox) comp).getSelectedItem(), -1, false, false); this.currentValuePane.paintComponent( g2, c, this.comboBox, 0, 0, comp.getWidth(), comp.getHeight()); }
// PENDING JW: this isn't aware of sorting/filtering - fix! private static boolean pointIsInActualBounds(JList list, int index, Point point) { ListCellRenderer renderer = list.getCellRenderer(); ListModel model = list.getModel(); Object element = model.getElementAt(index); Component comp = renderer.getListCellRendererComponent(list, element, index, false, false); Dimension prefSize = comp.getPreferredSize(); Rectangle cellBounds = list.getCellBounds(index, index); if (!(comp.getComponentOrientation().isLeftToRight())) { cellBounds.x += cellBounds.width - prefSize.width; } cellBounds.width = prefSize.width; return cellBounds.contains(point); }
public void paintCurrentValue(Graphics g, Rectangle bounds, boolean hasFocus) { ListCellRenderer renderer = comboBox.getRenderer(); Component c; Dimension d; c = renderer.getListCellRendererComponent( listBox, comboBox.getSelectedItem(), -1, false, false); c.setFont(comboBox.getFont()); if (comboBox.isEnabled()) { c.setForeground(comboBox.getForeground()); c.setBackground(comboBox.getBackground()); } else { c.setForeground(UIManager.getColor("ComboBox.disabledForeground")); c.setBackground(UIManager.getColor("ComboBox.disabledBackground")); } d = c.getPreferredSize(); currentValuePane.paintComponent(g, c, comboBox, bounds.x, bounds.y, bounds.width, d.height); }
/** * Calculates the placement and size of the popup portion of the combo box based on the combo * box location and the enclosing screen bounds. If no transformations are required, then the * returned rectangle will have the same values as the parameters. * * <p>In addition to the superclass behavior, this class offers to use the combo's popup * prototype display value to compute the popup menu width. This is an optional feature of the * JGoodies Plastic L&fs implemented via a client property key. * * <p>If a prototype is set, the popup width is the maximum of the combobox width and the * prototype based popup width. For the latter the renderer is used to render the prototype. The * prototype based popup width is the prototype's width plus the scrollbar width - if any. The * scrollbar test checks if there are more items than the combo's maximum row count. * * @param px starting x location * @param py starting y location * @param pw starting width * @param ph starting height * @return a rectangle which represents the placement and size of the popup * @see Options#COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY * @see JComboBox#getMaximumRowCount() */ protected Rectangle computePopupBounds(int px, int py, int pw, int ph) { Rectangle defaultBounds = super.computePopupBounds(px, py, pw, ph); Object popupPrototypeDisplayValue = comboBox.getClientProperty(Options.COMBO_POPUP_PROTOTYPE_DISPLAY_VALUE_KEY); if (popupPrototypeDisplayValue == null) { return defaultBounds; } ListCellRenderer renderer = list.getCellRenderer(); Component c = renderer.getListCellRendererComponent(list, popupPrototypeDisplayValue, -1, true, true); pw = c.getPreferredSize().width; boolean hasVerticalScrollBar = comboBox.getItemCount() > comboBox.getMaximumRowCount(); if (hasVerticalScrollBar) { // Add the scrollbar width. JScrollBar verticalBar = scroller.getVerticalScrollBar(); pw += verticalBar.getPreferredSize().width; } Rectangle prototypeBasedBounds = super.computePopupBounds(px, py, pw, ph); return prototypeBasedBounds.width > defaultBounds.width ? prototypeBasedBounds : defaultBounds; }
/** {@inheritDoc} */ @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof AttributeType) { AttributeType attr = (AttributeType) value; if (inheritedOptionalAttributes.contains(value) || inheritedRequiredAttributes.contains(value)) { value = attr.getNameOrOID() + " (*)"; } else { value = attr.getNameOrOID(); } } return defaultRenderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); }
@Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { JPanel panel = new JPanel(); JCheckBox checkBox = new JCheckBox(); panel.setLayout(new BorderLayout()); panel.setOpaque(false); checkBox.setOpaque(false); Component renderer = delegateRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); checkBox.setSelected(model.isSelectedIndex(index)); panel.add(checkBox, BorderLayout.WEST); panel.add(renderer, BorderLayout.CENTER); panel.setToolTipText(((JLabel) renderer).getToolTipText()); return panel; }
@Override public Component getListCellRendererComponent( JList<? extends BundleItem> jList, BundleItem bi, int i, boolean b, boolean b2) { Component lafComp = lookAndFeelRenderer.getListCellRendererComponent(jList, bi, i, b, b2); if (lafComp instanceof JLabel && bi != null) { try { JLabel label = (JLabel) lafComp; ImageIcon bundleImage = defaultIcon; // Open the bundle icon if defined if (bi.getBundle() != null) { Bundle bundle = bi.getBundle(); try { ImageIcon customBundleImage = getBundleIcon(bundle); if (customBundleImage != null) { bundleImage = customBundleImage; } } catch (Exception ex) { // If bundle state is not ready or an error occur when loading // an icon then show the default icon. LOGGER.error(ex.getLocalizedMessage(), ex); } } if (bi.getBundle() != null && bi.getBundle().getState() == Bundle.ACTIVE) { label.setIcon(mergeIcons(bundleImage.getImage(), activeLayer.getImage())); } else if (bi.getBundle() == null && bi.getObrResource() != null) { label.setIcon(obrIcon); } else { label.setIcon(bundleImage); } StringBuilder sb = new StringBuilder(); sb.append("<html><h4>"); sb.append(bi.getPresentationName()); sb.append(" ("); sb.append(bi.getVersion()); sb.append(")</h4>"); sb.append(bi.getShortDescription()); sb.append("</html>"); label.setText(sb.toString()); } catch (Exception ex) { LOGGER.error(ex.getLocalizedMessage(), ex); } } return lafComp; }
public final Component getListCellRendererComponent( final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { mySeparator = false; myIcon = null; myText = null; myForeground = null; myBackground = null; myFont = null; myToolTipText = null; @SuppressWarnings("unchecked") final T t = (T) value; customize(list, t, index, isSelected, cellHasFocus); if (mySeparator) { final TitledSeparator separator = new TitledSeparator(myText); separator.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0)); if (!UIUtil.isUnderGTKLookAndFeel()) { separator.setOpaque(false); separator.setBackground(UIUtil.TRANSPARENT_COLOR); separator.getLabel().setOpaque(false); separator.getLabel().setBackground(UIUtil.TRANSPARENT_COLOR); } return separator; } final Component component = myOriginalRenderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); if (component instanceof JLabel) { final JLabel label = (JLabel) component; label.setIcon(myIcon); if (myText != null) label.setText(myText); if (myForeground != null) label.setForeground(myForeground); if (myBackground != null && !isSelected) label.setBackground(myBackground); if (myFont != null) label.setFont(myFont); label.setToolTipText(myToolTipText); } return component; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (index == -1) { Component comp = cellRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); return comp; } getTableListCellRendererModel().setRow(index); setComponentOrientation(list.getComponentOrientation()); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else { setBackground(list.getBackground()); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); Border border = null; if (cellHasFocus) { if (isSelected) { border = UIManager.getBorder("List.focusSelectedCellHighlightBorder"); } if (border == null) { border = UIManager.getBorder("List.focusCellHighlightBorder"); } } else { border = getNoFocusBorder(); } setBorder(border); if (index == 0) { headerPanel.add(this); return headerPanel; } return this; }
public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { String message; if (value == null) { message = ""; // NOI18N } else { assert value instanceof SourceLevelKey; SourceLevelKey key = (SourceLevelKey) value; if (key.isBroken()) { message = "<html><font color=\"#A40000\">" // NOI18N + NbBundle.getMessage( PlatformUiSupport.class, "TXT_InvalidSourceLevel", // NOI18N key.getDisplayName()); } else { message = key.getDisplayName(); } } return delegate.getListCellRendererComponent(list, message, index, isSelected, cellHasFocus); }
/* * (non-Javadoc) * * @see org.protege.editor.owl.ui.renderer.OWLCellRenderer# * getListCellRendererComponent(javax.swing.JList, java.lang.Object, int, * boolean, boolean) */ @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { objectToRender = value; if (objectToRender instanceof OWLAxiomChange) { value = ((OWLOntologyChange) objectToRender).getAxiom(); } else if (objectToRender instanceof OWLAxiomChange) { value = ((ImportChange) objectToRender).getImportDeclaration(); } else if (objectToRender instanceof AddOntologyAnnotation) { value = ((AddOntologyAnnotation) objectToRender).getAnnotation(); } else if (objectToRender instanceof RemoveOntologyAnnotation) { value = ((RemoveOntologyAnnotation) objectToRender).getAnnotation(); } else { // do nothing } if (value instanceof String) { return defaultListCellRenderer.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); } else { return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); } }