KickJava   Java API By Example, From Geeks To Geeks.

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


1 package discRack.presentation.dpanels;
2
3 import discRack.presentation.delements.*;
4
5 import discRack.presentation.*;
6
7 import javax.swing.*;
8 import javax.swing.border.*;
9
10 import java.awt.*;
11
12 /**
13  * Base class for all panels that manage data of elements.
14  *
15  * @author Sasa Bojanic
16  * @version 1.0
17  */

18 public class DPanel extends JPanel {
19    public static final Dimension textFieldDimension=new Dimension(200,20);
20    public static final Dimension tableDimension=new Dimension(700,375);
21
22
23    private DSimpleElement myOwner;
24    private String JavaDoc title;
25
26    public DPanel () {
27       super();
28    }
29
30    public DPanel (DSimpleElement myOwner,int noOfElements,String JavaDoc title,
31       boolean isVertical,boolean hasBorder) {
32
33       super();
34
35       this.myOwner=myOwner;
36
37       setTitle(title,hasBorder);
38
39       setLayout(new BoxLayout(this,((isVertical) ? BoxLayout.Y_AXIS:BoxLayout.X_AXIS)));
40       setAlignmentX(Component.LEFT_ALIGNMENT);
41       setAlignmentY(Component.TOP_ALIGNMENT);
42
43       if (myOwner!=null) {
44          setEnabled(!myOwner.isReadOnly());
45       }
46
47    }
48
49    public void setTitle (String JavaDoc title,boolean hasBorder) {
50       this.title=title;
51
52       int emptyBorderHSize=10;
53       int emptyBorderVSize=10;
54       if (!hasBorder) {
55          emptyBorderVSize=1;
56       }
57       Border emptyb=BorderFactory.createEmptyBorder(emptyBorderVSize,emptyBorderHSize,
58          emptyBorderVSize,emptyBorderHSize);
59       Border inb=BorderFactory.createEmptyBorder(0,0,0,0);
60       if (hasBorder) {
61          inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
62          inb=BorderFactory.createTitledBorder(inb,title);
63       }
64       else {
65          emptyb=BorderFactory.createTitledBorder(emptyb,title);
66       }
67       setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
68    }
69
70    public static void defaultErrorMessage (Window w,String JavaDoc elementTitle) {
71       String JavaDoc message="The value must be defined, define it or press Cancel !!!";
72       String JavaDoc dialogTitle="Value is not defined";
73
74       DPanel.errorMessage(w,dialogTitle,elementTitle,message);
75    }
76
77    public static void errorMessage (Window w,String JavaDoc dialogTitle,String JavaDoc elementTitle,String JavaDoc message) {
78       JOptionPane.showMessageDialog(w,elementTitle+message,
79          dialogTitle,JOptionPane.ERROR_MESSAGE);
80    }
81
82    public DSimpleElement getOwner () {
83       return myOwner;
84    }
85
86    public String JavaDoc getTitle() {
87       return title;
88    }
89
90    /**
91    * Checks if the element that owns panel
92    */

93    public boolean checkRequired () {
94       return true;
95    }
96
97    // Always returns true, this is set because of panels that are never empty
98
// but this method is used when checking emptiness of group panel,
99
// and panels that do not override this method should not be ever considered
100
public boolean isEmpty () {
101       return true;
102    }
103
104    public void setElements () {
105       return;
106    }
107
108    /**
109    * Find the hosting window.
110    */

111    public Window getWindow () {
112       for (Container p = getParent(); p != null; p = p.getParent()) {
113          if (p instanceof Window) {
114             return (Window)p;
115          }
116       }
117       return null;
118    }
119
120 }
121
Popular Tags