Skip to content

Commit

Permalink
cleanups, display osx docicon, improved build, updated libraries, upd…
Browse files Browse the repository at this point in the history
…ated sbt, updated scala
  • Loading branch information
Herr Ritschwumm committed Mar 31, 2013
1 parent 988490c commit bda5f1c
Show file tree
Hide file tree
Showing 29 changed files with 282 additions and 324 deletions.
30 changes: 18 additions & 12 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ name := "commonist"

organization := "de.djini"

version := "0.5.0"
version := "0.6.0"

scalaVersion := "2.10.0"
scalaVersion := "2.10.1"

libraryDependencies ++= Seq(
"de.djini" %% "scutil" % "0.16.0" % "compile",
"de.djini" %% "scjson" % "0.16.0" % "compile",
"de.djini" %% "scmw" % "0.11.0" % "compile",
"de.djini" %% "scutil" % "0.18.0" % "compile",
"de.djini" %% "scjson" % "0.20.0" % "compile",
"de.djini" %% "scmw" % "0.15.0" % "compile",
"org.apache.httpcomponents" % "httpclient" % "4.2.3" % "compile",
"org.apache.httpcomponents" % "httpmime" % "4.2.3" % "compile",
"org.apache.sanselan" % "sanselan" % "0.97-incubator" % "compile"
"org.apache.sanselan" % "sanselan" % "0.97-incubator" % "compile",
"org.simplericity.macify" % "macify" % "1.6" % "compile"
)

