* The program to show in this panel.
* @param maxHeight
* The maximum height the program should have (in pixels).
*/
public void setProgram(Program program, int maxHeight) {
Program oldProgram = mProgram;
mProgram = program;
if (Settings.propProgramTableCutTitle.getBoolean()) {
mTitleIcon.setMaximumLineCount(Settings.propProgramTableCutTitleLines
.getInt());
} else {
mTitleIcon.setMaximumLineCount(-1);
}
mDescriptionIcon.setMaximumLineCount(-1);
boolean programChanged = (oldProgram != program);
if (programChanged) {
// Get the start time, filter duplicate strings
mProgramTimeAsString = StringPool.getString(program.getTimeString());
// Set the new title
mTitleIcon.setText(program.getTitle());
if(mProgram.getProgramState() == Program.IS_VALID_STATE) {
programHasChanged();
}
}
boolean dontShow = true;
if(mSettings.isShowingPictureForPlugins()) {
String[] pluginIds = mSettings.getPluginIds();
Marker[] markers = mProgram.getMarkerArr();
if(markers != null && pluginIds != null) {
for (Marker marker : markers) {
for (String pluginId : pluginIds) {
if(marker.getId().compareTo(pluginId) == 0) {
dontShow = false;
break;
}
}
}
}
}
// Create the picture area icon
int length = program.getLength();
if (!mSettings.isShowingOnlyDateAndTitle()
&& mProgram.hasFieldValue(ProgramFieldType.PICTURE_TYPE)
&& (
mSettings.isShowingPictureEver() || !dontShow ||
(mSettings.isShowingPictureInTimeRange() &&
!ProgramUtilities.isNotInTimeRange(mSettings.getPictureTimeRangeStart(),mSettings.getPictureTimeRangeEnd(),program)) ||
(mSettings
.isShowingPictureForDuration() && mSettings.getDuration() <= length)
)) {
mPictureAreaIcon = new PictureAreaIcon(program,mNormalFont, WIDTH_RIGHT - 4, mSettings.isShowingPictureDescription(), true, false);
} else {
mPictureAreaIcon = new PictureAreaIcon();
}
// Calculate the maximum description lines
int titleHeight = mTitleIcon.getIconHeight();
int maxDescLines;
if (Settings.propProgramPanelShortDurationActive.getBoolean()
&& length >= 0
&& length <= Settings.propProgramPanelShortDurationMinutes.getInt()) {
maxDescLines = 0;
mDescriptionIcon.setText("");
mDescriptionIcon.setMaximumLineCount(0);
} else {
maxDescLines = Settings.propProgramPanelMaxLines.getInt();
}
int additionalHeight = Settings.propProgramPanelUsesExtraSpaceForMarkIcons.getBoolean() && program.getMarkerArr().length > 0 ? 16 : 0;
if (maxHeight != -1) {
maxDescLines = (maxHeight - titleHeight - mPictureAreaIcon.getIconHeight() - additionalHeight - V_GAP) / mNormalFont.getSize();
}
if (programChanged
|| (maxDescLines != mDescriptionIcon.getMaximumLineCount())) {
int descHeight = 0;
// (Re)set the description text
if (!mSettings.isShowingOnlyDateAndTitle() && maxDescLines > 0) {
mDescriptionIcon.setMaximumLineCount(maxDescLines);
ProgramFieldType[] infoFieldArr = Settings.propProgramInfoFields
.getProgramFieldTypeArray();
Reader infoReader = new MultipleFieldReader(program, infoFieldArr);
try {
mDescriptionIcon.setText(infoReader);
} catch (IOException exc) {
mLog.log(Level.WARNING, "Reading program info failed for " + program,
exc);
}
descHeight = mDescriptionIcon.getIconHeight();
} else {
descHeight = 0;
}
// Calculate the height
mHeight = titleHeight + descHeight + mPictureAreaIcon.getIconHeight() + additionalHeight + V_GAP;
setPreferredSize(new Dimension(WIDTH_TOTAL, mHeight));
// Calculate the preferred height
mPreferredHeight = titleHeight + (maxDescLines * mNormalFont.getSize()) + mPictureAreaIcon.getIconHeight() + additionalHeight + V_GAP;
if (mHeight < mPreferredHeight) {
mPreferredHeight = mHeight;
}
}
if (isShowing()) {
if (oldProgram != null) {
oldProgram.removeChangeListener(this);
}
mProgram.addChangeListener(this);
revalidate();
repaint();
}