| author | haftmann | 
| Sat, 28 Aug 2010 16:14:32 +0200 | |
| changeset 38864 | 4abe644fcea5 | 
| parent 36786 | b7a62e7dec00 | 
| child 41381 | 77990a6cd558 | 
| permissions | -rw-r--r-- | 
| 31825 | 1 | /* Title: Pure/System/platform.scala | 
| 2 | Author: Makarius | |
| 3 | ||
| 4 | Raw platform identification. | |
| 5 | */ | |
| 6 | ||
| 7 | package isabelle | |
| 8 | ||
| 31828 | 9 | import javax.swing.UIManager | 
| 10 | ||
| 31825 | 11 | import scala.util.matching.Regex | 
| 12 | ||
| 13 | ||
| 14 | object Platform | |
| 15 | {
 | |
| 31828 | 16 | /* main OS variants */ | 
| 17 | ||
| 31825 | 18 |   val is_macos = System.getProperty("os.name") == "Mac OS X"
 | 
| 19 |   val is_windows = System.getProperty("os.name").startsWith("Windows")
 | |
| 20 | ||
| 31828 | 21 | |
| 36195 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 22 | /* Platform identifiers */ | 
| 31828 | 23 | |
| 31825 | 24 |   private val Solaris = new Regex("SunOS|Solaris")
 | 
| 25 |   private val Linux = new Regex("Linux")
 | |
| 26 |   private val Darwin = new Regex("Mac OS X")
 | |
| 36195 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 27 |   private val Windows = new Regex("Windows.*")
 | 
| 31825 | 28 | |
| 29 |   private val X86 = new Regex("i.86|x86")
 | |
| 30 |   private val X86_64 = new Regex("amd64|x86_64")
 | |
| 31 |   private val Sparc = new Regex("sparc")
 | |
| 32 |   private val PPC = new Regex("PowerPC|ppc")
 | |
| 33 | ||
| 36205 
e86d9a10e982
check JVM platform at most once -- still non-strict to prevent potential failure during initialization of object Platform;
 wenzelm parents: 
36195diff
changeset | 34 | lazy val jvm_platform: String = | 
| 31825 | 35 |   {
 | 
| 36195 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 36 | val arch = | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 37 |       java.lang.System.getProperty("os.arch") match {
 | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 38 | case X86() => "x86" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 39 | case X86_64() => "x86_64" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 40 | case Sparc() => "sparc" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 41 | case PPC() => "ppc" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 42 |         case _ => error("Failed to determine CPU architecture")
 | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 43 | } | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 44 | val os = | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 45 |       java.lang.System.getProperty("os.name") match {
 | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 46 | case Solaris() => "solaris" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 47 | case Linux() => "linux" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 48 | case Darwin() => "darwin" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 49 | case Windows() => "windows" | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 50 |         case _ => error("Failed to determine operating system platform")
 | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 51 | } | 
| 
9c098598db2a
system properties determine the JVM platform, not the Isabelle one;
 wenzelm parents: 
35002diff
changeset | 52 | arch + "-" + os | 
| 31825 | 53 | } | 
| 31828 | 54 | |
| 55 | ||
| 56 | /* Swing look-and-feel */ | |
| 57 | ||
| 35002 
fbb40a1091ea
try "GTK+" as well -- note that "Nimbus" is unavailable in versions of OpenJDK;
 wenzelm parents: 
31828diff
changeset | 58 | private def find_laf(name: String): Option[String] = | 
| 
fbb40a1091ea
try "GTK+" as well -- note that "Nimbus" is unavailable in versions of OpenJDK;
 wenzelm parents: 
31828diff
changeset | 59 | UIManager.getInstalledLookAndFeels().find(_.getName == name).map(_.getClassName) | 
| 
fbb40a1091ea
try "GTK+" as well -- note that "Nimbus" is unavailable in versions of OpenJDK;
 wenzelm parents: 
31828diff
changeset | 60 | |
| 36786 | 61 | def get_laf(): String = | 
| 31828 | 62 |   {
 | 
| 63 | if (is_windows || is_macos) UIManager.getSystemLookAndFeelClassName() | |
| 35002 
fbb40a1091ea
try "GTK+" as well -- note that "Nimbus" is unavailable in versions of OpenJDK;
 wenzelm parents: 
31828diff
changeset | 64 | else | 
| 
fbb40a1091ea
try "GTK+" as well -- note that "Nimbus" is unavailable in versions of OpenJDK;
 wenzelm parents: 
31828diff
changeset | 65 |       find_laf("Nimbus") orElse find_laf("GTK+") getOrElse
 | 
| 
fbb40a1091ea
try "GTK+" as well -- note that "Nimbus" is unavailable in versions of OpenJDK;
 wenzelm parents: 
31828diff
changeset | 66 | UIManager.getCrossPlatformLookAndFeelClassName() | 
| 31828 | 67 | } | 
| 36786 | 68 | |
| 69 | def init_laf(): Unit = UIManager.setLookAndFeel(get_laf()) | |
| 31825 | 70 | } | 
| 71 |