Search in sources :

Example 1 with CustomJButton

use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.

the class DbgPacker method config.

public JComponent config() {
    poll();
    JPanel top = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.insets = new Insets(0, 5, 0, 5);
    c.ipadx = 5;
    c.gridx = 0;
    c.gridy = 0;
    for (Map.Entry<File, JCheckBox> item : items.entrySet()) {
        File file = item.getKey();
        boolean exists = file.exists();
        JCheckBox box = item.getValue();
        if (box == null) {
            box = new JCheckBox(file.getName(), exists);
            item.setValue(box);
        }
        if (!exists) {
            box.setSelected(false);
            box.setEnabled(false);
        }
        c.weightx = 1.0;
        top.add(box, c);
        CustomJButton open = exists ? new CustomJButton(MetalIconFactory.getTreeLeafIcon()) : new CustomJButton("+");
        open.setActionCommand(file.getAbsolutePath());
        open.setToolTipText((exists ? "" : Messages.getString("DbgPacker.1") + " ") + file.getAbsolutePath());
        open.addActionListener(this);
        c.gridx++;
        c.weightx = 0.0;
        top.add(open, c);
        c.gridx--;
        c.gridy++;
    }
    c.weightx = 2.0;
    CustomJButton debugPack = new CustomJButton(Messages.getString("DbgPacker.2"));
    debugPack.setActionCommand("pack");
    debugPack.addActionListener(this);
    top.add(debugPack, c);
    openZip = new CustomJButton(MetalIconFactory.getTreeFolderIcon());
    openZip.setActionCommand("showzip");
    openZip.setToolTipText(Messages.getString("DbgPacker.3"));
    openZip.setEnabled(false);
    openZip.addActionListener(this);
    c.gridx++;
    c.weightx = 0.0;
    top.add(openZip, c);
    return top;
}
Also used : CustomJButton(net.pms.newgui.components.CustomJButton) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File)

Example 2 with CustomJButton

use of net.pms.newgui.components.CustomJButton 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 3 with CustomJButton

use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.

the class LooksFrame method createToolBarButton.

protected AbstractButton createToolBarButton(String text, String iconName, String toolTipText) {
    CustomJButton button = new CustomJButton(text, readImageIcon(iconName));
    button.setToolTipText(toolTipText);
    button.setFocusable(false);
    button.setBorderPainted(false);
    return button;
}
Also used : CustomJButton(net.pms.newgui.components.CustomJButton)

Example 4 with CustomJButton

use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.

the class PluginTab method removePlugin.

public void removePlugin(ExternalListener listener) {
    CustomJButton del = null;
    for (Component c : pPlugins.getComponents()) {
        if (c instanceof CustomJButton) {
            CustomJButton button = (CustomJButton) c;
            if (button.getText().equals(listener.name())) {
                del = button;
                break;
            }
        }
    }
    if (del != null) {
        pPlugins.remove(del);
        pPlugins.repaint();
    }
}
Also used : CustomJButton(net.pms.newgui.components.CustomJButton) Component(java.awt.Component) JComponent(javax.swing.JComponent)

Example 5 with CustomJButton

use of net.pms.newgui.components.CustomJButton in project UniversalMediaServer by UniversalMediaServer.

the class MEncoderVideo method config.

