Skip to content

Commit

Permalink
Make general improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
dcbriccetti committed Aug 8, 2012
1 parent 4f4e136 commit e5d4624
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
35 changes: 19 additions & 16 deletions desktop/src/main/scala/org/talkingpuffin/ui/LargeTweet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,31 @@ class LargeTweet(session: Session, backgroundColor: Color,
activateable: Function0[Option[Activateable]]) extends JTextPane with Loggable {
var filtersDialog: Option[FiltersDialog] = None
setBackground(backgroundColor)
setContentType("text/html");
setEditable(false);

setContentType("text/html")
setEditable(false)

private val findLinks =
if (Desktop.isDesktopSupported)
Some(LinkUnIndirector.findLinks(DesktopUtil.browse, DesktopUtil.browse) _)
else
None

addHyperlinkListener(new HyperlinkListener() {
def hyperlinkUpdate(e: HyperlinkEvent) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
if (Desktop.isDesktopSupported) {
LinkUnIndirector.findLinks(DesktopUtil.browse, DesktopUtil.browse)(e.getURL.toString)
}
activateable() match {
case Some(a) => a.activate // Let user resume using keyboard to move through tweets
case _ =>
}
if (e.getEventType == HyperlinkEvent.EventType.ACTIVATED) {
findLinks.foreach(_(e.getURL.toString))
activateable().foreach(_.activate) // Let user resume using keyboard to move through tweets
}
}
});
})

addMouseListener(new MouseAdapter {
override def mousePressed(e: MouseEvent) = showPopup(e)
override def mouseReleased(e: MouseEvent) = showPopup(e)
override def mousePressed(e: MouseEvent) {
showPopup(e)
}
override def mouseReleased(e: MouseEvent) {
showPopup(e)
}
def showPopup(e: MouseEvent) {
if (e.isPopupTrigger) {
val text = getSelectedText
Expand All @@ -59,6 +64,4 @@ class LargeTweet(session: Session, backgroundColor: Color,
}
}
})

}

14 changes: 12 additions & 2 deletions desktop/src/main/scala/org/talkingpuffin/ui/TweetDetailPanel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.talkingpuffin.apix.RichStatus._
import org.talkingpuffin.apix.RichUser._
import org.talkingpuffin.util.EscapeHtml
import util.{Activateable, CenteredPicture, TextChangingAnimator}
import java.net.URL

object medThumbPicFetcher extends PictureFetcher("Medium thumb", Some(Thumbnail.MEDIUM_SIZE), 2, Some(5))

Expand Down Expand Up @@ -142,11 +143,20 @@ class TweetDetailPanel(session: Session,
userAndStatus.retweetingUser))

if (GlobalPrefs.isOn(PrefKeys.EXPAND_URLS)) {
def urlWithoutRequestParams(url: String) = url.split("\\?")(0)
def formatUrl(url: String) = {
try {
val u = new URL(url)
//TODO make a way to show a short version of the ultimate URL while preserving the hyperlink
u.getHost + u.getPath
url
} catch {
case e: Exception => url
}
}

def replaceUrl(shortUrl: String, fullUrl: String) {
val beforeText = largeTweet.getText
val afterText = beforeText.replace(shortUrl, urlWithoutRequestParams(fullUrl))
val afterText = beforeText.replace(shortUrl, formatUrl(fullUrl))
if (beforeText != afterText) {
largeTweet setText afterText
largeTweet setCaretPosition 0
Expand Down

0 comments on commit e5d4624

Please sign in to comment.