@Override
  public Component getListCellRendererComponent(
      final JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {

    if (padre == null) {
      padre = list.getParent();
      padre.addComponentListener(
          new ComponentAdapter() {

            @Override
            public void componentResized(ComponentEvent e) {
              list.setCellRenderer(new CeldaListaRendererEntropy());
              list.repaint();
            }
          });
    }

    if (isSelected) {
      txaCelda.setBackground(LookAndFeelEntropy.COLOR_SELECCION_ITEM);
    } else {
      txaCelda.setBackground(Color.WHITE);
    }

    String strMostrar = value == null ? "" : value.toString();

    int intAnchoActual = list.getWidth();
    if (intAnchoActual != 0) {

      int intMaxCaracteres = 100;

      strMostrar =
          strMostrar.substring(
              0, strMostrar.length() <= intMaxCaracteres ? strMostrar.length() : intMaxCaracteres);
      if (strMostrar.length() == intMaxCaracteres) {
        strMostrar += "...";
      }

      int intAnchoDeseado = 0;
      int intCantidadLineas = 1;
      for (char c : strMostrar.toCharArray()) {
        intAnchoDeseado += txaCelda.getFontMetrics(txaCelda.getFont()).charWidth(c);
        if (intAnchoDeseado > intAnchoActual * intCantidadLineas) {
          intCantidadLineas++;
        }
      }
      txaCelda.setRows(intCantidadLineas);
    }

    txaCelda.setText(strMostrar);

    return txaCelda;
  }
Пример #2
0
  private void rebuildModel() {
    myModel.clear();
    myList.setFixedCellWidth(myList.getWidth());
    List<IMessage> messagesToAdd = new ArrayList<IMessage>();
    int width = 0;
    for (IMessage m : myMessages) {
      if (isVisible(m)) {
        width = Math.max(width, getMessageWidth(m));
        messagesToAdd.add(m);
      }
    }
    myList.setFixedCellWidth(width);

    myModel.addAll(messagesToAdd);
  }
  @Override
  protected int getMaxAvailablePageWidth(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Insets insets = list.getInsets(); // OWLFrameList.ITEM_BORDER.getBorderInsets();
    int componentWidth = list.getWidth();
    JViewport vp = (JViewport) SwingUtilities.getAncestorOfClass(JViewport.class, list);
    if (vp != null) {
      componentWidth = vp.getViewRect().width;
    }

    return componentWidth
        - list.getInsets().left
        - list.getInsets().right
        - insets.left
        + insets.right
        - 20;
  }
Пример #4
0
  @Override
  public Component getListCellRendererComponent(
      final JList list, Object value, int index, boolean isSelected, boolean hasFocus) {

    boolean nonFocusedSelection =
        isSelected && myLookup.getFocusDegree() == LookupImpl.FocusDegree.SEMI_FOCUSED;
    if (!myLookup.isFocused()) {
      isSelected = false;
    }

    myIsSelected = isSelected;
    final LookupElement item = (LookupElement) value;
    final Color foreground = getForegroundColor(isSelected);
    final Color background =
        nonFocusedSelection
            ? SELECTED_NON_FOCUSED_BACKGROUND_COLOR
            : isSelected ? SELECTED_BACKGROUND_COLOR : BACKGROUND_COLOR;

    int allowedWidth = list.getWidth() - AFTER_TAIL - AFTER_TYPE - getIconIndent();

    FontMetrics normalMetrics = getRealFontMetrics(item, false);
    FontMetrics boldMetrics = getRealFontMetrics(item, true);
    final LookupElementPresentation presentation =
        new RealLookupElementPresentation(
            isSelected ? getMaxWidth() : allowedWidth, normalMetrics, boldMetrics, myLookup);
    AccessToken token = ReadAction.start();
    try {
      if (item.isValid()) {
        try {
          item.renderElement(presentation);
        } catch (Exception e) {
          LOG.error(e);
        } catch (Error e) {
          LOG.error(e);
        }
      } else {
        presentation.setItemTextForeground(JBColor.RED);
        presentation.setItemText("Invalid");
      }
    } finally {
      token.finish();
    }

    myNameComponent.clear();
    myNameComponent.setIcon(augmentIcon(presentation.getIcon(), myEmptyIcon));
    myNameComponent.setBackground(background);
    allowedWidth -=
        setItemTextLabel(
            item,
            new JBColor(
                isSelected ? SELECTED_FOREGROUND_COLOR : presentation.getItemTextForeground(),
                foreground),
            isSelected,
            presentation,
            allowedWidth);

    Font customFont = myLookup.getCustomFont(item, false);
    myTailComponent.setFont(customFont != null ? customFont : myNormalFont);
    myTypeLabel.setFont(customFont != null ? customFont : myNormalFont);

    myTypeLabel.clear();
    if (allowedWidth > 0) {
      allowedWidth -=
          setTypeTextLabel(
              item,
              background,
              foreground,
              presentation,
              isSelected ? getMaxWidth() : allowedWidth,
              isSelected,
              nonFocusedSelection,
              normalMetrics);
    }

    myTailComponent.clear();
    myTailComponent.setBackground(background);
    if (isSelected || allowedWidth >= 0) {
      setTailTextLabel(
          isSelected,
          presentation,
          foreground,
          isSelected ? getMaxWidth() : allowedWidth,
          nonFocusedSelection,
          normalMetrics);
    }

    if (mySelected.containsKey(index)) {
      if (!isSelected && mySelected.get(index)) {
        myPanel.setUpdateExtender(true);
      }
    }
    mySelected.put(index, isSelected);

    final double w =
        myNameComponent.getPreferredSize().getWidth()
            + myTailComponent.getPreferredSize().getWidth()
            + myTypeLabel.getPreferredSize().getWidth();

    boolean useBoxLayout =
        isSelected
            && w > list.getWidth()
            && ((JBList) list).getExpandableItemsHandler().isEnabled();
    if (useBoxLayout != myPanel.getLayout() instanceof BoxLayout) {
      myPanel.removeAll();
      if (useBoxLayout) {
        myPanel.setLayout(new BoxLayout(myPanel, BoxLayout.X_AXIS));
        myPanel.add(myNameComponent);
        myPanel.add(myTailComponent);
        myPanel.add(myTypeLabel);
      } else {
        myPanel.setLayout(new BorderLayout());
        myPanel.add(myNameComponent, BorderLayout.WEST);
        myPanel.add(myTailComponent, BorderLayout.CENTER);
        myPanel.add(myTypeLabel, BorderLayout.EAST);
      }
    }

    return myPanel;
  }
 private void updateLocations() {
   groupsList.setBounds(
       LABEL_SPACE, 0, groupsList.getPreferredSize().width, groupsList.getPreferredSize().height);
   slider.setBounds(LABEL_SPACE + groupsList.getWidth(), 0, slider.getWidth(), slider.getHeight());
 }