コード例 #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;
    }
コード例 #3
0
  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;
  }
コード例 #4
0
  @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, // value
        // to
        // display
        int index, // cell index
        boolean isSelected, // is the cell selected
        boolean cellHasFocus) // the list and the cell have the focus
        {
      String s = value.toString();
      setText(s);

      setForeground(list.getForeground());

      String name = listItems.get(index);
      if (selected.contains(name)) {
        if (users.contains(name)) setBackground(Color.GREEN);
        else setBackground(Color.YELLOW);
      } else {
        setBackground(list.getBackground());
      }
      setEnabled(list.isEnabled());
      setFont(list.getFont());
      setOpaque(true);
      return this;
    }
コード例 #6
0
  protected void paintComponent(Graphics g) {

    // Set up rendering hints to look as close to native as possible
    Graphics2D g2d = (Graphics2D) g;
    Object old = null;

    // First, try to use the rendering hint set that is "native".
    Map hints = (Map) getToolkit().getDesktopProperty("awt.font.desktophints");
    if (hints != null) {
      old = g2d.getRenderingHints();
      g2d.addRenderingHints(hints);
    }
    // If a "native" set isn't found, just turn on standard text AA.
    else {
      old = g2d.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
      g2d.setRenderingHint(
          RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    }

    //		if (jsc!=null) {
    //			setText(null); // Stop "Foobar" from being painted
    //		}

    // We never paint "selection" around the icon, to imitate Eclipse
    final int iconW = 18;
    int h = getHeight();
    if (!selected) {
      g.setColor(getBackground());
      g.fillRect(0, 0, getWidth(), h);
    } else {
      g.setColor(altBG != null && evenRow ? altBG : list.getBackground());
      g.fillRect(0, 0, iconW, h);
      g.setColor(getBackground()); // Selection color
      g.fillRect(iconW, 0, getWidth() - iconW, h);
    }
    if (getIcon() != null) {
      int y = (h - getIcon().getIconHeight()) / 2;
      getIcon().paintIcon(this, g, 0, y);
    }

    int x = getX() + iconW + 2;
    g.setColor(selected ? list.getSelectionForeground() : list.getForeground());
    if (jsc != null && !simpleText) {
      jsc.rendererText(g, x, g.getFontMetrics().getHeight(), selected);
    } else {
      Completion c = jsc != null ? (Completion) jsc : nonJavaCompletion;
      if (c != null) {
        g.drawString(c.toString(), x, g.getFontMetrics().getHeight());
      }
    }

    // Restore rendering hints appropriately.
    if (hints != null) {
      g2d.addRenderingHints((Map) old);
    } else {
      g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, old);
    }
  }
コード例 #7
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;
  }
コード例 #8
0
ファイル: FBChatTab.java プロジェクト: b98901130/chatroom
 @SuppressWarnings("rawtypes")
 @Override
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   if (value != null) {
     FBUser user = (FBUser) value;
     setText(user.getName());
   }
   setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
   setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
   return this;
 }
コード例 #9
0
 @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);
 }
コード例 #10
0
 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();
 }
コード例 #11
0
ファイル: ShowSavedResults.java プロジェクト: pjotrp/EMBOSS
  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;
  }
コード例 #12
0
  /*
   * This method finds the image and text corresponding
   * to the selected value and returns the label, set up
   * to display the text and image.
   */
  @Override
  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());
    }

    return this;
  }
コード例 #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());
    }

    ImageIcon icon = (ImageIcon) value;
    setText(icon.getDescription());
    setIcon(icon);
    return this;
  }
