001 /* 002 * Licensed under the Apache License, Version 2.0 (the "License"); 003 * you may not use this file except in compliance with the License. 004 * You may obtain a copy of the License at 005 * 006 * http://www.apache.org/licenses/LICENSE-2.0 007 * 008 * Unless required by applicable law or agreed to in writing, software 009 * distributed under the License is distributed on an "AS IS" BASIS, 010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 011 * See the License for the specific language governing permissions and 012 * limitations under the License. 013 */ 014 /* 015 * This file has been modified by Chris Pheby in accordance with Section 4.2 016 * of the Apache Software License 017 */ 018 package org.jadira.dependencynavigator.gui; 019 020 import java.awt.Color; 021 import java.awt.Component; 022 import java.awt.Font; 023 024 import javax.swing.JTable; 025 import javax.swing.table.DefaultTableCellRenderer; 026 027 public class SelectableTableModelRenderer extends DefaultTableCellRenderer { 028 029 private static final long serialVersionUID = 5386816137675796795L; 030 031 @Override 032 public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { 033 DefaultTableCellRenderer r = (DefaultTableCellRenderer) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); 034 SelectableTableModel model = (SelectableTableModel) table.getModel(); 035 r.setForeground(Color.BLACK); 036 if (model.isSelected(row)) { 037 r.setFont(r.getFont().deriveFont(Font.BOLD)); 038 r.setBackground(Color.YELLOW); 039 r.setOpaque(true); 040 } else { 041 r.setFont(r.getFont().deriveFont(Font.PLAIN)); 042 r.setBackground(Color.WHITE); 043 r.setOpaque(false); 044 } 045 return r; 046 } 047 }