|
| 1 | +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ |
| 2 | + |
| 3 | +/* |
| 4 | + Part of the Processing project - http://processing.org |
| 5 | +
|
| 6 | + Copyright (c) 2006-14 Ben Fry and Casey Reas |
| 7 | +
|
| 8 | + This program is free software; you can redistribute it and/or modify |
| 9 | + it under the terms of the GNU General Public License version 2 |
| 10 | + as published by the Free Software Foundation. |
| 11 | +
|
| 12 | + This program is distributed in the hope that it will be useful, |
| 13 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + GNU General Public License for more details. |
| 16 | +
|
| 17 | + You should have received a copy of the GNU General Public License |
| 18 | + along with this program; if not, write to the Free Software Foundation, |
| 19 | + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | +*/ |
| 21 | + |
| 22 | +package processing.app.tools; |
| 23 | + |
| 24 | +import processing.app.*; |
| 25 | + |
| 26 | +import java.awt.datatransfer.Clipboard; |
| 27 | +import java.awt.datatransfer.StringSelection; |
| 28 | +import java.awt.event.*; |
| 29 | + |
| 30 | + |
| 31 | +/** |
| 32 | + * Color selector tool for the Tools menu. |
| 33 | + * <p/> |
| 34 | + * Using the keyboard shortcuts, you can copy/paste the values for the |
| 35 | + * colors and paste them into your program. We didn't do any sort of |
| 36 | + * auto-insert of colorMode() or fill() or stroke() code cuz we couldn't |
| 37 | + * decide on a good way to do this.. your contributions welcome). |
| 38 | + */ |
| 39 | +public class ColorSelector implements Tool { |
| 40 | + |
| 41 | + /** |
| 42 | + * Only create one instance, otherwise we'll have dozens of animation |
| 43 | + * threads going if you open/close a lot of editor windows. |
| 44 | + */ |
| 45 | + static ColorChooser selector; |
| 46 | + |
| 47 | + |
| 48 | + public String getMenuTitle() { |
| 49 | + return "Color Selector"; |
| 50 | + } |
| 51 | + |
| 52 | + |
| 53 | + public void init(Editor editor) { |
| 54 | + if (selector == null) { |
| 55 | + selector = new ColorChooser(editor, false, "Copy", new ActionListener() { |
| 56 | + |
| 57 | + @Override |
| 58 | + public void actionPerformed(ActionEvent e) { |
| 59 | + Clipboard clipboard = Toolkit.getSystemClipboard(); |
| 60 | + clipboard.setContents(new StringSelection(selector.getHexColor()), null); |
| 61 | + } |
| 62 | + }); |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + public void run() { |
| 68 | + selector.showSelector(); |
| 69 | + } |
| 70 | +} |
0 commit comments