Merge remote-tracking branch

'origin/GT-2853_dev747368_remove_tooltipmanager'

Conflicts:
	Ghidra/Framework/Docking/src/main/java/ghidra/util/task/TaskMonitorComponent.java
This commit is contained in:
ghidra1 2019-05-09 16:48:56 -04:00
commit 7da1abe3ea
44 changed files with 163 additions and 347 deletions

View file

@ -491,7 +491,7 @@ public class DialogComponentProvider
*/
protected void setApplyToolTip(String tooltip) {
if (applyButton != null) {
ToolTipManager.setToolTipText(applyButton, tooltip);
applyButton.setToolTipText(tooltip);
}
}
@ -507,7 +507,7 @@ public class DialogComponentProvider
*/
protected void setOkToolTip(String tooltip) {
if (okButton != null) {
ToolTipManager.setToolTipText(okButton, tooltip);
okButton.setToolTipText(tooltip);
}
}
@ -517,7 +517,7 @@ public class DialogComponentProvider
*/
protected void setCancelToolTip(String tooltip) {
if (cancelButton != null) {
ToolTipManager.setToolTipText(cancelButton, tooltip);
cancelButton.setToolTipText(tooltip);
}
}
@ -533,7 +533,7 @@ public class DialogComponentProvider
*/
protected void setDismissToolTip(String tooltip) {
if (dismissButton != null) {
ToolTipManager.setToolTipText(dismissButton, tooltip);
dismissButton.setToolTipText(tooltip);
}
}
@ -814,10 +814,10 @@ public class DialogComponentProvider
messageWidth = fm.stringWidth(text);
}
if (messageWidth > statusLabel.getWidth()) {
ToolTipManager.setToolTipText(statusLabel, text);
statusLabel.setToolTipText(text);
}
else {
ToolTipManager.setToolTipText(statusLabel, null);
statusLabel.setToolTipText(null);
}
}

View file

@ -351,4 +351,14 @@ public class DockingUtils {
c.setBackground(new Color(0, 0, 0, 0));
}
/** Hides any open tooltip window */
public static void hideTipWindow() {
// This is a hack, since Java's manager doesn't have this method
javax.swing.ToolTipManager.sharedInstance().setEnabled(false);
javax.swing.ToolTipManager.sharedInstance().setEnabled(true);
// TODO: Ultimately, the ESCAPE key binding in the Java TTM should hide any visible tooltips. We
// need to look into why this isn't working.
}
}

View file

