org.sikuli.guide.HTMLTextPane Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sikulixapi Show documentation
Show all versions of sikulixapi Show documentation
... for visual testing and automation
/*
* Copyright (c) 2010-2019, sikuli.org, sikulix.com - MIT license
*/
/**
*
*/
package org.sikuli.guide;
import java.awt.Dimension;
import javax.swing.JLabel;
import javax.swing.JTextPane;
class HTMLTextPane extends JTextPane {
int maximum_width;
String text;
public Dimension preferredDimension;
Visual comp = null;
String htmltxt;
public HTMLTextPane(Visual comp) {
this.comp = comp;
maximum_width = comp.maxWidth - 10;
init();
}
public HTMLTextPane() {
maximum_width = 400;
init();
}
private void init() {
setContentType("text/html");
}
@Override
public void setText(String text) {
this.text = text;
if (comp != null) {
maximum_width = comp.maxWidth - 2 * comp.PADDING_X;
htmltxt = ""
+ text + "";
} else {
htmltxt = ""+text+"";
}
super.setText(htmltxt);
JTextPane tp = new JTextPane();
tp.setText(htmltxt);
if (getPreferredSize().getWidth() > maximum_width) {
// hack to limit the width of the text to width
if (comp != null) {
htmltxt = ""
+ text + "";
} else {
htmltxt = ""+text+"";
}
super.setText(htmltxt);
}
setSize(getPreferredSize());
}
@Override
public String getText() {
return this.text;
}
}