| 1 | /******************************************************************************* | |
| 2 | * Copyhacked (H) 2012-2025. | |
| 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 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 javax.swing.text.JTextComponent; | |
| 17 | import java.awt.event.MouseAdapter; | |
| 18 | import java.awt.event.MouseEvent; | |
| 19 | ||
| 20 | /** | |
| 21 | * Add a popup menu to Decorated component. | |
| 22 | * @param <T> Component like JTextField or JTextArea to decorate | |
| 23 | */ | |
| 24 | public class JPopupComponent<T extends JTextComponent> extends JComponent implements DecoratorJComponent<T> { | |
| 25 | | |
| 26 | /** | |
| 27 | * Decorated component. | |
| 28 | */ | |
| 29 | private final T proxy; | |
| 30 | ||
| 31 | /** | |
| 32 | * Get the decorated component, add popup menu Select All and Copy. | |
| 33 | * @param proxy Swing component to decorate | |
| 34 | */ | |
| 35 | public JPopupComponent(final T proxy) { | |
| 36 | this.proxy = proxy; | |
| 37 |
1
1. <init> : removed call to javax/swing/text/JTextComponent::setComponentPopupMenu → NO_COVERAGE |
this.proxy.setComponentPopupMenu(new JPopupMenuComponent(this.proxy)); |
| 38 |
1
1. <init> : removed call to javax/swing/text/JTextComponent::addMouseListener → NO_COVERAGE |
this.proxy.addMouseListener(new MouseAdapter() { |
| 39 | @Override | |
| 40 | public void mousePressed(MouseEvent e) { | |
| 41 |
1
1. mousePressed : removed call to java/awt/event/MouseAdapter::mousePressed → NO_COVERAGE |
super.mousePressed(e); |
| 42 | // Left button will unselect text after selectAll, so only for right click | |
| 43 |
1
1. mousePressed : negated conditional → NO_COVERAGE |
if (SwingUtilities.isRightMouseButton(e)) { |
| 44 | JPopupComponent.this.proxy.requestFocusInWindow(); | |
| 45 | } | |
| 46 | } | |
| 47 | }); | |
| 48 | } | |
| 49 | ||
| 50 | @Override | |
| 51 | public T getProxy() { | |
| 52 |
1
1. getProxy : replaced return value with null for com/jsql/view/swing/text/JPopupComponent::getProxy → NO_COVERAGE |
return this.proxy; |
| 53 | } | |
| 54 | } | |
Mutations | ||
| 37 |
1.1 |
|
| 38 |
1.1 |
|
| 41 |
1.1 |
|
| 43 |
1.1 |
|
| 52 |
1.1 |