Source Code Cross Referenced for ImageSelection.java in  » Database-Client » squirrel-sql-2.6.5a » net » sourceforge » squirrel_sql » plugins » graph » graphtofiles » 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 » Database Client » squirrel sql 2.6.5a » net.sourceforge.squirrel_sql.plugins.graph.graphtofiles 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package net.sourceforge.squirrel_sql.plugins.graph.graphtofiles;
002:
003:        import javax.swing.*;
004:        import java.awt.datatransfer.Transferable;
005:        import java.awt.datatransfer.DataFlavor;
006:        import java.awt.datatransfer.UnsupportedFlavorException;
007:        import java.awt.datatransfer.Clipboard;
008:        import java.awt.*;
009:        import java.awt.event.ActionListener;
010:        import java.awt.event.ActionEvent;
011:        import java.io.IOException;
012:
013:        /**
014:         * Unused at the moment.
015:         * Might help one day to copy images to clipboard.
016:         * See usage example commented at the bottom of this file.
017:         */
018:        public class ImageSelection extends TransferHandler implements 
019:                Transferable {
020:
021:            private static final DataFlavor flavors[] = {
022:                    DataFlavor.imageFlavor,
023:                    new DataFlavor("image/jpeg", "JPEG image"),
024:                    new DataFlavor("image/gif", "GIF Image"),
025:                    new DataFlavor("mage/x-pict", "X Pict") };
026:
027:            private Image image;
028:
029:            public int getSourceActions(JComponent c) {
030:                return TransferHandler.COPY;
031:            }
032:
033:            public boolean canImport(JComponent comp, DataFlavor flavor[]) {
034:                if (!(comp instanceof  JLabel)
035:                        || (comp instanceof  AbstractButton)) {
036:                    return false;
037:                }
038:                for (int i = 0, n = flavor.length; i < n; i++) {
039:                    if (flavor[i].equals(flavors[0])) {
040:                        return true;
041:                    }
042:                }
043:                return false;
044:            }
045:
046:            public Transferable createTransferable(JComponent comp) {
047:                // Clear
048:                image = null;
049:                Icon icon = null;
050:
051:                if (comp instanceof  JLabel) {
052:                    JLabel label = (JLabel) comp;
053:                    icon = label.getIcon();
054:                } else if (comp instanceof  AbstractButton) {
055:                    AbstractButton button = (AbstractButton) comp;
056:                    icon = button.getIcon();
057:                }
058:                if (icon instanceof  ImageIcon) {
059:                    image = ((ImageIcon) icon).getImage();
060:                    return this ;
061:                }
062:                return null;
063:            }
064:
065:            public boolean importData(JComponent comp, Transferable t) {
066:                ImageIcon icon = null;
067:                try {
068:                    if (t.isDataFlavorSupported(flavors[0])) {
069:                        image = (Image) t.getTransferData(flavors[0]);
070:                        icon = new ImageIcon(image);
071:                    }
072:                    if (comp instanceof  JLabel) {
073:                        JLabel label = (JLabel) comp;
074:                        label.setIcon(icon);
075:                        return true;
076:                    } else if (comp instanceof  AbstractButton) {
077:                        AbstractButton button = (AbstractButton) comp;
078:                        button.setIcon(icon);
079:                        return true;
080:                    }
081:                } catch (UnsupportedFlavorException ignored) {
082:                } catch (IOException ignored) {
083:                }
084:                return false;
085:            }
086:
087:            // Transferable
088:            public Object getTransferData(DataFlavor flavor) {
089:                if (isDataFlavorSupported(flavor)) {
090:                    return image;
091:                }
092:                return null;
093:            }
094:
095:            public DataFlavor[] getTransferDataFlavors() {
096:                return flavors;
097:            }
098:
099:            public boolean isDataFlavorSupported(DataFlavor flavor) {
100:                return flavor.equals(flavors[0]);
101:            }
102:        }
103:
104:        //
105:        // USAGE EXAMPLE FOR IMAGESELECTION CLASS
106:        //
107:        //import net.sourceforge.squirrel_sql.plugins.graph.graphtofiles.ImageSelection;
108:        //
109:        //import java.awt.*;
110:        //import java.awt.event.*;
111:        //import java.awt.datatransfer.*;
112:        //import javax.swing.*;
113:        //
114:        //public class ImageCopy
115:        //{
116:        //
117:        //   public static void main(String args[])
118:        //   {
119:        //
120:        //      JFrame frame = new JFrame("Copy Image");
121:        //      frame.setDefaultCloseOperation
122:        //         (JFrame.EXIT_ON_CLOSE);
123:        //
124:        //      Container contentPane = frame.getContentPane();
125:        //
126:        //      Toolkit kit = Toolkit.getDefaultToolkit();
127:        //      final Clipboard clipboard =
128:        //         kit.getSystemClipboard();
129:        //
130:        //      // Your example pic here
131:        //      Icon icon = new ImageIcon("/tmp/anypic.jpg");
132:        //      final JLabel label = new JLabel(icon);
133:        //      label.setTransferHandler(new ImageSelection());
134:        //
135:        //      JScrollPane pane = new JScrollPane(label);
136:        //      contentPane.add(pane, BorderLayout.CENTER);
137:        //
138:        //      JButton copy = new JButton("Label Copy");
139:        //      copy.addActionListener(new ActionListener()
140:        //      {
141:        //         public void actionPerformed(ActionEvent e)
142:        //         {
143:        //            TransferHandler handler =
144:        //               label.getTransferHandler();
145:        //            handler.exportToClipboard(label, clipboard,
146:        //               TransferHandler.COPY);
147:        //         }
148:        //      });
149:        //
150:        //      JButton clear = new JButton("Label Clear");
151:        //      clear.addActionListener(new ActionListener()
152:        //      {
153:        //         public void actionPerformed(ActionEvent
154:        //            actionEvent)
155:        //         {
156:        //            label.setIcon(null);
157:        //         }
158:        //      });
159:        //
160:        //      JButton paste = new JButton("Label Paste");
161:        //      paste.addActionListener(new ActionListener()
162:        //      {
163:        //         public void actionPerformed(ActionEvent
164:        //            actionEvent)
165:        //         {
166:        //            Transferable clipData =
167:        //               clipboard.getContents(clipboard);
168:        //            if (clipData != null)
169:        //            {
170:        //               if (clipData.isDataFlavorSupported
171:        //                  (DataFlavor.imageFlavor))
172:        //               {
173:        //                  TransferHandler handler =
174:        //                     label.getTransferHandler();
175:        //                  handler.importData(label, clipData);
176:        //               }
177:        //            }
178:        //         }
179:        //      });
180:        //
181:        //      JPanel p = new JPanel();
182:        //      p.add(copy);
183:        //      p.add(clear);
184:        //      p.add(paste);
185:        //      contentPane.add(p, BorderLayout.NORTH);
186:        //
187:        //      JPanel pasteP = new JPanel();
188:        //      JButton pasteB = new JButton("Paste");
189:        //
190:        //      pasteB.setTransferHandler(new ImageSelection());
191:        //
192:        //      pasteB.addActionListener
193:        //         (TransferHandler.getPasteAction());
194:        //
195:        //      pasteP.add(pasteB);
196:        //      contentPane.add(pasteB, BorderLayout.SOUTH);
197:        //
198:        //      frame.setSize(400, 400);
199:        //      frame.show();
200:        //   }
201:        //}
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.