Skip to content

Commit 4807255

Browse files
committed
Fix unresponsive operator hierarchy font size
and call UI-updating actions on the EDT everywhere for consistency and to avoid deadlocks.
1 parent e671e8a commit 4807255

File tree

6 files changed

+46
-31
lines changed

6 files changed

+46
-31
lines changed

src/main/java/edu/umich/soar/visualsoar/datamap/DataMapTree.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,13 @@ public DataMapTree(DataMap initParent, TreeModel model, SoarWorkingMemoryModel _
379379
}//ctor
380380

381381
private void setFontSize(int fontSize) {
382-
final Font newSizedFont =
383-
new Font(
384-
getFont().getName(),
385-
getFont().getStyle(),
386-
fontSize);
387-
setFont(newSizedFont);
388-
setRowHeight(fontSize + ROW_TEXT_MARGIN);
389-
FontUtils.setContainerFontSize(contextMenu, fontSize);
382+
final Font newSizedFont = new Font(getFont().getName(), getFont().getStyle(), fontSize);
383+
SwingUtilities.invokeLater(
384+
() -> {
385+
setFont(newSizedFont);
386+
setRowHeight(fontSize + ROW_TEXT_MARGIN);
387+
FontUtils.setContainerFontSize(contextMenu, fontSize);
388+
});
390389
}
391390

392391
/**

src/main/java/edu/umich/soar/visualsoar/mainframe/MainFrame.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,26 @@ public void windowClosing(WindowEvent e)
227227
Prefs.editorFontSize.addChangeListener(newValue -> setFontSize((int) newValue));
228228
}//MainFrame ctor
229229

230-
////////////////////////////////////////
231-
// Methods
232-
////////////////////////////////////////
230+
////////////////////////////////////////
231+
// Methods
232+
////////////////////////////////////////
233233

234234
private void setFontSize(int fontSize) {
235-
setMenuBarFontSize(getJMenuBar(), fontSize);
236-
feedbackListBorder.setTitleFont(getResizedFont(feedbackListBorder.getTitleFont(), fontSize));
237-
UIManager.getLookAndFeelDefaults().forEach((key, value) -> {
238-
if (key.toString().endsWith(".font") && value instanceof Font) {
239-
Font oldFont = (Font) value;
240-
Font newFont = new Font(oldFont.getName(), oldFont.getStyle(), fontSize);
241-
UIManager.put(key, newFont);
242-
}
243-
});
235+
SwingUtilities.invokeLater(
236+
() -> {
237+
setMenuBarFontSize(getJMenuBar(), fontSize);
238+
feedbackListBorder.setTitleFont(
239+
getResizedFont(feedbackListBorder.getTitleFont(), fontSize));
240+
UIManager.getLookAndFeelDefaults()
241+
.forEach(
242+
(key, value) -> {
243+
if (key.toString().endsWith(".font") && value instanceof Font) {
244+
Font oldFont = (Font) value;
245+
Font newFont = new Font(oldFont.getName(), oldFont.getStyle(), fontSize);
246+
UIManager.put(key, newFont);
247+
}
248+
});
249+
});
244250
}
245251

246252
private boolean canAutoTile() {

src/main/java/edu/umich/soar/visualsoar/mainframe/feedback/FeedbackCellRenderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public FeedbackCellRenderer() {
1717
setOpaque(true);
1818
}
1919

20+
/** This method should only be called from the EDT, and it does not take care to do so itself. */
2021
void setFontSize(int fontSize) {
2122
final Font newSizedFont = new Font(getFont().getName(), getFont().getStyle(), fontSize);
2223
setFont(newSizedFont);

src/main/java/edu/umich/soar/visualsoar/mainframe/feedback/FeedbackList.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,12 @@ else if (SwingUtilities.isRightMouseButton(e)) {
107107

108108
private void setFontSize(int fontSize) {
109109
final Font newSizedFont = new Font(getFont().getName(), getFont().getStyle(), fontSize);
110-
setFont(newSizedFont);
111-
setContainerFontSize(rightClickContextMenu, fontSize);
112-
cellRenderer.setFontSize(fontSize);
110+
SwingUtilities.invokeLater(
111+
() -> {
112+
setFont(newSizedFont);
113+
setContainerFontSize(rightClickContextMenu, fontSize);
114+
cellRenderer.setFontSize(fontSize);
115+
});
113116
}
114117

115118
///////////////////////////////////////////////////////////////////

src/main/java/edu/umich/soar/visualsoar/operatorwindow/OperatorWindow.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class OperatorWindow extends JTree {
5151
DragGestureListener dgListener = new OWDragGestureListener();
5252

5353
private ProjectModel projectModel;
54+
55+
private final DefaultTreeCellRenderer owCellRenderer = new OperatorWindowRenderer();
5456
private static OperatorWindow s_OperatorWindow;
5557

5658
private static final int ROW_TEXT_MARGIN = 7;
@@ -63,7 +65,7 @@ public class OperatorWindow extends JTree {
6365
*/
6466
private OperatorWindow() {
6567

66-
setCellRenderer(new OperatorWindowRenderer());
68+
setCellRenderer(owCellRenderer);
6769

6870
s_OperatorWindow = this;
6971

@@ -119,15 +121,16 @@ public void mouseReleased(MouseEvent e) {
119121
}
120122
setFontSize(Prefs.editorFontSize.getInt());
121123
Prefs.editorFontSize.addChangeListener(
122-
newValue -> {
123-
setFontSize((int) newValue);
124-
});
124+
newValue -> setFontSize((int) newValue));
125125
}
126126

127127
private void setFontSize(int fontSize) {
128128
final Font newSizedFont = new Font(getFont().getName(), getFont().getStyle(), fontSize);
129-
setFont(newSizedFont);
130-
setRowHeight(fontSize + ROW_TEXT_MARGIN);
129+
SwingUtilities.invokeLater(() -> {
130+
setFont(newSizedFont);
131+
owCellRenderer.setFont(newSizedFont);
132+
setRowHeight(fontSize + ROW_TEXT_MARGIN);
133+
});
131134
}
132135

133136
/**

src/main/java/edu/umich/soar/visualsoar/ruleeditor/RuleEditor.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,8 +1040,11 @@ private void initMenuBar() {
10401040
}
10411041

10421042
private void setFontSize(int fontSize) {
1043-
setMenuBarFontSize(getJMenuBar(), fontSize);
1044-
setContainerFontSize(editorPane.getContextMenu(), fontSize);
1043+
SwingUtilities.invokeLater(
1044+
() -> {
1045+
setMenuBarFontSize(getJMenuBar(), fontSize);
1046+
setContainerFontSize(editorPane.getContextMenu(), fontSize);
1047+
});
10451048
}
10461049

10471050
private void initMenuBarExternFile() {

0 commit comments

Comments
 (0)