--- title: TextArea order: 10 layout: page --- [[components.textarea]] = TextArea ifdef::web[] [.sampler] image:{live-demo-image}[alt="Live Demo", link="http://demo.vaadin.com/sampler/#ui/data-input/text-input/text-area"] endif::web[] [classname]#TextArea# is a multi-line version of the [classname]#TextField# component described in <>. The following example creates a simple text area: [source, java] ---- // Create the area TextArea area = new TextArea("Big Area"); // Put some content in it area.setValue("A row\n"+ "Another row\n"+ "Yet another row"); ---- The result is shown in <>. [[figure.components.textarea]] .[classname]#TextArea# Example image::img/textarea-basic.png[width=40%, scaledwidth=50%] You can set the number of visible rows with [methodname]#setRows()# or use the regular [methodname]#setHeight()# to define the height in other units. If the actual number of rows exceeds the number, a vertical scrollbar will appear. Setting the height with [methodname]#setRows()# leaves space for a horizontal scrollbar, so the actual number of visible rows may be one higher if the scrollbar is not visible. You can set the width with the regular [methodname]#setWidth()# method. Setting the size with the __em__ unit, which is relative to the used font size, is recommended. [[components.textarea.wordwrap]] == Word Wrap The [methodname]#setWordwrap()# sets whether long lines are wrapped ( [literal]#++true++# - default) when the line length reaches the width of the writing area. If the word wrap is disabled ( [literal]#++false++#), a vertical scrollbar will appear instead. The word wrap is only a visual feature and wrapping a long line does not insert line break characters in the field value; shortening a wrapped line will undo the wrapping. [source, java] ---- TextArea area1 = new TextArea("Wrapping"); area1.setWordWrap(true); // The default area1.setValue("A quick brown fox jumps over the lazy dog"); TextArea area2 = new TextArea("Nonwrapping"); area2.setWordWrap(false); area2.setValue("Victor jagt zwölf Boxkämpfer quer "+ "über den Sylter Deich"); ---- The result is shown in <>. [[figure.components.textarea.wordwrap]] .Word Wrap in [classname]#TextArea# image::img/textarea-wordwrap.png[width=60%, scaledwidth=100%] [[components.textarea.css]] == CSS Style Rules [source, css] ---- .v-textarea { } ---- The HTML structure of [classname]#TextArea# is extremely simple, consisting only of an element with [literal]#++v-textarea++# style. ed'>Temp_PDF_in_PDF Apache XML Graphics FOP: https://github.com/apache/xmlgraphics-fopwww-data
aboutsummaryrefslogtreecommitdiffstats
blob: c4eb1c1a5fc521a230dee90586477c2b1561ea05 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * $Id$
 * Copyright (C) 2002 The Apache Software Foundation. All rights reserved.
 * For details on use and redistribution please refer to the
 * LICENSE file included with these sources.
 */

package org.apache.fop.pdf;

import org.apache.fop.util.StreamUtilities;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.io.File;

/**
 * StreamCache implementation that uses temporary files rather than heap.
 */
public class TempFileStreamCache extends StreamCache {

    /**
     * The current output stream.
     */
    private BufferedOutputStream output;

    /**
     * The temp file.
     */
    private File tempFile;

    /**
     * Creates a new TempFileStreamCache.
     */
    public TempFileStreamCache() throws IOException {
        tempFile = File.createTempFile("org.apache.fop.pdf.StreamCache-",
                                       ".temp");
        tempFile.deleteOnExit();
    }

    /**
     * Get the current OutputStream. Do not store it - it may change
     * from call to call.
     */
    public OutputStream getOutputStream() throws IOException {
        if (output == null)
            output = new BufferedOutputStream(
                       new FileOutputStream(tempFile));
        return output;
    }

    /**
     * Filter the cache with the supplied PDFFilter.
     */
    public void applyFilter(PDFFilter filter) throws IOException {
        if (output == null)
            return;

        output.close();
        output = null;

        // need a place to put results
        File newTempFile =
          File.createTempFile("org.apache.fop.pdf.StreamCache-",
                              ".temp");
        newTempFile.deleteOnExit();

        // filter may not be buffered
        BufferedInputStream input =
          new BufferedInputStream(new FileInputStream(tempFile));
        BufferedOutputStream output = new BufferedOutputStream(
                                        new FileOutputStream(newTempFile));
        filter.encode(input, output, (int) tempFile.length());
        input.close();
        output.close();
        tempFile.delete();
        tempFile = newTempFile;
    }

    /**
     * Outputs the cached bytes to the given stream.
     */
    public void outputStreamData(OutputStream stream) throws IOException {
        if (output == null)
            return;

        output.close();
        output = null;

        // don't need a buffer because streamCopy is buffered
        FileInputStream input = new FileInputStream(tempFile);
        StreamUtilities.streamCopy(input, output);
        input.close();
    }

    /**
     * Returns the current size of the stream.
     */
    public int getSize() throws IOException {
        if (output != null)
            output.flush();
        return (int) tempFile.length();
    }

    /**
     * Closes the cache and frees resources.
     */
    public void close() throws IOException {
        if (output != null) {
            output.close();
            output = null;
        }
        if (tempFile.exists())
            tempFile.delete();
    }

    /**
     * Clears and resets the cache.
     */
    public void reset() throws IOException {
        if (output != null) {
            output.close();
            output = null;
        }
        if (tempFile.exists())
            tempFile.delete();
    }
}