src/Pure/System/build_dialog.scala
author wenzelm
Thu, 06 Dec 2012 17:59:37 +0100
changeset 50403 87868964733c
parent 50381 d9711842f1f9
child 50404 898cac1dad5e
permissions -rw-r--r--
more uniform default logic, using settings, options, args etc.; clarified build_dialog -C: imitate jEdit logic selection more precisely;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/build_dialog.scala
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     3
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     4
Dialog for session build process.
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     5
*/
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     6
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     7
package isabelle
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     8
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
     9
50378
72367327bab2 evade ugly default font, notably on Windows laf;
wenzelm
parents: 50377
diff changeset
    10
import java.awt.{GraphicsEnvironment, Point, Font}
50379
a8b0d3729a69 added keyboard shortcut for button (canonical way to do that?);
wenzelm
parents: 50378
diff changeset
    11
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    12
import scala.swing.{ScrollPane, Button, CheckBox, FlowPanel,
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    13
  BorderPanel, MainFrame, TextArea, SwingApplication}
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    14
import scala.swing.event.ButtonClicked
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    15
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    16
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    17
object Build_Dialog extends SwingApplication
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    18
{
50403
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    19
  // FIXME avoid startup via GUI thread!?
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    20
  def startup(args: Array[String]) =
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    21
  {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    22
    Platform.init_laf()
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    23
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    24
    try {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    25
      args.toList match {
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    26
        case
50403
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    27
          Properties.Value.Boolean(check_existing) ::
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    28
          logic_option ::
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    29
          Properties.Value.Boolean(system_mode) ::
50403
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    30
          session_arg ::
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    31
          include_dirs =>
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    32
            val session =
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    33
              Isabelle_System.default_logic(session_arg,
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    34
                if (logic_option != "") Options.init().string(logic_option) else "")
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    35
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    36
            val no_dialog =  // FIXME full up-to-date test!?
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    37
              check_existing &&
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    38
                Isabelle_System.find_logics_dirs().exists(dir =>
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    39
                  (dir + Path.basic(session)).is_file)
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    40
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    41
            if (no_dialog) sys.exit(0)
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    42
            else {
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    43
              val center = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint()
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    44
              val top = build_dialog(system_mode, include_dirs.map(Path.explode), session)
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    45
              top.pack()
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    46
              top.location = new Point(center.x - top.size.width / 2, center.y - top.size.height / 2)
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    47
              top.visible = true
87868964733c more uniform default logic, using settings, options, args etc.;
wenzelm
parents: 50381
diff changeset
    48
            }
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    49
        case _ => error("Bad arguments:\n" + cat_lines(args))
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    50
      }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    51
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    52
    catch {
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    53
      case exn: Throwable =>
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    54
        Library.error_dialog(null, "Isabelle build failure",
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    55
          Library.scrollable_text(Exn.message(exn)))
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    56
        sys.exit(2)
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    57
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    58
  }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    59
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    60
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    61
  def build_dialog(
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    62
    system_mode: Boolean,
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    63
    include_dirs: List[Path],
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    64
    session: String): MainFrame = new MainFrame
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    65
  {
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    66
    /* GUI state */
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    67
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    68
    private var is_stopped = false
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    69
    private var return_code = 0
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    70
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    71
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    72
    /* text */
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    73
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    74
    val text = new TextArea {
50378
72367327bab2 evade ugly default font, notably on Windows laf;
wenzelm
parents: 50377
diff changeset
    75
      font = new Font("SansSerif", Font.PLAIN, 14)
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    76
      editable = false
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    77
      columns = 40
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
    78
      rows = 10
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    79
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    80
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    81
    val progress = new Build.Progress
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    82
    {
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    83
      override def echo(msg: String): Unit = Swing_Thread.now { text.append(msg + "\n") }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    84
      override def stopped: Boolean =
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    85
        Swing_Thread.now { val b = is_stopped; is_stopped = false; b  }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    86
    }
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
    87
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    88
50376
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    89
    /* action button */
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
    90
50376
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    91
    var button_action: () => Unit = (() => is_stopped = true)
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    92
    val button = new Button("Cancel") {
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    93
      reactions += { case ButtonClicked(_) => button_action() }
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    94
    }
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    95
    def button_exit(rc: Int)
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    96
    {
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    97
      button.text = if (rc == 0) "OK" else "Exit"
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
    98
      button_action = (() => sys.exit(rc))
50381
d9711842f1f9 clarified default button (cf. org/gjt/sp/jedit/gui/OptionsDialog.java);
wenzelm
parents: 50379
diff changeset
    99
      button.peer.getRootPane.setDefaultButton(button.peer)
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   100
    }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   101
50376
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
   102
    val action_panel = new FlowPanel(FlowPanel.Alignment.Center)(button)
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   103
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   104
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   105
    /* layout panel */
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   106
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   107
    val layout_panel = new BorderPanel
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   108
    layout_panel.layout(new ScrollPane(text)) = BorderPanel.Position.Center
50376
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
   109
    layout_panel.layout(action_panel) = BorderPanel.Position.South
50368
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   110
e6c0720e4cef basic interaction with build process;
wenzelm
parents: 50365
diff changeset
   111
    contents = layout_panel
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   112
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   113
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   114
    /* main build */
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   115
50374
1a7cae0711d2 tuned message;
wenzelm
parents: 50372
diff changeset
   116
    title = "Isabelle build (" + Isabelle_System.getenv("ML_IDENTIFIER") + ")"
50372
11c96cac860d tuned message;
wenzelm
parents: 50371
diff changeset
   117
    progress.echo("Build started for Isabelle/" + session + " ...")
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   118
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   119
    default_thread_pool.submit(() => {
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   120
      val (out, rc) =
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   121
        try {
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   122
          ("",
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   123
            Build.build(progress, build_heap = true,
50370
d5dbb63df0c7 check for existing image (even if outdated);
wenzelm
parents: 50369
diff changeset
   124
              system_mode = system_mode, sessions = List(session)))
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   125
        }
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   126
        catch { case exn: Throwable => (Exn.message(exn) + "\n", 2) }
50376
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
   127
      Swing_Thread.now {
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
   128
        progress.echo(out + (if (rc == 0) "OK\n" else "Return code: " + rc + "\n"))
82cbe4051d98 more direct dialog via existing GUI components;
wenzelm
parents: 50374
diff changeset
   129
        button_exit(rc)
50371
9b6f5f758c31 tuned OK feedback;
wenzelm
parents: 50370
diff changeset
   130
      }
50369
622002c702ad more elementary dialog, with less interaction;
wenzelm
parents: 50368
diff changeset
   131
    })
50365
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   132
  }
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   133
}
82f5aea343e7 basic wrapper for session build dialog;
wenzelm
parents:
diff changeset
   134