001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.swing;
019:
020: import java.awt.Component;
021: import java.io.Serializable;
022: import javax.swing.border.Border;
023:
024: /**
025: * <p>
026: * <i>DefaultListCellRenderer</i>
027: * </p>
028: * <h3>Implementation Notes:</h3>
029: * <ul>
030: * <li>The <code>serialVersionUID</code> fields are explicitly declared as a performance
031: * optimization, not as a guarantee of serialization compatibility.</li>
032: * </ul>
033: */
034: public class DefaultListCellRenderer extends JLabel implements
035: ListCellRenderer, Serializable {
036: private static final long serialVersionUID = -4095659446023979489L;
037:
038: public static class UIResource extends DefaultListCellRenderer
039: implements javax.swing.plaf.UIResource {
040: private static final long serialVersionUID = 5748603813962368116L;
041: }
042:
043: protected static Border noFocusBorder = BorderFactory
044: .createEmptyBorder(1, 1, 1, 1);
045:
046: public DefaultListCellRenderer() {
047: setBorder(noFocusBorder);
048: setHorizontalAlignment(SwingConstants.LEADING);
049: setOpaque(true);
050: }
051:
052: public Component getListCellRendererComponent(JList list,
053: Object value, int index, boolean isSelected,
054: boolean cellHasFocus) {
055: setText(value != null ? value.toString() : null);
056: if (isSelected) {
057: setForeground(list.getSelectionForeground());
058: setBackground(list.getSelectionBackground());
059: } else {
060: setForeground(list.getForeground());
061: setBackground(list.getBackground());
062: }
063: setOpaque(true);
064: setFont(list.getFont());
065: setEnabled(list.isEnabled());
066: setBorder(cellHasFocus ? UIManager
067: .getBorder("List.focusCellHighlightBorder")
068: : noFocusBorder);
069: setComponentOrientation(list.getComponentOrientation());
070: return this ;
071: }
072:
073: @Override
074: public void firePropertyChange(String propertyName,
075: boolean oldValue, boolean newValue) {
076: }
077:
078: @Override
079: public void firePropertyChange(String propertyName, byte oldValue,
080: byte newValue) {
081: }
082:
083: @Override
084: public void firePropertyChange(String propertyName, char oldValue,
085: char newValue) {
086: }
087:
088: @Override
089: public void firePropertyChange(String propertyName,
090: double oldValue, double newValue) {
091: }
092:
093: @Override
094: public void firePropertyChange(String propertyName, float oldValue,
095: float newValue) {
096: }
097:
098: @Override
099: public void firePropertyChange(String propertyName, int oldValue,
100: int newValue) {
101: }
102:
103: @Override
104: public void firePropertyChange(String propertyName, long oldValue,
105: long newValue) {
106: }
107:
108: @Override
109: public void firePropertyChange(String propertyName, short oldValue,
110: short newValue) {
111: }
112:
113: @Override
114: protected void firePropertyChange(String propertyName,
115: Object oldValue, Object newValue) {
116: }
117: }
|