javax.swing.JList源码实例Demo

javax.swing.event.TreeSelectionListener#javax.swing.JList源码实例Demo

下面列出了javax.swing.event.TreeSelectionListener#javax.swing.JList 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: whyline   文件: LineTablesUI.java
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;
}
 
源代码2 项目: wpcleaner   文件: AbstractPageListPopupListener.java
/**
 * 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());
}
 
源代码3 项目: ermaster-b   文件: RowHeaderTable.java
@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;
}
 
源代码4 项目: marathonv5   文件: RListTest.java
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());
}
 
源代码5 项目: Open-Realms-of-Stars   文件: FleetListRenderer.java
@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;
}
 
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;
}
 
源代码7 项目: Spark   文件: ListIconRenderer.java
@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;
   }
 
源代码8 项目: netbeans   文件: SuitePropertiesTest.java
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());
}
 
源代码9 项目: Spark   文件: JContactItemRenderer.java
@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;
}
 
源代码10 项目: netbeans   文件: IsOverriddenPopup.java
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;
}
 
源代码11 项目: netbeans   文件: ProjectCellRenderer.java
@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;
}
 
源代码12 项目: jpexs-decompiler   文件: MembersListRenderer.java
@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;
    }
}
 
源代码13 项目: openjdk-jdk9   文件: CheckRenderer.java
@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;
}
 
源代码14 项目: xdm   文件: QueuedItemsRenderer.java
@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;
}
 
源代码15 项目: openjdk-jdk9   文件: UpdateUIRecursionTest.java
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);
}
 
源代码16 项目: netbeans   文件: FileCompletionPopup.java
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);
}
 
源代码17 项目: MeteoInfo   文件: JCheckBoxList.java
@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);
    }
}
 
源代码18 项目: freecol   文件: UnitType.java
@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;
}
 
源代码19 项目: netbeans   文件: ToDoCustomizer.java
@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;
}
 
源代码20 项目: pumpernickel   文件: RepaintingDecoration.java
/**
 * 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;
}
 
源代码21 项目: freecol   文件: TradeRouteInputPanel.java
/**
 * {@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;
}
 
源代码22 项目: jeddict   文件: TableUISupport.java
public static Set<Table> getEnabledTables(JList list) {
    Set<Table> result = new HashSet<>();

    for (int i = 0; i < list.getModel().getSize(); i++) {
        Table table = (Table) list.getModel().getElementAt(i);
        if (!list.getCellRenderer().getListCellRendererComponent(list, table, i, false, false).isEnabled()) {
            continue;
        }
        result.add(table);
    }

    return result;
}
 
源代码23 项目: netbeans   文件: RepositoryUserRenderer.java
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (value instanceof RepositoryUser) {
        RepositoryUser user = (RepositoryUser)value;
        value = MessageFormat.format(pattern, user.getFullName(), user.getUserName());
    }
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
 
源代码24 项目: chipster   文件: ToolFilterPanel.java
public ToolFilterPanel(ToolPanel parent,
       List<ToolCategory> categories) {
    super(new GridLayout(1, 2));
    this.toolPanel = parent;
    this.categories = categories;
    
    categoryList = new JList();
    categoryList.setSelectedIndex(0);
    categoryList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    categoryList.addListSelectionListener(this);
    categoryList.setCellRenderer(new ToolSelectorPanel.CategoryListRenderer());
    categoryList.getInsets().right = 1;
    categoryList.setName("categoryList");
    
    // Operation list shows the results
    visibleOperationsList = new JList();
    visibleOperationsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    visibleOperationsList.addListSelectionListener(this);
    visibleOperationsList.setCellRenderer(new ToolSelectorPanel.FontSizeFriendlyListRenderer());
    visibleOperationsList.getInsets().right = 1;
    visibleOperationsList.setName("operationList");
    
    JScrollPane categoryListScroller = new JScrollPane(categoryList);       
    JScrollPane operationListScroller = new JScrollPane(visibleOperationsList);
    categoryListScroller.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1,
            VisualConstants.TOOL_LIST_BORDER_COLOR));
    operationListScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));

    this.add(categoryListScroller);
    this.add(operationListScroller);        
}
 
源代码25 项目: netbeans   文件: MainClassChooser.java
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    String displayName;
    if (value instanceof ElementHandle) {
        displayName = ((ElementHandle)value).getQualifiedName();
    } else {
        displayName = value.toString ();
    }
    return super.getListCellRendererComponent (list, displayName, index, isSelected, cellHasFocus);
}
 
源代码26 项目: openjdk-jdk9   文件: GUIBrowser.java
@Override
public Component getListCellRendererComponent(JList<? extends ClassNode> list,
        ClassNode value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {
    return get(value, isSelected);
}
 
源代码27 项目: marathonv5   文件: RList.java
public RList(Component source, JSONOMapConfig omapConfig, Point point, IJSONRecorder recorder) {
    super(source, omapConfig, point, recorder);
    JList list = (JList) source;
    this.point = point;
    index = JListJavaElement.getIndexAt(list, point);
    cellInfo = index != -1 ? getText(list, index) : null;
}
 
源代码28 项目: netbeans   文件: RunAnalysisPanel.java
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if (value instanceof AnalyzerAndWarning) {
        value = "    " + SPIAccessor.ACCESSOR.getWarningDisplayName(((AnalyzerAndWarning) value).wd);
    } else if (value instanceof String) {
        setFont(getFont().deriveFont(Font.ITALIC));
        setText((String) value);
        setEnabled(false);
        setBackground(list.getBackground());
        setForeground(UIManager.getColor("Label.disabledForeground"));

        return this;
    }

    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
 
源代码29 项目: pumpernickel   文件: IOLocationTileList.java
private void initialize() {
	JLabel label = new JLabel();
	label.setUI(new ThumbnailLabelUI());
	setCellRenderer(new BasicTileCellRenderer(new GraphicCache(), label));

	setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
	setFixedCellWidth(100);
	setFixedCellHeight(100);
	setVisibleRowCount(-1);
	setLayoutOrientation(JList.HORIZONTAL_WRAP);
	addKeyListener(commitKeyListener);
	addKeyListener(typingListener);
	addMouseListener(commitMouseListener);
}
 
源代码30 项目: netbeans   文件: ListValuePicker.java
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    if(value instanceof ListValue) {
        ListValue lv = (ListValue) value;
        return super.getListCellRendererComponent(list, lv.displayValue, index, isSelected, cellHasFocus);
    }
    return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}