src/Pure/System/platform.scala
author wenzelm
Wed Jun 02 11:09:26 2010 +0200 (2010-06-02 ago)
changeset 37251 72c7e636067b
parent 36786 b7a62e7dec00
child 41381 77990a6cd558
permissions -rw-r--r--
normalize and postprocess proof body in a separate future, taking care of platforms without multithreading (greately improves parallelization in general without the overhead of promised proofs, cf. usedir -q 0);
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@36195
    22
  /* 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@36195
    27
  private val Windows = 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@36205
    34
  lazy val jvm_platform: String =
wenzelm@31825
    35
  {
wenzelm@36195
    36
    val arch =
wenzelm@36195
    37
      java.lang.System.getProperty("os.arch") match {
wenzelm@36195
    38
        case X86() => "x86"
wenzelm@36195
    39
        case X86_64() => "x86_64"
wenzelm@36195
    40
        case Sparc() => "sparc"
wenzelm@36195
    41
        case PPC() => "ppc"
wenzelm@36195
    42
        case _ => error("Failed to determine CPU architecture")
wenzelm@36195
    43
      }
wenzelm@36195
    44
    val os =
wenzelm@36195
    45
      java.lang.System.getProperty("os.name") match {
wenzelm@36195
    46
        case Solaris() => "solaris"
wenzelm@36195
    47
        case Linux() => "linux"
wenzelm@36195
    48
        case Darwin() => "darwin"
wenzelm@36195
    49
        case Windows() => "windows"
wenzelm@36195
    50
        case _ => error("Failed to determine operating system platform")
wenzelm@36195
    51
      }
wenzelm@36195
    52
    arch + "-" + os
wenzelm@31825
    53
  }
wenzelm@31828
    54
wenzelm@31828
    55
wenzelm@31828
    56
  /* Swing look-and-feel */
wenzelm@31828
    57
wenzelm@35002
    58
  private def find_laf(name: String): Option[String] =
wenzelm@35002
    59
    UIManager.getInstalledLookAndFeels().find(_.getName == name).map(_.getClassName)
wenzelm@35002
    60
wenzelm@36786
    61
  def get_laf(): String =
wenzelm@31828
    62
  {
wenzelm@31828
    63
    if (is_windows || is_macos) UIManager.getSystemLookAndFeelClassName()
wenzelm@35002
    64
    else
wenzelm@35002
    65
      find_laf("Nimbus") orElse find_laf("GTK+") getOrElse
wenzelm@35002
    66
      UIManager.getCrossPlatformLookAndFeelClassName()
wenzelm@31828
    67
  }
wenzelm@36786
    68
wenzelm@36786
    69
  def init_laf(): Unit = UIManager.setLookAndFeel(get_laf())
wenzelm@31825
    70
}
wenzelm@31825
    71