Search in sources :

Example 6 with MTConfigDialog

use of org.omegat.gui.exttrans.MTConfigDialog in project omegat by omegat-org.

the class MicrosoftTranslatorAzure method showConfigurationUI.

@Override
public void showConfigurationUI(Window parent) {
    JCheckBox neuralCheckBox = new JCheckBox(OStrings.getString("MT_ENGINE_MICROSOFT_NEURAL_LABEL"));
    neuralCheckBox.setSelected(isNeural());
    MTConfigDialog dialog = new MTConfigDialog(parent, getName()) {

        @Override
        protected void onConfirm() {
            String key = panel.valueField1.getText().trim();
            boolean temporary = panel.temporaryCheckBox.isSelected();
            setCredential(PROPERTY_SUBSCRIPTION_KEY, key, temporary);
            System.setProperty(PROPERTY_NEURAL, Boolean.toString(neuralCheckBox.isSelected()));
            Preferences.setPreference(PROPERTY_NEURAL, neuralCheckBox.isSelected());
        }
    };
    dialog.panel.valueLabel1.setText(OStrings.getString("MT_ENGINE_MICROSOFT_SUBSCRIPTION_KEY_LABEL"));
    dialog.panel.valueField1.setText(getCredential(PROPERTY_SUBSCRIPTION_KEY));
    dialog.panel.valueLabel2.setVisible(false);
    dialog.panel.valueField2.setVisible(false);
    dialog.panel.temporaryCheckBox.setSelected(isCredentialStoredTemporarily(PROPERTY_SUBSCRIPTION_KEY));
    dialog.panel.itemsPanel.add(neuralCheckBox);
    dialog.show();
}
Also used : JCheckBox(javax.swing.JCheckBox) MTConfigDialog(org.omegat.gui.exttrans.MTConfigDialog)

Example 7 with MTConfigDialog

use of org.omegat.gui.exttrans.MTConfigDialog in project omegat by omegat-org.

the class MosesTranslate method showConfigurationUI.

@Override
public void showConfigurationUI(Window parent) {
    MTConfigDialog dialog = new MTConfigDialog(parent, getName()) {

        @Override
        protected void onConfirm() {
            String url = panel.valueField1.getText().trim();
            System.setProperty(PROPERTY_MOSES_URL, url);
            Preferences.setPreference(PROPERTY_MOSES_URL, url);
        }
    };
    JLabel messageLabel = new JLabel();
    JButton testButton = new JButton(OStrings.getString("MT_ENGINE_MOSES_TEST_BUTTON"));
    testButton.addActionListener(e -> {
        messageLabel.setText(OStrings.getString("MT_ENGINE_MOSES_TEST_TESTING"));
        String url = dialog.panel.valueField1.getText().trim();
        new SwingWorker<String, Void>() {

            @Override
            protected String doInBackground() throws Exception {
                XmlRpcClient client = getClient(new URL(url));
                Object response = client.execute("system.listMethods", (Object[]) null);
                if (Arrays.asList(((Object[]) response)).contains("translate")) {
                    return OStrings.getString("MT_ENGINE_MOSES_TEST_RESULT_OK");
                } else {
                    return OStrings.getString("MT_ENGINE_MOSES_TEST_RESULT_NO_TRANSLATE");
                }
            }

            @Override
            protected void done() {
                String message = null;
                try {
                    message = get();
                } catch (ExecutionException e) {
                    message = e.getCause().getLocalizedMessage();
                    Logger.getLogger(getClass().getName()).log(Level.SEVERE, message, e);
                } catch (Exception e) {
                    message = e.getLocalizedMessage();
                    Logger.getLogger(getClass().getName()).log(Level.SEVERE, message, e);
                }
                messageLabel.setText(message);
            }
        }.execute();
    });
    JPanel testPanel = new JPanel();
    testPanel.setLayout(new BoxLayout(testPanel, BoxLayout.LINE_AXIS));
    testPanel.add(testButton);
    testPanel.add(messageLabel);
    testPanel.setAlignmentX(0);
    dialog.panel.itemsPanel.add(testPanel);
    dialog.panel.valueLabel1.setText(OStrings.getString("MT_ENGINE_MOSES_URL_LABEL"));
    dialog.panel.valueField1.setText(getServerUrl());
    dialog.panel.valueField1.setColumns(20);
    dialog.panel.valueLabel2.setVisible(false);
    dialog.panel.valueField2.setVisible(false);
    dialog.panel.temporaryCheckBox.setVisible(false);
    dialog.show();
}
Also used : JPanel(javax.swing.JPanel) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) XmlRpcException(org.apache.xmlrpc.XmlRpcException) ExecutionException(java.util.concurrent.ExecutionException) URL(java.net.URL) MTConfigDialog(org.omegat.gui.exttrans.MTConfigDialog) ExecutionException(java.util.concurrent.ExecutionException)

