Skip to content

Instantly share code, notes, and snippets.

@mpen
mpen / JavaSwingTest2.scala
Created December 7, 2009 01:54
Scala で Java Swing GridBagLayout
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 December 5, 2009 10:32
ラベルにアイコンとテキストを表示
// ラベルにアイコンとテキストを表示
// テキストはアイコンの下中央
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 December 5, 2009 09:45
TableのセルにJEditorPaneを表示する
// 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 November 28, 2009 09:33
Scalaでソート List#sort, Sorting.stableSort
// 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 November 22, 2009 08:21
TwitterのPublic Timelineを取得し、ユーザ名とツイートを表示する
// 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)
@mpen
mpen / Twitter4jSearch.scala
Created November 10, 2009 01:07
Twitter4jで検索
// 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 November 9, 2009 05:10
java.util.Properties load/store, get/set
// 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 November 6, 2009 11:24
Twitter4jで公開タイムラインの取得
// 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 October 30, 2009 10:47
Apache HttpComponents HttpClient Get ResponseHandler
// 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 October 29, 2009 05:39
Apache HttpComponents HttpClient Get
// 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 }