-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClearSelectionAction.java
54 lines (49 loc) · 1.73 KB
/
ClearSelectionAction.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* @(#)ClearSelectionAction.java
*
* Copyright (c) 2008 by the original authors of JHotDraw
* and all its contributors.
* All rights reserved.
*
* The copyright of this software is owned by the authors and
* contributors of the JHotDraw project ("the copyright holders").
* You may not use, copy or modify this software, except in
* accordance with the license agreement you entered into with
* the copyright holders. For details see accompanying license terms.
*/
package org.jhotdraw.app.action;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.*;
import org.jhotdraw.util.*;
import org.jhotdraw.app.EditableComponent;
/**
* ClearSelectionAction.
*
* @author Werner Randelshofer.
* @version $Id$
*/
public class ClearSelectionAction extends AbstractAction {
public final static String ID = "edit.clearSelection";
/** Creates a new instance. */
public ClearSelectionAction() {
ResourceBundleUtil labels = ResourceBundleUtil.getBundle("org.jhotdraw.app.Labels");
labels.configureAction(this, ID);
}
public void actionPerformed(ActionEvent evt) {
Component focusOwner = KeyboardFocusManager.
getCurrentKeyboardFocusManager().
getPermanentFocusOwner();
if (focusOwner != null) {
if (focusOwner instanceof EditableComponent) {
((EditableComponent) focusOwner).clearSelection();
} else if (focusOwner instanceof JTextComponent) {
JTextComponent tc = ((JTextComponent) focusOwner);
tc.select(tc.getSelectionStart(), tc.getSelectionStart());
} else {
focusOwner.getToolkit().beep();
}
}
}
}