Class Gui

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
BatchOptionsGui, GeneratedGui, GuiOptions, GuiOptions, OptionsGui, ToolGui

public abstract class Gui extends JPanel
Base class for GUI code generated by Compiler.

Realizes fundamental methods for displaying and editing option arguments. These methods will partly be called by the generated code, partly by user code (for initialization and final checking), partly by the swing ui-process autonomously.

The layout of the control panel itself (inner panel, without the interactive buttons) is
  JPanel --- GridBagLayout
  |
  |  TTLabel       (=abbrev-string)
  |  JLabel        (= "/")
  |  TTLabel       (=name-string)
  |  JLabel        (= ":")
  |  JPanel  ("growing group") //  has "MultiLineFlowLayout"
  |  |  Field_int
  |  |  Field_bool
  |  |  
  |  |  Handles
  |  |  | TTHandle
  |  |  | TTHandle
  |  |  | TTHandle
  |  |  Collection ("growing group")
  |  |  | Field_int
  |  |  | Field_string
  |  |  Handles
  |  |  | ...
  |  |  Collection
  |  |  | ...
  |  |  Handles
  |  |  | ...
  |
  |  TTLabel    // next line
  |  JLabel 

All text fields, labels, tooltips etc are multilingual. The translations for the model-independent texts (e.g. "input integer" / "ganze Zahl eingeben") are fixed and contained in Messages.
Translations for further languages can be added to the value of field messages.

The documentation texts for option names and parameter fields are in the Model, namely Model.descriptions.
This class can be used in varying contexts (e.g. integrated in card layouts). But it also offers a standard way for modification and confirmation by the user by +++ editGraphically(String,JPanel,Dimension,String,String[],String[])

