src/Pure/System/platform.scala
author haftmann
Tue Oct 20 16:13:01 2009 +0200 (2009-10-20)
changeset 33037 b22e44496dc2
parent 31828 31584cf201cc
child 35002 fbb40a1091ea
permissions -rw-r--r--
replaced old_style infixes eq_set, subset, union, inter and variants by generic versions
wenzelm@31825
     1
/*  Title:      Pure/System/platform.scala
wenzelm@31825
     2
    Author:     Makarius
wenzelm@31825
     3
wenzelm@31825
     4
Raw platform identification.
wenzelm@31825
     5
*/
wenzelm@31825
     6
wenzelm@31825
     7
package isabelle
wenzelm@31825
     8
wenzelm@31828
     9
import javax.swing.UIManager
wenzelm@31828
    10
wenzelm@31825
    11
import scala.util.matching.Regex
wenzelm@31825
    12
wenzelm@31825
    13
wenzelm@31825
    14
object Platform
wenzelm@31825
    15
{
wenzelm@31828
    16
  /* main OS variants */
wenzelm@31828
    17
wenzelm@31825
    18
  val is_macos = System.getProperty("os.name") == "Mac OS X"
wenzelm@31825
    19
  val is_windows = System.getProperty("os.name").startsWith("Windows")
wenzelm@31825
    20
wenzelm@31828
    21
wenzelm@31828
    22
  /* Isabelle platform identifiers */
wenzelm@31828
    23
wenzelm@31825
    24
  private val Solaris = new Regex("SunOS|Solaris")
wenzelm@31825
    25
  private val Linux = new Regex("Linux")
wenzelm@31825
    26
  private val Darwin = new Regex("Mac OS X")
wenzelm@31825
    27
  private val Cygwin = new Regex("Windows.*")
wenzelm@31825
    28
wenzelm@31825
    29
  private val X86 = new Regex("i.86|x86")
wenzelm@31825
    30
  private val X86_64 = new Regex("amd64|x86_64")
wenzelm@31825
    31
  private val Sparc = new Regex("sparc")
wenzelm@31825
    32
  private val PPC = new Regex("PowerPC|ppc")
wenzelm@31825
    33
wenzelm@31825
    34
  // main default, optional 64bit variant
wenzelm@31825
    35
  val defaults: Option[(String, Option[String])] =
wenzelm@31825
    36
  {
wenzelm@31825
    37
    (java.lang.System.getProperty("os.name") match {
wenzelm@31825
    38
      case Solaris() => Some("solaris")
wenzelm@31825
    39
      case Linux() => Some("linux")
wenzelm@31825
    40
      case Darwin() => Some("darwin")
wenzelm@31825
    41
      case Cygwin() => Some("cygwin")
wenzelm@31825
    42
      case _ => None
wenzelm@31825
    43
    }) match {
wenzelm@31825
    44
      case Some(name) =>
wenzelm@31825
    45
        java.lang.System.getProperty("os.arch") match {
wenzelm@31825
    46
          case X86() => Some(("x86-" + name, None))
wenzelm@31825
    47
          case X86_64() => Some(("x86-" + name, if (is_windows) None else Some("x86_64-" + name)))
wenzelm@31825
    48
          case Sparc() => Some(("sparc-" + name, None))
wenzelm@31825
    49
          case PPC() => Some(("ppc-" + name, None))
wenzelm@31825
    50
        }
wenzelm@31825
    51
      case None => None
wenzelm@31825
    52
    }
wenzelm@31825
    53
  }
wenzelm@31828
    54
wenzelm@31828
    55
wenzelm@31828
    56
  /* Swing look-and-feel */
wenzelm@31828
    57
wenzelm@31828
    58
  def look_and_feel(): String =
wenzelm@31828
    59
  {
wenzelm@31828
    60
    if (is_windows || is_macos) UIManager.getSystemLookAndFeelClassName()
wenzelm@31828
    61
    else {
wenzelm@31828
    62
      UIManager.getInstalledLookAndFeels().find(laf => laf.getName == "Nimbus") match {
wenzelm@31828
    63
        case None => UIManager.getCrossPlatformLookAndFeelClassName()
wenzelm@31828
    64
        case Some(laf) => laf.getClassName
wenzelm@31828
    65
      }
wenzelm@31828
    66
    }
wenzelm@31828
    67
  }
wenzelm@31825
    68
}
wenzelm@31825
    69