KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > blocks > scalable > webmonitor > ResultTable


1 package sample.blocks.scalable.webmonitor;
2
3 /*
4  * Copyright 2002 by
5  * <a HREF="http://www.coridan.com">Coridan</a>
6  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
7  *
8  * The contents of this file are subject to the Mozilla Public License Version
9  * 1.1 (the "License"); you may not use this file except in compliance with the
10  * License. You may obtain a copy of the License at
11  * http://www.mozilla.org/MPL/
12  *
13  * Software distributed under the License is distributed on an "AS IS" basis,
14  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
15  * for the specific language governing rights and limitations under the
16  * License.
17  *
18  * The Original Code is "MantaRay" (TM).
19  *
20  * The Initial Developer of the Original Code is lital kasif and Amir Shevat.
21  * Portions created by the Initial Developer are Copyright (C) 2006
22  * Coridan Inc. All Rights Reserved.
23  *
24  * Contributor(s): all the names of the contributors are added in the source
25  * code where applicable.
26  *
27  * Alternatively, the contents of this file may be used under the terms of the
28  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
29  * provisions of LGPL are applicable instead of those above. If you wish to
30  * allow use of your version of this file only under the terms of the LGPL
31  * License and not to allow others to use your version of this file under
32  * the MPL, indicate your decision by deleting the provisions above and
33  * replace them with the notice and other provisions required by the LGPL.
34  * If you do not delete the provisions above, a recipient may use your version
35  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
36  
37  *
38  * This library is free software; you can redistribute it and/or modify it
39  * under the terms of the MPL as stated above or under the terms of the GNU
40  * Lesser General Public License as published by the Free Software Foundation;
41  * either version 2.1 of the License, or any later version.
42  *
43  * This library is distributed in the hope that it will be useful, but WITHOUT
44  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
45  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
46  * License for more details.
47  *
48  * Created on Jan 2, 2005
49  *
50  * Coridan LTD
51  */

52 import javax.swing.table.*;
53
54
55
56 import java.util.ArrayList JavaDoc;
57 import java.util.HashMap JavaDoc;
58 /**
59  * This object is used by 'WebMonitor' in order to store the URL status information
60  * received from the engine (via dispatcher) and update that inforamtion into the GUI
61  * table that dispay it.
62  *
63  * @author lital kasif and Amir Shevat
64  */

65 public class ResultTable extends AbstractTableModel {
66     /**
67      * Comment for <code>serialVersionUID</code>
68      */

69     private static final long serialVersionUID = 6951728232313370721L;
70     private String JavaDoc[] columnNames = {"URL","STATUS"};
71     protected static int NUM_COLUMNS = 2;
72     protected static int START_NUM_ROWS = 0;
73     protected int nextEmptyRow = 0;
74     protected int numRows = 0;
75
76     // urlsToStatus holds the names of the urlsToStatus to be inputed to the table
77
private ArrayList JavaDoc urls;
78     // urlsToStatus holds the stock values of the urlsToStatus to be inputed to the table
79
private HashMap JavaDoc urlsToStatus;
80
81     public ResultTable() {
82         //initializing
83
urls = new ArrayList JavaDoc();
84         urlsToStatus = new HashMap JavaDoc();
85     }
86
87 /**
88  * returns the the name of the column inserted
89  */

90     public String JavaDoc getColumnName(int column) {
91             return columnNames[column];
92     }
93
94     /**
95      * returns the number of exisiting column
96      */

97     public synchronized int getColumnCount() {
98         return NUM_COLUMNS;
99     }
100
101     /**
102      * returns the current number of rows
103      */

104     public synchronized int getRowCount() {
105         if (numRows < START_NUM_ROWS) {
106             return START_NUM_ROWS;
107         } else {
108             return numRows;
109         }
110     }
111
112     /**
113      * returns the current value of a cube in the stock table
114      */

115     public synchronized Object JavaDoc getValueAt(int row, int column) {
116         try {
117                 System.out.println("Getting row "+row+" by column "+column );
118                 switch (column) {
119                 //returns the name of the company
120
case 0:
121                     return urls.get(row);
122                 //retuns the value of the company
123
case 1:
124                       return urlsToStatus.get(urls.get(row));
125                 }
126         } catch (Exception JavaDoc e) {
127         }
128         return "N/A";
129     }//getValueAt
130

131     /**
132      * updates a stock value of a company
133      * @param companyName the name of the company
134      * @param value its new value
135      */

136     public synchronized void updateURLStatus(String JavaDoc url, String JavaDoc status) {
137     //the method either adds the new information to a new row or updates an existing row
138
boolean addedRow = !urls.contains(url) ;
139         urlsToStatus.put(url, status);
140         //Notify listeners that the stocksData changed.
141
if (addedRow) {
142             numRows++;
143             urls.add(url);
144             fireTableRowsInserted(urls.size(), urls.size());
145             System.out.println("init");
146         } else {
147             int row = urls.indexOf(url);
148             System.out.println("Updated row "+row);
149             fireTableRowsUpdated(row, row);
150             
151         }
152     }//updateCompany
153

154     
155
156 }//ResultTable
Popular Tags