Advertisement
Guest User

Untitled

a guest
May 22nd, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.MouseEvent;
  5. import java.awt.event.MouseListener;
  6. import java.awt.event.MouseMotionListener;
  7. import javax.swing.*;
  8.  
  9. /**
  10. * @author kosta
  11. */
  12.  
  13. public class RightClickMenu extends JPopupMenu implements ActionListener {
  14.  
  15. PostItNoteFrame Note;
  16.  
  17. /**
  18. * the menu that has the layout for the right click menu
  19. * @param PostItNoteFrame the post it note frame for the right click menu
  20. */
  21. public RightClickMenu (Object PostItNoteFrame) {
  22.  
  23. this.Note = Note;
  24.  
  25. JMenuItem Cut = new JMenuItem("Cut");
  26. Cut.addActionListener(this);
  27. this.add(Cut);
  28.  
  29. JMenuItem Copy = new JMenuItem("Copy");
  30. Copy.addActionListener(this);
  31. this.add(Copy);
  32.  
  33. JMenuItem Paste = new JMenuItem("Paste");
  34. Paste.addActionListener(this);
  35. this.add(Paste);
  36.  
  37. JMenuItem About = new JMenuItem("About");
  38. About.addActionListener(this);
  39. this.add(About);
  40.  
  41. JMenuItem Exit = new JMenuItem("Exit");
  42. Exit.addActionListener(this);
  43. this.add(Exit);
  44.  
  45.  
  46. }
  47.  
  48. /**
  49. * action performed menu that holds the functions for exit,copy,paste,about and cut functions
  50. */
  51. public void actionPerformed(ActionEvent e) {
  52. switch(e.getActionCommand()){
  53.  
  54. case "Exit":
  55. System.out.println("Exiting Post-It note application.");
  56. System.exit(0);
  57. break;
  58.  
  59. case "Copy":
  60. //note.getPostItNoteContent().copy();
  61. String copiedText = Note.getPostItNoteContent().getSelectedText();
  62.  
  63. if (copiedText != null){
  64. Note.setCopiedText(copiedText);
  65. System.out.println(copiedText);
  66. }
  67. break;
  68.  
  69. case "Paste":
  70. //Note.getPostItNoteContent().paste();
  71. if (Note.getCopiedText() != null){
  72.  
  73. Note.getPostItNoteContent().insert(Note.getCopiedText(), Note.getPostItNoteContent().getCaretPosition());
  74. System.out.println(Note.getCopiedText());
  75. }
  76. break;
  77. case "About":
  78. //AboutPostItNote dialog = new AboutPostItNote(this.note);
  79.  
  80. case "Cut":
  81. String cuttedText = Note.getPostItNoteContent().getSelectedText();
  82. if (cuttedText != null){
  83.  
  84. Note.setCopiedText(Note.getPostItNoteContent().getSelectedText());
  85. Note.getPostItNoteContent().setText(Note.getPostItNoteContent().getText().replace(Note.getPostItNoteContent().getSelectedText(), ""));
  86. }
  87. break;
  88. }
  89. }
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement