home *** CD-ROM | disk | FTP | other *** search
- package printplugin;
-
- import devplugin.Plugin;
- import devplugin.Program;
- import devplugin.ProgramFieldType;
- import java.awt.AlphaComposite;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Composite;
- import java.awt.Graphics;
- import java.awt.Graphics2D;
- import java.io.IOException;
- import java.io.Reader;
- import java.util.ArrayList;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.Icon;
- import util.io.IOUtilities;
- import util.ui.MultipleFieldReader;
- import util.ui.TextAreaIcon;
-
- public class ProgramIcon implements Icon {
- private static Logger mLog;
- private static final Composite NORMAL_COMPOSITE;
- private static final Composite PALE_COMPOSITE;
- private ProgramIconSettings mSettings;
- private int mHeight;
- private int mWidth;
- private int mPreferredHeight;
- private String mProgramTimeAsString;
- private TextAreaIcon mTitleIcon;
- private TextAreaIcon mDescriptionIcon;
- private Icon[] mIconArr;
- private Program mProgram;
- private static final ProgramIconSettings DEFAULT_PROGRAM_ICON_SETTINGS;
- // $FF: synthetic field
- static Class class$printplugin$ProgramIcon;
-
- public ProgramIcon(Program prog) {
- this(prog, (ProgramIconSettings)null, 100);
- }
-
- public ProgramIcon(Program prog, ProgramIconSettings settings, int width) {
- this.mHeight = 0;
- this.mPreferredHeight = 0;
- if (settings == null) {
- this.mSettings = DEFAULT_PROGRAM_ICON_SETTINGS;
- } else {
- this.mSettings = settings;
- }
-
- this.mWidth = width;
- this.mTitleIcon = new TextAreaIcon((String)null, this.mSettings.getTitleFont(), width - this.mSettings.getTimeFieldWidth() - 5);
- this.mDescriptionIcon = new TextAreaIcon((String)null, this.mSettings.getTextFont(), width - this.mSettings.getTimeFieldWidth() - 5);
- this.mDescriptionIcon.setMaximumLineCount(3);
- this.setProgram(prog, -1);
- }
-
- public void setMaximumHeight(int height) {
- this.setProgram(this.mProgram, height);
- }
-
- private Icon[] getPluginIcons(Program program) {
- ArrayList list = new ArrayList();
- String[] iconPluginArr = this.mSettings.getProgramTableIconPlugins();
- Plugin[] pluginArr = Plugin.getPluginManager().getInstalledPlugins();
-
- for(int i = 0; i < iconPluginArr.length; ++i) {
- for(int j = 0; j < pluginArr.length; ++j) {
- String className = pluginArr[j].getClass().getName();
- if (iconPluginArr[i].equals(className)) {
- Icon[] iconArr = pluginArr[j].getProgramTableIcons(program);
- if (iconArr != null) {
- for(int k = 0; k < iconArr.length; ++k) {
- list.add(iconArr[k]);
- }
- }
- }
- }
- }
-
- Icon[] asArr = new Icon[list.size()];
- list.toArray(asArr);
- return asArr;
- }
-
- private void setProgram(Program program, int maxHeight) {
- Program oldProgram = this.mProgram;
- this.mProgram = program;
- boolean programChanged = oldProgram != program;
- if (programChanged) {
- this.mProgramTimeAsString = program.getTimeString();
- this.mIconArr = this.getPluginIcons(program);
- this.mTitleIcon.setText(program.getTitle());
- }
-
- int titleHeight = this.mTitleIcon.getIconHeight();
- int maxDescLines = 0;
- if (maxHeight != -1) {
- maxDescLines = (maxHeight - titleHeight) / this.mSettings.getTextFont().getSize();
- }
-
- if (programChanged || maxDescLines != this.mDescriptionIcon.getMaximumLineCount()) {
- this.mDescriptionIcon.setMaximumLineCount(maxDescLines);
- ProgramFieldType[] infoFieldArr = this.mSettings.getProgramInfoFields();
- Reader infoReader = new MultipleFieldReader(program, infoFieldArr);
-
- try {
- this.mDescriptionIcon.setText(infoReader);
- } catch (IOException exc) {
- mLog.log(Level.WARNING, "Reading program info failed for " + program, exc);
- }
-
- this.mHeight = this.mTitleIcon.getIconHeight() + this.mDescriptionIcon.getIconHeight();
- this.mPreferredHeight = titleHeight + 3 * this.mSettings.getTextFont().getSize() + 10;
- if (this.mHeight < this.mPreferredHeight) {
- this.mPreferredHeight = this.mHeight;
- }
- }
-
- }
-
- public int getIconHeight() {
- return this.mHeight;
- }
-
- public int getIconWidth() {
- return this.mWidth;
- }
-
- public void paintIcon(Component component, Graphics g, int posX, int posY) {
- g.translate(posX, posY);
- int width = this.getIconWidth();
- int height = this.mHeight;
- Graphics2D grp = (Graphics2D)g;
- if (this.mSettings.getPaintProgramOnAir() && this.mProgram.isOnAir()) {
- int minutesAfterMidnight = IOUtilities.getMinutesAfterMidnight();
- int progLength = this.mProgram.getLength();
- int startTime = this.mProgram.getHours() * 60 + this.mProgram.getMinutes();
- int elapsedMinutes;
- if (minutesAfterMidnight < startTime) {
- elapsedMinutes = 1440 + minutesAfterMidnight - startTime;
- } else {
- elapsedMinutes = minutesAfterMidnight - startTime;
- }
-
- int progressY = 0;
- if (progLength > 0) {
- progressY = elapsedMinutes * height / progLength;
- }
-
- grp.setColor(this.mSettings.getColorOnAir_dark());
- grp.fillRect(1, 1, width - 2, progressY - 1);
- grp.setColor(this.mSettings.getColorOnAir_light());
- grp.fillRect(1, progressY, width - 2, height - progressY - 1);
- grp.draw3DRect(0, 0, width - 1, height - 1, true);
- }
-
- Plugin[] markedByPluginArr = this.mProgram.getMarkedByPlugins();
- if (this.mSettings.getPaintPluginMarks() && markedByPluginArr.length != 0) {
- grp.setColor(this.mSettings.getColorMarked());
- grp.fill3DRect(0, 0, width, height, true);
- }
-
- if (this.mSettings.getPaintExpiredProgramsPale() && this.mProgram.isExpired()) {
- grp.setColor(Color.gray);
- } else {
- grp.setColor(Color.black);
- }
-
- grp.setFont(this.mSettings.getTimeFont());
- grp.drawString(this.mProgramTimeAsString, 1, this.mSettings.getTimeFont().getSize());
- this.mTitleIcon.paintIcon(component, grp, this.mSettings.getTimeFieldWidth(), 0);
- this.mDescriptionIcon.paintIcon(component, grp, this.mSettings.getTimeFieldWidth(), this.mTitleIcon.getIconHeight());
- if (this.mSettings.getPaintExpiredProgramsPale() && this.mProgram.isExpired()) {
- grp.setComposite(PALE_COMPOSITE);
- }
-
- int x = width - 1;
- int y = this.mTitleIcon.getIconHeight() + this.mDescriptionIcon.getIconHeight() + 18;
- y = Math.min(y, height - 1);
- if (this.mSettings.getPaintPluginMarks()) {
- for(int i = 0; i < markedByPluginArr.length; ++i) {
- Icon icon = markedByPluginArr[i].getMarkIcon();
- if (icon != null) {
- x -= icon.getIconWidth();
- icon.paintIcon(component, grp, x, y - icon.getIconHeight());
- }
- }
- }
-
- if (this.mIconArr != null) {
- x = 2;
- y = this.mSettings.getTimeFont().getSize() + 3;
-
- for(int i = 0; i < this.mIconArr.length; ++i) {
- int iconHeight = this.mIconArr[i].getIconHeight();
- if (y + iconHeight < this.mHeight) {
- this.mIconArr[i].paintIcon(component, grp, x, y);
- y += iconHeight + 2;
- }
- }
- }
-
- if (this.mSettings.getPaintExpiredProgramsPale() && this.mProgram.isExpired()) {
- grp.setComposite(NORMAL_COMPOSITE);
- }
-
- g.translate(-posX, -posY);
- }
-
- // $FF: synthetic method
- static Class class$(String x0) {
- try {
- return Class.forName(x0);
- } catch (ClassNotFoundException x1) {
- throw new NoClassDefFoundError(x1.getMessage());
- }
- }
-
- static {
- mLog = Logger.getLogger((class$printplugin$ProgramIcon == null ? (class$printplugin$ProgramIcon = class$("printplugin.ProgramIcon")) : class$printplugin$ProgramIcon).getName());
- NORMAL_COMPOSITE = AlphaComposite.SrcOver;
- PALE_COMPOSITE = AlphaComposite.getInstance(3, 0.5F);
- DEFAULT_PROGRAM_ICON_SETTINGS = PrinterProgramIconSettings.create();
- }
- }
-