]]>学习Swing的一点体?/title>http://www.tkk7.com/Apple/archive/2005/08/07/9505.htmlҎҎSun, 07 Aug 2005 04:08:00 GMThttp://www.tkk7.com/Apple/archive/2005/08/07/9505.htmlhttp://www.tkk7.com/Apple/comments/9505.htmlhttp://www.tkk7.com/Apple/archive/2005/08/07/9505.html#Feedback5http://www.tkk7.com/Apple/comments/commentRss/9505.htmlhttp://www.tkk7.com/Apple/services/trackbacks/9505.html 以前在inforsense公司的KDEq_上已l有一个Table Editor,点击ȝ面上含有表格数据的节?可以打开表格,然后可以对各U表D行编?增删{简单操?而同时这些操作也会反映到ȝ面上的工作流模型?现在的目标是对这个工兯一步扩展其功能,不仅融如Excel spreadsheet的功?qo,对cellq行~辑{?,q有树图与表格视图q接h,可以q行两种视图之间的拖?dnd),切换{?现在更要与化学专业结合v?本来q款软g是ؓ化学家设计的,目的使他们操作v来更方便.所以还要把扩展后的表格~辑器和Interactive Browserl合h,做到对同一l数据的多种视图,而且它们是同步的.比如表格中会有Structure(化学分子l构),分子量这L特定的域,而点d可启动特定的~辑化学分子l构的Y件进行编?同时变化反映在表格数据中. 而我接触的都是Swing,它给我的感觉虽然好象仅仅是在AWT的类前面都加上了个J,但仔l研I?里面有各U设计模式的存在,q一点让我兴奋不?正好借这个机会学习设计模?我大部分旉接触的都是JTable和JTree.所以主要谈谈他?Swing基本是就是个MVC的设计架?拿JTable来说,JTable是View的部?而TableModel是M的部?下面一点点讲讲实现的细? 1.Filter(qo?: 要在表格中实现过滤的功能,而实际上不媄响原来的模型,可以考虑在原来的模型增加一个过滤器.它其实上也是一个TableModel(可以子类化TableModel的实现框架AbstractTableModel.),它把原来的TM作ؓ自己的成?M实际的操作如getColumnCount(),getRowCount(),getColumnName(){都交给原来的TM来完?调用TM的相应方?,只是在应该控制的地方控制一?比如,getValueAt(i,j)通过控制i,j来只q回qo器想昄的行或列的数?而具体的q回数据的操作还是由TM来完?对setValueAt(),isCellEditable()也是同样的道?我具体的做法是用一个List把我xC的??号保存下?在getValueAt(i,j)?i的取D围就是这个List?q其实是一UAdapter模式的思想.同样,实现Sort也可以用q种方式. 2)Selection: JTable中的选择都是由ListSelectionModel来完成的,行列都有默认的选择模型,讉K行的SelectionModel的方式是getSelectionModel(),讉K列的SelectionModel的方式是getColumnModel().getSelectionModel().你也可以实现自己的选择模型.可以通过 getRowSelectionAllowed()和getColumnSelectionAllowed()获取现在行列是否可选的信息,如果都可?则在CellU别是可选的.q就是ؓ什么在行列都可选的情况?讄i行被选中setRowSelectionInterval(i),同时讄j列被选中setColumnSelectionInterval(j),q样只有(i,j)的Cell单元被选中得到原因.但是反过?如果我只想(i,j)的Cell不被选中,而仅仅靠removeColumnSelectionInterval(j)和removeRowSelectionInterval(i)是实C了的.q难道是Swing的漏z? 前面已经讲到,讄改变选择状态主要是通过行列SelectionModel的setSelectionInterval(),addSelectionInterval(),removeSelectionInterval()三个方式实现? 3)header 表的?列的表头着实让我头痛了一?其是row header.我的row header是用一个JTable实现?关键是要和表格同步v?可以考虑与表格共用一个Filter,关键是改写getValueAt()和getRowCount()q两个方?q样表格qo留下的行也是表头q个JTable中所需要留下的?而选择的同步则是覆盖changeSelection()q个Ҏ实现?而操作的Ҏ是?)中提到的那几个方?讄rowHeader头只需要在JScrollPane中用setRowHeaderView()指定卛_,而表格最左上角的单元(行表头的表头)用setCorner()指定. ColumnHeader其实在JTable中已有实?如果要通过单击列头来选择全列的话,实现的方法可通过在列头上d一个MouseListener,然后在它的MouseClickedҎ中进行选择的同?其余步骤与行在changeSelection()中的cM,有一点值得注意,要获取单ȝ列的索引是通过getTableHeader()后得到的tableHeader.columnAtPoint(e.getPoint())得到?q里e是MouseEvent,也就是这个单ȝ动作事g. 具体的控制代码如? /** * once click on the header, that column should be selected */ public void mouseClicked(MouseEvent e) { JTableHeader header = table.getTableHeader(); TableColumnModel columns = header.getColumnModel(); if(!columns.getColumnSelectionAllowed()) return; //get the column index being clicked int column = header.columnAtPoint(e.getPoint()); if(column == -1) return; int count = table.getRowCount(); //set the entire column to be selected if(count != 0) table.setRowSelectionInterval(0,count-1); ListSelectionModel selection = columns.getSelectionModel(); //if the shift modifier is pushed down, need to select multiple columns if(e.isShiftDown()) { int anchor = selection.getAnchorSelectionIndex();// the first index int lead = selection.getLeadSelectionIndex();//the last index
if(anchor != -1) { boolean old = selection.getValueIsAdjusting(); selection.setValueIsAdjusting(true);
public class NLSTest { public NLSTest() { String str1="Hello world!"; System.out.println(str1); } public static void main(String[] args) { new NLSTest(); } }
// Creation & retrieval methods: public static Logger getRootLogger(); public static Logger getLogger(String name);
// printing methods: public void debug(Object message); public void info(Object message); public void warn(Object message); public void error(Object message); public void fatal(Object message);
// get a logger instance named "com.foo" Logger logger = Logger.getLogger("com.foo");
// Now set its level. Normally you do not need to set the // level of a logger programmatically. This is usually done // in configuration files. logger.setLevel(Level.INFO);
// This request is enabled, because WARN >= INFO. logger.warn("Low fuel level.");
// This request is disabled, because DEBUG < INFO. logger.debug("Starting search for nearest gas station.");
// The logger instance barlogger, named "com.foo.Bar", // will inherit its level from the logger named // "com.foo" Thus, the following request is enabled // because INFO >= INFO. barlogger.info("Located nearest gas station.");
// This request is disabled, because DEBUG < INFO. barlogger.debug("Exiting gas station search");
]]>【{载】语义万l网服务的自动发?/title>http://www.tkk7.com/Apple/archive/2005/06/29/6879.htmlҎҎWed, 29 Jun 2005 06:52:00 GMThttp://www.tkk7.com/Apple/archive/2005/06/29/6879.htmlhttp://www.tkk7.com/Apple/comments/6879.htmlhttp://www.tkk7.com/Apple/archive/2005/06/29/6879.html#Feedback0http://www.tkk7.com/Apple/comments/commentRss/6879.htmlhttp://www.tkk7.com/Apple/services/trackbacks/6879.html语义万维|服务的自动发现- -
原文地址Q?A >http://meta.blogchina.com/812188.html
我感兴趣的问题实际上是Ontology based metadata services for information retrieval. 实际上是开发一个或一l智能代理,利用Semantic Web services架构解决异构pȝ的情报检索互操作问题。前提条件是一定的Semantic Web services架构。首先必dq个概念解释清楚。这是个很热门的话题了实际上Q一经典的文章见(2001q的文章Q稍早一些,q没?FONT size=+0>DAML-SQ:http://www.daml.org/services/ieee01-KSL.pdfQ一个作者是南人,W三作者是个中国留学生Q都很年dQ?/P>
以下主要来自Q?FONT size=+0>Katia Sycara, Massimo Paolucci, Anupriya Ankolekar, Naveen Srinivasan, "Automated discovery, interaction and composition of Semantic Web services"Q?/P>
Web services 利用自主的代理在分布的环境中实现自动?按需"服务Q?FONT size=+0>Semantic Web提供服务描述和服务接口的语义支持Q目前这斚w的标准正在逐步建立hQ然而多?FONT size=+0>Web service之间的协调和语义一致性是一个关键问题,目前BPEL4WS ?FONT size=+0>WSCI在这斚w作了一些探索,然而最可能的途径是通过DAML-S提供解决框架?/P>
由此可以认ؓQ?语义Web服务"是语义元数据、本体、Ş式化工具?FONT size=+0>Web服务架构的集成,是基于良好定义的语言q行语义描述?FONT size=+0>Web服务(A Semantic Web service is a Web Service whose description is in a language that has well-defined semantics)?/P>
]]>【读书笔讎ͼjava数据l构与面向对象编E基】抽象数据类容器http://www.tkk7.com/Apple/archive/2005/06/25/6706.htmlҎҎSat, 25 Jun 2005 08:31:00 GMThttp://www.tkk7.com/Apple/archive/2005/06/25/6706.htmlhttp://www.tkk7.com/Apple/comments/6706.htmlhttp://www.tkk7.com/Apple/archive/2005/06/25/6706.html#Feedback0http://www.tkk7.com/Apple/comments/commentRss/6706.htmlhttp://www.tkk7.com/Apple/services/trackbacks/6706.html 区别容器对象本n和该容器包含的对象是很重要的。从某种意义上说Q研I数据结构也是研究容器。这里,给出容器这U抽象数据类型的行ؓ框架Qƈ且创建实现这U抽象数据类型的基本原型。根据一下的Ҏ可以区别不同类型的容器Q?BR> Q?Q容器中的对象是否可排序?/STRONG>比如Q按容器的一个承属性排序,或按容器中的对象的一个属性排序?BR> Q?Q是否允许对象的复制Q是否允讔R复)?BR> Q?Q容器中的对象可被限制ؓ一个特定的cd?BR> Q?Q容器中的对象可Z索引来访问?BR> Q?Q容器中的对象可Z相对位置来访问?BR> Q?Q容器中的对象可ZD问?BR> Q?Q容器可Ҏ其连通性(U性、非U性)来区别?/STRONG> q里以Container接口为根接口来表C所有容器最一般的形式?BR> 1.1 层的Container接口 在开发新的javacLQ我们应该先考虑是否需要可串行化。一个可串行化的对象可以很容易的从作为对象的文g中来读/写的。最一般的容器h一下特性: 1Q不考虑它所包含的对象的cdQ?BR> 2Q所包含的对象没有排序的要求Q?BR> 3Q接受复制的对象Q?BR> 4Q支持可串行化; 5Q接受本n为空的命令; 6Q接受一下查询:q回所包含的对象的个数、返回容器是否ؓI?BR>我们所定义的Container接口如下Q?BR> /** Interface Container - top level container*/ package foundations; import java.io.serializable; public interface Container extends Serializable { // Commands - see subinferfaces /** Remove all objects from the container if found */ public void makeEmpty (); //Queries /** Return true if the container is empty */ public boolean isEmpty(); /** Return the number of objects in the container */ public int size(); }
1.2 最单的容器Q-堆栈和队?BR> q里定义最单的容器Q堆栈(StackQ和队列QQueueQ?BR> 堆栈使一个容器,q具有以下特性: 1) 堆栈是有ơ序的,q也是堆栈的一个属性,与堆栈所包含的对象无兟뀂堆栈中对象的次序依赖于其插入、删除的序。后q先出?BR> 2Q对堆栈的操作只能在一个名为top的位|上。用PushҎ在堆栈顶部增加新的对?用popҎ删除堆栈剙的对象,用topҎ查询堆栈剙的对象?BR> 3Q用MakeEmptyҎ可以清除堆栈的对象,也可用isEmpty来查询该堆栈是否为空Q以及查询堆栈的大小Qsize()Q?BR> 接口Stack是对Container的扩展,因此它承了Container所有的ҎQƈ增加了新的方?push、pop、以及查询顶部对象的Ҏ?BR> /** Interface Stack - a first-in last-out container */ package foundations; public interface Stack extends Container { //Commands /** Add an object onto the top of the stack */ public void push(object obj);
/** Remove an object form the top of the stack * Throw NoSuchElementException if stack is empty */ public void pop(); //Queries
/** Return without removing, the top object on the stack * Throw NoSuchElementException if stack is empty */ public object top(); } 队列也是一个容器,q具有以下特性: 1Q队列有ơ序Q这也是它的一个属性,与队列所包含的对象无兟뀂队列中对象的次序依赖于其插入、删除的序。队列中的次序关pȝ主要特点是先q先出?BR>2Q对队列的操作限制在两个位置上,即frontQ对_、rearQ队)。我们可以在N增加对象Q在头部删除对象Q或查询头部的对象?BR>3Q可以用MakeEmptyҎ可以清除队列的对象,也可用isEmpty来查询该队列是否为空Q以及查询队列的大小Qsize()Q?BR>接口Queue是对Container的扩展,因此它承了Container所有的ҎQƈ增加了新的方?add、remove、以及查询头部对象的Ҏ?BR>/** Interface Queue */ public interface Queue extends Container { //Commands /** Add an object at the rear of the queue */ public void add(Object obj);
/** Remove an object from the front of the queue * Throws NoSuchElementException if queue is empty */ public void remove();
//Queries /** Return without removing, the front object in the queue * Throws NoSuchElementException if queue is empty */ public object front(); }
/** Return -1 if the receiver is less than obj, * 0 if the receiver equals obj and * 1 if the receiver is greater than obj */ public int compareTo (Object obj); }
cAssociation允许值和?Key)l合hQ即在键和其g间有一个关联。类Association在研I一个需要键Q|keyQvalueQ对的容器数据结构时起到什么重要的作用?BR> 在字典类容器中就包含Associationcȝ实例Q字典是由键l成的,也就是说Q我们查扑֭怸的对象时Q只是查扑֮的键。如果字典按某种序Q根据所包含的键的相对大)排列的,那么我们必须保证M输入到OrderdDictionaryQ有序字典)中的兌对的键也是可以比较的QComparableQ。同Ӟ我们要求兌也必L可串行化的,q样才能保证前面所提到的所有容器都要求是可串行化的。Association是一个类Q而不是接口?BR>/** Class Assocation * An instance must initialize a key on creation. * If used as a comparable Assocation,keys must be comparable and comparions is based on keys only. * Note that equals() does not enforce the comparable feature and requires equality of both key and value. */ package foundations; import java.io.serializable;
public class Association extends Object implements Comparable,Serializable { //Fields private Object key; private Object value;
/** Create an instance with specified key and null value */ public Assocation (Object key) { this(key,null); }
/** Create an instance with specified key and value */ public Association(Object key,Object value) { this.key=key; this.value=value; }
/** Set the value */ public void setValue(Object value) { this.value = value; }
/**Implement Comparable method compareTo * Compare based only on key; key must be comparable */ public int compareTo (Object obj) { return ((Comparable)key).compareTo((Association)obj.key()); }
/** Override inherited Object method hashCode(). *Return a unique int representing this object */ public int hashCode () { int bits1 = key.hashCode(); int bits2 = value.hashCode(); return (bits1 <<8)^(bits2>>8); } }
//接口 interface player { int flag = 1; void play();//播放 void pause();//暂停 void stop();//停止 }//end :)
//抽象c?BR>abstract class playing { public void display(Object oPara) { System.out.println(oPara); } abstract void winRun(); }//end :)
//l承了playing抽象cd实现cplayer接口 public class newPlay extends playing implements player { public void play() { display("newPlay.play()");//q里只是演示Q去掉了代码?BR> } public void pause() { display("newPlay.pause()");//q里只是演示Q去掉了代码?BR> } public void stop() { display("newPlay.stop()");//q里只是演示Q去掉了代码?BR> } void winRun() { display("newPlay.winRun()");//q里只是演示Q去掉了代码?BR> } public static void main(String[] args) { newPlay p = new newPlay(); p.play(); p.pause(); p.stop(); p.winRun(); } }//end