001 /*
002 * $Id: ListCellContext.java 3424 2009-07-30 10:53:39Z kleopatra $
003 *
004 * Copyright 2008 Sun Microsystems, Inc., 4150 Network Circle,
005 * Santa Clara, California 95054, U.S.A. All rights reserved.
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
020 */
021 package org.jdesktop.swingx.renderer;
022
023 import java.awt.Color;
024
025 import javax.swing.JList;
026
027 /**
028 * List specific <code>CellContext</code>.
029 */
030 public class ListCellContext extends CellContext {
031
032 /**
033 * Sets state of the cell's context. Note that the component might be null
034 * to indicate a cell without a concrete context. All accessors must cope
035 * with.
036 *
037 * @param component the component the cell resides on, might be null
038 * @param value the content value of the cell
039 * @param row the cell's row index in view coordinates
040 * @param column the cell's column index in view coordinates
041 * @param selected the cell's selected state
042 * @param focused the cell's focused state
043 * @param expanded the cell's expanded state
044 * @param leaf the cell's leaf state
045 */
046 public void installContext(JList component, Object value, int row, int column,
047 boolean selected, boolean focused, boolean expanded, boolean leaf) {
048 this.component = component;
049 installState(value, row, column, selected, focused, expanded, leaf);
050 this.dropOn = checkDropOnState();
051 }
052
053 /**
054 *
055 */
056 private boolean checkDropOnState() {
057 if ((getComponent() == null)) {
058 return false;
059 }
060 JList.DropLocation dropLocation = getComponent().getDropLocation();
061 if (dropLocation != null
062 && !dropLocation.isInsert()
063 && dropLocation.getIndex() == row) {
064 return true;
065 }
066 return false;
067 }
068
069
070 @Override
071 public JList getComponent() {
072 return (JList) super.getComponent();
073 }
074
075 /**
076 * {@inheritDoc}
077 */
078 @Override
079 protected Color getSelectionBackground() {
080 Color selection = null;
081 if (isDropOn()) {
082 selection = getDropCellBackground();
083 if (selection != null) return selection;
084 }
085 return getComponent() != null ? getComponent().getSelectionBackground() : null;
086 }
087
088 /**
089 * {@inheritDoc}
090 */
091 @Override
092 protected Color getSelectionForeground() {
093 Color selection = null;
094 if (isDropOn()) {
095 selection = getDropCellForeground();
096 if (selection != null) return selection;
097 }
098 return getComponent() != null ? getComponent().getSelectionForeground() : null;
099 }
100
101 /**
102 * {@inheritDoc}
103 */
104 @Override
105 protected String getUIPrefix() {
106 return "List.";
107 }
108
109
110
111 }