Example usage for javax.swing JTabbedPane getInputMap

List of usage examples for javax.swing JTabbedPane getInputMap

Introduction

In this page you can find the example usage for javax.swing JTabbedPane getInputMap.

Prototype

public final InputMap getInputMap(int condition) 

Source Link

Document

Returns the InputMap that is used during condition.

Usage

From source file:davmail.ui.SettingsFrame.java

/**
 * DavMail settings frame.//from ww w .  j ava2 s .  com
 */
public SettingsFrame() {
    setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    setTitle(BundleMessage.format("UI_DAVMAIL_SETTINGS"));
    try {
        setIconImage(DavGatewayTray.getFrameIcon());
    } catch (NoSuchMethodError error) {
        DavGatewayTray.debug(new BundleMessage("LOG_UNABLE_TO_SET_ICON_IMAGE"));
    }

    JTabbedPane tabbedPane = new JTabbedPane();
    // add help (F1 handler)
    tabbedPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F1"),
            "help");
    tabbedPane.getActionMap().put("help", new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            DesktopBrowser.browse("http://davmail.sourceforge.net");
        }
    });
    tabbedPane.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            boolean isSslEnabled = isSslEnabled();
            popNoSSLCheckBox.setEnabled(Settings.getProperty("davmail.popPort") != null && isSslEnabled);
            imapNoSSLCheckBox.setEnabled(imapPortCheckBox.isSelected() && isSslEnabled);
            smtpNoSSLCheckBox.setEnabled(smtpPortCheckBox.isSelected() && isSslEnabled);
            caldavNoSSLCheckBox.setEnabled(caldavPortCheckBox.isSelected() && isSslEnabled);
            ldapNoSSLCheckBox.setEnabled(ldapPortCheckBox.isSelected() && isSslEnabled);
        }
    });

    JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
    mainPanel.add(getSettingsPanel());
    mainPanel.add(getDelaysPanel());
    mainPanel.add(Box.createVerticalGlue());

    tabbedPane.add(BundleMessage.format("UI_TAB_MAIN"), mainPanel);

    JPanel proxyPanel = new JPanel();
    proxyPanel.setLayout(new BoxLayout(proxyPanel, BoxLayout.Y_AXIS));
    proxyPanel.add(getProxyPanel());
    proxyPanel.add(getNetworkSettingsPanel());
    tabbedPane.add(BundleMessage.format("UI_TAB_NETWORK"), proxyPanel);

    JPanel encryptionPanel = new JPanel();
    encryptionPanel.setLayout(new BoxLayout(encryptionPanel, BoxLayout.Y_AXIS));
    encryptionPanel.add(getKeystorePanel());
    encryptionPanel.add(getSmartCardPanel());
    // empty panel
    encryptionPanel.add(new JPanel());
    tabbedPane.add(BundleMessage.format("UI_TAB_ENCRYPTION"), encryptionPanel);

    JPanel loggingPanel = new JPanel();
    loggingPanel.setLayout(new BoxLayout(loggingPanel, BoxLayout.Y_AXIS));
    loggingPanel.add(getLoggingSettingsPanel());
    // empty panel
    loggingPanel.add(new JPanel());

    tabbedPane.add(BundleMessage.format("UI_TAB_LOGGING"), loggingPanel);

    JPanel advancedPanel = new JPanel();
    advancedPanel.setLayout(new BoxLayout(advancedPanel, BoxLayout.Y_AXIS));

    advancedPanel.add(getOtherSettingsPanel());
    // empty panel
    advancedPanel.add(new JPanel());

    tabbedPane.add(BundleMessage.format("UI_TAB_ADVANCED"), advancedPanel);

    if (OSXInfoPlist.isOSX()) {
        JPanel osxPanel = new JPanel();
        osxPanel.setLayout(new BoxLayout(osxPanel, BoxLayout.Y_AXIS));
        osxPanel.add(getOSXPanel());
        // empty panel
        osxPanel.add(new JPanel());

        tabbedPane.add(BundleMessage.format("UI_TAB_OSX"), osxPanel);
    }

    add(BorderLayout.CENTER, tabbedPane);

    JPanel buttonPanel = new JPanel();
    JButton cancel = new JButton(BundleMessage.format("UI_BUTTON_CANCEL"));
    JButton ok = new JButton(BundleMessage.format("UI_BUTTON_SAVE"));
    JButton help = new JButton(BundleMessage.format("UI_BUTTON_HELP"));
    ActionListener save = new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            // save options
            Settings.setProperty("davmail.url", urlField.getText());
            Settings.setProperty("davmail.popPort", popPortCheckBox.isSelected() ? popPortField.getText() : "");
            Settings.setProperty("davmail.ssl.nosecurepop", String.valueOf(popNoSSLCheckBox.isSelected()));
            Settings.setProperty("davmail.imapPort",
                    imapPortCheckBox.isSelected() ? imapPortField.getText() : "");
            Settings.setProperty("davmail.ssl.nosecureimap", String.valueOf(imapNoSSLCheckBox.isSelected()));
            Settings.setProperty("davmail.smtpPort",
                    smtpPortCheckBox.isSelected() ? smtpPortField.getText() : "");
            Settings.setProperty("davmail.ssl.nosecuresmtp", String.valueOf(smtpNoSSLCheckBox.isSelected()));
            Settings.setProperty("davmail.caldavPort",
                    caldavPortCheckBox.isSelected() ? caldavPortField.getText() : "");
            Settings.setProperty("davmail.ssl.nosecurecaldav",
                    String.valueOf(caldavNoSSLCheckBox.isSelected()));
            Settings.setProperty("davmail.ldapPort",
                    ldapPortCheckBox.isSelected() ? ldapPortField.getText() : "");
            Settings.setProperty("davmail.ssl.nosecureldap", String.valueOf(ldapNoSSLCheckBox.isSelected()));
            Settings.setProperty("davmail.keepDelay", keepDelayField.getText());
            Settings.setProperty("davmail.sentKeepDelay", sentKeepDelayField.getText());
            Settings.setProperty("davmail.caldavPastDelay", caldavPastDelayField.getText());
            Settings.setProperty("davmail.imapIdleDelay", imapIdleDelayField.getText());
            Settings.setProperty("davmail.useSystemProxies",
                    String.valueOf(useSystemProxiesField.isSelected()));
            Settings.setProperty("davmail.enableProxy", String.valueOf(enableProxyField.isSelected()));
            Settings.setProperty("davmail.proxyHost", httpProxyField.getText());
            Settings.setProperty("davmail.proxyPort", httpProxyPortField.getText());
            Settings.setProperty("davmail.proxyUser", httpProxyUserField.getText());
            Settings.setProperty("davmail.proxyPassword", httpProxyPasswordField.getText());
            Settings.setProperty("davmail.noProxyFor", noProxyForField.getText());

            Settings.setProperty("davmail.bindAddress", bindAddressField.getText());
            Settings.setProperty("davmail.clientSoTimeout", String.valueOf(clientSoTimeoutField.getText()));
            Settings.setProperty("davmail.allowRemote", String.valueOf(allowRemoteField.isSelected()));
            Settings.setProperty("davmail.server.certificate.hash", certHashField.getText());
            Settings.setProperty("davmail.disableUpdateCheck", String.valueOf(disableUpdateCheck.isSelected()));

            Settings.setProperty("davmail.caldavEditNotifications",
                    String.valueOf(caldavEditNotificationsField.isSelected()));
            Settings.setProperty("davmail.caldavAlarmSound", String.valueOf(caldavAlarmSoundField.getText()));
            Settings.setProperty("davmail.forceActiveSyncUpdate",
                    String.valueOf(forceActiveSyncUpdateCheckBox.isSelected()));
            Settings.setProperty("davmail.defaultDomain", String.valueOf(defaultDomainField.getText()));
            Settings.setProperty("davmail.showStartupBanner",
                    String.valueOf(showStartupBannerCheckBox.isSelected()));
            Settings.setProperty("davmail.disableGuiNotifications",
                    String.valueOf(disableGuiNotificationsCheckBox.isSelected()));
            Settings.setProperty("davmail.imapAutoExpunge",
                    String.valueOf(imapAutoExpungeCheckBox.isSelected()));
            Settings.setProperty("davmail.popMarkReadOnRetr",
                    String.valueOf(popMarkReadOnRetrCheckBox.isSelected()));
            String selectedEwsMode = (String) enableEwsComboBox.getSelectedItem();
            String enableEws;
            if (EWS.equals(selectedEwsMode)) {
                enableEws = "true";
            } else if (WEBDAV.equals(selectedEwsMode)) {
                enableEws = "false";
            } else {
                enableEws = "auto";
            }
            Settings.setProperty("davmail.enableEws", enableEws);
            Settings.setProperty("davmail.smtpSaveInSent", String.valueOf(smtpSaveInSentCheckBox.isSelected()));

            Settings.setProperty("davmail.ssl.keystoreType", (String) keystoreTypeCombo.getSelectedItem());
            Settings.setProperty("davmail.ssl.keystoreFile", keystoreFileField.getText());
            Settings.setProperty("davmail.ssl.keystorePass", String.valueOf(keystorePassField.getPassword()));
            Settings.setProperty("davmail.ssl.keyPass", String.valueOf(keyPassField.getPassword()));

            Settings.setProperty("davmail.ssl.clientKeystoreType",
                    (String) clientKeystoreTypeCombo.getSelectedItem());
            Settings.setProperty("davmail.ssl.clientKeystoreFile", clientKeystoreFileField.getText());
            Settings.setProperty("davmail.ssl.clientKeystorePass",
                    String.valueOf(clientKeystorePassField.getPassword()));
            Settings.setProperty("davmail.ssl.pkcs11Library", pkcs11LibraryField.getText());
            Settings.setProperty("davmail.ssl.pkcs11Config", pkcs11ConfigField.getText());

            Settings.setLoggingLevel("rootLogger", (Level) rootLoggingLevelField.getSelectedItem());
            Settings.setLoggingLevel("davmail", (Level) davmailLoggingLevelField.getSelectedItem());
            Settings.setLoggingLevel("org.apache.commons.httpclient",
                    (Level) httpclientLoggingLevelField.getSelectedItem());
            Settings.setLoggingLevel("httpclient.wire", (Level) wireLoggingLevelField.getSelectedItem());
            Settings.setProperty("davmail.logFilePath", logFilePathField.getText());
            Settings.setProperty("davmail.logFileSize", logFileSizeField.getText());

            setVisible(false);
            Settings.save();

            if (osxHideFromDockCheckBox != null) {
                OSXInfoPlist.setOSXHideFromDock(osxHideFromDockCheckBox.isSelected());
            }

            // restart listeners with new config
            DavGateway.restart();
        }
    };
    ok.addActionListener(save);

    cancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            reload();
            setVisible(false);
        }
    });

    help.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DesktopBrowser.browse("http://davmail.sourceforge.net");
        }
    });

    buttonPanel.add(ok);
    buttonPanel.add(cancel);
    buttonPanel.add(help);

    add(BorderLayout.SOUTH, buttonPanel);

    pack();
    //setResizable(false);
    // center frame
    setLocation(getToolkit().getScreenSize().width / 2 - getSize().width / 2,
            getToolkit().getScreenSize().height / 2 - getSize().height / 2);
    urlField.requestFocus();
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

public void setTabsPane(final JTabbedPane tabsPane) {
    this.tabsPane = tabsPane;

    // todo move to config
    tabsPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("control W"),
            "closeTab");
    tabsPane.getActionMap().put("closeTab", new ValidationAwareAction() {
        @Override//from  w w  w  . j ava2s  .co m
        public void actionPerformedAfterValidation(ActionEvent e) {
            closeTab((JComponent) tabsPane.getSelectedComponent());
        }
    });
}