View Javadoc

1   /*
2    *  File: ICellRenderer.java 
3    *  Copyright (c) 2004-2007  Peter Kliem (Peter.Kliem@jaret.de)
4    *  A commercial license is available, see http://www.jaret.de.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Common Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/cpl-v10.html
10   */
11  package de.jaret.util.ui.table.renderer;
12  
13  import java.util.List;
14  
15  import org.eclipse.swt.graphics.GC;
16  import org.eclipse.swt.graphics.Rectangle;
17  import org.eclipse.swt.printing.Printer;
18  
19  import de.jaret.util.ui.table.JaretTable;
20  import de.jaret.util.ui.table.model.IColumn;
21  import de.jaret.util.ui.table.model.IRow;
22  
23  /***
24   * Interface for a cell renderer for a jaret table.
25   * 
26   * @author Peter Kliem
27   * @version $Id: ICellRenderer.java 179 2007-01-07 17:37:50Z olk $
28   */
29  public interface ICellRenderer {
30      /***
31       * Draw a single cell. The draw method should be null safe (handling null as the cell value).
32       * 
33       * @param gc GC to paint on
34       * @param jaretTable table the rendering is for
35       * @param cellStyle style of the cell
36       * @param drawingArea rectangle to draw within
37       * @param row row of the cell to paint
38       * @param column column of the cell to paint
39       * @param drawFocus true if a focus mark should be drawn
40       * @param selected true if the cell is currently selected
41       * @param printing true if the render operation is for a printer
42       */
43      void draw(GC gc, JaretTable jaretTable, ICellStyle cellStyle, Rectangle drawingArea, IRow row, IColumn column,
44              boolean drawFocus, boolean selected, boolean printing);
45  
46      /***
47       * Calculate the preferred width for the column.
48       * 
49       * @param rows the rows currently displayed by the table
50       * @param column the column for which the preferred width is to be calculated
51       * @return the preferred width or -1 for no special preferred width.
52       */
53      int getPreferredWidth(List<IRow> rows, IColumn column);
54  
55      /***
56       * Calculate the preferred height of a specific cell.
57       * 
58       * @param gc GC that will used
59       * @param cellStyle cell style of the cell
60       * @param width width of the column (thus of the cell)
61       * @param row row
62       * @param column column
63       * @return the preferred height or -1 for no special preferred height
64       */
65      int getPreferredHeight(GC gc, ICellStyle cellStyle, int width, IRow row, IColumn column);
66  
67      /***
68       * Provide a tooltip text for display.
69       * 
70       * @param jaretTable table that is asking
71       * @param drawingArea area of the cell rendering
72       * @param row row
73       * @param column column
74       * @param x mouse x coordinate (absolute within drawing area)
75       * @param y mouse y coordinate (abs within drawing area)
76       * @return tootip text or <code>null</code> if no tooltip is to be shown
77       */
78      String getTooltip(JaretTable jaretTable, Rectangle drawingArea, IRow row, IColumn column, int x, int y);
79  
80      /***
81       * Create a renderer connfigured for printing.
82       * 
83       * @param printer printer to use
84       * @return a configured renderer for printing
85       */
86      ICellRenderer createPrintRenderer(Printer printer);
87  
88      /***
89       * If there are resources to free - this is the place.
90       * 
91       */
92      void dispose();
93  
94  }