Ejemplo n.º 1
0
 /**
  * Creates an encoding combo box and selects the specified encoding.
  *
  * @param dialog dialog reference
  * @param encoding original encoding
  * @return combo box
  */
 static BaseXCombo encoding(final BaseXDialog dialog, final String encoding) {
   final BaseXCombo cb = new BaseXCombo(dialog, ENCODINGS);
   boolean f = false;
   String enc = encoding == null ? Strings.UTF8 : encoding;
   for (final String s : ENCODINGS) f |= s.equals(enc);
   if (!f) {
     enc = enc.toUpperCase(Locale.ENGLISH);
     for (final String s : ENCODINGS) f |= s.equals(enc);
   }
   cb.setSelectedItem(enc);
   return cb;
 }
Ejemplo n.º 2
0
 /**
  * Returns the current serialization options.
  *
  * @param mth consider specified serialization method (may be {@code null})
  * @return options
  * @throws BaseXException database exception
  */
 private SerializerOptions options(final SerialMethod mth) throws BaseXException {
   final SerializerOptions sopts = new SerializerOptions();
   sopts.assign(params.getText());
   sopts.set(SerializerOptions.METHOD, SerialMethod.valueOf(method.getSelectedItem()));
   sopts.set(SerializerOptions.ENCODING, encoding.getSelectedItem());
   if (mth == SerialMethod.JSON) {
     final JsonSerialOptions jopts = new JsonSerialOptions();
     jopts.assign(mparams.getText());
     sopts.set(SerializerOptions.JSON, jopts);
   } else if (mth == SerialMethod.CSV) {
     final CsvOptions copts = new CsvOptions();
     copts.assign(mparams.getText());
     sopts.set(SerializerOptions.CSV, copts);
   }
   return sopts;
 }
Ejemplo n.º 3
0
 @Override
 public void action(final Object cmp) {
   creds.setText(TRANSLATION + COLS + creds(lang.getSelectedItem().toString()));
   if (cmp == names) {
     gui.gprop.set(GUIProp.SHOWNAME, names.isSelected());
     gui.notify.layout();
   }
   final int mh = hitsAsProperty();
   label.setText(mh == -1 ? ALL : Integer.toString(mh));
 }
Ejemplo n.º 4
0
  @Override
  public void close() {
    try {
      gui.set(MainOptions.EXPORTER, options(SerialMethod.valueOf(method.getSelectedItem())));
    } catch (final BaseXException ex) {
      throw Util.notExpected(ex);
    }
    if (!ok) return;

    super.close();
    path.store();
  }
Ejemplo n.º 5
0
  @Override
  public void close() {
    final MainProp mprop = gui.context.mprop;
    mprop.set(MainProp.LANG, lang.getSelectedItem().toString());

    // new database path: close existing database
    final String dbpath = path.getText();
    if (!mprop.get(MainProp.DBPATH).equals(dbpath)) gui.execute(new Close());
    mprop.set(MainProp.DBPATH, dbpath);
    mprop.write();

    final int mh = hitsAsProperty();
    gui.context.prop.set(Prop.MAXHITS, mh);

    final GUIProp gprop = gui.gprop;
    gprop.set(GUIProp.MOUSEFOCUS, focus.isSelected());
    gprop.set(GUIProp.SIMPLEFD, simpfd.isSelected());
    gprop.set(GUIProp.JAVALOOK, javalook.isSelected());
    gprop.set(GUIProp.MAXHITS, mh);
    gprop.write();
    dispose();
  }
Ejemplo n.º 6
0
  @Override
  public void action(final Object comp) {
    final String pth = path();
    final IOFile io = new IOFile(pth);
    String inf = io.isDir() && io.children().length > 0 ? DIR_NOT_EMPTY : null;
    ok = !pth.isEmpty();

    final SerialMethod mth = SerialMethod.valueOf(method.getSelectedItem());
    final OptionsOption<? extends Options> opts =
        mth == SerialMethod.JSON
            ? SerializerOptions.JSON
            : mth == SerialMethod.CSV ? SerializerOptions.CSV : null;
    final boolean showmparams = opts != null;
    mparams.setEnabled(showmparams);

    if (ok) {
      gui.gopts.set(GUIOptions.INPUTPATH, pth);
      try {
        if (comp == method) {
          if (showmparams) {
            final Options mopts = options(null).get(opts);
            mparams.setToolTipText(tooltip(mopts));
            mparams.setText(mopts.toString());
          } else {
            mparams.setToolTipText(null);
            mparams.setText("");
          }
        }
        Serializer.get(new ArrayOutput(), options(mth));
      } catch (final IOException ex) {
        ok = false;
        inf = ex.getMessage();
      }
    }

    info.setText(inf, ok ? Msg.WARN : Msg.ERROR);
    enableOK(buttons, B_OK, ok);
  }
