Source Code Cross Referenced for SVTableCellEditor.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » hssf » contrib » view » 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 » Collaboration » poi 3.0.2 beta2 » org.apache.poi.hssf.contrib.view 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ====================================================================
002:         Licensed to the Apache Software Foundation (ASF) under one or more
003:         contributor license agreements.  See the NOTICE file distributed with
004:         this work for additional information regarding copyright ownership.
005:         The ASF licenses this file to You under the Apache License, Version 2.0
006:         (the "License"); you may not use this file except in compliance with
007:         the License.  You may obtain a copy of the License at
008:
009:         http://www.apache.org/licenses/LICENSE-2.0
010:
011:         Unless required by applicable law or agreed to in writing, software
012:         distributed under the License is distributed on an "AS IS" BASIS,
013:         WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         See the License for the specific language governing permissions and
015:         limitations under the License.
016:         ==================================================================== */
017:
018:        package org.apache.poi.hssf.contrib.view;
019:
020:        import java.awt.*;
021:        import java.awt.event.*;
022:        import java.text.*;
023:        import java.util.*;
024:
025:        import javax.swing.*;
026:        import javax.swing.border.*;
027:        import javax.swing.table.*;
028:
029:        import org.apache.poi.hssf.usermodel.*;
030:        import org.apache.poi.hssf.util.HSSFColor;
031:
032:        /**
033:         * Sheet Viewer Table Cell Editor -- not commented via javadoc as it
034:         * nearly completely consists of overridden methods.
035:         *
036:         * @author     Jason Height
037:         * @since      16 July 2002
038:         */
039:        public class SVTableCellEditor extends AbstractCellEditor implements 
040:                TableCellEditor, ActionListener {
041:            private static final Color black = getAWTColor(new HSSFColor.BLACK());
042:            private static final Color white = getAWTColor(new HSSFColor.WHITE());
043:            private Hashtable colors = HSSFColor.getIndexHash();
044:
045:            private HSSFWorkbook wb;
046:            private JTextField editor;
047:
048:            private HSSFCell editorValue;
049:
050:            public SVTableCellEditor(HSSFWorkbook wb) {
051:                this .wb = wb;
052:                this .editor = new JTextField();
053:            }
054:
055:            /**
056:             *  Gets the cellEditable attribute of the SVTableCellEditor object
057:             *
058:             * @return    The cellEditable value
059:             */
060:            public boolean isCellEditable(java.util.EventObject e) {
061:                if (e instanceof  MouseEvent) {
062:                    return ((MouseEvent) e).getClickCount() >= 2;
063:                }
064:                return false;
065:            }
066:
067:            public boolean shouldSelectCell(EventObject anEvent) {
068:                return true;
069:            }
070:
071:            public boolean startCellEditing(EventObject anEvent) {
072:                System.out.println("Start Cell Editing");
073:                return true;
074:            }
075:
076:            public boolean stopCellEditing() {
077:                System.out.println("Stop Cell Editing");
078:                fireEditingStopped();
079:                return true;
080:            }
081:
082:            public void cancelCellEditing() {
083:                System.out.println("Cancel Cell Editing");
084:                fireEditingCanceled();
085:            }
086:
087:            public void actionPerformed(ActionEvent e) {
088:                System.out.println("Action performed");
089:                stopCellEditing();
090:            }
091:
092:            /**
093:             *  Gets the cellEditorValue attribute of the SVTableCellEditor object
094:             *
095:             * @return    The cellEditorValue value
096:             */
097:            public Object getCellEditorValue() {
098:                System.out.println("GetCellEditorValue");
099:                //JMH Look at when this method is called. Should it return a HSSFCell?
100:                return editor.getText();
101:            }
102:
103:            /**
104:             *  Gets the tableCellEditorComponent attribute of the SVTableCellEditor object
105:             *
106:             * @return             The tableCellEditorComponent value
107:             */
108:            public Component getTableCellEditorComponent(JTable table,
109:                    Object value, boolean isSelected, int row, int column) {
110:                System.out.println("GetTableCellEditorComponent");
111:                HSSFCell cell = (HSSFCell) value;
112:                if (cell != null) {
113:                    HSSFCellStyle style = cell.getCellStyle();
114:                    HSSFFont f = wb.getFontAt(style.getFontIndex());
115:                    boolean isbold = f.getBoldweight() > HSSFFont.BOLDWEIGHT_NORMAL;
116:                    boolean isitalics = f.getItalic();
117:
118:                    int fontstyle = Font.PLAIN;
119:
120:                    if (isbold)
121:                        fontstyle = Font.BOLD;
122:                    if (isitalics)
123:                        fontstyle = fontstyle | Font.ITALIC;
124:
125:                    int fontheight = f.getFontHeightInPoints();
126:                    if (fontheight == 9)
127:                        fontheight = 10; //fix for stupid ol Windows
128:
129:                    Font font = new Font(f.getFontName(), fontstyle, fontheight);
130:                    editor.setFont(font);
131:
132:                    if (style.getFillPattern() == HSSFCellStyle.SOLID_FOREGROUND) {
133:                        editor.setBackground(getAWTColor(style
134:                                .getFillForegroundColor(), white));
135:                    } else
136:                        editor.setBackground(white);
137:
138:                    editor.setForeground(getAWTColor(f.getColor(), black));
139:
140:                    //Set the value that is rendered for the cell
141:                    switch (cell.getCellType()) {
142:                    case HSSFCell.CELL_TYPE_BLANK:
143:                        editor.setText("");
144:                        break;
145:                    case HSSFCell.CELL_TYPE_BOOLEAN:
146:                        if (cell.getBooleanCellValue()) {
147:                            editor.setText("true");
148:                        } else {
149:                            editor.setText("false");
150:                        }
151:                        break;
152:                    case HSSFCell.CELL_TYPE_NUMERIC:
153:                        editor.setText(Double.toString(cell
154:                                .getNumericCellValue()));
155:                        break;
156:                    case HSSFCell.CELL_TYPE_STRING:
157:                        editor.setText(cell.getRichStringCellValue()
158:                                .getString());
159:                        break;
160:                    case HSSFCell.CELL_TYPE_FORMULA:
161:                    default:
162:                        editor.setText("?");
163:                    }
164:                    switch (style.getAlignment()) {
165:                    case HSSFCellStyle.ALIGN_LEFT:
166:                    case HSSFCellStyle.ALIGN_JUSTIFY:
167:                    case HSSFCellStyle.ALIGN_FILL:
168:                        editor.setHorizontalAlignment(SwingConstants.LEFT);
169:                        break;
170:                    case HSSFCellStyle.ALIGN_CENTER:
171:                    case HSSFCellStyle.ALIGN_CENTER_SELECTION:
172:                        editor.setHorizontalAlignment(SwingConstants.CENTER);
173:                        break;
174:                    case HSSFCellStyle.ALIGN_GENERAL:
175:                    case HSSFCellStyle.ALIGN_RIGHT:
176:                        editor.setHorizontalAlignment(SwingConstants.RIGHT);
177:                        break;
178:                    default:
179:                        editor.setHorizontalAlignment(SwingConstants.LEFT);
180:                        break;
181:                    }
182:
183:                }
184:                return editor;
185:            }
186:
187:            /** This method retrieves the AWT Color representation from the colour hash table
188:             *
189:             */
190:            private final Color getAWTColor(int index, Color deflt) {
191:                HSSFColor clr = (HSSFColor) colors.get(new Integer(index));
192:                if (clr == null)
193:                    return deflt;
194:                return getAWTColor(clr);
195:            }
196:
197:            private static final Color getAWTColor(HSSFColor clr) {
198:                short[] rgb = clr.getTriplet();
199:                return new Color(rgb[0], rgb[1], rgb[2]);
200:            }
201:
202:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.