KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* XMLLocationPanel.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 java.util.*;
17 import javax.swing.*;
18 import java.awt.*;
19 import java.awt.event.*;
20
21 /**
22 * Creates panel with JLabel, JTextField and JButton, this panel is
23 * used to set the file name from some choosed location.
24 */

25 public class XMLLocationPanel extends XMLPanel {
26
27    private static Dimension locationDimension=new Dimension(175,20);
28    private static Dimension fileButtonDimension=new Dimension(25,20);
29
30
31    public XMLLocationPanel (XMLElement myOwner) {
32       this(myOwner,XMLPanel.BOX_LAYOUT);
33    }
34
35    public XMLLocationPanel (XMLElement myOwner,int layout) {
36       this(myOwner,XMLPanel.BOX_LAYOUT,-1);
37    }
38
39    public XMLLocationPanel (XMLElement myOwner,int layout,final int filteringMode) {
40
41       super(myOwner,4,"",layout,false,false);
42
43       JLabel jl=new JLabel(myOwner.toLabel()+": ");
44       jl.setAlignmentX(Component.LEFT_ALIGNMENT);
45       jl.setAlignmentY(Component.BOTTOM_ALIGNMENT);
46       jl.setHorizontalAlignment(SwingConstants.RIGHT);
47       //jl.setMaximumSize(new Dimension(Short.MAX_VALUE,10));
48

49       final JTextField jtf=new JTextField();
50       jtf.setText(myOwner.toValue().toString());
51       jtf.setAlignmentX(Component.LEFT_ALIGNMENT);
52       jtf.setAlignmentY(Component.BOTTOM_ALIGNMENT);
53       jtf.setMinimumSize(new Dimension(locationDimension));
54       jtf.setMaximumSize(new Dimension(locationDimension));
55       jtf.setPreferredSize(new Dimension(locationDimension));
56       jtf.setEnabled(!myOwner.isReadOnly());
57
58       JButton jb=new JButton("...");
59       jb.setAlignmentX(Component.LEFT_ALIGNMENT);
60       jb.setAlignmentY(Component.BOTTOM_ALIGNMENT);
61       jb.setMinimumSize(new Dimension(fileButtonDimension));
62       jb.setMaximumSize(new Dimension(fileButtonDimension));
63       jb.setPreferredSize(new Dimension(fileButtonDimension));
64       jb.setEnabled(!myOwner.isReadOnly());
65
66       add(Box.createHorizontalGlue());
67       add(jl);
68       add(jtf);
69       add(jb);
70
71       jb.addActionListener(new ActionListener(){
72          public void actionPerformed( ActionEvent ae ){
73             String JavaDoc fileName="";
74             String JavaDoc message=XMLUtil.getLanguageDependentString("DialogChooseFile");
75             fileName=XMLUtil.dialog(getDialog(),message,0,filteringMode,null);
76             if (fileName!=null && fileName.length()>0) {
77                jtf.setText(fileName);
78             }
79          }
80       });
81    }
82
83    public boolean checkRequired () {
84       if (isEmpty() && getOwner().isRequired()
85          && !getOwner().isReadOnly()) {
86
87          XMLPanel.defaultErrorMessage(this.getDialog(),((JLabel)getComponent(1)).getText());
88          ((JTextField)getComponent(2)).requestFocus();
89          return false;
90       }
91       return true;
92    }
93
94    public boolean isEmpty () {
95       return getText().trim().equals("");
96    }
97
98    public void setElements () {
99       getOwner().setValue(getText());
100    }
101
102    public String JavaDoc getText () {
103       return ((JTextField)getComponent(2)).getText();
104    }
105
106 }
107
108 /* End of DTDLocationPanel.java */
109
Popular Tags