📄 panel.java
字号:
// Panel is a placeholder for one or more CanvasElements
// This panel is similar to Delphi's VCL Panel
package inline.ui.lo;
import inline.ui.*;
import inline.ui.ce.*;
import java.util.*;
public class Panel extends Vector
{
public final static int ALIGN_LEFT = 1;
public final static int ALIGN_RIGHT = 2;
public final static int ALIGN_TOP = 3;
public final static int ALIGN_BOTTOM = 4;
public final static int ALIGN_CLIENT = 5; // be greedy, take it all
public final static int ELEMENTS_LEFT = 1;
public final static int ELEMENTS_RIGHT = 2;
public final static int ELEMENTS_JUSTIFY = 3;
private int align;
private int elements;
private int px;
private int py;
private int width;
private int height;
public Panel(int aalign) // one of those ALING_XXX constants
{
align = aalign;
elements = ELEMENTS_JUSTIFY;
}
public Panel(int aalign, int eelems) // one of those ALING_XXX constants
{
align = aalign;
elements = eelems;
}
// deligate what we have
public void addCanvasElement(CanvasElement cce)
{
this.addElement(cce);
}
public void addCanvasElement(CanvasElement cce, int wwidth, int hheight)
{
this.addCanvasElement(cce);
cce.setMinimumSize(wwidth, hheight);
}
private void initSizes(int w, int h)
{
if (isHorizontal())
{
width = w;
}
else
{
int maxw = 0;
for(int i=0;i<size();i++)
{
CanvasElement ce = (CanvasElement)elementAt(i);
if (ce!=null && ce.isVisible())
{
int cw = ce.getContentWidth();
if (cw>maxw) maxw = cw;
}
}
width = maxw;
}
if (isVertical())
{
height = h;
}
else
{
int maxh = 0;
for(int i=0;i<size();i++)
{
CanvasElement ce = (CanvasElement)elementAt(i);
if (ce!=null && ce.isVisible())
{
int ch = ce.getContentHeight();
if (ch>maxh) maxh = ch;
}
}
//if (maxh == 0) maxh = h;
height = maxh;
}
}
protected void layout(int x, int y, int w, int h)
{
if (align==ALIGN_CLIENT)
{
width = w;
height = h;
}
else
{
initSizes(w,h);
}
if (align==ALIGN_LEFT)
{
px = x;
}
else
{
px = x+w-width;
}
px = x;
if (align==ALIGN_TOP)
{
py = y;
}
else
{
py = y+h-height;
}
if (isHorizontal())
{
layoutElementsH();
}
else
{
layoutElementsV();
}
}
protected boolean isVertical()
{
return (align == ALIGN_LEFT || align == ALIGN_RIGHT || align == ALIGN_CLIENT);
}
protected boolean isHorizontal()
{
return (align == ALIGN_TOP || align == ALIGN_BOTTOM || align == ALIGN_CLIENT);
}
protected int getWidth()
{
return width;
}
protected int getHeight()
{
return height;
}
protected int getAlign()
{
return align;
}
private void layoutElementsH()
{
int aelm = 0;
int midw = 0;
int havw = width;
for(int i=0;i<size();i++)
{
CanvasElement ce = (CanvasElement)elementAt(i);
if (ce!=null && ce.isVisible())
{
int cw = ce.getMinimumWidth();
if (cw>0)
{
havw -= cw;
}
else
{
aelm++;
}
}
}
// width for each element
if (aelm==0) aelm = 1;
// fixed float point to increase precision
midw = 1000 * havw / aelm;
int lp = 0;
int dl = 0;
for(int i=0;i<size();i++)
{
CanvasElement ce = (CanvasElement)elementAt(i);
if (ce!=null && ce.isVisible())
{
int cw = 1000*ce.getMinimumWidth();
if (cw == 0)
{
cw = midw;
}
else
{
if (i>0) cw=cw+1000;
}
if (i==size()-1)
{
if ((px + lp/1000+dl + cw/1000-dl)>width)
{
cw = cw - 1000;
}
}
ce.setPositionSize(px + lp/1000+dl, py, cw/1000-dl, height);
int llp = lp;
lp = lp + cw;
if ((llp%1000) + (cw%1000) > 1000)
{
dl = 0;
}
else
{
dl = 1;
}
}
}
}
private void layoutElementsV()
{
// to do, just like layoutElementsH
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -