Skip to content

Commit

Permalink
configure the title bar of a Swing text terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
siordache committed Jun 3, 2017
1 parent 0b285e7 commit 5b564ae
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dist/xbin/UserDataCollector.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,9 @@ textio.input.color = yellow

# swing.prompt.color = #22ff88
textio.pane.bgcolor = #002f00
textio.pane.title = User Data Collector
textio.pane.icon.file = data.png
# textio.pane.icon.resource = /your/resource/path/data.png
# textio.pane.icon.url = https://upload.wikimedia.org/wikipedia/commons/4/42/Favicon%28PNG%29.PNG

# jline.ansi.color.mode = indexed
Binary file added dist/xbin/data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions doc/user_guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ Default value: `false`.
|input.underline | ✓ | ✓ | ✓ | `true`, if the input text should be underlined. +
Default value: `false`.
|pane.bgcolor | - | ✓ | ✓ | The background color of the terminal pane.
|pane.icon.file | - | ✓ | - | The path to the file containing the icon to be used in the title bar of the terminal pane.
|pane.icon.resource | - | ✓ | - | The name of the resource containing the icon to be used in the title bar of the terminal pane.
|pane.icon.url | - | ✓ | - | The URL of the icon to be used in the title bar of the terminal pane.
|pane.style.class | - | - | ✓ | The CSS style class of the terminal pane.
|pane.title | - | ✓ | - | The text to appear in the title bar of the terminal pane.
|prompt.bgcolor | ✓ | ✓ | ✓ | The background color of the prompt text.
|prompt.bold | ✓ | ✓ | ✓ | `true`, if the prompt text should be bold. +
Default value: `false`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class PropertiesConstants {
public static final String PROP_PANE_BGCOLOR = "pane.bgcolor";
public static final String PROP_PANE_STYLE_CLASS = "pane.style.class";

public static final String PROP_PANE_TITLE = "pane.title";
public static final String PROP_PANE_ICON_URL = "pane.icon.url";
public static final String PROP_PANE_ICON_FILE = "pane.icon.file";
public static final String PROP_PANE_ICON_RESOURCE = "pane.icon.resource";

public static final String PROP_ANSI_COLOR_MODE = "ansi.color.mode";

public static final String PROP_USER_INTERRUPT_KEY = "user.interrupt.key";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
Expand All @@ -30,6 +31,10 @@
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.Optional;
import java.util.function.Consumer;

Expand Down Expand Up @@ -168,6 +173,10 @@ public SwingTextTerminal() {
props.addStringListener(PROP_USER_INTERRUPT_KEY, null, (term, newVal) -> setUserInterruptKey(newVal));

props.addStringListener(PROP_PANE_BGCOLOR, null, (term, newVal) -> setPaneBackgroundColor(newVal));
props.addStringListener(PROP_PANE_TITLE, null, (term, newVal) -> setPaneTitle(newVal));
props.addStringListener(PROP_PANE_ICON_URL, null, (term, newVal) -> setPaneIconUrl(newVal));
props.addStringListener(PROP_PANE_ICON_FILE, null, (term, newVal) -> setPaneIconFile(newVal));
props.addStringListener(PROP_PANE_ICON_RESOURCE, null, (term, newVal) -> setPaneIconResource(newVal));

props.addStringListener(PROP_PROMPT_COLOR, null, (term, newVal) -> setPromptColor(newVal));
props.addStringListener(PROP_PROMPT_BGCOLOR, null, (term, newVal) -> setPromptBackgroundColor(newVal));
Expand Down Expand Up @@ -422,6 +431,39 @@ public void setPaneBackgroundColor(String colorName) {
getColor(colorName).ifPresent(col -> textPane.setBackground(col));
}

public void setPaneTitle(String newTitle) {
frame.setTitle(newTitle);
}

public void setPaneIconUrl(String url) {
try {
frame.setIconImage(ImageIO.read(new URL(url)));
} catch (IOException e) {
logger.warn("Cannot set icon from URL " + url, e);
}
}

public void setPaneIconFile(String filePath) {
try {
frame.setIconImage(ImageIO.read(new File(filePath)));
} catch (IOException e) {
logger.warn("Cannot set icon from file " + filePath, e);
}
}

public void setPaneIconResource(String res) {
InputStream istream = getClass().getResourceAsStream(res);
if(istream == null) {
logger.warn("Cannot find icon resource " + res);
} else {
try {
frame.setIconImage(ImageIO.read(istream));
} catch (IOException e) {
logger.warn("Cannot set icon from resource " + res, e);
}
}
}


public static Optional<Color> getColor(String colorName) {
try {
Expand Down

0 comments on commit 5b564ae

Please sign in to comment.