Skip to content

Instantly share code, notes, and snippets.

@mpen
mpen / JavaSwingTest2.scala
Created Dec 7, 2009
Scala で Java Swing GridBagLayout
View JavaSwingTest2.scala
import java.awt.{ Color, Dimension, Font }
import javax.swing._
import javax.swing.border.LineBorder
import javax.swing.plaf.FontUIResource
object JavaSwingTest2 {
def main(args: Array[String]) = {
SwingUtilities.invokeLater {
new Runnable {
override def run() {
@mpen
mpen / JavaSwingTest1.scala
Created Dec 5, 2009
ラベルにアイコンとテキストを表示
View JavaSwingTest1.scala
// ラベルにアイコンとテキストを表示
// テキストはアイコンの下中央
import java.awt.Font
import javax.swing._
import javax.swing.plaf.FontUIResource
object JavaSwingTest1 {
def init() = {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName)
@mpen
mpen / EditorPaneAndTableRenderer.scala
Created Dec 5, 2009
TableのセルにJEditorPaneを表示する
View EditorPaneAndTableRenderer.scala
// TableのセルにJEditorPaneを表示する
class EditorPane extends TextComponent {
override lazy val peer = new JEditorPane
}
class EditorPaneRenderer(comp: EditorPane) extends Table.AbstractRenderer[String, EditorPane](comp) {
override def configure(table: Table, isSelected: Boolean, hasFocus: Boolean, a: String, row: Int, column: Int): Unit = {
component.text = a
}
@mpen
mpen / sort.scala
Created Nov 28, 2009
Scalaでソート List#sort, Sorting.stableSort
View sort.scala
// List#sort, Sorting.stableSort
import scala.collection.mutable
import scala.util.Sorting
List(1, 3, 2).sort(_ < _) // List(1, 2, 3)
val ar = Array(1, 3, 2)
Sorting.stableSort(ar)
ar // Array(1, 2, 3)
@mpen
mpen / TwitterPublicTimeline.scala
Created Nov 22, 2009
TwitterのPublic Timelineを取得し、ユーザ名とツイートを表示する
View TwitterPublicTimeline.scala
// TwitterのPublic Timelineを取得し、ユーザ名とツイートを表示する
// 元 http://gist.github.com/240444
import scala.io.Source
import scala.xml.XML
val source = Source.fromURL("http://twitter.com/statuses/public_timeline.xml", "UTF-8")
val contents = source.getLines.mkString
val doc = XML.loadString(contents)
View Twitter4jSearch.scala
// Twitter4jで検索
import scala.collection.jcl.Conversions.convertList
import twitter4j.{Tweet, QueryResult, Query, Twitter}
object Twitter4jSearch {
def main(args: Array[String]) {
val queryString = "#scala"
val lang = "ja"
val rpp = 5
@mpen
mpen / PropertiesLoadStore.scala
Created Nov 9, 2009
java.util.Properties load/store, get/set
View PropertiesLoadStore.scala
// java.util.Properties load/store, get/set
import java.io._
import java.util.{Date, Properties}
import org.apache.commons.io.IOUtils
object PropertiesLoadStore {
def main(args: Array[String]) {
val configFile = new File("PropertiesLoadStore.properties")
@mpen
mpen / Twitter4jGetPublicTimeline.scala
Created Nov 6, 2009
Twitter4jで公開タイムラインの取得
View Twitter4jGetPublicTimeline.scala
// Twitter4jで公開タイムラインの取得
import java.text.SimpleDateFormat
import scala.collection.jcl.Conversions.convertList
import twitter4j.{Status, Twitter}
object Twitter4jGetPublicTimeline {
def main(args: Array[String]) {
val twitter = new Twitter
val statuses = twitter.getPublicTimeline
@mpen
mpen / ApacheHttpClientGet2.scala
Created Oct 30, 2009
Apache HttpComponents HttpClient Get ResponseHandler
View ApacheHttpClientGet2.scala
// Apache HttpComponents HttpClient Get ResponseHandler
import java.io.File
import java.io.IOException
import java.net.URI
import java.net.URISyntaxException
import java.net.URLDecoder
import java.net.UnknownHostException
import org.apache.commons.io.FileUtils
import org.apache.commons.io.FilenameUtils
@mpen
mpen / ApacheHttpClientGet.scala
Created Oct 29, 2009
Apache HttpComponents HttpClient Get
View ApacheHttpClientGet.scala
// Apache HttpComponents HttpClient Get
import java.io.{ File, IOException }
import java.net.{ URI, UnknownHostException, URLDecoder }
import org.apache.http.impl.client.DefaultHttpClient
import org.apache.http.client.methods.HttpGet
import org.apache.http.{ HttpResponse, HttpEntity, HttpStatus }
import org.apache.http.util.EntityUtils
import org.apache.commons.io.{ FileUtils, FilenameUtils }