Пример #1
0
  private void commit() {
    String serverName = (String) server.getSelectedItem();
    if (serverName == null || serverName.equals("")) {
      vlog.error("No server name specified!");
      if (VncViewer.nViewers == 1)
        if (cc.viewer instanceof VncViewer) {
          ((VncViewer) cc.viewer).exit(1);
        }
      ret = false;
      endDialog();
    }

    // set params
    if (opts.via != null && opts.via.indexOf(':') >= 0) {
      opts.serverName = serverName;
    } else {
      opts.serverName = Hostname.getHost(serverName);
      opts.port = Hostname.getPort(serverName);
    }

    // Update the history list
    String valueStr = UserPreferences.get("ServerDialog", "history");
    String t = (valueStr == null) ? "" : valueStr;
    StringTokenizer st = new StringTokenizer(t, ",");
    StringBuffer sb = new StringBuffer().append((String) server.getSelectedItem());
    while (st.hasMoreTokens()) {
      String str = st.nextToken();
      if (!str.equals((String) server.getSelectedItem()) && !str.equals("")) {
        sb.append(',');
        sb.append(str);
      }
    }
    UserPreferences.set("ServerDialog", "history", sb.toString());
    UserPreferences.save("ServerDialog");
  }
Пример #2
0
  private void savePrefs() {
    SikuliIDE ide = SikuliIDE.getInstance();
    pref.setCaptureDelay((Double) _spnDelay.getValue());
    pref.setCaptureHotkey(_cap_hkey);
    pref.setCaptureHotkeyModifiers(_cap_mod);
    pref.setAutoNamingMethod(
        _radTimestamp.isSelected()
            ? UserPreferences.AUTO_NAMING_TIMESTAMP
            : _radOCR.isSelected()
                ? UserPreferences.AUTO_NAMING_OCR
                : UserPreferences.AUTO_NAMING_OFF);
    if (_old_cap_hkey != _cap_hkey || _old_cap_mod != _cap_mod) {
      ide.removeCaptureHotkey(_old_cap_hkey, _old_cap_mod);
      ide.installCaptureHotkey(_cap_hkey, _cap_mod);
    }
    pref.setCheckUpdate(_chkAutoUpdate.isSelected());

    pref.setExpandTab(_chkExpandTab.isSelected());
    pref.setTabWidth((Integer) _spnTabWidth.getValue());

    pref.setFontName((String) _cmbFontName.getSelectedItem());
    pref.setFontSize((Integer) _spnFontSize.getValue());

    Locale locale = (Locale) _cmbLang.getSelectedItem();
    pref.setLocale(locale);
    I18N.setLocale(locale);
  }
Пример #3
0
 private void initFontPrefs() {
   UserPreferences pref = UserPreferences.getInstance();
   String[] fontList =
       GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
   for (String font : fontList) _cmbFontName.addItem(font);
   _cmbFontName.setSelectedItem(pref.getFontName());
   _spnFontSize.setValue(pref.getFontSize());
 }
Пример #4
0
  private void loadPrefs() {
    SikuliIDE ide = SikuliIDE.getInstance();
    double delay = pref.getCaptureDelay();
    _spnDelay.setValue(delay);
    _old_cap_hkey = _cap_hkey = pref.getCaptureHotkey();
    _old_cap_mod = _cap_mod = pref.getCaptureHotkeyModifiers();
    setTxtHotkey(_cap_hkey, _cap_mod);
    switch (pref.getAutoNamingMethod()) {
      case UserPreferences.AUTO_NAMING_TIMESTAMP:
        _radTimestamp.setSelected(true);
        break;
      case UserPreferences.AUTO_NAMING_OCR:
        _radOCR.setSelected(true);
        break;
      case UserPreferences.AUTO_NAMING_OFF:
        _radOff.setSelected(true);
        break;
      default:
        Debug.error("Error in reading auto naming method preferences");
    }
    _chkAutoUpdate.setSelected(pref.getCheckUpdate());

    _chkExpandTab.setSelected(pref.getExpandTab());
    _spnTabWidth.setValue(pref.getTabWidth());
    initFontPrefs();
    initLangPrefs();
  }
Пример #5
0
  private void initLangPrefs() {
    String[] SUPPORT_LOCALES = {
      "es", "pt_BR", "ar", "fr", "ru", "bg", "he", "sv", "ca", "ja", "tr", "da", "ko", "uk", "de",
      "nl", "zh_CN", "en_US", "pl", "zh_TW"
    };
    Locale[] sortedLocales = new Locale[SUPPORT_LOCALES.length];
    UserPreferences pref = UserPreferences.getInstance();
    int count = 0;
    for (String locale_code : SUPPORT_LOCALES) {
      Locale l;
      if (locale_code.indexOf("_") >= 0) {
        String[] lang_country = locale_code.split("_");
        l = new Locale(lang_country[0], lang_country[1]);
      } else l = new Locale(locale_code);
      sortedLocales[count++] = l;
    }
    Arrays.sort(
        sortedLocales,
        new Comparator<Locale>() {
          public int compare(Locale l1, Locale l2) {
            return l1.getDisplayLanguage().compareTo(l2.getDisplayLanguage());
          }
        });

    for (Locale l : sortedLocales) {
      _cmbLang.addItem(l);
    }
    _cmbLang.setRenderer(new LocaleListCellRenderer());
    Locale curLocale = pref.getLocale();
    _cmbLang.setSelectedItem(curLocale);
    if (!_cmbLang.getSelectedItem().equals(curLocale)) {
      if (curLocale.getVariant().length() > 0) {
        curLocale = new Locale(curLocale.getLanguage(), curLocale.getCountry());
        _cmbLang.setSelectedItem(curLocale);
      }
      if (!_cmbLang.getSelectedItem().equals(curLocale))
        _cmbLang.setSelectedItem(new Locale(curLocale.getLanguage()));
    }
  }
