KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > directory > jxplorer > editor > largestringeditor


1 package com.ca.directory.jxplorer.editor;
2
3 import com.ca.commons.cbutil.*;
4 import javax.swing.*;
5 import java.awt.*;
6
7 /**
8  * Creates a simple text editor for displaying very
9  * large text attributes.
10  * @author Chris.
11  */

12 public class largestringeditor extends CBDialog
13     implements abstractstringeditor
14 {
15     protected JTextArea area;
16     protected JScrollPane scroll;
17     protected editablestring editableText;
18
19     /**
20      * Construct the GUI, but do not initialise it with data (yet).
21      */

22     public largestringeditor(Frame owner, editablestring text)
23     {
24         super(owner, CBIntText.get("Simple Text Editor"), null);
25         setModal(true);
26         
27         area = new JTextArea();
28         area.setLineWrap(true); //TE: wrap the lines.
29

30         scroll = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); //TE: no horizontal scroll.
31
scroll.setViewport(new CBViewport());
32         scroll.getViewport().setView(area);
33         scroll.setPreferredSize(new Dimension(310,60));
34         
35         makeHeavy();
36         addln(scroll);
37         
38         setSize(500, 400);
39         
40         setStringValue(text);
41     }
42
43    /**
44     * Sets the attribute value in the text area of the attribute editor.
45     * @param originalText
46     */

47     public void setStringValue(editablestring originalText)
48     {
49         editableText = originalText;
50         area.setText(editableText.getStringValue());
51         JViewport port = scroll.getViewport();
52         if (port != null)
53             port.setViewPosition(new Point(0,0));
54         else
55             System.out.println("NULL VIEWPORT");
56     }
57
58    /**
59     * Sets the changed attribute value from the attribute editor in the table.
60     */

61     public void doOK()
62     {
63         String JavaDoc newAttribute = area.getText();
64         
65         //sets the attribute value to reflect the changes
66
//made in the attribute editor.
67

68         editableText.setStringValue(newAttribute);
69
70         super.doOK();
71     }
72 }
Popular Tags