3 import javajs.api.GenericColor;
6 abstract public class Component {
8 protected boolean visible;
9 protected boolean enabled = true;
10 protected String text;
11 protected String name;
16 protected Object parent;
18 public void setParent(Object p) {
22 protected Object mouseListener;
24 private GenericColor bgcolor;
26 protected Component(String type) {
32 * SwingController.register(this, type);
39 public static String newID(String type) {
40 return type + ("" + Math.random()).substring(3, 10);
43 abstract public String toHTML();
45 public void setBackground(GenericColor color) {
49 public void setText(String text) {
54 * SwingController.setText(this);
61 public void setName(String name) {
65 public String getName() {
69 public Object getParent() {
73 public void setPreferredSize(Dimension dimension) {
74 this.width = dimension.width;
75 this.height = dimension.height;
78 public void addMouseListener(Object listener) {
79 mouseListener = listener;
82 public String getText() {
86 public boolean isEnabled() {
90 public void setEnabled(boolean enabled) {
91 this.enabled = enabled;
95 * SwingController.setEnabled(this);
101 public boolean isVisible() {
105 public void setVisible(boolean visible) {
106 this.visible = visible;
110 * SwingController.setVisible(this);
116 public int getHeight() {
120 public int getWidth() {
124 protected int minWidth = 30;
125 protected int minHeight = 30;
127 public void setMinimumSize(Dimension d) {
129 minHeight = d.height;
132 public int getSubcomponentWidth() {
136 public int getSubcomponentHeight() {
140 protected int renderWidth;
141 protected int renderHeight;
143 protected String getCSSstyle(int defaultPercentW, int defaultPercentH) {
144 int width = (renderWidth > 0 ? renderWidth : getSubcomponentWidth());
145 int height = (renderHeight > 0 ? renderHeight : getSubcomponentHeight());
146 return (width > 0 ? "width:" + width +"px;" : defaultPercentW > 0 ? "width:"+defaultPercentW+"%;" : "")
147 + (height > 0 ?"height:" + height + "px;" : defaultPercentH > 0 ? "height:"+defaultPercentH+"%;" : "")
148 + (bgcolor == null ? "" : "background-color:" + CU.toCSSString(bgcolor) + ";");
151 public void repaint() {