KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > renderings > AsyncPrintTableRenderingAction


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.debug.internal.ui.views.memory.renderings;
13
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.jface.viewers.StructuredViewer;
17 import org.eclipse.swt.graphics.GC;
18 import org.eclipse.swt.printing.Printer;
19 import org.eclipse.swt.widgets.Table;
20 import org.eclipse.swt.widgets.TableItem;
21
22 /**
23  * Print action for <code>AbstractAsyncTableRendering</code>. Only print what is visible in the view.
24  *
25  */

26 public class AsyncPrintTableRenderingAction extends PrintTableRenderingAction {
27
28     public AsyncPrintTableRenderingAction(AbstractBaseTableRendering rendering, StructuredViewer viewer) {
29         super(rendering, viewer);
30     }
31
32     protected void printTable(TableItem[] itemList, GC printGC, Printer printer) {
33         Table table = null;
34         if (itemList.length > 0)
35             table = itemList[0].getParent();
36         
37         int topIndex = table.getTopIndex();
38         int itemCount = table.getItemCount();
39         int numVisibleLines = Math.min((table.getBounds().height / table.getItemHeight()) + 2, itemCount - topIndex);
40         
41         ArrayList JavaDoc items = new ArrayList JavaDoc();
42         
43         // start at top index until there is no more data in the table
44
for (int i=topIndex; i< topIndex + numVisibleLines; i++)
45         {
46             if (itemList[i].getData() != null)
47             {
48                 items.add(itemList[i]);
49             }
50             else
51                 break;
52         }
53         
54         super.printTable((TableItem[])items.toArray(new TableItem[items.size()]), printGC, printer);
55     }
56 }
57
Popular Tags