01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.wicket.markup.html.basic;
18:
19: import org.apache.wicket.markup.ComponentTag;
20: import org.apache.wicket.markup.MarkupStream;
21: import org.apache.wicket.markup.html.WebComponent;
22: import org.apache.wicket.model.IModel;
23: import org.apache.wicket.model.Model;
24: import org.apache.wicket.util.string.Strings;
25:
26: /**
27: * A MultiLineLabel component replaces its body with the model object.
28: * <p>
29: * Unlike {@link Label}, {@link MultiLineLabel} shows text that spans multiple
30: * lines by inserting line breaks (<code>BR</code> tags) for newlines and
31: * paragraph markers (<code>P</code> tags) for sequences of more than one
32: * newline.
33: *
34: * @author Jonathan Locke
35: */
36: public class MultiLineLabel extends WebComponent {
37: private static final long serialVersionUID = 1L;
38:
39: /**
40: * Constructor. Same as Label(String).
41: *
42: * @param id
43: * See Component
44: * @see Label#Label(String)
45: */
46: public MultiLineLabel(final String id) {
47: super (id);
48: }
49:
50: /**
51: * Convenience constructor. Same as MultiLineLabel(String, new Model(String))
52: *
53: * @param id
54: * See Component
55: * @param label
56: * The label text
57: *
58: * @see org.apache.wicket.Component#Component(String, IModel)
59: */
60: public MultiLineLabel(final String id, String label) {
61: this (id, new Model(label));
62: }
63:
64: /**
65: * @see org.apache.wicket.Component#Component(String, IModel)
66: */
67: public MultiLineLabel(final String id, IModel model) {
68: super (id, model);
69: }
70:
71: /**
72: * @see org.apache.wicket.Component#onComponentTagBody(MarkupStream, ComponentTag)
73: */
74: protected void onComponentTagBody(final MarkupStream markupStream,
75: final ComponentTag openTag) {
76: final CharSequence body = Strings
77: .toMultilineMarkup(getModelObjectAsString());
78: replaceComponentTagBody(markupStream, openTag, body);
79: }
80: }
|