aramaki 

荒巻オンライン

Commit MetaInfo

Revisionfc56d21f24e5c944ea7f48f496c36bc3582f19c9 (tree)
Time2011-06-05 22:41:21
Authorsuperbacker <superbacker@user...>
Commitersuperbacker

Log Message

ふきだし / ログのURLをリンクに変換

Change Summary

Diff

--- a/src/net/scaltinof/aramaki/client/engine3d/objects/avatar/AvatarOverlay.java
+++ b/src/net/scaltinof/aramaki/client/engine3d/objects/avatar/AvatarOverlay.java
@@ -17,6 +17,8 @@
1717 */
1818 package net.scaltinof.aramaki.client.engine3d.objects.avatar;
1919
20+import net.scaltinof.aramaki.client.utils.AutoLink;
21+
2022 import com.google.gwt.core.client.GWT;
2123 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
2224 import com.google.gwt.uibinder.client.UiBinder;
@@ -70,7 +72,7 @@ public class AvatarOverlay extends Composite {
7072 return;
7173 }
7274 SafeHtmlBuilder builder = new SafeHtmlBuilder();
73- builder.appendEscapedLines(text);
75+ builder.appendHtmlConstant(AutoLink.escapeLinesURLToLink(text));
7476 balloon.setHTML(builder.toSafeHtml());
7577
7678 balloonContainer.setVisible(true);
--- a/src/net/scaltinof/aramaki/client/logger/LoggerUI.java
+++ b/src/net/scaltinof/aramaki/client/logger/LoggerUI.java
@@ -18,19 +18,26 @@
1818 package net.scaltinof.aramaki.client.logger;
1919
2020 import net.scaltinof.aramaki.client.engine3d.objects.avatar.Logger;
21+import net.scaltinof.aramaki.client.utils.AutoLink;
2122
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;
2227 import com.google.gwt.user.client.Element;
2328 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;
2530
2631 public class LoggerUI extends Composite implements Logger {
27- private final TextArea logArea = new TextArea();
32+ private final HTML logArea = new HTML();
2833
2934 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);
3139
32- logArea.setReadOnly(true);
33- logArea.removeStyleName("gwt-TextArea-readonly");
40+ initWidget(logArea);
3441 }
3542
3643 @Override
@@ -42,14 +49,18 @@ public class LoggerUI extends Composite implements Logger {
4249 }
4350
4451 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);
4655
47- if (text.length() > 0) {
48- text += "\n";
56+ if (html.length() > 0) {
57+ builder.appendHtmlConstant("<br>");
4958 }
5059
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());
5364 }
5465
5566 private void scrollBottom() {
--- /dev/null
+++ b/src/net/scaltinof/aramaki/client/utils/AutoLink.java
@@ -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(&quot;$&&quot;)\" 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+}
--- a/war/AramakiOnline.html
+++ b/war/AramakiOnline.html
@@ -21,6 +21,14 @@
2121 <script language="javascript" src="net.scaltinof.aramaki.AramakiOnline/net.scaltinof.aramaki.AramakiOnline.nocache.js"></script>
2222
2323 <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>
2432 </head>
2533
2634 <!-- -->
旧リポジトリブラウザで表示