javax.swing.JList Java Examples

The following examples show how to use javax.swing.JList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TradeRouteInputPanel.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean importData(JComponent target, Transferable data) {
    JList<TradeRouteStop> stl = TradeRouteInputPanel.this.stopList;
    if (target == stl
        && data instanceof StopListTransferable
        && canImport(target, data.getTransferDataFlavors())) {
        List<TradeRouteStop> stops
            = ((StopListTransferable)data).getStops();
        DefaultListModel<TradeRouteStop> model
            = new DefaultListModel<>();
        int index = stl.getMaxSelectionIndex();
        for (TradeRouteStop stop : stops) {
            if (index < 0) {
                model.addElement(stop);
            } else {
                index++;
                model.add(index, stop);
            }
        }
        stl.setModel(model);
        return true;
    }
    return false;
}
 
Example #2
Source File: LineTablesUI.java    From whyline with MIT License 6 votes vote down vote up
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
	 
	 Line line = (Line)value;
	 
	 String label = "<html><b>" + Util.fillOrTruncateString(line.getFile().getShortFileName(), 15) + ": " + Util.fillOrTruncateString(Integer.toString(line.getLineNumber().getNumber()), 10) + "</b>" + line.getLineText();
	 label = label.replace(" ", "&nbsp;");
     setText(label);
              
     if (isSelected) {
    	 setBackground(UI.getHighlightColor());
    	 setForeground(java.awt.Color.white);
     }
     else {
    	 setBackground(list.getBackground());
    	 setForeground(list.getForeground());
     }
     setEnabled(list.isEnabled());
     setFont(list.getFont());
     setOpaque(true);
     return this;
}
 
Example #3
Source File: RListTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void selectMultipleItemSelection() {
    final LoggingRecorder lr = new LoggingRecorder();
    siw(new Runnable() {
        @Override
        public void run() {
            list = (JList) ComponentUtils.findComponent(JList.class, frame);
            list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
            list.setSelectedIndices(new int[] { 0, 2 });
            RList rList = new RList(list, null, null, lr);
            rList.focusLost(null);
        }
    });
    Call call = lr.getCall();
    AssertJUnit.assertEquals("select", call.getFunction());
    AssertJUnit.assertEquals("[Jane Doe, Kathy Green]", call.getState());
}
 
Example #4
Source File: RowHeaderTable.java    From ermaster-b with Apache License 2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list,
		Object value, int index, boolean isSelected,
		boolean hasFocus) {
	JLabel label = (JLabel) super.getListCellRendererComponent(
			list, value, index, isSelected, hasFocus);

	if (this.iconEnable && index == 0) {
		label.setIcon(ICON);

	} else if (index == 1) {
		Font font = label.getFont().deriveFont(10.0f);
		label.setFont(font);
		label.setForeground(Color.GRAY);
	}

	return label;
}
 
Example #5
Source File: AbstractPageListPopupListener.java    From wpcleaner with Apache License 2.0 6 votes vote down vote up
/**
 * Show popup menu in response to a mouse event.
 * 
 * @param e Event.
 */
@Override
protected void showPopup(MouseEvent e) {

  // Retrieve information
  if (!(e.getComponent() instanceof JList)) {
    return;
  }
  JList tmpList = (JList) e.getComponent();
  int position = tmpList.locationToIndex(e.getPoint());
  if (position < 0) {
    return;
  }
  Object object = tmpList.getModel().getElementAt(position);
  if (!(object instanceof Page)) {
    return;
  }
  Page link = (Page) object;
  showPopup(tmpList, link, e.getX(), e.getY());
}
 
Example #6
Source File: FleetListRenderer.java    From Open-Realms-of-Stars with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(
    final JList<? extends Fleet> list, final Fleet value, final int index,
    final boolean isSelected, final boolean cellHasFocus) {
  JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(
      list, value, index, isSelected, cellHasFocus);
  renderer.setFont(GuiStatics.getFontCubellan());
  if (value.getNumberOfShip() == 1) {
    renderer
        .setText(value.getName() + " - " + value.getFirstShip().getName());
  } else {
    renderer.setText(
        value.getName() + " - " + value.getNumberOfShip() + " ships");
  }
  if (isSelected) {
    renderer.setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE);
    renderer.setBackground(GuiStatics.COLOR_DEEP_SPACE_PURPLE);
  } else {
    renderer.setForeground(GuiStatics.COLOR_COOL_SPACE_BLUE_DARK);
    renderer.setBackground(GuiStatics.COLOR_DEEP_SPACE_PURPLE_DARK);
  }
  return renderer;
}
 
