Skip to content

Commit 45c126d

Browse files
committed
start with fixing #3415
1 parent 6905ffc commit 45c126d

19 files changed

+184
-240
lines changed

key.ui/src/main/java/de/uka/ilkd/key/core/KeYMediator.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import de.uka.ilkd.key.control.ProofControl;
1717
import de.uka.ilkd.key.gui.GUIListener;
1818
import de.uka.ilkd.key.gui.UserActionListener;
19+
import de.uka.ilkd.key.gui.actions.MainWindowAction;
1920
import de.uka.ilkd.key.gui.actions.useractions.UserAction;
2021
import de.uka.ilkd.key.gui.notification.events.NotificationEvent;
2122
import de.uka.ilkd.key.gui.notification.events.ProofClosedNotificationEvent;
@@ -704,15 +705,21 @@ public void autoModeStopped(ProofEvent e) {
704705
}
705706
}
706707

707-
/*
708-
* Disable certain actions until a proof is loaded.
709-
*/
708+
/// Disable certain actions until a proof is loaded.
709+
///
710+
/// ### DEPRECATION
711+
/// You should rather use the [MainWindowAction] class
712+
/// with the [MainWindowAction#updateEnablednessOnSelectionChange()] method.
713+
///
714+
/// This provides more flexibility, as the enabledness can define in cases of a
715+
/// combination of predicates.
716+
///
717+
@Deprecated(forRemoval = true)
710718
public void enableWhenProofLoaded(final Action a) {
711719
a.setEnabled(getSelectedProof() != null);
712720
addKeYSelectionListener(new KeYSelectionListener() {
713-
714721
@Override
715-
public void selectedProofChanged(KeYSelectionEvent e) {
722+
public void selectedProofChanged(KeYSelectionEvent<Proof> e) {
716723
a.setEnabled(e.getSource().getSelectedProof() != null);
717724
}
718725
});
@@ -722,13 +729,13 @@ public void selectedProofChanged(KeYSelectionEvent e) {
722729
* Disable certain actions until a proof is loaded. This is a workaround for a broken proof
723730
* macro menu in the GUI. Remove this method as soon as another solution can be found.
724731
*/
725-
@Deprecated
732+
@Deprecated(forRemoval = true)
726733
public void enableWhenProofLoaded(final javax.swing.AbstractButton a) {
727734
a.setEnabled(getSelectedProof() != null);
728735
addKeYSelectionListener(new KeYSelectionListener() {
729736

730737
@Override
731-
public void selectedProofChanged(KeYSelectionEvent e) {
738+
public void selectedProofChanged(KeYSelectionEvent<Proof> e) {
732739
a.setEnabled(e.getSource().getSelectedProof() != null);
733740
}
734741
});

key.ui/src/main/java/de/uka/ilkd/key/gui/MainWindow.java

Lines changed: 21 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import java.awt.*;
77
import java.awt.event.ActionEvent;
88
import java.awt.event.KeyEvent;
9-
import java.awt.event.KeyListener;
10-
import java.awt.event.MouseEvent;
119
import java.beans.PropertyChangeEvent;
1210
import java.beans.PropertyChangeListener;
1311
import java.lang.reflect.InvocationTargetException;
@@ -24,7 +22,6 @@
2422
import javax.swing.event.ChangeListener;
2523
import javax.swing.event.MenuEvent;
2624
import javax.swing.event.MenuListener;
27-
import javax.swing.event.MouseInputAdapter;
2825

2926
import de.uka.ilkd.key.control.AutoModeListener;
3027
import de.uka.ilkd.key.control.TermLabelVisibilityManager;
@@ -56,6 +53,7 @@
5653
import de.uka.ilkd.key.gui.utilities.LruCached;
5754
import de.uka.ilkd.key.proof.Goal;
5855
import de.uka.ilkd.key.proof.Proof;
56+
import de.uka.ilkd.key.proof.ProofAggregate;
5957
import de.uka.ilkd.key.proof.ProofEvent;
6058
import de.uka.ilkd.key.settings.FeatureSettings;
6159
import de.uka.ilkd.key.settings.GeneralSettings;
@@ -106,6 +104,8 @@ public final class MainWindow extends JFrame {
106104
"Activates the 'Run All Proofs' action that allows you to run multiple proofs inside the UI.",
107105
false);
108106

107+
public static final String PROPERTY_IN_AUTO_MODE = "inAutoMode";
108+
109109
private static MainWindow instance = null;
110110
/**
111111
* Search bar for Sequent Views.
@@ -167,23 +167,27 @@ public final class MainWindow extends JFrame {
167167
private final ToggleProofTreeTooltipAction toogleProofTreeTooltipAction =
168168
new ToggleProofTreeTooltipAction(this);
169169
private final TermLabelMenu termLabelMenu;
170-
private boolean frozen = false;
170+
171171
/**
172172
*
173173
*/
174174
private final CControl dockControl = new CControl(this);
175+
175176
/**
176177
* the first toolbar
177178
*/
178179
private JToolBar controlToolBar;
180+
179181
/**
180182
* the second toolbar
181183
*/
182184
private JToolBar fileOpToolBar;
185+
183186
/**
184187
* the status line
185188
*/
186189
private MainStatusLine statusLine;
190+
187191
/**
188192
* action for opening a KeY file
189193
*/
@@ -278,6 +282,7 @@ public final class MainWindow extends JFrame {
278282

279283
private final LruCached<HTMLSyntaxHighlighter.Args, String> highlightCache =
280284
new LruCached<>(HTMLSyntaxHighlighter.Args::run);
285+
private boolean inAutoMode;
281286

282287
/*
283288
* This class should only be instantiated once!
@@ -442,7 +447,7 @@ public TermLabelVisibilityManager getVisibleTermLabels() {
442447
*/
443448
private void applyGnomeWorkaround() {
444449
Toolkit xToolkit = Toolkit.getDefaultToolkit();
445-
java.lang.reflect.Field awtAppClassNameField;
450+
Field awtAppClassNameField;
446451
try {
447452
awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
448453
awtAppClassNameField.setAccessible(true);
@@ -573,7 +578,7 @@ private void layoutMain() {
573578

574579
getContentPane().add(toolBarPanel, BorderLayout.PAGE_START);
575580

576-
proofListView.setPreferredSize(new java.awt.Dimension(350, 100));
581+
proofListView.setPreferredSize(new Dimension(350, 100));
577582
GuiUtilities.paintEmptyViewComponent(proofListView, "Proofs");
578583

579584
// JSplitPane leftPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, proofListView,
@@ -815,27 +820,6 @@ public void setStatusLine(final String str, final int max) {
815820
ThreadUtilities.invokeOnEventQueue(() -> setStatusLineImmediately(str, max));
816821
}
817822

818-
/**
819-
* Freeze the main window by blocking all input events, except those for the toolbar (i.e.
820-
* the abort button within the toolbar)
821-
*/
822-
public void freezeExceptAutoModeButton() {
823-
if (!frozen) {
824-
frozen = true;
825-
826-
Component glassPane = new BlockingGlassPane(getContentPane());
827-
setGlassPane(glassPane);
828-
glassPane.setVisible(true);
829-
}
830-
}
831-
832-
public void unfreezeExceptAutoModeButton() {
833-
if (frozen) {
834-
getGlassPane().setVisible(false);
835-
frozen = false;
836-
}
837-
}
838-
839823
/**
840824
* Update the sequent view.
841825
*/
@@ -846,7 +830,7 @@ public void makePrettyView() {
846830
SwingUtilities.invokeLater(this::updateSequentView);
847831
}
848832

849-
private void addToProofList(de.uka.ilkd.key.proof.ProofAggregate plist) {
833+
private void addToProofList(ProofAggregate plist) {
850834
proofList.addProof(plist);
851835
// TODO/Check: the code below emulates phantom actions. Check if this can be solved
852836
// differently
@@ -1183,7 +1167,7 @@ public CurrentGoalView getGoalView() {
11831167
return currentGoalView;
11841168
}
11851169

1186-
public void addProblem(final de.uka.ilkd.key.proof.ProofAggregate plist) {
1170+
public void addProblem(final ProofAggregate plist) {
11871171
Runnable guiUpdater = () -> {
11881172
disableCurrentGoalView = true;
11891173
addToProofList(plist);
@@ -1489,146 +1473,14 @@ public CurrentGoalView getCurrentGoalView() {
14891473
return currentGoalView;
14901474
}
14911475

1492-
/**
1493-
* Glass pane that only delivers events for the status line (i.e. the abort button)
1494-
* <p>
1495-
* This has been partly taken from the GlassPaneDemo of the Java Tutorial
1496-
*/
1497-
private static class BlockingGlassPane extends JComponent {
1498-
/**
1499-
*
1500-
*/
1501-
private static final long serialVersionUID = 1218022319090988424L;
1502-
private final GlassPaneListener listener;
1503-
1504-
public BlockingGlassPane(Container contentPane) {
1505-
setCursor(new Cursor(Cursor.WAIT_CURSOR));
1506-
1507-
listener = new GlassPaneListener(this, contentPane);
1508-
addMouseListener(listener);
1509-
addMouseMotionListener(listener);
1510-
addKeyListener(new KeyListener() {
1511-
1512-
@Override
1513-
public void keyPressed(KeyEvent e) {
1514-
e.consume();
1515-
}
1516-
1517-
@Override
1518-
public void keyReleased(KeyEvent e) {
1519-
e.consume();
1520-
1521-
}
1522-
1523-
@Override
1524-
public void keyTyped(KeyEvent e) {
1525-
e.consume();
1526-
}
1527-
1528-
});
1529-
}
1476+
public void setInAutoMode(boolean inAutoMode) {
1477+
var oldValue = this.inAutoMode;
1478+
this.inAutoMode = inAutoMode;
1479+
firePropertyChange(PROPERTY_IN_AUTO_MODE, oldValue, inAutoMode);
15301480
}
15311481

1532-
/**
1533-
* Mouse listener for the glass pane that only delivers events for the status line (i.e. the
1534-
* abort button)
1535-
* <p>
1536-
* This has been partly taken from the GlassPaneDemo of the Java Tutorial
1537-
*/
1538-
private static class GlassPaneListener extends MouseInputAdapter {
1539-
Component currentComponent = null;
1540-
final Component glassPane;
1541-
final Container contentPane;
1542-
1543-
public GlassPaneListener(Component glassPane, Container contentPane) {
1544-
this.glassPane = glassPane;
1545-
this.contentPane = contentPane;
1546-
}
1547-
1548-
@Override
1549-
public void mouseMoved(MouseEvent e) {
1550-
redispatchMouseEvent(e);
1551-
}
1552-
1553-
/*
1554-
* We must forward at least the mouse drags that started with mouse presses over the check
1555-
* box. Otherwise, when the user presses the check box then drags off, the check box isn't
1556-
* disarmed -- it keeps its dark gray background or whatever its L&F uses to indicate that
1557-
* the button is currently being pressed.
1558-
*/
1559-
@Override
1560-
public void mouseDragged(MouseEvent e) {
1561-
redispatchMouseEvent(e);
1562-
}
1563-
1564-
@Override
1565-
public void mouseClicked(MouseEvent e) {
1566-
redispatchMouseEvent(e);
1567-
}
1568-
1569-
@Override
1570-
public void mouseEntered(MouseEvent e) {
1571-
redispatchMouseEvent(e);
1572-
}
1573-
1574-
@Override
1575-
public void mouseExited(MouseEvent e) {
1576-
redispatchMouseEvent(e);
1577-
}
1578-
1579-
@Override
1580-
public void mousePressed(MouseEvent e) {
1581-
redispatchMouseEvent(e);
1582-
}
1583-
1584-
@Override
1585-
public void mouseReleased(MouseEvent e) {
1586-
redispatchMouseEvent(e);
1587-
currentComponent = null;
1588-
}
1589-
1590-
private void redispatchMouseEvent(MouseEvent e) {
1591-
if (currentComponent != null) {
1592-
dispatchForCurrentComponent(e);
1593-
} else {
1594-
int eventID = e.getID();
1595-
Point glassPanePoint = e.getPoint();
1596-
1597-
Point containerPoint =
1598-
SwingUtilities.convertPoint(glassPane, glassPanePoint, contentPane);
1599-
Component component = SwingUtilities.getDeepestComponentAt(contentPane,
1600-
containerPoint.x, containerPoint.y);
1601-
1602-
if (eventID == MouseEvent.MOUSE_PRESSED && isLiveComponent(component)) {
1603-
currentComponent = component;
1604-
dispatchForCurrentComponent(e);
1605-
}
1606-
}
1607-
}
1608-
1609-
// FIXME This is not really good.
1610-
private boolean isLiveComponent(Component c) {
1611-
// this is not the most elegant way to identify the right
1612-
// components, but it scales well ;-)
1613-
while (c != null) {
1614-
if ((c instanceof JComponent)
1615-
&& AUTO_MODE_TEXT.equals(((JComponent) c).getToolTipText())) {
1616-
return true;
1617-
}
1618-
c = c.getParent();
1619-
}
1620-
return false;
1621-
}
1622-
1623-
private void dispatchForCurrentComponent(MouseEvent e) {
1624-
Point glassPanePoint = e.getPoint();
1625-
Point componentPoint =
1626-
SwingUtilities.convertPoint(glassPane, glassPanePoint, currentComponent);
1627-
currentComponent.dispatchEvent(new MouseEvent(currentComponent, e.getID(), e.getWhen(),
1628-
// do not use as it freezes the stop button: e.getModifiersEx(),
1629-
e.getModifiers(), componentPoint.x, componentPoint.y, e.getClickCount(),
1630-
e.isPopupTrigger()));
1631-
}
1482+
public boolean isInAutoMode() {
1483+
return inAutoMode;
16321484
}
16331485

16341486
/**
@@ -1776,7 +1628,7 @@ public synchronized void autoModeStarted(ProofEvent e) {
17761628
LOGGER.debug("Automode started");
17771629
disableCurrentGoalView = true;
17781630
getMediator().removeKeYSelectionListener(proofListener);
1779-
freezeExceptAutoModeButton();
1631+
setInAutoMode(true);
17801632
}
17811633

17821634
/**
@@ -1785,9 +1637,9 @@ public synchronized void autoModeStarted(ProofEvent e) {
17851637
@Override
17861638
public synchronized void autoModeStopped(ProofEvent e) {
17871639
LOGGER.debug("Automode stopped");
1788-
unfreezeExceptAutoModeButton();
17891640
disableCurrentGoalView = false;
17901641
getMediator().addKeYSelectionListenerChecked(proofListener);
1642+
setInAutoMode(false);
17911643
}
17921644

17931645
@Override

key.ui/src/main/java/de/uka/ilkd/key/gui/actions/AbandonTaskAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AbandonTaskAction(MainWindow mainWindow, Proof proof) {
2424
setIcon(IconFactory.abandon(16));
2525
setTooltip("Drop current proof.");
2626

27-
getMediator().enableWhenProofLoaded(this);
27+
enabledOnAnActiveProof();
2828

2929
this.proof = proof;
3030
}

0 commit comments

Comments
 (0)