Пример #6
0
  public ServerDialog(OptionsDialog options_, Options opts_, CConn cc_) {

    super(true);
    cc = cc_;
    opts = opts_;

    options = options_;

    JLabel serverLabel = new JLabel("VNC server:", JLabel.RIGHT);
    String valueStr = null;
    if (opts.serverName != null) {
      String[] s = new String[1];
      s[0] = opts.serverName;
      server = new JComboBox(s);
    } else if ((valueStr = UserPreferences.get("ServerDialog", "history")) != null) {
      server = new JComboBox(valueStr.split(","));
    } else {
      server = new JComboBox();
    }

    // Hack to set the left inset on editable JComboBox
    if (UIManager.getLookAndFeel().getID() == "Windows") {
      server.setBorder(
          BorderFactory.createCompoundBorder(
              server.getBorder(), BorderFactory.createEmptyBorder(0, 2, 0, 0)));
    } else if (UIManager.getLookAndFeel().getID() == "Metal") {
      ComboBoxEditor editor = server.getEditor();
      JTextField jtf = (JTextField) editor.getEditorComponent();
      jtf.setBorder(new CompoundBorder(jtf.getBorder(), new EmptyBorder(0, 2, 0, 0)));
    }

    server.setEditable(true);
    editor = server.getEditor();
    editor
        .getEditorComponent()
        .addKeyListener(
            new KeyListener() {
              public void keyTyped(KeyEvent e) {}

              public void keyReleased(KeyEvent e) {}

              public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                  server.insertItemAt(editor.getItem(), 0);
                  server.setSelectedIndex(0);
                  commit();
                  endDialog();
                }
              }
            });

    topPanel = new JPanel(new GridBagLayout());

    Dialog.addGBComponent(
        new JLabel(VncViewer.logoIcon),
        topPanel,
        0,
        0,
        1,
        1,
        0,
        0,
        0,
        1,
        GridBagConstraints.HORIZONTAL,
        GridBagConstraints.LINE_START,
        new Insets(5, 5, 5, 15));
    Dialog.addGBComponent(
        serverLabel,
        topPanel,
        1,
        0,
        1,
        1,
        0,
        0,
        0,
        1,
        GridBagConstraints.HORIZONTAL,
        GridBagConstraints.LINE_END,
        new Insets(10, 0, 5, 5));
    Dialog.addGBComponent(
        server,
        topPanel,
        2,
        0,
        1,
        1,
        0,
        0,
        1,
        1,
        GridBagConstraints.HORIZONTAL,
        GridBagConstraints.CENTER,
        new Insets(10, 0, 5, 20));

    optionsButton = new JButton("Options...");
    aboutButton = new JButton("About...");
    okButton = new JButton("Connect");
    cancelButton = new JButton("Cancel");
    buttonPanel = new JPanel(new GridBagLayout());
    buttonPanel.setPreferredSize(new Dimension(350, 40));
    Dialog.addGBComponent(
        aboutButton,
        buttonPanel,
        0,
        3,
        1,
        1,
        0,
        0,
        0.8,
        1,
        GridBagConstraints.HORIZONTAL,
        GridBagConstraints.CENTER,
        new Insets(0, 2, 0, 5));
    Dialog.addGBComponent(
        optionsButton,
        buttonPanel,
        1,
        3,
        1,
        1,
        0,
        0,
        1,
        1,
        GridBagConstraints.HORIZONTAL,
        GridBagConstraints.CENTER,
        new Insets(0, 2, 0, 5));
    Dialog.addGBComponent(
        okButton,
        buttonPanel,
        2,
        3,
        1,
        1,
        0,
        0,
        0.7,
        1,
        GridBagConstraints.HORIZONTAL,
        GridBagConstraints.CENTER,
        new Insets(0, 2, 0, 5));
    Dialog.addGBComponent(
        cancelButton,
        buttonPanel,
        3,
        3,
        1,
        1,
        0,
        0,
        0.6,
        1,
        GridBagConstraints.HORIZONTAL,
        GridBagConstraints.CENTER,
        new Insets(0, 2, 0, 5));

    server.addActionListener(this);
    optionsButton.addActionListener(this);
    aboutButton.addActionListener(this);
    okButton.addActionListener(this);
    cancelButton.addActionListener(this);
  }
