01: package jtaDiscRack.presentation.dpanels;
02:
03: import jtaDiscRack.presentation.delements.*;
04:
05: import javax.swing.*;
06: import java.awt.*;
07:
08: /**
09: * Creates titled group panel with vertical or horizontal BoxLayout,
10: * that consists of panels of given elements.
11: *
12: * @author Sasa Bojanic
13: * @version 1.0
14: */
15: public class DGroupPanel extends DPanel {
16:
17: public DGroupPanel(DSimpleElement myOwner, Object[] elements,
18: String title, boolean isVertical, boolean hasBorder) {
19:
20: super (myOwner, elements.length + 1, title, isVertical,
21: 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: } else {
37: add(Box.createHorizontalGlue());
38: }
39:
40: }
41:
42: public DPanel getPanel(int no) {
43: if (no >= getComponentCount() - 1) {
44: return null;
45: }
46: return (DPanel) getComponent(no);
47: }
48:
49: public boolean checkRequired() {
50: if (isEmpty() && !getOwner().isRequired())
51: 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: for (int i = 0; i < getComponentCount(); i++) {
75: Component c = getComponent(i);
76: if (c instanceof DPanel) {
77: ((DPanel) c).setElements();
78: }
79: }
80: }
81:
82: }
|