📄 painterform.java
字号:
package webide.form;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.Hashtable;
import java.util.Vector;
import java.applet.Applet;
import webide.Wrapper;
import webide.Text;
import webide.Controlslist;
import webide.MainConsole;
import webide.views.toolbox.*;
import HAB.object.*;
import hc.util.MsgBox;
import webide.itools.Util;
public class PainterForm extends java.awt.Panel
implements MouseListener,
MouseMotionListener,
ComponentListener,
FocusListener,
ItemListener,
ActionListener,
KeyListener,
java.io.Serializable,
HAB.HcBean.HalcyonAppletBeanInterface {
public Hashtable prop = new Hashtable();
public Vector clist = new Vector();
public MainConsole mainConsole;
public FormPanel formPanel;
public static PainterForm pf;
public PainterForm(MainConsole mainConsole,FormPanel formPanel) {
super();
setLayout(null);
addMouseListener(this);
addMouseMotionListener(this);
addComponentListener(this);
addFocusListener(this);
addKeyListener(this);
instance = this;
this.mainConsole = mainConsole;
this.formPanel = formPanel;
setBounds(70,70,300,300);
topWrapper = new Wrapper(this);
//注-如要在画布中接收键盘事件,必须调用画布的requestFocus()方法。
//如果我们想在一个鼠标单击上捕捉键盘焦点,我们可以捕捉鼠标按下事件并且调用requestFocus()需求焦点方法。
requestFocus();
//setColor--------------
setBackground(Color.lightGray);
setForeground(Color.black);
initInput();
pf = this;
}
public Dimension getMinimumSize() {
return new Dimension(20,20);
}
public void updateBeanProp(Wrapper wrap, Hashtable propTab ) {
for (java.util.Enumeration e = propTab.keys(); e.hasMoreElements();) {
String propName = (String)e.nextElement();
if (propName.equalsIgnoreCase("height")
|| propName.equalsIgnoreCase("left")
|| propName.equalsIgnoreCase("top")
|| propName.equalsIgnoreCase("width")
|| propName.equalsIgnoreCase("x1")
|| propName.equalsIgnoreCase("x2")
|| propName.equalsIgnoreCase("y1")
|| propName.equalsIgnoreCase("y2"))
{
continue;
}
try {
Object propValue = propTab.get(propName);
wrap.setPropValue(propName, propValue);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public void setBeanBounds(Wrapper child, Hashtable prop)
{
float height = 0;
float left = 0;
float top = 0;
float width = 0;
Object bean = child.getBean();
Object tmp = prop.get("height");
if (tmp != null)
{
height = (Util.getFloatValue(tmp))/15;
child.height = height;
child.ininheight = false;
}
else if(bean instanceof PainterForm)
{
Object tm = prop.get("clientheight");
if(tm != null)
{
height = (Util.getFloatValue(tm) + 405)/15;
child.height = height;
child.ininheight = false;
prop.put("height",new Float(Util.getFloatValue(tm) + 405));
}
}
tmp = prop.get("left");
if (tmp != null)
{
left = (Util.getFloatValue(tmp))/15;
if(bean instanceof PainterForm)
{
child.left = left;
child.ininleft = false;
}
else
{
child.ininleft = false;
}
}
else if(bean instanceof PainterForm)
{
Object tm = prop.get("clientleft");
if(tm != null)
{
left = (Util.getFloatValue(tm) - 60)/15;
child.left = left;
child.ininleft = false;
prop.put("left",new Float(Util.getFloatValue(tm) - 60));
}
}
tmp = prop.get("top");
if (tmp != null)
{
top = (Util.getFloatValue(tmp))/15;
if(bean instanceof PainterForm)
{
child.top = top;
child.inintop = false;
}
else
{
child.top = top + getInsets().top;
child.inintop = false;
}
}
else if(bean instanceof PainterForm)
{
Object tm = prop.get("clienttop");
if(tm != null)
{
top = (Util.getFloatValue(tm) - 345)/15;
child.top = top;
child.inintop = false;
prop.put("top",new Float(Util.getFloatValue(tm) - 345));
}
}
tmp = prop.get("width");
if (tmp != null)
{
width = (Util.getFloatValue(tmp))/15;
child.width = width;
child.ininwidth = false;
}
else if(bean instanceof PainterForm)
{
Object tm = prop.get("clientwidth");
if(tm != null)
{
width = (Util.getFloatValue(tm) + 120)/15;
child.width = width;
child.ininwidth = false;
prop.put("width",new Float(Util.getFloatValue(tm) + 120));
}
}
if(prop.get("borderwidth") != null)
{
short borderwidth = ((Number)prop.get("borderwidth")).shortValue();
if(borderwidth > width)
{
width = borderwidth;
}
if(borderwidth > height)
{
height = borderwidth;
}
}
if (bean instanceof PainterForm)
{
if (width == 0.0 || height == 0.0) return;
setBounds((int)left, (int)top, (int)width, (int)height);
}
else
{
Component comp = child.getChild();
Container parent = comp.getParent();
if (parent instanceof java.awt.Frame)
{
Insets ins = getInsets();
formPanel.setChildBounds(comp,(int)left + ins.left, (int)top + ins.top, (int)width, (int)height);
}
else
{
formPanel.setChildBounds(comp,(int)left, (int)top, (int)width, (int)height);
}
}
} //end of setBeanBounds.
public void add_Controls(Controlslist ctrl, Object bean) {
Wrapper child = new Wrapper(this,bean);
EventSetDescriptor[] esd = child.getBeanInfo().getEventSetDescriptors();
ctrl.bean = bean;
ctrl.wrap = child;
child.setControl(ctrl);
try{
updateBeanProp(child,ctrl.prop);
}catch(Exception e) {
System.out.println("udpate bean prop Exception!");
}
Container parent = instance;
if (ctrl.parentCtrl != null) {
parent = (Container)ctrl.parentCtrl.wrap.getChild();
}
parent.add(child.getChild());
setBeanBounds(child, ctrl.prop);
}
private void initCtrlProp(Hashtable prop, Wrapper wrap) {
PropertyDescriptor[] properties = wrap.getProp();
for (int i=0; i<properties.length; i++) {
String name = properties[i].getDisplayName().toLowerCase();
if (name.equals("index") || name.equals("name")) continue;
Object value = wrap.getPropValue(i);
if (value != null) {
if (value instanceof java.awt.Color) {
value = Util.Changecolor(value);
}else if (value instanceof java.awt.Font) {
value = new HAB.object.font((java.awt.Font)value);
}
prop.put(name,value);
}
}
}
public synchronized void add_Controls(Object bean) {
add_Controls(bean,true);
}
public Wrapper add_Controls(Object bean,boolean tage) {
Controlslist control = new Controlslist();
Wrapper wrap = new Wrapper(this,bean);
wrap.setControl(control);
control.setProp(new Hashtable());
control.bean = bean;
control.wrap = wrap;
PropertyDescriptor[] properties = wrap.getProp();
EventSetDescriptor[] esd = wrap.getBeanInfo().getEventSetDescriptors();
Vector propVect = new Vector();
Component child = wrap.getChild();
child.setVisible(false);
for (int i = 0; i < properties.length; i++) {
String name = properties[i].getDisplayName().toLowerCase();
Class type = properties[i].getPropertyType();
propVect.addElement(name);
if (name.equalsIgnoreCase("font")) {
LinkWithForm.PropFontinit(name,wrap,type,control,prop,this);
}
}
String className = bean.getClass().getName();
int ii = className.lastIndexOf(java.io.File.separator);
if (ii != -1) {
control.className = className.substring(ii + 1);
}else{
control.className = className;
}
String ctrlName = control.className;
ii = ctrlName.lastIndexOf('.');
if (ii != -1) {
ctrlName = control.className.substring(ii+1);
}
int pos = 1;
while(hasBeingSameName(ctrlName+pos,clist)) {
pos++;
}
ctrlName = ctrlName+pos;
LinkWithForm.PropNCTLinit(ctrlName,wrap,control,propVect,pos);
String beanClsName = bean.getClass().getName();
if (!className.equalsIgnoreCase(beanClsName)) {
className = beanClsName;
initCtrlProp(control.prop,wrap);
control.className = className;
}
Container parent = null;
if (tage) {
parent = pContainer;
if (parent == null) {
parent = instance;
}
formPanel.setComponent(parent,child,isContainer);
}else{
parent = instance;
}
if (!(parent instanceof PainterForm)) {
Component cp = (Component)parent;
Controlslist con = getParentControl(cp,clist);
con.setChildCtrl(control);
control.setParentCtrl(con);
}else{
clist.addElement(control);
}
String className1 = control.className;
formPanel.setSelectBean();
setCurrentComponent(wrap);
LinkWithForm.saveHashtable(child,wrap,control.className,this);
return wrap;
} // end of add_Controls.
public boolean hasBeingSameName(String name, Vector clist) {
for (int i = 0; i< clist.size(); i++) {
Controlslist ctrl = (Controlslist)clist.elementAt(i);
String namevalue = (String)ctrl.prop.get("name");
if (namevalue.equalsIgnoreCase(name)) {
return true;
}
if (ctrl.childCtrls != null && ctrl.childCtrls.size()>0) {
if (hasBeingSameName(name, ctrl.childCtrls)) return true;
}
}
return false;
} // end fo hasBeenSameName.
public Controlslist getParentControl(Component parent, Vector clist) {
for (int i = 0; i< clist.size(); i++) {
Controlslist con = (Controlslist)clist.elementAt(i);
Component comp = con.wrap.getChild();
if (comp instanceof webInterface.ContainerCtrl) {
if (comp == parent) {
return con;
}
if (con.childCtrls != null && con.childCtrls.size()>0) {
Controlslist plist = getParentControl(parent, con.childCtrls);
if (plist != null) return plist;
}
}
}
return null;
} // end of getParentControl.
public void addComponent(Container contaier,Component child) {
contaier.add(child,0);
}//end of addComponent.
public void initInput() {
prop.put("height",new Integer(4500));
prop.put("left",new Integer(1500));
prop.put("top",new Integer(1500));
prop.put("width",new Integer(6750));
prop.put("clientheight",new Float(4500 - 405));
prop.put("clientwidth",new Float(6750 - 120));
prop.put("clientleft",new Float(1500 + 60));
prop.put("clienttop",new Float(1500 + 345));
prop.put("scaleheight",new Float(4095));
prop.put("scalewidth",new Float(6630));
prop.put("name","Form1");
}
public Wrapper findWrapper(Component child) {
if (child == this) {
return topWrapper;
}
return getWrapperOfComponent(child,clist);;
} // end of findWrapper.
private Wrapper getWrapperOfComponent(Component cp, Vector clist) {
for (int i = 0; i< clist.size(); i++) {
Controlslist con = (Controlslist)clist.elementAt(i);
Component comp = con.wrap.getChild();
if (cp == comp) return con.wrap;
if (comp instanceof webInterface.ContainerCtrl) {
if (con.childCtrls != null && con.childCtrls.size()>0) {
Wrapper wrap = getWrapperOfComponent(cp, con.childCtrls);
if (wrap != null && wrap.getChild() == cp) {
return wrap;
}
}
}
}
return null;
} // end of getWrapper.
public void setCurrentComponent(Wrapper focus) {
// Null means focus on the top-level beanbox.
if (focus == null) {
focus = topWrapper;
}
if (focus != mainConsole.currentFocus) {
mainConsole.setCurrentFocus(focus);
}
}// end of setCurrentComponent.
public void update(Graphics g) {
paint(g);
}
public void paint(Graphics g) {
formPanel.paintForm(g,this);
super.paint(g);
}
public void drawPicture(Graphics g,boolean p) {
if (p) drawPicture(g);
}//end of drawPicture.
public void drawPicture(Graphics g) {
int left = getInsets().left;
int top = getInsets().top;
if (imagePicture != null) {
if(getInsets().left == 0){
left = LET;
top = TP;
} else {
left = getInsets().left;
top = getInsets().top;
}
int w = imagePicture.getWidth(this);
int h = imagePicture.getHeight(this);
g.drawImage(imagePicture, left, top, w, h, this);
}
} //end of drawPicture.
public boolean isChange() {
int gw = 8;
int gh = 8;
int gWidth = getSize().width;
int gHeight= getSize().height;
boolean showGrid = true;
if (gWidth != gridWidth
|| gHeight != gridHeight
|| gw != gridw
|| gh != gridh
|| oldColorOfBack != getBackground()
|| oldColorOfFore != getForeground()
|| showGrid != gridOfForm) {
gridOfForm = showGrid;
oldColorOfFore = getForeground();
oldColorOfBack = getBackground();
gridWidth = gWidth;
gridHeight = gHeight;
gridw = gw;
gridh = gh;
return true;
}
return false;
}//end of isChange.
public Vector getFormComponents() {
Vector vect = new Vector();
vect.addElement(topWrapper);
for(int i = 0; i<clist.size();i++){
Controlslist con = (Controlslist)clist.elementAt(i);
addcontrol(con,vect);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -