source: other-projects/GlamED/trunk/src/org/honours/html/Table.java@ 26588

Last change on this file since 26588 was 26588, checked in by davidb, 11 years ago

Initial import of Korii's 520 project for managing digital cultural collections from Greenstone in Expeditee.

File size: 2.6 KB
Line 
1package org.honours.html;
2
3import java.awt.Color;
4import java.util.ArrayList;
5import java.util.List;
6
7import org.expeditee.io.Conversion;
8import org.expeditee.items.Dot;
9
10import org.w3c.dom.*;
11
12/**
13 * Class to produce table html elements from rectangles on
14 * an Expeditee frame. At least 2 rectangles joined together are
15 * required to produce a table.
16 * @author Korii
17 */
18public class Table {
19
20 //A table consists of a list of rows
21 private List<TableRow> _table;
22
23 private Dot _dot;
24
25 //Table attributes
26 private int _cellspacing;
27 private int _cellpadding;
28 private int _left;
29 private int _top;
30
31 private Alignment _alignment;
32 private Position _positioning;
33
34 public enum Alignment{
35 CENTER, LEFT, RIGHT;
36 }
37
38 public enum Position{
39 STATIC, ABSOLUTE, FIXED, RELATIVE, INHERIT;
40 }
41
42 public Table(){
43 _table = new ArrayList<TableRow>();
44 }
45
46 /**
47 * Returns a complete <table> element which includes
48 * all the <tr>'s, <td>'s and any text/images within
49 * the <td>'s.
50 * @param doc - the document to use when creating elements
51 * @return - a complete table
52 */
53 public Element getTableElement(Document doc){
54
55 Element tableElem = doc.createElement("table");
56 setTableStyle(tableElem);
57
58 //Append all <tr>'s to table. In TableRow class, append all <td>'s to the row.
59 for(int i = 0; i < _table.size(); i++){
60
61 Element trElem = doc.createElement("tr");
62 tableElem.appendChild(trElem);
63 }
64
65 return tableElem;
66 }
67
68 private void setTableStyle(Element tableElem){
69
70 Color c = (_dot.getColor() != null) ? _dot.getBorderColor() : _dot.getColor();
71 String color = (c != null) ? Conversion.getCssColor(c) : Conversion.getCssColor(Color.black);
72
73 float thickness = _dot.getThickness() >= 0 ? _dot.getThickness() : 1;
74
75 tableElem.setAttribute("cellpadding","1");
76 tableElem.setAttribute("cellspacing","0");
77
78 StringBuffer styleAttr = new StringBuffer("");
79 styleAttr.append("border-collapse: collapse; ");
80 styleAttr.append("border: " + thickness +"px solid " + color + ";");
81
82 tableElem.setAttribute("style",styleAttr.toString());
83 }
84
85 public void addRow(TableRow r){
86
87 _table.add(r);
88
89 //gets the first dot in the row's list of dots and uses this as the dot for customizing the table
90 //attributes
91 if(_table.size() == 1){
92
93 if(r.getDots() != null){
94
95 if(r.getDots().size() > 0 && r.getDots().get(0) != null)
96 setDot(r.getDots().get(0));
97 }
98 }
99 }
100
101 public List<TableRow> getTable(){
102 return _table;
103 }
104
105 private void setDot(Dot d){
106 _dot = d;
107 }
108
109 public Dot getDot(){
110 return _dot;
111 }
112
113
114}
Note: See TracBrowser for help on using the repository browser.