mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 07:17:13 -04:00
added some documentation
This commit is contained in:
parent
c942415347
commit
c0abf67059
@ -98,15 +98,19 @@ public class ConfirmDialogBuilder {
|
|||||||
*/
|
*/
|
||||||
public int show(Component parent) {
|
public int show(Component parent) {
|
||||||
Object[] options;
|
Object[] options;
|
||||||
if (cancle == null)
|
int optionType;
|
||||||
|
if (cancle == null) {
|
||||||
options = new Object[]{yes, no};
|
options = new Object[]{yes, no};
|
||||||
else
|
optionType = JOptionPane.YES_NO_OPTION;
|
||||||
|
} else {
|
||||||
options = new Object[]{yes, no, cancle};
|
options = new Object[]{yes, no, cancle};
|
||||||
|
optionType = JOptionPane.YES_NO_CANCEL_OPTION;
|
||||||
|
}
|
||||||
|
|
||||||
return JOptionPane.showOptionDialog(parent,
|
return JOptionPane.showOptionDialog(parent,
|
||||||
message,
|
message,
|
||||||
title,
|
title,
|
||||||
cancle == null ? JOptionPane.YES_NO_OPTION : JOptionPane.YES_NO_CANCEL_OPTION,
|
optionType,
|
||||||
JOptionPane.QUESTION_MESSAGE,
|
JOptionPane.QUESTION_MESSAGE,
|
||||||
null,
|
null,
|
||||||
options,
|
options,
|
||||||
|
@ -4,21 +4,38 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
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 {
|
public class ErrorMessage implements Runnable {
|
||||||
|
|
||||||
private final StringBuilder message;
|
private final StringBuilder message;
|
||||||
private Component component;
|
private Component component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*/
|
||||||
public ErrorMessage() {
|
public ErrorMessage() {
|
||||||
this("");
|
this("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates anew instance
|
||||||
|
*
|
||||||
|
* @param message the message to show
|
||||||
|
*/
|
||||||
public ErrorMessage(String message) {
|
public ErrorMessage(String message) {
|
||||||
this.message = new StringBuilder(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) {
|
public ErrorMessage addCause(Throwable e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
@ -28,15 +45,33 @@ public class ErrorMessage implements Runnable {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the error message
|
||||||
|
*
|
||||||
|
* @return this for call chaining
|
||||||
|
*/
|
||||||
public ErrorMessage show() {
|
public ErrorMessage show() {
|
||||||
return show(null);
|
return show(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shows the error message
|
||||||
|
*
|
||||||
|
* @param parent the parent
|
||||||
|
* @return this for call chaining
|
||||||
|
*/
|
||||||
public ErrorMessage show(Component parent) {
|
public ErrorMessage show(Component parent) {
|
||||||
JOptionPane.showMessageDialog(parent, message.toString(), "Error", JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(parent, message.toString(), "Error", JOptionPane.ERROR_MESSAGE);
|
||||||
return this;
|
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) {
|
public ErrorMessage setComponent(Component component) {
|
||||||
this.component = component;
|
this.component = component;
|
||||||
return this;
|
return this;
|
||||||
|
@ -98,7 +98,7 @@ public final class InfoDialog {
|
|||||||
private final HashMap<String, String> manifest;
|
private final HashMap<String, String> manifest;
|
||||||
private final URL url;
|
private final URL url;
|
||||||
|
|
||||||
public Manifest(URL url) throws IOException {
|
Manifest(URL url) throws IOException {
|
||||||
this.url = url;
|
this.url = url;
|
||||||
manifest = new HashMap<String, String>();
|
manifest = new HashMap<String, String>();
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
|
||||||
@ -135,10 +135,9 @@ public final class InfoDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Manifest{" +
|
return "Manifest{"
|
||||||
"manifest=" + manifest +
|
+ "manifest=" + manifest
|
||||||
", url=" + url +
|
+ ", url=" + url + '}';
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
package de.neemann.gui;
|
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) {
|
public static void addList(StringBuilder sb, Iterable<?> i, String separator) {
|
||||||
boolean first = true;
|
boolean first = true;
|
||||||
for (Object o : i) {
|
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) {
|
public static String getExceptionMessage(Throwable e) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
|
@ -4,31 +4,58 @@ import javax.swing.*;
|
|||||||
import java.awt.*;
|
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 {
|
public abstract class ToolTipAction extends AbstractAction {
|
||||||
private Icon icon;
|
private Icon icon;
|
||||||
private String toolTipText;
|
private String toolTipText;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param name the name of the action
|
||||||
|
*/
|
||||||
public ToolTipAction(String name) {
|
public ToolTipAction(String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance
|
||||||
|
*
|
||||||
|
* @param name the name of the action
|
||||||
|
* @param icon the icon
|
||||||
|
*/
|
||||||
public ToolTipAction(String name, Icon icon) {
|
public ToolTipAction(String name, Icon icon) {
|
||||||
super(name, icon);
|
super(name, icon);
|
||||||
this.icon = 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) {
|
public ToolTipAction setToolTip(String text) {
|
||||||
this.toolTipText = text;
|
this.toolTipText = text;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the activated state for this action
|
||||||
|
*
|
||||||
|
* @param newValue the new state
|
||||||
|
* @return this for call chaining
|
||||||
|
*/
|
||||||
public ToolTipAction setActive(boolean newValue) {
|
public ToolTipAction setActive(boolean newValue) {
|
||||||
super.setEnabled(newValue);
|
super.setEnabled(newValue);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a JButton associated with this action
|
||||||
|
*/
|
||||||
public JButton createJButton() {
|
public JButton createJButton() {
|
||||||
JButton b = new JButton(this);
|
JButton b = new JButton(this);
|
||||||
if (toolTipText != null) {
|
if (toolTipText != null) {
|
||||||
@ -37,6 +64,9 @@ public abstract class ToolTipAction extends AbstractAction {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a JButton associated with this action, contains only the icon
|
||||||
|
*/
|
||||||
public JButton createJButtonNoText() {
|
public JButton createJButtonNoText() {
|
||||||
JButton b = new JButton(this);
|
JButton b = new JButton(this);
|
||||||
if (toolTipText != null) {
|
if (toolTipText != null) {
|
||||||
@ -48,12 +78,18 @@ public abstract class ToolTipAction extends AbstractAction {
|
|||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a JButton associated with this action, contains only the icon
|
||||||
|
*/
|
||||||
public JButton createJButtonNoTextSmall() {
|
public JButton createJButtonNoTextSmall() {
|
||||||
JButton b = createJButtonNoText();
|
JButton b = createJButtonNoText();
|
||||||
b.setPreferredSize(new Dimension(icon.getIconWidth() + 4, icon.getIconHeight() + 4));
|
b.setPreferredSize(new Dimension(icon.getIconWidth() + 4, icon.getIconHeight() + 4));
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a JMenuItem associated with this action
|
||||||
|
*/
|
||||||
public JMenuItem createJMenuItem() {
|
public JMenuItem createJMenuItem() {
|
||||||
JMenuItem i = new JMenuItem(this);
|
JMenuItem i = new JMenuItem(this);
|
||||||
if (toolTipText != null) {
|
if (toolTipText != null) {
|
||||||
@ -62,6 +98,9 @@ public abstract class ToolTipAction extends AbstractAction {
|
|||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return a JMenuItem associated with this action, contains no icon
|
||||||
|
*/
|
||||||
public JMenuItem createJMenuItemNoIcon() {
|
public JMenuItem createJMenuItemNoIcon() {
|
||||||
JMenuItem i = createJMenuItem();
|
JMenuItem i = createJMenuItem();
|
||||||
i.setIcon(null);
|
i.setIcon(null);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user