Example 8 with MTConfigDialog

use of org.omegat.gui.exttrans.MTConfigDialog in project omegat by omegat-org.

the class DeepLTranslate method showConfigurationUI.

@Override
public void showConfigurationUI(Window parent) {
    MTConfigDialog dialog = new MTConfigDialog(parent, getName()) {

        @Override
        protected void onConfirm() {
            String key = panel.valueField1.getText().trim();
            boolean temporary = panel.temporaryCheckBox.isSelected();
            setCredential(PROPERTY_API_KEY, key, temporary);
        }
    };
    dialog.panel.valueLabel1.setText(OStrings.getString("MT_ENGINE_DEEPL_API_KEY_LABEL"));
    dialog.panel.valueField1.setText(getCredential(PROPERTY_API_KEY));
    dialog.panel.valueLabel2.setVisible(false);
    dialog.panel.valueField2.setVisible(false);
    dialog.panel.temporaryCheckBox.setSelected(isCredentialStoredTemporarily(PROPERTY_API_KEY));
    dialog.show();
}
Also used : MTConfigDialog(org.omegat.gui.exttrans.MTConfigDialog)

Example 9 with MTConfigDialog

use of org.omegat.gui.exttrans.MTConfigDialog in project omegat by omegat-org.

the class YandexTranslate method showConfigurationUI.

@Override
public void showConfigurationUI(Window parent) {
    MTConfigDialog dialog = new MTConfigDialog(parent, getName()) {

        @Override
        protected void onConfirm() {
            String key = panel.valueField1.getText().trim();
            boolean temporary = panel.temporaryCheckBox.isSelected();
            setCredential(PROPERTY_API_KEY, key, temporary);
        }
    };
    dialog.panel.valueLabel1.setText(OStrings.getString("MT_ENGINE_YANDEX_API_KEY_LABEL"));
    dialog.panel.valueField1.setText(getCredential(PROPERTY_API_KEY));
    dialog.panel.valueLabel2.setVisible(false);
    dialog.panel.valueField2.setVisible(false);
    dialog.panel.temporaryCheckBox.setSelected(isCredentialStoredTemporarily(PROPERTY_API_KEY));
    dialog.show();
}
Also used : MTConfigDialog(org.omegat.gui.exttrans.MTConfigDialog)

Aggregations

MTConfigDialog (org.omegat.gui.exttrans.MTConfigDialog)9 JCheckBox (javax.swing.JCheckBox)4 JPanel (javax.swing.JPanel)3 BoxLayout (javax.swing.BoxLayout)2 JLabel (javax.swing.JLabel)2 GridBagConstraints (java.awt.GridBagConstraints)1 ItemEvent (java.awt.event.ItemEvent)1 ItemListener (java.awt.event.ItemListener)1 URL (java.net.URL)1 ExecutionException (java.util.concurrent.ExecutionException)1 JButton (javax.swing.JButton)1 JTextField (javax.swing.JTextField)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DocumentListener (javax.swing.event.DocumentListener)1 XmlRpcException (org.apache.xmlrpc.XmlRpcException)1 XmlRpcClient (org.apache.xmlrpc.client.XmlRpcClient)1