Skip to content

Commit 8dd82ea

Browse files
authored
Version 2.2 Part 2
1 parent 2b98cba commit 8dd82ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+30468
-0
lines changed

version2p2/JTableBuilder.java

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import javax.swing.*;
2+
import javax.swing.table.*;
3+
import javax.swing.event.*;
4+
import java.awt.*;
5+
import java.awt.event.*;
6+
import java.util.ArrayList;
7+
8+
/******************************
9+
* Copyright (c) 2003,2019 Kevin Lano
10+
* This program and the accompanying materials are made available under the
11+
* terms of the Eclipse Public License 2.0 which is available at
12+
* http://www.eclipse.org/legal/epl-2.0
13+
*
14+
* SPDX-License-Identifier: EPL-2.0
15+
* *****************************/
16+
17+
interface TableCell
18+
{ public String getcellvalue();
19+
public void setcellvalue(String cellvaluex);
20+
}
21+
22+
class DatabaseTableModel implements TableModel
23+
{ TableCell[][] cells;
24+
int cols;
25+
int rows;
26+
27+
DatabaseTableModel(TableCell[][] cellsx, int colsx, int rowsx)
28+
{ cells = cellsx;
29+
rows = rowsx;
30+
cols = colsx;
31+
}
32+
33+
public void addTableModelListener(TableModelListener l) { }
34+
35+
public void removeTableModelListener(TableModelListener l) { }
36+
37+
38+
public Class getColumnClass(int cind)
39+
{ try
40+
{ return Class.forName("java.lang.String"); }
41+
catch (ClassNotFoundException e)
42+
{ System.out.println("Class not found");
43+
return null; }
44+
}
45+
46+
public int getColumnCount() { return cols; }
47+
48+
public String getColumnName(int cind)
49+
{ return null; }
50+
51+
public int getRowCount() { return rows; }
52+
53+
public Object getValueAt(int cind, int rind)
54+
{ if (inRange(cind,rind))
55+
{ return cells[cind][rind].getcellvalue(); }
56+
return null;
57+
}
58+
59+
public boolean isCellEditable(int cind, int rind)
60+
{ return inRange(cind,rind); }
61+
62+
public void setValueAt(Object val, int cind, int rind)
63+
{ if (inRange(cind,rind))
64+
{ try
65+
{ cells[cind][rind].setcellvalue(val + ""); }
66+
catch (Exception e) { }
67+
}
68+
}
69+
70+
private boolean inRange(int cind, int rind)
71+
{ return (0 <= rind && rind < rows &&
72+
0 <= cind && cind < cols); }
73+
}
74+
75+
76+
public class JTableBuilder
77+
{
78+
public JTable buildTable(TableCell[][] cells, int cols, int rows)
79+
{ TableModel tm =
80+
new DatabaseTableModel(cells,cols,rows);
81+
82+
DefaultTableColumnModel dtcm =
83+
new DefaultTableColumnModel();
84+
for (int i = 0; i < cols; i++)
85+
{ TableColumn tc =
86+
new TableColumn(i);
87+
dtcm.addColumn(tc);
88+
}
89+
JTableHeader header = new JTableHeader(dtcm);
90+
91+
JTable p = new JTable(tm,dtcm);
92+
header.setTable(p);
93+
return p;
94+
}
95+
}

