KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > xml > panels > XMLPanel


1 /* XMLPanel.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11
12 package org.enhydra.jawe.xml.panels;
13
14 import org.enhydra.jawe.xml.*;
15
16 import javax.swing.*;
17 import javax.swing.border.*;
18
19 import java.awt.*;
20
21 public class XMLPanel extends JPanel {
22
23    public static int GRID_LAYOUT=0;
24    public static int BOX_LAYOUT=1;
25
26    private XMLElement myOwner;
27    private String JavaDoc title;
28
29    public XMLPanel () {
30       super();
31    }
32
33    public XMLPanel (XMLElement myOwner,int noOfElements,String JavaDoc title,int layout,
34       boolean isVertical,boolean hasBorder) {
35
36       super();
37
38       this.myOwner=myOwner;
39
40       setTitle(title,hasBorder);
41
42       if (layout==XMLPanel.BOX_LAYOUT) {
43          setLayout(new BoxLayout(this,((isVertical) ? BoxLayout.Y_AXIS:BoxLayout.X_AXIS)));
44       }
45       else {
46          setLayout(new GridLayout
47             (((isVertical) ? noOfElements : 1),((isVertical) ? 1 : noOfElements)));
48       }
49       setAlignmentX(Component.LEFT_ALIGNMENT);
50       setAlignmentY(Component.TOP_ALIGNMENT);
51
52       if (myOwner!=null) {
53          setEnabled(!myOwner.isReadOnly());
54       }
55
56    }
57
58    public void setTitle (String JavaDoc title,boolean hasBorder) {
59       this.title=title;
60
61       int emptyBorderHSize=5;
62       int emptyBorderVSize=1;
63
64       Border emptyb=BorderFactory.createEmptyBorder(emptyBorderVSize,emptyBorderHSize,
65          emptyBorderVSize,emptyBorderHSize);
66       Border inb=BorderFactory.createEmptyBorder(0,0,0,0);
67       if (hasBorder) {
68          inb=BorderFactory.createMatteBorder(1,1,1,1,Color.darkGray);
69          inb=BorderFactory.createTitledBorder(inb,title);
70       }
71       else {
72          emptyb=BorderFactory.createTitledBorder(emptyb,title);
73       }
74       setBorder(BorderFactory.createCompoundBorder(emptyb,inb));
75    }
76
77    public static void defaultErrorMessage (Window w,String JavaDoc elementTitle) {
78       String JavaDoc message=XMLUtil.getLanguageDependentString("ErrorValueMustBeDefined");
79       String JavaDoc dialogTitle=XMLUtil.getLanguageDependentString("DialogValueIsNotDefined");
80       XMLPanel.errorMessage(w,dialogTitle,elementTitle,message);
81    }
82
83    public static void errorMessage (Window w,String JavaDoc dialogTitle,String JavaDoc elementTitle,String JavaDoc message) {
84       JOptionPane.showMessageDialog(w,elementTitle+message,
85          dialogTitle,JOptionPane.ERROR_MESSAGE);
86    }
87
88    public XMLElement getOwner () {
89       return myOwner;
90    }
91
92    public String JavaDoc getTitle() {
93       return title;
94    }
95
96    /**
97    * Checks if the element that owns panel
98    */

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

117    public JDialog getDialog () {
118       for (Container p = getParent(); p != null; p = p.getParent()) {
119          if (p instanceof JDialog) {
120             return (JDialog)p;
121          }
122       }
123       return null;
124    }
125
126 }
127
Popular Tags