X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=src%2Fjavajs%2Fawt%2FComponent.java;fp=src%2Fjavajs%2Fawt%2FComponent.java;h=505d0b338f5a5b85537757a3e3c8a2753609cac4;hp=4a24ddfb2c686e058bb94e43b3a042f85e37eb58;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/src/javajs/awt/Component.java b/src/javajs/awt/Component.java index 4a24ddf..505d0b3 100644 --- a/src/javajs/awt/Component.java +++ b/src/javajs/awt/Component.java @@ -1,155 +1,155 @@ -package javajs.awt; - -import javajs.api.GenericColor; -import javajs.util.CU; - -abstract public class Component { - - protected boolean visible; - protected boolean enabled = true; - protected String text; - protected String name; - protected int width; - protected int height; - protected String id; - - protected Object parent; - - public void setParent(Object p) { - parent = p; - } - - protected Object mouseListener; - - private GenericColor bgcolor; - - protected Component(String type) { - id = newID(type); - if (type == null) - return; - /** - * @j2sNative - * SwingController.register(this, type); - */ - { - } - - } - - public static String newID(String type) { - return type + ("" + Math.random()).substring(3, 10); - } - - abstract public String toHTML(); - - public void setBackground(GenericColor color) { - bgcolor = color; - } - - public void setText(String text) { - this.text = text; - /** - * @j2sNative - * - * SwingController.setText(this); - * - */ - { - } - } - - public void setName(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public Object getParent() { - return parent; - } - - public void setPreferredSize(Dimension dimension) { - this.width = dimension.width; - this.height = dimension.height; - } - - public void addMouseListener(Object listener) { - mouseListener = listener; - } - - public String getText() { - return text; - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - /** - * @j2sNative - * - * SwingController.setEnabled(this); - * - */ - {} - } - - public boolean isVisible() { - return visible; - } - - public void setVisible(boolean visible) { - this.visible = visible; - /** - * @j2sNative - * - * SwingController.setVisible(this); - * - */ - {} - } - - public int getHeight() { - return height; - } - - public int getWidth() { - return width; - } - - protected int minWidth = 30; - protected int minHeight = 30; - - public void setMinimumSize(Dimension d) { - minWidth = d.width; - minHeight = d.height; - } - - public int getSubcomponentWidth() { - return width; - } - - public int getSubcomponentHeight() { - return height; - } - - protected int renderWidth; - protected int renderHeight; - - protected String getCSSstyle(int defaultPercentW, int defaultPercentH) { - int width = (renderWidth > 0 ? renderWidth : getSubcomponentWidth()); - int height = (renderHeight > 0 ? renderHeight : getSubcomponentHeight()); - return (width > 0 ? "width:" + width +"px;" : defaultPercentW > 0 ? "width:"+defaultPercentW+"%;" : "") - + (height > 0 ?"height:" + height + "px;" : defaultPercentH > 0 ? "height:"+defaultPercentH+"%;" : "") - + (bgcolor == null ? "" : "background-color:" + CU.toCSSString(bgcolor) + ";"); - } - - public void repaint() { - // for inheritance - } - -} +package javajs.awt; + +import javajs.api.GenericColor; +import javajs.util.CU; + +abstract public class Component { + + protected boolean visible; + protected boolean enabled = true; + protected String text; + protected String name; + protected int width; + protected int height; + protected String id; + + protected Object parent; + + public void setParent(Object p) { + parent = p; + } + + protected Object mouseListener; + + private GenericColor bgcolor; + + protected Component(String type) { + id = newID(type); + if (type == null) + return; + /** + * @j2sNative + * SwingController.register(this, type); + */ + { + } + + } + + public static String newID(String type) { + return type + ("" + Math.random()).substring(3, 10); + } + + abstract public String toHTML(); + + public void setBackground(GenericColor color) { + bgcolor = color; + } + + public void setText(String text) { + this.text = text; + /** + * @j2sNative + * + * SwingController.setText(this); + * + */ + { + } + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public Object getParent() { + return parent; + } + + public void setPreferredSize(Dimension dimension) { + this.width = dimension.width; + this.height = dimension.height; + } + + public void addMouseListener(Object listener) { + mouseListener = listener; + } + + public String getText() { + return text; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + /** + * @j2sNative + * + * SwingController.setEnabled(this); + * + */ + {} + } + + public boolean isVisible() { + return visible; + } + + public void setVisible(boolean visible) { + this.visible = visible; + /** + * @j2sNative + * + * SwingController.setVisible(this); + * + */ + {} + } + + public int getHeight() { + return height; + } + + public int getWidth() { + return width; + } + + protected int minWidth = 30; + protected int minHeight = 30; + + public void setMinimumSize(Dimension d) { + minWidth = d.width; + minHeight = d.height; + } + + public int getSubcomponentWidth() { + return width; + } + + public int getSubcomponentHeight() { + return height; + } + + protected int renderWidth; + protected int renderHeight; + + protected String getCSSstyle(int defaultPercentW, int defaultPercentH) { + int width = (renderWidth > 0 ? renderWidth : getSubcomponentWidth()); + int height = (renderHeight > 0 ? renderHeight : getSubcomponentHeight()); + return (width > 0 ? "width:" + width +"px;" : defaultPercentW > 0 ? "width:"+defaultPercentW+"%;" : "") + + (height > 0 ?"height:" + height + "px;" : defaultPercentH > 0 ? "height:"+defaultPercentH+"%;" : "") + + (bgcolor == null ? "" : "background-color:" + CU.toCSSString(bgcolor) + ";"); + } + + public void repaint() { + // for inheritance + } + +}