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) {
|
||||
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,
|
||||
|
@ -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;
|
||||
|
@ -98,7 +98,7 @@ public final class InfoDialog {
|
||||
private final HashMap<String, String> manifest;
|
||||
private final URL url;
|
||||
|
||||
public Manifest(URL url) throws IOException {
|
||||
Manifest(URL url) throws IOException {
|
||||
this.url = url;
|
||||
manifest = new HashMap<String, String>();
|
||||
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 + '}';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user