@Override
public JComponent config() {
    // 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.EMPTY);
    builder.opaque(false);
    CellConstraints cc = new CellConstraints();
    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), FormLayoutUtil.flip(cc.xyw(1, 1, 15), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
    mencodermt = new JCheckBox(Messages.getString("MEncoderVideo.35"), configuration.getMencoderMT());
    mencodermt.setContentAreaFilled(false);
    mencodermt.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setMencoderMT(mencodermt.isSelected());
        }
    });
    mencodermt.setEnabled(Platform.isWindows() || Platform.isMac());
    builder.add(GuiUtil.getPreferredSizeComponent(mencodermt), FormLayoutUtil.flip(cc.xy(1, 3), colSpec, orientation));
    skipLoopFilter = new JCheckBox(Messages.getString("MEncoderVideo.0"), configuration.getSkipLoopFilterEnabled());
    skipLoopFilter.setContentAreaFilled(false);
    skipLoopFilter.setToolTipText(Messages.getString("MEncoderVideo.136"));
    skipLoopFilter.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setSkipLoopFilterEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(skipLoopFilter), FormLayoutUtil.flip(cc.xyw(3, 3, 12), colSpec, orientation));
    noskip = new JCheckBox(Messages.getString("MEncoderVideo.2"), configuration.isMencoderNoOutOfSync());
    noskip.setContentAreaFilled(false);
    noskip.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderNoOutOfSync((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(noskip), FormLayoutUtil.flip(cc.xy(1, 5), colSpec, orientation));
    CustomJButton button = new CustomJButton(Messages.getString("MEncoderVideo.29"));
    button.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JPanel codecPanel = new JPanel(new BorderLayout());
            final JTextArea textArea = new JTextArea();
            textArea.setText(configuration.getMencoderCodecSpecificConfig());
            textArea.setFont(new Font("Courier", Font.PLAIN, 12));
            JScrollPane scrollPane = new JScrollPane(textArea);
            scrollPane.setPreferredSize(new Dimension(900, 100));
            final JTextArea textAreaDefault = new JTextArea();
            textAreaDefault.setText(DEFAULT_CODEC_CONF_SCRIPT);
            textAreaDefault.setBackground(Color.WHITE);
            textAreaDefault.setFont(new Font("Courier", Font.PLAIN, 12));
            textAreaDefault.setEditable(false);
            textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync());
            JScrollPane scrollPaneDefault = new JScrollPane(textAreaDefault);
            scrollPaneDefault.setPreferredSize(new Dimension(900, 450));
            JPanel customPanel = new JPanel(new BorderLayout());
            intelligentsync = new JCheckBox(Messages.getString("MEncoderVideo.3"), configuration.isMencoderIntelligentSync());
            intelligentsync.setContentAreaFilled(false);
            intelligentsync.addItemListener(new ItemListener() {

                @Override
                public void itemStateChanged(ItemEvent e) {
                    configuration.setMencoderIntelligentSync((e.getStateChange() == ItemEvent.SELECTED));
                    textAreaDefault.setEnabled(configuration.isMencoderIntelligentSync());
                }
            });
            JLabel label = new JLabel(Messages.getString("MEncoderVideo.33"));
            customPanel.add(label, BorderLayout.NORTH);
            customPanel.add(scrollPane, BorderLayout.SOUTH);
            codecPanel.add(intelligentsync, BorderLayout.NORTH);
            codecPanel.add(scrollPaneDefault, BorderLayout.CENTER);
            codecPanel.add(customPanel, BorderLayout.SOUTH);
            while (JOptionPane.showOptionDialog(SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), codecPanel, Messages.getString("MEncoderVideo.34"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null) == JOptionPane.OK_OPTION) {
                String newCodecparam = textArea.getText();
                DLNAMediaInfo fakemedia = new DLNAMediaInfo();
                DLNAMediaAudio audio = new DLNAMediaAudio();
                audio.setCodecA("ac3");
                fakemedia.setCodecV("mpeg4");
                fakemedia.setContainer("matroska");
                fakemedia.setDuration(45d * 60);
                audio.getAudioProperties().setNumberOfChannels(2);
                fakemedia.setWidth(1280);
                fakemedia.setHeight(720);
                audio.setSampleFrequency("48000");
                fakemedia.setFrameRate("23.976");
                fakemedia.getAudioTracksList().add(audio);
                String[] result = getSpecificCodecOptions(newCodecparam, fakemedia, new OutputParams(configuration), "dummy.mpg", "dummy.srt", false, true);
                if (result.length > 0 && result[0].startsWith("@@")) {
                    String errorMessage = result[0].substring(2);
                    JOptionPane.showMessageDialog(SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()), errorMessage, Messages.getString("Dialog.Error"), JOptionPane.ERROR_MESSAGE);
                } else {
                    configuration.setMencoderCodecSpecificConfig(newCodecparam);
                    break;
                }
            }
        }
    });
    builder.add(button, FormLayoutUtil.flip(cc.xy(1, 11), colSpec, orientation));
    forcefps = new JCheckBox(Messages.getString("MEncoderVideo.4"), configuration.isMencoderForceFps());
    forcefps.setContentAreaFilled(false);
    forcefps.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderForceFps(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(forcefps), FormLayoutUtil.flip(cc.xyw(1, 7, 2), colSpec, orientation));
    yadif = new JCheckBox(Messages.getString("MEncoderVideo.26"), configuration.isMencoderYadif());
    yadif.setContentAreaFilled(false);
    yadif.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderYadif(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(yadif), FormLayoutUtil.flip(cc.xyw(3, 7, 7), colSpec, orientation));
    scaler = new JCheckBox(Messages.getString("MEncoderVideo.27"));
    scaler.setContentAreaFilled(false);
    scaler.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderScaler(e.getStateChange() == ItemEvent.SELECTED);
            scaleX.setEnabled(configuration.isMencoderScaler());
            scaleY.setEnabled(configuration.isMencoderScaler());
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(scaler), FormLayoutUtil.flip(cc.xyw(3, 5, 6), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.28"), FormLayoutUtil.flip(cc.xy(9, 5, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    scaleX = new JTextField("" + configuration.getMencoderScaleX());
    scaleX.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                configuration.setMencoderScaleX(Integer.parseInt(scaleX.getText()));
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse scaleX from \"" + scaleX.getText() + "\"");
            }
        }
    });
    builder.add(scaleX, FormLayoutUtil.flip(cc.xy(11, 5), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.30"), FormLayoutUtil.flip(cc.xy(13, 5, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    scaleY = new JTextField("" + configuration.getMencoderScaleY());
    scaleY.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            try {
                configuration.setMencoderScaleY(Integer.parseInt(scaleY.getText()));
            } catch (NumberFormatException nfe) {
                LOGGER.debug("Could not parse scaleY from \"" + scaleY.getText() + "\"");
            }
        }
    });
    builder.add(scaleY, FormLayoutUtil.flip(cc.xy(15, 5), colSpec, orientation));
    if (configuration.isMencoderScaler()) {
        scaler.setSelected(true);
    } else {
        scaleX.setEnabled(false);
        scaleY.setEnabled(false);
    }
    videoremux = new JCheckBox(Messages.getString("MEncoderVideo.38"), configuration.isMencoderMuxWhenCompatible());
    videoremux.setContentAreaFilled(false);
    videoremux.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderMuxWhenCompatible((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(videoremux), FormLayoutUtil.flip(cc.xyw(1, 9, 13), colSpec, orientation));
    normalizeaudio = new JCheckBox(Messages.getString("MEncoderVideo.134"), configuration.isMEncoderNormalizeVolume());
    normalizeaudio.setContentAreaFilled(false);
    normalizeaudio.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMEncoderNormalizeVolume((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    // Uncomment this if volume normalizing in MEncoder is ever fixed.
    // builder.add(normalizeaudio, FormLayoutUtil.flip(cc.xyw(1, 13, 13), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.6"), FormLayoutUtil.flip(cc.xy(1, 15), colSpec, orientation));
    mencoder_custom_options = new JTextField(configuration.getMencoderCustomOptions());
    mencoder_custom_options.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderCustomOptions(mencoder_custom_options.getText());
        }
    });
    builder.add(mencoder_custom_options, FormLayoutUtil.flip(cc.xyw(3, 15, 13), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.93"), FormLayoutUtil.flip(cc.xy(1, 17), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.28") + " (%)", FormLayoutUtil.flip(cc.xy(1, 17, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    ocw = new JTextField(configuration.getMencoderOverscanCompensationWidth());
    ocw.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderOverscanCompensationWidth(ocw.getText());
        }
    });
    builder.add(ocw, FormLayoutUtil.flip(cc.xy(3, 17), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.30") + " (%)", FormLayoutUtil.flip(cc.xy(5, 17), colSpec, orientation));
    och = new JTextField(configuration.getMencoderOverscanCompensationHeight());
    och.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderOverscanCompensationHeight(och.getText());
        }
    });
    builder.add(och, FormLayoutUtil.flip(cc.xy(7, 17), colSpec, orientation));
    cmp = builder.addSeparator(Messages.getString("MEncoderVideo.8"), FormLayoutUtil.flip(cc.xyw(1, 19, 15), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
    builder.addLabel(Messages.getString("MEncoderVideo.16"), FormLayoutUtil.flip(cc.xy(1, 27), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.133"), FormLayoutUtil.flip(cc.xy(1, 27, CellConstraints.RIGHT, CellConstraints.CENTER), colSpec, orientation));
    mencoder_noass_scale = new JTextField(configuration.getMencoderNoAssScale());
    mencoder_noass_scale.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssScale(mencoder_noass_scale.getText());
        }
    });
    builder.addLabel(Messages.getString("MEncoderVideo.17"), FormLayoutUtil.flip(cc.xy(5, 27), colSpec, orientation));
    mencoder_noass_outline = new JTextField(configuration.getMencoderNoAssOutline());
    mencoder_noass_outline.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssOutline(mencoder_noass_outline.getText());
        }
    });
    builder.addLabel(Messages.getString("MEncoderVideo.18"), FormLayoutUtil.flip(cc.xy(9, 27), colSpec, orientation));
    mencoder_noass_blur = new JTextField(configuration.getMencoderNoAssBlur());
    mencoder_noass_blur.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssBlur(mencoder_noass_blur.getText());
        }
    });
    builder.addLabel(Messages.getString("MEncoderVideo.19"), FormLayoutUtil.flip(cc.xy(13, 27), colSpec, orientation));
    mencoder_noass_subpos = new JTextField(configuration.getMencoderNoAssSubPos());
    mencoder_noass_subpos.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderNoAssSubPos(mencoder_noass_subpos.getText());
        }
    });
    builder.add(mencoder_noass_scale, FormLayoutUtil.flip(cc.xy(3, 27), colSpec, orientation));
    builder.add(mencoder_noass_outline, FormLayoutUtil.flip(cc.xy(7, 27), colSpec, orientation));
    builder.add(mencoder_noass_blur, FormLayoutUtil.flip(cc.xy(11, 27), colSpec, orientation));
    builder.add(mencoder_noass_subpos, FormLayoutUtil.flip(cc.xy(15, 27), colSpec, orientation));
    ass = new JCheckBox(Messages.getString("MEncoderVideo.20"), configuration.isMencoderAss());
    ass.setContentAreaFilled(false);
    ass.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e != null) {
                configuration.setMencoderAss(e.getStateChange() == ItemEvent.SELECTED);
            }
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(ass), FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation));
    ass.getItemListeners()[0].itemStateChanged(null);
    fc = new JCheckBox(Messages.getString("MEncoderVideo.21"), configuration.isMencoderFontConfig());
    fc.setContentAreaFilled(false);
    fc.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderFontConfig(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(fc), FormLayoutUtil.flip(cc.xyw(3, 23, 5), colSpec, orientation));
    builder.addLabel(Messages.getString("MEncoderVideo.92"), FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation));
    subq = new JTextField(configuration.getMencoderVobsubSubtitleQuality());
    subq.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setMencoderVobsubSubtitleQuality(subq.getText());
        }
    });
    builder.add(subq, FormLayoutUtil.flip(cc.xyw(3, 29, 1), colSpec, orientation));
    configuration.addConfigurationListener(new ConfigurationListener() {

        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (event.getPropertyName() == null) {
                return;
            }
            if ((!event.isBeforeUpdate()) && event.getPropertyName().equals(PmsConfiguration.KEY_DISABLE_SUBTITLES)) {
                boolean enabled = !configuration.isDisableSubtitles();
                ass.setEnabled(enabled);
                fc.setEnabled(enabled);
                mencoder_noass_scale.setEnabled(enabled);
                mencoder_noass_outline.setEnabled(enabled);
                mencoder_noass_blur.setEnabled(enabled);
                mencoder_noass_subpos.setEnabled(enabled);
                ocw.setEnabled(enabled);
                och.setEnabled(enabled);
                subq.setEnabled(enabled);
                if (enabled) {
                    ass.getItemListeners()[0].itemStateChanged(null);
                }
            }
        }
    });
    JPanel panel = builder.getPanel();
    // Apply the orientation to the panel and all components in it
    panel.applyComponentOrientation(orientation);
    return panel;
}
Also used : ConfigurationEvent(org.apache.commons.configuration.event.ConfigurationEvent) ConfigurationListener(org.apache.commons.configuration.event.ConfigurationListener) CellConstraints(com.jgoodies.forms.layout.CellConstraints) FormLayout(com.jgoodies.forms.layout.FormLayout) PanelBuilder(com.jgoodies.forms.builder.PanelBuilder) CustomJButton(net.pms.newgui.components.CustomJButton)

Aggregations

CustomJButton (net.pms.newgui.components.CustomJButton)14 PanelBuilder (com.jgoodies.forms.builder.PanelBuilder)6 CellConstraints (com.jgoodies.forms.layout.CellConstraints)6 FormLayout (com.jgoodies.forms.layout.FormLayout)6 File (java.io.File)6 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 IOException (java.io.IOException)4 Component (java.awt.Component)3 JComponent (javax.swing.JComponent)3 KeyedComboBoxModel (net.pms.util.KeyedComboBoxModel)3 ComponentOrientation (java.awt.ComponentOrientation)2 Dimension (java.awt.Dimension)2 FontMetrics (java.awt.FontMetrics)2 DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)2 TableColumn (javax.swing.table.TableColumn)2 BorderLayout (java.awt.BorderLayout)1 Font (java.awt.Font)1 GridLayout (java.awt.GridLayout)1 MouseEvent (java.awt.event.MouseEvent)1