| 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 | 
 | 
|  |     22 |   /* Isabelle platform identifiers */
 | 
|  |     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")
 | 
|  |     27 |   private val Cygwin = new Regex("Windows.*")
 | 
|  |     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 | 
 | 
|  |     34 |   // main default, optional 64bit variant
 | 
|  |     35 |   val defaults: Option[(String, Option[String])] =
 | 
|  |     36 |   {
 | 
|  |     37 |     (java.lang.System.getProperty("os.name") match {
 | 
|  |     38 |       case Solaris() => Some("solaris")
 | 
|  |     39 |       case Linux() => Some("linux")
 | 
|  |     40 |       case Darwin() => Some("darwin")
 | 
|  |     41 |       case Cygwin() => Some("cygwin")
 | 
|  |     42 |       case _ => None
 | 
|  |     43 |     }) match {
 | 
|  |     44 |       case Some(name) =>
 | 
|  |     45 |         java.lang.System.getProperty("os.arch") match {
 | 
|  |     46 |           case X86() => Some(("x86-" + name, None))
 | 
|  |     47 |           case X86_64() => Some(("x86-" + name, if (is_windows) None else Some("x86_64-" + name)))
 | 
|  |     48 |           case Sparc() => Some(("sparc-" + name, None))
 | 
|  |     49 |           case PPC() => Some(("ppc-" + name, None))
 | 
|  |     50 |         }
 | 
|  |     51 |       case None => None
 | 
|  |     52 |     }
 | 
|  |     53 |   }
 | 
| 31828 |     54 | 
 | 
|  |     55 | 
 | 
|  |     56 |   /* Swing look-and-feel */
 | 
|  |     57 | 
 | 
|  |     58 |   def look_and_feel(): String =
 | 
|  |     59 |   {
 | 
|  |     60 |     if (is_windows || is_macos) UIManager.getSystemLookAndFeelClassName()
 | 
|  |     61 |     else {
 | 
|  |     62 |       UIManager.getInstalledLookAndFeels().find(laf => laf.getName == "Nimbus") match {
 | 
|  |     63 |         case None => UIManager.getCrossPlatformLookAndFeelClassName()
 | 
|  |     64 |         case Some(laf) => laf.getClassName
 | 
|  |     65 |       }
 | 
|  |     66 |     }
 | 
|  |     67 |   }
 | 
| 31825 |     68 | }
 | 
|  |     69 | 
 |