Search in sources :

Example 1 with KeyedComboBoxModel

use of net.pms.util.KeyedComboBoxModel in project UniversalMediaServer by UniversalMediaServer.

the class GeneralTab method build.

public JComponent build() {
    // count the lines easier to add new ones
    int ypos = 1;
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation);
    FormLayout layout = new FormLayout(colSpec, ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DLU4);
    builder.opaque(true);
    CellConstraints cc = new CellConstraints();
    smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3"), configuration.isMinimized());
    smcheckBox.setContentAreaFilled(false);
    smcheckBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMinimized((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(1, ypos, 9), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
    // we hardcode here (promise last time)
    ypos = 7;
    builder.addLabel(Messages.getString("GeneralTab.14"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
    JPanel languagePanel = new JPanel();
    languagePanel.setLayout(new BoxLayout(languagePanel, BoxLayout.LINE_AXIS));
    currentLanguage.setEnabled(false);
    currentLanguage.setText(Messages.getString("Language." + configuration.getLanguageTag()));
    languagePanel.add(currentLanguage);
    CustomJButton selectLanguage = new CustomJButton("    ...    ");
    selectLanguage.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            LanguageSelection selectionDialog = new LanguageSelection(looksFrame, configuration.getLanguageLocale(), true);
            if (selectionDialog != null) {
                selectionDialog.show();
                if (!selectionDialog.isAborted()) {
                    currentLanguage.setText(Messages.getString("Language." + configuration.getLanguageTag()));
                }
            }
        }
    });
    languagePanel.add(selectLanguage);
    builder.add(languagePanel, FormLayoutUtil.flip(cc.xyw(3, ypos, 3), colSpec, orientation));
    ypos += 2;
    if (!configuration.isHideAdvancedOptions()) {
        serverName = new JTextField(configuration.getServerName());
        serverName.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                configuration.setServerName(serverName.getText());
            }
        });
        builder.addLabel(Messages.getString("NetworkTab.71"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        builder.add(serverName, FormLayoutUtil.flip(cc.xyw(3, ypos, 3), colSpec, orientation));
        appendProfileName = new JCheckBox(Messages.getString("NetworkTab.72"), configuration.isAppendProfileName());
        appendProfileName.setToolTipText(Messages.getString("NetworkTab.73"));
        appendProfileName.setContentAreaFilled(false);
        appendProfileName.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                configuration.setAppendProfileName((e.getStateChange() == ItemEvent.SELECTED));
            }
        });
        builder.add(GuiUtil.getPreferredSizeComponent(appendProfileName), FormLayoutUtil.flip(cc.xy(7, ypos), colSpec, orientation));
        ypos += 2;
    }
    builder.add(smcheckBox, FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
    if (Platform.isWindows()) {
        autoStart = new JCheckBox(Messages.getString("NetworkTab.57"), configuration.isAutoStart());
        autoStart.setContentAreaFilled(false);
        autoStart.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                configuration.setAutoStart((e.getStateChange() == ItemEvent.SELECTED));
            }
        });
        builder.add(GuiUtil.getPreferredSizeComponent(autoStart), FormLayoutUtil.flip(cc.xy(3, ypos), colSpec, orientation));
    }
    showSplashScreen = new JCheckBox(Messages.getString("NetworkTab.74"), configuration.isShowSplashScreen());
    showSplashScreen.setContentAreaFilled(false);
    showSplashScreen.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowSplashScreen((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(showSplashScreen), FormLayoutUtil.flip(cc.xy(5, ypos), colSpec, orientation));
    ypos += 2;
    if (!configuration.isHideAdvancedOptions()) {
        installService = new CustomJButton();
        refreshInstallServiceButtonState();
        builder.add(installService, FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        ypos += 2;
    }
    CustomJButton checkForUpdates = new CustomJButton(Messages.getString("NetworkTab.8"));
    checkForUpdates.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            looksFrame.checkForUpdates(false);
        }
    });
    builder.add(checkForUpdates, FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
    autoUpdateCheckBox = new JCheckBox(Messages.getString("NetworkTab.9"), configuration.isAutoUpdate());
    autoUpdateCheckBox.setContentAreaFilled(false);
    autoUpdateCheckBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAutoUpdate((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(autoUpdateCheckBox), FormLayoutUtil.flip(cc.xyw(3, ypos, 7), colSpec, orientation));
    ypos += 2;
    if (!Build.isUpdatable()) {
        checkForUpdates.setEnabled(false);
        autoUpdateCheckBox.setEnabled(false);
    }
    hideAdvancedOptions = new JCheckBox(Messages.getString("NetworkTab.61"), configuration.isHideAdvancedOptions());
    hideAdvancedOptions.setContentAreaFilled(false);
    hideAdvancedOptions.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setHideAdvancedOptions(hideAdvancedOptions.isSelected());
            if (hideAdvancedOptions.isSelected()) {
                looksFrame.setViewLevel(ViewLevel.NORMAL);
            } else {
                looksFrame.setViewLevel(ViewLevel.ADVANCED);
            }
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(hideAdvancedOptions), FormLayoutUtil.flip(cc.xyw(1, ypos, 9), colSpec, orientation));
    ypos += 2;
    runWizardOnProgramStartup = new JCheckBox(Messages.getString("GeneralTab.9"), configuration.isRunWizard());
    runWizardOnProgramStartup.setContentAreaFilled(false);
    runWizardOnProgramStartup.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setRunWizard(runWizardOnProgramStartup.isSelected());
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(runWizardOnProgramStartup), FormLayoutUtil.flip(cc.xyw(1, ypos, 9), colSpec, orientation));
    ypos += 2;
    if (!configuration.isHideAdvancedOptions()) {
        singleInstance = new JCheckBox(Messages.getString("GeneralTab.10"), configuration.isRunSingleInstance());
        singleInstance.setContentAreaFilled(false);
        singleInstance.setToolTipText(Messages.getString("GeneralTab.11"));
        singleInstance.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                configuration.setRunSingleInstance(singleInstance.isSelected());
            }
        });
        builder.add(GuiUtil.getPreferredSizeComponent(singleInstance), FormLayoutUtil.flip(cc.xyw(1, ypos, 9), colSpec, orientation));
        ypos += 2;
    }
    ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getEnabledRenderersConfigurations();
    ArrayList<Object> keyValues = new ArrayList<>();
    ArrayList<Object> nameValues = new ArrayList<>();
    keyValues.add("");
    nameValues.add(Messages.getString("NetworkTab.37"));
    if (allConfs != null) {
        sortRendererConfigurationsByName(allConfs);
        for (RendererConfiguration renderer : allConfs) {
            if (renderer != null) {
                keyValues.add(renderer.getRendererName());
                nameValues.add(renderer.getRendererName());
            }
        }
    }
    final KeyedComboBoxModel<String, String> renderersKcbm = new KeyedComboBoxModel<>(keyValues.toArray(new String[keyValues.size()]), nameValues.toArray(new String[nameValues.size()]));
    renderers = new JComboBox<>(renderersKcbm);
    renderers.setEditable(false);
    String defaultRenderer = configuration.getRendererDefault();
    renderersKcbm.setSelectedKey(defaultRenderer);
    if (renderers.getSelectedIndex() == -1) {
        renderers.setSelectedIndex(0);
    }
    if (!configuration.isHideAdvancedOptions()) {
        // Edit UMS configuration file manually
        CustomJButton confEdit = new CustomJButton(Messages.getString("NetworkTab.51"));
        confEdit.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                JPanel tPanel = new JPanel(new BorderLayout());
                final File conf = new File(configuration.getProfilePath());
                final JTextArea textArea = new JTextArea();
                textArea.setFont(new Font("Courier", Font.PLAIN, 12));
                JScrollPane scrollPane = new JScrollPane(textArea);
                scrollPane.setPreferredSize(new Dimension(900, 450));
                try {
                    try (FileInputStream fis = new FileInputStream(conf);
                        BufferedReader in = new BufferedReader(new InputStreamReader(fis))) {
                        String line;
                        StringBuilder sb = new StringBuilder();
                        while ((line = in.readLine()) != null) {
                            sb.append(line);
                            sb.append("\n");
                        }
                        textArea.setText(sb.toString());
                    }
                } catch (IOException e1) {
                    return;
                }
                tPanel.add(scrollPane, BorderLayout.NORTH);
                Object[] options = { Messages.getString("LooksFrame.9"), Messages.getString("NetworkTab.45") };
                if (JOptionPane.showOptionDialog(looksFrame, tPanel, Messages.getString("NetworkTab.51"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, null) == JOptionPane.OK_OPTION) {
                    String text = textArea.getText();
                    try {
                        try (FileOutputStream fos = new FileOutputStream(conf)) {
                            fos.write(text.getBytes());
                            fos.flush();
                        }
                        configuration.reload();
                    } catch (Exception e1) {
                        JOptionPane.showMessageDialog(looksFrame, Messages.getString("NetworkTab.52") + e1.toString());
                    }
                }
            }
        });
        builder.add(confEdit, FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        ypos += 2;
        host = new JTextField(configuration.getServerHostname());
        host.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                configuration.setHostname(host.getText());
            }
        });
        port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : "");
        port.setToolTipText(Messages.getString("NetworkTab.64"));
        port.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                try {
                    String p = port.getText();
                    if (StringUtils.isEmpty(p)) {
                        p = "5001";
                    }
                    int ab = Integer.parseInt(p);
                    configuration.setServerPort(ab);
                } catch (NumberFormatException nfe) {
                    LOGGER.debug("Could not parse port from \"" + port.getText() + "\"");
                }
            }
        });
        cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), FormLayoutUtil.flip(cc.xyw(1, ypos, 9), colSpec, orientation));
        ypos += 2;
        cmp = (JComponent) cmp.getComponent(0);
        cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
        final KeyedComboBoxModel<String, String> networkInterfaces = createNetworkInterfacesModel();
        networkinterfacesCBX = new JComboBox<>(networkInterfaces);
        networkInterfaces.setSelectedKey(configuration.getNetworkInterface());
        networkinterfacesCBX.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (e.getStateChange() == ItemEvent.SELECTED) {
                    configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey());
                }
            }
        });
        ip_filter = new JTextField(configuration.getIpFilter());
        ip_filter.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                configuration.setIpFilter(ip_filter.getText());
            }
        });
        maxbitrate = new JTextField(configuration.getMaximumBitrateDisplay());
        maxbitrate.setToolTipText(Messages.getString("NetworkTab.65"));
        maxbitrate.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent e) {
                configuration.setMaximumBitrate(maxbitrate.getText());
            }
        });
        if (configuration.isAutomaticMaximumBitrate()) {
            maxbitrate.setEnabled(false);
        } else {
            maxbitrate.setEnabled(true);
        }
        adaptBitrate = new JCheckBox(Messages.getString("GeneralTab.12"), configuration.isAutomaticMaximumBitrate());
        adaptBitrate.setContentAreaFilled(false);
        adaptBitrate.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                configuration.setAutomaticMaximumBitrate(adaptBitrate.isSelected());
                maxbitrate.setEnabled(!configuration.isAutomaticMaximumBitrate());
            }
        });
        builder.addLabel(Messages.getString("NetworkTab.20"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        builder.add(networkinterfacesCBX, FormLayoutUtil.flip(cc.xyw(3, ypos, 7), colSpec, orientation));
        ypos += 2;
        builder.addLabel(Messages.getString("NetworkTab.23"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        builder.add(host, FormLayoutUtil.flip(cc.xyw(3, ypos, 7), colSpec, orientation));
        ypos += 2;
        builder.addLabel(Messages.getString("NetworkTab.24"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        builder.add(port, FormLayoutUtil.flip(cc.xyw(3, ypos, 7), colSpec, orientation));
        ypos += 2;
        builder.addLabel(Messages.getString("NetworkTab.30"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        builder.add(ip_filter, FormLayoutUtil.flip(cc.xyw(3, ypos, 7), colSpec, orientation));
        ypos += 2;
        builder.addLabel(Messages.getString("NetworkTab.35"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        builder.add(maxbitrate, FormLayoutUtil.flip(cc.xyw(3, ypos, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(adaptBitrate), FormLayoutUtil.flip(cc.xy(7, ypos), colSpec, orientation));
        ypos += 2;
        cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), FormLayoutUtil.flip(cc.xyw(1, ypos, 9), colSpec, orientation));
        ypos += 2;
        cmp = (JComponent) cmp.getComponent(0);
        cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
        boolean preventSleepSupported = SleepManager.isPreventSleepSupported();
        if (preventSleepSupported) {
            builder.addLabel(Messages.getString("NetworkTab.PreventSleepLabel"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
            final KeyedComboBoxModel<PreventSleepMode, String> preventSleepModel = createPreventSleepModel();
            preventSleep = new JComboBox<>(preventSleepModel);
            preventSleep.setToolTipText(Messages.getString("NetworkTab.PreventSleepToolTip"));
            preventSleepModel.setSelectedKey(configuration.getPreventSleep());
            preventSleep.addItemListener(new ItemListener() {

                @Override
                public void itemStateChanged(ItemEvent e) {
                    if (e.getStateChange() == ItemEvent.SELECTED) {
                        configuration.setPreventSleep(preventSleepModel.getSelectedKey());
                    }
                }
            });
            builder.add(preventSleep, FormLayoutUtil.flip(cc.xy(3, ypos), colSpec, orientation));
        }
        newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32"), configuration.isHTTPEngineV2());
        newHTTPEngine.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                configuration.setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED));
            }
        });
        builder.add(newHTTPEngine, FormLayoutUtil.flip(cc.xy(preventSleepSupported ? 7 : 1, ypos), colSpec, orientation));
        ypos += 2;
        final SelectRenderers selectRenderers = new SelectRenderers();
        builder.addLabel(Messages.getString("NetworkTab.62"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        final CustomJButton setRenderers = new CustomJButton(Messages.getString("GeneralTab.5"));
        setRenderers.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                selectRenderers.showDialog();
            }
        });
        builder.add(setRenderers, FormLayoutUtil.flip(cc.xy(3, ypos), colSpec, orientation));
        ypos += 2;
        builder.addLabel(Messages.getString("NetworkTab.36"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        builder.add(renderers, FormLayoutUtil.flip(cc.xyw(3, ypos, 3), colSpec, orientation));
        fdCheckBox = new JCheckBox(Messages.getString("NetworkTab.38"), configuration.isRendererForceDefault());
        fdCheckBox.setContentAreaFilled(false);
        fdCheckBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                configuration.setRendererForceDefault((e.getStateChange() == ItemEvent.SELECTED));
            }
        });
        builder.add(fdCheckBox, FormLayoutUtil.flip(cc.xy(7, ypos), colSpec, orientation));
        ypos += 2;
        // External network box
        extNetBox = new JCheckBox(Messages.getString("NetworkTab.56"), configuration.getExternalNetwork());
        extNetBox.setToolTipText(Messages.getString("NetworkTab.67"));
        extNetBox.setContentAreaFilled(false);
        extNetBox.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                configuration.setExternalNetwork((e.getStateChange() == ItemEvent.SELECTED));
            }
        });
        builder.add(extNetBox, FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
        ypos += 2;
    }
    JPanel panel = builder.getPanel();
    // Apply the orientation to the panel and all components in it
    panel.applyComponentOrientation(orientation);
    JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    return scrollPane;
}
Also used : CellConstraints(com.jgoodies.forms.layout.CellConstraints) FormLayout(com.jgoodies.forms.layout.FormLayout) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) CustomJButton(net.pms.newgui.components.CustomJButton) KeyedComboBoxModel(net.pms.util.KeyedComboBoxModel) RendererConfiguration(net.pms.configuration.RendererConfiguration) PreventSleepMode(net.pms.util.PreventSleepMode)

