From bd03f07b5bcc5feb558caec4fbfd556947630fb9 Mon Sep 17 00:00:00 2001
From: Yuan Liao <liaoyuan@gmail.com>
Date: Sat, 19 Feb 2022 08:25:21 -0800
Subject: [PATCH] Update uses of javax.swing API members for Java 9+

These changes are backward compatible with Java 8.

Signed-off-by: Yuan Liao <liaoyuan@gmail.com>
---
 .../sf/jabref/FindUnlinkedFilesDialog.java    |  9 ++++-----
 .../net/sf/jabref/collab/EntryChange.java     |  6 +++---
 .../sf/jabref/groups/AddToGroupAction.java    |  5 +++--
 .../net/sf/jabref/groups/GroupSelector.java   |  9 +++++----
 .../net/sf/jabref/groups/GroupTreeNode.java   | 20 ++++++++-----------
 src/java/net/sf/jabref/groups/GroupsTree.java | 17 ++++++++--------
 .../jabref/imports/AppendDatabaseAction.java  |  5 +++--
 .../sf/jabref/sql/exporter/DBExporter.java    |  9 +++++----
 8 files changed, 40 insertions(+), 40 deletions(-)

diff --git a/src/java/net/sf/jabref/FindUnlinkedFilesDialog.java b/src/java/net/sf/jabref/FindUnlinkedFilesDialog.java
index 4bcbd73..5f7473d 100644
--- a/src/java/net/sf/jabref/FindUnlinkedFilesDialog.java
+++ b/src/java/net/sf/jabref/FindUnlinkedFilesDialog.java
@@ -669,13 +669,12 @@ public class FindUnlinkedFilesDialog extends JDialog {
 	 *            The root node representing a tree structure.
 	 * @return A list of files of all checked leaf nodes.
 	 */
-	@SuppressWarnings("unchecked")
 	private List<File> getFileListFromNode(CheckableTreeNode node) {
 		List<File> filesList = new ArrayList<File>();
-		Enumeration<CheckableTreeNode> childs = node.depthFirstEnumeration();
+		Enumeration<TreeNode> childs = node.depthFirstEnumeration();
 		ArrayList<CheckableTreeNode> nodesToRemove = new ArrayList<FindUnlinkedFilesDialog.CheckableTreeNode>();
 		while (childs.hasMoreElements()) {
-			CheckableTreeNode child = childs.nextElement();
+			CheckableTreeNode child = (CheckableTreeNode) childs.nextElement();
 			if (child.isLeaf() && child.getSelected()) {
 				File nodeFile = ((FileNodeWrapper) child.getUserObject()).file;
 				if (nodeFile != null && nodeFile.isFile()) {
@@ -1105,9 +1104,9 @@ public class FindUnlinkedFilesDialog extends JDialog {
 		@SuppressWarnings("unchecked")
 		public void setSelected(boolean bSelected) {
 			isSelected = bSelected;
-			Enumeration<CheckableTreeNode> children = this.children();
+			Enumeration<TreeNode> children = this.children();
 			while (children.hasMoreElements()) {
-				CheckableTreeNode child = children.nextElement();
+				CheckableTreeNode child = (CheckableTreeNode) children.nextElement();
 				child.setSelected(bSelected);
 			}
 
diff --git a/src/java/net/sf/jabref/collab/EntryChange.java b/src/java/net/sf/jabref/collab/EntryChange.java
index 924fd25..d479995 100644
--- a/src/java/net/sf/jabref/collab/EntryChange.java
+++ b/src/java/net/sf/jabref/collab/EntryChange.java
@@ -21,6 +21,7 @@ import java.util.TreeSet;
 import javax.swing.JComponent;
 import javax.swing.JLabel;
 import javax.swing.JScrollPane;
+import javax.swing.tree.TreeNode;
 
 import net.sf.jabref.*;
 import net.sf.jabref.undo.NamedCompound;
@@ -83,11 +84,10 @@ public class EntryChange extends Change {
 
   
 public boolean makeChange(BasePanel panel, BibtexDatabase secondary, NamedCompound undoEdit) {
-    @SuppressWarnings("unchecked")
     boolean allAccepted = true;
-    Enumeration<Change> e = children();
+    Enumeration<TreeNode> e = children();
     for (; e.hasMoreElements();) {
-        Change c = e.nextElement();
+        Change c = (Change) e.nextElement();
         if (c.isAcceptable() && c.isAccepted())
             c.makeChange(panel, secondary, undoEdit);
         else allAccepted = false;
diff --git a/src/java/net/sf/jabref/groups/AddToGroupAction.java b/src/java/net/sf/jabref/groups/AddToGroupAction.java
index 30d57c8..1840e32 100644
--- a/src/java/net/sf/jabref/groups/AddToGroupAction.java
+++ b/src/java/net/sf/jabref/groups/AddToGroupAction.java
@@ -20,6 +20,7 @@ import java.util.Enumeration;
 import java.util.Vector;
 
 import javax.swing.AbstractAction;
+import javax.swing.tree.TreeNode;
 import javax.swing.undo.AbstractUndoableEdit;
 
 import net.sf.jabref.BasePanel;
@@ -59,10 +60,10 @@ public class AddToGroupAction extends AbstractAction {
         
         if (m_move) {
             // collect warnings for removal
-            Enumeration<GroupTreeNode> e = ((GroupTreeNode) m_node.getRoot()).preorderEnumeration();
+            Enumeration<TreeNode> e = ((GroupTreeNode) m_node.getRoot()).preorderEnumeration();
             GroupTreeNode node;
             while (e.hasMoreElements()) {
-                node = e.nextElement();
+                node = (GroupTreeNode) e.nextElement();
                 if (!node.getGroup().supportsRemove())
                     continue;
                 for (int i = 0; i < entries.length; ++i) {
diff --git a/src/java/net/sf/jabref/groups/GroupSelector.java b/src/java/net/sf/jabref/groups/GroupSelector.java
index 4700d13..4813f12 100644
--- a/src/java/net/sf/jabref/groups/GroupSelector.java
+++ b/src/java/net/sf/jabref/groups/GroupSelector.java
@@ -60,6 +60,7 @@ import javax.swing.event.PopupMenuListener;
 import javax.swing.event.TreeSelectionEvent;
 import javax.swing.event.TreeSelectionListener;
 import javax.swing.tree.DefaultTreeModel;
+import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 import javax.swing.undo.AbstractUndoableEdit;
 import javax.swing.undo.CompoundEdit;
@@ -1498,8 +1499,8 @@ public class GroupSelector extends SidePaneComponent implements
         GroupTreeNode node;
         AbstractGroup group;
         Vector<GroupTreeNode> vec = new Vector<GroupTreeNode>();
-        for (Enumeration<GroupTreeNode> e = groupsRoot.preorderEnumeration(); e.hasMoreElements();) {
-            node = e.nextElement();
+        for (Enumeration<TreeNode> e = groupsRoot.preorderEnumeration(); e.hasMoreElements();) {
+            node = (GroupTreeNode) e.nextElement();
             group = node.getGroup();
             int i;
             for (i = 0; i < entries.length; ++i) {
@@ -1537,8 +1538,8 @@ public class GroupSelector extends SidePaneComponent implements
       BibtexEntry entry;
       Vector<GroupTreeNode> vec = new Vector<GroupTreeNode>();
       Map<String, String> dummyMap = new HashMap<String, String>(); // just because I don't want to use null...
-        for (Enumeration<GroupTreeNode> e = groupsRoot.depthFirstEnumeration(); e.hasMoreElements();) {
-          node = e.nextElement();
+        for (Enumeration<TreeNode> e = groupsRoot.depthFirstEnumeration(); e.hasMoreElements();) {
+          node = (GroupTreeNode) e.nextElement();
           rule = node.getSearchRule();
             for (Iterator<BibtexEntry> it = matches.iterator(); it.hasNext();) {
               entry = it.next();
diff --git a/src/java/net/sf/jabref/groups/GroupTreeNode.java b/src/java/net/sf/jabref/groups/GroupTreeNode.java
index 9013af4..c55c7cf 100644
--- a/src/java/net/sf/jabref/groups/GroupTreeNode.java
+++ b/src/java/net/sf/jabref/groups/GroupTreeNode.java
@@ -81,10 +81,10 @@ public class GroupTreeNode extends DefaultMutableTreeNode implements
 	 */
 	public String getTreeAsString() {
 		StringBuffer sb = new StringBuffer();
-		Enumeration<GroupTreeNode> e = preorderEnumeration();
+		Enumeration<TreeNode> e = preorderEnumeration();
 		GroupTreeNode cursor;
 		while (e.hasMoreElements()) {
-			cursor = e.nextElement();
+			cursor = (GroupTreeNode) e.nextElement();
             sb.append(cursor.getLevel()).append(" ").append(cursor.getGroup().toString()).append("\n");
 		}
 		return sb.toString();
@@ -194,26 +194,22 @@ public class GroupTreeNode extends DefaultMutableTreeNode implements
 	}
 
 	@Override
-	@SuppressWarnings("unchecked")
-	public Enumeration<GroupTreeNode> preorderEnumeration(){
+	public Enumeration<TreeNode> preorderEnumeration(){
 		return super.preorderEnumeration();
 	}
 	
 	@Override
-	@SuppressWarnings("unchecked")
-	public Enumeration<GroupTreeNode> depthFirstEnumeration(){
+	public Enumeration<TreeNode> depthFirstEnumeration(){
 		return super.depthFirstEnumeration();
 	}
 	
 	@Override
-	@SuppressWarnings("unchecked")
-	public Enumeration<GroupTreeNode> breadthFirstEnumeration(){
+	public Enumeration<TreeNode> breadthFirstEnumeration(){
 		return super.breadthFirstEnumeration();
 	}
 	
 	@Override
-	@SuppressWarnings("unchecked")
-	public Enumeration<GroupTreeNode> children(){
+	public Enumeration<TreeNode> children(){
 		return super.children();
 	}
 	
@@ -224,10 +220,10 @@ public class GroupTreeNode extends DefaultMutableTreeNode implements
 	 */
 	public AbstractGroup[] getMatchingGroups(BibtexEntry entry) {
 		Vector<AbstractGroup> matchingGroups = new Vector<AbstractGroup>();
-		Enumeration<GroupTreeNode> e = preorderEnumeration();
+		Enumeration<TreeNode> e = preorderEnumeration();
 		AbstractGroup group;
 		while (e.hasMoreElements()) {
-			group = (e.nextElement()).getGroup();
+			group = ((GroupTreeNode) e.nextElement()).getGroup();
 			if (group.contains(null, entry)) // first argument is never used
 				matchingGroups.add(group);
 		}
diff --git a/src/java/net/sf/jabref/groups/GroupsTree.java b/src/java/net/sf/jabref/groups/GroupsTree.java
index e58a567..c3daf94 100644
--- a/src/java/net/sf/jabref/groups/GroupsTree.java
+++ b/src/java/net/sf/jabref/groups/GroupsTree.java
@@ -31,6 +31,7 @@ import javax.swing.JTree;
 import javax.swing.SwingUtilities;
 import javax.swing.ToolTipManager;
 import javax.swing.tree.DefaultMutableTreeNode;
+import javax.swing.tree.TreeNode;
 import javax.swing.tree.TreePath;
 import javax.swing.tree.TreeSelectionModel;
 import javax.swing.undo.AbstractUndoableEdit;
@@ -415,14 +416,14 @@ public class GroupsTree extends JTree implements DragSourceListener,
 
 	/** Expand this node and all its children. */
 	public void expandSubtree(GroupTreeNode node) {
-		for (Enumeration<GroupTreeNode> e = node.depthFirstEnumeration(); e.hasMoreElements();)
-			expandPath(new TreePath(e.nextElement().getPath()));
+		for (Enumeration<TreeNode> e = node.depthFirstEnumeration(); e.hasMoreElements();)
+			expandPath(new TreePath(((GroupTreeNode) e.nextElement()).getPath()));
 	}
 
 	/** Collapse this node and all its children. */
 	public void collapseSubtree(GroupTreeNode node) {
-		for (Enumeration<GroupTreeNode> e = node.depthFirstEnumeration(); e.hasMoreElements();)
-			collapsePath(new TreePath((e.nextElement())
+		for (Enumeration<TreeNode> e = node.depthFirstEnumeration(); e.hasMoreElements();)
+			collapsePath(new TreePath(((GroupTreeNode) e.nextElement())
 					.getPath()));
 	}
 
@@ -432,8 +433,8 @@ public class GroupsTree extends JTree implements DragSourceListener,
 	 */
 	public boolean hasExpandedDescendant(TreePath path) {
 		GroupTreeNode node = (GroupTreeNode) path.getLastPathComponent();
-		for (Enumeration<GroupTreeNode> e = node.children(); e.hasMoreElements();) {
-			GroupTreeNode child = e.nextElement();
+		for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
+			GroupTreeNode child = (GroupTreeNode) e.nextElement();
 			if (child.isLeaf())
 				continue; // don't care about this case
 			TreePath pathToChild = path.pathByAddingChild(child);
@@ -449,8 +450,8 @@ public class GroupsTree extends JTree implements DragSourceListener,
 	 */
 	public boolean hasCollapsedDescendant(TreePath path) {
 		GroupTreeNode node = (GroupTreeNode) path.getLastPathComponent();
-		for (Enumeration<GroupTreeNode> e = node.children(); e.hasMoreElements();) {
-			GroupTreeNode child = e.nextElement();
+		for (Enumeration<TreeNode> e = node.children(); e.hasMoreElements();) {
+			GroupTreeNode child = (GroupTreeNode) e.nextElement();
 			if (child.isLeaf())
 				continue; // don't care about this case
 			TreePath pathToChild = path.pathByAddingChild(child);
diff --git a/src/java/net/sf/jabref/imports/AppendDatabaseAction.java b/src/java/net/sf/jabref/imports/AppendDatabaseAction.java
index ad84bbc..5fdce20 100644
--- a/src/java/net/sf/jabref/imports/AppendDatabaseAction.java
+++ b/src/java/net/sf/jabref/imports/AppendDatabaseAction.java
@@ -22,6 +22,7 @@ import java.util.Iterator;
 import java.util.List;
 
 import javax.swing.JOptionPane;
+import javax.swing.tree.TreeNode;
 
 import net.sf.jabref.BaseAction;
 import net.sf.jabref.BasePanel;
@@ -175,9 +176,9 @@ public class AppendDatabaseAction extends BaseAction {
                   ExplicitGroup group;
                   BibtexEntry entry;
                   
-                  for (Enumeration<GroupTreeNode> e = newGroups
+                  for (Enumeration<TreeNode> e = newGroups
 					.preorderEnumeration(); e.hasMoreElements();) {
-					node = e.nextElement();
+					node = (GroupTreeNode) e.nextElement();
 					if (!(node.getGroup() instanceof ExplicitGroup))
 						continue;
 					group = (ExplicitGroup) node.getGroup();
diff --git a/src/java/net/sf/jabref/sql/exporter/DBExporter.java b/src/java/net/sf/jabref/sql/exporter/DBExporter.java
index deb9126..1518e0b 100644
--- a/src/java/net/sf/jabref/sql/exporter/DBExporter.java
+++ b/src/java/net/sf/jabref/sql/exporter/DBExporter.java
@@ -32,6 +32,7 @@ import java.util.Set;
 import java.util.Vector;
 
 import javax.swing.JOptionPane;
+import javax.swing.tree.TreeNode;
 
 import net.sf.jabref.BibtexDatabase;
 import net.sf.jabref.BibtexEntry;
@@ -201,9 +202,9 @@ public abstract class DBExporter extends DBImporterExporter{
 			rs.next();
 			myID = rs.getInt("groups_id");
 		}
-		for (Enumeration<GroupTreeNode> e = cursor.children(); e
+		for (Enumeration<TreeNode> e = cursor.children(); e
 				.hasMoreElements();)
-			currentID = populateEntryGroupsTable(e.nextElement(), myID,
+			currentID = populateEntryGroupsTable((GroupTreeNode) e.nextElement(), myID,
 					currentID, out, database_id);
 		return currentID;
 	}
@@ -338,9 +339,9 @@ public abstract class DBExporter extends DBImporterExporter{
 			rs.next();
 			myID = rs.getInt("groups_id");
 		}
-		for (Enumeration<GroupTreeNode> e = cursor.children(); e
+		for (Enumeration<TreeNode> e = cursor.children(); e
 				.hasMoreElements();)
-			currentID = populateGroupsTable(e.nextElement(), myID, ++currentID,
+			currentID = populateGroupsTable((GroupTreeNode) e.nextElement(), myID, ++currentID,
 					out, database_id);
 		return currentID;
 	}
-- 
2.34.1

