Ejemplo n.º 1
0
    @Override
    public Component getListCellRendererComponent(
        JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
      super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      LibraryPlaylistsListCell cell = (LibraryPlaylistsListCell) value;
      setText(cell.getText());
      setToolTipText(cell.getDescription());
      setPreferredSize(
          new Dimension(getSize().width, TableSettings.DEFAULT_TABLE_ROW_HEIGHT.getValue()));
      Icon icon = cell.getIcon();
      if (icon != null) {
        setIcon(icon);
      }

      this.setFont(list.getFont());
      ThemeMediator.fixLabelFont(this);

      return this;
    }
Ejemplo n.º 2
0
  private void setupList() {
    _listMouseObserver = new LibraryPlaylistsMouseObserver();
    _listSelectionListener = new LibraryPlaylistsSelectionListener();

    SortedListModel sortedModel =
        new SortedListModel(
            _model,
            SortOrder.ASCENDING,
            new Comparator<LibraryPlaylistsListCell>() {

              @Override
              public int compare(LibraryPlaylistsListCell o1, LibraryPlaylistsListCell o2) {
                if (o1 == _newPlaylistCell) {
                  return -1;
                }
                if (o2 == _newPlaylistCell) {
                  return 1;
                }

                return o1.getText().compareTo(o2.getText());
              }
            });

    _list = new LibraryIconList(sortedModel);
    _list.setFixedCellHeight(TableSettings.DEFAULT_TABLE_ROW_HEIGHT.getValue());
    _list.setCellRenderer(new LibraryPlaylistsCellRenderer());
    _list.addMouseListener(new DefaultMouseListener(_listMouseObserver));
    _list.addListSelectionListener(_listSelectionListener);
    _list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    _list.setLayoutOrientation(JList.VERTICAL);
    _list.setPrototypeCellValue(
        new LibraryPlaylistsListCell(
            "test", "", GUIMediator.getThemeImage("playlist"), null, null));
    _list.setVisibleRowCount(-1);
    _list.setDragEnabled(true);
    _list.setTransferHandler(new LibraryPlaylistsTransferHandler(_list));
    ToolTipManager.sharedInstance().registerComponent(_list);

    _list.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            list_keyPressed(e);
          }
        });

    _list.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() > 1) {
              actionStartRename();
            }
          }
        });

    _textName = new JTextField();
    ThemeMediator.fixKeyStrokes(_textName);
    UIDefaults defaults = new UIDefaults();
    defaults.put("TextField.contentMargins", new InsetsUIResource(0, 4, 0, 4));
    _textName.putClientProperty("Nimbus.Overrides.InheritDefaults", Boolean.TRUE);
    _textName.putClientProperty("Nimbus.Overrides", defaults);
    _textName.addKeyListener(
        new KeyAdapter() {
          @Override
          public void keyPressed(KeyEvent e) {
            textName_keyPressed(e);
          }
        });
    _textName.setVisible(false);

    _list.add(_textName);
  }