Example 2 with KeyedComboBoxModel

use of net.pms.util.KeyedComboBoxModel in project UniversalMediaServer by UniversalMediaServer.

the class GeneralTab method addRenderers.

/**
 * Add the renderer configuration selection after they have been
 * initialized.
 */
public void addRenderers() {
    ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getEnabledRenderersConfigurations();
    ArrayList<String> keyValues = new ArrayList<>();
    ArrayList<String> nameValues = new ArrayList<>();
    keyValues.add("");
    nameValues.add(Messages.getString("NetworkTab.37"));
    if (allConfs != null) {
        sortRendererConfigurationsByName(allConfs);
        for (RendererConfiguration renderer : allConfs) {
            if (renderer != null) {
                keyValues.add(renderer.getRendererName());
                nameValues.add(renderer.getRendererName());
            }
        }
    }
    final KeyedComboBoxModel<String, String> renderersKcbm = new KeyedComboBoxModel<>(keyValues.toArray(new String[keyValues.size()]), nameValues.toArray(new String[nameValues.size()]));
    renderers.setModel(renderersKcbm);
    renderers.setEditable(false);
    String defaultRenderer = configuration.getRendererDefault();
    renderersKcbm.setSelectedValue(defaultRenderer);
    if (renderers.getSelectedIndex() == -1) {
        renderers.setSelectedIndex(0);
    }
    renderers.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setRendererDefault((String) renderersKcbm.getSelectedKey());
                LOGGER.info("Setting default renderer to \"{}\"", renderersKcbm.getSelectedKey().equals("") ? Messages.getRootString("NetworkTab.37") : renderersKcbm.getSelectedKey());
            }
        }
    });
}
Also used : KeyedComboBoxModel(net.pms.util.KeyedComboBoxModel) RendererConfiguration(net.pms.configuration.RendererConfiguration)

