Source Code Cross Referenced for HexPanel.java in  » Database-Client » SQL-Workbench » workbench » gui » components » 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.components 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * HexPanel.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.components;
013:
014:        import java.awt.BorderLayout;
015:        import java.awt.Color;
016:        import java.awt.Dimension;
017:        import java.awt.Font;
018:        import java.awt.FontMetrics;
019:        import javax.swing.JPanel;
020:        import javax.swing.JTable;
021:        import javax.swing.event.TableModelListener;
022:        import javax.swing.table.DefaultTableCellRenderer;
023:        import javax.swing.table.JTableHeader;
024:        import javax.swing.table.TableColumn;
025:        import javax.swing.table.TableColumnModel;
026:        import javax.swing.table.TableModel;
027:        import workbench.gui.WbSwingUtilities;
028:        import workbench.util.NumberStringCache;
029:
030:        /**
031:         * @author support@sql-workbench.net
032:         */
033:        public class HexPanel extends JPanel {
034:
035:            private JTable dataTable;
036:            private LineNumberTable lines;
037:
038:            public HexPanel() {
039:                setBorder(WbSwingUtilities.EMPTY_BORDER);
040:                dataTable = new JTable();
041:                dataTable.setAutoCreateColumnsFromModel(true);
042:                dataTable.setCellSelectionEnabled(false);
043:                dataTable.setShowGrid(false);
044:                dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
045:                Font dataFont = new Font("Monospaced", 0, 12);
046:                dataTable.setFont(dataFont);
047:                setLayout(new BorderLayout());
048:                lines = new LineNumberTable(dataTable);
049:                WbScrollPane scroll = new WbScrollPane(dataTable);
050:                scroll.setRowHeaderView(lines);
051:                JTableHeader header = dataTable.getTableHeader();
052:                DefaultTableCellRenderer rend = new DefaultTableCellRenderer();
053:                //header.setBorder(new LineBorder(Color.LIGHT_GRAY, 1));
054:                rend.setBackground(new Color(238, 240, 238));
055:                header.setDefaultRenderer(rend);
056:                this .add(header, BorderLayout.NORTH);
057:                this .add(scroll, BorderLayout.CENTER);
058:            }
059:
060:            public HexPanel(byte[] buffer) {
061:                this ();
062:                setData(buffer);
063:            }
064:
065:            public void setData(byte[] buffer) {
066:                ByteBufferTableModel model = new ByteBufferTableModel(buffer);
067:                dataTable.setModel(model);
068:                TableColumnModel tmod = dataTable.getColumnModel();
069:                int cols = tmod.getColumnCount();
070:                Font dataFont = dataTable.getFont();
071:                FontMetrics fm = dataTable.getFontMetrics(dataFont);
072:                int width = fm.stringWidth("000");
073:                for (int i = 0; i < cols - 1; i++) {
074:                    TableColumn col = tmod.getColumn(i);
075:                    col.setPreferredWidth(width);
076:                    col.setMinWidth(width);
077:                    col.setMaxWidth(width);
078:                }
079:
080:                width = fm.stringWidth("MMMMMMMMMMMMMMMMM");
081:                TableColumn col = tmod.getColumn(cols - 1);
082:                col.setPreferredWidth(width);
083:                col.setMinWidth(width);
084:                col.setMaxWidth(width);
085:
086:                String rowCount = NumberStringCache.getNumberString(model
087:                        .getRowCount());
088:                width = fm.stringWidth(rowCount);
089:                lines.setPreferredScrollableViewportSize(new Dimension(
090:                        width + 5, 32768));
091:            }
092:
093:        }
094:
095:        class ByteBufferTableModel implements  TableModel {
096:            private byte[] data;
097:            private int rowCount;
098:            private int columns = 16;
099:            private String[] labels;
100:
101:            public ByteBufferTableModel(byte[] buffer) {
102:                data = buffer;
103:                rowCount = (buffer.length / columns) + 1;
104:                labels = new String[columns + 1];
105:                for (int i = 0; i < columns; i++) {
106:                    labels[i] = NumberStringCache.getHexString(i);
107:                }
108:                labels[columns] = "0123456789abcdef";
109:            }
110:
111:            public int getRowCount() {
112:                return rowCount;
113:            }
114:
115:            public int getColumnCount() {
116:                return columns + 1;
117:            }
118:
119:            public String getColumnName(int columnIndex) {
120:                return labels[columnIndex];
121:            }
122:
123:            public Class getColumnClass(int columnIndex) {
124:                return String.class;
125:            }
126:
127:            public boolean isCellEditable(int rowIndex, int columnIndex) {
128:                return false;
129:            }
130:
131:            public Object getValueAt(int rowIndex, int columnIndex) {
132:                if (columnIndex == columns) {
133:                    int rowStart = rowIndex * columns;
134:                    int rowEnd = Math.min(rowIndex * columns + (columns - 1),
135:                            data.length);
136:                    StringBuilder result = new StringBuilder(16);
137:                    for (int i = rowStart; i < rowEnd; i++) {
138:                        int c = (data[i] < 0 ? 256 + data[i] : data[i]);
139:                        if (c > 31 && c < 128 || c > 128 && c < 255) {
140:                            result.append((char) c);
141:                        } else {
142:                            result.append('.');
143:                        }
144:
145:                    }
146:                    return result.toString();
147:                }
148:                int offset = rowIndex * columns + columnIndex;
149:                if (offset >= data.length)
150:                    return "";
151:                int c = (data[offset] < 0 ? 256 + data[offset] : data[offset]);
152:                return NumberStringCache.getHexString(c);
153:
154:                //		if (c < 16) return "0" + Integer.toHexString(c);
155:                //		else return Integer.toHexString(c);
156:            }
157:
158:            public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
159:            }
160:
161:            public void addTableModelListener(TableModelListener l) {
162:            }
163:
164:            public void removeTableModelListener(TableModelListener l) {
165:            }
166:
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.