@ -111,7 +111,7 @@ public class EmptyBorderToggleButton extends EmptyBorderButton {
setEnabled(((Boolean) e.getNewValue()).booleanValue());
}
else if (name.equals(Action.SHORT_DESCRIPTION)) {
ToolTipManager.setToolTipText(this, (String) e.getNewValue());
setToolTipText((String) e.getNewValue());
}
else if (name.equals(Action.SMALL_ICON)) {
setIcon((Icon) e.getNewValue());

View file

@ -386,7 +386,7 @@ public class GenericHeader extends JPanel {
*/
void setTitle(String s) {
titleLabel.setText(s);
ToolTipManager.setToolTipText(titleLabel, s);
titleLabel.setToolTipText(s);
}
/**

View file

@ -1,161 +0,0 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package docking;
import javax.swing.JComponent;
/**
* A tooltip manager that simply delegates to the Swing tooltip manager. This class replaces
* the previous tooltip manager that overrode much of the Swing tooltip manager's functionality.
*/
public class ToolTipManager {
private javax.swing.ToolTipManager delegate = javax.swing.ToolTipManager.sharedInstance();
private static ToolTipManager sharedInstance = new ToolTipManager();
/**
* Registers a component for tooltip management.
* <p>
* This will register key bindings to show and hide the tooltip text
* only if <code>component</code> has focus bindings. This is done
* so that components that are not normally focus traversable, such
* as <code>JLabel</code>, are not made focus traversable as a result
* of invoking this method.
*
* @param component a <code>JComponent</code> object to add
* @see JComponent#isFocusTraversable
*/
public void registerComponent(JComponent component) {
delegate.registerComponent( component );
}
/**
* Removes a component from tooltip control.
*
* @param component a <code>JComponent</code> object to remove
*/
public void unregisterComponent(JComponent component) {
delegate.unregisterComponent( component );
}
public int getDismissDelay() {
return delegate.getDismissDelay();
}
public int getReshowDelay() {
return delegate.getReshowDelay();
}
public boolean isEnabled() {
return delegate.isEnabled();
}
public int getInitialDelay() {
return delegate.getInitialDelay();
}
public boolean isLightWeightPopupEnabled() {
return delegate.isLightWeightPopupEnabled();
}
public void setLightWeightPopupEnabled( boolean aFlag ) {
delegate.setLightWeightPopupEnabled( aFlag );
}
@Override
public String toString() {
return delegate.toString();
}
public static void setToolTipText( JComponent c, String text ) {
String oldText = (String) c.getClientProperty(JComponent.TOOL_TIP_TEXT_KEY);
c.putClientProperty(JComponent.TOOL_TIP_TEXT_KEY, text);
if (text != null) {
if (oldText == null) {
sharedInstance.registerComponent(c);
}
} else {
sharedInstance.unregisterComponent(c);
}
}
public static ToolTipManager sharedInstance() {
javax.swing.ToolTipManager.sharedInstance();
return sharedInstance;
}
/**
* Enables or disables the tooltip.
*
* @param flag true to enable the tip, false otherwise
*/
public void setEnabled( boolean flag ) {
delegate.setEnabled( flag );
}
/**
* Specifies the initial delay value.
*
* @param milliseconds the number of milliseconds to delay
* (after the cursor has paused) before displaying the
* tooltip
* @see #getInitialDelay
*/
public void setInitialDelay( int milliseconds ) {
delegate.setInitialDelay( milliseconds );
}
/**
* Specifies the dismissal delay value.
*
* @param milliseconds the number of milliseconds to delay
* before taking away the tooltip
* @see #getDismissDelay
*/
public void setDismissDelay( int milliseconds ) {
delegate.setDismissDelay( milliseconds );
}
/**
* Used to specify the amount of time before the user has to wait
* <code>initialDelay</code> milliseconds before a tooltip will be
* shown. That is, if the tooltip is hidden, and the user moves into
* a region of the same Component that has a valid tooltip within
* <code>milliseconds</code> milliseconds the tooltip will immediately
* be shown. Otherwise, if the user moves into a region with a valid
* tooltip after <code>milliseconds</code> milliseconds, the user
* will have to wait an additional <code>initialDelay</code>
* milliseconds before the tooltip is shown again.
*
* @param milliseconds time in milliseconds
* @see #getReshowDelay
*/
public void setReshowDelay( int milliseconds ) {
delegate.setReshowDelay( milliseconds );
}
/** Hides any open tooltip window */
public void hideTipWindow() {
// This is a hack, since Java's manager doesn't have this method
delegate.setEnabled( false );
delegate.setEnabled( true );
// TODO: Ultimately, the ESCAPE key binding in the Java TTM should hide any visible tooltips. We
// need to look into why this isn't working.
}
}

View file

@ -22,7 +22,6 @@ import java.awt.event.MouseEvent;
import javax.swing.*;
import docking.ToolTipManager;
import docking.widgets.label.GDLabel;
import ghidra.framework.options.EditorState;
import ghidra.util.HTMLUtilities;
@ -56,9 +55,9 @@ public class DefaultOptionComponent extends GenericOptionsComponent {
String description = editorState.getDescription();
if (description != null) {
String htmlDescription = HTMLUtilities.toWrappedHTML(description);
ToolTipManager.setToolTipText(label, htmlDescription);
label.setToolTipText(htmlDescription);
if (component instanceof JComponent) {
ToolTipManager.setToolTipText((JComponent) component, htmlDescription);
((JComponent) component).setToolTipText(htmlDescription);
}
}
add(label);

View file

@ -24,9 +24,8 @@ import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import resources.ResourceManager;
import docking.ToolTipManager;
import ghidra.docking.util.DockingWindowsLookAndFeelUtils;
import resources.ResourceManager;
/**
* Class that is a JButton that has an empty border and adds a mouse listener

View file

@ -1,6 +1,5 @@
/* ###
* IP: GHIDRA
* REVIEWED: YES
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,6 +19,7 @@ import java.awt.Rectangle;
import java.awt.event.*;
import javax.swing.Timer;
import javax.swing.ToolTipManager;
import docking.widgets.fieldpanel.field.Field;
import docking.widgets.fieldpanel.support.FieldLocation;
@ -63,7 +63,7 @@ public class HoverHandler implements ActionListener {
public void setHoverProvider(HoverProvider hoverProvider) {
this.hoverProvider = hoverProvider;
if (hoverProvider != null && hoverTimer == null) {
int timeout = docking.ToolTipManager.sharedInstance().getInitialDelay();
int timeout = ToolTipManager.sharedInstance().getInitialDelay();
hoverTimer = new Timer(timeout, this);
hoverTimer.setRepeats(false);
hoverTimer.stop();

View file

@ -551,8 +551,8 @@ public class GTable extends JTable implements KeyStrokeConsumer, DockingActionPr
}
private void init(boolean allowAutoEdit) {
docking.ToolTipManager.sharedInstance().unregisterComponent(this);
docking.ToolTipManager.sharedInstance().registerComponent(this);
ToolTipManager.sharedInstance().unregisterComponent(this);
ToolTipManager.sharedInstance().registerComponent(this);
setTableHeader(new GTableHeader(this));
if (!allowAutoEdit) {
putClientProperty("JTable.autoStartsEdit", Boolean.FALSE);

View file

@ -18,8 +18,7 @@ package docking.widgets.table;
import java.awt.*;
import java.awt.event.*;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.*;
import javax.swing.table.*;
import docking.DockingWindowManager;
@ -54,7 +53,7 @@ public class GTableHeader extends JTableHeader {
GTableHeader(GTable table) {
super(table.getColumnModel());
gTable = table;
docking.ToolTipManager.sharedInstance().registerComponent(this);
ToolTipManager.sharedInstance().registerComponent(this);
addMouseListener(new MouseAdapter() {
@Override

View file

@ -21,13 +21,11 @@ import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JTextField;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.text.*;
import docking.DockingUtils;
import docking.ToolTipManager;
import docking.util.GraphicsUtils;
import ghidra.util.SystemUtilities;

View file

@ -208,7 +208,7 @@ public class GTree extends JPanel implements BusyListener {
tree.setRowHeight(-1);// variable size rows
tree.setSelectionModel(new GTreeSelectionModel());
tree.setInvokesStopCellEditing(true);// clicking outside the cell editor will trigger a save, not a cancel
docking.ToolTipManager.sharedInstance().registerComponent(tree);
ToolTipManager.sharedInstance().registerComponent(tree);
setLayout(new BorderLayout());

View file

@ -23,7 +23,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import javax.swing.*;
import docking.ToolTipManager;
import docking.widgets.EmptyBorderButton;
import docking.widgets.OptionDialog;
import docking.widgets.label.GDHtmlLabel;
@ -44,10 +43,10 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
private WeakSet<CancelledListener> listeners =
WeakDataStructureFactory.createCopyOnReadWeakSet();
private JProgressBar progressBar;
private JButton cancelButton;
private JPanel cancelPanel;
private JPanel progressBarPanel;
private JPanel mainContentPanel;
@ -55,11 +54,11 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
private String progressMessage;
private String taskName;
private JLabel messageLabel;
private volatile boolean isCancelled;
private long lastProgress = -1;
private long progress;
private long lastMaxProgress = -1;
@ -76,14 +75,14 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
private boolean showingCancelButton = true;
private boolean cancelEnabled = true;
private boolean paintProgressValue = true;
private AtomicBoolean isIndeterminate = new AtomicBoolean(false);
private AtomicInteger taskID = new AtomicInteger();
private Timer updateTimer;
private NumberFormat percentFormat = NumberFormat.getPercentInstance();
/**
* Constructor
*/
@ -117,7 +116,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
buildProgressPanel(includeTextField, includeCancelButton);
}
@Override
public void addCancelledListener(CancelledListener mcl) {
listeners.add(mcl);
@ -127,7 +126,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
public void removeCancelledListener(CancelledListener mcl) {
listeners.remove(mcl);
}
@Override
public void incrementProgress(long incrementAmount) {
setProgress(progress + incrementAmount);
@ -164,7 +163,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
progress = value;
startUpdateTimer();
}
@Override
public void initialize(long maxValue) {
setMaximum(maxValue);
@ -179,7 +178,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
}
startUpdateTimer();
}
/**
* Sets the <code>indeterminate</code> property of the progress bar,
* which determines whether the progress bar is in determinate
@ -242,7 +241,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
isCancelled = false;
}
}
@Override
public void setShowProgressValue(boolean showProgressValue) {
this.paintProgressValue = showProgressValue;
@ -253,7 +252,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
public long getMaximum() {
return maxProgress;
}
/**
* Reset this monitor so that it can be reused
*/
@ -262,7 +261,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
isCancelled = false;
taskID.incrementAndGet();
}
/**
* Returns true if {@link #setIndeterminate(boolean)} with a value of <tt>true</tt> has
* been called.
@ -314,9 +313,9 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
else {
remove(cancelPanel);
}
repaint();
showingCancelButton = visible;
showingCancelButton = visible;
}
/**
@ -340,7 +339,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
SystemUtilities.runSwingNow(r);
}
protected void notifyChangeListeners() {
Runnable r = () -> {
for (CancelledListener mcl : listeners) {
@ -349,7 +348,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
};
SwingUtilities.invokeLater(r);
}
private synchronized void startUpdateTimer() {
if (!updateTimer.isRunning()) {
updateTimer.start();
@ -428,7 +427,7 @@ public class TaskMonitorComponent extends JPanel implements TaskMonitor {
}
private void updateToolTip() {
ToolTipManager.setToolTipText(cancelButton, "Cancel " + getTaskName());
cancelButton.setToolTipText("Cancel " + getTaskName());
}
private String getTaskName() {