Example 3 with KeyedComboBoxModel

use of net.pms.util.KeyedComboBoxModel in project UniversalMediaServer by UniversalMediaServer.

the class TranscodingTab method buildAudioSetupPanel.

private JComponent buildAudioSetupPanel() {
    String colSpec = FormLayoutUtil.getColSpec("left:pref, 3dlu, pref:grow", orientation);
    FormLayout layout = new FormLayout(colSpec, "$lgap, pref, 3dlu, 5*(pref, 3dlu), pref, 12dlu, 3*(pref, 3dlu), pref:grow");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DLU4);
    CellConstraints cc = new CellConstraints();
    builder.addLabel(Messages.getString("TrTab2.50"), FormLayoutUtil.flip(cc.xy(1, 2), colSpec, orientation));
    Integer[] keys = new Integer[] { 2, 6 };
    String[] values = new String[] { Messages.getString("TrTab2.55"), // 7.1 not supported by Mplayer
    Messages.getString("TrTab2.56") };
    final KeyedComboBoxModel<Integer, String> audioChannelsModel = new KeyedComboBoxModel<>(keys, values);
    channels = new JComboBox<>(audioChannelsModel);
    channels.setEditable(false);
    audioChannelsModel.setSelectedKey(configuration.getAudioChannelCount());
    channels.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAudioChannelCount(audioChannelsModel.getSelectedKey());
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(channels), FormLayoutUtil.flip(cc.xy(3, 2), colSpec, orientation));
    forcePCM = new JCheckBox(Messages.getString("TrTab2.27"), configuration.isAudioUsePCM());
    forcePCM.setToolTipText(Messages.getString("TrTab2.83"));
    forcePCM.setContentAreaFilled(false);
    forcePCM.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAudioUsePCM(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(forcePCM), FormLayoutUtil.flip(cc.xy(1, 4), colSpec, orientation));
    ac3remux = new JCheckBox(Messages.getString("TrTab2.26"), configuration.isAudioRemuxAC3());
    ac3remux.setToolTipText(Messages.getString("TrTab2.84") + (Platform.isWindows() ? " " + Messages.getString("TrTab2.21") : "") + "</html>");
    ac3remux.setEnabled(!configuration.isEncodedAudioPassthrough());
    ac3remux.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAudioRemuxAC3((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(ac3remux), FormLayoutUtil.flip(cc.xy(1, 6), colSpec, orientation));
    forceDTSinPCM = new JCheckBox(Messages.getString("TrTab2.28"), configuration.isAudioEmbedDtsInPcm());
    forceDTSinPCM.setToolTipText(Messages.getString("TrTab2.85") + (Platform.isWindows() ? " " + Messages.getString("TrTab2.21") : "") + "</html>");
    forceDTSinPCM.setEnabled(!configuration.isEncodedAudioPassthrough());
    forceDTSinPCM.setContentAreaFilled(false);
    forceDTSinPCM.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setAudioEmbedDtsInPcm(forceDTSinPCM.isSelected());
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(forceDTSinPCM), FormLayoutUtil.flip(cc.xy(1, 8), colSpec, orientation));
    encodedAudioPassthrough = new JCheckBox(Messages.getString("TrTab2.53"), configuration.isEncodedAudioPassthrough());
    encodedAudioPassthrough.setToolTipText(Messages.getString("TrTab2.86") + (Platform.isWindows() ? " " + Messages.getString("TrTab2.21") : "") + "</html>");
    encodedAudioPassthrough.setContentAreaFilled(false);
    encodedAudioPassthrough.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setEncodedAudioPassthrough((e.getStateChange() == ItemEvent.SELECTED));
            ac3remux.setEnabled((e.getStateChange() != ItemEvent.SELECTED));
            forceDTSinPCM.setEnabled((e.getStateChange() != ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(encodedAudioPassthrough), cc.xyw(1, 10, 3));
    builder.addLabel(Messages.getString("TrTab2.29"), FormLayoutUtil.flip(cc.xy(1, 12), colSpec, orientation));
    abitrate = new JTextField("" + configuration.getAudioBitrate());
    abitrate.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                int ab = Integer.parseInt(abitrate.getText());
                configuration.setAudioBitrate(ab);
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse audio bitrate from \"" + abitrate.getText() + "\"");
            }
        }
    });
    builder.add(abitrate, FormLayoutUtil.flip(cc.xy(3, 12), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.7"), FormLayoutUtil.flip(cc.xy(1, 14), colSpec, orientation));
    langs = new JTextField(configuration.getAudioLanguages());
    langs.setToolTipText(Messages.getString("TrTab2.75"));
    langs.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAudioLanguages(langs.getText());
        }
    });
    builder.add(langs, FormLayoutUtil.flip(cc.xy(3, 14), colSpec, orientation));
    JPanel panel = builder.getPanel();
    panel.applyComponentOrientation(orientation);
    return panel;
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) CustomJTextField(net.pms.newgui.components.CustomJTextField) KeyedComboBoxModel(net.pms.util.KeyedComboBoxModel) CellConstraints(com.jgoodies.forms.layout.CellConstraints)

