Source Code Cross Referenced for JListComponent.java in  » XML-UI » SwingML » org » swingml » component » 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 » XML UI » SwingML » org.swingml.component 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * SwingML Copyright (C) 2002 SwingML Team
003:         * 
004:         * This library is free software; you can redistribute it and/or modify it under
005:         * the terms of the GNU Lesser General Public License as published by the Free
006:         * Software Foundation; either version 2 of the License, or (at your option) any
007:         * later version.
008:         * 
009:         * This library is distributed in the hope that it will be useful, but WITHOUT
010:         * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011:         * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012:         * details.
013:         * 
014:         * You should have received a copy of the GNU Lesser General Public License
015:         * along with this library; if not, write to the Free Software Foundation, Inc.,
016:         * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017:         * 
018:         * Authors: Ezequiel Cuellar <ecuellar@crosslogic.com> Robert Morris
019:         * <robertj@morris.net>
020:         */
021:        package org.swingml.component;
022:
023:        import java.awt.datatransfer.*;
024:        import java.awt.dnd.*;
025:        import java.awt.event.*;
026:        import java.io.*;
027:
028:        import javax.swing.*;
029:        import javax.swing.event.*;
030:
031:        import org.swingml.*;
032:        import org.swingml.event.*;
033:        import org.swingml.model.*;
034:        import org.swingml.system.*;
035:
036:        public class JListComponent extends JList implements 
037:                ListSelectionListener, XMLTranslatable, DropTargetListener,
038:                DragSourceListener, DragGestureListener, MouseListener {
039:
040:            private DragSource dragSource = null;
041:            //    private DropTarget dropTarget = null;
042:            private EventHandler eventHandler = EventHandler.getInstance();
043:            private JListModel model = null;
044:            private Object selected = null;
045:
046:            public JListComponent(JListModel theModel) {
047:                this .model = theModel;
048:                super .setListData(model.getChildren().toArray());
049:                super .setName(model.getName());
050:                super .setToolTipText(model.getTooltip());
051:                super .setSelectedIndices(model.getSelectedIndexes());
052:                super .setSelectionMode(model.getMode());
053:                super .setVisibleRowCount(model.getVisibleRowCount());
054:                super .addListSelectionListener(this );
055:                super .addMouseListener(this );
056:                if (theModel.isDndEnabled()) {
057:                    //            this.dropTarget = new DropTarget(this, this);
058:                    new DropTarget(this , this );
059:                    this .dragSource = new DragSource();
060:                    this .dragSource.createDefaultDragGestureRecognizer(this ,
061:                            DnDConstants.ACTION_MOVE, this );
062:                }
063:            }
064:
065:            public void addElement(Object anElement) {
066:                ItemModel theNewItem = new ItemModel();
067:                theNewItem.setText(anElement.toString());
068:                JListModel theListModel = this .getListModel();
069:                theListModel.addChild(theNewItem);
070:                super .setListData(theListModel.getChildren().toArray());
071:            }
072:
073:            // -- DragSourceListener realization.
074:            public void dragDropEnd(DragSourceDropEvent aEvt) {
075:                if (aEvt.getDropSuccess()) {
076:                    removeElement();
077:                }
078:            }
079:
080:            public void dragEnter(DragSourceDragEvent aEvt) {
081:            }
082:
083:            public void dragEnter(DropTargetDragEvent aEvt) {
084:                aEvt.acceptDrag(DnDConstants.ACTION_MOVE);
085:            }
086:
087:            public void dragExit(DragSourceEvent aEvt) {
088:            }
089:
090:            public void dragExit(DropTargetEvent aEvt) {
091:            }
092:
093:            // -- DragGestureListener realization.
094:            public void dragGestureRecognized(DragGestureEvent aEvt) {
095:                this .selected = getSelectedValue();
096:                if (selected != null) {
097:                    StringSelection theText = new StringSelection(selected
098:                            .toString());
099:                    dragSource.startDrag(aEvt, DragSource.DefaultMoveDrop,
100:                            theText, this );
101:                }
102:            }
103:
104:            public void dragOver(DragSourceDragEvent aEvt) {
105:            }
106:
107:            public void dragOver(DropTargetDragEvent aEvt) {
108:            }
109:
110:            // -- DropTargetListener realization.
111:            public void drop(DropTargetDropEvent aEvt) {
112:                try {
113:                    Transferable theTransferable = aEvt.getTransferable();
114:                    if (theTransferable
115:                            .isDataFlavorSupported(DataFlavor.stringFlavor)) {
116:                        aEvt.acceptDrop(DnDConstants.ACTION_MOVE);
117:                        String theText = (String) theTransferable
118:                                .getTransferData(DataFlavor.stringFlavor);
119:                        addElement(theText);
120:                        aEvt.getDropTargetContext().dropComplete(true);
121:                    } else {
122:                        aEvt.rejectDrop();
123:                    }
124:                } catch (IOException e) {
125:                    SwingMLLogger.getInstance().log(e);
126:                    aEvt.rejectDrop();
127:                } catch (UnsupportedFlavorException e) {
128:                    SwingMLLogger.getInstance().log(e);
129:                    aEvt.rejectDrop();
130:                }
131:            }
132:
133:            public void dropActionChanged(DragSourceDragEvent aEvt) {
134:            }
135:
136:            public void dropActionChanged(DropTargetDragEvent aEvt) {
137:            }
138:
139:            // -- Utility methods.
140:            public JListModel getListModel() {
141:                return this .model;
142:            }
143:
144:            // -- XMLTranslatable realization.
145:            public String getXMLValue() {
146:                Object[] theValues = null;
147:                StringBuffer theResult = new StringBuffer();
148:                if (this .getListModel().getPostStyle().equalsIgnoreCase(
149:                        Constants.POST_ALL)) {
150:                    theValues = this .getListModel().getChildren().toArray();
151:                } else {
152:                    // Constants.POST_SELECTED
153:                    theValues = this .getSelectedValues();
154:                }
155:                if (theValues != null && theValues.length > 0) {
156:                    for (int i = 0; i < theValues.length; i++) {
157:                        // Determine whether or not the original SwingML document
158:                        // indicated a VALUE attribute
159:                        // for the ITEM tag. If so, return that value rather than the
160:                        // value of the TEXT attribute.
161:                        if (theValues[i] instanceof  ItemModel
162:                                && ((ItemModel) theValues[i]).getValue() != null) {
163:                            theResult.append(((ItemModel) theValues[i])
164:                                    .getValue());
165:                        } else {
166:                            theResult.append(theValues[i].toString());
167:                        }
168:                        if (i < theValues.length - 1) {
169:                            theResult.append(",");
170:                        }
171:                    }
172:                }
173:                return theResult.toString();
174:            }
175:
176:            // MouseListener Realization.
177:            /**
178:             * @see java.awt.event.MouseListener#mouseClicked(MouseEvent)
179:             */
180:            public void mouseClicked(MouseEvent aEvt) {
181:                final int DOUBLE_CLICK_COUNT = 2;
182:                final int SINGLE_CLICK_COUNT = 1;
183:                String theEventType = null;
184:                switch (aEvt.getClickCount()) {
185:                case DOUBLE_CLICK_COUNT:
186:                    theEventType = Constants.MOUSE_DOUBLE_CLICKED;
187:                    break;
188:                case SINGLE_CLICK_COUNT:
189:                    theEventType = Constants.MOUSE_SINGLE_CLICKED;
190:                    break;
191:                default:
192:                    theEventType = null;
193:                    break;
194:                }
195:                if (theEventType != null && theEventType.length() > 0) {
196:                    this .eventHandler.handleEvent(this .model, theEventType,
197:                            this );
198:                }
199:            }
200:
201:            /**
202:             * @see java.awt.event.MouseListener#mouseEntered(MouseEvent)
203:             */
204:            public void mouseEntered(MouseEvent aEvt) {
205:            }
206:
207:            /**
208:             * @see java.awt.event.MouseListener#mouseExited(MouseEvent)
209:             */
210:            public void mouseExited(MouseEvent aEvt) {
211:            }
212:
213:            /**
214:             * @see java.awt.event.MouseListener#mousePressed(MouseEvent)
215:             */
216:            public void mousePressed(MouseEvent aEvt) {
217:            }
218:
219:            /**
220:             * @see java.awt.event.MouseListener#mouseReleased(MouseEvent)
221:             */
222:            public void mouseReleased(MouseEvent aEvt) {
223:            }
224:
225:            public void removeElement() {
226:                JListModel theListModel = this .getListModel();
227:                theListModel.getChildren().remove(selected);
228:                super .setListData(theListModel.getChildren().toArray());
229:            }
230:
231:            public void setListModel(JListModel aListModel) {
232:                this .model = aListModel;
233:                super .setListData(aListModel.getChildren().toArray());
234:            }
235:
236:            // -- ListSelectionListener realization.
237:            public void valueChanged(ListSelectionEvent aEvt) {
238:                this.eventHandler.handleEvent(this.model,
239:                        Constants.LIST_VALUE_CHANGED, this);
240:            }
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.