View source with raw comments or as raw
    1/*  Part of XPCE --- The SWI-Prolog GUI toolkit
    2
    3    Author:        Jan Wielemaker and Anjo Anjewierden
    4    E-mail:        wielemak@science.uva.nl
    5    WWW:           http://www.swi-prolog.org/packages/xpce/
    6    Copyright (c)  1999-2011, University of Amsterdam
    7    All rights reserved.
    8
    9    Redistribution and use in source and binary forms, with or without
   10    modification, are permitted provided that the following conditions
   11    are met:
   12
   13    1. Redistributions of source code must retain the above copyright
   14       notice, this list of conditions and the following disclaimer.
   15
   16    2. Redistributions in binary form must reproduce the above copyright
   17       notice, this list of conditions and the following disclaimer in
   18       the documentation and/or other materials provided with the
   19       distribution.
   20
   21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   22    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   23    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
   24    FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
   25    COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
   26    INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
   27    BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
   28    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
   29    CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   30    LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
   31    ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   32    POSSIBILITY OF SUCH DAMAGE.
   33*/
   34
   35:- module(pce_reporter, []).   36:- use_module(library(pce)).   37
   38:- pce_begin_class(reporter, label,
   39                   "Label for reporting").
   40
   41variable(hor_stretch,   int := 100,     get, "Stretch-ability").
   42variable(hor_shrink,    int := 100,     get, "Shrink-ability").
   43variable(error_delay,   int := 5,       both, "Delay after error").
   44variable(warning_delay, int := 2,       both, "Delay after warning").
   45variable(delay_next_to, date*,          get, "Delay errors and warnings").
   46
   47initialise(R) :->
   48    send_super(R, initialise, reporter, ''),
   49    send(R, elevation, -1),
   50    send(R, border, 2),
   51    send(R, reference, point(0, R?height)).
   52
   53report(R, Status:name, Fmt:[char_array], Args:any ...) :->
   54    (   get(R, delay_next_to, DelayTo),
   55        DelayTo \== @nil,
   56        get(DelayTo, difference, new(date), ToGo),
   57        ToGo > 0,
   58        (   vital(Status)
   59        ->  send(timer(ToGo), delay),
   60            fail
   61        ;   true
   62        )
   63    ->  true
   64    ;   Msg =.. [report, Status, Fmt | Args],
   65        colour(Status, Colour),
   66        send(R, colour, Colour),
   67        delay(R, Status, Date),
   68        send(R, slot, delay_next_to, Date),
   69        send_super(R, Msg)
   70    ).
   71
   72colour(error, red) :- !.
   73colour(_, @default).
   74
   75delay(R, warning, Date) :-
   76    get(R, warning_delay, Delay),
   77    Delay > 0,
   78    !,
   79    new(Date, date),
   80    send(Date, advance, Delay).
   81delay(R, error, Date) :-
   82    get(R, error_delay, Delay),
   83    Delay > 0,
   84    !,
   85    new(Date, date),
   86    send(Date, advance, Delay).
   87delay(_, _, @nil).
   88
   89vital(warning).
   90vital(error).
   91vital(inform).
   92
   93:- pce_end_class.
   94
   95
   96:- pce_begin_class(report_dialog, dialog,
   97                   "Dialog window holding reporter").
   98
   99variable(reporter, reporter, get, "Associated reporter").
  100delegate_to(reporter).
  101
  102initialise(D) :->
  103    send_super(D, initialise),
  104    send(D, gap, size(0, 0)),
  105    send(D, resize_message, message(D, layout, @arg2)),
  106    send(D, append, new(R, reporter)),
  107    send(D, slot, reporter, R).
  108
  109:- pce_end_class