Example 4 with KeyedComboBoxModel

use of net.pms.util.KeyedComboBoxModel in project UniversalMediaServer by UniversalMediaServer.

the class NavigationShareTab method initSimpleComponents.

private void initSimpleComponents(CellConstraints cc) {
    // Thumbnail seeking position
    seekpos = new JTextField("" + configuration.getThumbnailSeekPos());
    seekpos.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                int ab = Integer.parseInt(seekpos.getText());
                configuration.setThumbnailSeekPos(ab);
                if (configuration.getUseCache()) {
                    PMS.get().getDatabase().init(true);
                }
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse thumbnail seek position from \"" + seekpos.getText() + "\"");
            }
        }
    });
    if (configuration.isThumbnailGenerationEnabled()) {
        seekpos.setEnabled(true);
    } else {
        seekpos.setEnabled(false);
    }
    // Generate thumbnails
    thumbgenCheckBox = new JCheckBox(Messages.getString("NetworkTab.2"), configuration.isThumbnailGenerationEnabled());
    thumbgenCheckBox.setContentAreaFilled(false);
    thumbgenCheckBox.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setThumbnailGenerationEnabled((e.getStateChange() == ItemEvent.SELECTED));
            seekpos.setEnabled(configuration.isThumbnailGenerationEnabled());
            mplayer_thumb.setEnabled(configuration.isThumbnailGenerationEnabled());
        }
    });
    // Use MPlayer for video thumbnails
    mplayer_thumb = new JCheckBox(Messages.getString("FoldTab.14"), configuration.isUseMplayerForVideoThumbs());
    mplayer_thumb.setToolTipText(Messages.getString("FoldTab.61"));
    mplayer_thumb.setContentAreaFilled(false);
    mplayer_thumb.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseMplayerForVideoThumbs((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    if (configuration.isThumbnailGenerationEnabled()) {
        mplayer_thumb.setEnabled(true);
    } else {
        mplayer_thumb.setEnabled(false);
    }
    // DVD ISO thumbnails
    dvdiso_thumb = new JCheckBox(Messages.getString("FoldTab.19"), configuration.isDvdIsoThumbnails());
    dvdiso_thumb.setContentAreaFilled(false);
    dvdiso_thumb.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setDvdIsoThumbnails((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Image thumbnails
    image_thumb = new JCheckBox(Messages.getString("FoldTab.21"), configuration.getImageThumbnailsEnabled());
    image_thumb.setContentAreaFilled(false);
    image_thumb.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setImageThumbnailsEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Audio thumbnails import
    final KeyedComboBoxModel<CoverSupplier, String> thumbKCBM = new KeyedComboBoxModel<>(new CoverSupplier[] { CoverSupplier.NONE, CoverSupplier.COVER_ART_ARCHIVE }, new String[] { Messages.getString("FoldTab.35"), Messages.getString("FoldTab.73") });
    audiothumbnail = new JComboBox<>(thumbKCBM);
    audiothumbnail.setEditable(false);
    thumbKCBM.setSelectedKey(configuration.getAudioThumbnailMethod());
    audiothumbnail.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setAudioThumbnailMethod(thumbKCBM.getSelectedKey());
                LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.26"), thumbKCBM.getSelectedValue());
            }
        }
    });
    // Alternate video cover art folder
    defaultThumbFolder = new JTextField(configuration.getAlternateThumbFolder());
    defaultThumbFolder.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAlternateThumbFolder(defaultThumbFolder.getText());
        }
    });
    // Alternate video cover art folder button
    select = new CustomJButton("...");
    select.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                defaultThumbFolder.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setAlternateThumbFolder(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    // Show Server Settings folder
    isShowFolderServerSettings = new JCheckBox(Messages.getString("FoldTab.38"), configuration.isShowServerSettingsFolder());
    isShowFolderServerSettings.setContentAreaFilled(false);
    isShowFolderServerSettings.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowServerSettingsFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Show #--TRANSCODE--# folder
    isShowFolderTranscode = new JCheckBox(Messages.getString("FoldTab.33"), configuration.isShowTranscodeFolder());
    isShowFolderTranscode.setContentAreaFilled(false);
    isShowFolderTranscode.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowTranscodeFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Show Media Library folder
    isShowFolderMediaLibrary = new JCheckBox(Messages.getString("FoldTab.32"), configuration.isShowMediaLibraryFolder());
    isShowFolderMediaLibrary.setContentAreaFilled(false);
    isShowFolderMediaLibrary.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowMediaLibraryFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Browse compressed archives
    archive = new JCheckBox(Messages.getString("NetworkTab.1"), configuration.isArchiveBrowsing());
    archive.setContentAreaFilled(false);
    archive.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setArchiveBrowsing(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    // Enable the cache
    cacheenable = new JCheckBox(Messages.getString("NetworkTab.17"), configuration.getUseCache());
    cacheenable.setToolTipText(Messages.getString("FoldTab.48"));
    cacheenable.setContentAreaFilled(false);
    cacheenable.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseCache((e.getStateChange() == ItemEvent.SELECTED));
            cachereset.setEnabled(configuration.getUseCache());
            setScanLibraryEnabled(configuration.getUseCache());
        }
    });
    // Reset cache
    cachereset = new CustomJButton(Messages.getString("NetworkTab.18"));
    cachereset.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("NetworkTab.13") + "\n" + Messages.getString("NetworkTab.19"), Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
            if (option == JOptionPane.YES_OPTION) {
                PMS.get().getDatabase().init(true);
            }
        }
    });
    cachereset.setEnabled(configuration.getUseCache());
    // Hide file extensions
    hideextensions = new JCheckBox(Messages.getString("FoldTab.5"), configuration.isHideExtensions());
    hideextensions.setContentAreaFilled(false);
    if (configuration.isPrettifyFilenames()) {
        hideextensions.setEnabled(false);
    }
    hideextensions.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideExtensions((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Hide transcoding engine names
    hideengines = new JCheckBox(Messages.getString("FoldTab.8"), configuration.isHideEngineNames());
    hideengines.setToolTipText(Messages.getString("FoldTab.46"));
    hideengines.setContentAreaFilled(false);
    hideengines.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideEngineNames((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Hide empty folders
    hideemptyfolders = new JCheckBox(Messages.getString("FoldTab.31"), configuration.isHideEmptyFolders());
    hideemptyfolders.setToolTipText(Messages.getString("FoldTab.59"));
    hideemptyfolders.setContentAreaFilled(false);
    hideemptyfolders.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setHideEmptyFolders((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Show iTunes library
    itunes = new JCheckBox(Messages.getString("FoldTab.30"), configuration.isShowItunesLibrary());
    itunes.setToolTipText(Messages.getString("FoldTab.47"));
    itunes.setContentAreaFilled(false);
    if (!(Platform.isMac() || Platform.isWindows())) {
        itunes.setEnabled(false);
    }
    itunes.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowItunesLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Show iPhoto library
    iphoto = new JCheckBox(Messages.getString("FoldTab.29"), configuration.isShowIphotoLibrary());
    iphoto.setContentAreaFilled(false);
    if (!Platform.isMac()) {
        iphoto.setEnabled(false);
    }
    iphoto.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowIphotoLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Show aperture library
    aperture = new JCheckBox(Messages.getString("FoldTab.34"), configuration.isShowApertureLibrary());
    aperture.setContentAreaFilled(false);
    if (!Platform.isMac()) {
        aperture.setEnabled(false);
    }
    aperture.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowApertureLibrary((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // File order
    final KeyedComboBoxModel<Integer, String> kcbm = new KeyedComboBoxModel<>(new Integer[] { // alphabetical
    UMSUtils.SORT_LOC_SENS, // natural sort
    UMSUtils.SORT_LOC_NAT, // ASCIIbetical
    UMSUtils.SORT_INS_ASCII, // newest first
    UMSUtils.SORT_MOD_NEW, // oldest first
    UMSUtils.SORT_MOD_OLD, // random
    UMSUtils.SORT_RANDOM, // no sorting
    UMSUtils.SORT_NO_SORT }, new String[] { Messages.getString("FoldTab.15"), Messages.getString("FoldTab.22"), Messages.getString("FoldTab.20"), Messages.getString("FoldTab.16"), Messages.getString("FoldTab.17"), Messages.getString("FoldTab.58"), Messages.getString("FoldTab.62") });
    sortmethod = new JComboBox<>(kcbm);
    sortmethod.setEditable(false);
    kcbm.setSelectedKey(configuration.getSortMethod(null));
    sortmethod.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setSortMethod(kcbm.getSelectedKey());
                LOGGER.info("Setting {} {}", Messages.getRootString("FoldTab.18"), kcbm.getSelectedValue());
            }
        }
    });
    // Ignore the word "the" while sorting
    ignorethewordthe = new JCheckBox(Messages.getString("FoldTab.39"), configuration.isIgnoreTheWordAandThe());
    ignorethewordthe.setToolTipText(Messages.getString("FoldTab.44"));
    ignorethewordthe.setContentAreaFilled(false);
    ignorethewordthe.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setIgnoreTheWordAandThe((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    atzLimit = new JTextField("" + configuration.getATZLimit());
    atzLimit.setToolTipText(Messages.getString("FoldTab.49"));
    atzLimit.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                int ab = Integer.parseInt(atzLimit.getText());
                configuration.setATZLimit(ab);
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse ATZ limit from \"" + atzLimit.getText() + "\"");
                LOGGER.debug("The full error was: " + nfe);
            }
        }
    });
    isShowFolderLiveSubtitles = new JCheckBox(Messages.getString("FoldTab.42"), configuration.isShowLiveSubtitlesFolder());
    isShowFolderLiveSubtitles.setContentAreaFilled(false);
    isShowFolderLiveSubtitles.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowLiveSubtitlesFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    prettifyfilenames = new JCheckBox(Messages.getString("FoldTab.43"), configuration.isPrettifyFilenames());
    prettifyfilenames.setToolTipText(Messages.getString("FoldTab.45"));
    prettifyfilenames.setContentAreaFilled(false);
    prettifyfilenames.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setPrettifyFilenames((e.getStateChange() == ItemEvent.SELECTED));
            hideextensions.setEnabled((e.getStateChange() != ItemEvent.SELECTED));
            episodeTitles.setEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    episodeTitles = new JCheckBox(Messages.getString("FoldTab.74"), configuration.isUseInfoFromIMDb());
    episodeTitles.setToolTipText(Messages.getString("FoldTab.64"));
    episodeTitles.setContentAreaFilled(false);
    if (!configuration.isPrettifyFilenames()) {
        episodeTitles.setEnabled(false);
    }
    episodeTitles.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseInfoFromIMDb((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    isShowFolderNewMedia = new JCheckBox(Messages.getString("FoldTab.54"), configuration.isShowNewMediaFolder());
    isShowFolderNewMedia.setToolTipText(Messages.getString("FoldTab.66"));
    isShowFolderNewMedia.setContentAreaFilled(false);
    isShowFolderNewMedia.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowNewMediaFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    resume = new JCheckBox(Messages.getString("NetworkTab.68"), configuration.isResumeEnabled());
    resume.setToolTipText(Messages.getString("NetworkTab.69"));
    resume.setContentAreaFilled(false);
    resume.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setResume((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    isShowFolderRecentlyPlayed = new JCheckBox(Messages.getString("FoldTab.55"), configuration.isShowRecentlyPlayedFolder());
    isShowFolderRecentlyPlayed.setContentAreaFilled(false);
    isShowFolderRecentlyPlayed.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setShowRecentlyPlayedFolder((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Fully played action
    final KeyedComboBoxModel<FullyPlayedAction, String> fullyPlayedActionModel = new KeyedComboBoxModel<>(new FullyPlayedAction[] { FullyPlayedAction.NO_ACTION, FullyPlayedAction.MARK, FullyPlayedAction.HIDE_VIDEO, FullyPlayedAction.MOVE_FOLDER, FullyPlayedAction.MOVE_TRASH }, new String[] { Messages.getString("FoldTab.67"), Messages.getString("FoldTab.68"), Messages.getString("FoldTab.69"), Messages.getString("FoldTab.70"), Messages.getString("FoldTab.71") });
    fullyPlayedAction = new JComboBox<>(fullyPlayedActionModel);
    fullyPlayedAction.setEditable(false);
    fullyPlayedActionModel.setSelectedKey(configuration.getFullyPlayedAction());
    fullyPlayedAction.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setFullyPlayedAction(fullyPlayedActionModel.getSelectedKey());
                fullyPlayedOutputDirectory.setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);
                selectFullyPlayedOutputDirectory.setEnabled(fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.MOVE_FOLDER);
                if (configuration.getUseCache() && fullyPlayedActionModel.getSelectedKey() == FullyPlayedAction.NO_ACTION) {
                    PMS.get().getDatabase().init(true);
                }
            }
        }
    });
    // Watched video output directory
    fullyPlayedOutputDirectory = new JTextField(configuration.getFullyPlayedOutputDirectory());
    fullyPlayedOutputDirectory.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setFullyPlayedOutputDirectory(fullyPlayedOutputDirectory.getText());
        }
    });
    fullyPlayedOutputDirectory.setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);
    // Watched video output directory selection button
    selectFullyPlayedOutputDirectory = new CustomJButton("...");
    selectFullyPlayedOutputDirectory.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                fullyPlayedOutputDirectory.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setFullyPlayedOutputDirectory(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    selectFullyPlayedOutputDirectory.setEnabled(configuration.getFullyPlayedAction() == FullyPlayedAction.MOVE_FOLDER);
}
Also used : FullyPlayedAction(net.pms.util.FullyPlayedAction) CoverSupplier(net.pms.util.CoverSupplier) KeyedComboBoxModel(net.pms.util.KeyedComboBoxModel) CustomJButton(net.pms.newgui.components.CustomJButton) Component(java.awt.Component)