Пример #7
0
public class PreferencesWin extends JFrame {
  UserPreferences pref = UserPreferences.getInstance();
  int _cap_hkey, _cap_mod;
  int _old_cap_hkey, _old_cap_mod;

  public PreferencesWin() {
    super(SikuliIDE._I("winPreferences"));
    initComponents();
    loadPrefs();
  }

  private void loadPrefs() {
    SikuliIDE ide = SikuliIDE.getInstance();
    double delay = pref.getCaptureDelay();
    _spnDelay.setValue(delay);
    _old_cap_hkey = _cap_hkey = pref.getCaptureHotkey();
    _old_cap_mod = _cap_mod = pref.getCaptureHotkeyModifiers();
    setTxtHotkey(_cap_hkey, _cap_mod);
    switch (pref.getAutoNamingMethod()) {
      case UserPreferences.AUTO_NAMING_TIMESTAMP:
        _radTimestamp.setSelected(true);
        break;
      case UserPreferences.AUTO_NAMING_OCR:
        _radOCR.setSelected(true);
        break;
      case UserPreferences.AUTO_NAMING_OFF:
        _radOff.setSelected(true);
        break;
      default:
        Debug.error("Error in reading auto naming method preferences");
    }
    _chkAutoUpdate.setSelected(pref.getCheckUpdate());

    _chkExpandTab.setSelected(pref.getExpandTab());
    _spnTabWidth.setValue(pref.getTabWidth());
    initFontPrefs();
    initLangPrefs();
  }

  private void initLangPrefs() {
    String[] SUPPORT_LOCALES = {
      "es", "pt_BR", "ar", "fr", "ru", "bg", "he", "sv", "ca", "ja", "tr", "da", "ko", "uk", "de",
      "nl", "zh_CN", "en_US", "pl", "zh_TW"
    };
    Locale[] sortedLocales = new Locale[SUPPORT_LOCALES.length];
    UserPreferences pref = UserPreferences.getInstance();
    int count = 0;
    for (String locale_code : SUPPORT_LOCALES) {
      Locale l;
      if (locale_code.indexOf("_") >= 0) {
        String[] lang_country = locale_code.split("_");
        l = new Locale(lang_country[0], lang_country[1]);
      } else l = new Locale(locale_code);
      sortedLocales[count++] = l;
    }
    Arrays.sort(
        sortedLocales,
        new Comparator<Locale>() {
          public int compare(Locale l1, Locale l2) {
            return l1.getDisplayLanguage().compareTo(l2.getDisplayLanguage());
          }
        });

    for (Locale l : sortedLocales) {
      _cmbLang.addItem(l);
    }
    _cmbLang.setRenderer(new LocaleListCellRenderer());
    Locale curLocale = pref.getLocale();
    _cmbLang.setSelectedItem(curLocale);
    if (!_cmbLang.getSelectedItem().equals(curLocale)) {
      if (curLocale.getVariant().length() > 0) {
        curLocale = new Locale(curLocale.getLanguage(), curLocale.getCountry());
        _cmbLang.setSelectedItem(curLocale);
      }
      if (!_cmbLang.getSelectedItem().equals(curLocale))
        _cmbLang.setSelectedItem(new Locale(curLocale.getLanguage()));
    }
  }

  private void initFontPrefs() {
    UserPreferences pref = UserPreferences.getInstance();
    String[] fontList =
        GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    for (String font : fontList) _cmbFontName.addItem(font);
    _cmbFontName.setSelectedItem(pref.getFontName());
    _spnFontSize.setValue(pref.getFontSize());
  }

  private void savePrefs() {
    SikuliIDE ide = SikuliIDE.getInstance();
    pref.setCaptureDelay((Double) _spnDelay.getValue());
    pref.setCaptureHotkey(_cap_hkey);
    pref.setCaptureHotkeyModifiers(_cap_mod);
    pref.setAutoNamingMethod(
        _radTimestamp.isSelected()
            ? UserPreferences.AUTO_NAMING_TIMESTAMP
            : _radOCR.isSelected()
                ? UserPreferences.AUTO_NAMING_OCR
                : UserPreferences.AUTO_NAMING_OFF);
    if (_old_cap_hkey != _cap_hkey || _old_cap_mod != _cap_mod) {
      ide.removeCaptureHotkey(_old_cap_hkey, _old_cap_mod);
      ide.installCaptureHotkey(_cap_hkey, _cap_mod);
    }
    pref.setCheckUpdate(_chkAutoUpdate.isSelected());

    pref.setExpandTab(_chkExpandTab.isSelected());
    pref.setTabWidth((Integer) _spnTabWidth.getValue());

    pref.setFontName((String) _cmbFontName.getSelectedItem());
    pref.setFontSize((Integer) _spnFontSize.getValue());

    Locale locale = (Locale) _cmbLang.getSelectedItem();
    pref.setLocale(locale);
    I18N.setLocale(locale);
  }

  private void setTxtHotkey(int code, int mod) {
    _cap_hkey = code;
    _cap_mod = mod;
    _txtHotkey.setText(Utils.convertKeyToText(code, mod));
  }

  private void btnOkActionPerformed(ActionEvent e) {
    savePrefs();
    this.dispose();
  }