Ejemplo n.º 7
0
  /**
   * Default constructor.
   *
   * @param main reference to the main window
   */
  public DialogExport(final GUI main) {
    super(main, EXPORT);

    // create checkboxes
    final BaseXBack p = new BaseXBack(new TableLayout(4, 1, 0, 0));
    p.add(new BaseXLabel(OUTPUT_DIR + COL, true, true).border(0, 0, 6, 0));

    // output label
    BaseXBack pp = new BaseXBack(new TableLayout(1, 2, 8, 0));

    path = new BaseXTextField(main.gopts.get(GUIOptions.INPUTPATH), this);
    pp.add(path.history(GUIOptions.INPUTS, this));

    final BaseXButton browse = new BaseXButton(BROWSE_D, this);
    browse.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            choose();
          }
        });
    pp.add(browse);
    p.add(pp);

    // provide components for method and encoding
    final MainOptions opts = gui.context.options;
    final SerializerOptions sopts = opts.get(MainOptions.EXPORTER);

    // method (ignore last entry)
    final StringList sl = new StringList();
    for (final SerialMethod sm : SerialMethod.values()) sl.add(sm.name());
    sl.remove(sl.size() - 1);
    method = new BaseXCombo(this, sl.finish());
    final SerialMethod sm = sopts.get(SerializerOptions.METHOD);
    method.setSelectedItem((sm == null ? SerialMethod.BASEX : sm).name());

    mparams = new BaseXTextField(this);
    mparams.setColumns(24);

    final BaseXBack mth = new BaseXBack(new TableLayout(1, 2, 8, 0));
    mth.add(method);
    mth.add(mparams);

    encoding = new BaseXCombo(this, ENCODINGS);
    String enc = sopts.get(SerializerOptions.ENCODING);
    boolean f = false;
    for (final String s : ENCODINGS) f |= s.equals(enc);
    if (!f) {
      enc = enc.toUpperCase(Locale.ENGLISH);
      for (final String s : ENCODINGS) f |= s.equals(enc);
    }
    encoding.setSelectedItem(f ? enc : sopts.get(SerializerOptions.ENCODING));

    params = new BaseXTextField(sopts.toString(), this);
    params.setToolTipText(tooltip(SerializerMode.DEFAULT.get()));

    pp = new BaseXBack(new TableLayout(3, 2, 16, 6)).border(8, 0, 8, 0);
    pp.add(new BaseXLabel(METHOD + COL, true, true));
    pp.add(mth);
    pp.add(new BaseXLabel(ENCODING + COL, true, true));
    pp.add(encoding);
    pp.add(new BaseXLabel(PARAMETERS + COL, true, true));
    pp.add(params);
    p.add(pp);
    info = new BaseXLabel(" ").border(8, 0, 0, 0);
    p.add(info);

    // indentation
    set(p, BorderLayout.CENTER);

    // buttons
    pp = new BaseXBack(new BorderLayout());
    buttons = okCancel();
    pp.add(buttons, BorderLayout.EAST);
    set(pp, BorderLayout.SOUTH);

    action(method);
    finish(null);
  }
Ejemplo n.º 8
0
  /**
   * Default constructor.
   *
   * @param main reference to the main window
   */
  public DialogPrefs(final GUI main) {
    super(main, PREFERENCES);

    // create checkboxes
    final BaseXBack pp;
    if (Prop.langright) pp = new BaseXBack(new RTLTableLayout(12, 1));
    else pp = new BaseXBack(new TableLayout(12, 1));
    pp.add(new BaseXLabel(DATABASE_PATH + COL, true, true));

    BaseXBack p;
    if (Prop.langright) p = new BaseXBack(new RTLTableLayout(1, 2, 8, 0));
    else p = new BaseXBack(new TableLayout(1, 2, 8, 0));

    final MainProp mprop = gui.context.mprop;
    final GUIProp gprop = gui.gprop;
    path = new BaseXTextField(mprop.dbpath().path(), this);

    final BaseXButton button = new BaseXButton(BROWSE_D, this);
    button.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final IOFile file =
                new BaseXFileChooser(CHOOSE_DIR, path.getText(), gui).select(Mode.DOPEN);
            if (file != null) path.setText(file.dirPath());
          }
        });

    p.add(path);
    p.add(button);
    pp.add(p);
    pp.add(new BaseXLabel(GUI_INTERACTIONS + COL, true, true).border(12, 0, 6, 0));

    // checkbox for Java look and feel
    javalook = new BaseXCheckBox(JAVA_LF, gprop.is(GUIProp.JAVALOOK), this);
    pp.add(javalook);

    // checkbox for realtime mouse focus
    focus = new BaseXCheckBox(RT_FOCUS, gprop.is(GUIProp.MOUSEFOCUS), this);
    pp.add(focus);

    // checkbox for simple file dialog
    simpfd = new BaseXCheckBox(SIMPLE_FILE_CHOOSER, gprop.is(GUIProp.SIMPLEFD), this);
    pp.add(simpfd);

    // enable only if current document contains name attributes
    final boolean sn = gprop.is(GUIProp.SHOWNAME);
    names = new BaseXCheckBox(SHOW_NAME_ATTS, sn, 6, this);
    final Data data = gui.context.data();
    names.setEnabled(data != null && ViewData.nameID(data) != 0);
    oldShowNames = sn;
    pp.add(names);

    // maximum number of hits to be displayed
    final int mh = hitsForSlider();
    limit =
        new BaseXSlider(
            0,
            HITS.length - 1,
            mh,
            this,
            new ActionListener() {
              @Override
              public void actionPerformed(final ActionEvent e) {
                action(limit);
              }
            });
    label = new BaseXLabel(" ");
    if (Prop.langright) p = new BaseXBack(new RTLTableLayout(1, 4, 12, 0));
    else p = new BaseXBack(new TableLayout(1, 4, 12, 0));
    p.add(new BaseXLabel(MAX_NO_OF_HITS + COL));
    p.add(limit);
    p.add(label);
    pp.add(p);

    // checkbox for simple file dialog
    pp.add(new BaseXLabel(LANGUAGE_RESTART + COL, true, true).border(16, 0, 6, 0));
    lang = new BaseXCombo(this, LANGS[0]);
    lang.setSelectedItem(mprop.get(MainProp.LANG));
    creds = new BaseXLabel(" ");
    if (Prop.langright) p = new BaseXBack(new RTLTableLayout(1, 2, 12, 0));
    else p = new BaseXBack(new TableLayout(1, 2, 12, 0));
    p.add(lang);
    p.add(creds);
    pp.add(p);

    set(pp, BorderLayout.CENTER);
    set(okCancel(), BorderLayout.SOUTH);
    action(null);
    finish(null);
  }