Java Code Examples for javax.swing.JList#getForeground()

The following examples show how to use javax.swing.JList#getForeground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixProfile.java    From netbeans with Apache License 2.0 6 votes vote down vote up
LibsRenderer(@NonNull final JList list) {
    this.root = new JLabel();
    this.root.setHorizontalAlignment(LEFT);
    this.root.setOpaque(false);
    this.root.setFont(list.getFont());
    this.profile = new JLabel();
    this.profile.setHorizontalAlignment(RIGHT);
    this.profile.setOpaque(false);
    this.profile.setFont(list.getFont());
    this.container = new JPanel();
    this.container.setLayout(new BorderLayout());
    this.container.add (this.root, BorderLayout.WEST);
    this.container.add (this.profile, BorderLayout.EAST);
    
    fgColor = list.getForeground();
    fgColorLighter = new Color(
        Math.min(255, fgColor.getRed() + LIGHTER_COLOR_COMPONENT),
        Math.min(255, fgColor.getGreen() + LIGHTER_COLOR_COMPONENT),
        Math.min(255, fgColor.getBlue() + LIGHTER_COLOR_COMPONENT));
    bgColor = new Color(list.getBackground().getRGB());
    bgSelectionColor = list.getSelectionBackground();
    fgSelectionColor = list.getSelectionForeground();
}
 
Example 2
Source File: TreeList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (!(value instanceof TreeListNode)) {
        //shoudln't happen
        return new JLabel();
    }
    TreeListNode node = (TreeListNode) value;
    int rowHeight = list.getFixedCellHeight();
    int rowWidth = list.getVisibleRect().width;
    int dropIndex = -1;
    DropLocation dropLocation = list.getDropLocation();
    if (dropLocation != null && !dropLocation.isInsert()) {
        dropIndex = dropLocation.getIndex();
    }
    boolean isDropTarget = dropIndex == index;
    isSelected = isSelected || isDropTarget;
    Color background = isSelected ? list.getSelectionBackground() : list.getBackground();
    Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground();

    return node.getRenderer(foreground, background, isSelected, cellHasFocus, rowHeight, rowWidth);
}
 
Example 3
Source File: SelectionList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent( JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus ) {
    if (!(value instanceof ListNode)) {
        //shoudln't happen
        return new JLabel();
    }
    if( list instanceof SelectionList ) {
        isSelected |= index == ((SelectionList)list).getMouseOverRow();
    }
    ListNode node = (ListNode) value;
    int rowHeight = list.getFixedCellHeight();
    int rowWidth = list.getWidth();
    JScrollPane scroll = ( JScrollPane ) SwingUtilities.getAncestorOfClass( JScrollPane.class, list);
    if( null != scroll )
        rowWidth = scroll.getViewport().getWidth();
    Color background = isSelected ? list.getSelectionBackground() : list.getBackground();
    Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground();

    return node.getListRenderer(foreground, background, isSelected, cellHasFocus, rowHeight, rowWidth);
}
 
Example 4
Source File: RemoveSurroundingCodePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Renderer(JList list) {
    setFont(list.getFont());
    fgColor = list.getForeground();
    bgColor = list.getBackground();
    bgColorDarker = new Color(Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT));
    bgSelectionColor = list.getSelectionBackground();
    fgSelectionColor = list.getSelectionForeground();
}
 
Example 5
Source File: ImportClassPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Renderer( JList list ) {
    setFont( list.getFont() );            
    fgColor = list.getForeground();
    bgColor = list.getBackground();
    bgColorDarker = new Color(
                            Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
                            Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
                            Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT)
                    );
    bgSelectionColor = list.getSelectionBackground();
    fgSelectionColor = list.getSelectionForeground();        
}
 
Example 6
Source File: RunAsRemoteWeb.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private Color getForeground(RemoteConfiguration remoteConfig, JList list, boolean isSelected) {
    if (remoteConfig == RunConfigRemote.MISSING_REMOTE_CONFIGURATION
            || remoteConfig == RunConfigRemote.NO_REMOTE_CONFIGURATION) {
        return UIManager.getColor("nb.errorForeground"); // NOI18N
    }
    return isSelected ? list.getSelectionForeground() : list.getForeground();
}
 
