From c0abf6705902d2dcb19b78e684c46a1f4cf489b8 Mon Sep 17 00:00:00 2001 From: hneemann Date: Sun, 17 Apr 2016 14:10:14 +0200 Subject: [PATCH] added some documentation --- .../de/neemann/gui/ConfirmDialogBuilder.java | 10 +++-- .../java/de/neemann/gui/ErrorMessage.java | 37 ++++++++++++++++- src/main/java/de/neemann/gui/InfoDialog.java | 9 ++-- src/main/java/de/neemann/gui/StringUtils.java | 19 ++++++++- .../java/de/neemann/gui/ToolTipAction.java | 41 ++++++++++++++++++- 5 files changed, 105 insertions(+), 11 deletions(-) diff --git a/src/main/java/de/neemann/gui/ConfirmDialogBuilder.java b/src/main/java/de/neemann/gui/ConfirmDialogBuilder.java index 417a114e1..ac8e78c2b 100644 --- a/src/main/java/de/neemann/gui/ConfirmDialogBuilder.java +++ b/src/main/java/de/neemann/gui/ConfirmDialogBuilder.java @@ -98,15 +98,19 @@ public class ConfirmDialogBuilder { */ public int show(Component parent) { Object[] options; - if (cancle == null) + int optionType; + if (cancle == null) { options = new Object[]{yes, no}; - else + optionType = JOptionPane.YES_NO_OPTION; + } else { options = new Object[]{yes, no, cancle}; + optionType = JOptionPane.YES_NO_CANCEL_OPTION; + } return JOptionPane.showOptionDialog(parent, message, title, - cancle == null ? JOptionPane.YES_NO_OPTION : JOptionPane.YES_NO_CANCEL_OPTION, + optionType, JOptionPane.QUESTION_MESSAGE, null, options, diff --git a/src/main/java/de/neemann/gui/ErrorMessage.java b/src/main/java/de/neemann/gui/ErrorMessage.java index cd335ec8a..28f8369cd 100644 --- a/src/main/java/de/neemann/gui/ErrorMessage.java +++ b/src/main/java/de/neemann/gui/ErrorMessage.java @@ -4,21 +4,38 @@ import javax.swing.*; import java.awt.*; /** - * Created by hneemann on 09.02.14. + * Used to show error messages. + * Implements runnable so you can apply this class directly to {@link SwingUtilities#invokeLater(Runnable)} + * + * @author hneemann on 09.02.14. */ public class ErrorMessage implements Runnable { private final StringBuilder message; private Component component; + /** + * Creates a new instance + */ public ErrorMessage() { this(""); } + /** + * Creates anew instance + * + * @param message the message to show + */ public ErrorMessage(String message) { this.message = new StringBuilder(message); } + /** + * Adds a cause to the message + * + * @param e the cause + * @return this for call chaining + */ public ErrorMessage addCause(Throwable e) { e.printStackTrace(); @@ -28,15 +45,33 @@ public class ErrorMessage implements Runnable { return this; } + /** + * Shows the error message + * + * @return this for call chaining + */ public ErrorMessage show() { return show(null); } + /** + * Shows the error message + * + * @param parent the parent + * @return this for call chaining + */ public ErrorMessage show(Component parent) { JOptionPane.showMessageDialog(parent, message.toString(), "Error", JOptionPane.ERROR_MESSAGE); return this; } + /** + * Sets a parents component. + * Used if supplied to {@link SwingUtilities#invokeLater(Runnable)} + * + * @param component the parent + * @return this for call chaining + */ public ErrorMessage setComponent(Component component) { this.component = component; return this; diff --git a/src/main/java/de/neemann/gui/InfoDialog.java b/src/main/java/de/neemann/gui/InfoDialog.java index 73c41bd31..0055e5214 100644 --- a/src/main/java/de/neemann/gui/InfoDialog.java +++ b/src/main/java/de/neemann/gui/InfoDialog.java @@ -98,7 +98,7 @@ public final class InfoDialog { private final HashMap manifest; private final URL url; - public Manifest(URL url) throws IOException { + Manifest(URL url) throws IOException { this.url = url; manifest = new HashMap(); BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8")); @@ -135,10 +135,9 @@ public final class InfoDialog { @Override public String toString() { - return "Manifest{" + - "manifest=" + manifest + - ", url=" + url + - '}'; + return "Manifest{" + + "manifest=" + manifest + + ", url=" + url + '}'; } } } diff --git a/src/main/java/de/neemann/gui/StringUtils.java b/src/main/java/de/neemann/gui/StringUtils.java index b40842b32..b7d385757 100644 --- a/src/main/java/de/neemann/gui/StringUtils.java +++ b/src/main/java/de/neemann/gui/StringUtils.java @@ -1,9 +1,20 @@ package de.neemann.gui; /** + * Some helper functions concerning strings */ -public class StringUtils { +public final class StringUtils { + private StringUtils() { + } + + /** + * Adds a list to a {@link StringBuilder} + * + * @param sb the StringBuilder + * @param i the list + * @param separator the separator to use + */ public static void addList(StringBuilder sb, Iterable i, String separator) { boolean first = true; for (Object o : i) { @@ -15,6 +26,12 @@ public class StringUtils { } } + /** + * Creates a exception message + * + * @param e the {@link Throwable} instance + * @return the message + */ public static String getExceptionMessage(Throwable e) { StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/de/neemann/gui/ToolTipAction.java b/src/main/java/de/neemann/gui/ToolTipAction.java index ed15513ea..13eb8cea8 100644 --- a/src/main/java/de/neemann/gui/ToolTipAction.java +++ b/src/main/java/de/neemann/gui/ToolTipAction.java @@ -4,31 +4,58 @@ import javax.swing.*; import java.awt.*; /** - * Created by hneemann on 06.03.15. + * Action to handle tool tips. + * C@author hneemann on 06.03.15. */ public abstract class ToolTipAction extends AbstractAction { private Icon icon; private String toolTipText; + /** + * Creates a new instance + * + * @param name the name of the action + */ public ToolTipAction(String name) { super(name); } + /** + * Creates a new instance + * + * @param name the name of the action + * @param icon the icon + */ public ToolTipAction(String name, Icon icon) { super(name, icon); this.icon = icon; } + /** + * Sets the tool tip text + * + * @param text the tool tip text + * @return this for call chaining + */ public ToolTipAction setToolTip(String text) { this.toolTipText = text; return this; } + /** + * Sets the activated state for this action + * + * @param newValue the new state + * @return this for call chaining + */ public ToolTipAction setActive(boolean newValue) { super.setEnabled(newValue); return this; } + /** + * @return a JButton associated with this action + */ public JButton createJButton() { JButton b = new JButton(this); if (toolTipText != null) { @@ -37,6 +64,9 @@ public abstract class ToolTipAction extends AbstractAction { return b; } + /** + * @return a JButton associated with this action, contains only the icon + */ public JButton createJButtonNoText() { JButton b = new JButton(this); if (toolTipText != null) { @@ -48,12 +78,18 @@ public abstract class ToolTipAction extends AbstractAction { return b; } + /** + * @return a JButton associated with this action, contains only the icon + */ public JButton createJButtonNoTextSmall() { JButton b = createJButtonNoText(); b.setPreferredSize(new Dimension(icon.getIconWidth() + 4, icon.getIconHeight() + 4)); return b; } + /** + * @return a JMenuItem associated with this action + */ public JMenuItem createJMenuItem() { JMenuItem i = new JMenuItem(this); if (toolTipText != null) { @@ -62,6 +98,9 @@ public abstract class ToolTipAction extends AbstractAction { return i; } + /** + * @return a JMenuItem associated with this action, contains no icon + */ public JMenuItem createJMenuItemNoIcon() { JMenuItem i = createJMenuItem(); i.setIcon(null);