See Also:
  • Field Details

    • errorstate

      protected boolean errorstate
      Is set/reset by the InputVerifier methods of all fields with syntax, and read by the handle buttons, to make them inactive as long as a widget input error is pending.
    • errorkey

      protected String errorkey
      The un-translated error message, i.e. the key into the translation map.
    • errorcomponent

      @Opt protected @Opt JComponent errorcomponent
      The component, the editing of which caused the last error, if any.
    • messagePane

      @Opt protected @Opt JLabel messagePane
      message pane for showing the message if a "field with syntax" cannot be left because the current text input cannot be parsed into a value. INPUT parameter, must be set from outside.
    • buttonKeys

      protected Map<JButton,String> buttonKeys
      Maps each JButton to a key into messages for dynamic language switching.
    • messages

      public final Messages messages
      For translating the (generic!) error messages ("please insert integer!") and button label ("ok", "cancel"). The translations for the option descriptions, displayed as a tool tip over Gui.TTLabel, are NOT from here, but from the model. This field is public, so further languages can be added by the caller, and further translations for buttons, column headers, menu items, tabbed pane riders, etc.
    • prefLangs

      public List<String> prefLangs
      List of languages for all translations. Mere input data, linked to some outer list object which is maintained dynamically by some employer. Must be set by calling setLivingListLanguagePreferences(List) before GUI gets visible.
    • growingGroup

      protected JPanel growingGroup
      After the generated code has created its labels, this is the panel in which to create the argument value widgets.
    • errorControlled

      protected Set<JComponent> errorControlled
      Make the arguments becoming inactive on input errors, and active again when the error is corrected.
    • react_int

      protected final Gui.TextReaction react_int
      Has a verify method according to the syntax of decimal integer input.
    • react_int_hex

      protected final Gui.TextReaction react_int_hex
      Has a verify method according to the syntax of decimal integer input, including hexadecimal.
    • react_float

      protected final Gui.TextReaction react_float
      Has a verify method according to the syntax of decimal floating point input.
    • react_rational

      protected final Gui.TextReaction react_rational
      Has a verify method according to the syntax of rational number input.
    • react_noSyntax

      protected final Gui.TextReaction react_noSyntax
      Has a verify method which lets pass any string.
    • uriDialogActive

      protected boolean uriDialogActive
    • backgroundColor_error

      public static final Color backgroundColor_error
      Evident
    • backgroundColor_warning

      public static final Color backgroundColor_warning
      Evident
    • backgroundColor_ok

      public static final Color backgroundColor_ok
      Evident
    • iinsert

      protected static final Gui.StringIcon iinsert
      Icon for the button in the a Gui.TTHandle. Attention, its object identity is used for switching reactions.
    • idelete

      protected static final Gui.StringIcon idelete
      Icon for the button in the a Gui.TTHandle. Attention, its object identity is used for switching reactions.
    • iswap

      protected static final Gui.StringIcon iswap
      Icon for the button in the a Gui.TTHandle. Attention, its object identity is used for switching reactions.
    • buttonsize

      protected static final Dimension buttonsize
      Size for a single Gui.TTHandle.
    • handlesize

      protected static final Dimension handlesize
      Size for the group of three handles in a Gui.Handles.
    • buttoninsets

      protected static final Insets buttoninsets
      Distance around a single Gui.TTHandle.
    • action_insert

      protected final ActionListener action_insert
      re-usable constant for handle buttons.
    • action_delete

      protected final ActionListener action_delete
      re-usable constant for handle buttons.
    • action_swap

      protected final ActionListener action_swap
      re-usable constant for handle buttons.
    • serializationField

      @Opt protected @Opt JLabel serializationField
      Field where with each change in the GUI inputs a serialization will be presented. Input field, must be set by the user.
    • editingFrame

      protected JFrame editingFrame
  • Constructor Details

    • Gui

      public Gui()
  • Method Details

    • setMessagePane

      public void setMessagePane(JLabel mp)
      Set the field were syntax errors are shown when the input form is stuck.
    • getModel

      protected abstract Model getModel()
      Overriden by generated code. Gives access to the corresponding Model object.
    • makeInstance

      public abstract Gui makeInstance(Model m)
      Overriden by generated code. Creates all fields and initializes them.
    • view2model

      public abstract void view2model(Model m)
      Overriden by generated code. Copies all argumenta values from GUI to Model.
    • model2view

      public abstract void model2view(Model m)
      Overriden by generated code. Copies all argumenta values from Model to GUI.
    • setLivingListLanguagePreferences

      public void setLivingListLanguagePreferences(List<String> lang_prefs)
      Sets a link to a "living", i.e. dynamically changing list of language codes, used for translation. Changes are signalled by calling updateLanguage()
    • updateLanguage

      public void updateLanguage()
      Signals from outside that the language preferences (in particular the first language) have changed.
      Tooltips will be affected the next time they pop-up (language change passive, rendering inquires text actively.)
      Error messages will be affected only from now on (passive).
      Button texts will be changed immediately (language change is active).
    • populate

      protected abstract void populate()
      Callback function, overriden by generated code. Inserts the different labels and input widgets for options and their arguments into this. Does not yet fill in values.
    • translate_description

      @Opt protected @Opt String translate_description(String key)
      Translate a key into the application specific descriptions. (NOT into the standard generic messages.) The result can be in a different language, if the key has not been translated in preferred language. In this case the result is enclosed in brackets.
    • make_label

      protected void make_label(@Opt @Opt String name, @Opt @Opt String abbrev, List<Component> allcomponents)
      Called by Generated code. Creates labels with name and/or abbrev and a panel for the value widgets ("growingGroup") and puts them into top level grid bag. Not both of "name" and "abbrev" may be ==null.
    • getInitialWidthOfValuesPanel

      protected int getInitialWidthOfValuesPanel()
      Deliver the width (in pixels) for the right part (=value part) of every option's representation. Can be overridden by the generated code.
    • make_commentfield

      protected Gui.CommentField make_commentfield(String key, String text)
      Called by generated code whenever a "comment" instruction is interspered into the sequence of option definitions.
      Translated text (found by "key") will be set whenever language is switched by updateLanguage().
    • makeErrorControlled

      public void makeErrorControlled(JComponent... comps)
      Make the arguments becoming inactive on input errors, and active again when the error is corrected.
    • clearErrorControlled

      public void clearErrorControlled()
      Make no external component to become inactive on input errors, and active again when the error is corrected.
    • set_error_on

      protected void set_error_on(JComponent comp, String mkey)
      Reflect an illegal input syntax in the gui. The offending field is coloured backgroundColor_error (=normally red); all focus shifts (internal to the GUI) away from it are hindered by in-activating all sibling inputs; a multi-lingual error text is shown in the dedicated field messagePane.
    • set_error_on

      protected void set_error_on(String mkey)
      Translate the error message key mkey according to messages and present it to the user in the pane messagePane. Memorize errorstate and the key of the message text, for switching the language on the fly.
    • set_error_off

      public void set_error_off()
      Clear errorstate and the contents of messagePane.
    • makeField_int

      protected Gui.Field_int makeField_int(boolean has16)
      Factory method called by populate() in compiled code.
    • makeField_float

      protected Gui.Field_float makeField_float()
      Factory method called by populate() in compiled code.
    • makeField_rat

      protected Gui.Field_rational makeField_rat()
      Factory method called by populate() in compiled code.
    • makeField_string

      protected Gui.Field_string makeField_string()
      Factory method called by populate() in compiled code.
    • makeField_bool

      protected Gui.Field_bool makeField_bool()
      Factory method called by populate() in compiled code.
    • makeField_uri

      protected Gui.Field_uri makeField_uri()
      Factory method called by populate() in compiled code.
    • makeField_uri

      protected Gui.Field_uri makeField_uri(boolean _dirOnly, boolean _fileOnly, boolean _writableOnly)
      Factory method called by populate() in compiled code.

      Renaming of files is disabled via UIManager; thanks to http://stackoverflow.com/questions/8188459/disable-rename-of-a-file-in-jfilechooser/8188695
    • makeField_enum

      protected <E extends Enum<E>> Gui.Field_enum<E> makeField_enum(Class<E> e)
      Factory method called by populate() in compiled code.
      For tooltips on JComboBox-Enum-Items see http://stackoverflow.com/questions/480261/java-swing-mouseover-text-on-jcombobox-items
    • makeField_enumSet

      protected <E extends Enum<E>> Gui.Field_enumSet<E> makeField_enumSet(Class<E> e)
      Factory method called by populate() in compiled code.
    • updatePos

      public static void updatePos(JPanel container, boolean isStar)
      Re-assigns the numbering of the groups, which appears in the title, and makes certain buttons invisible in the "Handles" groups at both ends.

      ASSUME only called when container does contain Handles. Then the last component (count-1) is a Handle, and the next-to-last (count-2) is not!

      Each "middle" handle has all three actions; the "last" has only "add"; The "first" has "add" and (possibly) "delete". The structure of the JPanel is
            panel "pp"                                               count=14
      (6    7       8           9        10          11       12       num=13)
       XXX  Handles Collection  Handles  Collection  Handles  Collection   Handles
                    #0                   #1                  #2
            b b -   F F F       b b b    F F F       b b b    F F F        b - - 
      
      
    • field2coordinates

      protected Object[] field2coordinates(Component field)
      Calculates the position (option name, numeric positions) of an input field for showing it (as a synthesized muli-text) to the user.
      (Currently only used for the title etc. of a FileChooser.)
      res[0]:String = longest parameter name
      res[1]:int 0..n = repetition group number, or -1 for the non-repeting prefix
      res[2]:int 0..n = parameter no in that group, or -1 for single member
              TTLabel JLabel TTLabel JPanel=growingGroup
                                     field field field  Handle Collection(with pos)
                                                               field field field 
        
    • switchOptionEnableState

      public static final void switchOptionEnableState(List<Component> comps, boolean active)
      Sets all components in the list (and all sub-components) to enabled/disableds.
    • switchOptionEnableState

      public static final void switchOptionEnableState(Component comp, boolean active)
      Sets the component itself, and all descendants, to enabled/disabled.
    • displayActive

      protected void displayActive()
      Will be overridden by the generated code. Sets some options to active and others to inactive, depending on the rules and the current states of arguments.
    • setSerializationField

      public void setSerializationField(@Opt @Opt JLabel serializationField)
      Set the widget in wich with each change in the GUI inputs a serialization will be presented.
    • displaySerialization

      protected void displaySerialization()
      Calculate and display a serialization of the current input state of the GUI
    • model2view_repeting

      public static void model2view_repeting(JPanel container, List models)
      Called by the generated code for data transfer. Un-zips the list of components in "container" into Collections and Handles, then calls "model2view" for all objects in "models", possibly after creating new view Collections via "doplus()" of any (/of the first) Gui.Handles.
    • view2model_repeting

      public static <Sub> void view2model_repeting(JPanel container, List<Sub> models)
      Called by the generated code for data transfer. Un-zips the list of components in "container" into Collections and Handles, then calls "view2model" for all Collections, possibly after creating new model instances via "makeModelInstance()" of any (/of the first) Gui.Handles.
    • editGraphically

      public void editGraphically(@Opt @Opt String titleText, @Opt @Opt JPanel titleGraphic, @Opt @Opt Dimension innerArea, String lang, String[] buttonLabels, String[] cancelButtons)
      Interactive execution of the gui panel, very simple style.
      Only one language, no Menus. The method opens a top-level (dialog-)window with the option pane (as generated by the compiler), plus additional buttons plus an error message line. It lets the user play with the widgets until one of the buttons is pressed (and currently no syntax error pending!) Then buttonAction(String) is called, with the untranslated label key.
      Parameters:
      titleText - text on top of the window
      titleGraphic - included above the parameters' panel
      innerArea - if set, default size of parameters' panel
      lang - the initial language
      buttonLabels - the keys of the action buttons (the presented texts are translations from the current muli configuration.)
      cancelButtons - keys of buttons which are active during input errors
    • buttonAction

      protected void buttonAction(String key)