Source Code Cross Referenced for CompoundLineView.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » components » line » 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.components.line 
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.components.line;
020:
021:        import java.awt.BorderLayout;
022:        import java.awt.Component;
023:        import java.awt.Graphics2D;
024:        import java.awt.image.BufferedImage;
025:        import java.util.Iterator;
026:
027:        import javax.swing.DefaultListModel;
028:        import javax.swing.Icon;
029:        import javax.swing.ImageIcon;
030:        import javax.swing.JLabel;
031:        import javax.swing.JList;
032:        import javax.swing.ListCellRenderer;
033:        import javax.swing.UIManager;
034:
035:        import com.jeta.forms.components.panel.FormPanel;
036:        import com.jeta.forms.store.properties.CompoundLineProperty;
037:        import com.jeta.forms.store.properties.LineProperty;
038:        import com.jeta.open.gui.framework.JETAPanel;
039:        import com.jeta.swingbuilder.gui.utils.FormDesignerUtils;
040:
041:        /**
042:         * View that is used to create and edit lines
043:         * 
044:         * @author Jeff Tassin
045:         */
046:        public class CompoundLineView extends JETAPanel {
047:            /**
048:             * The actual view
049:             */
050:            private FormPanel m_view;
051:
052:            /**
053:             * The list model that handles the borders
054:             */
055:            private DefaultListModel m_lines_model;
056:
057:            private int m_old_position = 0;
058:
059:            /**
060:             * ctor
061:             */
062:            public CompoundLineView(CompoundLineProperty lines) {
063:                setLayout(new BorderLayout());
064:                m_view = new FormPanel(
065:                        "com/jeta/swingbuilder/gui/components/line/compoundLineView.frm");
066:                add(m_view, BorderLayout.CENTER);
067:                setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 10,
068:                        10, 10));
069:
070:                m_lines_model = new DefaultListModel();
071:                JList list = m_view.getList(CompoundLineNames.ID_LINES_LIST);
072:                list.setModel(m_lines_model);
073:                list.setCellRenderer(new LineCellRenderer());
074:
075:                m_old_position = lines.getPosition();
076:                Iterator iter = lines.iterator();
077:                while (iter.hasNext()) {
078:                    LineProperty bp = (LineProperty) iter.next();
079:                    addLine(bp);
080:                }
081:
082:                setController(new CompoundLineController(this ));
083:            }
084:
085:            /**
086:             * Adds a border to the list
087:             */
088:            public void addLine(LineProperty lp) {
089:                m_lines_model.addElement(new LineInfo(lp));
090:                updatePreview();
091:            }
092:
093:            /**
094:             * Ensure the selected border is visible in the list.
095:             */
096:            void ensureIndexIsVisible() {
097:                JList list = m_view.getList(CompoundLineNames.ID_LINES_LIST);
098:                int index = list.getSelectedIndex();
099:                if (index >= 0)
100:                    list.ensureIndexIsVisible(index);
101:            }
102:
103:            /**
104:             * Creates a LineProperty based on this view
105:             */
106:            public CompoundLineProperty createLineProperty() {
107:                CompoundLineProperty prop = new CompoundLineProperty();
108:                prop.setPosition(m_old_position);
109:                for (int index = 0; index < m_lines_model.size(); index++) {
110:                    LineInfo li = (LineInfo) m_lines_model.elementAt(index);
111:                    LineProperty bp = li.getLineProperty();
112:                    prop.addLine(bp);
113:                }
114:                return prop;
115:            }
116:
117:            /**
118:             * Deletes the selected lin
119:             */
120:            public void deleteSelectedLine() {
121:                LineInfo li = (LineInfo) m_view.getList(
122:                        CompoundLineNames.ID_LINES_LIST).getSelectedValue();
123:                if (li != null) {
124:                    m_lines_model.removeElement(li);
125:                    updatePreview();
126:                }
127:            }
128:
129:            /**
130:             * @return the selected border in the border list.
131:             */
132:            public LineProperty getSelectedLine() {
133:                LineInfo li = (LineInfo) m_view.getList(
134:                        CompoundLineNames.ID_LINES_LIST).getSelectedValue();
135:                if (li == null)
136:                    return null;
137:                else
138:                    return li.getLineProperty();
139:            }
140:
141:            /**
142:             * @return the current number of lines that make up this compound line
143:             */
144:            public int getLineCount() {
145:                return m_lines_model.size();
146:            }
147:
148:            /**
149:             * Modifies a given border and sets it to a new border
150:             */
151:            public void setLine(LineProperty new_prop, LineProperty old_prop) {
152:                for (int index = 0; index < m_lines_model.size(); index++) {
153:                    LineInfo li = (LineInfo) m_lines_model.elementAt(index);
154:                    if (li.getLineProperty() == old_prop) {
155:                        m_lines_model.setElementAt(new LineInfo(new_prop),
156:                                index);
157:                        updatePreview();
158:                        return;
159:                    }
160:                }
161:
162:                assert (false);
163:            }
164:
165:            /**
166:             * Creates a swing border based on the properties in this view and displays
167:             * it.
168:             */
169:            public void updatePreview() {
170:                /*
171:                 * LineComponent lcomp = (LineComponent)m_view.getComponentByName(
172:                 * CompoundLineNames.ID_LINE_COMPONENT ); lcomp.setLineDefinition(
173:                 * createLineProperty() ); revalidate(); doLayout(); lcomp.repaint();
174:                 */
175:            }
176:
177:            public static class LineInfo {
178:                private LineProperty m_prop;
179:                private ImageIcon m_icon;
180:                private boolean m_selected = false;
181:
182:                public LineInfo(LineProperty prop) {
183:                    m_prop = prop;
184:                }
185:
186:                public Icon getIcon(boolean selected) {
187:                    if (m_icon == null || (m_selected != selected)) {
188:                        m_selected = selected;
189:                        int width = 100;
190:                        int height = 20;
191:                        BufferedImage bimage = new BufferedImage(width, height,
192:                                BufferedImage.TYPE_INT_RGB);
193:                        Graphics2D bg = bimage.createGraphics();
194:
195:                        if (selected)
196:                            bg.setColor(UIManager
197:                                    .getColor("List.selectionBackground"));
198:                        else
199:                            bg.setColor(UIManager.getColor("List.background"));
200:
201:                        bg.fillRect(0, 0, width, height);
202:                        ImageIcon line_icon = FormDesignerUtils
203:                                .loadImage("forms/line_property.gif");
204:                        bg.drawImage(line_icon.getImage(), 0, 4, bg.getColor(),
205:                                null);
206:
207:                        java.awt.BasicStroke s = (java.awt.BasicStroke) m_prop
208:                                .getStroke(16);
209:                        // System.out.println( "CompoundLineView.getIcon stroke
210:                        // thickness: " + s.getLineWidth() );
211:
212:                        bg.setColor(m_prop.getColor());
213:                        bg.setStroke(s);
214:                        bg.drawLine(20, height / 2, width, height / 2);
215:                        bg.dispose();
216:                        m_icon = new ImageIcon(bimage);
217:                    }
218:                    return m_icon;
219:                }
220:
221:                public LineProperty getLineProperty() {
222:                    return m_prop;
223:                }
224:
225:                public void setLineProperty(LineProperty prop) {
226:                    m_prop = prop;
227:                    m_icon = null;
228:                }
229:            }
230:
231:            /**
232:             * Line Renderer
233:             */
234:            public static class LineCellRenderer extends JLabel implements 
235:                    ListCellRenderer {
236:                public LineCellRenderer() {
237:                    // must set or the background color won't show
238:                    setOpaque(true);
239:                }
240:
241:                public Component getListCellRendererComponent(JList list,
242:                        Object value, int index, boolean isSelected,
243:                        boolean cellHasFocus) {
244:                    // LineProperty info = (LineProperty)value;
245:                    LineInfo info = (LineInfo) value;
246:                    if (info == null) {
247:                        assert (false);
248:                        setIcon(null);
249:                    } else {
250:                        setIcon(info.getIcon(isSelected));
251:                    }
252:
253:                    if (isSelected) {
254:                        setBackground(UIManager
255:                                .getColor("List.selectionBackground"));
256:                        setForeground(UIManager
257:                                .getColor("List.selectionForeground"));
258:                    } else {
259:                        setBackground(UIManager.getColor("List.background"));
260:                        setForeground(UIManager.getColor("List.foreground"));
261:                    }
262:                    return this;
263:                }
264:            }
265:
266:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.