OSDN Git Service

TODO解消
[coroid/inqubus.git] / frontend / src / saccubus / util / PopupRightClick.java
1 /**
2  * 右クリックメニュー作成用。
3  * 2005年かー。ずいぶん前のを流用してるんだなあ。
4  */
5 package saccubus.util;
6
7 import java.awt.event.*;
8 import javax.swing.*;
9 import javax.swing.text.*;
10
11 /**
12  * <p>
13  * タイトル: ポケモンセーブデータエディタ for GBA
14  * </p>
15  *
16  * <p>
17  * 説明:
18  * </p>
19  *
20  * <p>
21  * 著作権: Copyright (c) 2005 PSI
22  * </p>
23  *
24  * <p>
25  * 会社名: ψ(プサイ)の興味関心空間
26  * </p>
27  *
28  * @author PSI
29  * @version 1.0
30  */
31 public class PopupRightClick extends MouseAdapter implements ActionListener {
32
33     JPopupMenu popup;
34     JMenuItem CutMenu;
35     JMenuItem CopyMenu;
36     JMenuItem PasteMenu;
37     JTextComponent Owner;
38     public static final String Actin_Cut = "CO";
39     public static final String Actin_Copy = "CU";
40     public static final String Actin_Paste = "P";
41     private boolean pressed = false;
42
43     public PopupRightClick(JTextComponent owner) {
44         this.Owner = owner;
45         popup = new JPopupMenu("メニュー");
46         CopyMenu = new JMenuItem("コピー(CTRL + C)");
47         CopyMenu.setActionCommand(Actin_Copy);
48         CopyMenu.addActionListener(this);
49         popup.add(CopyMenu);
50
51         CutMenu = new JMenuItem("切り取り(CTRL + X)");
52         CutMenu.setActionCommand(Actin_Cut);
53         CutMenu.addActionListener(this);
54         popup.add(CutMenu);
55
56         PasteMenu = new JMenuItem("貼り付け(CTRL + V)");
57         PasteMenu.setActionCommand(Actin_Paste);
58         PasteMenu.addActionListener(this);
59         popup.add(PasteMenu);
60     }
61
62     /**
63      * Invoked when the mouse exits a component.
64      *
65      * @param e
66      *            MouseEvent
67      */
68     @Override
69     public void mouseExited(MouseEvent e) {
70         pressed = false;
71     }
72
73     /**
74      * Invoked when a mouse button has been pressed on a component.
75      *
76      * @param e
77      *            MouseEvent
78      */
79     @Override
80     public void mousePressed(MouseEvent e) {
81         pressed = true;
82     }
83
84     /**
85      * Invoked when a mouse button has been released on a component.
86      *
87      * @param e
88      *            MouseEvent
89      */
90     @Override
91     public void mouseReleased(MouseEvent e) {
92         // 右クリックの時だけの話
93         if (pressed && SwingUtilities.isRightMouseButton(e)) {
94             popup.show(e.getComponent(), e.getX(), e.getY());
95         }
96         pressed = false;
97     }
98
99     /**
100      * こっちはPopupMenu
101      *
102      * @param e
103      *            ActionEvent
104      */
105     @Override
106     public void actionPerformed(ActionEvent e) {
107         String ActionCommand = e.getActionCommand();
108         if (ActionCommand.equals(Actin_Cut)) { // カット
109             Owner.cut();
110         } else if (ActionCommand.equals(Actin_Copy)) { // コピー
111             Owner.copy();
112         } else if (ActionCommand.equals(Actin_Paste)) { // 貼り付け
113             Owner.paste();
114         }
115     }
116 }