Source Code Cross Referenced for BlobColumnRenderer.java in  » Database-Client » SQL-Workbench » workbench » gui » renderer » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database Client » SQL Workbench » workbench.gui.renderer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BlobColumnRenderer.java
003:         *
004:         * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005:         *
006:         * Copyright 2002-2008, Thomas Kellerer
007:         * No part of this code maybe reused without the permission of the author
008:         *
009:         * To contact the author please send an email to: support@sql-workbench.net
010:         *
011:         */
012:        package workbench.gui.renderer;
013:
014:        import java.awt.Color;
015:        import java.awt.Component;
016:        import java.awt.Font;
017:        import java.awt.event.ActionEvent;
018:        import java.awt.event.ActionListener;
019:        import java.awt.event.MouseEvent;
020:        import java.io.File;
021:        import java.util.EventObject;
022:        import javax.swing.AbstractCellEditor;
023:        import javax.swing.JTable;
024:        import javax.swing.SwingConstants;
025:        import javax.swing.table.TableCellEditor;
026:        import javax.swing.table.TableCellRenderer;
027:        import javax.swing.table.TableColumn;
028:        import javax.swing.table.TableColumnModel;
029:        import workbench.WbManager;
030:        import workbench.gui.WbSwingUtilities;
031:        import workbench.gui.actions.WbAction;
032:        import workbench.gui.components.*;
033:        import workbench.resource.Settings;
034:
035:        /**
036:         * @author  support@sql-workbench.net
037:         */
038:        public class BlobColumnRenderer extends AbstractCellEditor implements 
039:                TableCellEditor, ActionListener, TableCellRenderer, WbRenderer {
040:            private BlobColumnPanel displayPanel;
041:            private Object currentValue;
042:            private WbTable currentTable;
043:            private boolean isPrinting = false;
044:            private int currentRow;
045:            private int currentColumn;
046:            private Color alternateColor = Settings.getInstance()
047:                    .getAlternateRowColor();
048:            private Color nullColor = Settings.getInstance().getNullColor();
049:
050:            private boolean useAlternatingColors = Settings.getInstance()
051:                    .getUseAlternateRowColor();
052:
053:            public BlobColumnRenderer() {
054:                super ();
055:                this .displayPanel = new BlobColumnPanel();
056:                this .displayPanel.addActionListener(this );
057:            }
058:
059:            public void setFont(Font aFont) {
060:                this .displayPanel.setFont(aFont);
061:            }
062:
063:            public Component getTableCellEditorComponent(JTable table,
064:                    Object value, boolean isSelected, int row, int column) {
065:                return getComponent(table, value, true, isSelected, row, column);
066:            }
067:
068:            public int getHorizontalAlignment() {
069:                return SwingConstants.LEFT;
070:            }
071:
072:            public Component getTableCellRendererComponent(JTable table,
073:                    Object value, boolean isSelected, boolean hasFocus,
074:                    int row, int column) {
075:                return getComponent(table, value, isSelected, hasFocus, row,
076:                        column);
077:            }
078:
079:            private Component getComponent(JTable table, Object value,
080:                    boolean isSelected, boolean hasFocus, int row, int column) {
081:                if (isSelected) {
082:                    this .displayPanel.setForeground(table
083:                            .getSelectionForeground());
084:                    this .displayPanel.setBackground(table
085:                            .getSelectionBackground());
086:                } else {
087:                    this .displayPanel.setForeground(table.getForeground());
088:                    if (value == null && nullColor != null) {
089:                        this .displayPanel.setBackground(nullColor);
090:                    } else {
091:                        if (useAlternatingColors && ((row % 2) == 1)) {
092:                            this .displayPanel
093:                                    .setBackground(this .alternateColor);
094:                        } else {
095:                            this .displayPanel.setBackground(table
096:                                    .getBackground());
097:                        }
098:                    }
099:                }
100:                if (hasFocus) {
101:                    this .displayPanel
102:                            .setBorder(WbSwingUtilities.FOCUSED_CELL_BORDER);
103:                } else {
104:                    this .displayPanel.setBorder(WbSwingUtilities.EMPTY_BORDER);
105:                }
106:
107:                currentValue = value;
108:                currentRow = row;
109:                currentColumn = column;
110:                currentTable = (WbTable) table;
111:                displayPanel.setValue(value);
112:                return displayPanel;
113:            }
114:
115:            public boolean isCellEditable(EventObject e) {
116:                if (e instanceof  MouseEvent) {
117:                    MouseEvent evt = (MouseEvent) e;
118:                    this .currentTable = (WbTable) e.getSource();
119:
120:                    int clickedColumn = this .currentTable.columnAtPoint(evt
121:                            .getPoint());
122:                    TableColumnModel model = this .currentTable.getColumnModel();
123:                    int columnOffset = 0;
124:                    for (int i = 0; i < clickedColumn; i++) {
125:                        columnOffset += model.getColumn(i).getWidth();
126:                    }
127:                    TableColumn col = model.getColumn(clickedColumn);
128:                    int posInCol = ((int) evt.getPoint().getX() - columnOffset);
129:                    int buttonStart = (col.getWidth() - displayPanel
130:                            .getButtonWidth());
131:                    boolean buttonClicked = (posInCol >= buttonStart);
132:                    return buttonClicked;
133:                }
134:                return false;
135:            }
136:
137:            public void setBackground(Color c) {
138:                this .displayPanel.setBackground(c);
139:            }
140:
141:            public Object getCellEditorValue() {
142:                return currentValue;
143:            }
144:
145:            public String getDisplayValue() {
146:                return displayPanel.getLabel();
147:            }
148:
149:            public void setUseAlternatingColors(boolean flag) {
150:                this .useAlternatingColors = flag;
151:            }
152:
153:            public void actionPerformed(ActionEvent e) {
154:                cancelCellEditing();
155:                boolean ctrlPressed = WbAction.isCtrlPressed(e);
156:                boolean shiftPressed = WbAction.isShiftPressed(e);
157:                BlobHandler handler = new BlobHandler();
158:                if (ctrlPressed) {
159:                    handler.showBlobAsText(currentValue);
160:                } else if (shiftPressed) {
161:                    handler.showBlobAsImage(currentValue);
162:                } else {
163:                    handler.showBlobInfoDialog(WbManager.getInstance()
164:                            .getCurrentWindow(), currentValue);
165:                }
166:                File f = handler.getUploadFile();
167:                if (f != null) {
168:                    currentTable.setValueAt(f, currentRow, currentColumn);
169:                } else if (handler.isChanged()) {
170:                    currentTable.setValueAt(handler.getNewValue(), currentRow,
171:                            currentColumn);
172:                } else if (handler.setToNull()) {
173:                    currentTable.setValueAt(null, currentRow, currentColumn);
174:                }
175:            }
176:
177:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.