  private void btnApplyActionPerformed(ActionEvent e) {
    savePrefs();
  }

  private void btnCancelActionPerformed(ActionEvent e) {
    this.dispose();
  }

  private void txtHotkeyFocusGained(FocusEvent e) {
    _txtHotkey.setEditable(true);
  }

  private void txtHotkeyKeyPressed(KeyEvent e) {
    int code = e.getKeyCode();
    int mod = e.getModifiers();
    Debug.log(7, "" + code + " " + mod);
    setTxtHotkey(code, mod);
    _txtHotkey.setEditable(false);
  }

  private void updateFontPreview() {
    SikuliIDE ide = SikuliIDE.getInstance();
    Font font =
        new Font(
            (String) _cmbFontName.getSelectedItem(), Font.PLAIN, (Integer) _spnFontSize.getValue());

    SikuliCodePane codePane = SikuliIDE.getInstance().getCurrentCodePane();
    if (Utils.typeOfCodePane(codePane) == Utils.SikuliCodePaneType.SIKULI_PANE_TYPE_TEXT) {
      // preview only supported on text code panes
      SikuliTextPane textPane = (SikuliTextPane) (codePane.getComponent());
      textPane.setFont(font);
    }
  }

  private void fontNameItemStateChanged(ItemEvent e) {
    updateFontPreview();
  }

  private void fontSizeStateChanged(ChangeEvent e) {
    updateFontPreview();
  }