Example #7
Source File: InjectScript.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
private Boolean reorderProjects(TransferHandler.TransferSupport support) {
    JList list = (JList) support.getComponent();
    try {
        int[] selectedIndices = (int[]) support.getTransferable().getTransferData(INDICES);
        DefaultListModel model = (DefaultListModel) list.getModel();
        JList.DropLocation dl = (JList.DropLocation) support.getDropLocation();
        if (dl.getIndex() != -1) {
            for (int selectedIndex : selectedIndices) {
                Object value = model.get(selectedIndex);
                model.removeElement(value);
                model.add(dl.getIndex(), value);
            }
            return true;
        } else {
            LOG.warning("Invalid Drop Location");
        }
    } catch (UnsupportedFlavorException | IOException ex) {
        LOG.log(Level.SEVERE, ex.getMessage(), ex);
    }
    return false;
}
 
Example #8
Source File: ListIconRenderer.java    From Spark with Apache License 2.0 6 votes vote down vote up
@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());
       }

       setHorizontalAlignment(SwingConstants.LEFT);
       ImageIcon icon = (ImageIcon)value;
       setText(icon.getDescription());
       setIcon(icon);
       return this;
   }
 
Example #9
Source File: SuitePropertiesTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testRemoveAllSubModules() throws Exception {
    SuiteProject suite1 = generateSuite("suite1");
    TestBase.generateSuiteComponent(suite1, "module1a");
    TestBase.generateSuiteComponent(suite1, "module1b");
    SuiteProperties suite1Props = getSuiteProperties(suite1);
    
    SuiteSubModulesListModel model = suite1Props.getModulesListModel();
    assertNotNull(model);
    
    // simulate removing all items from the list
    JList moduleList = new JList(model);
    moduleList.setSelectedIndices(new int[] {0, model.getSize() - 1});
    model.removeModules(Arrays.asList(moduleList.getSelectedValues()));
    assertEquals("no subModule should be left", 0, model.getSize());
    
    saveProperties(suite1Props);
    
    SubprojectProvider spp = getSubProjectProvider(suite1);
    assertEquals("no module should be left", 0, spp.getSubprojects().size());
}
 
Example #10
Source File: JContactItemRenderer.java    From Spark with Apache License 2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, 
		boolean isSelected, boolean cellHasFocus) {
	
	basicPanelRenderer.getListCellRendererComponent(list, this, index, isSelected, cellHasFocus);
	ContactItem renderItem = (ContactItem)value;
	setFocusable(false);
	setNickname(renderItem.getNickname());
	setAlias(renderItem.getAlias());
               if (this.getDisplayName().trim().isEmpty()) {
                   // Fallback hack to show something other than empty string.
                   // JID can't be set after object creation, so alias is reset.
                   setAlias(renderItem.getDisplayName());
               }
	setIcon(renderItem.getIcon());
	setStatus(renderItem.getStatus());
	getNicknameLabel().setFont(renderItem.getNicknameLabel().getFont());
	getNicknameLabel().setForeground(renderItem.getNicknameLabel().getForeground());
	getDescriptionLabel().setFont(renderItem.getDescriptionLabel().getFont());
	getDescriptionLabel().setText(renderItem.getDescriptionLabel().getText());
	getSpecialImageLabel().setIcon(renderItem.getSpecialImageLabel().getIcon());
	getSideIcon().setIcon(renderItem.getSideIcon().getIcon());
	return this;
}
 
Example #11
Source File: IsOverriddenPopup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
    Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    
    if (value instanceof OverrideDescription) {
        OverrideDescription desc = (OverrideDescription) value;
        
        setIcon(desc.getIcon());
        setText(desc.location.getDisplayHtml(new GsfHtmlFormatter()));
    }
    
    return c;
}
 
