001/** 002 * '$Author: barseghian $' 003 * '$Date: 2011-01-15 02:14:56 +0000 (Sat, 15 Jan 2011) $' 004 * '$Revision: 26692 $' 005 * 006 * For Details: 007 * http://www.kepler-project.org 008 * 009 * Copyright (c) 2009-2010 The Regents of the 010 * University of California. All rights reserved. Permission is hereby granted, 011 * without written agreement and without license or royalty fees, to use, copy, 012 * modify, and distribute this software and its documentation for any purpose, 013 * provided that the above copyright notice and the following two paragraphs 014 * appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF 015 * CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, 016 * OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS 017 * DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE 018 * POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY 019 * DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 020 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE 021 * SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF 022 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, 023 * ENHANCEMENTS, OR MODIFICATIONS. 024 */ 025 026package org.kepler.workflowrunmanager.gui; 027 028import java.awt.Component; 029import java.util.Map; 030 031import javax.swing.JLabel; 032import javax.swing.JTable; 033import javax.swing.table.TableCellRenderer; 034 035import org.kepler.util.WorkflowRun; 036import org.kepler.workflowrunmanager.WRMDefaults; 037 038import util.TableSorter; 039 040// This renderer extends a component. It is used each time a 041// cell must be displayed. 042public class WRMDefaultTableCellRenderer extends JLabel implements 043 TableCellRenderer { 044 // This method is called each time a cell in a column 045 // using this renderer needs to be rendered. 046 private TableSorter ts = null; 047 private WorkflowRunManagerTableModel wrmtm = null; 048 private int modelRowIndex; 049 private WRMDefaults wrmdefaults = WRMDefaults.getInstance(); 050 051 public WRMDefaultTableCellRenderer() { 052 setOpaque(true); 053 } 054 055 public Component getTableCellRendererComponent(JTable table, Object value, 056 boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) { 057 // 'value' is value contained in the cell located at 058 // (rowIndex, vColIndex) 059 060 setFont(WRMDefaults.WRM_FONT); 061 062 if (isSelected) { 063 // cell (and perhaps other cells) are selected 064 setBackground(table.getSelectionBackground()); 065 setForeground(table.getSelectionForeground()); 066 } else { 067 setBackground(table.getBackground()); 068 setForeground(table.getForeground()); 069 } 070 setSpecialBackgroundIfNecessary(table, rowIndex, isSelected); 071 072 // if (hasFocus) { 073 // this cell is the anchor and the table has the focus 074 // this.setBackground(table.getSelectionBackground()); 075 // } 076 077 try { 078 if (table.convertColumnIndexToModel(vColIndex) == wrmdefaults 079 .getDefaultColIndex(WRMDefaults.USER)){ 080 //|| table.convertColumnIndexToModel(vColIndex) == wrmdefaults 081 // .getDefaultColIndex(WRMDefaults.EXEC_ID)) { 082 setHorizontalAlignment(javax.swing.SwingConstants.RIGHT); 083 } 084 } catch (Exception e) { 085 // TODO Auto-generated catch block 086 e.printStackTrace(); 087 } 088 089 if (value != null) { 090 // setToolTipText(value.toString()); 091 setText(value.toString()); 092 } 093 094 // Since the renderer is a component, return itself 095 return this; 096 } 097 098 private void setSpecialBackgroundIfNecessary(JTable table, int rowIndex, 099 boolean isSelected) { 100 // paint cells in run rows with non-empty error msgs red. 101 // if not an error run, but an imported run, also paint special color 102 // TODO better way? i'm guessing this is very expensive: 103 ts = (TableSorter) table.getModel(); 104 wrmtm = (WorkflowRunManagerTableModel) ts.getTableModel(); 105 modelRowIndex = ts.modelIndex(rowIndex); 106 WorkflowRun wr = wrmtm.getWorkflowRunForRow(modelRowIndex); 107 Map<Integer,String> errs = wr.getErrorMessages(); 108 String type = wr.getType(); 109 110 //reset foreground in case it's changed 111 setForeground(table.getForeground()); 112 113 if (!errs.isEmpty()) { 114 if (isSelected) { 115 setBackground(WRMDefaults.ERROR_ROW_SELECTED_COLOR); 116 } else { 117 setBackground(WRMDefaults.ERROR_ROW_COLOR); 118 } 119 } 120 else if (type.equals(WorkflowRun.type.Imported.toString())) { 121 if (isSelected) { 122 setBackground(WRMDefaults.IMPORTED_ROW_SELECTED_COLOR); 123 } else { 124 setBackground(WRMDefaults.IMPORTED_ROW_COLOR); 125 } 126 } 127 128 if (type.equals(WorkflowRun.type.Preview.toString()) || 129 type.equals(WorkflowRun.type.Preview_Error.toString())) { 130 if (!isSelected){ 131 setForeground(WRMDefaults.PREVIEW_TEXT_COLOR); 132 } 133 } 134 } 135 136 // The following methods override the defaults for performance reasons 137 public void validate() { 138 } 139 140 public void revalidate() { 141 } 142 143 protected void firePropertyChange(String propertyName, Object oldValue, 144 Object newValue) { 145 } 146 147 public void firePropertyChange(String propertyName, boolean oldValue, 148 boolean newValue) { 149 } 150 151}