1 package com.calipso.reportgenerator.userinterface; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.util.Vector ; 6 import java.util.HashMap ; 7 import java.util.Iterator ; 8 9 14 15 public class UPsPanel extends JPanel { 16 17 private UPCollection upCollection; 18 19 public UPsPanel(LayoutManager layout, boolean isDoubleBuffered, UPCollection upCollection) { 20 super(layout, isDoubleBuffered); 21 this.upCollection = upCollection; 22 initialize(); 23 } 24 25 public UPsPanel(LayoutManager layout, UPCollection upCollection) { 26 super(layout); 27 this.upCollection = upCollection; 28 initialize(); 29 } 30 31 public UPsPanel(boolean isDoubleBuffered, UPCollection upCollection) { 32 super(isDoubleBuffered); 33 this.upCollection = upCollection; 34 initialize(); 35 } 36 37 public UPsPanel(UPCollection upCollection) { 38 this.upCollection = upCollection; 39 initialize(); 40 } 41 42 private void initialize() { 43 Vector upElements = upCollection.getUpCollection(); 44 setLayout(new GridBagLayout()); 45 GridBagConstraints cons = new GridBagConstraints(); 46 int pos = 0; 47 for(int i = 0 ; i < upElements.size() ; i++) { 48 UPCollectionElement upElement = (UPCollectionElement) upElements.elementAt(i); 49 pos += addVisualComponent(upElement.getVisualComponent(), cons, pos); 50 } 51 } 52 53 private int addVisualComponent(UPPanel visualComponent, GridBagConstraints cons, int pos) { 54 cons.fill = GridBagConstraints.HORIZONTAL; 55 cons.gridwidth = 1; 56 cons.gridx = 0; 57 cons.gridy = pos; 58 if(visualComponent instanceof UPValuePanel){ 59 cons.gridheight = 1; 60 pos++; 61 }else{ 62 cons.gridheight = 2; 63 pos += 2; 64 } 65 ((GridBagLayout)getLayout()).setConstraints(visualComponent, cons); 66 add(visualComponent); 67 return pos; 68 } 69 70 78 79 public boolean fillParamsMap(HashMap params) { 80 for(int i = 0 ; i < getComponentCount() ; i++) { 81 UPPanel currentPanel = (UPPanel) this.getComponent(i); 82 boolean succeded = currentPanel.fillParamsMap(params); 83 if(!succeded) { 84 return false; 85 } 86 } 87 return true; 88 } 89 } 90 | Popular Tags |