Skip to content

Commit 5ef39a5

Browse files
committed
Update TregexGUI to use Java 11+ Desktop class (not historical Apple stuff)
Remove old (no longer usable) Apple Java extensions class. Support Options/Preferences/About via modern Desktop class methods. Clean up and correct for 2020s some of the properties for Apple options. Do running things on the Swing thread correctly.
1 parent 645f407 commit 5ef39a5

File tree

9 files changed

+248
-271
lines changed

9 files changed

+248
-271
lines changed

lib/AppleJavaExtensions.jar

-4.09 KB
Binary file not shown.

lib/README

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,6 @@ LAST UPDATE: 2020/10/17
175175
LAST UPDATE BY: Christopher Manning
176176

177177
----------------------------------------------------------------------
178-
AppleJavaExtensions.jar
179-
180-
ORIGINAL JAR NAME: AppleJavaExtensions.jar
181-
182-
VERSION: 1.3
183-
184-
RELEASE DATE: 2006-10-17
185-
186-
SOURCE AVAILABLE: no
187-
188-
DESCRIPTION: Stub methods to allow programs that can use Mac graphical
189-
stuff load on non-macs. Should only be on compile classpath, not actually
190-
used at run time (Macs actually have the classes in this jar, and should load
191-
by reflection; see TregexGUI for an example).
192-
193-
URL: http://developer.apple.com/samplecode/AppleJavaExtensions/index.html
194-
195-
USED BY: TregexGUI.java
196-
Not needed by CoreNLP distributions
197-
(Only used for fake compilation -- at runtime, either Mac supplies this or it doesn't.)
198-
199-
LAST UPDATE: 2007/09/18
200-
201-
LAST UPDATE BY: Anna Rafferty.
202-
203-
-----------------------------------------------------------------------
204178
xom-1.3.9.jar
205179

206180
ORIGINAL JAR NAME: xom-1.3.9.jar

src/edu/stanford/nlp/trees/tregex/gui/DisplayMatchesPanel.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
@SuppressWarnings("serial")
7171
public class DisplayMatchesPanel extends JPanel implements ListSelectionListener {
7272

73-
private JScrollPane scroller;
73+
private final JScrollPane scroller;
7474
private MouseEvent firstMouseEvent = null;
7575

7676
private String fontName = "";
@@ -102,7 +102,7 @@ private DisplayMatchesPanel() {
102102
scroller = new JScrollPane(spaceholder);
103103

104104
// Fix slow scrolling on OS X
105-
if (TregexGUI.isMacOSX()) {
105+
if (TregexGUI.isMacOS()) {
106106
scroller.getVerticalScrollBar().setUnitIncrement(3);
107107
scroller.getHorizontalScrollBar().setUnitIncrement(3);
108108
}
@@ -186,10 +186,10 @@ public void mousePressed(MouseEvent e) {
186186
firstMouseEvent = e;
187187
}
188188
e.consume();
189-
if(((e.getModifiersEx()) & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
189+
if (((e.getModifiersEx()) & InputEvent.SHIFT_DOWN_MASK) == InputEvent.SHIFT_DOWN_MASK) {
190190
//shift is being held
191191
addHighlight(textField, firstMouseEvent, e);
192-
} else if(!HighlightUtils.isInHighlight(e, textField, textField.getHighlighter())) {
192+
} else if (!HighlightUtils.isInHighlight(e, textField, textField.getHighlighter())) {
193193
textField.getHighlighter().removeAllHighlights();
194194
firstMouseEvent = e;
195195
dragNDrop = false;
@@ -360,8 +360,9 @@ private ScrollableTreeJPanel getTreeJPanel(Tree t, List<Tree> matchedParts) {
360360
copy.setActionCommand((String) TransferHandler.getCopyAction()
361361
.getValue(Action.NAME));
362362
copy.addActionListener(new TregexGUI.TransferActionListener());
363-
int mask = TregexGUI.isMacOSX() ? InputEvent.META_MASK : InputEvent.CTRL_MASK;
363+
int mask = TregexGUI.isMacOS() ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK;
364364
copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, mask));
365+
365366
treePopup.add(copy);
366367

367368
JMenuItem exportTree = new JMenuItem("Export tree as image");

src/edu/stanford/nlp/trees/tregex/gui/FilePanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public class FilePanel extends JPanel {
5555

5656
private static final long serialVersionUID = -2229250395240163264L;
5757
private static FilePanel filePanel = null;
58-
private JTree tree;
58+
private final JTree tree;
5959
private FileTreeModel treeModel;
6060

6161
public static synchronized FilePanel getInstance() {
@@ -91,7 +91,7 @@ public void mouseClicked(MouseEvent e) {
9191

9292
//layout/panel stuff
9393
this.setLayout(new BorderLayout());
94-
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),"Tree files: "));
94+
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),"Tree files"));
9595
JScrollPane scroller = new JScrollPane(tree);
9696
this.add(scroller, BorderLayout.CENTER);
9797
}

src/edu/stanford/nlp/trees/tregex/gui/InputPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ private InputPanel() {
119119

120120
//layout/image stuff
121121
this.setLayout(new GridBagLayout());
122-
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),"Search pattern: "));
122+
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),"Search pattern"));
123123