Example 7
Source File: ImportModulePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Renderer(JList list) {
    setFont(list.getFont());
    fgColor = list.getForeground();
    bgColor = list.getBackground();
    bgColorDarker = new Color(
            Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT));
    bgSelectionColor = list.getSelectionBackground();
    fgSelectionColor = list.getSelectionForeground();
}
 
Example 8
Source File: AuthenticationSettingsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends AuthenticationCheckboxListItem> list, AuthenticationCheckboxListItem value,
        int index, boolean isSelected, boolean cellHasFocus) {
    final Color bc;
    final Color fc;
    if (isSelected) {
        bc = UIManager.getColor("List.selectionBackground"); //NOI18N
        fc = UIManager.getColor("List.selectionForeground"); //NOI18N
    } else {
        bc = list.getBackground();
        fc = list.getForeground();
    }
    setBackground(bc); // NOI18N
    setForeground(fc); // NOI18N
    
    label.setBackground(bc);
    label.setForeground(fc);
    label.setText(value.getDisplayName());
    label.setFont(list.getFont());
    
    check.setSelected(value.isSelected());
    check.setBackground(bc);
    check.setForeground(fc);
    check.setEnabled(list.isEnabled());
    
    Border border;
    if (cellHasFocus) {
        border = focusBorder;
    } else {
        border = noFocusBorder;
    }
    setBorder(border);
    
    return this;
}
 
Example 9
Source File: GenerateCodePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public Renderer(JList list) {
    setFont(list.getFont());
    fgColor = list.getForeground();
    bgColor = list.getBackground();
    bgColorDarker = new Color(Math.abs(bgColor.getRed() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getGreen() - DARKER_COLOR_COMPONENT),
            Math.abs(bgColor.getBlue() - DARKER_COLOR_COMPONENT));
    bgSelectionColor = list.getSelectionBackground();
    fgSelectionColor = list.getSelectionForeground();
}
 
Example 10
Source File: ConfigurationRenderer.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
    
    if (value != null) {
        if (value instanceof Configuration) {
            setText(((Configuration) value).getDisplayName());
        } else {
            setText(value.toString());
        }
    }

    if (!bordersInitialized) {
        //#222894: the original border must be kept for GTK
        originalBorder = getBorder();
        Separator separator = new Separator(list.getForeground());
        if (originalBorder != null) separatorBorder = new CompoundBorder(originalBorder, separator);
        else separatorBorder = separator;
        bordersInitialized = true;
    }
    
    if (index == list.getModel().getSize()-5 && ((ConfigurationsComboModel) list.getModel()).canModify() ) {
        setBorder(separatorBorder);
    } else {
        setBorder(originalBorder);
    }
    
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    // #89393: GTK needs name to render cell renderer "natively"
    setName("ComboBox.listRenderer"); // NOI18N
    return this;
}
 
