Source Code Cross Referenced for guiRenderingPannel.java in  » Net » JCGrid » org » homedns » dade » jcgrid » gui » 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 » Net » JCGrid » org.homedns.dade.jcgrid.gui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         Copyright (C) 2004 David Bucciarelli (davibu@interfree.it)
003:
004:         This program is free software; you can redistribute it and/or
005:         modify it under the terms of the GNU General Public License
006:         as published by the Free Software Foundation; either version 2
007:         of the License, or (at your option) any later version.
008:
009:         This program is distributed in the hope that it will be useful,
010:         but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         GNU General Public License for more details.
013:
014:         You should have received a copy of the GNU General Public License
015:         along with this program; if not, write to the Free Software
016:         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
017:         */
018:
019:        package org.homedns.dade.jcgrid.gui;
020:
021:        import java.io.*;
022:        import java.awt.*;
023:        import java.awt.image.*;
024:        import javax.swing.*;
025:        import javax.imageio.*;
026:
027:        import org.apache.log4j.*;
028:
029:        public class guiRenderingPannel extends javax.swing.JPanel {
030:            private final static String className = guiRenderingPannel.class
031:                    .getName();
032:            private static Logger log = Logger.getLogger(className);
033:            private static Logger logDetail = Logger.getLogger("DETAIL."
034:                    + className);
035:
036:            private static final long serialVersionUID = 1L;
037:
038:            private BufferedImage bImage;
039:            private Graphics2D graph;
040:
041:            private boolean enableCursor;
042:            private int cursorX;
043:            private int cursorY;
044:
045:            public guiRenderingPannel() {
046:                initComponents();
047:
048:                enableCursor = false;
049:                cursorX = 0;
050:                cursorY = 0;
051:            }
052:
053:            public synchronized void setCursorEnable(boolean v) {
054:                enableCursor = v;
055:            }
056:
057:            public double getCursorX() {
058:                return cursorX / (double) this .getWidth();
059:            }
060:
061:            public double getCursorY() {
062:                return 1.0 - cursorY / (double) this .getHeight();
063:            }
064:
065:            public synchronized void initImage() {
066:                int w = this .getSize().width;
067:                int h = this .getSize().height;
068:
069:                if ((w <= 0) || (h <= 0)) {
070:                    bImage = null;
071:                    graph = null;
072:                    return;
073:                }
074:
075:                bImage = new BufferedImage(w, h, BufferedImage.TYPE_3BYTE_BGR);
076:                graph = bImage.createGraphics();
077:
078:                this .clearImage();
079:            }
080:
081:            public Graphics2D getGraphics2D() {
082:                return graph;
083:            }
084:
085:            public synchronized void saveImage(String imgName) {
086:                int idx = imgName.lastIndexOf('.');
087:                if (idx == -1)
088:                    JOptionPane.showMessageDialog(this ,
089:                            "Missing image file extension", "IO error",
090:                            JOptionPane.ERROR_MESSAGE);
091:                else {
092:                    String outputFormat = imgName.substring(idx + 1);
093:
094:                    String[] formats = ImageIO.getWriterFormatNames();
095:                    boolean found = false;
096:                    for (int i = 0; i < formats.length; i++) {
097:                        if (formats[i].equals(outputFormat)) {
098:                            found = true;
099:                            break;
100:                        }
101:                    }
102:
103:                    if (!found)
104:                        JOptionPane.showMessageDialog(this , "The image format "
105:                                + outputFormat + " is not supported",
106:                                "IO error", JOptionPane.ERROR_MESSAGE);
107:                    else {
108:                        File f = new File(imgName);
109:                        try {
110:                            ImageIO.write(bImage, outputFormat, f);
111:                        } catch (Exception ex) {
112:                            log.warn("Error saving the image", ex);
113:
114:                            JOptionPane.showMessageDialog(this ,
115:                                    "Error saving the image", "IO error",
116:                                    JOptionPane.ERROR_MESSAGE);
117:                        }
118:                    }
119:                }
120:            }
121:
122:            public synchronized void resizeImage(int width, int height) {
123:                if ((width == bImage.getWidth())
124:                        && (height == bImage.getHeight()))
125:                    return;
126:
127:                bImage = new BufferedImage(width, height,
128:                        BufferedImage.TYPE_3BYTE_BGR);
129:                graph = bImage.createGraphics();
130:
131:                this .clearImage();
132:            }
133:
134:            public synchronized void clearImage() {
135:                int w = this .getSize().width;
136:                int h = this .getSize().height;
137:
138:                if ((w <= 0) || (h <= 0)) {
139:                    bImage = null;
140:                    graph = null;
141:                    return;
142:                }
143:
144:                for (int y = 0; y < h; y += 10) {
145:                    for (int x = 0; x < w; x += 10) {
146:                        if (((x / 10 + y / 10) % 2) == 0)
147:                            graph.setColor(Color.BLACK);
148:                        else
149:                            graph.setColor(Color.WHITE);
150:                        graph.fillRect(x, y, 10, 10);
151:                    }
152:                }
153:
154:                this .repaint();
155:            }
156:
157:            public synchronized void paintComponent(Graphics g) {
158:                super .paintComponent(g);
159:
160:                // Retry to inizilize image
161:
162:                if (bImage == null)
163:                    this .initImage();
164:
165:                // Repaint image
166:
167:                if (bImage != null)
168:                    g.drawImage(bImage, 0, 0, Color.BLACK, null);
169:
170:                if (enableCursor) {
171:                    g.setColor(Color.YELLOW);
172:                    g.setXORMode(Color.BLUE);
173:                    g.drawLine(cursorX - 5, cursorY, cursorX + 5, cursorY);
174:                    g.drawLine(cursorX, cursorY - 5, cursorX, cursorY + 5);
175:                }
176:            }
177:
178:            /** This method is called from within the constructor to
179:             * initialize the form.
180:             * WARNING: Do NOT modify this code. The content of this method is
181:             * always regenerated by the Form Editor.
182:             */
183:            private void initComponents() {//GEN-BEGIN:initComponents
184:
185:                setLayout(new java.awt.BorderLayout());
186:
187:                addMouseListener(new java.awt.event.MouseAdapter() {
188:                    public void mouseClicked(java.awt.event.MouseEvent evt) {
189:                        formMouseClicked(evt);
190:                    }
191:                });
192:
193:            }//GEN-END:initComponents
194:
195:            private void formMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_formMouseClicked
196:                cursorX = evt.getX();
197:                cursorY = evt.getY();
198:
199:                this .repaint();
200:            }//GEN-LAST:event_formMouseClicked
201:
202:            // Variables declaration - do not modify//GEN-BEGIN:variables
203:            // End of variables declaration//GEN-END:variables
204:
205:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.