Example #12
Source File: MembersListRenderer.java    From jpexs-decompiler with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(final JList list, Object value, final int index,
        final boolean isSelected, boolean cellHasFocus) {
    Color back = (index % 2 == 1) ? list.getBackground() : evensColor;
    if (value instanceof Method) {
        final Method method = (Method) value;
        return new MethodCell(list, isSelected, back, method, dlg.getTheClass());
    } else if (value instanceof Field) {
        Field field = (Field) value;
        return new FieldCell(list, isSelected, back, field, dlg.getTheClass());
    } else if (value instanceof Constructor) {
        Constructor cons = (Constructor) value;
        return new ConstructorCell(list, isSelected, back, cons, dlg.getTheClass());
    } else {
        Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        comp.setBackground(back);
        return comp;
    }
}
 
Example #13
Source File: UpdateUIRecursionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public UpdateUIRecursionTest() {
    super("UpdateUIRecursionTest");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 400);

    String[] listData = {
        "First", "Second", "Third", "Fourth", "Fifth", "Sixth"
    };

    list = new JList(listData);
    list.setCellRenderer(this);
    renderer = new DefaultListCellRenderer();
    getContentPane().add(new JScrollPane(list), BorderLayout.CENTER);

    setVisible(true);
}
 
Example #14
Source File: RepaintingDecoration.java    From pumpernickel with MIT License 6 votes vote down vote up
/**
 * Returns whether this decoration should be visible.
 * <p>
 * Do not override this method. To customize the visibility of this object,
 * change the <code>ListDecoration</code> this decoration delegates to.
 */
@Override
public final boolean isVisible(JList list, Object value, int row,
		boolean isSelected, boolean cellHasFocus) {
	boolean returnValue = decoration.isVisible(list, value, row,
			isSelected, cellHasFocus);
	synchronized (repaintingCells) {
		CellInfo cellInfo = new CellInfo(list, row);
		if (returnValue) {
			if (repaintingCells.add(cellInfo)
					&& (!repaintTimer.isRunning())) {
				repaintTimer.start();
			}
		} else {
			repaintingCells.remove(cellInfo);
		}
	}
	return returnValue;
}
 
Example #15
Source File: ToDoCustomizer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
    if (comp instanceof JLabel) {
        JLabel jLabel = (JLabel) comp;
        if (value instanceof FileIdentifier) {
            FileIdentifier identifier = (FileIdentifier) value;
            if (isCommentTagValid(identifier)) {
                jLabel.setIcon(EMPTY_ICON);
            } else {
                jLabel.setIcon(NOT_VALID_ICON);
            }
        } else if (!isSelected) {
            ((JLabel) comp).setForeground(UIManager.getColor("Label.disabledForeground"));
        }
    }
    return comp;
}
 
Example #16
Source File: UnitType.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int getMaximumIndex(Colony colony, JList<BuildableType> buildQueueList, int UNABLE_TO_BUILD) {
    ListModel<BuildableType> buildQueue = buildQueueList.getModel();
    final int buildQueueLastPos = buildQueue.getSize();

    boolean canBuild = false;
    if (colony.canBuild(this)) {
        canBuild = true;
    }

    // does not depend on anything, nothing depends on it
    // can be built at any time
    if (canBuild) return buildQueueLastPos;
    // check for building in queue that allows builting this unit
    for (int index = 0; index < buildQueue.getSize(); index++) {
        BuildableType toBuild = buildQueue.getElementAt(index);
        if (toBuild == this) continue;
        if (toBuild.hasAbility(Ability.BUILD, this)) {
            return buildQueueLastPos;
        }
    }
    return UNABLE_TO_BUILD;
}
 
Example #17
Source File: JCheckBoxList.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index,
        boolean isSelected, boolean cellHasFocus) {
    if (value instanceof CheckBoxListEntry) {
        CheckBoxListEntry checkbox = (CheckBoxListEntry) value;
        checkbox.setBackground(isSelected ? list.getSelectionBackground() : list.getBackground());
        if (checkbox.isRed()) {
            checkbox.setForeground(Color.red);
        } else {
            checkbox.setForeground(isSelected ? list.getSelectionForeground() : list.getForeground());
        }
        checkbox.setEnabled(isEnabled());
        checkbox.setFont(getFont());
        checkbox.setFocusPainted(false);
        checkbox.setBorderPainted(true);
        checkbox.setBorder(isSelected ? UIManager.getBorder("List.focusCellHighlightBorder")
                : noFocusBorder);

        return checkbox;
    } else {
        return super.getListCellRendererComponent(list, value.getClass().getName(), index,
                isSelected, cellHasFocus);
    }
}
 
