KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* XMLMultiLineTextPanel.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
20
21 /**
22 * Creates panel with JLabel and JTextArea.
23 */

24 public class XMLMultiLineTextPanel extends XMLPanel {
25
26    public static Dimension textAreaDimension=new Dimension(200,60);
27
28    public XMLMultiLineTextPanel (XMLElement myOwner) {
29       this(myOwner,XMLPanel.BOX_LAYOUT);
30    }
31
32    public XMLMultiLineTextPanel (XMLElement myOwner,int layout) {
33       this(myOwner,layout,false,false,true);
34    }
35
36    public XMLMultiLineTextPanel (XMLElement myOwner,int layout,
37       boolean isVertical,boolean bigPanel,boolean wrapLines) {
38
39       super(myOwner,3,"",layout,isVertical,false);
40
41       JScrollPane jsp=new JScrollPane();
42       jsp.setAlignmentX(Component.LEFT_ALIGNMENT);
43       jsp.setAlignmentY(Component.TOP_ALIGNMENT);
44
45       JLabel jl=new JLabel(myOwner.toLabel()+": ");
46       jl.setAlignmentX(Component.LEFT_ALIGNMENT);
47       jl.setAlignmentY(Component.TOP_ALIGNMENT);
48       jl.setHorizontalAlignment(SwingConstants.RIGHT);
49
50       JTextArea jta=new JTextArea();
51
52       jta.setTabSize(4);
53       jta.setText(myOwner.toValue().toString());
54       jta.getCaret().setDot(0);
55       jta.setLineWrap(wrapLines);
56       jta.setWrapStyleWord(wrapLines);
57
58       jta.setAlignmentX(Component.LEFT_ALIGNMENT);
59       jta.setAlignmentY(Component.TOP_ALIGNMENT);
60
61       jta.setEnabled(!myOwner.isReadOnly());
62
63       jsp.setViewportView(jta);
64       jsp.setAlignmentX(Component.LEFT_ALIGNMENT);
65       jsp.setAlignmentY(Component.TOP_ALIGNMENT);
66       if (!bigPanel) {
67          jsp.setPreferredSize(new Dimension(textAreaDimension));
68       } else {
69          jsp.setPreferredSize(new Dimension(400,300));
70       }
71       add(Box.createHorizontalGlue());
72       add(jl);
73       add(jsp);
74    }
75
76    public boolean checkRequired () {
77       if (isEmpty() && getOwner().isRequired() && !getOwner().isReadOnly()) {
78
79          XMLPanel.defaultErrorMessage(this.getDialog(),((JLabel)getComponent(1)).getText());
80          JScrollPane jsp=(JScrollPane)getComponent(2);
81          JViewport jvp=(JViewport)jsp.getComponent(0);
82          ((JTextArea)jvp.getComponent(0)).requestFocus();
83          return false;
84       }
85       return true;
86    }
87
88    public boolean isEmpty () {
89       return getText().trim().equals("");
90    }
91
92    public void setElements () {
93       getOwner().setValue(getText());
94    }
95
96    public String JavaDoc getText () {
97       JScrollPane jsp=(JScrollPane)getComponent(2);
98       JViewport jvp=(JViewport)jsp.getComponent(0);
99       return ((JTextArea)jvp.getComponent(0)).getText();
100    }
101
102 }
103
Popular Tags