Source Code Cross Referenced for RecentSwatchPanel.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » colorchooser » 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 » Swing Library » abeille forms designer » com.jeta.swingbuilder.gui.colorchooser 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) 2005 Jeff Tassin
003:         *
004:         * This library is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU Lesser General Public
006:         * License as published by the Free Software Foundation; either
007:         * version 2.1 of the License, or (at your option) any later version.
008:         *
009:         * This library 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 GNU
012:         * Lesser General Public License for more details.
013:         *
014:         * You should have received a copy of the GNU Lesser General Public
015:         * License along with this library; if not, write to the Free Software
016:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
017:         */
018:
019:        package com.jeta.swingbuilder.gui.colorchooser;
020:
021:        import java.awt.Color;
022:        import java.awt.Dimension;
023:        import java.awt.Graphics;
024:        import java.awt.Insets;
025:        import java.awt.event.MouseEvent;
026:
027:        import javax.swing.UIManager;
028:
029:        import com.jeta.forms.store.properties.ColorHolder;
030:        import com.jeta.open.gui.framework.JETAPanel;
031:        import com.jeta.swingbuilder.store.RecentColorsModel;
032:
033:        /**
034:         * This panel is used to display recent colors selected in the JETAColorChooser.
035:         * It is needed because the JColorChooser has a curiously poor design.
036:         * 
037:         * @author Jeff Tassin
038:         */
039:        public class RecentSwatchPanel extends JETAPanel {
040:            /**
041:             * Used to store the recent colors between application invocations.
042:             */
043:            private RecentColorsModel m_colors;
044:
045:            /**
046:             * The size in pixels of each swatch
047:             */
048:            private Dimension m_swatch_size;
049:
050:            private static final int SWATCH_COLUMNS = 30;
051:            private static final int SWATCH_ROWS = 2;
052:
053:            /**
054:             * A small space between each swatch.
055:             */
056:            protected Dimension m_gap;
057:
058:            /**
059:             * The default color for a swatch if one has not been defined.
060:             */
061:            private ColorHolder m_default_color;
062:
063:            public RecentSwatchPanel() {
064:                Color default_color = UIManager
065:                        .getColor("ColorChooser.swatchesDefaultRecentColor");
066:                if (default_color == null)
067:                    default_color = UIManager.getColor("control");
068:                if (default_color == null)
069:                    default_color = Color.gray;
070:
071:                m_default_color = new ColorHolder(default_color);
072:                m_colors = RecentColorsModel.createInstance(SWATCH_ROWS
073:                        * SWATCH_COLUMNS);
074:
075:                m_swatch_size = UIManager
076:                        .getDimension("ColorChooser.swatchesRecentSwatchSize");
077:                if (m_swatch_size == null)
078:                    m_swatch_size = new Dimension(10, 10);
079:
080:                m_gap = new Dimension(1, 1);
081:
082:                setToolTipText("");
083:                setRequestFocusEnabled(false);
084:                setBorder(javax.swing.BorderFactory
085:                        .createLineBorder(Color.black));
086:            }
087:
088:            public boolean isFocusTraversable() {
089:                return false;
090:            }
091:
092:            public void paintComponent(Graphics g) {
093:                Insets insets = getInsets();
094:                g.setColor(Color.white);
095:                g.fillRect(0, 0, getWidth(), getHeight());
096:                for (int row = 0; row < SWATCH_ROWS; row++) {
097:                    for (int column = 0; column < SWATCH_COLUMNS; column++) {
098:                        g.setColor(getColorForCell(column, row).getColor());
099:                        int x = insets.left + column
100:                                * (m_swatch_size.width + m_gap.width);
101:                        int y = insets.top + row
102:                                * (m_swatch_size.height + m_gap.height);
103:                        g.fillRect(x, y, m_swatch_size.width,
104:                                m_swatch_size.height);
105:                        g.setColor(Color.black);
106:                        g.drawLine(x + m_swatch_size.width - 1, y, x
107:                                + m_swatch_size.width - 1, y
108:                                + m_swatch_size.height - 1);
109:                        g.drawLine(x, y + m_swatch_size.height - 1, x
110:                                + m_swatch_size.width - 1, y
111:                                + m_swatch_size.height - 1);
112:                    }
113:                }
114:
115:                g.setColor(Color.white);
116:                int width = SWATCH_COLUMNS
117:                        * (m_swatch_size.width + m_gap.width) - 2;
118:                int height = SWATCH_ROWS
119:                        * (m_swatch_size.height + m_gap.height) - 2;
120:                g.drawLine(insets.left, insets.top, insets.left + width,
121:                        insets.top);
122:                g.drawLine(insets.left, insets.top, insets.left, insets.top
123:                        + height);
124:                g.drawLine(insets.left, insets.top + height, insets.left
125:                        + width, insets.top + height);
126:                g.drawLine(insets.left + width, insets.top,
127:                        insets.left + width, insets.top + height);
128:            }
129:
130:            public Dimension getPreferredSize() {
131:                Insets insets = getInsets();
132:                int width = SWATCH_COLUMNS
133:                        * (m_swatch_size.width + m_gap.width) - 1 + insets.left
134:                        + insets.right;
135:                int height = SWATCH_ROWS
136:                        * (m_swatch_size.height + m_gap.height) - 1
137:                        + insets.top + insets.bottom;
138:                return new Dimension(width, height);
139:            }
140:
141:            public String getToolTipText(MouseEvent e) {
142:                ColorHolder color = getColorForLocation(e.getX(), e.getY());
143:                return color.getRed() + ", " + color.getGreen() + ", "
144:                        + color.getBlue();
145:            }
146:
147:            public ColorHolder getColorForLocation(int x, int y) {
148:                int column = x / (m_swatch_size.width + m_gap.width);
149:                int row = y / (m_swatch_size.height + m_gap.height);
150:                return getColorForCell(column, row);
151:            }
152:
153:            private ColorHolder getColorForCell(int column, int row) {
154:                return m_colors.getColor((row * SWATCH_COLUMNS) + column,
155:                        m_default_color);
156:            }
157:
158:            public void setMostRecentColor(Color c) {
159:                m_colors.setRecentColor(new ColorHolder(c));
160:                repaint();
161:            }
162:
163:            /**
164:             * Saves the recent color settings to the application store
165:             */
166:            public void saveSettings() {
167:                RecentColorsModel.save(m_colors);
168:            }
169:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.