コード例 #14
0
    /**
     * 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;
    }
コード例 #15
0
ファイル: CheckList.java プロジェクト: programus/j-bots
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
   setEnabled(list.isEnabled());
   setSelected(((CheckListItem) value).isSelected());
   setFont(list.getFont());
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setText(value.toString());
   return this;
 }
コード例 #16
0
 @Override
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   String key = (String) value;
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setText(key);
   setIcon(content.get(key));
   setFont(list.getFont());
   return this;
 }
コード例 #17
0
 public Component getListCellRendererComponent(
     JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   if (value != null) {
     Integer num = (Integer) value;
     setText(cm.NameMap.get(num));
     setIcon(new ImageIcon(cm.IconMap.get(num)));
   }
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     // 设置选取与取消选取的前景与背景颜色.
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   return this;
 }
コード例 #18
0
    protected Component buildPage() {
      JList listBox = SwingComponentFactory.buildList(this.buildSelectedNodesListModel());
      listBox.setBorder(BorderFactory.createEmptyBorder());
      listBox.setCellRenderer(new DisplayableListCellRenderer());

      listBox.setBackground(UIManager.getColor("Panel.background"));
      listBox.setForeground(UIManager.getColor("List.foreground"));
      listBox.setSelectionBackground(UIManager.getColor("ScrollPane.background"));
      listBox.setSelectionForeground(listBox.getForeground());

      JScrollPane scrollPane = new JScrollPane(listBox);
      scrollPane.setBorder(new EmptyBorder(5, 0, 0, 0));
      scrollPane.getVerticalScrollBar().setUnitIncrement(10);
      scrollPane.setViewportBorder(BorderFactory.createEmptyBorder());

      return scrollPane;
    }
コード例 #19
0
  /**
   * Gets the list cell renderer component.
   *
   * @param list the instance of JList
   * @param value the value object
   * @param index the index value
   * @param isSelected the boolean of isSelected
   * @param cellHasFocus the boolean of cellHasFocus
   */
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
    IElementNode elementNode = (IElementNode) value;
    checkBox.setSelected(elementNode.isSelected());
    cellLabel.setText(elementNode.getText());
    cellLabel.setIcon(elementNode.getIcon());
    cellLabel.setToolTipText(elementNode.getToolTipText());
    cellLabel.setSelected(isSelected);
    cellLabel.setFont(list.getFont());
    cellLabel.setFocus(hasFocus);
    cellLabel.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
    cellLabel.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());

    setToolTipText(elementNode.getToolTipText());

    return this;
  }
コード例 #20
0
    @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;
    }
コード例 #21
0
ファイル: TestListPanel.java プロジェクト: oschrenk/jts
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   Testable testCase = (Testable) value;
   setText(testName(testCase));
   setOpaque(true);
   setIcon(testCase.isPassed() ? tickIcon : (testCase.isFailed() ? crossIcon : clearIcon));
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setEnabled(list.isEnabled());
   setFont(list.getFont());
   return this;
 }
コード例 #22
0
  /*
   * This method finds the image and text corresponding
   * to the selected value and returns the label, set up
   * to display the text and image.
   */
  public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    // Get the selected index. (The index param isn't
    // always valid, so just use the value.)

    if (isSelected) {
      setBackground(list.getSelectionBackground());
      setForeground(list.getSelectionForeground());
      // setBorder(BorderFactory.createLineBorder(Color.red,2));
    } else {
      setBackground(list.getBackground());
      setForeground(list.getForeground());
    }
    setHorizontalAlignment(LEFT);
    setText(((App) value).getNombre());
    return this;
  }
コード例 #23
0
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   String s = value.toString();
   setText(s);
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setEnabled(list.isEnabled());
   setFont(list.getFont());
   setOpaque(true);
   setToolTipText(((StyleSourceInfo) value).getTooltip());
   return this;
 }
コード例 #24
0
 public Component getListCellRendererComponent(
     JList<? extends String> list,
     String value,
     int index,
     boolean isSelected,
     boolean cellHasFocus) {
   setIcon(getIcon(value, parser));
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setEnabled(list.isEnabled());
   return this;
 }
コード例 #25
0
 /** {@inheritDoc} */
 @Override
 public Component getListCellRendererComponent(
     JList<? extends String> list,
     String value,
     int index,
     boolean isSelected,
     boolean cellHasFocus) {
   FreeColGameObject fcgo = getGame().getFreeColGameObject(value);
   if (fcgo instanceof Location) {
     setText(Messages.message(((Location) fcgo).getLocationLabel()));
   } else {
     setText(value);
   }
   setForeground((isSelected) ? list.getSelectionForeground() : list.getForeground());
   setBackground((isSelected) ? list.getSelectionBackground() : list.getBackground());
   return this;
 }
コード例 #26
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;
 }
コード例 #27
0
 @Override
 public Component getListCellRendererComponent(
     JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
   String str = (value == null) ? null : value.toString();
   if (Utils.SEPARATOR.equals(str)) {
     return separator;
   }
   if (isSelected) {
     setBackground(list.getSelectionBackground());
     setForeground(list.getSelectionForeground());
   } else {
     setBackground(list.getBackground());
     setForeground(list.getForeground());
   }
   setFont(list.getFont());
   setText(str);
   updateHeight();
   return this;
 }
コード例 #28
0
ファイル: BenutzerRechte.java プロジェクト: kdupke/thera-pi-2
    @Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

      // int selectedIndex = ((Integer)value).intValue();

      if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
      } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
      }
      if (value != null) {
        setIcon((ImageIcon) value);
      }

      return this;
    }
コード例 #29
0
ファイル: CellArrow.java プロジェクト: DarwinNE/FidoCadJ
  /**
   * 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);
  }
コード例 #30
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;
  }