Skip to content

Commit

Permalink
fix: tweak spotbugs errors
Browse files Browse the repository at this point in the history
  • Loading branch information
miurahr committed Mar 23, 2024
1 parent 13dae6b commit 45dfaf0
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ public void actionPerformed(ActionEvent e) {
//addTab(key.getName(), key.getIcon(), (Component)dc, key.getTooltip());
addTab("", smartIcon, (Component) dc, key.getTooltip());
//addTab(key.getName(),smartIcon, (Component) dc, key.getTooltip());
tab = getTabCount() - 1;
// tab = getTabCount() - 1;
} else {
//insertTab(key.getName(), key.getIcon(), (Component)dc, key.getTooltip(), tab);
insertTab("", smartIcon, (Component) dc, key.getTooltip(), tab);
Expand Down
23 changes: 10 additions & 13 deletions src/main/java/com/vlsolutions/swing/docking/DockingContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@

import java.awt.Window;
import java.awt.event.WindowEvent;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -243,16 +241,15 @@ public DockableState[] getDockables() {
* @see #readXML(InputStream)
* */
public void writeXML(OutputStream stream) throws IOException {
PrintWriter out = new PrintWriter(stream);
out.println("<?xml version=\"1.0\"?>");
out.println("<VLDocking version=\"2.1\">");
for(int i = 0; i < desktops.size(); i++) {
DockingDesktop desktop = (DockingDesktop) desktops.get(i);
desktop.writeDesktopNode(out);
try (PrintWriter out = new PrintWriter(new OutputStreamWriter(stream, StandardCharsets.UTF_8))) {
out.println("<?xml version=\"1.0\"?>");
out.println("<VLDocking version=\"2.1\">");
for (DockingDesktop dockingDesktop : desktops) {
dockingDesktop.writeDesktopNode(out);
}
out.println("</VLDocking>");
out.flush();
}
out.println("</VLDocking>");

out.flush();
}

/** Reads an XML encoded stream as the new desktop configuration.
Expand Down
93 changes: 51 additions & 42 deletions src/main/java/com/vlsolutions/swing/docking/DockingDesktop.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@
import java.awt.event.WindowListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
Expand Down Expand Up @@ -1315,31 +1312,29 @@ private void splitTab(Component base, TabbedDockableContainer tdc,
DockingConstants.Split position) {
// should be used only when drag and dropping

if (base == null)
if (base == null) {
throw new NullPointerException("base");
Dockable firstDockable = tdc.getDockableAt(0);
DockableState currentState = getDockableState(firstDockable);
boolean stateChange = false;
if (currentState.isFloating()) {
removePreviousFloatingStates(tdc); // clear reference of the
// previous state
stateChange = true;
}

Container oldContainer = (Container) tdc;
int oldWidth = 0;
int oldHeight = 0;
if (oldContainer != null) {
int oldWidth;
int oldHeight;
boolean stateChange = false;
if (tdc instanceof Container) {
Container oldContainer = (Container) tdc;
oldWidth = oldContainer.getWidth();
oldHeight = oldContainer.getHeight();
DockableState currentState = getDockableState(tdc.getDockableAt(0));
if (currentState.isFloating()) {
removePreviousFloatingStates(tdc); // clear reference of the
// previous state
stateChange = true;
}
} else {
oldWidth = base.getWidth() / 2;
oldWidth = base.getWidth() / 2;
oldHeight = base.getHeight() / 2;
}

DockableContainer dockableContainer = tdc;

// create a new splitcontainer that will replace baseDockable's
// create a new splitcontainer that will replace baseDockable's
// container
SplitContainer split;
if (position == DockingConstants.SPLIT_TOP
Expand All @@ -1358,10 +1353,10 @@ private void splitTab(Component base, TabbedDockableContainer tdc,

if (position == DockingConstants.SPLIT_TOP
|| position == DockingConstants.SPLIT_LEFT) {
split.setLeftComponent((Component) dockableContainer);
split.setLeftComponent((Component) tdc);
split.setRightComponent(base);
} else {
split.setRightComponent((Component) dockableContainer);
split.setRightComponent((Component) tdc);
split.setLeftComponent(base);
}
} else {
Expand All @@ -1372,14 +1367,14 @@ private void splitTab(Component base, TabbedDockableContainer tdc,
split);
if (position == DockingConstants.SPLIT_TOP
|| position == DockingConstants.SPLIT_LEFT) {
split.setLeftComponent((Component) dockableContainer);
split.setLeftComponent((Component) tdc);
split.setRightComponent(dockingPanelChild);
} else {
split.setRightComponent((Component) dockableContainer);
split.setRightComponent((Component) tdc);
split.setLeftComponent(dockingPanelChild);
}
} else { // dockingpanel is empty
dockingPanel.add((Component) dockableContainer);
dockingPanel.add((Component) tdc);
}

}
Expand Down Expand Up @@ -1832,8 +1827,12 @@ public void restore(final Dockable dockable) {

DockableState currentState = getDockableState(dockable);
@SuppressWarnings("null")
boolean stateChange = currentState != null
|| currentState.isMaximized();
boolean stateChange;
if (currentState == null) {
stateChange = false;
} else {
stateChange = currentState.isMaximized();
}
DockableState newState = new DockableState(this, dockable,
DockableState.Location.DOCKED);
DockableState.Location currentLocation = getLocation(currentState);
Expand Down Expand Up @@ -3011,17 +3010,26 @@ void writeDesktopNode(PrintWriter out) throws IOException {

Window desktopWindow = SwingUtilities.getWindowAncestor(this);
Point windowLocation;
if (desktopWindow != null) {
windowLocation = desktopWindow.getLocation();
} else {
windowLocation = new Point(); // fail safe
}

out.println("<DockingDesktop name=\"" + desktopName + "\">");
out.println("<DockingPanel x=\"" + (int) windowLocation.getX()
+ "\" y=\"" + (int) windowLocation.getY() + "\" width=\""
+ desktopWindow.getWidth() + "\" height=\""
+ desktopWindow.getHeight() + "\"" + ">");
long x;
long y;
int width;
int height;
if (desktopWindow == null) {
x = 0;
y = 0;
width = 0;
height = 0;
} else {
windowLocation = desktopWindow.getLocation();
x = Math.round(windowLocation.getX());
y = Math.round(windowLocation.getY());
width = desktopWindow.getWidth();
height = desktopWindow.getHeight();
}

out.println("<DockingDesktop name=\"" + desktopName + "\">");
out.println("<DockingPanel x=\"" + x + "\" y=\"" + y
+ "\" width=\"" + width + "\" height=\"" + height + "\"" + ">");
if (dockingPanel.getComponentCount() > 0) {
// only one top component (DockableContainer or SplitContainer)
xmlWriteComponent(dockingPanel.getComponent(0), out);
Expand All @@ -3037,9 +3045,9 @@ void writeDesktopNode(PrintWriter out) throws IOException {

out.println("</DockingPanel>");

for (int i = 0; i < borderPanes.length; i++) {
xmlWriteBorder(borderPanes[i], out);
}
for (AutoHideButtonPanel borderPane : borderPanes) {
xmlWriteBorder(borderPane, out);
}

// finish with the floating dockables
xmlWriteFloating(out);
Expand Down Expand Up @@ -3072,11 +3080,12 @@ private void xmlWriteFloating(PrintWriter out) throws IOException {

Window desktopWindow = SwingUtilities.getWindowAncestor(this);
Point windowLocation;
/*
if (desktopWindow != null) {
windowLocation = desktopWindow.getLocation();
} else {
windowLocation = new Point(); // fail safe
}
}*/

ArrayList<Dockable> floatingDockables = context.getDockablesByState(
this, DockableState.Location.FLOATING);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
*/
public class AutoHideButtonPanelUI extends BasicPanelUI implements PropertyChangeListener {

private static AutoHideButtonPanelUI instance = new AutoHideButtonPanelUI();
private static final AutoHideButtonPanelUI instance = new AutoHideButtonPanelUI();

public static ComponentUI createUI(JComponent c) {
return instance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*/
public class AutoHideButtonUI extends BasicLabelUI implements PropertyChangeListener {

protected static AutoHideButtonUI instance = new AutoHideButtonUI();
protected static final AutoHideButtonUI instance = new AutoHideButtonUI();

public AutoHideButtonUI() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,7 +752,7 @@ public void installDockViewTitleBarSettings() {
UIManager.put("DockViewTitleBarUI",
"com.vlsolutions.swing.docking.ui.DockViewTitleBarUI");

UIManager.put("DockViewTitleBar.height", new Integer(20));
UIManager.put("DockViewTitleBar.height", 20);
UIManager.put("DockViewTitleBar.closeButtonText",
UIManager.getString("InternalFrameTitlePane.closeButtonText"));
UIManager.put("DockViewTitleBar.minimizeButtonText", UIManager
Expand Down Expand Up @@ -793,7 +793,7 @@ public void installDockViewTitleBarSettings() {
public void installSplitContainerSettings() {
UIManager.put("DockingSplitPaneUI",
"com.vlsolutions.swing.docking.ui.DockingSplitPaneUI");
UIManager.put("SplitContainer.dividerSize", new Integer(4));
UIManager.put("SplitContainer.dividerSize", 4);
UIManager.put("SplitContainer.isResizingEnabled", Boolean.TRUE); // 2007/08/11

}
Expand All @@ -802,8 +802,7 @@ public void installSplitContainerSettings() {
public void installTabbedContainerSettings() {
@SuppressWarnings("unused")
final String prefix = "/com/vldocking/swing/docking/";
UIManager.put("TabbedDockableContainer.tabPlacement", new Integer(
SwingConstants.TOP));
UIManager.put("TabbedDockableContainer.tabPlacement", SwingConstants.TOP);

UIManager.put("DockTabbedPane.closeButtonText",
UIManager.getString("InternalFrameTitlePane.closeButtonText"));
Expand Down Expand Up @@ -832,8 +831,8 @@ public void installTabbedContainerSettings() {
public void installCloseableTabs() {
// this one is already provided by the look and feel
// UIManager.put("TabbedPane.textIconGap", new Integer(4));
UIManager.put("TabbedPane.otherIconsGap", new Integer(8));
UIManager.put("TabbedPane.inBetweenOtherIconsGap", new Integer(4));
UIManager.put("TabbedPane.otherIconsGap", 8);
UIManager.put("TabbedPane.inBetweenOtherIconsGap", 4);
UIManager.put("TabbedPane.alternateTabIcons", Boolean.FALSE);
}

Expand Down Expand Up @@ -887,6 +886,9 @@ public void installIcons() {
UIManager.put("DockViewTitleBar.close", closeIcon);
UIManager.put("DockViewTitleBar.close.rollover", closeRolloverIcon);
UIManager.put("DockViewTitleBar.close.pressed", closePressedIcon);
UIManager.put("DockViewTitleBar.closeTab", closeTabIcon);
UIManager.put("DockViewTitleBar.closeTab.rollover", closeTabRolloverIcon);
UIManager.put("DockViewTitleBar.closeTab.pressed", closeTabPressedIcon);

UIManager.put("DockViewTitleBar.dock", new ImageIcon(getClass()
.getResource(prefix + "dock16v2.png")));
Expand Down Expand Up @@ -952,7 +954,7 @@ public void installIcons() {
public void installAccelerators() {

int MENU_SHORTCUT_MASK = Toolkit.getDefaultToolkit()
.getMenuShortcutKeyMask();
.getMenuShortcutKeyMaskEx();
// this returns CTRL_MASK or META_MASK depending on the platform
// (win/mac os)

Expand All @@ -961,7 +963,7 @@ public void installAccelerators() {
// toggle maximize/restore
UIManager
.put("DockingDesktop.maximizeActionAccelerator", KeyStroke
.getKeyStroke(KeyEvent.VK_ESCAPE, KeyEvent.SHIFT_MASK));
.getKeyStroke(KeyEvent.VK_ESCAPE, KeyEvent.SHIFT_DOWN_MASK));

// toggle autohide/dock
UIManager.put("DockingDesktop.dockActionAccelerator", KeyStroke
Expand All @@ -975,7 +977,7 @@ public void installAccelerators() {
/** installs the DockinDesktop related properties */
public void installDesktopSettings() {
UIManager.put("DockingDesktop.notificationColor", Color.ORANGE);
UIManager.put("DockingDesktop.notificationBlinkCount", new Integer(5));
UIManager.put("DockingDesktop.notificationBlinkCount", 5);
UIManager.put(
"DragControler.stopDragCursor",
new ImageIcon(getClass().getResource(
Expand Down
Loading

0 comments on commit 45dfaf0

Please sign in to comment.