KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > db > sql > visualeditor > querybuilder > QueryBuilderTable


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  *
22  * @author Sanjay Dhamankar
23  */

24
25 package org.netbeans.modules.db.sql.visualeditor.querybuilder;
26
27 import javax.swing.JTable JavaDoc;
28
29 import javax.swing.table.TableColumn JavaDoc;
30
31 import java.awt.*;
32
33 import org.openide.ErrorManager;
34
35 import org.netbeans.modules.db.sql.visualeditor.Log;
36
37 // Represents the information presented inside a table node, which includes
38
// selected status, key status, and column name
39

40 public class QueryBuilderTable extends JTable JavaDoc {
41
42     private boolean DEBUG = false;
43
44
45     // Constructor
46

47     public QueryBuilderTable( QueryBuilderTableModel model) {
48
49         super();
50         super.setModel( model );
51
52         Log.err.log(ErrorManager.INFORMATIONAL, "Entering QueryBuilderTable ctor, model: " + model); // NOI18N
53

54         this.setAutoResizeMode (JTable.AUTO_RESIZE_OFF);
55
56         // This may not be required afterall. We need to keep the size of the cell fixed.
57
this.initColumnSizes(this, model);
58         this.setShowHorizontalLines(false);
59         this.setShowVerticalLines(false);
60         this.setBackground(Color.white);
61         this.setRowHeight(this.getRowHeight() + 2);
62         this.setRowSelectionAllowed (false);
63         this.setTableHeader (null);
64     }
65
66
67     // Methods
68

69     private void initColumnSizes(JTable JavaDoc table, QueryBuilderTableModel model) {
70
71         TableColumn JavaDoc column = null;
72         Component comp = null;
73         int headerWidth = 0;
74         int cellWidth = 0;
75
76         for (int i = 0; i < getColumnCount(); i++) {
77
78             column = table.getColumnModel().getColumn(i);
79
80             comp = table.getDefaultRenderer(column.getClass()).
81                 getTableCellRendererComponent(
82                     table, column.getHeaderValue(),
83                     false, false, -1, 0);
84             headerWidth = comp.getPreferredSize().width;
85
86             try {
87                 comp = column.getHeaderRenderer().
88                     getTableCellRendererComponent(
89                         null, column.getHeaderValue(),
90                         false, false, 0, 0);
91                 headerWidth = comp.getPreferredSize().width;
92             } catch (NullPointerException JavaDoc e) {
93             }
94
95             if ( i != 0 )
96             {
97                 for (int j=0; j< table.getRowCount(); j++)
98                 {
99                     comp = table.getDefaultRenderer(model.getColumnClass(i)).
100                         getTableCellRendererComponent(
101                             table, getValueAt(j, 2),
102                             false, false, 0, i);
103                     int tmpCellWidth = comp.getPreferredSize().width;
104
105                     if ( tmpCellWidth > cellWidth )
106                         cellWidth = tmpCellWidth;
107                 }
108             }
109
110             //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
111
column.setPreferredWidth(Math.max(headerWidth+15, cellWidth+15));
112         }
113
114         table.addNotify();
115     }
116 }
117
Popular Tags