home *** CD-ROM | disk | FTP | other *** search
- package programinfo;
-
- import devplugin.Plugin;
- import devplugin.Program;
- import devplugin.ProgramFieldType;
- import java.awt.BorderLayout;
- import java.awt.Dimension;
- import java.awt.FlowLayout;
- import java.awt.Frame;
- import java.awt.event.MouseEvent;
- import java.util.logging.Logger;
- import javax.swing.Icon;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JDialog;
- import javax.swing.JEditorPane;
- import javax.swing.JLabel;
- import javax.swing.JPanel;
- import javax.swing.JPopupMenu;
- import javax.swing.JScrollPane;
- import javax.swing.SwingConstants;
- import javax.swing.SwingUtilities;
- import util.io.IOUtilities;
- import util.ui.Localizer;
- import util.ui.UiUtilities;
- import util.ui.html.ExtendedHTMLDocument;
- import util.ui.html.ExtendedHTMLEditorKit;
-
- public class ProgramInfoDialog extends JDialog implements SwingConstants {
- private static final Localizer mLocalizer;
- private static Logger mLog;
- private String mStyleSheet;
- private JEditorPane mInfoEP;
- // $FF: synthetic field
- static Class class$programinfo$ProgramInfoDialog;
-
- public ProgramInfoDialog(Frame parent, String styleSheet, Program program, int[] infoBitArr, Icon[] infoIconArr, String[] infoMsgArr) {
- super(parent, true);
- this.mStyleSheet = styleSheet;
- this.setTitle(mLocalizer.msg("title", "Program information"));
- JPanel main = new JPanel(new BorderLayout());
- main.setPreferredSize(new Dimension(500, 350));
- main.setBorder(UiUtilities.DIALOG_BORDER);
- this.setContentPane(main);
- this.mInfoEP = new JEditorPane();
- this.mInfoEP.setEditorKit(new ExtendedHTMLEditorKit());
- ExtendedHTMLDocument doc = (ExtendedHTMLDocument)this.mInfoEP.getDocument();
- String text = this.createInfoText(program, doc, infoBitArr, infoIconArr, infoMsgArr);
- this.mInfoEP.setText(text);
- this.mInfoEP.setEditable(false);
- this.mInfoEP.addHyperlinkListener(new 1(this));
- this.mInfoEP.addMouseListener(new 2(this, program));
- JScrollPane scrollPane = new JScrollPane(this.mInfoEP);
- main.add(scrollPane, "Center");
- JPanel buttonPn = new JPanel(new FlowLayout(4));
- main.add(buttonPn, "South");
- JButton closeBtn = new JButton(mLocalizer.msg("close", "Close"));
- closeBtn.addActionListener(new 3(this));
- buttonPn.add(closeBtn);
- this.getRootPane().setDefaultButton(closeBtn);
- Runnable runnable = new 4(this, scrollPane);
- SwingUtilities.invokeLater(runnable);
- }
-
- private void handleMouseClicked(MouseEvent evt, Program program) {
- if (SwingUtilities.isRightMouseButton(evt)) {
- if (program != null) {
- JPopupMenu menu = Plugin.getPluginManager().createPluginContextMenu(program, ProgramInfo.getInstance());
- menu.show(this.mInfoEP, evt.getX() - 15, evt.getY() - 15);
- }
- } else if (SwingUtilities.isLeftMouseButton(evt) && evt.getClickCount() == 2 && program != null) {
- Plugin plugin = Plugin.getPluginManager().getDefaultContextMenuPlugin();
- if (plugin != null && plugin != ProgramInfo.getInstance()) {
- plugin.execute(program);
- }
- }
-
- }
-
- private String createInfoText(Program prog, ExtendedHTMLDocument doc, int[] infoBitArr, Icon[] infoIconArr, String[] infoMsgArr) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("<html><head><style type=\"text/css\" media=\"screen\"><!--" + this.mStyleSheet + "-->" + "</style>" + "</head>" + "<body>");
- buffer.append("<table width=\"100%\"><tr><td valign=\"top\">");
- this.newPara(buffer, "title", prog.getTitle());
- this.openPara(buffer, "time");
- int length = prog.getLength();
- if (length > 0) {
- String msg = mLocalizer.msg("minutes", "{0} min", new Integer(length));
- buffer.append(msg + " (");
- int hours = prog.getHours();
- int minutes = prog.getMinutes();
- int endTime = (hours * 60 + minutes + length) % 1440;
- minutes = endTime % 60;
- hours = endTime / 60;
- String until = hours + ":" + (minutes < 10 ? "0" : "") + minutes;
- buffer.append(mLocalizer.msg("until", "until {0}", until));
- int netLength = prog.getIntField(ProgramFieldType.NET_PLAYING_TIME_TYPE);
- if (netLength != -1) {
- msg = mLocalizer.msg("netMinuted", "{0} min net", new Integer(netLength));
- buffer.append(" - " + msg);
- }
-
- buffer.append(")");
- }
-
- this.closePara(buffer);
- buffer.append("</td><td width=\"1%\" valign=\"top\" nowrap>");
- this.newPara(buffer, "maininfo", prog.getDateString());
- this.newPara(buffer, "maininfo", prog.getTimeString());
- this.newPara(buffer, "maininfo", prog.getChannel().getName());
- buffer.append("</td></tr></table>");
- int info = prog.getInfo();
- if (info != -1 && info != 0) {
- this.openPara(buffer, "info");
- buffer.append(" ");
-
- for(int i = 0; i < infoBitArr.length; ++i) {
- if (ProgramInfo.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(" ");
- }
- }
-
- this.closePara(buffer);
- }
-
- buffer.append("<br>\n");
- int offset = buffer.length();
- this.newPara(buffer, "info", prog, ProgramFieldType.EPISODE_TYPE);
- this.newPara(buffer, "info", prog, ProgramFieldType.GENRE_TYPE);
- this.newPara(buffer, "info", prog, ProgramFieldType.REPETITION_OF_TYPE);
- this.newPara(buffer, "info", prog, ProgramFieldType.REPETITION_ON_TYPE);
- this.newPara(buffer, "info", prog, ProgramFieldType.AGE_LIMIT_TYPE);
- this.newPara(buffer, "info", prog, ProgramFieldType.VPS_TYPE);
- this.newPara(buffer, "info", prog, ProgramFieldType.SHOWVIEW_NR_TYPE);
- Plugin[] pluginArr = prog.getMarkedByPlugins();
- if (pluginArr != null && pluginArr.length != 0) {
- this.openPara(buffer, "info");
- buffer.append(" ");
-
- for(int i = 0; i < pluginArr.length; ++i) {
- Icon icon = pluginArr[i].getMarkIcon();
- JLabel iconLabel = new JLabel(icon);
- iconLabel.setToolTipText(pluginArr[i].getInfo().getName());
- buffer.append(doc.createCompTag(iconLabel));
- }
-
- this.closePara(buffer);
- }
-
- if (offset != buffer.length()) {
- buffer.append("<br>\n");
- offset = buffer.length();
- }
-
- byte[] image = prog.getBinaryField(ProgramFieldType.IMAGE_TYPE);
- if (image != null) {
- Icon icon = new ImageIcon(image);
- JLabel iconLabel = new JLabel(icon);
- buffer.append(doc.createCompTag(iconLabel));
- }
-
- String description = prog.getDescription();
- String shortInfo = prog.getShortInfo();
- if (shortInfo != null) {
- String shortInfoSubString = shortInfo;
- if (shortInfo.endsWith("...")) {
- shortInfoSubString = shortInfo.substring(0, shortInfo.length() - 3);
- }
-
- if (description == null || !description.startsWith(shortInfoSubString)) {
- this.newPara(buffer, "text", shortInfo, true);
- }
- }
-
- this.newPara(buffer, "text", description, true);
- if (offset != buffer.length()) {
- buffer.append("<br>\n");
- offset = buffer.length();
- }
-
- this.newPara(buffer, "small", prog, ProgramFieldType.ORIGIN_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.PRODUCTION_YEAR_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.URL_TYPE, true);
- this.newPara(buffer, "small", prog, ProgramFieldType.ORIGINAL_TITLE_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.ORIGINAL_EPISODE_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.MODERATION_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.DIRECTOR_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.ACTOR_LIST_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.SCRIPT_TYPE);
- this.newPara(buffer, "small", prog, ProgramFieldType.MUSIC_TYPE);
- buffer.append("</body></html>");
- return buffer.toString();
- }
-
- private void openPara(StringBuffer buffer, String style) {
- buffer.append("<div id=\"" + style + "\">");
- }
-
- private void closePara(StringBuffer buffer) {
- buffer.append("</div>\n");
- }
-
- private void newPara(StringBuffer buffer, String style, Program prog, ProgramFieldType fieldType) {
- this.newPara(buffer, style, prog, fieldType, false);
- }
-
- private void newPara(StringBuffer buffer, String style, Program prog, ProgramFieldType fieldType, boolean createLinks) {
- String label = fieldType.getLocalizedName();
- String text = null;
- if (fieldType.getFormat() == 3) {
- text = prog.getTextField(fieldType);
- } else if (fieldType.getFormat() == 5) {
- text = prog.getTimeFieldAsString(fieldType);
- } else if (fieldType.getFormat() == 4) {
- text = prog.getIntFieldAsString(fieldType);
- }
-
- this.newPara(buffer, style, label, text, createLinks);
- }
-
- private void newPara(StringBuffer buffer, String style, String text) {
- this.newPara(buffer, style, (String)null, (String)text, false);
- }
-
- private void newPara(StringBuffer buffer, String style, String text, boolean createLinks) {
- this.newPara(buffer, style, (String)null, (String)text, createLinks);
- }
-
- private void newPara(StringBuffer buffer, String style, String label, String text, boolean createLinks) {
- if (text != null && text.length() != 0) {
- text = IOUtilities.replace(text.trim(), "<", "<");
- text = IOUtilities.replace(text.trim(), ">", ">");
- text = IOUtilities.replace(text.trim(), "\n", "<br>");
- if (createLinks) {
- text = text.replaceAll("(http://|www.)[^\\s<]*", "<a href=\"$0\">$0</a>");
- }
-
- this.openPara(buffer, style);
- if (label != null) {
- buffer.append("<b>" + label + ":</b> ");
- }
-
- buffer.append(text);
- this.closePara(buffer);
- }
- }
-
- // $FF: synthetic method
- static Class class$(String x0) {
- try {
- return Class.forName(x0);
- } catch (ClassNotFoundException x1) {
- throw new NoClassDefFoundError(x1.getMessage());
- }
- }
-
- // $FF: synthetic method
- static void access$000(ProgramInfoDialog x0, MouseEvent x1, Program x2) {
- x0.handleMouseClicked(x1, x2);
- }
-
- static {
- mLocalizer = Localizer.getLocalizerFor(class$programinfo$ProgramInfoDialog == null ? (class$programinfo$ProgramInfoDialog = class$("programinfo.ProgramInfoDialog")) : class$programinfo$ProgramInfoDialog);
- mLog = Logger.getLogger((class$programinfo$ProgramInfoDialog == null ? (class$programinfo$ProgramInfoDialog = class$("programinfo.ProgramInfoDialog")) : class$programinfo$ProgramInfoDialog).getName());
- }
- }
-