001 // This file is part of AceWiki. 002 // Copyright 2008-2012, AceWiki developers. 003 // 004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU 005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of 006 // the License, or (at your option) any later version. 007 // 008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 010 // Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If 013 // not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.acewiki.gui; 016 017 import java.util.List; 018 019 import nextapp.echo.app.Color; 020 import nextapp.echo.app.Row; 021 import ch.uzh.ifi.attempto.acewiki.Wiki; 022 import ch.uzh.ifi.attempto.acewiki.core.OntologyTextElement; 023 import ch.uzh.ifi.attempto.base.TextElement; 024 import ch.uzh.ifi.attempto.echocomp.HSpace; 025 import ch.uzh.ifi.attempto.echocomp.SolidLabel; 026 027 /** 028 * This component renders a CNL text into GUI elements. 029 * 030 * @author Tobias Kuhn 031 */ 032 public class TextRow extends Row { 033 034 private static final long serialVersionUID = -3410891086679856030L; 035 036 /** 037 * Creates a new text row with the given text. 038 * 039 * @param text The text as a list of text elements. 040 * @param wiki The wiki object. 041 * @param isRed true if the text color should be red. 042 */ 043 public TextRow(List<TextElement> text, Wiki wiki, boolean isRed) { 044 Color color = Color.BLACK; 045 if (isRed) { 046 color = new Color(180, 0, 0); 047 } 048 TextElement prev = null; 049 for (TextElement e : text) { 050 if (prev != null) { 051 String glue = wiki.getLanguageHandler().getTextOperator().getGlue(prev, e); 052 if (glue.matches("\\s+")) { 053 add(new HSpace(5 * glue.length())); 054 } else if (glue.length() > 0) { 055 add(new SolidLabel(glue)); 056 } 057 } 058 prev = e; 059 if (e instanceof OntologyTextElement) { 060 add(new WikiLink(((OntologyTextElement) e), wiki, isRed)); 061 } else { 062 SolidLabel l = new SolidLabel(e.getText()); 063 l.setForeground(color); 064 add(l); 065 } 066 } 067 } 068 069 /** 070 * Creates a new text row with the given text. 071 * 072 * @param text The text as a list of text elements. 073 * @param wiki The wiki object. 074 */ 075 public TextRow(List<TextElement> text, Wiki wiki) { 076 this(text, wiki, false); 077 } 078 079 }