Example #18
Source File: FileCompletionPopup.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public FileCompletionPopup(JFileChooser chooser, JTextField textField, Vector<File> files) {
    this.list = new JList(files);
    this.textField = textField;
    this.chooser = chooser;
    list.setVisibleRowCount(4);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    
    JScrollPane jsp = new JScrollPane(list);
    add(jsp);
    
    list.setFocusable(false);
    jsp.setFocusable(false);
    setFocusable(false);
    
    list.addFocusListener(new FocusHandler());
    list.addMouseListener(new MouseHandler());
    list.addMouseMotionListener(new MouseHandler());
    
    textField.addKeyListener(this);
}
 
Example #19
Source File: QueuedItemsRenderer.java    From xdm with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<? extends String> list, String value, int index,
		boolean isSelected, boolean cellHasFocus) {
	if (isSelected) {
		setBackground(ColorResource.getSelectionColor());
	} else {
		setBackground(ColorResource.getDarkerBgColor());
	}
	DownloadEntry ent = XDMApp.getInstance().getEntry(value);
	String str = "";
	if (ent != null) {
		str += ent.getFile();
		if (ent.getSize() > 0) {
			str += " [ " + FormatUtilities.formatSize(ent.getSize()) + " ]";
		}
	}
	setText(str);
	return this;
}
 
Example #20
Source File: CheckRenderer.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Component getListCellRendererComponent(final JList<? extends Object> list, Object value, final int index, boolean isSelected, boolean cellHasFocus) {
    setText(value.toString());
    CheckNode node = ((CheckNodeListModel) list.getModel()).getCheckNodeAt(index);
    this.setSelected(node.isSelected());
    this.setEnabled(list.isEnabled());

    if (isSelected && list.hasFocus()) {
        this.setBackground(list.getSelectionBackground());
        this.setForeground(list.getSelectionForeground());
    } else if (isSelected) {
        assert !list.hasFocus();
        this.setBackground(startBackground);
        this.setForeground(list.getForeground());

    } else {
        this.setBackground(list.getBackground());
        this.setForeground(list.getForeground());
    }
    return this;
}
 
Example #21
Source File: ProjectCellRenderer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    // #89393: GTK needs name to render cell renderer "natively"
    setName("ComboBox.listRenderer"); // NOI18N
    if (value instanceof Project) {
        ProjectInformation pi = ProjectUtils.getInformation((Project) value);
        setText(pi.getDisplayName());
        setIcon(pi.getIcon());
    } else {
        setText(value == null ? "" : value.toString()); // NOI18N
        setIcon(null);
    }
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    } else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }
    return this;
}
 
Example #22
Source File: JFrame_Main.java    From MobyDroid with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    setBackground(isSelected ? MaterialColor.TEAL_100 : list.getBackground());
    setOpaque(isSelected);
    setIcon(ResourceLoader.MaterialIcons_PHONE_ANDROID);
    setText((String) value);
    setFont(list.getFont());
    return this;
}
 
Example #23
Source File: CreateRulePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a renderer for the stylesheets combobox dropdown.
 */    
private ListCellRenderer createStylesheetsRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value == null) {
                //empty model
                return c;
            }
            if(value instanceof FileObject) {
                FileObject file = (FileObject) value;
                if(webRoot == null) {
                    setText(file.getNameExt());
                } else {
                    String relativePath = FileUtil.getRelativePath(webRoot, file);
                    if(relativePath != null) {
                        setText(relativePath);
                    } else {
                        //should not happen
                        setText(file.getNameExt());
                    }
                }
            } else if(value instanceof String) {
                setText((String)value);
            }
            
            return c;
        }
    };
}
 
Example #24
Source File: SplitPaneTreeView.java    From pdfxtk with Apache License 2.0 5 votes vote down vote up
public Component getListCellRendererComponent(JList   list,
		  Object  value,
		  int     index,
		  boolean isSelected,
		  boolean cellHasFocus)
{
  NodeList nl = (NodeList)list;
  isLeaf = nl.node == null ? true : controler.tree.isLeaf(controler.tree.getChild(nl.node, index));
  
  return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
 
Example #25
Source File: ComboBoxRenderer.java    From energy2d with GNU Lesser General Public License v3.0 5 votes vote down vote up
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());
	}
	String s = (String) value;
	setText(s);
	setFont(new Font(s, Font.PLAIN, 12));
	return this;
}
 
