@Override
    public Component getListCellRendererComponent(
        JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      if (list instanceof CheckList) {
        // calculate the max width of the logo
        int maxWidth = 0;
        for (int i = 0; i < list.getModel().getSize(); i++) {
          Object obj = list.getModel().getElementAt(i);
          if (obj instanceof MediaScraper) {
            MediaScraper ms = (MediaScraper) obj;
            ImageIcon logo = getIcon(ms.getLogoURL());
            maxWidth = Math.max(maxWidth, logo.getIconWidth());
          }
        }

        CheckList cbl = (CheckList) list;
        ListCheckModel model = cbl.getModel();
        boolean checked = model.isChecked(value);
        boolean locked = model.isLocked(value);
        setSelected(checked);

        if (locked || cbl.isEnabled() == false) {
          setEnabled(false);
        } else {
          setEnabled(true);
        }

        if (getHighlight().equals(Highlight.MOUSE_OVER_AND_CHECKED_ITEMS)
            && (checked || isSelected)) {
          panel.setBackground(selectionBackground);
          panel.setForeground(selectionForeground);
        } else if (getHighlight().equals(Highlight.MOUSE_OVER) && isSelected) {
          panel.setBackground(selectionBackground);
          panel.setForeground(selectionForeground);
        } else if (getHighlight().equals(Highlight.CHECKED_ITEMS) && checked) {
          panel.setBackground(selectionBackground);
          panel.setForeground(selectionForeground);
        } else {
          panel.setBackground(background);
          panel.setForeground(foreground);
        }
        if (value instanceof MediaScraper) {
          MediaScraper scraper = (MediaScraper) value;
          int currentWidth = 0;
          ImageIcon logo = getIcon(scraper.getLogoURL());
          if (logo != null) {
            currentWidth = logo.getIconWidth();
          }

          label.setIcon(logo);
          label.setIconTextGap(maxWidth + 4 - currentWidth); // 4 = default iconTextGap
        } else {
          label.setIcon(null);
          label.setIconTextGap(4); // 4 = default iconTextGap
        }
      }
      label.setText(getText(value));
      return panel;
    }
Esempio n. 2
0
  @Override
  protected Component buildExampleComponent() {
    List<String> countries = CountryNames.getCountries();

    CheckComboBox ccb = new CheckComboBox();

    ListCheckModel model = ccb.getModel();
    for (String color : countries) {
      model.addElement(color);
    }

    BatchSelection bs = new BatchSelection.CheckBox();
    EmbeddedComponent comp = new EmbeddedComponent(bs, Anchor.NORTH);
    ccb.setEmbeddedComponent(comp);

    JPanel panel = new JPanel();
    panel.setOpaque(false);
    panel.add(ccb);
    return panel;
  }