ongoing work on url recognition

cusax-fix
Yana Stamcheva 20 years ago
parent 56ea23decc
commit d986309dc5

@ -7,6 +7,7 @@
package net.java.sip.communicator.impl.gui.main.customcontrols;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
@ -50,7 +51,8 @@ public SIPCommButton() {
super();
this.bgImage = ImageLoader.getImage(ImageLoader.BUTTON_BG);
this.bgRolloverImage = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.bgRolloverImage
= ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.setIcon(new ImageIcon(this.bgImage));
this.setPreferredSize(new Dimension(this.bgImage.getWidth(null),
@ -66,7 +68,8 @@ public SIPCommButton(String text) {
super(text);
this.bgImage = ImageLoader.getImage(ImageLoader.BUTTON_BG);
this.bgRolloverImage = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.bgRolloverImage
= ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.setPreferredSize(new Dimension(this.bgImage.getWidth(null),
this.bgImage.getHeight(null)));
@ -83,7 +86,8 @@ public SIPCommButton(Image iconImage) {
this.iconImage = iconImage;
this.bgImage = ImageLoader.getImage(ImageLoader.BUTTON_BG);
this.bgRolloverImage = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.bgRolloverImage
= ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.setPreferredSize(new Dimension(this.bgImage.getWidth(null),
this.bgImage.getHeight(null)));
@ -102,7 +106,8 @@ public SIPCommButton(Image iconImage, String iconLayout) {
this.iconImage = iconImage;
this.iconLayout = iconLayout;
this.bgImage = ImageLoader.getImage(ImageLoader.BUTTON_BG);
this.bgRolloverImage = ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.bgRolloverImage
= ImageLoader.getImage(ImageLoader.BUTTON_ROLLOVER_BG);
this.setPreferredSize(new Dimension(this.bgImage.getWidth(null),
this.bgImage.getHeight(null)));
@ -117,7 +122,8 @@ public SIPCommButton(Image iconImage, String iconLayout) {
* @param rolloverImage The rollover image
* @param iconImage The icon.
*/
public SIPCommButton (Image bgImage, Image rolloverImage, Image iconImage) {
public SIPCommButton
(Image bgImage, Image rolloverImage, Image iconImage) {
super();
this.iconImage = iconImage;
@ -168,14 +174,15 @@ public SIPCommButton(Image bgImage, Image rolloverImage) {
}
public SIPCommButton(String text, Image bgImage, Image rolloverImage) {
public SIPCommButton
(String text, Image bgImage, Image rolloverImage) {
super(text);
this.bgImage = bgImage;
this.bgRolloverImage = rolloverImage;
this.setPreferredSize(new Dimension(this.bgImage.getWidth(null) + 80,
this.bgImage.getHeight(null)));
this.setPreferredSize(new Dimension(this.bgImage.getWidth(null)
+ 80, this.bgImage.getHeight(null)));
}
/**
@ -186,8 +193,12 @@ public void paint(Graphics g) {
g.drawImage(this.bgImage, 0, 0, this);
if (this.iconImage != null) {
if (this.iconImage != null) {
if(!isEnabled()){
Graphics gImg = this.iconImage.getGraphics();
gImg.setColor(new Color(150, 150, 150, 200));
gImg.drawRect(0, 0, this.iconImage.getWidth(null), this.iconImage.getHeight(null));
}
//draw the button icon depending the current layout
if (this.iconLayout.equals(SIPCommButton.CENTER_ICON_LAYOUT))
g.drawImage(this.iconImage,
@ -218,21 +229,24 @@ else if (this.iconLayout.equals(SIPCommButton.LEFT_ICON_LAYOUT))
if (this.iconImage != null) {
if (this.iconLayout.equals(SIPCommButton.CENTER_ICON_LAYOUT))
if (this.iconLayout
.equals(SIPCommButton.CENTER_ICON_LAYOUT))
g.drawImage(this.iconImage,
(this.bgImage.getWidth(null) -
this.iconImage.getWidth(null)) / 2,
(this.bgImage.getHeight(null) -
this.iconImage.getHeight(null)) / 2, this);
else if (this.iconLayout.equals(SIPCommButton.LEFT_ICON_LAYOUT))
else if (this.iconLayout
.equals(SIPCommButton.LEFT_ICON_LAYOUT))
g.drawImage(this.iconImage,
7,
(this.bgImage.getHeight(null) -
this.iconImage.getHeight(null)) / 2,
this);
else if (this.iconLayout.equals(SIPCommButton.LEFT_ICON_LAYOUT))
else if (this.iconLayout
.equals(SIPCommButton.LEFT_ICON_LAYOUT))
g.drawImage(this.iconImage,
this.bgImage.getWidth(null) - 3,
(this.bgImage.getHeight(null) -
@ -252,21 +266,24 @@ else if (this.iconLayout.equals(SIPCommButton.LEFT_ICON_LAYOUT))
if (this.iconImage != null) {
if (this.iconLayout.equals(SIPCommButton.CENTER_ICON_LAYOUT))
if (this.iconLayout
.equals(SIPCommButton.CENTER_ICON_LAYOUT))
g.drawImage(this.iconImage,
(this.bgImage.getWidth(null) -
this.iconImage.getWidth(null)) / 2 + 1,
(this.bgImage.getHeight(null) -
this.iconImage.getHeight(null)) / 2 + 1, this);
else if (this.iconLayout.equals(SIPCommButton.LEFT_ICON_LAYOUT))
else if (this.iconLayout
.equals(SIPCommButton.LEFT_ICON_LAYOUT))
g.drawImage(this.iconImage,
7 + 1,
(this.bgImage.getHeight(null) -
this.iconImage.getHeight(null)) / 2 + 1,
this);
else if (this.iconLayout.equals(SIPCommButton.LEFT_ICON_LAYOUT))
else if (this.iconLayout
.equals(SIPCommButton.LEFT_ICON_LAYOUT))
g.drawImage(this.iconImage,
this.bgImage.getWidth(null) - 3 + 1,
(this.bgImage.getHeight(null) -
@ -275,7 +292,7 @@ else if (this.iconLayout.equals(SIPCommButton.LEFT_ICON_LAYOUT))
}
}
}
if(this.getText() != null)
g.drawString(this.getText(), 12, 10);
}

@ -37,6 +37,7 @@ font=Font
help=Help
history=History
hour=Hour
insertSmiley=Insert smiley
last=Last
launchOnStartUp=Launch on start up
login=Login
@ -65,7 +66,6 @@ sendMessage=Send message
settings=Settings
showOfflineUsers=Show offline users
sipCommunicator=SIPCommunicator
smily=Smily
statusChangeGeneralError=The status could not be changed due to a general application error.
statusChangeNetworkFailure=The status could not be changed due to a network \n failure. Please check yout network connection.
today=Today

@ -162,7 +162,8 @@ public void processMessage(String contactName,
* @return The message string with properly formatted links.
*/
private String processLinks(String message) {
String msgString = message;
/*
String msgString = message;
Pattern p = Pattern
.compile("(\\bwww\\.\\S+\\.\\S+\\b)");
@ -182,6 +183,8 @@ private String processLinks(String message) {
+ m1.group() + "'>" + m1.group() + "</A>");
}
return msgString;
*/
return URLRecognitionManager.processURL(message);
}
/**

@ -0,0 +1,63 @@
package net.java.sip.communicator.impl.gui.main.message;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class URLRecognitionManager {
private static String digits = "(?:\\d+)";
private static String hex = "[a-fA-F\\d]";
private static String alpha = "[a-zA-Z]";
private static String alphanum = "[a-zA-Z\\d]";
private static String safe = "[$\\-_.+]";
private static String extra = "[!*'(),]";
private static String escape = "(?:%"+hex+"{2})";
private static String uchar
= "(?:"+alphanum+"|"+safe+"|"+extra+"|"+escape+")";
private static String qm = "\\?";
private static String hostnumber
= "(?:"+digits+"(?:\\."+digits+"){3})";
private static String toplabel
= "(?:"+alpha+"(?:(?:"+alphanum+"|-)*"+alphanum+")?)";
private static String domainlabel
= "(?:"+alphanum+"(?:(?:"+alphanum+"|-)*"+alphanum+")?)";
private static String hostname
= "(?:(?:"+domainlabel+"\\.)*"+toplabel+")";
private static String host
= "(?:"+hostname+"|"+hostnumber+")";
private static String hostPort = "(?:"+host+"(?::"+digits+")?)";
public static String processURL(String sourceMsg){
return recognizeHTTP(sourceMsg);
}
private static String recognizeHTTP(String sourceMsg){
String message = sourceMsg;
String hsegment = "(?:(?:"+uchar+"|[;:\\@&=])*)";
String hpath = "(?:" + hsegment +"(?:/" + hsegment + ")*)";
//String httpurl = "(?:http://" + hostPort +
// "(?:/" + hpath + "(?:" + qm + hsegment + ")?)?)";
String httpurl = "(?:http://(?:(?:(?:(?:(?:[a-zA-Z\\d](?:(?:[a-zA-Z\\d]|-)*[a-zA-Z\\d])?)\\." +
")*(?:[a-zA-Z](?:(?:[a-zA-Z\\d]|-)*[a-zA-Z\\d])?))|(?:(?:\\d+)(?:\\.(?:\\d+)" +
"){3}))(?::(?:\\d+))?)(?:/(?:(?:(?:(?:[a-zA-Z\\d$\\-_.+!*'(),]|(?:%[a-fA-F" +
"\\d]{2}))|[;:\\@&=])*)(?:/(?:(?:(?:[a-zA-Z\\d$\\-_.+!*'(),]|(?:%[a-fA-F\\d]{" +
"2}))|[;:\\@&=])*))*)(?:\\?(?:(?:(?:[a-zA-Z\\d$\\-_.+!*'(),]|(?:%[a-fA-F\\d]{" +
"2}))|[;:\\@&=])*))?)?)";
System.out.println("REGEXP============" + httpurl);
Pattern p = Pattern.compile(httpurl);
Matcher m = p.matcher(message);
while (m.find()) {
message = message.replaceAll(m.group().trim(), "<A href='"
+ m.group() + "'>" + m.group() + "</A>");
}
System.out.println("EHPOOOOOOOOOO:::::::" + message);
return message;
}
}

@ -118,7 +118,7 @@ public MainToolBar (ChatWindow messageWindow){
this.pasteButton.setToolTipText(Messages.getString("paste"));
this.smilyButton.setName("smily");
this.smilyButton.setToolTipText(Messages.getString("smily"));
this.smilyButton.setToolTipText(Messages.getString("insertSmiley"));
this.previousButton.setName("previous");
this.previousButton.setToolTipText(Messages.getString("previous"));

Loading…
Cancel
Save