1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss about it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | *******************************************************************************/ | |
11 | package com.jsql.view.swing.text; | |
12 | ||
13 | import com.jsql.view.swing.popupmenu.JPopupMenuComponent; | |
14 | ||
15 | import javax.swing.*; | |
16 | import java.awt.event.MouseAdapter; | |
17 | import java.awt.event.MouseEvent; | |
18 | ||
19 | /** | |
20 | * Add a popup menu to Decorated component. | |
21 | * @param <T> Component like JTextField or JTextArea to decorate | |
22 | */ | |
23 | public class JPopupComponent<T extends JComponent> extends JComponent implements DecoratorJComponent<T> { | |
24 | | |
25 | /** | |
26 | * Decorated component. | |
27 | */ | |
28 | private final T proxy; | |
29 | ||
30 | /** | |
31 | * Get the decorated component, add popup menu Select All and Copy. | |
32 | * @param proxy Swing component to decorate | |
33 | */ | |
34 | public JPopupComponent(final T proxy) { | |
35 | | |
36 | this.proxy = proxy; | |
37 |
1
1. <init> : removed call to javax/swing/JComponent::setComponentPopupMenu → NO_COVERAGE |
this.proxy.setComponentPopupMenu(new JPopupMenuComponent(this.proxy)); |
38 | | |
39 |
1
1. <init> : removed call to javax/swing/JComponent::addMouseListener → NO_COVERAGE |
this.proxy.addMouseListener(new MouseAdapter() { |
40 | @Override | |
41 | public void mousePressed(MouseEvent e) { | |
42 | | |
43 |
1
1. mousePressed : removed call to java/awt/event/MouseAdapter::mousePressed → NO_COVERAGE |
super.mousePressed(e); |
44 | ||
45 | // Left button will unselect text after selectAll, so only for right click | |
46 |
1
1. mousePressed : negated conditional → NO_COVERAGE |
if (SwingUtilities.isRightMouseButton(e)) { |
47 | JPopupComponent.this.proxy.requestFocusInWindow(); | |
48 | } | |
49 | } | |
50 | }); | |
51 | } | |
52 | ||
53 | @Override | |
54 | public T getProxy() { | |
55 |
1
1. getProxy : replaced return value with null for com/jsql/view/swing/text/JPopupComponent::getProxy → NO_COVERAGE |
return this.proxy; |
56 | } | |
57 | } | |
Mutations | ||
37 |
1.1 |
|
39 |
1.1 |
|
43 |
1.1 |
|
46 |
1.1 |
|
55 |
1.1 |