| | @@ -18,19 +18,26 @@ |
| 18 | 18 | package net.scaltinof.aramaki.client.logger; |
| 19 | 19 | |
| 20 | 20 | import net.scaltinof.aramaki.client.engine3d.objects.avatar.Logger; |
| 21 | +import net.scaltinof.aramaki.client.utils.AutoLink; |
| 21 | 22 | |
| 23 | +import com.google.gwt.dom.client.Style; |
| 24 | +import com.google.gwt.dom.client.Style.Overflow; |
| 25 | +import com.google.gwt.dom.client.Style.Unit; |
| 26 | +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
| 22 | 27 | import com.google.gwt.user.client.Element; |
| 23 | 28 | import com.google.gwt.user.client.ui.Composite; |
| 24 | | -import com.google.gwt.user.client.ui.TextArea; |
| 29 | +import com.google.gwt.user.client.ui.HTML; |
| 25 | 30 | |
| 26 | 31 | public class LoggerUI extends Composite implements Logger { |
| 27 | | - private final TextArea logArea = new TextArea(); |
| 32 | + private final HTML logArea = new HTML(); |
| 28 | 33 | |
| 29 | 34 | public LoggerUI() { |
| 30 | | - initWidget(logArea); |
| 35 | + final Style style = logArea.getElement().getStyle(); |
| 36 | + style.setOverflow(Overflow.AUTO); |
| 37 | + style.setProperty("borderStyle", "inset"); |
| 38 | + style.setBorderWidth(1, Unit.PX); |
| 31 | 39 | |
| 32 | | - logArea.setReadOnly(true); |
| 33 | | - logArea.removeStyleName("gwt-TextArea-readonly"); |
| 40 | + initWidget(logArea); |
| 34 | 41 | } |
| 35 | 42 | |
| 36 | 43 | @Override |
| | @@ -42,14 +49,18 @@ public class LoggerUI extends Composite implements Logger { |
| 42 | 49 | } |
| 43 | 50 | |
| 44 | 51 | private void doAppend(String name, String message) { |
| 45 | | - String text = logArea.getText(); |
| 52 | + final String html = logArea.getHTML(); |
| 53 | + final SafeHtmlBuilder builder = new SafeHtmlBuilder(); |
| 54 | + builder.appendHtmlConstant(html); |
| 46 | 55 | |
| 47 | | - if (text.length() > 0) { |
| 48 | | - text += "\n"; |
| 56 | + if (html.length() > 0) { |
| 57 | + builder.appendHtmlConstant("<br>"); |
| 49 | 58 | } |
| 50 | 59 | |
| 51 | | - text += name + " : " + message.replace("\n", ""); |
| 52 | | - logArea.setText(text); |
| 60 | + builder.appendEscaped(name + " : "); |
| 61 | + builder.appendHtmlConstant(AutoLink.escapedURLToLink(message)); |
| 62 | + |
| 63 | + logArea.setHTML(builder.toSafeHtml()); |
| 53 | 64 | } |
| 54 | 65 | |
| 55 | 66 | private void scrollBottom() { |
| | @@ -0,0 +1,48 @@ |
| 1 | +/* |
| 2 | + * Aramaki Online |
| 3 | + * Copyright (C) 2005 - 2011 superbacker |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/> |
| 17 | + */ |
| 18 | +package net.scaltinof.aramaki.client.utils; |
| 19 | + |
| 20 | +import com.google.gwt.regexp.shared.RegExp; |
| 21 | +import com.google.gwt.safehtml.shared.SafeHtml; |
| 22 | +import com.google.gwt.safehtml.shared.SafeHtmlBuilder; |
| 23 | + |
| 24 | +public abstract class AutoLink { |
| 25 | + private static final RegExp URL_MATCH_PATTERN = RegExp.compile("(http://|https://){1}[\\w\\.\\-/:\\#\\?\\=\\&\\;\\%\\~\\+]+", "gi"); |
| 26 | + |
| 27 | + /** |
| 28 | + * URLをリンクに変換する |
| 29 | + * リンクがクリックされたときHTMLのopenConfirm(url)を呼び出して、URLを開くかどうか確認する。 |
| 30 | + */ |
| 31 | + public static String urlToLink(SafeHtml html) { |
| 32 | + return URL_MATCH_PATTERN.replace(html.asString(), "<a href=\"javascript:openConfirm("$&")\" target=\"_blank\">$&</a>"); |
| 33 | + } |
| 34 | + |
| 35 | + public static String escapedURLToLink(String string) { |
| 36 | + final SafeHtmlBuilder dataBuilder = new SafeHtmlBuilder(); |
| 37 | + dataBuilder.appendEscaped(string); |
| 38 | + |
| 39 | + return urlToLink(dataBuilder.toSafeHtml()); |
| 40 | + } |
| 41 | + |
| 42 | + public static String escapeLinesURLToLink(String string) { |
| 43 | + final SafeHtmlBuilder dataBuilder = new SafeHtmlBuilder(); |
| 44 | + dataBuilder.appendEscapedLines(string); |
| 45 | + |
| 46 | + return urlToLink(dataBuilder.toSafeHtml()); |
| 47 | + } |
| 48 | +} |
| | @@ -21,6 +21,14 @@ |
| 21 | 21 | <script language="javascript" src="net.scaltinof.aramaki.AramakiOnline/net.scaltinof.aramaki.AramakiOnline.nocache.js"></script> |
| 22 | 22 | |
| 23 | 23 | <meta name="viewport" content="target-densitydpi=medium-dpi,width=device-width,height=device-height,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/> |
| 24 | + |
| 25 | + <script language="javascript"> |
| 26 | + function openConfirm(url) { |
| 27 | + if (window.confirm(url + "を開きますか")) { |
| 28 | + window.open(url); |
| 29 | + } |
| 30 | + } |
| 31 | + </script> |
| 24 | 32 | </head> |
| 25 | 33 | |
| 26 | 34 | <!-- --> |