org.sikuli.guide.SxText 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-2016, Sikuli.org, sikulix.com
* Released under the MIT License.
*
*/
/**
*
*/
package org.sikuli.guide;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JLabel;
public class SxText extends Visual {
JLabel label;
boolean initDone = false;
public SxText(String text) {
super();
init(text);
}
private void init(String text) {
this.text = text;
label = new JLabel();
add(label);
fontSize = 12;
label.setFont(new Font("SansSerif", Font.PLAIN, 36));
updateComponent();
initDone = true;
}
@Override
public void updateComponent() {
String htmltxt = ""
+ text + "";
label.setText(htmltxt);
Dimension size = label.getPreferredSize();
if (size.width > maxWidth) {
// hack to limit the width of the text to width
htmltxt = ""
+ text + "";
label.setText(htmltxt);
size = label.getPreferredSize();
}
label.setSize(size);
setActualSize(size);
}
@Override
public void paintComponent(Graphics g) {
Dimension originalSize = label.getPreferredSize();
Dimension actualSize = getActualSize();
float scalex = 1f * actualSize.width / originalSize.width;
float scaley = 1f * actualSize.height / originalSize.height;
((Graphics2D) g).scale(scalex, scaley);
super.paintComponent(g);
}
//
/* TextPropertyEditor ed = null;
*
* public void setEditable(boolean editable) {
* if (editable) {
* } else {
* }
* }*/ //
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy