Source Code Cross Referenced for ColumnMargin.java in  » Swing-Library » abeille-forms-designer » com » jeta » swingbuilder » gui » editor » 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.editor 
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.editor;
020:
021:        import java.awt.Graphics;
022:        import java.awt.Insets;
023:        import java.awt.Point;
024:        import java.awt.Rectangle;
025:        import java.awt.event.MouseAdapter;
026:        import java.awt.event.MouseEvent;
027:        import java.awt.event.MouseMotionAdapter;
028:
029:        import javax.swing.ImageIcon;
030:        import javax.swing.JOptionPane;
031:        import javax.swing.JViewport;
032:        import javax.swing.UIManager;
033:
034:        import com.jeta.forms.gui.common.FormSpecAdapter;
035:        import com.jeta.forms.gui.common.FormUtils;
036:        import com.jeta.forms.gui.components.ComponentSource;
037:        import com.jeta.forms.gui.form.FormComponent;
038:        import com.jeta.forms.gui.form.GridComponent;
039:        import com.jeta.forms.gui.form.GridView;
040:        import com.jeta.open.i18n.I18N;
041:        import com.jeta.open.registry.JETARegistry;
042:        import com.jeta.open.resources.ResourceLoader;
043:        import com.jeta.swingbuilder.gui.commands.CommandUtils;
044:        import com.jeta.swingbuilder.gui.commands.EditColumnSpecCommand;
045:        import com.jeta.swingbuilder.gui.dnd.DesignerDragSource;
046:        import com.jeta.swingbuilder.gui.project.UserPreferencesNames;
047:        import com.jeta.swingbuilder.interfaces.userprops.TSUserPropertiesUtils;
048:        import com.jgoodies.forms.layout.ColumnSpec;
049:
050:        public class ColumnMargin extends Margin {
051:            /**
052:             * The x-position of the middle of the drag thumb
053:             */
054:            private int m_xpos;
055:
056:            private int m_drag_x_diff;
057:
058:            /**
059:             * Icon for resize thumb
060:             */
061:            private static ImageIcon m_column_thumb;
062:
063:            static {
064:                try {
065:                    ResourceLoader loader = (ResourceLoader) JETARegistry
066:                            .lookup(ResourceLoader.COMPONENT_ID);
067:                    m_column_thumb = loader
068:                            .loadImage("jeta.resources/images/forms/thumb_vertical.png");
069:                } catch (Exception e) {
070:                    e.printStackTrace();
071:                }
072:            }
073:
074:            /**
075:             * ctor
076:             * 
077:             * @param formcomponent
078:             *            the main formcomponent that contains the view that will render
079:             *            the resize indicator
080:             * @param viewport
081:             *            the viewport that contains the top level view. Needed when the
082:             *            view is scrolled right or down
083:             */
084:            public ColumnMargin(FormComponent fc, GridView topview,
085:                    ComponentSource compSrc, JViewport viewport, boolean show) {
086:                super (Orientation.HORIZONTAL, fc, topview, compSrc, viewport,
087:                        show);
088:                addMouseListener(new MouseHandler());
089:                addMouseMotionListener(new MouseMotionHandler());
090:            }
091:
092:            protected void paintComponent(Graphics g) {
093:                if (isPaintMargin()) {
094:                    Rectangle clip = g.getClipBounds();
095:                    g.setColor(UIManager.getColor("control"));
096:                    g.fillRect(clip.x, clip.y, clip.width, clip.height);
097:
098:                    if (m_gc != null) {
099:                        java.awt.Graphics2D g2 = (java.awt.Graphics2D) g;
100:                        g2.drawImage(m_column_thumb.getImage(), m_xpos
101:                                - THUMB_WIDTH / 2, 0, this );
102:                    }
103:                }
104:            }
105:
106:            /**
107:             * Changes the thumb position to the specified grid component
108:             */
109:            void update(GridComponent gc) {
110:                DesignerDragSource dds = (DesignerDragSource) JETARegistry
111:                        .lookup(DesignerDragSource.COMPONENT_ID);
112:                if (dds != null && dds != this  && dds.isDragging()) {
113:                    return;
114:                }
115:
116:                if (isPaintMargin() && !m_dragging
117:                        && m_compsrc.isSelectionTool()) {
118:                    m_gc = gc;
119:                    if (gc != null) {
120:                        GridView parentview = gc.getParentView();
121:                        if (parentview == m_view) {
122:                            m_gc = null;
123:                        } else {
124:                            if (parentview != null) {
125:                                Insets insets = parentview.getInsets();
126:                                int col_offset = gc.getColumn()
127:                                        + gc.getColumnSpan() - 1;
128:
129:                                Point pt = javax.swing.SwingUtilities
130:                                        .convertPoint(
131:                                                parentview,
132:                                                parentview
133:                                                        .getColumnOrgX(col_offset)
134:                                                        + parentview
135:                                                                .getColumnWidth(col_offset)
136:                                                        + insets.left, 0, this );
137:                                m_xpos = pt.x;
138:                            }
139:                        }
140:                    }
141:                    repaint();
142:                }
143:            }
144:
145:            private class MouseHandler extends MouseAdapter {
146:                public void mousePressed(MouseEvent e) {
147:                    int x = e.getX();
148:                    if ((x >= (m_xpos - THUMB_WIDTH / 2))
149:                            && (x <= (m_xpos + THUMB_WIDTH)) && isPaintMargin()) {
150:                        if (m_gc != null) {
151:                            startDrag();
152:                            m_drag_x_diff = e.getX() - m_xpos;
153:                            m_resize_indicator.setPosition(m_xpos);
154:                            int col = m_gc.getColumn() + m_gc.getColumnSpan()
155:                                    - 1;
156:                            GridView view = m_gc.getParentView();
157:                            FormSpecAdapter adapter = new FormSpecAdapter(view
158:                                    .getColumnSpec(col));
159:                            if (adapter.isComponentSize()) {
160:                                m_units = TSUserPropertiesUtils
161:                                        .getString(
162:                                                UserPreferencesNames.ID_DEFAULT_RESIZE_UNITS,
163:                                                "PX");
164:                                if (!FormUtils.isValidUnits(m_units))
165:                                    m_units = "PX";
166:                            } else {
167:                                m_units = adapter.getConstantUnits();
168:                                if (m_units == null)
169:                                    m_units = "PX";
170:                            }
171:                        }
172:                    } else {
173:                        m_view.deselectAll();
174:                        m_form.setSelected(true);
175:                        m_gc = null;
176:                    }
177:                }
178:
179:                public void mouseReleased(MouseEvent e) {
180:                    if (m_dragging && m_gc != null) {
181:                        if (m_comp_size > 0) {
182:                            int col = m_gc.getColumn() + m_gc.getColumnSpan()
183:                                    - 1;
184:                            GridView view = m_gc.getParentView();
185:                            ColumnSpec oldspec = view.getColumnSpec(col);
186:                            FormEditor editor = FormEditor.getEditor(view);
187:
188:                            if (editor != null) {
189:                                NewSizeAdapter adapter = new NewSizeAdapter(
190:                                        oldspec, m_comp_size, m_units);
191:                                if (!adapter.isResizeGrow()
192:                                        && !adapter.isBoundedSize()) {
193:                                    String newspec = FormUtils
194:                                            .toEncodedString(adapter);
195:                                    EditColumnSpecCommand cmd = new EditColumnSpecCommand(
196:                                            view.getParentForm(), col,
197:                                            new ColumnSpec(newspec), oldspec);
198:                                    CommandUtils.invoke(cmd, editor);
199:                                } else {
200:                                    String msg = null;
201:                                    if (adapter.isBoundedSize()) {
202:                                        msg = I18N
203:                                                .getLocalizedMessage("The column size is set to bounded.\nYou must manually set the size in the column specification window.");
204:                                    } else if (adapter.isResizeGrow()) {
205:                                        msg = I18N
206:                                                .getLocalizedMessage("The column resize behavior is set to grow.\nYou must manually set the size in the column specification window.");
207:                                    } else {
208:                                        msg = I18N
209:                                                .getLocalizedMessage("You must manually set the size in the column specification window.");
210:                                    }
211:
212:                                    String title = I18N
213:                                            .getLocalizedMessage("Error");
214:                                    JOptionPane.showMessageDialog(m_view, msg,
215:                                            title, JOptionPane.ERROR_MESSAGE);
216:                                }
217:                            } else {
218:                                assert (false);
219:                            }
220:                        }
221:
222:                        javax.swing.SwingUtilities.invokeLater(new Runnable() {
223:                            public void run() {
224:                                m_overlay.setResizeIndicator(null);
225:                                m_overlay.repaint();
226:                                m_dragging = false;
227:                                update(m_gc);
228:                            }
229:                        });
230:                    }
231:                }
232:            }
233:
234:            private class MouseMotionHandler extends MouseMotionAdapter {
235:                public void mouseDragged(MouseEvent e) {
236:                    if (m_gc != null && m_dragging) {
237:                        int x = e.getX() - m_drag_x_diff;
238:
239:                        GridView parentview = m_gc.getParentView();
240:                        Insets insets = parentview.getInsets();
241:
242:                        Point pt = javax.swing.SwingUtilities.convertPoint(
243:                                ColumnMargin.this , x, 0, parentview);
244:                        Point offsetpt = m_viewport.getViewPosition();
245:
246:                        // pt.x is the new width of the grid component
247:                        int pixels = pt.x
248:                                - parentview.getColumnOrgX(m_gc.getColumn()
249:                                        + m_gc.getColumnSpan() - 1)
250:                                - insets.left;
251:                        m_comp_size = convertPoint(pixels, m_units);
252:                        m_xpos = x;
253:                        repaint();
254:                        m_resize_indicator.setPosition(m_xpos + offsetpt.x);
255:                        m_resize_indicator.setSize(m_comp_size, m_units,
256:                                offsetpt.y);
257:                        m_overlay.repaint();
258:                    }
259:                }
260:            }
261:
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.