Example 5 with KeyedComboBoxModel

use of net.pms.util.KeyedComboBoxModel in project UniversalMediaServer by UniversalMediaServer.

the class TranscodingTab method buildSubtitlesSetupPanel.

private JComponent buildSubtitlesSetupPanel() {
    String colSpec = FormLayoutUtil.getColSpec("left:pref, 3dlu, p:grow, 3dlu, right:p:grow, 3dlu, p:grow, 3dlu, right:p:grow,3dlu, p:grow, 3dlu, right:p:grow,3dlu, pref:grow", orientation);
    FormLayout layout = new FormLayout(colSpec, "$lgap, 11*(pref, 3dlu), pref");
    final PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DLU4);
    CellConstraints cc = new CellConstraints();
    builder.addLabel(Messages.getString("MEncoderVideo.9"), FormLayoutUtil.flip(cc.xy(1, 2), colSpec, orientation));
    defaultsubs = new CustomJTextField(configuration.getSubtitlesLanguages());
    defaultsubs.setToolTipText(Messages.getString("TrTab2.76"));
    defaultsubs.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setSubtitlesLanguages(defaultsubs.getText());
        }
    });
    builder.add(defaultsubs, FormLayoutUtil.flip(cc.xyw(3, 2, 5), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.94"), FormLayoutUtil.flip(cc.xy(9, 2, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    forcedsub = new JTextField(configuration.getForcedSubtitleLanguage());
    forcedsub.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setForcedSubtitleLanguage(forcedsub.getText());
        }
    });
    builder.add(forcedsub, FormLayoutUtil.flip(cc.xy(11, 2), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.95"), FormLayoutUtil.flip(cc.xy(13, 2, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    forcedtags = new JTextField(configuration.getForcedSubtitleTags());
    forcedtags.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setForcedSubtitleTags(forcedtags.getText());
        }
    });
    builder.add(forcedtags, FormLayoutUtil.flip(cc.xy(15, 2), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.10"), FormLayoutUtil.flip(cc.xy(1, 4), colSpec, orientation));
    defaultaudiosubs = new JTextField(configuration.getAudioSubLanguages());
    defaultaudiosubs.setToolTipText(Messages.getString("TrTab2.77"));
    defaultaudiosubs.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAudioSubLanguages(defaultaudiosubs.getText());
        }
    });
    builder.add(defaultaudiosubs, FormLayoutUtil.flip(cc.xyw(3, 4, 13), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.37"), FormLayoutUtil.flip(cc.xyw(1, 6, 2), colSpec, orientation));
    alternateSubFolder = new JTextField(configuration.getAlternateSubtitlesFolder());
    alternateSubFolder.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAlternateSubtitlesFolder(alternateSubFolder.getText());
        }
    });
    builder.add(alternateSubFolder, FormLayoutUtil.flip(cc.xyw(3, 6, 12), colSpec, orientation));
    folderSelectButton = new JButton("...");
    folderSelectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser;
            try {
                chooser = new JFileChooser();
            } catch (Exception ee) {
                chooser = new JFileChooser(new RestrictedFileSystemView());
            }
            chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                alternateSubFolder.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setAlternateSubtitlesFolder(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    builder.add(folderSelectButton, FormLayoutUtil.flip(cc.xy(15, 6), colSpec, orientation));
    builder.addLabel(Messages.getString("TrTab2.95"), FormLayoutUtil.flip(cc.xy(1, 8), colSpec, orientation));
    String[] keys = new String[] { "", "cp874", "cp932", "cp936", "cp949", "cp950", "cp1250", "cp1251", "cp1252", "cp1253", "cp1254", "cp1255", "cp1256", "cp1257", "cp1258", "ISO-2022-CN", "ISO-2022-JP", "ISO-2022-KR", "ISO-8859-1", "ISO-8859-2", "ISO-8859-3", "ISO-8859-4", "ISO-8859-5", "ISO-8859-6", "ISO-8859-7", "ISO-8859-8", "ISO-8859-9", "ISO-8859-10", "ISO-8859-11", "ISO-8859-13", "ISO-8859-14", "ISO-8859-15", "ISO-8859-16", "Big5", "EUC-JP", "EUC-KR", "GB18030", "IBM420", "IBM424", "KOI8-R", "Shift_JIS", "TIS-620" };
    String[] values = new String[] { Messages.getString("General.2"), Messages.getString("CharacterSet.874"), Messages.getString("CharacterSet.932"), Messages.getString("CharacterSet.936"), Messages.getString("CharacterSet.949"), Messages.getString("CharacterSet.950"), Messages.getString("CharacterSet.1250"), Messages.getString("CharacterSet.1251"), Messages.getString("CharacterSet.1252"), Messages.getString("CharacterSet.1253"), Messages.getString("CharacterSet.1254"), Messages.getString("CharacterSet.1255"), Messages.getString("CharacterSet.1256"), Messages.getString("CharacterSet.1257"), Messages.getString("CharacterSet.1258"), Messages.getString("CharacterSet.2022-CN"), Messages.getString("CharacterSet.2022-JP"), Messages.getString("CharacterSet.2022-KR"), Messages.getString("CharacterSet.8859-1"), Messages.getString("CharacterSet.8859-2"), Messages.getString("CharacterSet.8859-3"), Messages.getString("CharacterSet.8859-4"), Messages.getString("CharacterSet.8859-5"), Messages.getString("CharacterSet.8859-6"), Messages.getString("CharacterSet.8859-7"), Messages.getString("CharacterSet.8859-8"), Messages.getString("CharacterSet.8859-9"), Messages.getString("CharacterSet.8859-10"), Messages.getString("CharacterSet.8859-11"), Messages.getString("CharacterSet.8859-13"), Messages.getString("CharacterSet.8859-14"), Messages.getString("CharacterSet.8859-15"), Messages.getString("CharacterSet.8859-16"), Messages.getString("CharacterSet.Big5"), Messages.getString("CharacterSet.EUC-JP"), Messages.getString("CharacterSet.EUC-KR"), Messages.getString("CharacterSet.GB18030"), Messages.getString("CharacterSet.IBM420"), Messages.getString("CharacterSet.IBM424"), Messages.getString("CharacterSet.KOI8-R"), Messages.getString("CharacterSet.ShiftJIS"), Messages.getString("CharacterSet.TIS-620") };
    final KeyedComboBoxModel<String, String> subtitleCodePageModel = new KeyedComboBoxModel<>(keys, values);
    subtitleCodePage = new CustomJComboBox<>(subtitleCodePageModel);
    subtitleCodePage.setToolTipText(Messages.getString("TrTab2.94"));
    subtitleCodePageModel.setSelectedKey(configuration.getSubtitlesCodepage());
    subtitleCodePage.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setSubtitlesCodepage(subtitleCodePageModel.getSelectedKey());
            }
        }
    });
    subtitleCodePage.setEditable(false);
    builder.add(subtitleCodePage, FormLayoutUtil.flip(cc.xyw(3, 8, 7), colSpec, orientation));
    fribidi = new JCheckBox(Messages.getString("MEncoderVideo.23"), configuration.isMencoderSubFribidi());
    fribidi.setContentAreaFilled(false);
    fribidi.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderSubFribidi(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(fribidi), FormLayoutUtil.flip(cc.xyw(11, 8, 4), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.24"), FormLayoutUtil.flip(cc.xy(1, 10), colSpec, orientation));
    defaultfont = new JTextField(configuration.getFont());
    defaultfont.setToolTipText(Messages.getString("TrTab2.97"));
    defaultfont.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setFont(defaultfont.getText());
        }
    });
    builder.add(defaultfont, FormLayoutUtil.flip(cc.xyw(3, 10, 12), colSpec, orientation));
    fontselect = new CustomJButton("...");
    fontselect.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JFileChooser chooser = new JFileChooser();
            chooser.setFileFilter(new FontFileFilter());
            int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("MEncoderVideo.25"));
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                defaultfont.setText(chooser.getSelectedFile().getAbsolutePath());
                configuration.setFont(chooser.getSelectedFile().getAbsolutePath());
            }
        }
    });
    builder.add(fontselect, FormLayoutUtil.flip(cc.xy(15, 10), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.12"), FormLayoutUtil.flip(cc.xy(1, 12), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.133"), FormLayoutUtil.flip(cc.xy(1, 12, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    ass_scale = new JTextField(configuration.getAssScale());
    ass_scale.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAssScale(ass_scale.getText());
        }
    });
    builder.addLabel(Messages.getString("MEncoderVideo.13"), FormLayoutUtil.flip(cc.xy(5, 12), colSpec, orientation));
    ass_outline = new JTextField(configuration.getAssOutline());
    ass_outline.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAssOutline(ass_outline.getText());
        }
    });
    builder.addLabel(Messages.getString("MEncoderVideo.14"), FormLayoutUtil.flip(cc.xy(9, 12), colSpec, orientation));
    ass_shadow = new JTextField(configuration.getAssShadow());
    ass_shadow.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAssShadow(ass_shadow.getText());
        }
    });
    builder.addLabel(Messages.getString("MEncoderVideo.15"), FormLayoutUtil.flip(cc.xy(13, 12), colSpec, orientation));
    ass_margin = new JTextField(configuration.getAssMargin());
    ass_margin.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setAssMargin(ass_margin.getText());
        }
    });
    builder.add(ass_scale, FormLayoutUtil.flip(cc.xy(3, 12), colSpec, orientation));
    builder.add(ass_outline, FormLayoutUtil.flip(cc.xy(7, 12), colSpec, orientation));
    builder.add(ass_shadow, FormLayoutUtil.flip(cc.xy(11, 12), colSpec, orientation));
    builder.add(ass_margin, FormLayoutUtil.flip(cc.xy(15, 12), colSpec, orientation));
    autoloadExternalSubtitles = new JCheckBox(Messages.getString("MEncoderVideo.22"), configuration.isAutoloadExternalSubtitles());
    autoloadExternalSubtitles.setToolTipText(Messages.getString("TrTab2.78"));
    autoloadExternalSubtitles.setContentAreaFilled(false);
    autoloadExternalSubtitles.setEnabled(!configuration.isForceExternalSubtitles());
    autoloadExternalSubtitles.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAutoloadExternalSubtitles((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(autoloadExternalSubtitles), FormLayoutUtil.flip(cc.xyw(1, 14, 11), colSpec, orientation));
    subColor = new JButton();
    subColor.setText(Messages.getString("MEncoderVideo.31"));
    subColor.setBackground(configuration.getSubsColor());
    subColor.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final JColorChooser jColorChooser = new JColorChooser(subColor.getBackground());
            Locale locale = PMS.getLocale();
            jColorChooser.setLocale(locale);
            jColorChooser.setComponentOrientation(ComponentOrientation.getOrientation(locale));
            JDialog dialog = JColorChooser.createDialog(looksFrame, Messages.getString("MEncoderVideo.125"), true, jColorChooser, new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Color newColor = jColorChooser.getColor();
                    if (newColor != null) {
                        subColor.setBackground(newColor);
                        configuration.setSubsColor(newColor);
                        // Subtitle color has been changed so all temporary subtitles must be deleted
                        SubtitleUtils.deleteSubs();
                    }
                }
            }, null);
            dialog.setVisible(true);
            dialog.dispose();
        }
    });
    builder.add(subColor, FormLayoutUtil.flip(cc.xyw(13, 14, 3), colSpec, orientation));
    forceExternalSubtitles = new JCheckBox(Messages.getString("TrTab2.87"), configuration.isForceExternalSubtitles());
    forceExternalSubtitles.setToolTipText(Messages.getString("TrTab2.88"));
    forceExternalSubtitles.setContentAreaFilled(false);
    forceExternalSubtitles.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setForceExternalSubtitles((e.getStateChange() == ItemEvent.SELECTED));
            if (configuration.isForceExternalSubtitles()) {
                autoloadExternalSubtitles.setSelected(true);
            }
            autoloadExternalSubtitles.setEnabled(!configuration.isForceExternalSubtitles());
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(forceExternalSubtitles), FormLayoutUtil.flip(cc.xyw(1, 16, 11), colSpec, orientation));
    useEmbeddedSubtitlesStyle = new JCheckBox(Messages.getString("MEncoderVideo.36"), configuration.isUseEmbeddedSubtitlesStyle());
    useEmbeddedSubtitlesStyle.setToolTipText(Messages.getString("TrTab2.89"));
    useEmbeddedSubtitlesStyle.setContentAreaFilled(false);
    useEmbeddedSubtitlesStyle.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setUseEmbeddedSubtitlesStyle(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(useEmbeddedSubtitlesStyle), FormLayoutUtil.flip(cc.xyw(1, 18, 11), colSpec, orientation));
    Integer[] depth = { -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5 };
    builder.addLabel(Messages.getString("TrTab2.90"), FormLayoutUtil.flip(cc.xy(1, 20), colSpec, orientation));
    depth3D = new JComboBox<>(depth);
    depth3D.setSelectedItem(configuration.getDepth3D());
    depth3D.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setDepth3D((int) e.getItem());
            }
        }
    });
    builder.add(depth3D, FormLayoutUtil.flip(cc.xy(3, 20), colSpec, orientation));
    final JPanel panel = builder.getPanel();
    GuiUtil.enableContainer(panel, !configuration.isDisableSubtitles());
    disableSubs.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            // If "Disable Subtitles" is not selected, subtitles are enabled
            GuiUtil.enableContainer(panel, e.getStateChange() != ItemEvent.SELECTED);
        }
    });
    panel.applyComponentOrientation(orientation);
    return panel;
}
Also used : Locale(java.util.Locale) CustomJButton(net.pms.newgui.components.CustomJButton) CustomJTextField(net.pms.newgui.components.CustomJTextField) CellConstraints(com.jgoodies.forms.layout.CellConstraints) FormLayout(com.jgoodies.forms.layout.FormLayout) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) KeyedComboBoxModel(net.pms.util.KeyedComboBoxModel) CustomJButton(net.pms.newgui.components.CustomJButton) CustomJTextField(net.pms.newgui.components.CustomJTextField)

Aggregations

KeyedComboBoxModel (net.pms.util.KeyedComboBoxModel)5 PanelBuilder (com.jgoodies.forms.builder.PanelBuilder)3 CellConstraints (com.jgoodies.forms.layout.CellConstraints)3 FormLayout (com.jgoodies.forms.layout.FormLayout)3 CustomJButton (net.pms.newgui.components.CustomJButton)3 RendererConfiguration (net.pms.configuration.RendererConfiguration)2 CustomJTextField (net.pms.newgui.components.CustomJTextField)2 Component (java.awt.Component)1 Locale (java.util.Locale)1 CoverSupplier (net.pms.util.CoverSupplier)1 FullyPlayedAction (net.pms.util.FullyPlayedAction)1 PreventSleepMode (net.pms.util.PreventSleepMode)1