Copyright (C) 2001, Geert Vernaeve. All Rights Reserved. Created 25-jan-2001
package
gve.calc.formula;
import
java.awt.*;
public
class
Stack
extends
Tabular
{
private
Part
[] elements;
Create an empty Stack
public
Stack
() { elements =
new
Part
[0]; }
Create a Stack with one element
public
Stack
(
Part
p) { elements =
new
Part
[1]; elements[0] = p; p.setParent(this); }
public
Stack
(
Part
[] cloneme) { elements =
new
Part
[cloneme.length];
for
(
int
i = cloneme.length-1; i>=0; i--) { elements[i] = (
Part
)cloneme[i].clone(); elements[i].setParent(this); } }
public
int
getHeight() {
return
elements.length; }
public
int
getWidth() {
return
1; }
public
Part
elementAt(
int
i,
int
j) {
if
(j == 0)
return
elements[i];
throw
new
ArrayIndexOutOfBoundsException(
"invalid column"
+j); }
public
void
setElementAt(
int
i,
int
j,
Part
el) {
if
(j == 0) { elements[i] = el; el.setParent(this); }
else
throw
new
ArrayIndexOutOfBoundsException(
"invalid column"
+j); }
public
Part
elementAt(
int
i) {
return
elements[i]; }
public
void
setElementAt(
int
i,
Part
el) { elements[i] = el; el.setParent(this); }
public
Object clone() {
return
new
Stack
(elements); }
public
void
insertRow(
int
pos) {
int
h = getHeight();
Part
[] newel =
new
Part
[h+1];
for
(
int
i = 0; i < h; i++) {
if
(i < pos) newel[i] = elements[i];
else
newel[i+1] = elements[i]; } elements = newel; setElementAt(pos,
new
Identifier
());
super
.insertRow(pos); }
public
void
removeRow(
int
pos) {
int
h = getHeight();
Part
[] newel =
new
Part
[h-1];
for
(
int
i = 0; i < h; i++) {
if
(i < pos) newel[i] = elements[i];
else
newel[i] = elements[i+1]; } elements = newel;
super
.removeRow(pos); }
public
Component createView(
FormulaView
view) {
return
new
StackView
(this,view); } }