📄 columnheaders.java
字号:
package webide.itools;
import java.util.*;
import java.beans.*;
public class ColumnHeaders {
/*-----------------------------------------------------------------------------*/
/*Private Data Members---------------------------------------------------------*/
private int count;
private Vector keyString;
private Vector storeColumnHeaders;
private ListView listview;
public ColumnHeaders()
{
keyString=new Vector();
storeColumnHeaders=new Vector();
this.listview=null;
this.count=0;
}
public ColumnHeaders(ListView listview)
{
keyString=new Vector();
storeColumnHeaders=new Vector();
this.listview=listview;
this.count=0;
}
public void PaintColumnHeaders(){
listview.repaint();
}
/*------------------------------------------------------------------------------*/
/*Property-----------------------------------------------------------------------*/
public int getCount()
{
return this.count;
}
public void setCount(int value)
{
// empty
}
public void setNumColumnHeaders(int value)
{
// empty
}
public int getNumColumnHeaders()
{
return this.count;
}
public ColumnHeaders getObject()
{
return this;
}
public void setname(String name)
{
;
}
public String getname()
{
return "ColumnHeaders";
}
/*------------------------------------------------------------------------------*/
/*Add Method-------------------------------------------------------------------------*/
public ColumnHeader addItem(boolean append,int index,String key,String text,int width,int alingment)
{
this.count++;
if (append) index=count; // very important
ColumnHeader insertColumnHeader = new ColumnHeader(index,key,text,width/15,alingment,this);
String insertKey=new String(key);
if (append)
{
keyString.addElement(insertKey);
storeColumnHeaders.addElement(insertColumnHeader);
}
else
{
keyString.insertElementAt(insertKey,index-1); // must index-1`
storeColumnHeaders.insertElementAt(insertColumnHeader,index-1);
ChangeColumnHeadersIndex(true,index); // must 'index'
}
return insertColumnHeader;
}
public int ArgumentsLength()
{
return 5;
}
/*--------------------------------------------------------------------------*/
/*-Clear Method-------------------------------------------------------------*/
public void Clear() throws Exception
{
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
this.count=0;
keyString.removeAllElements();
storeColumnHeaders.removeAllElements();
PaintListView();
}
/*---------------------------------------------------------------------------*/
/*Remove Method -------------------------------------------------------------*/
public void Remove(int index) throws Exception
{
// Very Important // Don't Delete
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
// Very important
boolean designtime=Beans.isDesignTime();
if ((index<1)||(index>this.count))
{
if (designtime) return;
else throw new Exception("35600:Index out of bounds");
}
this.count--;
keyString.removeElementAt(index-1); // must index-1
storeColumnHeaders.removeElementAt(index-1);
ChangeColumnHeadersIndex(false,index); // must 'index'
PaintListView();
}
public void Remove(String key) throws Exception
{
// Very Important // Don't Delete
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
// Very important
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
boolean designtime=Beans.isDesignTime();
if (key==null) return;
if (key.equals(""))
{
if (designtime) return;
else throw new Exception("35603:Invalid key");
}
boolean find=false;
int i=0;
String value;
while (i<this.count)
{
value=(String)(keyString.elementAt(i));
if (key.equals(value)) {
find=true;
break;
}
else i++;
}
if (! find) throw new Exception("35601:Element not found");
Remove(i+1);
PaintListView();
}
/*-------------------------------------------------------------------------*/
/*Item Method--------------------------------------------------------------*/
public ColumnHeader Item(int index) throws Exception
{
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
boolean designtime=Beans.isDesignTime();
if ((index<1)||(index>this.count))
{
if (designtime) return null;
else throw new Exception("35600:Index out of bounds");
}
return (ColumnHeader)(storeColumnHeaders.elementAt(index-1));
}
public ColumnHeader Item(String key) throws Exception
{
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
boolean designtime=Beans.isDesignTime();
if (key==null) return null;
if (key.equals(""))
{
if (designtime) return null;
else throw new Exception("35603:Invalid key");
}
boolean find=false;
int i=0;
String value;
while (i<this.count)
{
value=(String)(keyString.elementAt(i));
if (key.equals(value)) {
find=true;
break;
}
else i++;
}
if (! find) throw new Exception("35601:Element not found");
return Item(i+1);
}
public void PaintListView() throws Exception
{
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
listview.repaint();
}
public void setVBBounds(java.util.Vector value) throws Exception// from '0' // Base is 'double[4]'
{
if ((value==null)||(value.size()!=this.count))
throw new Exception("The ColumnHeaders Size Wrong");
ColumnHeader ls;
double[] vbvalue;
for (int index=1;index<=this.count;index++)
{
ls=(ColumnHeader)(this.storeColumnHeaders.elementAt(index-1)); // must 'index-1'
vbvalue=(double[])(value.elementAt(index-1));
ls.changeLeft(vbvalue[0]);
ls.changeTop(vbvalue[1]);
}
}
private void ChangeColumnHeadersIndex(boolean add,int index)
{
int n=index;
ColumnHeader ls;
if (add) n++;
for (;n<=this.count;n++)
{
ls=(ColumnHeader)(this.storeColumnHeaders.elementAt(n-1)); // must 'n-1'
ls.ChangeIndex(n);
}
}
public int findUnique(String key,int index)
{
if ((index<1)||(index>this.count)) return 1;
if (key.equals(""))
{
keyString.setElementAt("",index-1); // must index-1
return 0;
}
boolean unique=true;
int n=1;
String ls;
while ((n<=this.count)&&(unique))
{
if (n!=index)
{
ls=(String)(this.keyString.elementAt(n-1)); // must 'n-1'
if (key.equals(ls))
unique=false;
else
n++;
}
else n++;
} // while
if (! unique)
return 2;
else {
this.keyString.setElementAt(new String(key),index-1); // must 'n-1'
return 0;
}
}
public java.util.Vector getStoreColumnHeaders()
{
return (java.util.Vector)(this.storeColumnHeaders);
}
/*------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -