All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sikuli.guide.SxText Maven / Gradle / Ivy

There is a newer version: 2.0.5
Show newest version
/**
 *
 */
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 - 2024 Weber Informatics LLC | Privacy Policy