Example #26
Source File: DiplomacyView.java    From Open-Realms-of-Stars with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create Tech List from tech
 * @param techs Which are used for creating Tech List
 * @return JList full of tech
 */
private JList<Tech> createTechList(final Tech[] techs) {
  JList<Tech> techList = new JList<>(techs);
  techList.setCellRenderer(new TechListRenderer());
  techList.setBackground(Color.BLACK);
  techList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
  return techList;
}
 
Example #27
Source File: ImportModulePanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example #28
Source File: SwingUtilities2.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * A variation of locationToIndex() which only returns an index if the
 * Point is within the actual bounds of a list item (not just in the cell)
 * and if the JList has the "List.isFileList" client property set.
 * Otherwise, this method returns -1.
 * This is used to make Windows {@literal L&F} JFileChooser act
 * like native dialogs.
 */
public static int loc2IndexFileList(JList<?> list, Point point) {
    int index = list.locationToIndex(point);
    if (index != -1) {
        Object bySize = list.getClientProperty("List.isFileList");
        if (bySize instanceof Boolean && ((Boolean)bySize).booleanValue() &&
            !pointIsInActualBounds(list, index, point)) {
            index = -1;
        }
    }
    return index;
}
 
Example #29
Source File: SummaryCellRenderer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    AbstractSummaryView.ShowAllEventsItem item = (AbstractSummaryView.ShowAllEventsItem) value;
    id = item.getItemId();
    if (linkerSupport.getLinker(ShowRemainingFilesLink.class, id) == null) {
        linkerSupport.add(new ShowRemainingFilesLink(item.getParent()), id);
    }
    StringBuilder sb = new StringBuilder("<html><a href=\"expand\">"); //NOI18N
    int i = item.getParent().getNextFilesToShowCount();
    String label;
    if (i > 0) {
        label = NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ShowMoreFiles", i); //NOI18N
    } else {
        label = NbBundle.getMessage(SummaryCellRenderer.class, "MSG_ShowAllFiles"); //NOI18N
    }
    if (isSelected) {
        Component c = dlcr.getListCellRendererComponent(list, "<html><a href=\"expand\">ACTION_NAME</a>", index, isSelected, cellHasFocus); //NOI18N
        sb.append("<font color=\"").append(getColorString(c.getForeground())).append("\">") //NOI18N
                .append(label).append("</font>"); //NOI18N
    } else if (LINK_COLOR != null) {
        sb.append("<font color=\"").append(getColorString(LINK_COLOR)).append("\">") //NOI18N
                .append(label).append("</font>"); //NOI18N
    } else {
        sb.append(label);
    }
    sb.append("</a></html>"); //NOI18N
    comp = dlcr.getListCellRendererComponent(list, sb.toString(), index, isSelected, cellHasFocus);
    removeAll();
    add(comp);
    comp.setMaximumSize(comp.getPreferredSize());
    setBackground(comp.getBackground());
    return this;
}
 
Example #30
Source File: OperatorListCellRenderer.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected,
		boolean cellHasFocus) {
	OperatorDescription operatorDescription = (OperatorDescription) value;
	Component component = super.getListCellRendererComponent(list, operatorDescription.getName(), index, isSelected,
			cellHasFocus);
	JLabel label = (JLabel) component;
	try {
		label.setIcon(operatorDescription.getSmallIcon());
	} catch (Exception e) {
		// error --> no icon
	}
	if (coloredBackground && !isSelected && index % 2 != 0) {
		label.setBackground(SwingTools.LIGHTEST_BLUE);
	}

	String descriptionString = operatorDescription.getLongDescriptionHTML();
	if (descriptionString == null) {
		descriptionString = operatorDescription.getShortDescription();
	}
	StringBuffer toolTipText = new StringBuffer("<b>Description:</b> " + descriptionString);
	label.setToolTipText(SwingTools.transformToolTipText(toolTipText.toString(), false, false));

	if (operatorDescription.isDeprecated()) {
		label.setForeground(Color.LIGHT_GRAY);
	}
	label.setBorder(null);
	return label;
}