01: package discRack.presentation.dpanels;
02:
03: import discRack.presentation.delements.*;
04:
05: import java.util.*;
06: import javax.swing.*;
07: import java.awt.*;
08:
09: /**
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[] elements,
19: String title, boolean isVertical, boolean hasBorder) {
20:
21: super (myOwner, elements.length + 1, title, isVertical,
22: hasBorder);
23:
24: DPanel dtdp = null;
25: for (int i = 0; i < elements.length; i++) {
26: if (elements[i] instanceof DSimpleElement) {
27: dtdp = ((DSimpleElement) elements[i]).getPanel();
28: } else if (elements[i] instanceof DPanel) {
29: dtdp = (DPanel) elements[i];
30: }
31: dtdp.setEnabled(!myOwner.isReadOnly());
32: add(dtdp);
33: }
34:
35: if (isVertical) {
36: add(Box.createVerticalGlue());
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())
52: return true;
53: boolean isOK = true;
54: for (int i = 0; i < getComponentCount(); i++) {
55: Component c = getComponent(i);
56: if (c instanceof DPanel) {
57: isOK = isOK && ((DPanel) c).checkRequired();
58: }
59: }
60: return isOK;
61: }
62:
63: public boolean isEmpty() {
64: boolean isEmpty = true;
65: for (int i = 0; i < getComponentCount(); i++) {
66: Component c = getComponent(i);
67: if (c instanceof DPanel) {
68: isEmpty = isEmpty && ((DPanel) c).isEmpty();
69: }
70: }
71: return isEmpty;
72: }
73:
74: public void setElements() {
75: boolean isOK = true;
76: for (int i = 0; i < getComponentCount(); i++) {
77: Component c = getComponent(i);
78: if (c instanceof DPanel) {
79: // System.out.println("Comp no "+(i+1)+" = "+getComponent(i));
80: ((DPanel) c).setElements();
81: }
82: }
83: }
84:
85: }
|