124124
//pattern/history area
125125
JPanel tregexInput = makeTregexPatternArea();

src/edu/stanford/nlp/trees/tregex/gui/MatchesPanel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,10 @@
5151
@SuppressWarnings("serial")
5252
public class MatchesPanel extends JPanel implements ListSelectionListener {
5353
private static MatchesPanel instance = null;
54-
private JList<TreeFromFile> list;
54+
private final JList<TreeFromFile> list;
5555
// todo: Change the below to just be a List<List<Tree>> paralleling list above
5656
private Map<TreeFromFile,List<Tree>> matchedParts;
57-
private List<MatchesPanelListener> listeners;
57+
private final List<MatchesPanelListener> listeners;
5858
private Color highlightColor = Color.CYAN;
5959
private boolean showOnlyMatchedPortion = false;
6060
private JTextField lastSelected = null;
@@ -171,7 +171,7 @@ private int getCharOffset(FontMetrics fm, String characters, int xPos) {
171171
listeners = new ArrayList<>();
172172
//layout
173173
this.setLayout(new BorderLayout());
174-
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),"Matches: "));
174+
this.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEmptyBorder(),"Matches"));
175175
JScrollPane scroller = new JScrollPane(list);
176176
this.add(scroller, BorderLayout.CENTER);
177177
}

