📄 listitems.java
字号:
package webide.itools;
import java.util.*;
public class ListItems {
/*-----------------------------------------------------------------------------*/
/*Private Data Members---------------------------------------------------------*/
private int count;
private Vector keyString;
private Vector storeListItems;
private ListView listview;
public ListItems()
{
keyString=new Vector();
storeListItems=new Vector();
this.listview=null;
this.count=0;
}
public ListItems(ListView listview)
{
keyString=new Vector();
storeListItems=new Vector();
this.listview=listview;
this.count=0;
}
/*------------------------------------------------------------------------------*/
/*Property-----------------------------------------------------------------------*/
public int getCount()
{
return this.count;
}
public void setCount(int value)
{
// empty
}
public void setNumListItems(int value)
{
// empty
}
public int getNumListItems()
{
return this.count;
}
public ListItems getObject()
{
return this;
}
public void setname(String name)
{
;
}
public String getname()
{
return "ListItems";
}
/*------------------------------------------------------------------------------*/
/*Add Method-------------------------------------------------------------------------*/
public ListItem addItem(boolean append,int index,String key,String text,int icon,int smallicon,boolean isdir)
{
this.count++;
if (append) index = count; // very important
ListItem insertListItem = new ListItem(index,key,text,icon,smallicon,isdir,this);
try{
insertListItem.setSubItemsWithIndex(1," ");
}catch(Exception e){
}
String insertKey=new String(key);
if (append)
{
keyString.addElement(insertKey);
storeListItems.addElement(insertListItem);
}
else
{
keyString.insertElementAt(insertKey,index-1); // must index-1
storeListItems.insertElementAt(insertListItem,index-1);
ChangeListItemsIndex(true,index); // must 'index'
}
return insertListItem;
}
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();
storeListItems.removeAllElements();
}
/*---------------------------------------------------------------------------*/
/*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=false;
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
storeListItems.removeElementAt(index-1);
ChangeListItemsIndex(false,index); // must 'index'
}
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=false;
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);
}
/*-------------------------------------------------------------------------*/
/*Item Method--------------------------------------------------------------*/
public ListItem Item(int index)
{
if (this.listview==null) return null;
boolean designtime = false;
if ((index<1)||(index>this.count))
{
return null;
}
return (ListItem)(storeListItems.elementAt(index-1));
}
public ListItem Item(String key) throws Exception
{
if (this.listview==null) throw new Exception("91:Object variable or with block variable not set");
boolean designtime = false;
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");
this.listview.repaint();
}
private void ChangeListItemsIndex(boolean add,int index)
{
int n=index;
ListItem ls;
if (add) n++;
for (;n<=this.count;n++)
{
ls=(ListItem)(this.storeListItems.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 getStoreListItems()
{
return (java.util.Vector)(this.storeListItems);
}
/*------------------------------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------------------------------*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -