1 package org.catacomb.druid.xtext.base; 2 3 import org.catacomb.report.E; 4 5 import java.util.ArrayList; 6 7 public class ContainerBlock extends Block { 8 9 public ArrayList<Block> items; 10 11 12 DownBlock downBlock; 13 UpBlock upBlock; 14 15 16 17 public ContainerBlock() { 18 items = new ArrayList<Block>(); 19 } 20 21 22 public void addBlock(Block bw) { 23 items.add(bw); 24 bw.setParent(this); 25 } 26 27 public ArrayList<Block> getBlocks() { 28 return items; 29 } 30 31 32 33 public void link() { 34 DownBlock db = new DownBlock(this); 35 setDownBlock(db); 36 setNext(db); 37 38 Block bcur = db; 39 for (Block b : getBlocks()) { 40 bcur.setNext(b); 41 42 if (b instanceof TextBlock) { 43 bcur = b; 44 45 } else if (b instanceof ContainerBlock) { 46 ContainerBlock cb = (ContainerBlock)b; 47 cb.link(); 48 bcur = cb.getUpBlock(); 49 50 } else { 51 E.error("wrong block type " + b); 52 } 53 } 54 55 UpBlock bup = new UpBlock(this); 56 setUpBlock(bup); 57 bcur.setNext(bup); 58 } 59 60 61 62 63 public DownBlock getDownBlock() { 64 return downBlock; 65 } 66 67 68 69 public void setDownBlock(DownBlock downBlock) { 70 this.downBlock = downBlock; 71 } 72 73 public UpBlock getUpBlock() { 74 return upBlock; 75 } 76 77 78 79 public void setUpBlock(UpBlock upBlock) { 80 this.upBlock = upBlock; 81 } 82 83 84 public static ContainerBlock newEmptyText() { 85 ContainerBlock cb = new ContainerBlock(); 86 cb.addBlock(new WordBlock("hello")); 87 cb.link(); 88 return cb; 89 } 90 91 }