desktops = new ArrayList<>();
/** Creates a workspace with a single default WSDesktop */
public Workspace() {
@@ -79,16 +75,16 @@ public int getDesktopCount() {
/** Returns the index-th desktop contained */
public WSDesktop getDesktop(int index) {
- return (WSDesktop) desktops.get(index);
+ return desktops.get(index);
}
/** Returns a desktop identified by its name or null if not found */
public WSDesktop getDesktop(String desktopName) {
if(desktops.size() == 1) {
- return (WSDesktop) desktops.get(0);
+ return desktops.get(0);
}
for(int i = 0; i < desktops.size(); i++) {
- WSDesktop d = (WSDesktop) desktops.get(i);
+ WSDesktop d = desktops.get(i);
if(d.getDesktopName().equals(desktopName)) {
return d;
}
@@ -102,30 +98,26 @@ public WSDesktop getDesktop(String desktopName) {
* by this workspace layout.
*/
public void apply(DockingContext dockingContext) throws WorkspaceException {
- ByteArrayOutputStream outb = new ByteArrayOutputStream();
- PrintWriter out = new PrintWriter(outb);
- out.println("");
- out.println("");
- for(int i = 0; i < desktops.size(); i++) {
- WSDesktop desktop = (WSDesktop) desktops.get(i);
- desktop.writeDesktopNode(out);
- }
- out.println("");
- out.close();
- byte[] bytes = outb.toByteArray();
- //System.out.println(new String(bytes));
- ByteArrayInputStream is = new ByteArrayInputStream(bytes);
- try {
- dockingContext.readXML(is);
- } catch(Exception ex) {
- throw new WorkspaceException(ex);
- } finally {
- try {
- is.close();
- } catch(Exception ignore) {
+ try (ByteArrayOutputStream outb = new ByteArrayOutputStream()) {
+ try (PrintWriter out = new PrintWriter(new OutputStreamWriter(outb, StandardCharsets.UTF_8))) {
+ out.println("");
+ out.println("");
+ for (WSDesktop desktop : desktops) {
+ desktop.writeDesktopNode(out);
+ }
+ out.println("");
+ }
+ byte[] bytes = outb.toByteArray();
+ //System.out.println(new String(bytes));
+ try (ByteArrayInputStream is = new ByteArrayInputStream(bytes)) {
+ dockingContext.readXML(is);
+ } catch (Exception ex) {
+ throw new WorkspaceException(ex);
}
- }
- }
+ } catch (IOException ex) {
+ throw new WorkspaceException(ex);
+ }
+ }
/** Loads and configures this workspace from a given docking context.
*
@@ -158,17 +150,16 @@ public void loadFrom(DockingContext context) throws WorkspaceException {
*
* @see #readXML(InputStream)
* */
- public void writeXML(OutputStream stream) throws IOException {
- PrintWriter out = new PrintWriter(stream);
- out.println("");
- out.println("");
- for(int i = 0; i < desktops.size(); i++) {
- WSDesktop desktop = (WSDesktop) desktops.get(i);
- desktop.writeDesktopNode(out);
+ public void writeXML(OutputStream stream) {
+ try (PrintWriter out = new PrintWriter(new OutputStreamWriter(stream, StandardCharsets.UTF_8))) {
+ out.println("");
+ out.println("");
+ for (WSDesktop desktop : desktops) {
+ desktop.writeDesktopNode(out);
+ }
+ out.println("");
+ out.flush();
}
- out.println("");
-
- out.flush();
}
public void readXML(InputStream in) throws ParserConfigurationException, IOException, SAXException {
@@ -176,7 +167,7 @@ public void readXML(InputStream in) throws ParserConfigurationException, IOExcep
// remove all dockable states
for(int i = 0; i < desktops.size(); i++) {
- WSDesktop desk = (WSDesktop) desktops.get(i);
+ WSDesktop desk = desktops.get(i);
desk.clear();
}
diff --git a/src/main/java/com/vlsolutions/swing/toolbars/ToolBarGripperUI.java b/src/main/java/com/vlsolutions/swing/toolbars/ToolBarGripperUI.java
index 10b99d4..9c10091 100644
--- a/src/main/java/com/vlsolutions/swing/toolbars/ToolBarGripperUI.java
+++ b/src/main/java/com/vlsolutions/swing/toolbars/ToolBarGripperUI.java
@@ -34,10 +34,10 @@
public class ToolBarGripperUI extends ComponentUI {
/** the "grip" (an alpha blended dot image, 3*3 pixels, hightlighted underneath ) */
- protected static Image gripImage = new ImageIcon(ToolBarGripperUI.class.getResource("gripper.png")).getImage();
+ protected static final Image gripImage = new ImageIcon(ToolBarGripperUI.class.getResource("gripper.png")).getImage();
- protected static Image gripExpandHImage = new ImageIcon(ToolBarGripperUI.class.getResource("grip_expand_h.png")).getImage();
- protected static Image gripExpandVImage = new ImageIcon(ToolBarGripperUI.class.getResource("grip_expand_v.png")).getImage();
+ protected static final Image gripExpandHImage = new ImageIcon(ToolBarGripperUI.class.getResource("grip_expand_h.png")).getImage();
+ protected static final Image gripExpandVImage = new ImageIcon(ToolBarGripperUI.class.getResource("grip_expand_v.png")).getImage();
/** Constructs a new gripper UI */
public ToolBarGripperUI() {}
diff --git a/src/main/java/com/vlsolutions/swing/toolbars/ToolBarIO.java b/src/main/java/com/vlsolutions/swing/toolbars/ToolBarIO.java
index 3ae87bc..14e10cc 100644
--- a/src/main/java/com/vlsolutions/swing/toolbars/ToolBarIO.java
+++ b/src/main/java/com/vlsolutions/swing/toolbars/ToolBarIO.java
@@ -21,10 +21,8 @@
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
-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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
@@ -55,14 +53,14 @@ public ToolBarIO(ToolBarContainer container) {
*
* @see #readXML(InputStream)
* */
- public void writeXML(OutputStream stream) throws IOException {
- PrintWriter out = new PrintWriter(stream);
- out.println("");
- out.println("");
- xmlWriteContainer(out);
-
- out.println("");
- out.flush();
+ public void writeXML(OutputStream stream) {
+ try (PrintWriter out = new PrintWriter(new OutputStreamWriter(stream, StandardCharsets.UTF_8))) {
+ out.println("");
+ out.println("");
+ xmlWriteContainer(out);
+ out.println("");
+ out.flush();
+ }
}
private void xmlWriteContainer(PrintWriter out) {
diff --git a/src/main/java/com/vlsolutions/swing/toolbars/VLToolBar.java b/src/main/java/com/vlsolutions/swing/toolbars/VLToolBar.java
index 9b2e16c..387db39 100644
--- a/src/main/java/com/vlsolutions/swing/toolbars/VLToolBar.java
+++ b/src/main/java/com/vlsolutions/swing/toolbars/VLToolBar.java
@@ -292,9 +292,6 @@ public Border getDraggedBorder() {
}
private void gripperDragged(MouseEvent e) {
- // where are we ?
- @SuppressWarnings("unused")
- Component gripper = e.getComponent();
ToolBarPanel panel = (ToolBarPanel) this.getParent();
if(! (panel.getParent() instanceof ToolBarContainer)) { //2006/12/01
// this is a safety for users willing to include toolbar panels outside