src/edu/stanford/nlp/trees/tregex/gui/OSXAdapter.java

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/edu/stanford/nlp/trees/tregex/gui/PreferencesPanel.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ public class PreferencesPanel extends JDialog {
7474
private static final String HISTORY_ERROR = "history";//error code if history size is not an int >0
7575
private static final String MAX_MATCH_ERROR = "maxMatch";//error code if history size is not an int >0
7676

77-
private TregexGUI gui;
77+
private final TregexGUI gui;
7878

7979
final JButton highlightButton;
80-
private JTextField setEncoding;//declared here because may change in different places
80+
private final JTextField setEncoding;//declared here because may change in different places
8181

8282
public PreferencesPanel(TregexGUI gui) {
83-
super(gui, "Preferences");
83+
super(gui, TregexGUI.isMacOS() ? "Settings": "Preferences");
8484

8585
this.gui = gui;
8686

@@ -121,7 +121,7 @@ public PreferencesPanel(TregexGUI gui) {
121121
JPanel treeDisplayOptions = new JPanel();
122122
treeDisplayOptions.setLayout(new GridLayout(4,2));
123123
JLabel fontName = new JLabel("Font: ");
124-
final JComboBox fontPicker = new JComboBox(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
124+
final JComboBox<String> fontPicker = new JComboBox<>(GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames());
125125
fontPicker.setSelectedItem(Preferences.getFont());
126126

127127
JLabel sizeLabel = new JLabel("Font size: ");
@@ -154,12 +154,12 @@ public PreferencesPanel(TregexGUI gui) {
154154
advOptions.setBorder(BorderFactory.createTitledBorder("Advanced "));
155155
advOptions.setLayout(new GridLayout(3,2,0,4));
156156
JLabel headfinderName = new JLabel("Head finder:");
157-
final JComboBox headfinderPicker = new JComboBox(new String[] {"ArabicHeadFinder", "BikelChineseHeadFinder", "ChineseHeadFinder", "ChineseSemanticHeadFinder", "CollinsHeadFinder", "DybroFrenchHeadFinder", "LeftHeadFinder", "ModCollinsHeadFinder", "NegraHeadFinder", "SemanticHeadFinder", "SunJurafskyChineseHeadFinder", "TueBaDZHeadFinder", "UniversalSemanticHeadFinder"}); //
157+
final JComboBox<String> headfinderPicker = new JComboBox<>(new String[] {"ArabicHeadFinder", "BikelChineseHeadFinder", "ChineseHeadFinder", "ChineseSemanticHeadFinder", "CollinsHeadFinder", "DybroFrenchHeadFinder", "LeftHeadFinder", "ModCollinsHeadFinder", "NegraHeadFinder", "SemanticHeadFinder", "SunJurafskyChineseHeadFinder", "TueBaDZHeadFinder", "UniversalSemanticHeadFinder"}); //
158158
headfinderPicker.setEditable(true);
159159
headfinderPicker.setSelectedItem(Preferences.getHeadFinder()
160160
.getClass().getSimpleName());
161161
JLabel treeReaderFactoryName = new JLabel("Tree reader factory:");
162-
final JComboBox trfPicker = new JComboBox(new String[] {"ArabicTreeReaderFactory", "ArabicTreeReaderFactory.ArabicRawTreeReaderFactory", "CTBTreeReaderFactory", "Basic categories only (LabeledScoredTreeReaderFactory)", "FrenchTreeReaderFactory","NoEmptiesCTBTreeReaderFactory", "PennTreeReaderFactory", "TregexTreeReaderFactory" });
162+
final JComboBox<String> trfPicker = new JComboBox<>(new String[] {"ArabicTreeReaderFactory", "ArabicTreeReaderFactory.ArabicRawTreeReaderFactory", "CTBTreeReaderFactory", "Basic categories only (LabeledScoredTreeReaderFactory)", "FrenchTreeReaderFactory","NoEmptiesCTBTreeReaderFactory", "PennTreeReaderFactory", "TregexTreeReaderFactory" });
163163
trfPicker.setEditable(true);
164164
trfPicker.setSelectedItem(Preferences.getTreeReaderFactory()
165165
.getClass().getSimpleName());
@@ -248,7 +248,7 @@ public void actionPerformed(ActionEvent arg0) {
248248
JOptionPane.showMessageDialog(prefPanel, "Please enter an integer greater than 0 for the font size.", "Font size error", JOptionPane.ERROR_MESSAGE);
249249
else if (e.getMessage() == PreferencesPanel.HISTORY_ERROR)
250250
JOptionPane.showMessageDialog(prefPanel, "Please enter an integer greater than or equal to 0 for the number of recent matches to remember.", "History size error", JOptionPane.ERROR_MESSAGE);
251-
else if (e.getMessage() == PreferencesPanel.HISTORY_ERROR)
251+
else if (e.getMessage() == PreferencesPanel.MAX_MATCH_ERROR)
252252
JOptionPane.showMessageDialog(prefPanel, "Please enter an integer greater than or equal to 0 for the maximum number of matches to display.", "Max Matches size error", JOptionPane.ERROR_MESSAGE);
253253
else
254254
JOptionPane.showMessageDialog(prefPanel, "Please check that the font size, max matches to display, and number of recent matches to remember are all integers greater than 0.", "Size error", JOptionPane.ERROR_MESSAGE);
@@ -267,7 +267,7 @@ else if (e.getMessage() == PreferencesPanel.HISTORY_ERROR)
267267
private static Integer checkNumberFormat(JTextField component, String errorType) throws NumberFormatException {
268268
Integer number = null;
269269
String txt = component.getText();
270-
if(txt!= null && !"".equals(txt)) {
270+
if (txt!= null && ! txt.isEmpty()) {
271271
try {
272272
number = Integer.parseInt(txt);
273273
if(number <= 0)
@@ -360,8 +360,6 @@ private void doEncodingPrompt(final String encoding, final String oldEncoding) {
360360
final JDialog dialog = fileFilterDialog.createDialog(null, "Default encoding changed...");
361361
useNewEncoding.addActionListener(arg0 -> {
362362
FileTreeModel.setCurEncoding(encoding);
363-
if(setEncoding == null)
364-
System.out.println("encoding null!!");
365363
setEncoding.setText(encoding);
366364
dialog.setVisible(false);
367365
});

0 commit comments

Comments
 (0)