  private void initComponents() {
    // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
    DefaultComponentFactory compFactory = DefaultComponentFactory.getInstance();
    _tabPane = new JTabbedPane();
    JPanel paneCapture = new JPanel();
    _txtHotkey = new JTextField();
    _lblHotkey = new JLabel();
    _lblDelay = new JLabel();
    _spnDelay = new JSpinner();
    _lblDelaySecs = new JLabel();
    _lblNaming = new JLabel();
    _radTimestamp = new JRadioButton();
    _radOCR = new JRadioButton();
    _radOff = new JRadioButton();
    _paneTextEditing = new JPanel();
    _chkExpandTab = new JCheckBox();
    _lblTabWidth = new JLabel();
    _cmbFontName = new JComboBox();
    _lblFont = new JLabel();
    _titleAppearance = compFactory.createTitle("");
    _titleIndentation = compFactory.createTitle("");
    _spnTabWidth = new JSpinner();
    _lblFontSize = new JLabel();
    _spnFontSize = new JSpinner();
    JPanel paneGeneral = new JPanel();
    _chkAutoUpdate = new JCheckBox();
    _cmbLang = new JComboBox();
    _lblUpdates = new JLabel();
    _lblLanguage = new JLabel();
    JPanel paneOkCancel = new JPanel();
    JPanel hSpacer1 = new JPanel(null);
    _btnOk = new JButton();
    _btnApply = new JButton();
    _btnCancel = new JButton();

    // ======== this ========
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    // ======== _tabPane ========
    {
      _tabPane.setBorder(new EmptyBorder(10, 10, 0, 10));

      // ======== paneCapture ========
      {

        // ---- _txtHotkey ----
        _txtHotkey.setHorizontalAlignment(SwingConstants.RIGHT);
        _txtHotkey.addFocusListener(
            new FocusAdapter() {
              @Override
              public void focusGained(FocusEvent e) {
                txtHotkeyFocusGained(e);
              }
            });
        _txtHotkey.addKeyListener(
            new KeyAdapter() {
              @Override
              public void keyPressed(KeyEvent e) {
                txtHotkeyKeyPressed(e);
              }
            });

        // ---- _lblHotkey ----
        _lblHotkey.setLabelFor(_txtHotkey);

        // ---- _lblDelay ----
        _lblDelay.setLabelFor(_spnDelay);

        // ---- _spnDelay ----
        _spnDelay.setModel(new SpinnerNumberModel(1.0, 0.0, null, 0.1));

        // ---- _radTimestamp ----
        _radTimestamp.setSelected(true);

        GroupLayout paneCaptureLayout = new GroupLayout(paneCapture);
        paneCapture.setLayout(paneCaptureLayout);
        paneCaptureLayout.setHorizontalGroup(
            paneCaptureLayout
                .createParallelGroup()
                .add(
                    paneCaptureLayout
                        .createSequentialGroup()
                        .add(26, 26, 26)
                        .add(
                            paneCaptureLayout
                                .createParallelGroup()
                                .add(GroupLayout.TRAILING, _lblDelay)
                                .add(GroupLayout.TRAILING, _lblHotkey)
                                .add(GroupLayout.TRAILING, _lblNaming))
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(
                            paneCaptureLayout
                                .createParallelGroup()
                                .add(_radTimestamp)
                                .add(_radOCR)
                                .add(_radOff)
                                .add(
                                    paneCaptureLayout
                                        .createSequentialGroup()
                                        .add(
                                            _spnDelay,
                                            GroupLayout.DEFAULT_SIZE,
                                            148,
                                            Short.MAX_VALUE)
                                        .addPreferredGap(LayoutStyle.RELATED)
                                        .add(
                                            _lblDelaySecs,
                                            GroupLayout.DEFAULT_SIZE,
                                            161,
                                            Short.MAX_VALUE))
                                .add(_txtHotkey, GroupLayout.DEFAULT_SIZE, 315, Short.MAX_VALUE))
                        .add(69, 69, 69)));
        paneCaptureLayout.setVerticalGroup(
            paneCaptureLayout
                .createParallelGroup()
                .add(
                    paneCaptureLayout
                        .createSequentialGroup()
                        .add(34, 34, 34)
                        .add(
                            paneCaptureLayout
                                .createParallelGroup(GroupLayout.BASELINE)
                                .add(
                                    _lblHotkey,
                                    GroupLayout.PREFERRED_SIZE,
                                    22,
                                    GroupLayout.PREFERRED_SIZE)
                                .add(
                                    _txtHotkey,
                                    GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(
                            paneCaptureLayout
                                .createParallelGroup()
                                .add(
                                    _lblDelay,
                                    GroupLayout.PREFERRED_SIZE,
                                    28,
                                    GroupLayout.PREFERRED_SIZE)
                                .add(
                                    _spnDelay,
                                    GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                                .add(
                                    _lblDelaySecs,
                                    GroupLayout.PREFERRED_SIZE,
                                    28,
                                    GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(
                            paneCaptureLayout
                                .createParallelGroup(GroupLayout.LEADING, false)
                                .add(
                                    paneCaptureLayout
                                        .createSequentialGroup()
                                        .add(
                                            paneCaptureLayout
                                                .createParallelGroup(GroupLayout.BASELINE)
                                                .add(
                                                    _lblNaming,
                                                    GroupLayout.PREFERRED_SIZE,
                                                    22,
                                                    GroupLayout.PREFERRED_SIZE)
                                                .add(_radTimestamp))
                                        .add(18, 18, 18)
                                        .add(_radOff)
                                        .addPreferredGap(LayoutStyle.RELATED))
                                .add(
                                    GroupLayout.TRAILING,
                                    paneCaptureLayout
                                        .createSequentialGroup()
                                        .add(_radOCR)
                                        .add(21, 21, 21)))
                        .add(80, 80, 80)));
      }
      _tabPane.addTab(I18N._I("prefTabScreenCapturing"), paneCapture);

      // ======== _paneTextEditing ========
      {

        // ---- _lblTabWidth ----
        _lblTabWidth.setLabelFor(_spnTabWidth);

        // ---- _cmbFontName ----
        _cmbFontName.addItemListener(
            new ItemListener() {
              public void itemStateChanged(ItemEvent e) {
                fontNameItemStateChanged(e);
              }
            });

        // ---- _lblFont ----
        _lblFont.setLabelFor(_cmbFontName);

        // ---- _lblFontSize ----
        _lblFontSize.setLabelFor(_cmbFontName);

        // ---- _spnFontSize ----
        _spnFontSize.addChangeListener(
            new ChangeListener() {
              public void stateChanged(ChangeEvent e) {
                fontSizeStateChanged(e);
              }
            });

        GroupLayout _paneTextEditingLayout = new GroupLayout(_paneTextEditing);
        _paneTextEditing.setLayout(_paneTextEditingLayout);
        _paneTextEditingLayout.setHorizontalGroup(
            _paneTextEditingLayout
                .createParallelGroup()
                .add(
                    GroupLayout.TRAILING,
                    _paneTextEditingLayout
                        .createSequentialGroup()
                        .add(95, 95, 95)
                        .add(
                            _paneTextEditingLayout
                                .createParallelGroup()
                                .add(
                                    _titleIndentation,
                                    GroupLayout.PREFERRED_SIZE,
                                    GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                                .add(
                                    _paneTextEditingLayout
                                        .createSequentialGroup()
                                        .add(
                                            _titleAppearance,
                                            GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(LayoutStyle.RELATED)
                                        .add(
                                            _paneTextEditingLayout
                                                .createParallelGroup()
                                                .add(
                                                    _paneTextEditingLayout
                                                        .createSequentialGroup()
                                                        .add(29, 29, 29)
                                                        .add(
                                                            _paneTextEditingLayout
                                                                .createParallelGroup()
                                                                .add(
                                                                    GroupLayout.TRAILING,
                                                                    _lblTabWidth)
                                                                .add(GroupLayout.TRAILING, _lblFont)
                                                                .add(
                                                                    GroupLayout.TRAILING,
                                                                    _lblFontSize))
                                                        .addPreferredGap(LayoutStyle.RELATED)
                                                        .add(
                                                            _paneTextEditingLayout
                                                                .createParallelGroup()
                                                                .add(
                                                                    _cmbFontName,
                                                                    0,
                                                                    218,
                                                                    Short.MAX_VALUE)
                                                                .add(
                                                                    _spnFontSize,
                                                                    GroupLayout.PREFERRED_SIZE,
                                                                    67,
                                                                    GroupLayout.PREFERRED_SIZE)
                                                                .add(
                                                                    _spnTabWidth,
                                                                    GroupLayout.PREFERRED_SIZE,
                                                                    52,
                                                                    GroupLayout.PREFERRED_SIZE))
                                                        .addPreferredGap(
                                                            LayoutStyle.RELATED,
                                                            97,
                                                            Short.MAX_VALUE))
                                                .add(
                                                    _chkExpandTab,
                                                    GroupLayout.DEFAULT_SIZE,
                                                    420,
                                                    Short.MAX_VALUE))))
                        .addContainerGap()));
        _paneTextEditingLayout.setVerticalGroup(
            _paneTextEditingLayout
                .createParallelGroup()
                .add(
                    _paneTextEditingLayout
                        .createSequentialGroup()
                        .add(21, 21, 21)
                        .add(
                            _titleIndentation,
                            GroupLayout.PREFERRED_SIZE,
                            GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                        .add(
                            _paneTextEditingLayout
                                .createParallelGroup()
                                .add(
                                    _paneTextEditingLayout
                                        .createSequentialGroup()
                                        .add(81, 81, 81)
                                        .add(
                                            _titleAppearance,
                                            GroupLayout.PREFERRED_SIZE,
                                            GroupLayout.DEFAULT_SIZE,
                                            GroupLayout.PREFERRED_SIZE))
                                .add(
                                    _paneTextEditingLayout
                                        .createSequentialGroup()
                                        .addPreferredGap(LayoutStyle.RELATED)
                                        .add(_chkExpandTab)
                                        .addPreferredGap(LayoutStyle.RELATED)
                                        .add(
                                            _paneTextEditingLayout
                                                .createParallelGroup()
                                                .add(
                                                    _lblTabWidth,
                                                    GroupLayout.PREFERRED_SIZE,
                                                    16,
                                                    GroupLayout.PREFERRED_SIZE)
                                                .add(
                                                    _spnTabWidth,
                                                    GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE))
                                        .add(40, 40, 40)
                                        .add(
                                            _paneTextEditingLayout
                                                .createParallelGroup(GroupLayout.BASELINE)
                                                .add(_lblFont)
                                                .add(
                                                    _cmbFontName,
                                                    GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE))
                                        .addPreferredGap(LayoutStyle.RELATED)
                                        .add(
                                            _paneTextEditingLayout
                                                .createParallelGroup(GroupLayout.TRAILING)
                                                .add(
                                                    _lblFontSize,
                                                    GroupLayout.PREFERRED_SIZE,
                                                    27,
                                                    GroupLayout.PREFERRED_SIZE)
                                                .add(
                                                    _spnFontSize,
                                                    GroupLayout.PREFERRED_SIZE,
                                                    GroupLayout.DEFAULT_SIZE,
                                                    GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(154, Short.MAX_VALUE)));
        _paneTextEditingLayout.linkSize(
            new Component[] {_lblTabWidth, _spnTabWidth}, GroupLayout.VERTICAL);
        _paneTextEditingLayout.linkSize(
            new Component[] {_cmbFontName, _lblFont}, GroupLayout.VERTICAL);
      }
      _tabPane.addTab(I18N._I("PreferencesWin.paneTextEditing.tab.title"), _paneTextEditing);

      // ======== paneGeneral ========
      {

        // ---- _lblUpdates ----
        _lblUpdates.setFont(
            _lblUpdates.getFont().deriveFont(_lblUpdates.getFont().getStyle() | Font.BOLD));

        // ---- _lblLanguage ----
        _lblLanguage.setFont(
            _lblLanguage.getFont().deriveFont(_lblLanguage.getFont().getStyle() | Font.BOLD));

        GroupLayout paneGeneralLayout = new GroupLayout(paneGeneral);
        paneGeneral.setLayout(paneGeneralLayout);
        paneGeneralLayout.setHorizontalGroup(
            paneGeneralLayout
                .createParallelGroup()
                .add(
                    paneGeneralLayout
                        .createSequentialGroup()
                        .add(137, 137, 137)
                        .add(
                            paneGeneralLayout
                                .createParallelGroup()
                                .add(
                                    paneGeneralLayout
                                        .createSequentialGroup()
                                        .add(_lblLanguage)
                                        .add(185, 185, 185))
                                .add(
                                    paneGeneralLayout
                                        .createSequentialGroup()
                                        .add(38, 38, 38)
                                        .add(
                                            _cmbLang,
                                            GroupLayout.PREFERRED_SIZE,
                                            215,
                                            GroupLayout.PREFERRED_SIZE))
                                .add(
                                    paneGeneralLayout
                                        .createSequentialGroup()
                                        .add(_lblUpdates)
                                        .add(318, 318, 318))
                                .add(
                                    GroupLayout.TRAILING,
                                    paneGeneralLayout
                                        .createSequentialGroup()
                                        .add(38, 38, 38)
                                        .add(
                                            _chkAutoUpdate,
                                            GroupLayout.DEFAULT_SIZE,
                                            376,
                                            Short.MAX_VALUE)))
                        .addContainerGap()));
        paneGeneralLayout.setVerticalGroup(
            paneGeneralLayout
                .createParallelGroup()
                .add(
                    paneGeneralLayout
                        .createSequentialGroup()
                        .add(26, 26, 26)
                        .add(_lblUpdates)
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(_chkAutoUpdate)
                        .add(40, 40, 40)
                        .add(_lblLanguage)
                        .addPreferredGap(LayoutStyle.RELATED)
                        .add(
                            _cmbLang,
                            GroupLayout.PREFERRED_SIZE,
                            GroupLayout.DEFAULT_SIZE,
                            GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(196, Short.MAX_VALUE)));
      }
      _tabPane.addTab(I18N._I("prefTabGeneralSettings"), paneGeneral);
    }
    contentPane.add(_tabPane, BorderLayout.CENTER);

    // ======== paneOkCancel ========
    {
      paneOkCancel.setBorder(new EmptyBorder(5, 5, 5, 5));
      paneOkCancel.setLayout(new BoxLayout(paneOkCancel, BoxLayout.X_AXIS));
      paneOkCancel.add(hSpacer1);

      // ---- _btnOk ----
      _btnOk.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              btnOkActionPerformed(e);
            }
          });
      paneOkCancel.add(_btnOk);

      // ---- _btnCancel ----
      _btnCancel.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              btnCancelActionPerformed(e);
            }
          });
      paneOkCancel.add(_btnCancel);

      // ---- _btnApply ----
      _btnApply.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              btnApplyActionPerformed(e);
            }
          });
      paneOkCancel.add(_btnApply);
    }
    contentPane.add(paneOkCancel, BorderLayout.SOUTH);
    setSize(600, 475);
    setLocationRelativeTo(getOwner());

    // ---- btngrpNaming ----
    ButtonGroup btngrpNaming = new ButtonGroup();
    btngrpNaming.add(_radTimestamp);
    btngrpNaming.add(_radOCR);
    btngrpNaming.add(_radOff);

    initComponentsI18n();
    // JFormDesigner - End of component initialization  //GEN-END:initComponents
  }

  private void initComponentsI18n() {
    // JFormDesigner - Component i18n initialization - DO NOT MODIFY  //GEN-BEGIN:initI18n
    DefaultComponentFactory.setTextAndMnemonic(
        _titleAppearance, I18N._I("PreferencesWin.titleAppearance.textWithMnemonic"));
    DefaultComponentFactory.setTextAndMnemonic(
        _titleIndentation, I18N._I("PreferencesWin.titleIndentation.textWithMnemonic"));
    _lblHotkey.setText(I18N._I("prefCaptureHotkey"));
    _lblDelay.setText(I18N._I("prefCaptureDelay"));
    _lblDelaySecs.setText(I18N._I("prefSeconds"));
    _lblNaming.setText(I18N._I("prefAutoNaming"));
    _radTimestamp.setText(I18N._I("prefTimestamp"));
    _radOCR.setText(I18N._I("prefRecognizedText"));
    _radOff.setText(I18N._I("prefManualInput"));
    _tabPane.setTitleAt(0, I18N._I("prefTabScreenCapturing"));
    _chkExpandTab.setText(I18N._I("PreferencesWin.chkExpandTab.text"));
    _lblTabWidth.setText(I18N._I("PreferencesWin.lblTabWidth.text"));
    _lblFont.setText(I18N._I("PreferencesWin.lblFont.text"));
    _lblFontSize.setText(I18N._I("PreferencesWin.lblFontSize.text"));
    _tabPane.setTitleAt(1, I18N._I("PreferencesWin.paneTextEditing.tab.title"));
    _chkAutoUpdate.setText(I18N._I("prefGeneralAutoCheck"));
    _lblUpdates.setText(I18N._I("PreferencesWin.lblUpdates.text"));
    _lblLanguage.setText(I18N._I("PreferencesWin.lblLanguage.text"));
    _tabPane.setTitleAt(2, I18N._I("prefTabGeneralSettings"));
    _btnOk.setText(I18N._I("ok"));
    _btnApply.setText(I18N._I("apply"));
    _btnCancel.setText(I18N._I("cancel"));
    // JFormDesigner - End of component i18n initialization  //GEN-END:initI18n
  }

  // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
  private JTabbedPane _tabPane;
  private JTextField _txtHotkey;
  private JLabel _lblHotkey;
  private JLabel _lblDelay;
  private JSpinner _spnDelay;
  private JLabel _lblDelaySecs;
  private JLabel _lblNaming;
  private JRadioButton _radTimestamp;
  private JRadioButton _radOCR;
  private JRadioButton _radOff;
  private JPanel _paneTextEditing;
  private JCheckBox _chkExpandTab;
  private JLabel _lblTabWidth;
  private JComboBox _cmbFontName;
  private JLabel _lblFont;
  private JLabel _titleAppearance;
  private JLabel _titleIndentation;
  private JSpinner _spnTabWidth;
  private JLabel _lblFontSize;
  private JSpinner _spnFontSize;
  private JCheckBox _chkAutoUpdate;
  private JComboBox _cmbLang;
  private JLabel _lblUpdates;
  private JLabel _lblLanguage;
  private JButton _btnOk;
  private JButton _btnApply;
  private JButton _btnCancel;
  // JFormDesigner - End of variables declaration  //GEN-END:variables
}
  MyCustomizableGUI() {

    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    textField = new JTextField(20);
    buttonPref = new JButton("Preferences");

    this.add(textField);
    this.add(buttonPref);

    buttonPref.addActionListener(evt -> prefDialog.setVisible(true));

    frame = new JFrame("My text editor");
    frame.setContentPane(this);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    // Preferences dialog box
    prefDialog = new JDialog(frame, "Dialog", true);
    prefDialog.setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 2));
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));

