use of javax.swing.text.StyledDocument in project grafikon by jub77.
the class FreightCheckPanel method initializeStyles.
private void initializeStyles() {
if (okStyle == null && errorStyle == null && textPane.getGraphics() != null) {
FontMetrics metrics = textPane.getGraphics().getFontMetrics();
int size = metrics.getAscent() * 5 / 6;
// images
StyledDocument document = (StyledDocument) textPane.getDocument();
okStyle = document.addStyle("ok.style", null);
ImageIcon okIcon = GuiComponentUtils.resizeIcon(ResourceLoader.createImageIcon(GuiIcon.OK), size, size);
StyleConstants.setIcon(okStyle, okIcon);
errorStyle = document.addStyle("error.style", null);
ImageIcon errorIcon = GuiComponentUtils.resizeIcon(ResourceLoader.createImageIcon(GuiIcon.ERROR), size, size);
StyleConstants.setIcon(errorStyle, errorIcon);
StyleConstants.setSubscript(okStyle, true);
boldUnderlineStyle = document.addStyle("bold.underline", null);
StyleConstants.setUnderline(boldUnderlineStyle, true);
StyleConstants.setBold(boldUnderlineStyle, true);
}
}
use of javax.swing.text.StyledDocument in project ffx by mjschnie.
the class ModelingShell method run.
/**
* Configure the Swing GUI for the shell.
*/
@Override
public void run() {
if (!headless) {
try {
super.run();
// Output JTextPane
JTextPane output = getOutputArea();
output.setBackground(Color.BLACK);
output.setForeground(Color.WHITE);
// Input JTextPane
JTextPane input = getInputArea();
input.setBackground(Color.WHITE);
input.setForeground(Color.BLACK);
// Output StyledDocument Styles
StyledDocument doc = output.getStyledDocument();
Style defStyle = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
Style regular = doc.addStyle("regular", defStyle);
Style prompt = doc.addStyle("prompt", regular);
Style command = doc.addStyle("command", regular);
Style result = doc.addStyle("result", regular);
StyleConstants.setFontFamily(regular, "Monospaced");
setPromptStyle(prompt);
setCommandStyle(command);
setResultStyle(result);
StyleConstants.setForeground(prompt, Color.ORANGE);
StyleConstants.setForeground(command, Color.GREEN);
StyleConstants.setForeground(result, Color.GREEN);
StyleConstants.setBackground(result, Color.BLACK);
clearOutput();
// initMenus();
// Set labels and icon for Force Field X.
getStatusLabel().setText("Welcome to the Force Field X Shell.");
JFrame frame = (JFrame) this.getFrame();
frame.setTitle("Force Field X Shell");
URL iconURL = getClass().getClassLoader().getResource("ffx/ui/icons/icon64.png");
ImageIcon icon = new ImageIcon(iconURL);
frame.setIconImage(icon.getImage());
frame.setSize(600, 600);
} catch (Exception e) {
logger.warning(e.toString());
}
}
}
use of javax.swing.text.StyledDocument in project GenericKnimeNodes by genericworkflownodes.
the class ParameterDialog method updateDocumentationSection.
private void updateDocumentationSection(String description) {
StyledDocument doc = (StyledDocument) help.getDocument();
Style style = doc.addStyle("StyleName", null);
StyleConstants.setFontFamily(style, "SansSerif");
try {
doc.remove(0, doc.getLength());
doc.insertString(0, description, style);
} catch (BadLocationException e) {
LOGGER.warn("Documentation update failed.", e);
}
}
use of javax.swing.text.StyledDocument in project org.alloytools.alloy by AlloyTools.
the class SwingLogPanel method setFontName.
/**
* Set the font name.
*/
public void setFontName(String fontName) {
if (log == null)
return;
this.fontName = fontName;
log.setFont(new Font(fontName, Font.PLAIN, fontSize));
StyleConstants.setFontFamily(styleRegular, fontName);
StyleConstants.setFontFamily(styleBold, fontName);
StyleConstants.setFontFamily(styleRed, fontName);
StyleConstants.setFontSize(styleRegular, fontSize);
StyleConstants.setFontSize(styleBold, fontSize);
StyleConstants.setFontSize(styleRed, fontSize);
// Changes all existing text
StyledDocument doc = log.getStyledDocument();
Style temp = doc.addStyle("temp", null);
StyleConstants.setFontFamily(temp, fontName);
StyleConstants.setFontSize(temp, fontSize);
doc.setCharacterAttributes(0, doc.getLength(), temp, false);
// Changes all existing hyperlinks
Font newFont = new Font(fontName, Font.BOLD, fontSize);
for (JLabel link : links) {
link.setFont(newFont);
}
}
use of javax.swing.text.StyledDocument in project org.alloytools.alloy by AlloyTools.
the class SwingLogPanel method reallyLog.
private void reallyLog(String text, Style style) {
if (log == null || text.length() == 0)
return;
int i = text.lastIndexOf('\n'), j = text.lastIndexOf('\r');
if (i >= 0 && i < j) {
i = j;
}
StyledDocument doc = log.getStyledDocument();
try {
if (i < 0) {
doc.insertString(doc.getLength(), text, style);
} else {
// Performs intelligent caret positioning
doc.insertString(doc.getLength(), text.substring(0, i + 1), style);
log.setCaretPosition(doc.getLength());
if (i < text.length() - 1) {
doc.insertString(doc.getLength(), text.substring(i + 1), style);
}
}
} catch (BadLocationException e) {
// Harmless
}
if (style != styleRed) {
lastSize = doc.getLength();
}
}
Aggregations