ProgramTextCreator.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
util.program |
![]() |
![]() |
TV-Browser |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* TV-Browser
* Copyright (C) 04-2003 Martin Oberhauser (darras@users.sourceforge.net)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* CVS information:
* $RCSfile$
* $Source$
* $Date: 2008-07-31 16:40:06 -0400 (Thu, 31 Jul 2008) $
* $Author: Bananeweizen $
* $Revision: 4874 $
*/
package util.program;
import java.awt.Font;
import java.util.ArrayList;
import java.util.Arrays;
import java.text.DecimalFormat;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import tvbrowser.extras.common.InternalPluginProxyIf;
import tvbrowser.extras.common.InternalPluginProxyList;
import tvbrowser.extras.favoritesplugin.FavoritesPluginProxy;
import tvbrowser.extras.favoritesplugin.core.Favorite;
import tvbrowser.extras.favoritesplugin.dlgs.FavoriteTreeModel;
import util.settings.PluginPictureSettings;
import util.settings.ProgramPanelSettings;
import util.ui.Localizer;
import util.ui.UiUtilities;
import util.ui.html.ExtendedHTMLDocument;
import util.ui.html.HTMLTextHelper;
import util.ui.html.HorizontalLine;
import devplugin.Date;
import devplugin.Marker;
import devplugin.Plugin;
import devplugin.PluginAccess;
import devplugin.Program;
import devplugin.ProgramFieldType;
import devplugin.ProgramInfoHelper;
/**
* Creates the String for the ProgramInfoDialog
*/
public class ProgramTextCreator {
/**
* The Localizer for this class.
*/
private static final util.ui.Localizer mLocalizer = util.ui.Localizer
.getLocalizerFor(ProgramTextCreator.class);
private static String mBodyFontSize;
/** The used link protocol for actor links */
public static final String TVBROWSER_URL_PROTOCOL = "tvbrowser://";
/**
*
* @param prog
* The Program to show
* @param doc
* The HTMLDocument.
* @param fieldArr The object array with the field types.
* @param tFont The title Font.
* @param bFont The body Font.
* @param showImage If the image should be shown if it is available.
* @param showHelpLinks Show the Help-Links (Quality of Data, ShowView)
* @return The HTML String.
*/
public static String createInfoText(Program prog, ExtendedHTMLDocument doc,
Object[] fieldArr, Font tFont, Font bFont, boolean showImage, boolean showHelpLinks) {
return createInfoText(prog,doc,fieldArr,tFont,bFont,new ProgramPanelSettings(showImage ? ProgramPanelSettings.SHOW_PICTURES_EVER : ProgramPanelSettings.SHOW_PICTURES_NEVER, -1, -1, false, true, 10),showHelpLinks, 100);
}
/**
*
* @param prog
* The Program to show
* @param doc
* The HTMLDocument.
* @param fieldArr
* The object array with the field types.
* @param tFont
* The title Font.
* @param bFont
* The body Font.
* @param settings
* Settings of the ProgramPanel
* @param showHelpLinks
* Show the Help-Links (Quality of Data, ShowView)
* @param zoom The zoom value for the picture.
* @return The HTML String.
* @since 2.2.2
*/
public static String createInfoText(Program prog, ExtendedHTMLDocument doc,
Object[] fieldArr, Font tFont, Font bFont, ProgramPanelSettings settings,
boolean showHelpLinks, int zoom) {
return createInfoText(prog,doc,fieldArr,tFont,bFont,settings,showHelpLinks, zoom, true);
}
/**
*
* @param prog
* The Program to show
* @param doc
* The HTMLDocument.
* @param fieldArr
* The object array with the field types.
* @param tFont
* The title Font.
* @param bFont
* The body Font.
* @param settings
* Settings of the ProgramPanel
* @param showHelpLinks
* Show the Help-Links (Quality of Data, ShowView)
* @param zoom The zoom value for the picture.
* @return The HTML String.
* @since 2.6
*/
public static String createInfoText(Program prog, ExtendedHTMLDocument doc,
Object[] fieldArr, Font tFont, Font bFont, PluginPictureSettings settings,
boolean showHelpLinks, int zoom) {
return createInfoText(prog,doc,fieldArr,tFont,bFont,new ProgramPanelSettings(settings,false),showHelpLinks, zoom, true);
}
/**
*
* @param prog
* The Program to show
* @param doc
* The HTMLDocument.
* @param fieldArr
* The object array with the field types.
* @param tFont
* The title Font.
* @param bFont
* The body Font.
* @param settings
* Settings of the ProgramPanel
* @param showHelpLinks
* Show the Help-Links (Quality of Data, ShowView)
* @param zoom The zoom value for the picture.
* @param showPluginIcons If the plugin icons should be shown.
* @return The HTML String.
* @since 2.5.3
*/
public static String createInfoText(Program prog, ExtendedHTMLDocument doc,
Object[] fieldArr, Font tFont, Font bFont, ProgramPanelSettings settings,
boolean showHelpLinks, int zoom, boolean showPluginIcons) {try {
// NOTE: All field types are included until type 25 (REPETITION_ON_TYPE)
StringBuffer buffer = new StringBuffer();
String titleFont, titleSize, bodyFont;
if (tFont == null && bFont != null) {
titleFont = bodyFont = bFont.getFamily();
titleSize = mBodyFontSize = String.valueOf(bFont.getSize());
} else if (tFont != null && bFont != null) {
titleFont = tFont.getFamily();
bodyFont = bFont.getFamily();
titleSize = String.valueOf(tFont.getSize());
mBodyFontSize = String.valueOf(bFont.getSize());
} else {
return null;
}
if (fieldArr == null) {
return null;
}
buffer.append("<html>");
buffer.append("<table width=\"100%\" style=\"font-family:");
buffer.append(bodyFont);
buffer.append(";\"><tr>");
buffer.append("<td width=\"60\">");
buffer.append("<p \"align=center\">");
JLabel channelLogo = new JLabel(prog.getChannel().getIcon());
channelLogo.setToolTipText(prog.getChannel().getName());
buffer.append(doc.createCompTag(channelLogo));
buffer.append("</p></td><td>");
buffer.append("<div style=\"color:#ff0000; font-size:");
buffer.append(mBodyFontSize);
buffer.append(";\"><b>");
if(prog.getDate().equals(Date.getCurrentDate().addDays(-1))) {
buffer.append(Localizer.getLocalization(Localizer.I18N_YESTERDAY));
buffer.append(" ∑ ").append(prog.getDateString());
}
else if(prog.getDate().equals(Date.getCurrentDate())){
buffer.append(Localizer.getLocalization(Localizer.I18N_TODAY));
buffer.append(" ∑ ").append(prog.getDateString());
}
else if(prog.getDate().equals(Date.getCurrentDate().addDays(1))){
buffer.append(Localizer.getLocalization(Localizer.I18N_TOMORROW));
buffer.append(" ∑ ").append(prog.getDateString());
}
else {
buffer.append(prog.getDateString());
}
buffer.append(" ∑ ");
buffer.append(prog.getTimeString());
if (prog.getLength() > 0) {
buffer.append("-");
buffer.append(prog.getEndTimeString());
}
buffer.append(" ∑ ");
buffer.append(prog.getChannel());
buffer.append("</b></div><div style=\"color:#003366; font-size:");
buffer.append(titleSize);
buffer.append("; line-height:2.5em; font-family:");
buffer.append(titleFont);
buffer.append("\"><b>");
buffer.append(prog.getTitle());
buffer.append("</b></div>");
String episode = CompoundedProgramFieldType.EPISODE_COMPOSITION.getFormatedValueForProgram(prog);
if (episode != null && episode.trim().length() > 0) {
buffer.append("<div style=\"color:#808080; font-size:");
buffer.append(mBodyFontSize);
buffer.append("\">");
buffer.append(episode);
buffer.append("</div>");
}
buffer.append("</td></tr>");
boolean show = false;
if(settings.isShowingPictureForPlugins()) {
String[] pluginIds = settings.getPluginIds();
Marker[] markers = prog.getMarkerArr();
if(markers != null && pluginIds != null) {
for (Marker marker : markers) {
for (String pluginId : pluginIds) {
if(marker.getId().compareTo(pluginId) == 0) {
show = true;
break;
}
}
}
}
}
if(settings.isShowingPictureEver() ||
(settings.isShowingPictureInTimeRange() && !ProgramUtilities.isNotInTimeRange(settings.getPictureTimeRangeStart(),settings.getPictureTimeRangeEnd(), prog)) ||
show || (settings.isShowingPictureForDuration() && settings.getDuration() <= prog.getLength())) {
byte[] image = prog.getBinaryField(ProgramFieldType.PICTURE_TYPE);
if (image != null) {
String line = "<tr><td></td><td valign=\"top\" style=\"color:black; font-size:0\">";
buffer.append(line);
try {
ImageIcon imageIcon = new ImageIcon(image);
if(zoom != 100) {
imageIcon = (ImageIcon)UiUtilities.scaleIcon(imageIcon, imageIcon.getIconWidth() * zoom/100);
}
StringBuffer value = new StringBuffer();
if(prog.getTextField(ProgramFieldType.PICTURE_COPYRIGHT_TYPE) != null) {
value.append(prog.getTextField(ProgramFieldType.PICTURE_COPYRIGHT_TYPE));
}
if(settings.isShowingPictureDescription() && prog.getTextField(ProgramFieldType.PICTURE_DESCRIPTION_TYPE) != null) {
value.append("<br>").append(prog.getTextField(ProgramFieldType.PICTURE_DESCRIPTION_TYPE));
}
buffer.append(doc.createCompTag(new JLabel(imageIcon)));
buffer.append("<div style=\"font-size:");
buffer.append(mBodyFontSize);
buffer.append("\">");
buffer.append(value);
buffer.append("</div>");
buffer.append("</td></tr>");
} catch (Exception e) {
// Picture was wrong;
buffer.delete(buffer.length() - line.length(), buffer.length());
}
}
}
Marker[] pluginArr = prog.getMarkerArr();
if (showPluginIcons && (pluginArr != null) && (pluginArr.length != 0)) {
addSeparator(doc, buffer);
buffer.append("<tr><td valign=\"top\" style=\"color:#808080; font-size:");
buffer.append(mBodyFontSize);
buffer.append("\"><b>");
buffer.append(mLocalizer.msg("markedBy", "Marked by"));
buffer.append("</b></td><td valign=\"middle\" style=\"font-size:4\">");
openPara(buffer, "info");
// Workaround: Without the the component are not put in one line.
buffer.append(" ");
for (int markerCount = pluginArr.length-1; markerCount >= 0; markerCount--) {
Icon[] icons = pluginArr[markerCount].getMarkIcons(prog);
if (icons != null) {
for(int i = icons.length - 1; i >= 0 ; i--) {
JLabel iconLabel = new JLabel(icons[i]);
PluginAccess plugin = Plugin.getPluginManager()
.getActivatedPluginForId(pluginArr[markerCount].getId());
if (plugin != null) {
iconLabel.setToolTipText(plugin.getInfo().getName());
}
else {
InternalPluginProxyIf internalPlugin = InternalPluginProxyList.getInstance().getProxyForId(pluginArr[markerCount].getId());
if (internalPlugin != null) {
iconLabel.setToolTipText(internalPlugin.getName());
if (internalPlugin.equals(FavoritesPluginProxy.getInstance())) {
// if this is a favorite, add the names of the favorite
String favTitles = "";
for (Favorite favorite : FavoriteTreeModel.getInstance().getFavoritesContainingProgram(prog)) {
if (favTitles.length() > 0) {
favTitles = favTitles + ", ";
}
favTitles = favTitles + favorite.getName();
}
if (favTitles.length() > 0) {
iconLabel.setToolTipText(iconLabel.getToolTipText() + " (" + favTitles + ")");
}
}
}
else {
iconLabel.setToolTipText(pluginArr[markerCount].toString());
}
}
buffer.append(doc.createCompTag(iconLabel));
buffer.append(" ");
}
}
}
closePara(buffer);
buffer.append("</td></tr>");
}
PluginAccess[] plugins = Plugin.getPluginManager().getActivatedPlugins();
ArrayList<JLabel> iconLabels = new ArrayList<JLabel>();
for (PluginAccess plugin : plugins) {
Icon[] icons = plugin.getProgramTableIcons(prog);
if (icons != null) {
for (Icon icon : icons) {
JLabel iconLabel = new JLabel(icon);
iconLabel.setToolTipText(plugin.getInfo().getName());
iconLabels.add(iconLabel);
}
}
}
if (showPluginIcons && iconLabels.size() > 0) {
addSeparator(doc, buffer);
buffer
.append("<tr><td valign=\"middle\" style=\"color:#808080; font-size:");
buffer.append(mBodyFontSize);
buffer.append("\"><b>");
buffer.append("Plugin-Icons");
buffer.append("</b></td><td valign=\"top\" style=\"font-size:4\">");
openPara(buffer, "info");
// Workaround: Without the the component are not put in one line.
buffer.append(" ");
for (JLabel iconLabel : iconLabels) {
buffer.append(doc.createCompTag(iconLabel));
buffer.append(" ");
}
closePara(buffer);
buffer.append("</td></tr>");
}
addSeparator(doc, buffer);
for (Object id : fieldArr) {
ProgramFieldType type = null;
if (id instanceof String) {
if (((String) id).matches("\\d+")) {
try {
type = ProgramFieldType
.getTypeForId(Integer.parseInt((String) id, 10));
} catch (Exception e) {
// Empty Catch
}
}
if (type == null) {
int length = prog.getLength();
if (length > 0 && ((String) id).trim().length() > 0) {
buffer
.append("<tr><td valign=\"top\" style=\"color:gray; font-size:");
buffer.append(mBodyFontSize);
buffer.append("\"><b>");
buffer.append(mLocalizer.msg("duration",
"Program duration/<br>-end"));
buffer.append("</b></td><td style=\"font-size:");
buffer.append(mBodyFontSize);
buffer.append("\">");
openPara(buffer, "time");
String msg = mLocalizer.msg("minutes", "{0} min", length);
buffer.append(msg).append(" (");
buffer.append(mLocalizer.msg("until", "until {0}", prog.getEndTimeString()));
int netLength = prog
.getIntField(ProgramFieldType.NET_PLAYING_TIME_TYPE);
if (netLength != -1) {
msg = mLocalizer.msg("netMinuted", "{0} min net", netLength);
buffer.append(" - ").append(msg);
}
buffer.append(")");
closePara(buffer);
buffer.append("</td></tr>");
addSeparator(doc, buffer);
}
}
} else if(id instanceof CompoundedProgramFieldType) {
CompoundedProgramFieldType value = (CompoundedProgramFieldType) id;
String entry = value.getFormatedValueForProgram(prog);
if(entry != null) {
startInfoSection(buffer, value.getName());
buffer.append(HTMLTextHelper.convertTextToHtml(entry, false));
addSeparator(doc,buffer);
}
}
else {
type = (ProgramFieldType) id;
if (type == ProgramFieldType.DESCRIPTION_TYPE) {
if (prog.getDescription() != null
&& prog.getDescription().trim().length() > 0) {
addEntry(doc, buffer, prog, ProgramFieldType.DESCRIPTION_TYPE, true,
showHelpLinks);
} else {
addEntry(doc, buffer, prog, ProgramFieldType.SHORT_DESCRIPTION_TYPE,
true, showHelpLinks);
}
} else if (type == ProgramFieldType.INFO_TYPE) {
int info = prog.getInfo();
if ((info != -1) && (info != 0)) {
buffer
.append("<tr><td valign=\"top\" style=\"color:gray; font-size:");
buffer.append(mBodyFontSize);
buffer.append("\"><b>");
buffer
.append(type.getLocalizedName());
buffer
.append("</b></td><td valign=\"middle\" style=\"font-size:5\">");
openPara(buffer, "info");
// Workaround: Without the the component are not put in one
// line.
buffer.append(" ");
int[] infoBitArr = ProgramInfoHelper.mInfoBitArr;
Icon[] infoIconArr = ProgramInfoHelper.mInfoIconArr;
String[] infoMsgArr = ProgramInfoHelper.mInfoMsgArr;
for (int i = 0; i < infoBitArr.length; i++) {
if (ProgramInfoHelper.bitSet(info, infoBitArr[i])) {
if (infoIconArr[i] != null) {
JLabel iconLabel = new JLabel(infoIconArr[i]);
iconLabel.setToolTipText(infoMsgArr[i]);
buffer.append(doc.createCompTag(iconLabel));
} else {
buffer.append(infoMsgArr[i]);
}
buffer.append(" ");
}
}
closePara(buffer);
buffer.append("</td></tr>");
addSeparator(doc, buffer);
}
} else if (type == ProgramFieldType.URL_TYPE) {
addEntry(doc, buffer, prog, ProgramFieldType.URL_TYPE, true,
showHelpLinks);
} else if (type == ProgramFieldType.ACTOR_LIST_TYPE) {
ArrayList<String> knownNames = new ArrayList<String>();
String[] recognizedActors = ProgramUtilities.getActorNames(prog);
if (recognizedActors != null) {
knownNames.addAll(Arrays.asList(recognizedActors));
}
String actorField = prog.getTextField(type);
if (actorField != null) {
ArrayList<String>[] lists = ProgramUtilities.splitActors(prog);
if (lists == null) {
lists = splitActorsSimple(prog);
}
if (lists != null && lists[0].size() > 0) {
startInfoSection(buffer, type.getLocalizedName());
buffer.append("<table border=\"0\" cellpadding=\"0\" style=\"font-family:");
buffer.append(bodyFont);
buffer.append(";\">");
for (int i=0; i < lists[0].size(); i++) {
String[] parts = new String[2];
parts[0] = lists[0].get(i);
parts[1] = "";
if (i < lists[1].size()) {
parts[1] = lists[1].get(i);
}
int actorIndex = 0;
if (knownNames.contains(parts[0])) {
parts[0] = addWikiLink(parts[0]);
}
else if (knownNames.contains(parts[1])) {
parts[1] = addWikiLink(parts[1]);
actorIndex = 1;
}
buffer.append("<tr><td valign=\"top\">• </td><td valign=\"top\">");
buffer.append(parts[actorIndex]);
buffer.append("</td><td width=\"10\"> </td>");
if (parts[1-actorIndex].length() > 0) {
buffer.append("<td valign=\"top\">");
buffer.append(parts[1-actorIndex]);
buffer.append("</td>");
} else {
// if roles are missing add next actor in the same line
if (i+1 < lists[0].size() && lists[1].size() == 0) {
i++;
buffer.append("<td valign=\"top\">• </td><td valign=\"top\">");
buffer.append(addWikiLink(lists[0].get(i)));
buffer.append("</td>");
}
}
buffer.append("</td></tr>");
}
buffer.append("</table>");
buffer.append("</td></tr>");
addSeparator(doc, buffer);
}
else {
addEntry(doc, buffer, prog, type, showHelpLinks);
}
}
}
else {
addEntry(doc, buffer, prog, type, showHelpLinks);
}
}
}
if (showHelpLinks) {
buffer
.append("<tr><td colspan=\"2\" valign=\"top\" align=\"center\" style=\"color:#808080; font-size:");
buffer.append(mBodyFontSize).append("\">");
buffer.append("<a href=\"");
buffer.append(
mLocalizer.msg("dataInfo",
"http://wiki.tvbrowser.org/index.php/Qualit%C3%A4t_der_Daten"))
.append("\">");
buffer.append(mLocalizer
.msg("dataQuality", "Details of the data quality"));
buffer.append("</a>");
buffer.append("</td></tr>");
}
buffer.append("</table></html>");
return buffer.toString();}catch(Exception e) {e.printStackTrace();}
return "";
}
private static ArrayList<String>[] splitActorsSimple(Program prog) {
@SuppressWarnings("unchecked")
ArrayList<String> list1 = new ArrayList();
@SuppressWarnings("unchecked")
ArrayList<String> list2 = new ArrayList();
String actorField = prog.getTextField(ProgramFieldType.ACTOR_LIST_TYPE).trim();
String[] actors;
// don't try any parsing if newlines and commas are available
// this must be recognized by the more advanced actors parsing
if (actorField.contains("\n")) {
if (actorField.contains(",")) {
return null;
}
actors = actorField.split("\n");
}
else if (actorField.contains(",")) {
actors = actorField.split(",");
}
else if (actorField.contains("\t")) {
actors = new String[1];
actors[0] = actorField;
}
else {
return null;
}
for (String actor : actors) {
actor = actor.trim();
if (actor.length() > 0) {
String part1 = actor;
String part2 = "";
if (actor.contains("\t")) {
part1 = actor.substring(0, actor.indexOf("\t")).trim();
part2 = actor.substring(actor.indexOf("\t")).trim();
}
else if (actor.contains("(") && actor.contains(")")) {
part1 = actor.substring(0, actor.indexOf("(")).trim();
part2 = actor.substring(actor.indexOf("(")+1, actor.lastIndexOf(")")).trim();
}
list1.add(part1);
list2.add(part2);
}
}
@SuppressWarnings("unchecked")
ArrayList<String>[] result = new ArrayList[2];
result[0] = list1;
result[1] = list2;
return result;
}
private static String addSearchLink(String topic, String displayText) {
String style = " style=\"color:black; border-bottom: 1px dashed;\"";
StringBuffer buffer = new StringBuffer();
buffer.append("<a href=\"");
buffer.append(TVBROWSER_URL_PROTOCOL);
buffer.append(topic.replaceAll("\"", "").replaceAll("'", ""));
buffer.append("\" ");
buffer.append(style);
buffer.append(">");
buffer.append(displayText);
buffer.append("</a>");
return buffer.toString();
}
private static String addWikiLink(String topic) {
String[] parts = topic.split(" und ");
String result = "";
for (int i = 0; i < parts.length; i++) {
result = result + addSearchLink(parts[i], parts[i]);
if (i < parts.length - 1) {
result = result + " und ";
}
}
return result;
}
private static String[] splitList(String field) {
String[] items;
if (field.contains("\n")) {
items = field.split("\n");
}
else if (field.contains(",")) {
items = field.split(",");
}
else {
items = new String[1];
items[0] = field;
}
for (int i = 0; i < items.length; i++) {
items[i] = items[i].trim();
if (items[i].endsWith(",")) {
items[i] = items[i].substring(0, items[i].length() - 1);
}
}
return items;
}
private static void addEntry(ExtendedHTMLDocument doc, StringBuffer buffer,
Program prog, ProgramFieldType fieldType, boolean showHelpLinks) {
addEntry(doc, buffer, prog, fieldType, false, showHelpLinks);
}
private static void addEntry(ExtendedHTMLDocument doc, StringBuffer buffer,
Program prog, ProgramFieldType fieldType, boolean createLinks,
boolean showHelpLinks) {
String text = null;
String name = fieldType.getLocalizedName();
int blank = name.indexOf(' ', 16);
if (blank > 0) {
name = name.substring(0, blank) + "<br>" + name.substring(blank +1);
}
if (fieldType.getFormat() == ProgramFieldType.TEXT_FORMAT) {
if (fieldType == ProgramFieldType.DESCRIPTION_TYPE) {
String description = prog.getDescription().trim();
if (prog.getShortInfo() != null) {
StringBuffer shortInfo = new StringBuffer(prog.getShortInfo().trim());
while (shortInfo.toString().endsWith(".")) {
shortInfo.deleteCharAt(shortInfo.length() - 1);
}
if (!description.trim().startsWith(shortInfo.toString())) {
addEntry(doc, buffer, prog,
ProgramFieldType.SHORT_DESCRIPTION_TYPE, true, showHelpLinks);
}
}
}
text = prog.getTextField(fieldType);
} else if (fieldType.getFormat() == ProgramFieldType.TIME_FORMAT) {
text = prog.getTimeFieldAsString(fieldType);
} else if (fieldType.getFormat() == ProgramFieldType.INT_FORMAT) {
if (fieldType == ProgramFieldType.RATING_TYPE) {
int value = prog.getIntField(fieldType);
if (value > -1) {
text = new DecimalFormat("##.#").format((double)prog.getIntField(fieldType) / 10) + "/10";
}
} else {
text = prog.getIntFieldAsString(fieldType);
}
}
if (fieldType == ProgramFieldType.ORIGIN_TYPE) {
String temp = prog
.getIntFieldAsString(ProgramFieldType.PRODUCTION_YEAR_TYPE);
if (temp != null && temp.trim().length() > 0) {
if (text == null || text.trim().length() < 1) {
name = ProgramFieldType.PRODUCTION_YEAR_TYPE.getLocalizedName();
text = temp;
} else {
name += "/<br>"
+ ProgramFieldType.PRODUCTION_YEAR_TYPE.getLocalizedName();
text += " " + temp;
}
}
}
if (text == null || text.trim().length() < 1) {
if (ProgramFieldType.SHOWVIEW_NR_TYPE == fieldType) {
text = mLocalizer.msg("noShowview", "No Showview data ");
} else {
return;
}
}
startInfoSection(buffer, name);
// add wikipedia links
if (ProgramFieldType.DIRECTOR_TYPE == fieldType
|| ProgramFieldType.SCRIPT_TYPE == fieldType
|| ProgramFieldType.CAMERA_TYPE == fieldType
|| ProgramFieldType.CUTTER_TYPE == fieldType
|| ProgramFieldType.MUSIC_TYPE == fieldType
|| ProgramFieldType.MODERATION_TYPE == fieldType) {
String[] persons = splitList(text);
for (int i = 0; i < persons.length; i++) {
String topic;
if (persons[i].contains("(")) {
topic = persons[i].substring(0, persons[i].indexOf("("));
persons[i] = addSearchLink(topic, persons[i]);
} else {
persons[i] = addWikiLink(persons[i]);
}
}
buffer.append(concatList(persons));
}
else {
buffer.append(HTMLTextHelper.convertTextToHtml(text, createLinks));
}
if ((ProgramFieldType.SHOWVIEW_NR_TYPE == fieldType) && (showHelpLinks)) {
buffer.append(" (<a href=\"").append(
mLocalizer.msg("showviewInfo",
"http://wiki.tvbrowser.org/index.php/Showviewnummern")).append(
"\">?</a>)");
}
buffer.append("</td></tr>");
addSeparator(doc, buffer);
}
private static String concatList(String[] strings) {
String result = "";
for (int i = 0; i < strings.length; i++) {
if (i > 0) {
result = result + ", ";
}
result = result + strings[i];
}
return result;
}
private static void startInfoSection(StringBuffer buffer, String section) {
buffer.append("<tr><td valign=\"top\" style=\"color:#808080; font-size:");
buffer.append(mBodyFontSize);
buffer.append("\"><b>");
buffer.append(section);
buffer.append("</b></td><td style=\"font-size:");
buffer.append(mBodyFontSize);
buffer.append("\">");
}
private static void addSeparator(ExtendedHTMLDocument doc, StringBuffer buffer) {
buffer.append("<tr><td colspan=\"2\">");
buffer.append("<div style=\"font-size:0;\">").append(
doc.createCompTag(new HorizontalLine())).append("</div></td></tr>");
}
private static void openPara(StringBuffer buffer, String style) {
buffer.append("<div id=\"").append(style).append("\">");
}
private static void closePara(StringBuffer buffer) {
buffer.append("</div>\n");
}
/**
*
* @return The default order of the entries.
*/
public static Object[] getDefaultOrder() {
return new Object[] {
ProgramFieldType.GENRE_TYPE,
ProgramFieldType.DESCRIPTION_TYPE,
ProgramFieldType.RATING_TYPE,
ProgramFieldType.ORIGIN_TYPE,
ProgramFieldType.DIRECTOR_TYPE,
ProgramFieldType.SCRIPT_TYPE,
ProgramFieldType.ACTOR_LIST_TYPE,
ProgramFieldType.MODERATION_TYPE,
ProgramFieldType.MUSIC_TYPE,
ProgramFieldType.PRODUCER_TYPE,
ProgramFieldType.CAMERA_TYPE,
ProgramFieldType.CUTTER_TYPE,
ProgramFieldType.ADDITIONAL_PERSONS_TYPE,
ProgramFieldType.URL_TYPE,
ProgramFieldType.ORIGINAL_TITLE_TYPE,
ProgramFieldType.ORIGINAL_EPISODE_TYPE,
ProgramFieldType.PROCUCTION_COMPANY_TYPE,
ProgramFieldType.REPETITION_OF_TYPE,
ProgramFieldType.REPETITION_ON_TYPE, ProgramFieldType.AGE_LIMIT_TYPE,
ProgramFieldType.INFO_TYPE, ProgramFieldType.VPS_TYPE,
ProgramFieldType.SHOWVIEW_NR_TYPE,
getDurationTypeString() };
}
/**
* @return The String for the duration/end of a program.
*/
public static String getDurationTypeString() {
return mLocalizer.msg("duration", "Program duration/<br>-end").replaceAll(
"<br>", "");
}
}
The table below shows all metrics for ProgramTextCreator.java.




