home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2005 June / PCpro_2005_06.ISO / files / opensource / tvbrowser / TvBrowser_1.0.exe / plugins / ProgramInfo.jar / programinfo / ProgramInfoDialog.class (.txt) < prev    next >
Encoding:
Java Class File  |  2004-09-19  |  11.9 KB  |  275 lines

  1. package programinfo;
  2.  
  3. import devplugin.Plugin;
  4. import devplugin.Program;
  5. import devplugin.ProgramFieldType;
  6. import java.awt.BorderLayout;
  7. import java.awt.Dimension;
  8. import java.awt.FlowLayout;
  9. import java.awt.Frame;
  10. import java.awt.event.MouseEvent;
  11. import java.util.logging.Logger;
  12. import javax.swing.Icon;
  13. import javax.swing.ImageIcon;
  14. import javax.swing.JButton;
  15. import javax.swing.JDialog;
  16. import javax.swing.JEditorPane;
  17. import javax.swing.JLabel;
  18. import javax.swing.JPanel;
  19. import javax.swing.JPopupMenu;
  20. import javax.swing.JScrollPane;
  21. import javax.swing.SwingConstants;
  22. import javax.swing.SwingUtilities;
  23. import util.io.IOUtilities;
  24. import util.ui.Localizer;
  25. import util.ui.UiUtilities;
  26. import util.ui.html.ExtendedHTMLDocument;
  27. import util.ui.html.ExtendedHTMLEditorKit;
  28.  
  29. public class ProgramInfoDialog extends JDialog implements SwingConstants {
  30.    private static final Localizer mLocalizer;
  31.    private static Logger mLog;
  32.    private String mStyleSheet;
  33.    private JEditorPane mInfoEP;
  34.    // $FF: synthetic field
  35.    static Class class$programinfo$ProgramInfoDialog;
  36.  
  37.    public ProgramInfoDialog(Frame parent, String styleSheet, Program program, int[] infoBitArr, Icon[] infoIconArr, String[] infoMsgArr) {
  38.       super(parent, true);
  39.       this.mStyleSheet = styleSheet;
  40.       this.setTitle(mLocalizer.msg("title", "Program information"));
  41.       JPanel main = new JPanel(new BorderLayout());
  42.       main.setPreferredSize(new Dimension(500, 350));
  43.       main.setBorder(UiUtilities.DIALOG_BORDER);
  44.       this.setContentPane(main);
  45.       this.mInfoEP = new JEditorPane();
  46.       this.mInfoEP.setEditorKit(new ExtendedHTMLEditorKit());
  47.       ExtendedHTMLDocument doc = (ExtendedHTMLDocument)this.mInfoEP.getDocument();
  48.       String text = this.createInfoText(program, doc, infoBitArr, infoIconArr, infoMsgArr);
  49.       this.mInfoEP.setText(text);
  50.       this.mInfoEP.setEditable(false);
  51.       this.mInfoEP.addHyperlinkListener(new 1(this));
  52.       this.mInfoEP.addMouseListener(new 2(this, program));
  53.       JScrollPane scrollPane = new JScrollPane(this.mInfoEP);
  54.       main.add(scrollPane, "Center");
  55.       JPanel buttonPn = new JPanel(new FlowLayout(4));
  56.       main.add(buttonPn, "South");
  57.       JButton closeBtn = new JButton(mLocalizer.msg("close", "Close"));
  58.       closeBtn.addActionListener(new 3(this));
  59.       buttonPn.add(closeBtn);
  60.       this.getRootPane().setDefaultButton(closeBtn);
  61.       Runnable runnable = new 4(this, scrollPane);
  62.       SwingUtilities.invokeLater(runnable);
  63.    }
  64.  
  65.    private void handleMouseClicked(MouseEvent evt, Program program) {
  66.       if (SwingUtilities.isRightMouseButton(evt)) {
  67.          if (program != null) {
  68.             JPopupMenu menu = Plugin.getPluginManager().createPluginContextMenu(program, ProgramInfo.getInstance());
  69.             menu.show(this.mInfoEP, evt.getX() - 15, evt.getY() - 15);
  70.          }
  71.       } else if (SwingUtilities.isLeftMouseButton(evt) && evt.getClickCount() == 2 && program != null) {
  72.          Plugin plugin = Plugin.getPluginManager().getDefaultContextMenuPlugin();
  73.          if (plugin != null && plugin != ProgramInfo.getInstance()) {
  74.             plugin.execute(program);
  75.          }
  76.       }
  77.  
  78.    }
  79.  
  80.    private String createInfoText(Program prog, ExtendedHTMLDocument doc, int[] infoBitArr, Icon[] infoIconArr, String[] infoMsgArr) {
  81.       StringBuffer buffer = new StringBuffer();
  82.       buffer.append("<html><head><style type=\"text/css\" media=\"screen\"><!--" + this.mStyleSheet + "-->" + "</style>" + "</head>" + "<body>");
  83.       buffer.append("<table width=\"100%\"><tr><td valign=\"top\">");
  84.       this.newPara(buffer, "title", prog.getTitle());
  85.       this.openPara(buffer, "time");
  86.       int length = prog.getLength();
  87.       if (length > 0) {
  88.          String msg = mLocalizer.msg("minutes", "{0} min", new Integer(length));
  89.          buffer.append(msg + " (");
  90.          int hours = prog.getHours();
  91.          int minutes = prog.getMinutes();
  92.          int endTime = (hours * 60 + minutes + length) % 1440;
  93.          minutes = endTime % 60;
  94.          hours = endTime / 60;
  95.          String until = hours + ":" + (minutes < 10 ? "0" : "") + minutes;
  96.          buffer.append(mLocalizer.msg("until", "until {0}", until));
  97.          int netLength = prog.getIntField(ProgramFieldType.NET_PLAYING_TIME_TYPE);
  98.          if (netLength != -1) {
  99.             msg = mLocalizer.msg("netMinuted", "{0} min net", new Integer(netLength));
  100.             buffer.append(" - " + msg);
  101.          }
  102.  
  103.          buffer.append(")");
  104.       }
  105.  
  106.       this.closePara(buffer);
  107.       buffer.append("</td><td width=\"1%\" valign=\"top\" nowrap>");
  108.       this.newPara(buffer, "maininfo", prog.getDateString());
  109.       this.newPara(buffer, "maininfo", prog.getTimeString());
  110.       this.newPara(buffer, "maininfo", prog.getChannel().getName());
  111.       buffer.append("</td></tr></table>");
  112.       int info = prog.getInfo();
  113.       if (info != -1 && info != 0) {
  114.          this.openPara(buffer, "info");
  115.          buffer.append(" ");
  116.  
  117.          for(int i = 0; i < infoBitArr.length; ++i) {
  118.             if (ProgramInfo.bitSet(info, infoBitArr[i])) {
  119.                if (infoIconArr[i] != null) {
  120.                   JLabel iconLabel = new JLabel(infoIconArr[i]);
  121.                   iconLabel.setToolTipText(infoMsgArr[i]);
  122.                   buffer.append(doc.createCompTag(iconLabel));
  123.                } else {
  124.                   buffer.append(infoMsgArr[i]);
  125.                }
  126.  
  127.                buffer.append(" ");
  128.             }
  129.          }
  130.  
  131.          this.closePara(buffer);
  132.       }
  133.  
  134.       buffer.append("<br>\n");
  135.       int offset = buffer.length();
  136.       this.newPara(buffer, "info", prog, ProgramFieldType.EPISODE_TYPE);
  137.       this.newPara(buffer, "info", prog, ProgramFieldType.GENRE_TYPE);
  138.       this.newPara(buffer, "info", prog, ProgramFieldType.REPETITION_OF_TYPE);
  139.       this.newPara(buffer, "info", prog, ProgramFieldType.REPETITION_ON_TYPE);
  140.       this.newPara(buffer, "info", prog, ProgramFieldType.AGE_LIMIT_TYPE);
  141.       this.newPara(buffer, "info", prog, ProgramFieldType.VPS_TYPE);
  142.       this.newPara(buffer, "info", prog, ProgramFieldType.SHOWVIEW_NR_TYPE);
  143.       Plugin[] pluginArr = prog.getMarkedByPlugins();
  144.       if (pluginArr != null && pluginArr.length != 0) {
  145.          this.openPara(buffer, "info");
  146.          buffer.append(" ");
  147.  
  148.          for(int i = 0; i < pluginArr.length; ++i) {
  149.             Icon icon = pluginArr[i].getMarkIcon();
  150.             JLabel iconLabel = new JLabel(icon);
  151.             iconLabel.setToolTipText(pluginArr[i].getInfo().getName());
  152.             buffer.append(doc.createCompTag(iconLabel));
  153.          }
  154.  
  155.          this.closePara(buffer);
  156.       }
  157.  
  158.       if (offset != buffer.length()) {
  159.          buffer.append("<br>\n");
  160.          offset = buffer.length();
  161.       }
  162.  
  163.       byte[] image = prog.getBinaryField(ProgramFieldType.IMAGE_TYPE);
  164.       if (image != null) {
  165.          Icon icon = new ImageIcon(image);
  166.          JLabel iconLabel = new JLabel(icon);
  167.          buffer.append(doc.createCompTag(iconLabel));
  168.       }
  169.  
  170.       String description = prog.getDescription();
  171.       String shortInfo = prog.getShortInfo();
  172.       if (shortInfo != null) {
  173.          String shortInfoSubString = shortInfo;
  174.          if (shortInfo.endsWith("...")) {
  175.             shortInfoSubString = shortInfo.substring(0, shortInfo.length() - 3);
  176.          }
  177.  
  178.          if (description == null || !description.startsWith(shortInfoSubString)) {
  179.             this.newPara(buffer, "text", shortInfo, true);
  180.          }
  181.       }
  182.  
  183.       this.newPara(buffer, "text", description, true);
  184.       if (offset != buffer.length()) {
  185.          buffer.append("<br>\n");
  186.          offset = buffer.length();
  187.       }
  188.  
  189.       this.newPara(buffer, "small", prog, ProgramFieldType.ORIGIN_TYPE);
  190.       this.newPara(buffer, "small", prog, ProgramFieldType.PRODUCTION_YEAR_TYPE);
  191.       this.newPara(buffer, "small", prog, ProgramFieldType.URL_TYPE, true);
  192.       this.newPara(buffer, "small", prog, ProgramFieldType.ORIGINAL_TITLE_TYPE);
  193.       this.newPara(buffer, "small", prog, ProgramFieldType.ORIGINAL_EPISODE_TYPE);
  194.       this.newPara(buffer, "small", prog, ProgramFieldType.MODERATION_TYPE);
  195.       this.newPara(buffer, "small", prog, ProgramFieldType.DIRECTOR_TYPE);
  196.       this.newPara(buffer, "small", prog, ProgramFieldType.ACTOR_LIST_TYPE);
  197.       this.newPara(buffer, "small", prog, ProgramFieldType.SCRIPT_TYPE);
  198.       this.newPara(buffer, "small", prog, ProgramFieldType.MUSIC_TYPE);
  199.       buffer.append("</body></html>");
  200.       return buffer.toString();
  201.    }
  202.  
  203.    private void openPara(StringBuffer buffer, String style) {
  204.       buffer.append("<div id=\"" + style + "\">");
  205.    }
  206.  
  207.    private void closePara(StringBuffer buffer) {
  208.       buffer.append("</div>\n");
  209.    }
  210.  
  211.    private void newPara(StringBuffer buffer, String style, Program prog, ProgramFieldType fieldType) {
  212.       this.newPara(buffer, style, prog, fieldType, false);
  213.    }
  214.  
  215.    private void newPara(StringBuffer buffer, String style, Program prog, ProgramFieldType fieldType, boolean createLinks) {
  216.       String label = fieldType.getLocalizedName();
  217.       String text = null;
  218.       if (fieldType.getFormat() == 3) {
  219.          text = prog.getTextField(fieldType);
  220.       } else if (fieldType.getFormat() == 5) {
  221.          text = prog.getTimeFieldAsString(fieldType);
  222.       } else if (fieldType.getFormat() == 4) {
  223.          text = prog.getIntFieldAsString(fieldType);
  224.       }
  225.  
  226.       this.newPara(buffer, style, label, text, createLinks);
  227.    }
  228.  
  229.    private void newPara(StringBuffer buffer, String style, String text) {
  230.       this.newPara(buffer, style, (String)null, (String)text, false);
  231.    }
  232.  
  233.    private void newPara(StringBuffer buffer, String style, String text, boolean createLinks) {
  234.       this.newPara(buffer, style, (String)null, (String)text, createLinks);
  235.    }
  236.  
  237.    private void newPara(StringBuffer buffer, String style, String label, String text, boolean createLinks) {
  238.       if (text != null && text.length() != 0) {
  239.          text = IOUtilities.replace(text.trim(), "<", "<");
  240.          text = IOUtilities.replace(text.trim(), ">", ">");
  241.          text = IOUtilities.replace(text.trim(), "\n", "<br>");
  242.          if (createLinks) {
  243.             text = text.replaceAll("(http://|www.)[^\\s<]*", "<a href=\"$0\">$0</a>");
  244.          }
  245.  
  246.          this.openPara(buffer, style);
  247.          if (label != null) {
  248.             buffer.append("<b>" + label + ":</b> ");
  249.          }
  250.  
  251.          buffer.append(text);
  252.          this.closePara(buffer);
  253.       }
  254.    }
  255.  
  256.    // $FF: synthetic method
  257.    static Class class$(String x0) {
  258.       try {
  259.          return Class.forName(x0);
  260.       } catch (ClassNotFoundException x1) {
  261.          throw new NoClassDefFoundError(x1.getMessage());
  262.       }
  263.    }
  264.  
  265.    // $FF: synthetic method
  266.    static void access$000(ProgramInfoDialog x0, MouseEvent x1, Program x2) {
  267.       x0.handleMouseClicked(x1, x2);
  268.    }
  269.  
  270.    static {
  271.       mLocalizer = Localizer.getLocalizerFor(class$programinfo$ProgramInfoDialog == null ? (class$programinfo$ProgramInfoDialog = class$("programinfo.ProgramInfoDialog")) : class$programinfo$ProgramInfoDialog);
  272.       mLog = Logger.getLogger((class$programinfo$ProgramInfoDialog == null ? (class$programinfo$ProgramInfoDialog = class$("programinfo.ProgramInfoDialog")) : class$programinfo$ProgramInfoDialog).getName());
  273.    }
  274. }
  275.