Source Code Cross Referenced for AttachmentView.java in  » Mail-Clients » columba-1.4 » org » columba » mail » gui » composer » 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 » Mail Clients » columba 1.4 » org.columba.mail.gui.composer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        //The contents of this file are subject to the Mozilla Public License Version 1.1
002:        //(the "License"); you may not use this file except in compliance with the
003:        //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004:        //
005:        //Software distributed under the License is distributed on an "AS IS" basis,
006:        //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007:        //for the specific language governing rights and
008:        //limitations under the License.
009:        //
010:        //The Original Code is "The Columba Project"
011:        //
012:        //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013:        //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014:        //
015:        //All Rights Reserved.
016:        package org.columba.mail.gui.composer;
017:
018:        import java.awt.event.KeyEvent;
019:        import java.awt.event.KeyListener;
020:        import java.awt.event.MouseAdapter;
021:
022:        import javax.swing.DefaultListModel;
023:        import javax.swing.ImageIcon;
024:        import javax.swing.UIManager;
025:
026:        import org.columba.core.resourceloader.ImageLoader;
027:        import org.columba.ristretto.message.MimeHeader;
028:        import org.columba.ristretto.message.MimePart;
029:        import org.columba.ristretto.message.MimeType;
030:        import org.frapuccino.iconpanel.IconPanel;
031:
032:        /**
033:         * Attachment view. Used in the composer to show a list of attachments. Is part
034:         * of a controller-view framework together with AttachmentController.
035:         * 
036:         * @author frdietz
037:         * @author redsolo
038:         */
039:
040:        public class AttachmentView extends IconPanel {
041:
042:            /** Reference to the controller controlling this view */
043:            private AttachmentController attachmentController;
044:
045:            private AttachmentImageIconLoader attachmentIconLoader;
046:
047:            /** Underlying data model for the list view */
048:            private DefaultListModel listModel;
049:
050:            /**
051:             * Default constructor. Sets up the view and stores a reference to the
052:             * controller for later use.
053:             * 
054:             * @param controller
055:             *            Reference to the controller of this view
056:             */
057:            public AttachmentView(AttachmentController controller) {
058:                super ();
059:
060:                attachmentController = controller;
061:
062:                listModel = new DefaultListModel();
063:
064:                setOpaque(true);
065:
066:                setBackground(UIManager.getColor("List.background"));
067:
068:                attachmentIconLoader = new AttachmentImageIconLoader();
069:
070:                setDoubleClickAction(new OpenAttachmentAction(this ));
071:
072:                //TODO Let the AttachmentViewer get the focus so that this works
073:                addKeyListener(new KeyListener() {
074:
075:                    public void keyPressed(KeyEvent e) {
076:                        if (e.getKeyCode() == KeyEvent.VK_DELETE) {
077:                            removeSelected();
078:                        }
079:
080:                    }
081:
082:                    public void keyReleased(KeyEvent e) {
083:
084:                    }
085:
086:                    public void keyTyped(KeyEvent e) {
087:                    }
088:                });
089:
090:                //setModel(listModel);
091:
092:                //setCellRenderer(new ListRenderer());
093:            }
094:
095:            /**
096:             * Installs the attachment controller as listener
097:             * 
098:             * @param c
099:             *            Controller of this view
100:             */
101:            public void installListener(AttachmentController c) {
102:                addKeyListener(c);
103:            }
104:
105:            /**
106:             * Adds a popup listener
107:             * 
108:             * @param a
109:             *            Listener to add
110:             */
111:            public void addPopupListener(MouseAdapter a) {
112:                addMouseListener(a);
113:            }
114:
115:            /**
116:             * Adds an attachment to be displayed in the view
117:             * 
118:             * @param mp
119:             *            Attachment to add
120:             */
121:            public void add(MimePart mp) {
122:                listModel.addElement(mp);
123:
124:                MimeHeader header = mp.getHeader();
125:
126:                MimeType mimeType = header.getMimeType();
127:
128:                ImageIcon icon = attachmentIconLoader.getImageIcon(mimeType
129:                        .getType(), mimeType.getSubtype());
130:
131:                String text = header.getFileName();
132:                if (text == null || text.length() == 0) {
133:                    if (header.getContentDescription() != null) {
134:                        text = header.getContentDescription();
135:                    } else {
136:                        text = mimeType.toString();
137:                    }
138:                }
139:
140:                //      Get Tooltip for Icon
141:                StringBuffer tooltip = new StringBuffer();
142:                tooltip.append("<html><body>");
143:
144:                if (mp.getHeader().getFileName() != null) {
145:                    tooltip.append(header.getFileName());
146:                    tooltip.append(" - ");
147:                }
148:
149:                tooltip.append("<i>");
150:
151:                if (header.getContentDescription() != null) {
152:                    tooltip.append(header.getContentDescription());
153:                } else {
154:                    tooltip.append(mimeType.getType());
155:                    tooltip.append("/");
156:                    tooltip.append(mimeType.getSubtype());
157:                }
158:
159:                tooltip.append("</i></body></html>");
160:                add(icon, text, tooltip.toString());
161:            }
162:
163:            public void removeSelected() {
164:                // remove from model
165:                int[] indices = getSelectedIndices();
166:
167:                for (int i = 0; i < indices.length; i++) {
168:                    listModel.removeElementAt(indices[i]);
169:
170:                }
171:
172:                // remove from view
173:                super .removeSelected();
174:            }
175:
176:            /**
177:             * Clears the view, i.e. removes all attachments.
178:             */
179:            public void clear() {
180:                // clear model
181:                listModel.clear();
182:
183:                // clear view
184:                removeAll();
185:            }
186:
187:            /**
188:             * Gets an attachment from the view by index
189:             * 
190:             * @param index
191:             *            Index of attachment (zero based)
192:             * @return The specified attachment
193:             */
194:            public MimePart get(int index) {
195:                return (MimePart) listModel.get(index);
196:            }
197:
198:            /**
199:             * Gets number of attachments currently displayed in the view.
200:             * 
201:             * @return the number of attachments currently displayed in the view.
202:             */
203:            public int count() {
204:                return listModel.size();
205:            }
206:
207:            /**
208:             * Selects the list item that is at the position in the component/list.
209:             * 
210:             * @param x
211:             *            the x pos.
212:             * @param y
213:             *            the y pos.
214:             */
215:            public void fixSelection(int x, int y) {
216:                /*
217:                 * int index = locationToIndex(new Point(x, y));
218:                 * 
219:                 * setSelectedIndex(index);
220:                 */
221:            }
222:
223:            /**
224:             * @return Returns the controller for the view.
225:             */
226:            public AttachmentController getController() {
227:                return attachmentController;
228:            }
229:
230:            /**
231:             * Imageloader using a content-type and subtype to determine the image name.
232:             * <p>
233:             * Automatically falls back to the default icon.
234:             * 
235:             * @author fdietz
236:             */
237:            class AttachmentImageIconLoader {
238:
239:                /**
240:                 * Utility constructor.
241:                 */
242:                private AttachmentImageIconLoader() {
243:                }
244:
245:                /**
246:                 * Returns the image icon for the content type.
247:                 * 
248:                 * @param contentType
249:                 *            content type
250:                 * @param contentSubtype
251:                 *            content sub type
252:                 * @return an Image Icon for the content type.
253:                 */
254:                public ImageIcon getImageIcon(String contentType,
255:                        String contentSubtype) {
256:                    StringBuffer buf = new StringBuffer();
257:                    buf.append("gnome-");
258:                    buf.append(contentType);
259:                    buf.append("-");
260:                    buf.append(contentSubtype);
261:                    buf.append(".png");
262:
263:                    ImageIcon icon = ImageLoader
264:                            .getMimetypeIcon(buf.toString());
265:
266:                    if (icon == null) {
267:                        icon = ImageLoader.getMimetypeIcon("gnome-"
268:                                + contentType + ".png");
269:                    }
270:
271:                    if (icon == null) {
272:                        icon = ImageLoader.getMimetypeIcon("gnome-text.png");
273:                    }
274:
275:                    return icon;
276:                }
277:            }
278:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.