示例#1
0
 @Override
 public Component getListCellRendererComponent(
     JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) {
   label.setText(Objects.toString(value, ""));
   this.list = list;
   this.index = index;
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     label.setForeground(list.getSelectionForeground());
   } else {
     setBackground(index % 2 == 0 ? EVEN_COLOR : list.getBackground());
     label.setForeground(list.getForeground());
   }
   MutableComboBoxModel m = (MutableComboBoxModel) list.getModel();
   if (index < 0 || m.getSize() - 1 <= 0) {
     setOpaque(false);
     deleteButton.setVisible(false);
     label.setForeground(list.getForeground());
   } else {
     boolean f = index == rolloverIndex;
     setOpaque(true);
     deleteButton.setVisible(true);
     deleteButton.getModel().setRollover(f);
     deleteButton.setForeground(f ? Color.WHITE : list.getForeground());
   }
   return this;
 }
示例#2
0
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      // #93658: GTK needs name to render cell renderer "natively"
      setName("ComboBox.listRenderer"); // NOI18N

      String config = (String) value;
      String label;
      if (config == null) {
        // uninitialized?
        label = null;
      } else if (config.length() > 0) {
        Map<String, String> m = configs.get(config);
        label = m != null ? m.get("$label") : /* temporary? */ null; // NOI18N
        if (label == null) {
          label = config;
        }
      } else {
        label =
            NbBundle.getBundle("org.netbeans.modules.java.j2seproject.Bundle")
                .getString("J2SEConfigurationProvider.default.label"); // NOI18N
      }
      setText(label);

      if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
      } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
      }

      return this;
    }
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

    /**
     * if (isSelected) { setBackground(UIManager.getColor("ComboBox.selectionBackground"));
     * setForeground(UIManager.getColor("ComboBox.selectionForeground")); } else {
     * setBackground(UIManager.getColor("ComboBox.background"));
     * setForeground(UIManager.getColor("ComboBox.foreground")); }*
     */
    if (isSelected) {
      setBackground(list.getSelectionBackground());
      setForeground(list.getSelectionForeground());
    } else {
      setBackground(list.getBackground());
      setForeground(list.getForeground());
    }

    setFont(list.getFont());

    if (value instanceof Icon) {
      setIcon((Icon) value);
    } else {
      setText((value == null) ? "" : value.toString());
    }
    return this;
  }
  @Override
  protected boolean customizeNonPsiElementLeftRenderer(
      ColoredListCellRenderer renderer,
      JList list,
      Object value,
      int index,
      boolean selected,
      boolean hasFocus) {
    if (!(value instanceof NavigationItem)) return false;

    NavigationItem item = (NavigationItem) value;

    TextAttributes attributes = getNavigationItemAttributes(item);

    SimpleTextAttributes nameAttributes =
        attributes != null ? SimpleTextAttributes.fromTextAttributes(attributes) : null;

    Color color = list.getForeground();
    if (nameAttributes == null) nameAttributes = new SimpleTextAttributes(Font.PLAIN, color);

    renderer.append(item + " ", nameAttributes);
    ItemPresentation itemPresentation = item.getPresentation();
    assert itemPresentation != null;
    renderer.setIcon(itemPresentation.getIcon(true));

    String locationString = itemPresentation.getLocationString();
    if (!StringUtil.isEmpty(locationString)) {
      renderer.append(locationString, new SimpleTextAttributes(Font.PLAIN, JBColor.GRAY));
    }
    return true;
  }
示例#5
0
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (value != null) {
      panel.setTodoItem((TodoItem) value);
    }
    if (isSelected) {
      adjustColors(list.getSelectionBackground(), list.getSelectionForeground());
    } else {
      adjustColors(list.getBackground(), list.getForeground());

      if ((index % 2) == 0) {
        panel.setBackground(STRIPE_COLOR);
        adjustColors(STRIPE_COLOR, list.getForeground());
      }
    }

    return panel;
  }
 @Override
 protected void fillPage(
     final Page page,
     JList list,
     Object value,
     int index,
     boolean isSelected,
     boolean cellHasFocus) {
   Color foreground = isSelected ? list.getSelectionForeground() : list.getForeground();
   Color background = isSelected ? list.getSelectionBackground() : list.getBackground();
   renderCellValue(page, value, foreground, background, isSelected);
 }
示例#7
0
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    setText(value.toString());

    setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
    setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());

    setFont(list.getFont());
    setBorder(
        (cellHasFocus) ? UIManager.getBorder("List.focusCellHighlightBorder") : m_noFocusBorder);

    return this;
  }
    /**
     * Return a component that has been configured to display the specified value.
     *
     * @param list The JList we're painting.
     * @param value The value returned by list.getModel().getElementAt(index).
     * @param index The cells index.
     * @param isSelected True if the specified cell was selected.
     * @param cellHasFocus True if the specified cell has the focus.
     * @return A component whose paint() method will render the specified value.
     * @todo Implement this javax.swing.ListCellRenderer method
     */
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      HostItem hi = (HostItem) value;
      JLabel c = new JLabel(hi.name);
      if (isSelected && hi.eavesDroppingEnabled) {
        c.setBackground(Color.magenta);
        c.setForeground(list.getSelectionForeground());
      } else if (!isSelected && hi.eavesDroppingEnabled) {
        c.setBackground(Color.red);
        c.setForeground(list.getForeground());
      } else if (isSelected) {
        c.setBackground(list.getSelectionBackground());
        c.setForeground(list.getSelectionForeground());
      } else {
        c.setBackground(list.getBackground());
        c.setForeground(list.getForeground());
      }

      c.setEnabled(list.isEnabled());
      c.setFont(list.getFont());
      c.setOpaque(true);

      return c;
    }
    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

      XmlElementDescriptor descriptor = (XmlElementDescriptor) value;
      Color backgroundColor = isSelected ? list.getSelectionBackground() : list.getBackground();

      myNameLabel.setText(descriptor.getName());
      myNameLabel.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
      myPanel.setBackground(backgroundColor);

      myNSLabel.setText(getNamespace(descriptor));
      myNSLabel.setForeground(LookupCellRenderer.getGrayedForeground(isSelected));
      myNSLabel.setBackground(backgroundColor);

      return myPanel;
    }
