1 package org.catacomb.druid.blocks; 2 3 import org.catacomb.datalish.SColor; 4 import org.catacomb.druid.build.Context; 5 import org.catacomb.druid.build.GUIPath; 6 import org.catacomb.druid.build.Realizer; 7 import org.catacomb.druid.gui.base.DruFrame; 8 import org.catacomb.druid.gui.base.DruMenuBar; 9 import org.catacomb.druid.gui.base.DruPanel; 10 import org.catacomb.druid.gui.base.UIColors; 11 import org.catacomb.interlish.structure.AddableTo; 12 import org.catacomb.report.E; 13 14 15 16 17 public class Frame implements AddableTo, Realizer { 18 19 20 public String title; 21 public MenuBar menuBar; 22 public Panel panel; 23 public String info; 24 25 public String id; 26 27 public SColor backgroundColor; 28 29 public int prefWidth; 30 public int prefHeight; 31 32 public Frame() { 33 } 34 35 36 public Frame(String ttl, MenuBar mb, Panel p) { 37 title = ttl; 38 menuBar = mb; 39 panel = p; 40 } 41 42 43 public void add(Object obj) { 44 if (obj instanceof Panel) { 45 if (panel != null) { 46 E.error("can only have one panel in a frame"); 47 } else { 48 panel = (Panel)obj; 49 } 50 } else if (obj instanceof MenuBar) { 51 menuBar = (MenuBar)obj; 52 } else if (obj instanceof Menu) { 53 if (menuBar == null) { 54 menuBar = new MenuBar(); 55 } 56 menuBar.add(obj); 57 } else { 58 E.error("cant add to frame: " + obj); 59 } 60 61 } 62 63 64 public Object realize(Context ctx, GUIPath gpathin) { 65 GUIPath gpath = gpathin; 66 gpath = gpath.extend(id); 67 68 if (backgroundColor != null) { 69 ctx.setBg(backgroundColor.getColor()); 70 } 71 72 UIColors.initialize(ctx.getBg()); 73 74 75 DruFrame axf = new DruFrame((title != null ? title : "")); 76 axf.setID(id); 77 78 axf.setBackgroundColor(ctx.getBg()); 79 80 if (menuBar != null) { 81 DruMenuBar amb = (DruMenuBar)(menuBar.realize(ctx, gpath)); 82 83 axf.setDruMenuBar(amb); 84 } 85 86 if (panel != null) { 87 DruPanel axp = (DruPanel)(panel.realize(ctx, gpath)); 88 axf.setDruPanel(axp); 89 } 90 91 ctx.addComponent(axf, gpath); 92 93 if (info != null && info.length() > 1) { 94 ctx.getInfoAggregator().receiveInfo(title, info); 95 } 96 97 if (prefWidth > 0 || prefHeight > 0) { 98 if (prefHeight == 0) { 99 prefHeight = prefWidth; 100 } 101 if (prefWidth == 0) { 102 prefWidth = prefHeight; 103 } 104 105 axf.setPreferredSize(prefWidth, prefHeight); 106 } 107 108 return axf; 109 } 110 111 112 113 }