Example 11
Source File: PageListCellRenderer.java    From wpcleaner with Apache License 2.0 4 votes vote down vote up
@Override
public Component getListCellRendererComponent(
    JList<? extends Page> list,
    Page value,
    @SuppressWarnings("unused") int index,
    boolean isSelected,
    @SuppressWarnings("unused") boolean cellHasFocus) {

  // Retrieve data
  String pageName = (value != null) ? value.toString() : "";
  String text = pageName;
  Boolean disambiguation = null;
  Boolean exist = null;
  boolean redirect = false;
  InternalLinkCount count = null;
  if (value != null) {
    Page pageElement = value;
    pageName = pageElement.getTitle();
    text = pageName;
    disambiguation = pageElement.isDisambiguationPage();
    exist = pageElement.isExisting();
    count = (analysis != null) ? analysis.getLinkCount(pageElement) : null;
    if (showCountOccurrence &&
        (count != null) &&
        (count.getTotalLinkCount() > 0)) {
      text += " → " + count.getTotalLinkCount(); 
    }
    redirect = pageElement.getRedirects().isRedirect();
    if (redirect && showRedirectBacklinks) {
      Integer backlinks = pageElement.getBacklinksCountInMainNamespace();
      if ((backlinks != null) && (backlinks.intValue() > 0)) {
        text += " ← " + backlinks;
      }
    }
  }

  // Text
  setText(text);

  // Color
  Color background = isSelected ? list.getSelectionBackground() : Color.WHITE;
  Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground();
  if (showDisambiguation) {
    if (disambiguation == null) {
      if (!isSelected) {
        foreground = Color.DARK_GRAY;
      }
    } else if (disambiguation.booleanValue()) {
      if (count == null) {
        foreground = Color.RED;
      } else if ((count.getInternalLinkCount() > 0) || (count.getIncorrectTemplateCount() > 0)) {
        foreground = Color.RED;
      } else if ((count.getHelpNeededCount() > 0)) {
        foreground = Color.ORANGE;
      } else {
        foreground = Color.BLUE;
      }
    }
  } else if (pageProperties != null) {
    String property = pageProperties.getProperty(pageName);
    if (Configuration.VALUE_PAGE_NORMAL.equals(property)) {
      foreground = Color.GREEN;
    } else if (Configuration.VALUE_PAGE_HELP_NEEDED.equals(property)) {
      foreground = Color.ORANGE;
    }
  }
  setBackground(background);
  setForeground(foreground);

  // Font
  if (showMissing && Boolean.FALSE.equals(exist)) {
    setFont(missingFont);
  } else if (showRedirect && redirect) {
    setFont(redirectFont);
  } else {
    setFont(normalFont);
  }

  return this;
}
 
Example 12
Source File: CheckErrorPageListCellRenderer.java    From wpcleaner with Apache License 2.0 4 votes vote down vote up
@Override
public Component getListCellRendererComponent(
    JList<? extends CheckErrorPage> list,
    CheckErrorPage value,
    @SuppressWarnings("unused") int index,
    boolean isSelected,
    @SuppressWarnings("unused") boolean cellHasFocus) {

  // Retrieve data
  String text = (value != null) ? value.toString() : "";
  Boolean errorsPresent = null;
  Boolean globalFix = null;
  boolean whiteList = false;
  if (value != null) {
    CheckErrorPage errorPage = value;
    whiteList = errorPage.isInWhiteList();
    if (forPage && (errorPage.getPage() != null)) {
      text = errorPage.getPage().getTitle();
    } else {
      text = errorPage.getAlgorithm().toString();
      int errorCount = errorPage.getActiveResultsCount();
      if (errorCount > 0) {
        errorsPresent = Boolean.TRUE;
        if ((showCountOccurence) &&
            (errorCount > 1)) {
          text += " (" + errorCount + ")";
        }
      } else if (errorPage.getErrorFound()) {
        errorsPresent = Boolean.TRUE;
      } else {
        errorsPresent = Boolean.FALSE;
      }
      String[] globalFixes = errorPage.getAlgorithm().getGlobalFixes();
      if ((globalFixes != null) && (globalFixes.length > 0)) {
        globalFix = Boolean.TRUE;
      }
    }
  }

  // Text
  setText(text);
  if (Boolean.TRUE.equals(globalFix)) {
    setIcon(globalFixIcon);
  } else {
    setIcon(null);
  }

  // Color
  Color background = isSelected ? new Color(230, 230, 230) : Color.WHITE;
  Color foreground = list.getForeground();
  if (forPage) {
    if (whiteList) {
      foreground = Color.GREEN;
    }
  } else if (errorsPresent == null) {
    if (!isSelected) {
      foreground = Color.DARK_GRAY;
    }
  } else if (whiteList) {
    foreground = Color.GREEN;
  } else if (errorsPresent.booleanValue()) {
    foreground = Color.RED;
  }
  setBackground(background);
  setForeground(foreground);

  return this;
}