-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
62 changes: 62 additions & 0 deletions
62
convex-gui/src/main/java/convex/gui/components/RightCopyMenu.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package convex.gui.components; | ||
|
||
import java.awt.Component; | ||
import java.awt.event.ActionEvent; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.MouseAdapter; | ||
import java.awt.event.MouseEvent; | ||
|
||
import javax.swing.JMenuItem; | ||
import javax.swing.JPopupMenu; | ||
import javax.swing.text.JTextComponent; | ||
|
||
@SuppressWarnings("serial") | ||
public class RightCopyMenu extends JPopupMenu implements ActionListener { | ||
|
||
JMenuItem copyMenuItem = new JMenuItem("Copy"); | ||
JMenuItem cutMenuItem = new JMenuItem("Cut"); | ||
JMenuItem pasteMenuItem = new JMenuItem("Paste"); | ||
|
||
public RightCopyMenu(Component invoker) { | ||
copyMenuItem.addActionListener(this); | ||
cutMenuItem.addActionListener(this); | ||
pasteMenuItem.addActionListener(this); | ||
|
||
add(copyMenuItem); | ||
add(cutMenuItem); | ||
add(pasteMenuItem); | ||
|
||
setInvoker(invoker); | ||
} | ||
|
||
public static void addTo(JTextComponent tf) { | ||
tf.addMouseListener(new MouseAdapter() { | ||
public void mousePressed(MouseEvent e) { | ||
switch(e.getButton()) { | ||
case MouseEvent.BUTTON3: { | ||
Component comp=e.getComponent(); | ||
RightCopyMenu menu=new RightCopyMenu(comp); | ||
menu.show(comp, e.getX(), e.getY()); | ||
break; | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
Object source = e.getSource(); | ||
Component invoker=getInvoker(); | ||
if (invoker instanceof JTextComponent) { | ||
JTextComponent tf = (JTextComponent)invoker; | ||
if (source == cutMenuItem) { | ||
tf.cut(); | ||
} else if (source == copyMenuItem) { | ||
tf.copy(); | ||
} else if (source == pasteMenuItem) { | ||
tf.paste(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters