| 
     
      
      
      From: <kp...@us...> - 2021-03-13 08:32:48
      
     
   | 
Revision: 25420
          http://sourceforge.net/p/jedit/svn/25420
Author:   kpouer
Date:     2021-03-13 08:32:47 +0000 (Sat, 13 Mar 2021)
Log Message:
-----------
Some cleanup
Modified Paths:
--------------
    jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowFactory.java
    jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManager.java
    jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManagerProvider.java
    jEdit/trunk/org/gjt/sp/jedit/gui/DockingLayoutManager.java
Modified: jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowFactory.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowFactory.java	2021-02-13 18:09:26 UTC (rev 25419)
+++ jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowFactory.java	2021-03-13 08:32:47 UTC (rev 25420)
@@ -23,15 +23,10 @@
 package org.gjt.sp.jedit.gui;
 
 //{{{ Imports
-import java.awt.Color;
 import java.io.IOException;
 import java.io.InputStream;
 import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Stack;
+import java.util.*;
 
 import javax.swing.JComponent;
 import javax.swing.LookAndFeel;
@@ -127,14 +122,7 @@
 	 */
 	public void unloadDockableWindows(PluginJAR plugin)
 	{
-		Iterator entries = dockableWindowFactories.entrySet().iterator();
-		while(entries.hasNext())
-		{
-			Map.Entry entry = (Map.Entry)entries.next();
-			Window factory = (Window)entry.getValue();
-			if(factory.plugin == plugin)
-				entries.remove();
-		}
+		dockableWindowFactories.entrySet().removeIf(entry -> plugin == entry.getValue().plugin);
 	} //}}}
 
 	//{{{ cacheDockableWindows() method
@@ -215,14 +203,14 @@
 		{
 			this.plugin = plugin;
 			this.uri = uri;
-			stateStack = new Stack<String>();
+			stateStack = new Stack<>();
 			actions = true;
 			movable = MOVABLE_DEFAULT;
 
 			code = new StringBuilder();
-			cachedDockableNames = new LinkedList<String>();
-			cachedDockableActionFlags = new LinkedList<Boolean>();
-			cachedDockableMovableFlags = new LinkedList<Boolean>();
+			cachedDockableNames = new LinkedList<>();
+			cachedDockableActionFlags = new LinkedList<>();
+			cachedDockableMovableFlags = new LinkedList<>();
 		} //}}}
 
 		//{{{ resolveEntity() method
@@ -273,10 +261,8 @@
 					registerDockableWindow(plugin,
 						dockableName,code.toString(),actions, movable);
 					cachedDockableNames.add(dockableName);
-					cachedDockableActionFlags.add(
-						Boolean.valueOf(actions));
-					cachedDockableMovableFlags.add(
-							Boolean.valueOf(movable));
+					cachedDockableActionFlags.add(actions);
+					cachedDockableMovableFlags.add(movable);
 					// make default be true for the next
 					// action
 					actions = true;
@@ -338,7 +324,7 @@
 			int i = 0;
 			for (Boolean value : list)
 			{
-				returnValue[i++] = value.booleanValue();
+				returnValue[i++] = value;
 			}
 
 			return returnValue;
@@ -347,21 +333,21 @@
 		//{{{ Private members
 
 		//{{{ Instance variables
-		private PluginJAR plugin;
+		private final PluginJAR plugin;
 		// What is the purpose of this?
 		private URL uri;
 
-		private java.util.List<String> cachedDockableNames;
-		private java.util.List<Boolean> cachedDockableActionFlags;
-		private java.util.List<Boolean> cachedDockableMovableFlags;
+		private final java.util.List<String> cachedDockableNames;
+		private final java.util.List<Boolean> cachedDockableActionFlags;
+		private final java.util.List<Boolean> cachedDockableMovableFlags;
 
 		private String dockableName;
-		private StringBuilder code;
+		private final StringBuilder code;
 		private boolean actions;
 		private boolean movable;
 		static final boolean MOVABLE_DEFAULT = false;
 
-		private Stack<String> stateStack;
+		private final Stack<String> stateStack;
 		//}}}
 
 		//{{{ pushElement() method
@@ -397,7 +383,7 @@
 		String code;
 		boolean loaded;
 		boolean movable;
