/* * $Id: TableRolloverController.java,v 1.2 2008/10/14 22:31:45 rah003 Exp $ * * Copyright 2008 Sun Microsystems, Inc., 4150 Network Circle, * Santa Clara, California 95054, U.S.A. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ package org.jdesktop.swingx.rollover; import java.awt.Cursor; import java.awt.Point; import java.awt.Rectangle; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; /** * listens to rollover properties. * Repaints effected component regions. * Updates link cursor. * * @author Jeanette Winzenburg */ public class TableRolloverController<T extends JTable> extends RolloverController<T> { private Cursor oldCursor; // --------------------------- JTable rollover @Override protected void rollover(Point oldLocation, Point newLocation) { if (oldLocation != null) { Rectangle r = component.getCellRect(oldLocation.y, oldLocation.x, false); r.x = 0; r.width = component.getWidth(); component.repaint(r); } if (newLocation != null) { Rectangle r = component.getCellRect(newLocation.y, newLocation.x, false); r.x = 0; r.width = component.getWidth(); component.repaint(r); } setRolloverCursor(newLocation); } /** * overridden to return false if cell editable. */ @Override protected boolean isClickable(Point location) { return super.isClickable(location) && !component.isCellEditable(location.y, location.x); } @Override protected RolloverRenderer getRolloverRenderer(Point location, boolean prepare) { TableCellRenderer renderer = component.getCellRenderer(location.y, location.x); RolloverRenderer rollover = renderer instanceof RolloverRenderer ? (RolloverRenderer) renderer : null; if ((rollover != null) && !rollover.isEnabled()) { rollover = null; } if ((rollover != null) && prepare) { component.prepareRenderer(renderer, location.y, location.x); } return rollover; } private void setRolloverCursor(Point location) { if (hasRollover(location)) { if (oldCursor == null) { oldCursor = component.getCursor(); component.setCursor(Cursor .getPredefinedCursor(Cursor.HAND_CURSOR)); } } else { if (oldCursor != null) { component.setCursor(oldCursor); oldCursor = null; } } } @Override protected Point getFocusedCell() { int leadRow = component.getSelectionModel() .getLeadSelectionIndex(); int leadColumn = component.getColumnModel().getSelectionModel() .getLeadSelectionIndex(); return new Point(leadColumn, leadRow); } }