1 package net.mograsim.logic.ui.model.components;
3 import org.eclipse.swt.graphics.Color;
5 import net.haspamelodica.swt.helper.gcs.GeneralGC;
6 import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
7 import net.haspamelodica.swt.helper.swtobjectwrappers.Rectangle;
8 import net.mograsim.logic.ui.model.ViewModelModifiable;
9 import net.mograsim.logic.ui.modeladapter.ViewLogicModelAdapter;
10 import net.mograsim.logic.ui.modeladapter.componentadapters.NoLogicAdapter;
11 import net.mograsim.preferences.Preferences;
13 public class TextComponent extends GUIComponent
15 private final String text;
16 private Point textExtent;
18 public TextComponent(ViewModelModifiable model, String text)
25 public void render(GeneralGC gc, Rectangle visibleRegion)
27 textExtent = gc.textExtent(text);
28 Color textColor = Preferences.current().getColor("net.mograsim.logic.ui.color.text");
29 if (textColor != null)
30 gc.setForeground(textColor);
31 gc.drawText(text, getPosX() - textExtent.x / 2, getPosY() - textExtent.y / 2, true);
35 public Rectangle getBounds()
37 if (textExtent == null)
38 return super.getBounds();
39 return new Rectangle(getPosX() - textExtent.x / 2, getPosY() - textExtent.y / 2, textExtent.x, textExtent.y);
44 ViewLogicModelAdapter.addComponentAdapter(NoLogicAdapter.forClass(TextComponent.class));