KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > presentation > dpanels > DGroupPanel


1 package discRack.presentation.dpanels;
2
3 import discRack.presentation.delements.*;
4
5 import java.util.*;
6 import javax.swing.*;
7 import java.awt.*;
8
9 /**
10  * Creates titled group panel with vertical or horizontal BoxLayout,
11  * that consists of panels of given elements.
12  *
13  * @author Sasa Bojanic
14  * @version 1.0
15  */

16 public class DGroupPanel extends DPanel{
17
18    public DGroupPanel (DSimpleElement myOwner,Object JavaDoc[] elements,String JavaDoc title,
19       boolean isVertical,boolean hasBorder) {
20
21       super(myOwner,elements.length+1,title,isVertical,hasBorder);
22
23       DPanel dtdp=null;
24       for (int i=0; i<elements.length; i++) {
25          if (elements[i] instanceof DSimpleElement) {
26             dtdp=((DSimpleElement)elements[i]).getPanel();
27          } else if (elements[i] instanceof DPanel) {
28             dtdp=(DPanel)elements[i];
29          }
30          dtdp.setEnabled(!myOwner.isReadOnly());
31          add(dtdp);
32       }
33
34       if (isVertical) {
35          add(Box.createVerticalGlue());
36       }
37       else {
38          add(Box.createHorizontalGlue());
39       }
40
41    }
42
43    public DPanel getPanel (int no) {
44       if (no>=getComponentCount()-1) {
45          return null;
46       }
47       return (DPanel)getComponent(no);
48    }
49
50    public boolean checkRequired () {
51       if (isEmpty() && !getOwner().isRequired()) return true;
52       boolean isOK=true;
53       for (int i=0; i<getComponentCount();i++) {
54          Component c=getComponent(i);
55          if (c instanceof DPanel) {
56             isOK=isOK && ((DPanel)c).checkRequired();
57          }
58       }
59       return isOK;
60    }
61
62    public boolean isEmpty () {
63       boolean isEmpty=true;
64       for (int i=0; i<getComponentCount();i++) {
65          Component c=getComponent(i);
66          if (c instanceof DPanel) {
67             isEmpty=isEmpty && ((DPanel)c).isEmpty();
68          }
69       }
70       return isEmpty;
71    }
72
73    public void setElements () {
74       boolean isOK=true;
75       for (int i=0; i<getComponentCount();i++) {
76          Component c=getComponent(i);
77          if (c instanceof DPanel) {
78 // System.out.println("Comp no "+(i+1)+" = "+getComponent(i));
79
((DPanel)c).setElements();
80          }
81       }
82    }
83
84 }
85
Popular Tags