1 /*
2  * aTunes
3  * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors
4  *
5  * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors
6  *
7  * http://www.atunes.org
8  * http://sourceforge.net/projects/atunes
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  */
20 
21 package net.sourceforge.atunes.gui.views.controls;
22 
23 import javax.swing.Action;
24 import javax.swing.JPopupMenu;
25 import javax.swing.JSeparator;
26 import javax.swing.text.JTextComponent;
27 
28 import net.sourceforge.atunes.model.IOSManager;
29 import net.sourceforge.atunes.utils.ClipboardFacade;
30 
31 /**
32  * Common popup menu for text components with cut, copy, paste... options
33  *
34  * @author fleax
35  */
36 public class EditionPopUpMenu extends JPopupMenu {
37 
38 	private static final long serialVersionUID = -3103254879422133063L;
39 
40 	/**
41 	 * @param textComponent
42 	 * @param clipboard
43 	 * @param osManager
44 	 */
EditionPopUpMenu(final JTextComponent textComponent, final ClipboardFacade clipboard, final IOSManager osManager)45 	EditionPopUpMenu(final JTextComponent textComponent,
46 			final ClipboardFacade clipboard, final IOSManager osManager) {
47 		super();
48 		Action cutAction = new TextComponentCutAction(textComponent, clipboard,
49 				osManager);
50 		Action copyAction = new TextComponentCopyAction(textComponent,
51 				clipboard, osManager);
52 		Action pasteAction = new TextComponentPasteAction(textComponent,
53 				clipboard, osManager);
54 		Action deleteAction = new TextComponentDeleteAction(textComponent);
55 		Action selectAllAction = new TextComponentSelectAllAction(textComponent);
56 		addPopUpMenu(textComponent, cutAction, copyAction, pasteAction,
57 				deleteAction, selectAllAction, clipboard, osManager);
58 	}
59 
60 	/**
61 	 * Adds popup menu with edition options
62 	 *
63 	 * @param textComponent
64 	 * @param cutAction
65 	 * @param copyAction
66 	 * @param pasteAction
67 	 * @param deleteAction
68 	 * @param selectAllAction
69 	 * @param clipboard
70 	 * @param osManager
71 	 */
addPopUpMenu(final JTextComponent textComponent, final Action cutAction, final Action copyAction, final Action pasteAction, final Action deleteAction, final Action selectAllAction, final ClipboardFacade clipboard, final IOSManager osManager)72 	private void addPopUpMenu(final JTextComponent textComponent,
73 			final Action cutAction, final Action copyAction,
74 			final Action pasteAction, final Action deleteAction,
75 			final Action selectAllAction, final ClipboardFacade clipboard,
76 			final IOSManager osManager) {
77 		add(cutAction);
78 		add(copyAction);
79 		add(pasteAction);
80 		add(deleteAction);
81 		add(new JSeparator());
82 		add(selectAllAction);
83 		textComponent.addMouseListener(new TextComponentPopupMenuMouseAdapter(
84 				osManager, this, textComponent, copyAction, deleteAction,
85 				selectAllAction, pasteAction, cutAction, clipboard));
86 	}
87 }
88