Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable ProofTree tooltips, render them lazily #3510

Merged
merged 3 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions key.core/src/main/java/de/uka/ilkd/key/settings/ViewSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ public class ViewSettings extends AbstractPropertiesSettings {
/** this setting enables/disables tool tips in the source view */
private static final String SOURCE_VIEW_TOOLTIP = "SourceViewTooltips";

/** this setting enables/disables tool tips in the proof tree */
private static final String PROOF_TREE_TOOLTIP = "ProofTreeTooltips";

private static final String HIGHLIGHT_ORIGIN = "HighlightOrigin";
/**
*
Expand Down Expand Up @@ -202,6 +205,8 @@ public class ViewSettings extends AbstractPropertiesSettings {
createBooleanProperty(SEQUENT_VIEW_TOOLTIP, true);
private final PropertyEntry<Boolean> showSourceViewTooltips =
createBooleanProperty(SOURCE_VIEW_TOOLTIP, true);
private final PropertyEntry<Boolean> showProofTreeTooltips =
createBooleanProperty(PROOF_TREE_TOOLTIP, true);
private final PropertyEntry<Boolean> highlightOrigin =
createBooleanProperty(HIGHLIGHT_ORIGIN, true);
private final PropertyEntry<Set<String>> clutterRules =
Expand Down Expand Up @@ -539,6 +544,14 @@ public void setShowSourceViewTooltips(boolean showSourceViewTooltips) {
this.showSourceViewTooltips.set(showSourceViewTooltips);
}

public boolean isShowProofTreeTooltips() {
return showProofTreeTooltips.get();
}

public void setShowProofTreeTooltips(boolean showProofTreeTooltips) {
this.showProofTreeTooltips.set(showProofTreeTooltips);
}

public double getUIFontSizeFactor() {
return uiFontSizeFactor.get();
}
Expand Down
8 changes: 8 additions & 0 deletions key.ui/src/main/java/de/uka/ilkd/key/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ public final class MainWindow extends JFrame {
new ToggleSequentViewTooltipAction(this);
private final ToggleSourceViewTooltipAction toggleSourceViewTooltipAction =
new ToggleSourceViewTooltipAction(this);
private final ToggleProofTreeTooltipAction toogleProofTreeTooltipAction =
new ToggleProofTreeTooltipAction(this);
private final TermLabelMenu termLabelMenu;
private boolean frozen = false;
/**
Expand Down Expand Up @@ -930,6 +932,7 @@ private JMenu createViewMenu() {
view.add(new JCheckBoxMenuItem(hidePackagePrefixToggleAction));
view.add(new JCheckBoxMenuItem(toggleSequentViewTooltipAction));
view.add(new JCheckBoxMenuItem(toggleSourceViewTooltipAction));
view.add(new JCheckBoxMenuItem(toogleProofTreeTooltipAction));

view.addSeparator();
{
Expand Down Expand Up @@ -1457,6 +1460,11 @@ public boolean isShowTacletInfo() {
return mainFrame.isShowTacletInfo();
}

public void setShowProofTreeTooltip(Object source) {
toogleProofTreeTooltipAction
.actionPerformed(new ActionEvent(proofTreeView, ActionEvent.ACTION_PERFORMED, ""));
}

public AutoModeAction getAutoModeAction() {
return autoModeAction;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* This file is part of KeY - https://key-project.org
* KeY is licensed under the GNU General Public License Version 2
* SPDX-License-Identifier: GPL-2.0-only */
package de.uka.ilkd.key.gui.actions;

import java.awt.event.ActionEvent;
import java.beans.PropertyChangeListener;
import javax.swing.*;

import de.uka.ilkd.key.gui.MainWindow;
import de.uka.ilkd.key.settings.ProofIndependentSettings;
import de.uka.ilkd.key.settings.ViewSettings;

/**
* Toggles the tooltips of the proof tree.
*
* @author Wolfram Pfeifer
*/
public class ToggleProofTreeTooltipAction extends MainWindowAction {
/** This action's name. */
public static final String NAME = "Show Tooltips in Proof Tree";

/** This action's tooltip. */
public static final String TOOL_TIP = "If ticked, moving the mouse over a node in the proof"
+ " tree will show a tooltip with additional information.";

/**
* Create a new action.
*
* @param mainWindow the main window.
*/
public ToggleProofTreeTooltipAction(MainWindow mainWindow) {
super(mainWindow);
setName(NAME);
setTooltip(TOOL_TIP);
// Listens to changes to the view settings to call {@link #updateSelectedState()}.
PropertyChangeListener viewSettingsListener = e -> updateSelectedState();
ProofIndependentSettings.DEFAULT_INSTANCE.getViewSettings()
.addPropertyChangeListener(viewSettingsListener);
updateSelectedState();
}

/**
* Updates the state of this action according to {@link ViewSettings#isShowProofTreeTooltips()}
*/
protected void updateSelectedState() {
final boolean setting =
ProofIndependentSettings.DEFAULT_INSTANCE.getViewSettings().isShowProofTreeTooltips();
setSelected(setting);
}

@Override
public void actionPerformed(ActionEvent e) {
boolean selected = ((JCheckBoxMenuItem) e.getSource()).isSelected();
ProofIndependentSettings.DEFAULT_INSTANCE.getViewSettings()
.setShowProofTreeTooltips(selected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import de.uka.ilkd.key.gui.fonticons.IconFactory;
import de.uka.ilkd.key.proof.Goal;
import de.uka.ilkd.key.proof.Proof;
import de.uka.ilkd.key.settings.ProofIndependentSettings;

import bibliothek.gui.dock.common.action.CAction;
import bibliothek.gui.dock.common.action.CButton;
Expand Down Expand Up @@ -39,6 +40,7 @@ public static CAction create(ProofTreeView view) {
menu.addSeparator();

menu.add(createExpandOSSToggle(view));
menu.add(createTooltipToggle());
menu.add(createTacletInfoToggle());
return menu;
};
Expand Down Expand Up @@ -134,6 +136,27 @@ protected void changed() {
return check;
}

private static CCheckBox createTooltipToggle() {
CCheckBox check = new CCheckBox() {
@Override
protected void changed() {
/*
* The ToogleProofTreeTooltipAction (in the View menu) is updated via
* PropertyChangeListener, no manual update needed!
*/
final boolean selected = isSelected();
ProofIndependentSettings.DEFAULT_INSTANCE.getViewSettings()
.setShowProofTreeTooltips(selected);
}
};
check.setText("Show Tooltips");
// No PropertyChangeListener needed, since the menu is always freshly generated.
final boolean setting =
ProofIndependentSettings.DEFAULT_INSTANCE.getViewSettings().isShowProofTreeTooltips();
check.setSelected(setting);
return check;
}

/**
* The checkbox used in the proof tree settings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,35 @@ public ProofTreeView() {
delegateView = new JTree(new DefaultMutableTreeNode("No proof loaded")) {
private static final long serialVersionUID = 6555955929759162324L;

@Override
public String getToolTipText(MouseEvent mouseEvent) {
/*
* For performance reasons, we want to make sure that the tooltips are only rendered
* when they are really needed. Therefore, they are now lazily generated and can
* also be disabled completely.
*/
if (!ProofIndependentSettings.DEFAULT_INSTANCE.getViewSettings()
.isShowProofTreeTooltips()) {
return null;
}
TreePath path = delegateView.getPathForLocation(mouseEvent.getX(),
mouseEvent.getY());
if (path == null) {
return null;
}
var last = path.getLastPathComponent();

if (last instanceof GUIAbstractTreeNode node) {

Style style = renderer.initStyleForNode(node);
if (style.tooltip != null) {
return renderTooltip(style.tooltip);
}
}

return super.getToolTipText(mouseEvent);
}

@Override
public void setFont(Font font) {
iconHeight = font.getSize();
Expand Down Expand Up @@ -1243,16 +1272,7 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean

super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);

Style style = new Style();
style.foreground = getForeground();
style.background = getBackground();
// Normalize whitespace
style.text = value.toString().replaceAll("\\s+", " ");
style.border = null;
style.tooltip = new Style.Tooltip();
style.icon = null;

stylers.forEach(it -> it.style(style, node));
Style style = initStyleForNode(node);

setForeground(style.foreground);
setBackground(style.background);
Expand All @@ -1265,13 +1285,34 @@ public Component getTreeCellRendererComponent(JTree tree, Object value, boolean
}

setFont(getFont().deriveFont(Font.PLAIN));
String tooltip = renderTooltip(style.tooltip);
setToolTipText(tooltip);
// For performance reasons, we render the tooltips now lazily ...
// String tooltip = renderTooltip(style.tooltip);
// setToolTipText(tooltip);
setText(style.text);
setIcon(style.icon);

return this;
}

/**
* Creates a new Style object and fills it for the given node.
*
* @param node the tree node
* @return the created Style with all the info about the node
*/
public Style initStyleForNode(GUIAbstractTreeNode node) {
Style style = new Style();
style.foreground = getForeground();
style.background = getBackground();
// Normalize whitespace
style.text = node.toString().replaceAll("\\s+", " ");
style.border = null;
style.tooltip = new Style.Tooltip();
style.icon = null;

stylers.forEach(it -> it.style(style, node));
return style;
}
}

public Node getSelectedNode() {
Expand Down
Loading