示例#10
0
 public Component getListCellRendererComponent(JList list, Object value,
                                               int index,
                                               boolean isSelected,
                                               boolean cellHasFocus) {
   setText(" " + ((JmolInstance) value).name);
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setEnabled(list.isEnabled());
   setFont(list.getFont());
   setOpaque(true);
   enableButtons(list);
   return this;
 }
示例#11
0
  /** Implement this method in ListCellRenderer */
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Object[] pair = (Object[]) value; // Cast value into an array
    jlblCell.setOpaque(true);
    jlblCell.setIcon((ImageIcon) pair[0]);
    jlblCell.setText(pair[1].toString());

    if (isSelected) {
      jlblCell.setForeground(list.getSelectionForeground());
      jlblCell.setBackground(list.getSelectionBackground());
    } else {
      jlblCell.setForeground(list.getForeground());
      jlblCell.setBackground(list.getBackground());
    }

    jlblCell.setBorder(cellHasFocus ? lineBorder : emptyBorder);

    return jlblCell;
  }
示例#12
0
  /**
   * Paint the arrow in the panel, using the current style.
   *
   * @param g the graphic context.
   */
  public void paintComponent(Graphics g) {
    g.setColor(isSelected ? list.getSelectionBackground() : list.getBackground());

    g.fillRect(0, 0, getWidth(), getHeight());
    g.setColor(isSelected ? list.getSelectionForeground() : list.getForeground());

    g.drawLine(getWidth() / 3, getHeight() / 2, 2 * getWidth() / 3, getHeight() / 2);
    Arrow arrowDummy = new Arrow();

    arrowDummy.drawArrowPixels(
        new Graphics2DSwing(g),
        getWidth() / 3,
        getHeight() / 2,
        2 * getWidth() / 3,
        getHeight() / 2,
        10,
        4,
        arrow.style);
  }
示例#13
0
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

    if (isSelected) {
      setBackground(list.getSelectionBackground());
      setForeground(list.getSelectionForeground());
    } else {
      setBackground(list.getBackground());
      setForeground(list.getForeground());
    }

    if (value instanceof ConfigParamDescr) {
      ConfigParamDescr descr = (ConfigParamDescr) value;
      setText(descr.getDisplayName());
    } else {
      setText(value.toString());
    }
    return this;
  }
示例#14
0
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   if (value != null) {
     String name = Languages.getLanguageName(((String) value).split("_")[0]);
     setText(value + " - " + name);
     setToolTipText(value + " - " + name);
     setBorder(null);
   } else {
     setText(" ");
     setToolTipText("");
     setBorder(BorderFactory.createLineBorder(Color.RED));
   }
   return this;
 }
    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      ReopenProjectAction item = (ReopenProjectAction) value;

      Color fore = isSelected ? UIUtil.getListSelectionForeground() : list.getForeground();
      Color back =
          isSelected
              ? cellHasFocus
                  ? UIUtil.getListSelectionBackground()
                  : UIUtil.getListUnfocusedSelectionBackground()
              : list.getBackground();

      myName.setForeground(fore);
      myPath.setForeground(isSelected ? fore : UIUtil.getInactiveTextColor());

      setBackground(back);

      myName.setText(item.getProjectName());
      myPath.setText(getTitle2Text(item.getProjectPath(), myPath));

      return this;
    }
    // value is a QualifiedHolder
    public Component getListCellRendererComponent(
        JList list,
        Object value, // expected to be
        int index,
        boolean isSelected,
        boolean cellHasFocus) {

      clear();

      ImportCandidateHolder item = (ImportCandidateHolder) value;
      setIcon(item.getImportable().getIcon(0));
      String item_name = item.getPresentableText(myName);
      append(item_name, SimpleTextAttributes.REGULAR_ATTRIBUTES);

      setFont(FONT);
      if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
      } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
      }
      return this;
    }
示例#17
0
 @Override
 public Component getListCellRendererComponent(
     JList<? extends E> list, E value, int index, boolean isSelected, boolean cellHasFocus) {
   label.setText(Objects.toString(value, ""));
   this.index = index;
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     label.setForeground(list.getSelectionForeground());
   } else {
     setBackground(index % 2 == 0 ? EVEN_COLOR : list.getBackground());
     label.setForeground(list.getForeground());
   }
   resetButtonStatus();
   if (Objects.nonNull(button)) {
     if (index == pressedIndex) {
       button.getModel().setSelected(true);
       button.getModel().setArmed(true);
       button.getModel().setPressed(true);
     } else if (index == rolloverIndex) {
       button.getModel().setRollover(true);
     }
   }
   return this;
 }