* i2psnark: Message area tweaks and clear link

This commit is contained in:
zzz
2012-03-20 14:09:17 +00:00
parent 4ffbfce51e
commit 444ba47463
5 changed files with 58 additions and 15 deletions

View File

@ -1029,6 +1029,8 @@ public class Snark
//if (debug >= INFO && t != null) //if (debug >= INFO && t != null)
// t.printStackTrace(); // t.printStackTrace();
stopTorrent(); stopTorrent();
if (t != null)
s += ": " + t;
throw new RuntimeException(s, t); throw new RuntimeException(s, t);
} }

View File

@ -51,7 +51,7 @@ public class SnarkManager implements Snark.CompleteListener {
private Properties _config; private Properties _config;
private final I2PAppContext _context; private final I2PAppContext _context;
private final Log _log; private final Log _log;
private final List _messages; private final List<String> _messages;
private final I2PSnarkUtil _util; private final I2PSnarkUtil _util;
private PeerCoordinatorSet _peerCoordinatorSet; private PeerCoordinatorSet _peerCoordinatorSet;
private ConnectionAcceptor _connectionAcceptor; private ConnectionAcceptor _connectionAcceptor;
@ -156,6 +156,7 @@ public class SnarkManager implements Snark.CompleteListener {
public I2PSnarkUtil util() { return _util; } public I2PSnarkUtil util() { return _util; }
private static final int MAX_MESSAGES = 5; private static final int MAX_MESSAGES = 5;
public void addMessage(String message) { public void addMessage(String message) {
synchronized (_messages) { synchronized (_messages) {
_messages.add(message); _messages.add(message);
@ -167,12 +168,19 @@ public class SnarkManager implements Snark.CompleteListener {
} }
/** newest last */ /** newest last */
public List getMessages() { public List<String> getMessages() {
synchronized (_messages) { synchronized (_messages) {
return new ArrayList(_messages); return new ArrayList(_messages);
} }
} }
/** @since 0.9 */
public void clearMessages() {
synchronized (_messages) {
_messages.clear();
}
}
/** /**
* @return default false * @return default false
* @since 0.8.9 * @since 0.8.9

View File

@ -160,7 +160,7 @@ public class I2PSnarkServlet extends DefaultServlet {
PrintWriter out = resp.getWriter(); PrintWriter out = resp.getWriter();
//if (_log.shouldLog(Log.DEBUG)) //if (_log.shouldLog(Log.DEBUG))
// _manager.addMessage((_context.clock().now() / 1000) + " xhr1 p=" + req.getParameter("p")); // _manager.addMessage((_context.clock().now() / 1000) + " xhr1 p=" + req.getParameter("p"));
writeMessages(out); writeMessages(out, false);
writeTorrents(out, req); writeTorrents(out, req);
return; return;
} }
@ -277,7 +277,7 @@ public class I2PSnarkServlet extends DefaultServlet {
_manager.addMessage(_("Click \"Add torrent\" button to fetch torrent")); _manager.addMessage(_("Click \"Add torrent\" button to fetch torrent"));
out.write("<div class=\"page\"><div id=\"mainsection\" class=\"mainsection\">"); out.write("<div class=\"page\"><div id=\"mainsection\" class=\"mainsection\">");
writeMessages(out); writeMessages(out, isConfigure);
if (isConfigure) { if (isConfigure) {
// end of mainsection div // end of mainsection div
@ -297,14 +297,20 @@ public class I2PSnarkServlet extends DefaultServlet {
out.write(FOOTER); out.write(FOOTER);
} }
private void writeMessages(PrintWriter out) throws IOException { private void writeMessages(PrintWriter out, boolean isConfigure) throws IOException {
out.write("<div class=\"snarkMessages\"><table><tr><td align=\"left\"><pre>"); List<String> msgs = _manager.getMessages();
List msgs = _manager.getMessages(); if (!msgs.isEmpty()) {
for (int i = msgs.size()-1; i >= 0; i--) { out.write("<div class=\"snarkMessages\"><ul>");
String msg = (String)msgs.get(i); for (int i = msgs.size()-1; i >= 0; i--) {
out.write(msg + "\n"); String msg = (String)msgs.get(i);
out.write("<li>" + msg + "</li>\n");
}
// lazy GET, lose p parameter
out.write("</ul><p><a href=\"/i2psnark/");
if (isConfigure)
out.write("configure");
out.write("?action=Clear&amp;nonce=" + _nonce + "\">" + _("clear messages") + "</a></p></div>");
} }
out.write("</pre></td></tr></table></div>");
} }
private void writeTorrents(PrintWriter out, HttpServletRequest req) throws IOException { private void writeTorrents(PrintWriter out, HttpServletRequest req) throws IOException {
@ -751,6 +757,8 @@ public class I2PSnarkServlet extends DefaultServlet {
if (snark.isStopped()) if (snark.isStopped())
snark.startTorrent(); snark.startTorrent();
} }
} else if ("Clear".equals(action)) {
_manager.clearMessages();
} else { } else {
_manager.addMessage("Unknown POST action: \"" + action + '\"'); _manager.addMessage("Unknown POST action: \"" + action + '\"');
} }

View File

@ -82,7 +82,7 @@ body {
} }
.snarkMessages { .snarkMessages {
font: bold 9pt "Lucida Console","DejaVu Sans Mono",Courier,mono !important; font: bold 8pt "Lucida Console","DejaVu Sans Mono",Courier,mono !important;
text-align: left; text-align: left;
margin: 0 0 10px 0; margin: 0 0 10px 0;
padding: 3px 5px; padding: 3px 5px;
@ -93,7 +93,8 @@ body {
border: 1px solid #000; border: 1px solid #000;
overflow: auto; overflow: auto;
color: #26f; color: #26f;
height: 70px; max-height: 76px;
min-height: 45px;
width: auto; width: auto;
background: #2a192a url('/themes/snark/ubergine/images/hat.png') no-repeat scroll right center; background: #2a192a url('/themes/snark/ubergine/images/hat.png') no-repeat scroll right center;
} }
@ -106,6 +107,17 @@ body {
color: #f90 !important; color: #f90 !important;
} }
.snarkMessages ul {
margin: 0;
padding: 0 0 0 16px;
}
.snarkMessages p {
font-style: italic;
margin: 0;
text-align: right;
}
.logshim { .logshim {
margin-top: -10px !important; margin-top: -10px !important;
} }

View File

@ -81,7 +81,7 @@ body {
} }
.snarkMessages { .snarkMessages {
font: bold 9pt "Lucida Console","DejaVu Sans Mono",Courier,mono !important; font: bold 8pt "Lucida Console","DejaVu Sans Mono",Courier,mono !important;
text-align: left; text-align: left;
margin: 0 0 10px 0; margin: 0 0 10px 0;
padding: 3px 5px; padding: 3px 5px;
@ -92,7 +92,8 @@ body {
border: 1px solid #000; border: 1px solid #000;
overflow: auto; overflow: auto;
color: #26f; color: #26f;
height: 70px; max-height: 76px;
min-height: 45px;
width: auto; width: auto;
background: #eda url('/themes/snark/ubergine/images/hat.png') no-repeat scroll right center; background: #eda url('/themes/snark/ubergine/images/hat.png') no-repeat scroll right center;
} }
@ -108,6 +109,18 @@ body {
.snarkMessages a:visited { .snarkMessages a:visited {
color: #d30 !important; color: #d30 !important;
} }
.snarkMessages ul {
margin: 0;
padding: 0 0 0 16px;
}
.snarkMessages p {
font-style: italic;
margin: 0;
text-align: right;
}
.logshim { .logshim {
margin-top: -10px !important; margin-top: -10px !important;
} }