scalacOptions ++= Seq(
Expand Down Expand Up @@ -48,6 +49,11 @@ scriptstartConfigs := Seq(ScriptConfig(
mainClass = "commonist.Commonist"
))

// scriptstart::zipper
inTask(scriptstartBuild)(zipperSettings ++ Seq(
zipperFiles <<= scriptstartBuild map { dir => selectSubpaths(dir, -DirectoryFilter).toSeq }
))

//--------------------------------------------------------------------------------

osxappSettings
Expand All @@ -62,6 +68,12 @@ osxappMainClass := Some("commonist.Commonist")

osxappVmOptions := Seq("-Xmx192m")

// osxapp::zipper
inTask(osxappBuild)(zipperSettings ++ Seq(
zipperFiles <<= osxappBuild map { dir => selectSubpaths(dir, -DirectoryFilter).toSeq },
zipperBundle <<= zipperBundle { _ + ".app" }
))

//--------------------------------------------------------------------------------

webstartSettings
Expand Down Expand Up @@ -105,9 +117,3 @@ webstartJnlpConfigs := Seq(JnlpConfig(
webstartExtras <<= sourceDirectory in Compile map { source =>
Path selectSubpaths (source / "webstart" , -DirectoryFilter) toSeq
}

//------------------------------------------------------------------------------

zipperSettings

zipperFiles <<= scriptstartBuild map { dir => selectSubpaths(dir, -DirectoryFilter).toSeq }
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.12.2
sbt.version=0.12.3
8 changes: 4 additions & 4 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
addSbtPlugin("de.djini" % "xsbt-webstart" % "0.9.0")
addSbtPlugin("de.djini" % "xsbt-webstart" % "0.10.0")

addSbtPlugin("de.djini" % "xsbt-scriptstart" % "0.9.0")
addSbtPlugin("de.djini" % "xsbt-scriptstart" % "0.10.0")

addSbtPlugin("de.djini" % "xsbt-osxapp" % "0.5.0")
addSbtPlugin("de.djini" % "xsbt-osxapp" % "0.6.0")

addSbtPlugin("de.djini" % "xsbt-zipper" % "0.2.0")
addSbtPlugin("de.djini" % "xsbt-zipper" % "0.4.0")

addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.1.2")
6 changes: 6 additions & 0 deletions src/main/doc/changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
0.6.0
feature added zipfile for an osx app to the build
bugfix display the commonist icon the dock on osx again
bugfix on startup the selected directory was not visible in the
directory tree

0.5.0 01mar13
change issued a new snakeoil certificate
change library updates
Expand Down
3 changes: 2 additions & 1 deletion src/main/doc/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ <h2>requirements</h2>

<h2>download</h2>
<ul>
<li><a href="$(project)-$(version).zip">$(project)-$(version).zip</a> binary</li>
<li><a href="$(project)-$(version).zip">$(project)-$(version).zip</a> generic binary</li>
<li><a href="$(project)-$(version).app.zip">$(project)-$(version).app.zip</a> osx application</li>
<!--
<li><a href="$(project)-$(version)-bin.zip">$(project)-$(version)-bin.zip</a> binary</li>
<li><a href="$(project)-$(version)-src.zip">$(project)-$(version)-src.zip</a> sourcecode</li>
Expand Down
Binary file added src/main/resources/commonist-128.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 28 additions & 9 deletions src/main/scala/commonist/Commonist.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@ package commonist
import java.awt.{ List => AwtList, _ }
import java.io._
import java.net._
import javax.imageio.ImageIO

import bsh.Interpreter
import bsh.EvalError

import org.simplericity.macify.eawt._

import scutil.Implicits._
import scutil.ThreadUtil
import scutil.ExceptionUtil
import scutil.SystemProperties
import scutil.Files._
import scutil.Resource._
import scutil.AppleQuit
import scutil.log.Logging
import scutil.gui.SwingApp
import scutil.log._

import commonist.data._
import commonist.task._
Expand All @@ -23,9 +26,16 @@ import commonist.ui._
import commonist.util._

/** the main application class */
object Commonist extends SwingApp {
ExceptionUtil.logAllExceptions()
ExceptionUtil.logAWTExceptions()
object Commonist extends SwingApp with Logging {
def onStartupError(e:Exception) {
e.printStackTrace()
}
ExceptionUtil logAllExceptions { (thread,throwable) =>
throwable.printStackTrace()
}
ExceptionUtil logAWTExceptions { (thread,throwable) =>
throwable.printStackTrace()
}

private val settingsProp = (System getProperty "commonist.settings").guardNotNull
private val settingsDir = settingsProp map { new File(_) } getOrElse (HOME / ".commonist")
Expand All @@ -42,7 +52,7 @@ object Commonist extends SwingApp {
val programIcon = null
val programHeading = "The Commonist " + Constants.VERSION

private val userLanguage = System.getProperty("user.language")
private val userLanguage = SystemProperties.user.language
INFO("using user language: " + userLanguage)
loadMessages(userLanguage)

Expand Down Expand Up @@ -80,7 +90,16 @@ object Commonist extends SwingApp {
def quit() { doQuit() }
})

AppleQuit install doQuit
private val macifyApplication = new DefaultApplication
macifyApplication addApplicationListener new ApplicationAdapter {
override def handleQuit(ev:ApplicationEvent) {
doQuit()
}
}
"/commonist-128.png" |> getClass.getResource |> ImageIO.read |>
macifyApplication.setApplicationIconImage
macifyApplication.removeAboutMenuItem()
macifyApplication.removePreferencesMenuItem()

//-------------------------------------------------------------------------
//## life cycle
Expand Down Expand Up @@ -167,11 +186,11 @@ object Commonist extends SwingApp {
}

/** load licenses */
private def loadLicenses():List[LicenseData] =
private def loadLicenses():Seq[LicenseData] =
Parser parseLicenses (loader resourceURL "licenses.txt" getOrError "cannot load licenses.txt")

/** load wikis */
private def loadWikis():List[WikiData] =
private def loadWikis():Seq[WikiData] =
Parser parseWikis (loader resourceURL "wikis.txt" getOrError "cannot load wikis.txt")

/*
Expand Down
32 changes: 8 additions & 24 deletions src/main/scala/commonist/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import java.util.regex._

import scutil.Implicits._
import scutil.Resource._
import scutil.log.Logging
import scutil.log._

import scmw._

Expand All @@ -31,10 +31,10 @@ object Parser extends Logging {
.mkString("\n")
}

def parseCoordinates(s:String):Option[Pair[String,String]] =
def parseCoordinates(s:String):Option[(String,String)] =
s splitAround ',' map { parseCoordinate _ } match {
case Seq(Some(latitude), Some(longitude)) =>
Some(Pair(latitude, longitude))
Some((latitude, longitude))
case _ =>
WARN("could not parse coordinates", s)
None
Expand All @@ -48,7 +48,7 @@ object Parser extends Logging {
//------------------------------------------------------------------------------

val WikiDataPattern = """\s*(\S+)\s+(\S+)\s+(\S+)\s*""".r
def parseWikis(url:URL):List[WikiData] = parseURL(url) {
def parseWikis(url:URL):Seq[WikiData] = parseURL(url) {
_ match {
case WikiDataPattern(family, site, api) =>
Some(WikiData(family, parseSite(site), api))
Expand All @@ -60,7 +60,7 @@ object Parser extends Logging {
def parseSite(s:String):Option[String] = (s != "_") guard s

val LicenseDataPattern = """(\{\{[^\}]+\}\})\s*(.*)""".r
def parseLicenses(url:URL):List[LicenseData] = parseURL(url) {
def parseLicenses(url:URL):Seq[LicenseData] = parseURL(url) {
_ match {
case LicenseDataPattern(template, description) =>
Some(LicenseData(template, description))
Expand All @@ -70,29 +70,13 @@ object Parser extends Logging {
}
}

private def parseURL[T](url:URL)(parseLine:String=>Iterable[T]):List[T] =
private def parseURL[T](url:URL)(parseLine:String=>Iterable[T]):Seq[T] =
slurpLines(url)
.map { _.trim }
.filter { _.nonEmpty }
.filter { !_.startsWith("#") }
.flatMap { parseLine }

private def slurpLines(url:URL):List[String] = {
import java.io._
import scala.collection.mutable.ListBuffer
import scala.annotation.tailrec

new BufferedReader(new InputStreamReader(url.openStream, "UTF-8")) use { in =>
val out = new ListBuffer[String]
@tailrec def readLine() {
val line = in.readLine
if (line != null) {
out += line
readLine()
}
}
readLine()
out.toList
}
}
private def slurpLines(url:URL):Seq[String] =
new BufferedReader(new InputStreamReader(url.openStream, "UTF-8")) use { _.readLines() }
}
5 changes: 3 additions & 2 deletions src/main/scala/commonist/Task.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package commonist

import scutil.log.Logging
import scutil.log._

final class TaskVar[T <: Task] {
private var current:Option[T] = None
Expand Down Expand Up @@ -32,7 +32,8 @@ abstract class Task extends Logging { outer =>
}
)
// see http://java.sun.com/developer/JDCTechTips/2005/tt0727.html#1
thread.setPriority(Thread.NORM_PRIORITY)
thread setPriority Thread.NORM_PRIORITY

private var waitFor:Thread = null

/** start the task in its own thread */
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/commonist/data/CommonData.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ case class CommonData(
author:String,
permission:String,
license:LicenseData,
categories:String)
categories:String)
6 changes: 3 additions & 3 deletions src/main/scala/commonist/data/ImageListData.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commonist.data

/** Data edited in an ImageListUI */
case class ImageListData(imageDatas:List[ImageData]) {
def hasSelected:Boolean = imageDatas find { _.upload } isDefined;
def selected:List[ImageData] = imageDatas filter { _.upload }
case class ImageListData(imageDatas:Seq[ImageData]) {
def hasSelected:Boolean = imageDatas exists { _.upload }
def selected:Seq[ImageData] = imageDatas filter { _.upload }
}
6 changes: 3 additions & 3 deletions src/main/scala/commonist/task/ChangeDirectoryTask.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import java.io.File
import javax.swing.Icon

import scutil.Implicits._
import scutil.log.Logging
import scutil.log._

import commonist._
import commonist.thumb._
Expand All @@ -29,7 +29,7 @@ final class ChangeDirectoryTask(mainWindow:MainWindow, imageListUI:ImageListUI,
.getOrElse { WARN("directory does not exist: " + directory); return }

// TODO duplicate code
val sorted = listed.toList sortBy { _.getPath }
val sorted = listed sortBy { _.getPath }

val (readable,unreadable) = sorted partition { _.canRead }
unreadable foreach { it => WARN("cannot read: " + it) }
Expand All @@ -54,7 +54,7 @@ final class ChangeDirectoryTask(mainWindow:MainWindow, imageListUI:ImageListUI,

// update when a given number of ImageUIs have been added
// or a given delay has elapsed or
val now = System.currentTimeMillis()
val now = System.currentTimeMillis
if (now - last > Constants.IMAGELIST_UPDATE_DELAY
|| (cur % Constants.IMAGELIST_UPDATE_COUNT) == 0) {
imageListUILater.updateSelectStatus()
Expand Down
Loading

0 comments on commit bda5f1c

Please sign in to comment.