001 // GraphLab Project: http://graphlab.sharif.edu 002 // Copyright (C) 2008 Mathematical Science Department of Sharif University of Technology 003 // Distributed under the terms of the GNU General Public License (GPL): http://www.gnu.org/licenses/ 004 package graphlab.plugins.commonplugin.reporter; 005 006 import graphlab.ui.components.utils.GFrameLocationProvider; 007 008 import javax.swing.*; 009 import java.awt.*; 010 import java.io.BufferedWriter; 011 import java.io.File; 012 import java.io.FileWriter; 013 import java.io.IOException; 014 import java.net.URL; 015 016 public class Browser extends JFrame { 017 018 /** 019 * 020 */ 021 private static final long serialVersionUID = -9157914659496711380L; 022 023 protected JTextField urlField; 024 protected JEditorPane browserPane; 025 026 public static String header = "" 027 + "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\n" + 028 "<head>\n" + 029 " <title>New Ticket - GraphLab - Trac</title><link rel=\"start\" href=\"http://graphlab.sharif.ir/trac/graphlab/wiki\" /><link rel=\"search\" href=\"http://graphlab.sharif.ir/trac/graphlab/search\" /><link rel=\"help\" href=\"http://graphlab.sharif.ir/trac/graphlab/wiki/TracGuide\" /><link rel=\"stylesheet\" href=\"http://graphlab.sharif.ir/trac/graphlab/chrome/common/css/trac.css\" type=\"text/css\" /><link rel=\"stylesheet\" href=\"http://graphlab.sharif.ir/trac/graphlab/chrome/common/css/ticket.css\" type=\"text/css\" /><link rel=\"icon\" href=\"http://graphlab.sharif.ir/trac/graphlab/chrome/common/trac.ico\" type=\"image/x-icon\" /><link rel=\"shortcut icon\" href=\"http://graphlab.sharif.ir/trac/graphlab/chrome/common/trac.ico\" type=\"image/x-icon\" /><style type=\"text/css\">\n" + 030 "</style>\n" + 031 " <script type=\"text/javascript\" src=\"http://graphlab.sharif.ir/trac/graphlab/chrome/common/js/trac.js\"></script>\n" + 032 "</head>\n" + 033 "<body>\n" + 034 "<div id=\"content\" class=\"ticket\">\n" + 035 "<h1>Create New Ticket</h1>\n" + 036 "\n" + 037 "\n" + 038 "<form id=\"newticket\" method=\"post\" action=\"http://graphlab.sharif.ir/trac/newticket#preview\"><div><input name=\"__FORM_TOKEN\" value=\"aef7815afa05dc29c165b2d6\" type=\"hidden\"></div>\n" + 039 " \n" + 040 " <div class=\"field\">\n" + 041 " <label for=\"reporter\">Your email or username:</label><br>\n" + 042 " <input id=\"reporter\" name=\"reporter\" size=\"40\" value=\"anonymous\" type=\"text\"><br>\n" + 043 " </div>\n" + 044 " \n" + 045 " <div class=\"field\">\n" + 046 "\n" + 047 " <label for=\"summary\">Short summary:</label><br>\n" + 048 " <input id=\"summary\" name=\"summary\" size=\"80\" value=\"\" type=\"text\">\n" + 049 " </div>\n" + 050 " <div class=\"field\"><label for=\"type\">Type:</label> \n" + 051 " <select size=\"1\" id=\"type\" name=\"type\">\n" + 052 " <option selected=\"selected\">defect</option>\n" + 053 " <option>enhancement</option>\n" + 054 "\n" + 055 " <option>task</option>\n" + 056 " </select>\n" + 057 " </div>\n" + 058 " <div class=\"field\">\n" + 059 " <label for=\"description\">Full description (you may use <a tabindex=\"42\" href=\"/trac/wiki/WikiFormatting\">WikiFormatting</a> here):</label><br>\n" + 060 " <div class=\"wikitoolbar\"><a tabindex=\"400\" title=\"Bold text: '''Example'''\" id=\"strong\" href=\"#\"></a><a tabindex=\"400\" title=\"Italic text: ''Example''\" id=\"em\" href=\"#\"></a><a tabindex=\"400\" title=\"Heading: == Example ==\" id=\"heading\" href=\"#\"></a><a tabindex=\"400\" title=\"Link: [http://www.example.com/ Example]\" id=\"link\" href=\"#\"></a><a tabindex=\"400\" title=\"Code block: {{{ example }}}\" id=\"code\" href=\"#\"></a><a tabindex=\"400\" title=\"Horizontal rule: ----\" id=\"hr\" href=\"#\"></a><a tabindex=\"400\" title=\"New paragraph\" id=\"np\" href=\"#\"></a><a tabindex=\"400\" title=\"Line break: [[BR]]\" id=\"br\" href=\"#\"></a></div><textarea id=\"description\" name=\"description\" class=\"wikitext\" rows=\"10\" cols=\"78\">"; 061 062 public static String footer = "" 063 + "</textarea>\n" + 064 "\n" + 065 " </div>\n" + 066 "\n" + 067 " <fieldset id=\"properties\">\n" + 068 " <legend>Ticket Properties</legend>\n" + 069 " <input name=\"action\" value=\"create\" type=\"hidden\">\n" + 070 " <input name=\"status\" value=\"new\" type=\"hidden\">\n" + 071 " <table><tbody><tr>\n" + 072 " <th class=\"col1\"><label for=\"priority\">Priority:</label></th>\n" + 073 "\n" + 074 " <td><select id=\"priority\" name=\"priority\"><option>blocker</option><option>critical</option><option selected=\"selected\">major</option><option>minor</option><option>trivial</option></select></td>\n" + 075 " <th class=\"col2\"><label for=\"milestone\">Milestone:</label></th>\n" + 076 " <td><select id=\"milestone\" name=\"milestone\"><option></option><option>milestone1</option><option>milestone2</option><option>milestone3</option><option>milestone4</option></select></td></tr><tr>\n" + 077 " <th class=\"col1\"><label for=\"component\">Component:</label></th>\n" + 078 "\n" + 079 " <td><select id=\"component\" name=\"component\"><option selected=\"selected\">component1</option><option>component2</option></select></td>\n" + 080 " <th class=\"col2\"><label for=\"version\">Version:</label></th>\n" + 081 " <td><select id=\"version\" name=\"version\"><option></option><option>2.0</option><option>1.0</option></select></td></tr><tr>\n" + 082 " <th class=\"col1\"><label for=\"keywords\">Keywords:</label></th>\n" + 083 " <td><input id=\"keywords\" name=\"keywords\" value=\"\" type=\"text\"></td>\n" + 084 " <th class=\"col2\"><label for=\"owner\">Assign to:</label></th>\n" + 085 "\n" + 086 " <td><input id=\"owner\" name=\"owner\" value=\"\" type=\"text\"></td></tr><tr>\n" + 087 " <th class=\"col1\"><label for=\"cc\">Cc:</label></th>\n" + 088 " <td><input id=\"cc\" name=\"cc\" value=\"\" type=\"text\"></td><th class=\"col2\"></th><td></td></tr>\n" + 089 " </tbody></table>\n" + 090 " </fieldset>\n" + 091 "\n" + 092 " <script type=\"text/javascript\" src=\"/trac/chrome/common/js/wikitoolbar.js\"></script>\n" + 093 "\n" + 094 " <p>\n" + 095 "\n" + 096 " <label><input name=\"attachment\" type=\"checkbox\">\n" + 097 " I have files to attach to this ticket\n" + 098 " </label>\n" + 099 " </p>\n" + 100 "\n" + 101 " <div class=\"buttons\">\n" + 102 " <input name=\"preview\" value=\"Preview\" accesskey=\"r\" type=\"submit\"> \n" + 103 " <input value=\"Submit ticket\" type=\"submit\">\n" + 104 " </div>\n" + 105 "</form>\n" + 106 "\n" + 107 "<div id=\"help\">\n" + 108 " <strong>Note:</strong> See <a href=\"/trac/wiki/TracTickets\">TracTickets</a> for help on using tickets.\n" + 109 "</div>\n" + 110 "</div>" + 111 " </body>\n" + 112 "</html>\n" + 113 ""; 114 115 public Browser() { 116 super("Browser"); 117 setPreferredSize(GFrameLocationProvider.getPopUpSize()); 118 setLocation(GFrameLocationProvider.getPopUpLocation()); 119 // browser pane 120 browserPane = new JEditorPane(); 121 browserPane.setContentType("text/html"); 122 browserPane.setEditable(false); 123 browserPane.addHyperlinkListener(new HyperActive()); 124 125 // create content pane 126 JPanel contentPane = new JPanel(new BorderLayout()); 127 JScrollPane scrollPane = new JScrollPane(browserPane); 128 contentPane.add(scrollPane, BorderLayout.CENTER); 129 contentPane.setPreferredSize(new Dimension(500, 300)); 130 setContentPane(contentPane); 131 } 132 133 public static boolean browse(URL url) { 134 try { 135 Desktop.getDesktop().browse(url.toURI()); 136 return true; 137 } catch (Exception e) { 138 e.printStackTrace(); 139 return false; 140 } 141 } 142 143 public boolean browseInternal(URL url) { 144 try { 145 browserPane.setPage(url); 146 return true; 147 } catch (IOException e) { 148 System.err.println("Attempted to read a bad URL: " + url); 149 return false; 150 } 151 } 152 153 public static boolean browse(String htmlText) { 154 try { 155 File temp = File.createTempFile("graphlab", ".html"); 156 temp.deleteOnExit(); 157 BufferedWriter out = new BufferedWriter(new FileWriter(temp)); 158 out.write(htmlText); 159 out.close(); 160 browse(temp.toURL()); 161 return true; 162 } catch (IOException e) { 163 e.printStackTrace(); 164 return false; 165 } 166 } 167 168 public boolean browseInternal(String htmlText) { 169 browserPane.setText(htmlText); 170 System.out.println(htmlText); 171 return true; 172 } 173 }