1 package rero.gui; 2 3 import rero.client.Feature; 4 import rero.config.ClientDefaults; 5 import rero.config.ClientState; 6 import rero.util.ClientUtils; 7 import text.event.ClickEvent; 8 import text.event.ClickListener; 9 10 import java.util.regex.Matcher ; 11 import java.util.regex.Pattern ; 12 13 public class ClickableURLHandler extends Feature implements ClickListener { 14 private static final Pattern CHAN_PATTERN = Pattern.compile("[@+%]*(#.*)"); 15 16 public void wordClicked(ClickEvent ev) { 17 int clickCount = ev.getEvent().getClickCount(); 18 boolean dclick = ClientState.getClientState().isOption("dclick.links", ClientDefaults.dclick_links); 19 int need_clicks = dclick ? 2 : 1; 20 21 if (clickCount == need_clicks) { 22 String item = ev.getClickedText().toLowerCase(); 23 24 if (item.matches("^\\(*(http|https|ftp)://.*")) { 25 ClientUtils.openURL(extractURL(ev.getClickedText())); 26 ev.consume(); 27 ev.acknowledge(); 28 } else if (item.matches("^www\\..*")) { 29 String location = extractURL(ev.getClickedText()); 30 ClientUtils.openURL("http://" + location); 31 ev.consume(); 32 ev.acknowledge(); 33 } else { 34 Matcher m = CHAN_PATTERN.matcher(ev.getClickedText()); 35 if (m.matches()) { 36 String chan = m.group(1).trim(); 37 getCapabilities().sendln("JOIN " + chan); 38 ev.consume(); 39 ev.acknowledge(); 40 } 41 } 42 } 43 } 44 45 private static String extractURL(String url) { 46 if (url.charAt(0) == '(') { 47 url = url.substring(1, url.length() - 1); 48 } 49 return url; 50 } 51 52 public void init() { 53 } 54 } 55 | Popular Tags |