-		boolean isBeingCreated = false;
+		boolean isBeingCreated;
 
 		//{{{ Window constructor
 		Window(PluginJAR plugin, String name, String code,
@@ -498,16 +484,17 @@
 		//{{{ OpenAction class
 		class OpenAction extends EditAction
 		{
-			private String dockable;
+			private final String dockable;
 
 			//{{{ OpenAction constructor
 			OpenAction(String name)
 			{
 				super(name);
-				this.dockable = name;
+				dockable = name;
 			} //}}}
 
 			//{{{ invoke() method
+			@Override
 			public void invoke(View view)
 			{
 				view.getDockableWindowManager()
@@ -526,16 +513,17 @@
 		//{{{ ToggleAction class
 		class ToggleAction extends EditAction
 		{
-			private String dockable;
+			private final String dockable;
 
 			//{{{ ToggleAction constructor
 			ToggleAction(String name)
 			{
 				super(name + "-toggle");
-				this.dockable = name;
+				dockable = name;
 			} //}}}
 
 			//{{{ invoke() method
+			@Override
 			public void invoke(View view)
 			{
 				view.getDockableWindowManager()
@@ -561,16 +549,17 @@
 		//{{{ FloatAction class
 		class FloatAction extends EditAction
 		{
-			private String dockable;
+			private final String dockable;
 
 			//{{{ FloatAction constructor
 			FloatAction(String name)
 			{
 				super(name + "-float");
-				this.dockable = name;
+				dockable = name;
 			} //}}}
 
 			//{{{ invoke() method
+			@Override
 			public void invoke(View view)
 			{
 				view.getDockableWindowManager()
Modified: jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManager.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManager.java	2021-02-13 18:09:26 UTC (rev 25419)
+++ jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManager.java	2021-03-13 08:32:47 UTC (rev 25420)
@@ -5,7 +5,6 @@
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.io.File;
-import java.io.FilenameFilter;
 import java.util.*;
 import java.util.Map.Entry;
 
@@ -434,12 +433,7 @@
 	// {{{ addPluginDockable
 	private void addPluginDockable(PluginJAR plugin, String name)
 	{
-		Set<String> dockables = plugins.get(plugin);
-		if (dockables == null)
-		{
-			dockables = new HashSet<String>();
-			plugins.put(plugin, dockables);
-		}
+		Set<String> dockables = plugins.computeIfAbsent(plugin, k -> new HashSet<>());
 		dockables.add(name);
 	}
 	// }}}
@@ -560,7 +554,7 @@
 		{
 			String oldPosition = positions.get(dockable);
 			String newPosition = getDockablePosition(dockable);
-			if (oldPosition == null || !newPosition.equals(oldPosition))
+			if (!newPosition.equals(oldPosition))
 			{
 				positions.put(dockable, newPosition);
 				dockingPositionChanged(dockable, oldPosition, newPosition);
@@ -678,10 +672,10 @@
 		private List<Key> parseShortcut(String shortcut)
 		{
 			String [] parts = shortcut.split("\\s+");
-			List<Key> keys = new ArrayList<Key>(parts.length);
+			List<Key> keys = new ArrayList<>(parts.length);
 			for (String part: parts)
 			{
-				if (part.length() > 0)
+				if (!part.isEmpty())
 					keys.add(KeyEventTranslator.parseKey(part));
 			}
 			return keys;
@@ -704,19 +698,15 @@
 		{
 		}
 
-		public String [] getSavedLayouts()
+		public String[] getSavedLayouts()
 		{
 			String layoutDir = getLayoutDirectory();
 			if (layoutDir == null)
 				return null;
 			File dir = new File(layoutDir);
-			File[] files = dir.listFiles(new FilenameFilter()
-			{
-				public boolean accept(File dir, String name)
-				{
-					return name.endsWith(".xml");
-				}
-			});
+			File[] files = dir.listFiles((dir1, name) -> name.endsWith(".xml"));
+			if (files == null)
+				return null;
 			String[] layouts = new String[files.length];
 			for (int i = 0; i < files.length; i++)
 				layouts[i] = fileToLayout(files[i].getName());
Modified: jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManagerProvider.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManagerProvider.java	2021-02-13 18:09:26 UTC (rev 25419)
+++ jEdit/trunk/org/gjt/sp/jedit/gui/DockableWindowManagerProvider.java	2021-03-13 08:32:47 UTC (rev 25420)
@@ -4,7 +4,6 @@
 import org.gjt.sp.jedit.View.ViewConfig;
 import org.gjt.sp.jedit.gui.DockableWindowManager.DockingLayout;
 
-
 /** jEdit's classic dockable window manager, turned into a "provider" service.
    *
    *  @author Shlomy Reinstein
@@ -12,15 +11,15 @@
    */
 public class DockableWindowManagerProvider implements DockingFrameworkProvider
 {
-	public DockableWindowManager create(View view,
-			DockableWindowFactory instance, ViewConfig config)
+	@Override
+	public DockableWindowManager create(View view, DockableWindowFactory instance, ViewConfig config)
 	{
 		return new DockableWindowManagerImpl(view, instance, config);
 	}
 
+	@Override
 	public DockingLayout createDockingLayout()
 	{
 		return new DockableWindowManagerImpl.DockableWindowConfig();
 	}
-
 }
Modified: jEdit/trunk/org/gjt/sp/jedit/gui/DockingLayoutManager.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/gui/DockingLayoutManager.java	2021-02-13 18:09:26 UTC (rev 25419)
+++ jEdit/trunk/org/gjt/sp/jedit/gui/DockingLayoutManager.java	2021-03-13 08:32:47 UTC (rev 25420)
@@ -2,7 +2,9 @@
 
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Objects;
 
+import javax.annotation.Nonnull;
 import javax.swing.JOptionPane;
 
 import org.gjt.sp.jedit.ActionSet;
@@ -20,6 +22,7 @@
 import org.gjt.sp.jedit.msg.EditPaneUpdate;
 import org.gjt.sp.jedit.msg.ViewUpdate;
 import org.gjt.sp.jedit.options.DockingOptionPane;
+import org.gjt.sp.util.StandardUtilities;
 
 /** Saves and loads dockable layouts to disk
     @author Shlomy Reinstein
@@ -35,12 +38,13 @@
 	private static final String SAVE_LAYOUT_MESSAGE = "save-layout.message";
 	private static ActionSet actions;
 	private static DockingLayoutManager instance;
-	private Map<View, String> currentMode;
+	private final Map<View, String> currentMode;
 
 	private DockingLayoutManager()
 	{
-		currentMode = new HashMap<View, String>();
+		currentMode = new HashMap<>();
 	}
+
 	private static boolean save(View view, String layoutName)
 	{
 		if (jEdit.getSettingsDirectory() == null)
@@ -114,7 +118,7 @@
 		if (docking != null)
 			layouts = docking.getSavedLayouts();
 		if (layouts == null)
-			return new String[0];
+			return StandardUtilities.EMPTY_STRING_ARRAY;
 		return layouts;
 	}
 
@@ -150,7 +154,7 @@
 	{
 		private static final String LOAD_PREFIX = "load-";
 
-		public LoadPerspectiveAction(String layoutName)
+		LoadPerspectiveAction(String layoutName)
 		{
 			super(LOAD_PREFIX + layoutName, new String[] { layoutName });
 			jEdit.setTemporaryProperty(LOAD_PREFIX + layoutName + ".label", LOAD_PREFIX + layoutName);
@@ -163,7 +167,7 @@
 		}
 	}
 
-	private boolean canChangeEditMode(EBMessage message)
+	private static boolean canChangeEditMode(EBMessage message)
 	{
 		if (message instanceof BufferUpdate)
 		{
@@ -189,6 +193,7 @@
 		return false;
 	}
 
+	@Override
 	public void handleMessage(EBMessage message)
 	{
 		boolean autoLoadModeLayout = jEdit.getBooleanProperty(
@@ -214,10 +219,8 @@
 			return;
 		String newMode = getCurrentEditMode(view);
 		String mode = currentMode.get(view);
-		boolean sameMode =
-			(mode == null && newMode == null) ||
-			(mode != null && mode.equals(newMode));
-		if (! sameMode)
+		boolean sameMode = Objects.equals(mode, newMode);
+		if (!sameMode)
 		{
 			boolean autoSaveModeLayout = jEdit.getBooleanProperty(
 				DockingOptionPane.AUTO_SAVE_MODE_LAYOUT_PROP, false);
@@ -228,7 +231,7 @@
 		}
 	}
 
-	private String getCurrentEditMode(View view)
+	private static String getCurrentEditMode(View view)
 	{
 		Buffer buffer = view.getBuffer();
 		if (buffer == null)
@@ -241,19 +244,15 @@
 
 	private static final String GLOBAL_MODE = "DEFAULT";
 
-	private void saveModeLayout(View view, String mode)
+	private static void saveModeLayout(View view, String mode)
 	{
 		String modeLayout = getModePerspective(mode);
-		if (modeLayout == null)
-			return;
 		save(view, modeLayout);
 	}
 
-	private void loadModeLayout(View view, String mode)
+	private static void loadModeLayout(View view, String mode)
 	{
 		String modeLayout = getModePerspective(mode);
-		if (modeLayout == null)
-			return;
 		load(view, modeLayout);
 	}
 
@@ -261,8 +260,8 @@
 	{
 		if (view == null)
 			return;
-		String mode = instance.getCurrentEditMode(view);
-		instance.loadModeLayout(view, mode);
+		String mode = DockingLayoutManager.getCurrentEditMode(view);
+		loadModeLayout(view, mode);
 	}
 
 	public static void saveCurrentModeLayout(View view)
@@ -269,11 +268,12 @@
 	{
 		if (view == null)
 			return;
-		String mode = instance.getCurrentEditMode(view);
-		instance.saveModeLayout(view, mode);
+		String mode = DockingLayoutManager.getCurrentEditMode(view);
+		saveModeLayout(view, mode);
 	}
 
-	private String getModePerspective(String mode)
+	@Nonnull
+	private static String getModePerspective(String mode)
 	{
 		if (mode == null)
 			mode = GLOBAL_MODE;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |