Gridarta Editor
Copy.java
Go to the documentation of this file.
1 /*
2  * InputHandler.java - Manages key bindings and executes actions
3  * Copyright (C) 1999 Slava Pestov
4  * Copyright (C) 2000-2023 The Gridarta Developers.
5  *
6  * You may use and modify this package for any purpose. Redistribution is
7  * permitted, in both source and binary form, provided that this notice
8  * remains intact in all source distributions of this package.
9  */
10 
11 package net.sf.gridarta.textedit.textarea.actions;
12 
13 import java.awt.Toolkit;
14 import java.awt.datatransfer.StringSelection;
15 import java.awt.event.ActionEvent;
16 import java.awt.event.ActionListener;
18 
23 public class Copy implements ActionListener {
24 
28  @Override
29  public void actionPerformed(final ActionEvent e) {
30  // get the selected string
31  final String text = InputHandler.getTextArea(e).getSelectedText();
32  if (text != null) {
33  final StringSelection selection = new StringSelection(text);
34  // set above string to the system clipboard
35  Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
36  }
37  }
38 
39 }
net.sf.gridarta.textedit.textarea.actions.Copy
Action listener for COPY actions.
Definition: Copy.java:23
net.sf.gridarta.textedit.textarea
This package contains the other part of the script editor.
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.textedit.textarea.actions.Copy.actionPerformed
void actionPerformed(final ActionEvent e)
Copy current selection into the system clipboard.
Definition: Copy.java:29
net.sf
net.sf.gridarta.textedit.textarea.InputHandler
An input handler converts the user's key strokes into concrete actions.
Definition: InputHandler.java:36
net.sf.gridarta.textedit
net.sf.gridarta.textedit.textarea.JEditTextArea.getSelectedText
String getSelectedText()
Returns the selected text, or null if no selection is active.
Definition: JEditTextArea.java:709
net
net.sf.gridarta.textedit.textarea.InputHandler.getTextArea
static JEditTextArea getTextArea(final EventObject evt)
Returns the text area that fired the specified event.
Definition: InputHandler.java:144