version2p2/JTableTest.java

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
import javax.swing.*;
2+
import javax.swing.table.*;
3+
import javax.swing.event.*;
4+
import java.awt.*;
5+
import java.awt.event.*;
6+
import java.util.ArrayList;
7+
8+
/******************************
9+
* Copyright (c) 2003,2019 Kevin Lano
10+
* This program and the accompanying materials are made available under the
11+
* terms of the Eclipse Public License 2.0 which is available at
12+
* http://www.eclipse.org/legal/epl-2.0
13+
*
14+
* SPDX-License-Identifier: EPL-2.0
15+
* *****************************/
16+
17+
class DatabaseTableModel implements TableModel
18+
{ Square[][] cells = new Square[9][9];
19+
20+
DatabaseTableModel(Square[][] squares)
21+
{ cells = squares; }
22+
23+
public void addTableModelListener(TableModelListener l) { }
24+
25+
public void removeTableModelListener(TableModelListener l) { }
26+
27+
28+
public Class getColumnClass(int cind)
29+
{ try
30+
{ return Class.forName("java.lang.String"); }
31+
catch (ClassNotFoundException e)
32+
{ System.out.println("Class not found");
33+
return null; }
34+
}
35+
36+
public int getColumnCount() { return 9; }
37+
38+
public String getColumnName(int cind)
39+
{ // if (cind == 0) { return "Name"; }
40+
// if (cind == 1) { return "Address"; }
41+
// if (cind == 2) { return "Phone"; }
42+
return null; }
43+
44+
public int getRowCount() { return 9; }
45+
46+
public Object getValueAt(int rind, int cind)
47+
{ if (inRange(rind,cind))
48+
{ return cells[rind][cind].getvalue() + ""; }
49+
return null;
50+
}
51+
52+
public boolean isCellEditable(int rind, int cind)
53+
{ return inRange(rind,cind); }
54+
55+
public void setValueAt(Object val, int rind, int cind)
56+
{ if (inRange(rind,cind))
57+
{ try
58+
{ int v = Integer.parseInt(val + "");
59+
cells[rind][cind].setvalue(v);
60+
}
61+
catch (Exception e) { }
62+
}
63+
}
64+
65+
66+
private boolean inRange(int rind, int cind)
67+
{ return (0 <= rind && rind < 9 &&
68+
0 <= cind && cind < 9); }
69+
}
70+
71+
public class JTableTest extends JFrame
72+
{
73+
74+
public JTableTest(Square[][] squares)
75+
{
76+
TableModel tm =
77+
new DatabaseTableModel(squares);
78+
79+
DefaultTableColumnModel dtcm =
80+
new DefaultTableColumnModel();
81+
// String[] colHeadings = { "Name", "Address", "Phone"};
82+
for (int i = 0; i < 9; i++)
83+
{ TableColumn tc =
84+
new TableColumn(i);
85+
tc.setWidth(100);
86+
dtcm.addColumn(tc); }
87+
JTableHeader header = new JTableHeader(dtcm);
88+
89+
JTable p = new JTable(tm,dtcm);
90+
header.setTable(p);
91+
92+
getContentPane().add(p, BorderLayout.CENTER);
93+
addWindowListener(new WindowAdapter()
94+
{ public void windowClosing(WindowEvent e)
95+
{
96+
System.exit(0); }
97+
});
98+
}
99+
100+
}

version2p2/JavaOperation.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/******************************
2+
* Copyright (c) 2003,2019 Kevin Lano
3+
* This program and the accompanying materials are made available under the
4+
* terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
* *****************************/
9+
10+
class JavaOperation
11+
{ String opname;
12+
String inpars = "";
13+
String outpars = "";
14+
String defn = "";
15+
16+
JavaOperation(String nme)
17+
{ opname = nme; }
18+
19+
public void setinpars(String prs)
20+
{ inpars = prs; }
21+
22+
public void setoutpars(String prs)
23+
{ outpars = prs; }
24+
25+
public void setdefn(String dfn)
26+
{ defn = dfn; }
27+
28+
public String toString()
29+
{ String res = "public " + outpars + " " + opname +
30+
"(" + inpars + ")\n" +
31+
" { " + defn + " }";
32+
return res;
33+
}
34+
}

version2p2/JoinNode.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/******************************
2+
* Copyright (c) 2003,2019 Kevin Lano
3+
* This program and the accompanying materials are made available under the
4+
* terms of the Eclipse Public License 2.0 which is available at
5+
* http://www.eclipse.org/legal/epl-2.0
6+
*
7+
* SPDX-License-Identifier: EPL-2.0
8+
* *****************************/
9+
10+
public class JoinNode extends ControlNode
11+
{ public JoinNode(String nme)
12+
{ super(nme); }
13+
}

0 commit comments

Comments
 (0)