    001package org.vishia.gral.cfg;
    002
    003import java.io.File;
    004import java.text.ParseException;
    005
    006import org.vishia.gral.base.GralGraphicTimeOrder;
    007import org.vishia.gral.base.GralMng;
    008import org.vishia.gral.base.GralPanelContent;
    009import org.vishia.gral.base.GralWindow;
    010import org.vishia.gral.ifc.GralWindow_ifc;
    011import org.vishia.mainCmd.MainCmdLogging_ifc;
    012import org.vishia.msgDispatch.LogMessageStream;
    013
    014/*Test with Jbat: call Jbat with this java file with its full path:
    015file: D:/vishia/Java/srcJava_vishiaGui/org/vishia/gral/cfg/GralCfgWindow.java
    016==JZcmd==
    017java org.vishia.gral.test.HelloWorld.openWindow();
    018String windowTitle = <:>Test GralCfgWindow<.>;
    019String gConfig =
    020<:>
    021 ##A value to show, following by a label.
    022 @4+2,2+30:Show("name"); Text("label");
    023 @6..-2, 2..0: InputBox(box);
    024<.>;
    025Obj window = java org.vishia.gral.cfg.GralCfgWindow.createWindow("testCfgWind", windowTitle, gConfig, jzcmdsub.currdir, jzcmd.log);
    026window.setTextIn("name", "example");
    027window.setTextIn("box", "Box input");
    028java org.vishia.gral.test.HelloWorld.waitForClosePrimaryWindow();
    029==endJZcmd==
    030*/
    031
    032/**This is the class to build a graphic window in any application which is configurable.
    033 * It uses an existing instance of the {@link GralMng}
    034 * <br><br>
    035 * Note: See {@link org.vishia.gral.area9.GuiCfg}, that is an application with 9 areas for configuration.
    036 *
    037 * @author Hartmut Schorrig
    038 *
    039 */
    040public class GralCfgWindow
    041{
    042
    043  /**The version, history and license.
    044   * <ul>
    045   * <li>2018-09-17 GralCfgWindow: with argument for size and AWT/SWT
    046   * <li>2015-04-26 Hartmut created: For usage in Jzcmd-scripts.
    047   * </ul>
    048   *
    049   * <b>Copyright/Copyleft</b>:
    050   * For this source the LGPL Lesser General Public License,
    051   * published by the Free Software Foundation is valid.
    052   * It means:
    053   * <ol>
    054   * <li> You can use this source without any restriction for any desired purpose.
    055   * <li> You can redistribute copies of this source to everybody.
    056   * <li> Every user of this source, also the user of redistribute copies
    057   *    with or without payment, must accept this license for further using.
    058   * <li> But the LPGL is not appropriate for a whole software product,
    059   *    if this source is only a part of them. It means, the user
    060   *    must publish this part of source,
    061   *    but don't need to publish the whole source of the own product.
    062   * <li> You can study and modify (improve) this source
    063   *    for own using or for redistribution, but you have to license the
    064   *    modified sources likewise under this LGPL Lesser General Public License.
    065   *    You mustn't delete this Copyright/Copyleft inscription in this source file.
    066   * </ol>
    067   * If you are intent to use this sources without publishing its usage, you can get
    068   * a second license subscribing a special contract with the author.
    069   *
    070   * @author Hartmut Schorrig = hartmut.schorrig@vishia.de
    071   *
    072   *
    073   */
    074  public final static int version = 0x20150426;
    075
    076
    077  final private MainCmdLogging_ifc log;
    078
    079  /**The configuration data for graphical appearance. */
    080  final private GralCfgData guiCfgData;
    081
    082  /**Directory for images. */
    083  File imgDir;
    084
    085  final public GralWindow window;
    086
    087  /**Creates a new Window or opens the existing one with given name.
    088   * @param sName Name of the window inside the gral manager to address the window.
    089   * @param sTitle text in the title bar
    090   * @param size 'A'...'E' as pixel/grid unit for SWT graphic. 'a'...'e' same for AWT-Graphic
    091   * @param sCfg textual given configuration for the window.
    092   * @param imgDir start directory path where images are located if given with relative path.
    093   * @param log interface for logging output of parser and creation.
    094   * @throws ParseException on errors in the sCfg
    095   */
    096  private GralCfgWindow(String sName, String sTitle, char size, CharSequence sCfg, File imgDir, MainCmdLogging_ifc log) throws ParseException {
    097    this.log = log !=null ? log : log;
    098    this.guiCfgData = new GralCfgData(null);  //no config conditions given.
    099    this.imgDir = imgDir;
    100    String swtOrawt;
    101    if(size < 'a') { swtOrawt = "SWT"; }
    102    else { size -= 'a'-'A'; swtOrawt = "AWT"; }
    103    GralCfgZbnf cfgZbnf = new GralCfgZbnf();  //temporary instance for parsing
    104    cfgZbnf.configureWithZbnf(sCfg, guiCfgData); //
    105    int props = GralWindow_ifc.windRemoveOnClose | GralWindow_ifc.windConcurrently | GralWindow_ifc.windResizeable;
    106    GralMng mng = GralMng.get();
    107    mng.selectPrimaryWindow();
    108    this.window = new GralWindow("10+50, 10+100", sName, sTitle, props);
    109    configInGthread.getCtDone(0);
    110    this.window.create(swtOrawt, size, log, configInGthread);
    111    configInGthread.awaitExecution(1, 0);
    112  }
    113
    114  /**Creates a window with a given configuration.
    115   * The window will be removed on closing.
    116   * @param sName Name of the window inside the gral manager to address the window.
    117   * @param sTitle text in the title bar
    118   * @param size 'A'...'E' as pixel/grid unit for SWT graphic. 'a'...'e' same for AWT-Graphic
    119   * @param sCfg textual given configuration for the window.
    120   * @param imgDir start directory path where images are located if given with relative path.
    121   * @param log log output for status and parse messages
    122   * @throws ParseException on errors in the sCfg
    123   */
    124  public static GralWindow createWindow(String sName, String sTitle, char size, CharSequence sCfg, File imgDir, MainCmdLogging_ifc log)
    125  throws ParseException
    126  {
    127    GralCfgWindow thiz = new GralCfgWindow(sName, sTitle, size, sCfg, imgDir, log);
    128    return thiz.window;
    129  }
    130
    131
    132
    133
    134
    135
    136  /**Code snippet to run the ZBNF-configurator (text controlled GUI)
    137   *
    138   */
    139  @SuppressWarnings("synthetic-access")
    140  GralGraphicTimeOrder configInGthread = new GralGraphicTimeOrder("GralCfgWindow.config")
    141  {
    142
    143    private static final long serialVersionUID = 1L;
    144
    145    @Override public void executeOrder(){
    146      GralMng mng = GralMng.get();
    147      mng.selectPanel("primaryWindow");  //window position relative to the primary window.
    148      window.setToPanel(mng);
    149      window.setVisible(true);
    150      GralCfgBuilder cfgBuilder = new GralCfgBuilder(guiCfgData, mng, imgDir);
    151      cfgBuilder.buildGui(log, 0);
    152    }
    153  ////
    154  };
    155
    156
    157
    158
    159}