    buttonSave = new JButton("Save");
    buttonCancel = new JButton("Cancel");

    buttonSave.addActionListener(
        evtSave -> {
          String fontChosen;
          int fontSizeChosen;

          prefDialog.setVisible(false);

          if ((String) color.getSelectedItem() == "Red") {
            textField.setForeground(Color.red);
          } else if ((String) color.getSelectedItem() == "Green") {
            textField.setForeground(Color.green);
          } else if ((String) color.getSelectedItem() == "Blue") {
            textField.setForeground(Color.blue);
          } else if ((String) color.getSelectedItem() == "Cyan") {
            textField.setForeground(Color.cyan);
          } else if ((String) color.getSelectedItem() == "Magenta") {
            textField.setForeground(Color.magenta);
          } else if ((String) color.getSelectedItem() == "Yellow") {
            textField.setForeground(Color.yellow);
          } else if ((String) color.getSelectedItem() == "Black") {
            textField.setForeground(Color.black);
          }

          fontChosen = (String) font.getSelectedItem();
          fontSizeChosen = Integer.parseInt((String) fontSize.getSelectedItem());
          textField.setFont(new Font(fontChosen, Font.PLAIN, fontSizeChosen));

          UserPreferences userPrefs = new UserPreferences();
          userPrefs.setColor((String) color.getSelectedItem());
          userPrefs.setFont(fontChosen);
          userPrefs.setFontSize(fontSizeChosen);

          try (FileOutputStream fileOut = new FileOutputStream("preferences.ser");
              ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); ) {

            objectOut.writeObject(userPrefs);

          } catch (IOException ioe) {
            System.out.println("I/O error: " + ioe.getMessage());
          }
        });

    buttonCancel.addActionListener(evt -> prefDialog.setVisible(false));

    colorLabel = new JLabel("Color:");
    fontLabel = new JLabel("Font:");
    fontSizeLabel = new JLabel("Font size:");
    color = new JComboBox(colorList);
    font = new JComboBox(fontList);
    fontSize = new JComboBox(fontSizeList);

    p1.add(colorLabel);
    p1.add(color);
    p1.add(fontLabel);
    p1.add(font);
    p1.add(fontSizeLabel);
    p1.add(fontSize);
    p2.add(buttonCancel);
    p2.add(buttonSave);

    prefDialog.add(BorderLayout.NORTH, p1);
    prefDialog.add(BorderLayout.SOUTH, p2);

    prefDialog.pack();
  }
  public static void main(String[] args) {

    MyCustomizableGUI custGUI = new MyCustomizableGUI();
    UserPreferences savedPrefs;

    try (FileInputStream fileIn = new FileInputStream("preferences.ser");
        ObjectInputStream objectIn = new ObjectInputStream(fileIn); ) {

      savedPrefs = (UserPreferences) objectIn.readObject();

      if (savedPrefs.getColor().contains("Red")) {
        custGUI.textField.setForeground(Color.red);
        custGUI.color.setSelectedItem("Red");
      } else if (savedPrefs.getColor().contains("Green")) {
        custGUI.textField.setForeground(Color.green);
        custGUI.color.setSelectedItem("Green");
      } else if (savedPrefs.getColor().contains("Blue")) {
        custGUI.textField.setForeground(Color.blue);
        custGUI.color.setSelectedItem("Blue");
      } else if (savedPrefs.getColor().contains("Cyan")) {
        custGUI.textField.setForeground(Color.cyan);
        custGUI.color.setSelectedItem("Cyan");
      } else if (savedPrefs.getColor().contains("Magenta")) {
        custGUI.textField.setForeground(Color.magenta);
        custGUI.color.setSelectedItem("Magenta");
      } else if (savedPrefs.getColor().contains("Yellow")) {
        custGUI.textField.setForeground(Color.yellow);
        custGUI.color.setSelectedItem("Yellow");
      } else if (savedPrefs.getColor().contains("Black")) {
        custGUI.textField.setForeground(Color.black);
        custGUI.color.setSelectedItem("Black");
      }

      custGUI.setFont(savedPrefs.getFont(), savedPrefs.getFontSize());
      custGUI.font.setSelectedItem(savedPrefs.getFont());
      custGUI.fontSize.setSelectedItem("" + savedPrefs.getFontSize());

    } catch (FileNotFoundException noFile) {
      // load default font and color
      custGUI.setFont("Arial", 25);
      custGUI.textField.setForeground(Color.black);

    } catch (ClassNotFoundException noPrefs) {
      noPrefs.printStackTrace();
    } catch (IOException e) {
      System.out.println("I/O Error: " + e.getMessage());
    }
  }