Java 类javax.swing.DefaultListCellRenderer 实例源码
项目:incubator-netbeans
文件:FoldOptionsPanel.java
/**
* Creates new form FoldOptionsPanel
*/
public FoldOptionsPanel(FoldOptionsController ctrl) {
this.ctrl = ctrl;
initComponents();
langSelect.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof String[]) {
value = ((String[])value)[1];
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //To change body of generated methods, choose Tools | Templates.
}
});
langSelect.addActionListener(this);
contentPreview.addActionListener(this);
foldedSummary.addActionListener(this);
// preferences should be set as a reaction to index selection
}
项目:incubator-netbeans
文件:EditRulesPanel.java
private ListCellRenderer createSelectorsRenderer() {
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) {
SelectorItemRenderer selectorModelItemRenderer = getSelectorModelItemRenderer();
selectorModelItemRenderer.setItem((SelectorItem) value, isSelected);
return selectorModelItemRenderer;
// setText(item.getDisplayName());
}
return c;
}
};
}
项目:incubator-netbeans
文件:EditRulesPanel.java
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;
}
FileObject file = (FileObject) value;
String fileNameExt = file.getNameExt();
setText(fileNameExt);
// if(file.equals(context)) {
// StringBuilder sb = new StringBuilder();
// sb.append("<html><body><b>"); //NOI18N
// sb.append(fileNameExt);
// sb.append("</b></body></html>"); //NOI18N
// setText(sb.toString());
// } else {
// setText(fileNameExt);
// }
return c;
}
};
}
项目:incubator-netbeans
文件:CreateRulePanel.java
/**
* Creates a renderer for the at-rules combobox dropdown.
*/
private ListCellRenderer createAtRulesRenderer() {
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) {
setText(Bundle.none_item());
} else if(value instanceof AtRuleItem) {
setText(((AtRuleItem) value).getDisplayName());
} else if(value instanceof String) {
setText((String)value);
}
return c;
}
};
}
项目:incubator-netbeans
文件:ShowEffPomDiffPanel.java
/**
* Creates new form ShowEffPomDiffPanel
*/
public ShowEffPomDiffPanel(ProjectConfigurationProvider<MavenConfiguration> configs) {
initComponents();
ComboBoxModel<MavenConfiguration> model = new DefaultComboBoxModel<MavenConfiguration>(configs.getConfigurations().toArray(new MavenConfiguration[0]));
comConfiguration.setModel(model);
comConfiguration.setEditable(false);
comConfiguration.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
return super.getListCellRendererComponent(list, ((ProjectConfiguration)value).getDisplayName(), index, isSelected, cellHasFocus);
}
});
comConfiguration.setSelectedItem(configs.getActiveConfiguration());
enableFields();
epProperties.setContentType("text/x-properties");
}
项目:incubator-netbeans
文件:UnshelveChangesAction.java
public Unshelve () {
panel = new UnshelveChangesPanel();
panel.cmbPatches.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent (JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof Patch) {
value = ((Patch) value).getPatchName();
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
unshelveButton = new JButton();
removeButton = new JButton();
panel.cmbPatches.addActionListener(this);
initializePatches();
}
项目:incubator-netbeans
文件:ModifyElementRulesPanel.java
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) {
setText("<html>" + Bundle.none_item());
} else {
FileObject file = (FileObject) value;
FileObject webRoot = ProjectWebRootQuery.getWebRoot(file);
String file2string;
if (webRoot != null) {
file2string = FileUtil.getRelativePath(webRoot, file);
} else {
file2string = FileUtil.getFileDisplayName(file);
}
setText(file2string);
}
return c;
}
};
}
项目:incubator-netbeans
文件:OnSaveTabPanel.java
public OnSaveTabPanel() {
initComponents();
// Languages combobox renderer
cboLanguage.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if ((value instanceof String) && selector != null) {
value = selector.getLanguageName((String) value);
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
commonPanel = new OnSaveCommonPanel();
commonPanelContainer.setLayout(new BorderLayout());
commonPanelContainer.add(commonPanel, BorderLayout.WEST);
customPanelContainer.setLayout(new BorderLayout());
}
项目:incubator-netbeans
文件:FolderBasedOptionPanel.java
/** Creates new form FolderBasedOptionPanel */
FolderBasedOptionPanel(FolderBasedController controller, Document filterDocument, boolean allowFiltering) {
this.controller = controller;
initComponents();
filter.setDocument(filterDocument);
if (!allowFiltering) {
filter.setVisible(false);
filterLabel.setVisible(false);
}
ListCellRenderer renderer = new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof String)
value = EditorSettings.getDefault().getLanguageName((String)value);
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
};
languageCombo.setRenderer(renderer);
languageCombo.addActionListener(this);
update();
}
项目:incubator-netbeans
文件:CodeCompletionOptionsPanel.java
/**
* Creates new form CodeCompletionOptionsPanel.
*/
public CodeCompletionOptionsPanel () {
initComponents ();
// Languages combobox renderer
cbLanguage.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if (value instanceof String) {
value = ((String)value).length() > 0
? EditorSettings.getDefault().getLanguageName((String)value)
: org.openide.util.NbBundle.getMessage(CodeCompletionOptionsPanel.class, "LBL_AllLanguages"); //NOI18N
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
}
项目:incubator-netbeans
文件:CharsetSelector.java
public CharsetSelector() {
super(
Charset.availableCharsets().values().toArray(new Charset[]{})
);
this.setRenderer(new DefaultListCellRenderer(){
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Object displayValue;
if(value instanceof Charset) {
displayValue = ((Charset) value).displayName();
} else {
displayValue = value;
}
return super.getListCellRendererComponent(list, displayValue, index, isSelected, cellHasFocus);
}
});
}
项目:JavaGraph
文件:FindReplaceDialog.java
/** Returns the combo box for the label in the given type graph. */
private JComboBox<TypeLabel> getLabelComboBox(TypeGraph typeGraph) {
final JComboBox<TypeLabel> result = new JComboBox<>();
result.setFocusable(false);
result.setRenderer(new DefaultListCellRenderer() {
@SuppressWarnings("rawtypes")
@Override
public Component getListCellRendererComponent(JList list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
if (value instanceof TypeLabel) {
value = HTMLConverter.HTML_TAG.on(((TypeLabel) value).toLine().toHTMLString());
}
return super.getListCellRendererComponent(list,
value,
index,
isSelected,
cellHasFocus);
}
});
for (TypeLabel label : sortLabels(typeGraph.getLabels())) {
if (!label.isDataType() && label != TypeLabel.NODE) {
result.addItem(label);
}
}
return result;
}
项目:Equella
文件:DisplayNodeList.java
public DisplayNodeList(final SchemaModel schemaModel, final boolean extrasVisible)
{
super(true);
this.schemaModel = schemaModel;
this.extrasVisible = extrasVisible;
setListCellRenderer(new DefaultListCellRenderer()
{
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus)
{
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
String title = CurrentLocale.get(((DisplayNode) value).getTitle(), null);
setText(title != null ? title : UNTITLED);
return this;
}
});
}
项目:word-constraints
文件:SepComboBox.java
private ListCellRenderer createRenderer()
{
return new DefaultListCellRenderer()
{
private final Component SEPARATOR = new SeparatorComponent();
public Component getListCellRendererComponent( JList list,
Object value, int index, boolean isSelected, boolean cellHasFocus)
{
if ( value instanceof ComboItem )
{
value = ((ComboItem)value).getDelegate();
}
if ( value == null )
{
return SEPARATOR;
}
return super.getListCellRendererComponent( list, value, index,
isSelected, cellHasFocus );
}
};
}
项目:openjdk-jdk10
文件: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);
}
项目:openjdk-jdk10
文件:UpdateUIRecursionTest.java
public UpdateUIRecursionTest() {
super("UpdateUIRecursionTest");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 400);
String[] listData = {
"First", "Second", "Third", "Fourth", "Fifth", "Sixth"
};
combo = new JComboBox(listData);
combo.setRenderer(this);
renderer = new DefaultListCellRenderer();
getContentPane().add(new JScrollPane(combo), BorderLayout.CENTER);
setVisible(true);
}
项目:gcs
文件:LibraryDockable.java
private void createCategoryCombo() {
mCategoryCombo = new JComboBox<>();
// Next two client properties are specific to Mac OS X
mCategoryCombo.putClientProperty("JComponent.sizeVariant", "small"); //$NON-NLS-1$ //$NON-NLS-2$
mCategoryCombo.putClientProperty("JComboBox.isPopDown", Boolean.TRUE); //$NON-NLS-1$
mCategoryCombo.setMaximumRowCount(20);
mCategoryCombo.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component comp = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
setFont(getFont().deriveFont(index == 0 ? Font.ITALIC : Font.PLAIN));
return comp;
}
});
mCategoryCombo.addActionListener((event) -> {
mCategoryCombo.setFont(mCategoryCombo.getFont().deriveFont(mCategoryCombo.getSelectedIndex() == 0 ? Font.ITALIC : Font.PLAIN));
mCategoryCombo.revalidate();
mCategoryCombo.repaint();
if (mOutline != null) {
mOutline.reapplyRowFilter();
}
});
mToolbar.add(mCategoryCombo);
adjustCategoryCombo();
}
项目:Ardulink-2
文件:ConnectionPanel.java
private JComboBox createURICombo() {
JComboBox uris = new JComboBox();
uris.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 2756587449741341859L;
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {
return super.getListCellRendererComponent(list,
extractNameFromURI(URIs.newURI((String) value)), index,
isSelected, cellHasFocus);
}
});
uris.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent event) {
if (event.getStateChange() == SELECTED) {
replaceSubpanel();
}
}
});
return uris;
}
项目:jailer
文件:AssociationEditor.java
/**
* Creates renderer for {@link AssociationEditor#type}.
*
* @return renderer for {@link AssociationEditor#type}
*/
private ListCellRenderer createTypeRenderer() {
DefaultListCellRenderer renderer = new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean cellHasFocus) {
if ("".equals(value)) {
value = "associates";
} else if ("A".equals(value)) {
value = "has dependent";
} else if ("B".equals(value)) {
value = "depends on";
}
return super.getListCellRendererComponent(list, value, index, isSelected,
cellHasFocus);
}
private static final long serialVersionUID = 1992399605806444015L;
};
return renderer;
}
项目:sqlpower-library
文件:DataSourceTypeCopyPropertiesPanel.java
public DataSourceTypeCopyPropertiesPanel(JDBCDataSourceType type, DataSourceCollection collection) {
this.dsType = type;
List<JDBCDataSourceType> types = new ArrayList<JDBCDataSourceType>(collection.getDataSourceTypes());
types.remove(dsType);
dsTypesComboBox = new JComboBox(types.toArray());
dsTypesComboBox.setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected, boolean cellHasFocus) {
Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (c instanceof JLabel && value != null) {
((JLabel) c).setText(((JDBCDataSourceType) value).getName());
}
return c;
}
});
panel = buildUI();
}
项目:Stud.IP-Client
文件:DropDownBox.java
@SuppressWarnings("rawtypes")
@Override
protected ListCellRenderer createRenderer() {
return new ListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
boolean cellHasFocus) {
JLabel renderer = (JLabel) new DefaultListCellRenderer().getListCellRendererComponent(list, value,
index, isSelected, cellHasFocus);
if (cellHasFocus || isSelected) {
renderer.setBackground(Template.COLOR_ACCENT);
renderer.setForeground(Color.WHITE);
} else {
renderer.setBackground(Color.WHITE);
renderer.setForeground(Color.BLACK);
}
renderer.setBorder(new EmptyBorder(5, 5, 5, 5));
return renderer;
}
};
}
项目:vso-intellij
文件:CreatePullRequestForm.java
private void createUIComponents() {
this.targetBranchDropdown = new JComboBox();
this.targetBranchDropdown.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list,
Object gitRemoteBranch,
int index,
boolean isSelected,
boolean cellHasFocus) {
return super.getListCellRendererComponent(list,
gitRemoteBranch != null ? ((GitRemoteBranch) gitRemoteBranch).getName() : "",
index,
isSelected,
cellHasFocus);
}
});
this.targetBranchDropdown.setActionCommand(CMD_TARGET_BRANCH_UPDATED);
}
项目:vso-intellij
文件:CreateBranchForm.java
private void ensureInitialized() {
if (!this.initialized) {
// override the renderer so it doesn't show the object toString but instead shows the branch name
remoteBranchComboBox.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
return super.getListCellRendererComponent(list,
value != null ? ((GitRemoteBranch) value).getName() : StringUtils.EMPTY,
index,
isSelected,
cellHasFocus);
}
});
this.initialized = true;
}
}
项目:openwonderland
文件:ModelCellComponentProperties.java
/** Creates new form SampleComponentProperties */
public ModelCellComponentProperties() {
// Initialize the GUI
initComponents();
// Listen for changes to the info text field
deployedModelURLTF.getDocument().addDocumentListener(
new InfoTextFieldListener());
ComboBoxModel cb = new DefaultComboBoxModel(TransparencyMode.values());
transparencyCB.setModel(cb);
transparencyCB.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value,
int index, boolean isSelected,
boolean cellHasFocus)
{
TransparencyMode tv = (TransparencyMode) value;
String valueString = BUNDLE.getString("TransparencyMode_" + tv.name());
return super.getListCellRendererComponent(list, valueString, index,
isSelected, cellHasFocus);
}
});
}
项目:CryodexSource
文件:L5RRoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CryodexSource
文件:ArmadaRoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CryodexSource
文件:DestinyRoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CryodexSource
文件:SWLCGRoundPanel.java
private JComboBox<String> getGame1ResultCombo() {
if (game1ResultsCombo == null) {
game1ResultsCombo = new JComboBox<String>(getComboValues());
game1ResultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
game1ResultsCombo.addActionListener(this);
}
return game1ResultsCombo;
}
项目:CryodexSource
文件:SWLCGRoundPanel.java
private JComboBox<String> getGame2ResultCombo() {
if (game2ResultsCombo == null) {
game2ResultsCombo = new JComboBox<String>(getComboValues());
game2ResultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
game2ResultsCombo.addActionListener(this);
}
return game2ResultsCombo;
}
项目:CryodexSource
文件:XWingRoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CryodexSource
文件:IARoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CryodexSource
文件:RunewarsRoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CryodexSource
文件:EtcRoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CryodexSource
文件:KraytRoundPanel.java
private JComboBox<String> getResultCombo() {
if (resultsCombo == null) {
resultsCombo = new JComboBox<String>(getComboValues());
resultsCombo.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public void paint(Graphics g) {
setForeground(Color.BLACK);
super.paint(g);
}
});
resultsCombo.addActionListener(GamePanel.this);
}
return resultsCombo;
}
项目:CodenameOne
文件:PickMIDlet.java
/** Creates new form PickMIDlet */
public PickMIDlet() {
initComponents();
midletPicker.setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
if(value == null) {
value = "";
} else {
String s = (String)value;
value = s.substring(0, s.indexOf(','));
}
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
Preferences pref = Preferences.userNodeForPackage(ResourceEditorView.class);
jarFile.setText(pref.get("jar", ""));
updateMIDletList();
midletPicker.setSelectedItem(pref.get("midlet", null));
customComponents = null;
}
项目:svarog
文件:WignerMapScaleComboBoxCellRenderer.java
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
DefaultListCellRenderer renderer = (DefaultListCellRenderer) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (value instanceof WignerMapScaleType) {
WignerMapScaleType scale = (WignerMapScaleType) value;
renderer.setText(scale.i18n());
if (scale == WignerMapScaleType.NORMAL) {
renderer.setIcon(linearIcon);
}
else if (scale == WignerMapScaleType.LOG) {
renderer.setIcon(logIcon);
}
else if (scale == WignerMapScaleType.SQRT) {
renderer.setIcon(sqrtIcon);
} else {
// else no icon
renderer.setIcon(null);
}
}
// else leave text put by superclass
return renderer;
}
项目:settlers-remake
文件:EditorControl.java
/**
* Constructor
*/
public EditorControl() {
// use heavyweight component
playerCombobox.setLightWeightPopupEnabled(false);
playerCombobox.addActionListener(e -> currentPlayer = (Integer) playerCombobox.getSelectedItem());
playerCombobox.setRenderer(new DefaultListCellRenderer() {
private static final long serialVersionUID = 1L;
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
Integer player = (Integer) value;
setIcon(new RectIcon(22, new Color(mapContent.getPlayerColor(player.byteValue()).getARGB()), Color.GRAY));
setText(String.format(Locale.ENGLISH, EditorLabels.getLabel("general.player_x"), player));
return this;
}
});
}
项目:cn1
文件:BasicListUITest.java
public void testGetPreferredSize() throws Exception {
ui.installUI(list);
list.setSize(100, 100);
assertEquals(new Dimension(0, 0), ui.getPreferredSize(list));
list.setListData(new Object[] { "a", "bbb" });
Component renderer = new DefaultListCellRenderer().getListCellRendererComponent(list,
"bbb", 1, false, false);
assertEquals(new Dimension(renderer.getPreferredSize().width, 2 * renderer
.getPreferredSize().height), ui.getPreferredSize(list));
list.setFixedCellHeight(20);
list.setFixedCellWidth(30);
assertEquals(new Dimension(30, 40), ui.getPreferredSize(list));
list.setVisibleRowCount(1);
assertEquals(new Dimension(30, 40), ui.getPreferredSize(list));
list.setLayoutOrientation(JList.VERTICAL_WRAP);
assertEquals(new Dimension(60, 20), ui.getPreferredSize(list));
}
项目:cn1
文件:BasicListUITest.java
public void testIndexToLocation() throws Exception {
ui.installUI(list);
assertNull(ui.indexToLocation(list, -1));
assertNull(ui.indexToLocation(list, 0));
list.setListData(new Object[] { "a", "bbb" });
Component renderer = new DefaultListCellRenderer().getListCellRendererComponent(list,
"bbb", 1, false, false);
assertEquals(new Point(0, 0), ui.indexToLocation(list, 0));
assertEquals(new Point(0, renderer.getPreferredSize().height), ui.indexToLocation(list,
1));
list.setVisibleRowCount(1);
list.setLayoutOrientation(JList.VERTICAL_WRAP);
assertEquals(new Point(0, 0), ui.indexToLocation(list, 0));
assertEquals(new Point(renderer.getPreferredSize().width, 0), ui.indexToLocation(list,
1));
assertNull(ui.indexToLocation(list, 2));
}
项目:cn1
文件:BasicListUITest.java
public void testInstallDefaults() throws Exception {
UIManager.getDefaults().put("List.background", new ColorUIResource(Color.red));
UIManager.getDefaults().put("List.foreground", new ColorUIResource(Color.yellow));
Font font = new FontUIResource(list.getFont().deriveFont(100f));
UIManager.getDefaults().put("List.font", font);
DefaultListCellRenderer renderer = new DefaultListCellRenderer.UIResource();
UIManager.getDefaults().put("List.cellRenderer", renderer);
Border border = new BorderUIResource(BorderFactory.createEmptyBorder(0, 0, 0, 0));
UIManager.getDefaults().put("List.border", border);
list.setUI(ui);
ui.installDefaults();
assertEquals(Color.red, list.getBackground());
assertEquals(Color.yellow, list.getForeground());
assertEquals(font, list.getFont());
assertEquals(renderer, list.getCellRenderer());
assertEquals(border, list.getBorder());
}