Example usage for javax.swing JComponent getComponent

List of usage examples for javax.swing JComponent getComponent

Introduction

In this page you can find the example usage for javax.swing JComponent getComponent.

Prototype

public Component getComponent(int n) 

Source Link

Document

Gets the nth component in this container.

Usage

From source file:net.pms.newgui.NetworkTab.java

public JComponent build() {
    FormLayout layout = new FormLayout("left:pref, 2dlu, p, 2dlu , p, 2dlu, p, 2dlu, pref:grow",
            "p, 0dlu, p, 0dlu, p, 3dlu, p, 3dlu, p, 3dlu,p, 3dlu, p, 15dlu, p, 3dlu,p, 3dlu, p,  3dlu, p, 3dlu, p, 3dlu, p,3dlu, p, 3dlu, p, 15dlu, p,3dlu, p, 3dlu, p, 15dlu, p, 3dlu, p");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.DLU4_BORDER);
    builder.setOpaque(true);/*ww  w.  ja  v a  2 s . co  m*/

    CellConstraints cc = new CellConstraints();

    smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3"));
    smcheckBox.setContentAreaFilled(false);
    smcheckBox.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setMinimized((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    if (PMS.getConfiguration().isMinimized()) {
        smcheckBox.setSelected(true);
    }

    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(1, 1, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    builder.addLabel(Messages.getString("NetworkTab.0"), cc.xy(1, 7));
    final KeyedComboBoxModel kcbm = new KeyedComboBoxModel(
            new Object[] { "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "is", "it",
                    "ja", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv" },
            new Object[] { "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)", "Czech",
                    "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Icelandic",
                    "Italian", "Japanese", "Norwegian", "Polish", "Portuguese", "Portuguese (Brazilian)",
                    "Romanian", "Russian", "Slovenian", "Spanish", "Swedish" });
    langs = new JComboBox(kcbm);
    langs.setEditable(false);
    //langs.setSelectedIndex(0);
    String defaultLang = null;
    if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) {
        defaultLang = configuration.getLanguage();
    } else {
        defaultLang = Locale.getDefault().getLanguage();
    }
    if (defaultLang == null) {
        defaultLang = "en";
    }
    kcbm.setSelectedKey(defaultLang);
    if (langs.getSelectedIndex() == -1) {
        langs.setSelectedIndex(0);
    }

    langs.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setLanguage((String) kcbm.getSelectedKey());

            }
        }
    });
    builder.add(langs, cc.xyw(3, 7, 7));

    builder.add(smcheckBox, cc.xyw(1, 9, 9));

    JButton service = new JButton(Messages.getString("NetworkTab.4"));
    service.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.get().installWin32Service()) {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"),
                        "Information", JOptionPane.INFORMATION_MESSAGE);

            } else {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.14"), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    builder.add(service, cc.xy(1, 11));
    if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) {
        service.setEnabled(false);
    }

    host = new JTextField(PMS.getConfiguration().getServerHostname());
    host.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setHostname(host.getText());
            PMS.get().getFrame().setReloadable(true);
        }
    });
    // host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ;
    port = new JTextField(configuration.getServerPort() != 5001 ? "" + configuration.getServerPort() : "");
    port.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @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);
                PMS.get().getFrame().setReloadable(true);
            } catch (NumberFormatException nfe) {
            }

        }
    });

    cmp = builder.addSeparator(Messages.getString("NetworkTab.22"), cc.xyw(1, 21, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    ArrayList<String> names = new ArrayList<String>();
    names.add("");
    ArrayList<String> interfaces = new ArrayList<String>();
    interfaces.add("");
    Enumeration<NetworkInterface> enm;
    try {
        enm = NetworkInterface.getNetworkInterfaces();
        while (enm.hasMoreElements()) {
            NetworkInterface ni = enm.nextElement();
            // check for interface has at least one ip address.
            if (ni.getInetAddresses().hasMoreElements()) {
                names.add(ni.getName());
                String displayName = ni.getDisplayName();
                if (displayName == null) {
                    displayName = ni.getName();
                }
                interfaces.add(displayName.trim());
            }
        }
    } catch (SocketException e1) {
        logger.error(null, e1);
    }

    final KeyedComboBoxModel networkInterfaces = new KeyedComboBoxModel(names.toArray(), interfaces.toArray());
    networkinterfacesCBX = new JComboBox(networkInterfaces);
    networkInterfaces.setSelectedKey(configuration.getNetworkInterface());
    networkinterfacesCBX.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setNetworkInterface((String) networkInterfaces.getSelectedKey());
                //host.setEnabled( StringUtils.isBlank(configuration.getNetworkInterface())) ;
                PMS.get().getFrame().setReloadable(true);
            }
        }
    });

    ip_filter = new JTextField(PMS.getConfiguration().getIpFilter());
    ip_filter.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            configuration.setIpFilter(ip_filter.getText());
            PMS.get().getFrame().setReloadable(true);
        }
    });

    builder.addLabel(Messages.getString("NetworkTab.20"), cc.xy(1, 23));
    builder.add(networkinterfacesCBX, cc.xyw(3, 23, 7));
    builder.addLabel(Messages.getString("NetworkTab.23"), cc.xy(1, 25));
    builder.add(host, cc.xyw(3, 25, 7));
    builder.addLabel(Messages.getString("NetworkTab.24"), cc.xy(1, 27));
    builder.add(port, cc.xyw(3, 27, 7));
    builder.addLabel(Messages.getString("NetworkTab.30"), cc.xy(1, 29));
    builder.add(ip_filter, cc.xyw(3, 29, 7));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.31"), cc.xyw(1, 31, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32"));
    newHTTPEngine.setSelected(PMS.getConfiguration().isHTTPEngineV2());
    newHTTPEngine.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(newHTTPEngine, cc.xyw(1, 33, 9));

    preventSleep = new JCheckBox(Messages.getString("NetworkTab.33"));
    preventSleep.setSelected(PMS.getConfiguration().isPreventsSleep());
    preventSleep.addItemListener(new ItemListener() {

        public void itemStateChanged(ItemEvent e) {
            PMS.getConfiguration().setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(preventSleep, cc.xyw(1, 35, 9));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.34"), cc.xyw(1, 37, 9));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    JPanel panel = builder.getPanel();
    JScrollPane scrollPane = new JScrollPane(panel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    return scrollPane;
}

From source file:net.pms.encoders.AviSynthMEncoder.java

@Override
public JComponent config() {
    FormLayout layout = new FormLayout("left:pref, 0:grow",
            "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 12dlu, p, 3dlu, 0:grow");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.EMPTY);/*from w  ww.j  a v a  2s  .c  o m*/
    builder.opaque(false);

    CellConstraints cc = new CellConstraints();

    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"), cc.xyw(2, 1, 1));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    multithreading = new JCheckBox(Messages.getString("MEncoderVideo.35"),
            configuration.getAvisynthMultiThreading());
    multithreading.setContentAreaFilled(false);
    multithreading.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAvisynthMultiThreading((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(multithreading), cc.xy(2, 3));

    interframe = new JCheckBox(Messages.getString("AviSynthMEncoder.13"),
            configuration.getAvisynthInterFrame());
    interframe.setContentAreaFilled(false);
    interframe.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setAvisynthInterFrame(interframe.isSelected());
            if (configuration.getAvisynthInterFrame()) {
                JOptionPane.showMessageDialog(
                        SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame()),
                        Messages.getString("AviSynthMEncoder.16"), Messages.getString("Dialog.Information"),
                        JOptionPane.INFORMATION_MESSAGE);
            }
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(interframe), cc.xy(2, 5));

    interframegpu = new JCheckBox(Messages.getString("AviSynthMEncoder.15"),
            configuration.getAvisynthInterFrameGPU());
    interframegpu.setContentAreaFilled(false);
    interframegpu.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAvisynthInterFrameGPU((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(interframegpu), cc.xy(2, 7));

    convertfps = new JCheckBox(Messages.getString("AviSynthMEncoder.3"), configuration.getAvisynthConvertFps());
    convertfps.setContentAreaFilled(false);
    convertfps.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setAvisynthConvertFps((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(GuiUtil.getPreferredSizeComponent(convertfps), cc.xy(2, 9));

    String aviSynthScriptInstructions = Messages.getString("AviSynthMEncoder.4")
            + Messages.getString("AviSynthMEncoder.5") + Messages.getString("AviSynthMEncoder.6")
            + Messages.getString("AviSynthMEncoder.7") + Messages.getString("AviSynthMEncoder.8");
    JTextArea aviSynthScriptInstructionsContainer = new JTextArea(aviSynthScriptInstructions);
    aviSynthScriptInstructionsContainer.setEditable(false);
    aviSynthScriptInstructionsContainer.setBorder(BorderFactory.createEtchedBorder());
    aviSynthScriptInstructionsContainer.setBackground(new Color(255, 255, 192));
    aviSynthScriptInstructionsContainer.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(new Color(130, 135, 144)),
                    BorderFactory.createEmptyBorder(3, 5, 3, 5)));
    builder.add(aviSynthScriptInstructionsContainer, cc.xy(2, 11));

    String clip = configuration.getAvisynthScript();
    if (clip == null) {
        clip = "";
    }
    StringBuilder sb = new StringBuilder();
    StringTokenizer st = new StringTokenizer(clip, PMS.AVS_SEPARATOR);
    int i = 0;
    while (st.hasMoreTokens()) {
        if (i > 0) {
            sb.append("\n");
        }
        sb.append(st.nextToken());
        i++;
    }
    textArea = new JTextArea(sb.toString());
    textArea.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            StringBuilder sb = new StringBuilder();
            StringTokenizer st = new StringTokenizer(textArea.getText(), "\n");
            int i = 0;
            while (st.hasMoreTokens()) {
                if (i > 0) {
                    sb.append(PMS.AVS_SEPARATOR);
                }
                sb.append(st.nextToken());
                i++;
            }
            configuration.setAvisynthScript(sb.toString());
        }
    });

    JScrollPane pane = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    pane.setPreferredSize(new Dimension(500, 350));
    builder.add(pane, cc.xy(2, 13));

    configuration.addConfigurationListener(new ConfigurationListener() {
        @Override
        public void configurationChanged(ConfigurationEvent event) {
            if (event.getPropertyName() == null) {
                return;
            }
            if ((!event.isBeforeUpdate())
                    && event.getPropertyName().equals(PmsConfiguration.KEY_GPU_ACCELERATION)) {
                interframegpu.setEnabled(configuration.isGPUAcceleration());
            }
        }
    });

    return builder.getPanel();
}

From source file:net.pms.newgui.StatusTab.java

public JComponent build() {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());

    String colSpec = FormLayoutUtil.getColSpec("pref, 30dlu, fill:pref:grow, 30dlu, pref", orientation);
    //                                             1     2          3           4     5

    FormLayout layout = new FormLayout(colSpec,
            //                          1     2          3            4     5
            //                   //////////////////////////////////////////////////
            "p," // Detected Media Renderers --------------------//  1
                    + "9dlu," //                                              //
                    + "fill:p:grow," //                 <renderers>                  //  3
                    + "3dlu," //                                              //
                    + "p," // ---------------------------------------------//  5
                    + "3dlu," //           |                       |          //
                    + "p," // Connected |  Memory Usage         |<bitrate> //  7
                    + "3dlu," //           |                       |          //
                    + "p," //  <icon>   |  <statusbar>          |          //  9
                           //////////////////////////////////////////////////
    );//from w  w  w  .  ja v  a2s . c o m

    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DIALOG);
    builder.opaque(true);
    CellConstraints cc = new CellConstraints();

    // Renderers
    JComponent cmp = builder.addSeparator(Messages.getString("StatusTab.9"),
            FormLayoutUtil.flip(cc.xyw(1, 1, 5), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    Font bold = cmp.getFont().deriveFont(Font.BOLD);
    Color fgColor = new Color(68, 68, 68);
    cmp.setFont(bold);

    renderers = new JPanel(new GuiUtil.WrapLayout(FlowLayout.CENTER, 20, 10));
    JScrollPane rsp = new JScrollPane(renderers, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    rsp.setBorder(BorderFactory.createEmptyBorder());
    rsp.setPreferredSize(new Dimension(0, 260));
    rsp.getHorizontalScrollBar().setLocation(0, 250);

    builder.add(rsp, cc.xyw(1, 3, 5));

    cmp = builder.addSeparator(null, FormLayoutUtil.flip(cc.xyw(1, 5, 5), colSpec, orientation));

    // Connected
    jl = new JLabel(Messages.getString("StatusTab.3"));
    builder.add(jl, FormLayoutUtil.flip(cc.xy(1, 7, "center, top"), colSpec, orientation));
    jl.setFont(bold);
    jl.setForeground(fgColor);

    imagePanel = buildImagePanel("/resources/images/icon-status-connecting.png");
    builder.add(imagePanel, FormLayoutUtil.flip(cc.xy(1, 9), colSpec, orientation));

    // Memory
    memBarUI = new GuiUtil.SegmentedProgressBarUI(Color.white, Color.gray);
    memBarUI.setActiveLabel("{}", Color.white, 0);
    memBarUI.setActiveLabel("{}", Color.red, 90);
    memBarUI.addSegment("", memColor);
    memBarUI.addSegment("", bufColor);
    memBarUI.setTickMarks(getTickMarks(), "{}");
    memoryProgressBar = new GuiUtil.CustomUIProgressBar(0, 100, memBarUI);
    memoryProgressBar.setStringPainted(true);
    memoryProgressBar.setForeground(new Color(75, 140, 181));
    memoryProgressBar.setString(Messages.getString("StatusTab.5"));

    JLabel mem = builder
            .addLabel(
                    "<html><b>" + Messages.getString("StatusTab.6") + "</b> ("
                            + Messages.getString("StatusTab.12") + ")</html>",
                    FormLayoutUtil.flip(cc.xy(3, 7), colSpec, orientation));
    mem.setForeground(fgColor);
    builder.add(memoryProgressBar, FormLayoutUtil.flip(cc.xyw(3, 9, 1), colSpec, orientation));

    // Bitrate
    String bitColSpec = "left:pref, 3dlu, right:pref:grow";
    PanelBuilder bitrateBuilder = new PanelBuilder(new FormLayout(bitColSpec, "p, 1dlu, p, 1dlu, p"));

    bitrateLabel = new JLabel("<html><b>" + Messages.getString("StatusTab.13") + "</b> ("
            + Messages.getString("StatusTab.11") + ")</html>");
    bitrateLabel.setForeground(fgColor);
    bitrateBuilder.add(bitrateLabel, FormLayoutUtil.flip(cc.xy(1, 1), bitColSpec, orientation));

    currentBitrateLabel = new JLabel(Messages.getString("StatusTab.14"));
    currentBitrateLabel.setForeground(fgColor);
    bitrateBuilder.add(currentBitrateLabel, FormLayoutUtil.flip(cc.xy(1, 3), bitColSpec, orientation));

    currentBitrate = new JLabel("0");
    currentBitrate.setForeground(fgColor);
    bitrateBuilder.add(currentBitrate, FormLayoutUtil.flip(cc.xy(3, 3), bitColSpec, orientation));

    peakBitrateLabel = new JLabel(Messages.getString("StatusTab.15"));
    peakBitrateLabel.setForeground(fgColor);
    bitrateBuilder.add(peakBitrateLabel, FormLayoutUtil.flip(cc.xy(1, 5), bitColSpec, orientation));

    peakBitrate = new JLabel("0");
    peakBitrate.setForeground(fgColor);
    bitrateBuilder.add(peakBitrate, FormLayoutUtil.flip(cc.xy(3, 5), bitColSpec, orientation));

    builder.add(bitrateBuilder.getPanel(),
            FormLayoutUtil.flip(cc.xywh(5, 7, 1, 3, "left, top"), colSpec, orientation));

    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_NEVER,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    startMemoryUpdater();
    return scrollPane;
}

From source file:net.pms.newgui.GeneralTab.java

public JComponent build() {
    // Apply the orientation for the locale
    Locale locale = new Locale(configuration.getLanguage());
    ComponentOrientation orientation = ComponentOrientation.getOrientation(locale);
    String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation);

    FormLayout layout = new FormLayout(colSpec, ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.DLU4_BORDER);
    builder.setOpaque(true);/*from   w w w.  j  a  v  a 2s  .  c om*/

    CellConstraints cc = new CellConstraints();

    smcheckBox = new JCheckBox(Messages.getString("NetworkTab.3"));
    smcheckBox.setContentAreaFilled(false);
    smcheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            configuration.setMinimized((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    if (configuration.isMinimized()) {
        smcheckBox.setSelected(true);
    }

    JComponent cmp = builder.addSeparator(Messages.getString("NetworkTab.5"),
            FormLayoutUtil.flip(cc.xyw(1, 1, 9), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));
    builder.addLabel(Messages.getString("NetworkTab.0"),
            FormLayoutUtil.flip(cc.xy(1, 7), colSpec, orientation));
    final KeyedComboBoxModel kcbm = new KeyedComboBoxModel(
            new Object[] { "ar", "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "fi", "fr", "de", "el", "iw",
                    "is", "it", "ja", "ko", "no", "pl", "pt", "br", "ro", "ru", "sl", "es", "sv", "tr" },
            new Object[] { "Arabic", "Bulgarian", "Catalan", "Chinese (Simplified)", "Chinese (Traditional)",
                    "Czech", "Danish", "Dutch", "English", "Finnish", "French", "German", "Greek", "Hebrew",
                    "Icelandic", "Italian", "Japanese", "Korean", "Norwegian", "Polish", "Portuguese",
                    "Portuguese (Brazilian)", "Romanian", "Russian", "Slovenian", "Spanish", "Swedish",
                    "Turkish" });
    langs = new JComboBox(kcbm);
    langs.setEditable(false);
    String defaultLang = null;
    if (configuration.getLanguage() != null && configuration.getLanguage().length() > 0) {
        defaultLang = configuration.getLanguage();
    } else {
        defaultLang = Locale.getDefault().getLanguage();
    }
    if (defaultLang == null) {
        defaultLang = "en";
    }
    kcbm.setSelectedKey(defaultLang);
    if (langs.getSelectedIndex() == -1) {
        langs.setSelectedIndex(0);
    }

    langs.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                configuration.setLanguage((String) kcbm.getSelectedKey());

            }
        }
    });

    builder.add(langs, FormLayoutUtil.flip(cc.xyw(3, 7, 7), colSpec, orientation));

    builder.add(smcheckBox, FormLayoutUtil.flip(cc.xyw(1, 9, 9), colSpec, orientation));

    JButton service = new JButton(Messages.getString("NetworkTab.4"));
    service.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (PMS.get().installWin32Service()) {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.11") + Messages.getString("NetworkTab.12"),
                        Messages.getString("Dialog.Information"), JOptionPane.INFORMATION_MESSAGE);

            } else {
                JOptionPane.showMessageDialog(
                        (JFrame) (SwingUtilities.getWindowAncestor((Component) PMS.get().getFrame())),
                        Messages.getString("NetworkTab.14"), Messages.getString("Dialog.Error"),
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    });

    builder.add(service, FormLayoutUtil.flip(cc.xy(1, 11), colSpec, orientation));

    if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) {
        service.setEnabled(false);
    }

    JButton checkForUpdates = new JButton(Messages.getString("NetworkTab.8"));

    checkForUpdates.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            LooksFrame frame = (LooksFrame) PMS.get().getFrame();
            frame.checkForUpdates();
        }
    });

    builder.add(checkForUpdates, FormLayoutUtil.flip(cc.xy(1, 13), colSpec, orientation));

    autoUpdateCheckBox = new JCheckBox(Messages.getString("NetworkTab.9"));
    autoUpdateCheckBox.setContentAreaFilled(false);
    autoUpdateCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            configuration.setAutoUpdate((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    if (configuration.isAutoUpdate()) {
        autoUpdateCheckBox.setSelected(true);
    }

    builder.add(autoUpdateCheckBox, FormLayoutUtil.flip(cc.xyw(7, 13, 3), colSpec, orientation));

    if (!Build.isUpdatable()) {
        checkForUpdates.setEnabled(false);
        autoUpdateCheckBox.setEnabled(false);
    }

    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.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, 21, 9), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    final KeyedComboBoxModel networkInterfaces = createNetworkInterfacesModel();
    networkinterfacesCBX = new JComboBox(networkInterfaces);
    networkInterfaces.setSelectedKey(configuration.getNetworkInterface());
    networkinterfacesCBX.addItemListener(new ItemListener() {
        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.getMaximumBitrate());
    maxbitrate.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            PMS.getConfiguration().setMaximumBitrate(maxbitrate.getText());
        }
    });

    builder.addLabel(Messages.getString("NetworkTab.20"),
            FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation));
    builder.add(networkinterfacesCBX, FormLayoutUtil.flip(cc.xyw(3, 23, 7), colSpec, orientation));
    builder.addLabel(Messages.getString("NetworkTab.23"),
            FormLayoutUtil.flip(cc.xy(1, 25), colSpec, orientation));
    builder.add(host, FormLayoutUtil.flip(cc.xyw(3, 25, 7), colSpec, orientation));
    builder.addLabel(Messages.getString("NetworkTab.24"),
            FormLayoutUtil.flip(cc.xy(1, 27), colSpec, orientation));
    builder.add(port, FormLayoutUtil.flip(cc.xyw(3, 27, 7), colSpec, orientation));
    builder.addLabel(Messages.getString("NetworkTab.30"),
            FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation));
    builder.add(ip_filter, FormLayoutUtil.flip(cc.xyw(3, 29, 7), colSpec, orientation));
    builder.addLabel(Messages.getString("NetworkTab.35"),
            FormLayoutUtil.flip(cc.xy(1, 31), colSpec, orientation));
    builder.add(maxbitrate, FormLayoutUtil.flip(cc.xyw(3, 31, 7), colSpec, orientation));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.31"),
            FormLayoutUtil.flip(cc.xyw(1, 33, 9), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    newHTTPEngine = new JCheckBox(Messages.getString("NetworkTab.32"));
    newHTTPEngine.setSelected(configuration.isHTTPEngineV2());
    newHTTPEngine.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            configuration.setHTTPEngineV2((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(newHTTPEngine, FormLayoutUtil.flip(cc.xyw(1, 35, 9), colSpec, orientation));

    preventSleep = new JCheckBox(Messages.getString("NetworkTab.33"));
    preventSleep.setSelected(configuration.isPreventsSleep());
    preventSleep.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            configuration.setPreventsSleep((e.getStateChange() == ItemEvent.SELECTED));
        }
    });
    builder.add(preventSleep, FormLayoutUtil.flip(cc.xyw(1, 37, 9), colSpec, orientation));

    JCheckBox fdCheckBox = new JCheckBox(Messages.getString("NetworkTab.38"));
    fdCheckBox.setContentAreaFilled(false);
    fdCheckBox.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            configuration.setRendererForceDefault((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    if (configuration.isRendererForceDefault()) {
        fdCheckBox.setSelected(true);
    }

    builder.addLabel(Messages.getString("NetworkTab.36"),
            FormLayoutUtil.flip(cc.xy(1, 39), colSpec, orientation));

    ArrayList<RendererConfiguration> allConfs = RendererConfiguration.getAllRendererConfigurations();
    ArrayList<Object> keyValues = new ArrayList<Object>();
    ArrayList<Object> nameValues = new ArrayList<Object>();
    keyValues.add("");
    nameValues.add(Messages.getString("NetworkTab.37"));

    if (allConfs != null) {
        for (RendererConfiguration renderer : allConfs) {
            if (renderer != null) {
                keyValues.add(renderer.getRendererName());
                nameValues.add(renderer.getRendererName());
            }
        }
    }

    final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel(
            (Object[]) keyValues.toArray(new Object[keyValues.size()]),
            (Object[]) nameValues.toArray(new Object[nameValues.size()]));
    renderers = new JComboBox(renderersKcbm);
    renderers.setEditable(false);
    String defaultRenderer = configuration.getRendererDefault();
    renderersKcbm.setSelectedKey(defaultRenderer);

    if (renderers.getSelectedIndex() == -1) {
        renderers.setSelectedIndex(0);
    }

    builder.add(renderers, FormLayoutUtil.flip(cc.xyw(3, 39, 7), colSpec, orientation));

    builder.add(fdCheckBox, FormLayoutUtil.flip(cc.xyw(1, 41, 9), colSpec, orientation));

    cmp = builder.addSeparator(Messages.getString("NetworkTab.34"),
            FormLayoutUtil.flip(cc.xyw(1, 43, 9), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    pPlugins = new JPanel(new GridLayout());
    builder.add(pPlugins, FormLayoutUtil.flip(cc.xyw(1, 45, 9), colSpec, orientation));

    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);

    return scrollPane;
}

From source file:net.pms.encoders.TsMuxeRVideo.java

@Override
public JComponent config() {
    // Apply the orientation for the locale
    Locale locale = new Locale(configuration.getLanguage());
    ComponentOrientation orientation = ComponentOrientation.getOrientation(locale);
    String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation);
    FormLayout layout = new FormLayout(colSpec, ROW_SPEC);

    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.EMPTY_BORDER);
    builder.setOpaque(false);/*from   www.  ja va 2  s. c o m*/

    CellConstraints cc = new CellConstraints();

    JComponent cmp = builder.addSeparator(Messages.getString("TSMuxerVideo.3"),
            FormLayoutUtil.flip(cc.xyw(2, 1, 1), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    tsmuxerforcefps = new JCheckBox(Messages.getString("TSMuxerVideo.2"));
    tsmuxerforcefps.setContentAreaFilled(false);
    if (configuration.isTsmuxerForceFps()) {
        tsmuxerforcefps.setSelected(true);
    }
    tsmuxerforcefps.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setTsmuxerForceFps(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(tsmuxerforcefps, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));

    muxallaudiotracks = new JCheckBox(Messages.getString("TSMuxerVideo.19"));
    muxallaudiotracks.setContentAreaFilled(false);
    if (configuration.isMuxAllAudioTracks()) {
        muxallaudiotracks.setSelected(true);
    }

    muxallaudiotracks.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMuxAllAudioTracks(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(muxallaudiotracks, FormLayoutUtil.flip(cc.xy(2, 5), colSpec, orientation));

    JPanel panel = builder.getPanel();

    // Apply the orientation to the panel and all components in it
    panel.applyComponentOrientation(orientation);

    return panel;
}

From source file:net.pms.encoders.FFmpegVideo.java

protected JComponent config(String languageLabel) {
    FormLayout layout = new FormLayout("left:pref, 0:grow", "p, 3dlu, p, 3dlu, p, 3dlu, p");
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.EMPTY_BORDER);
    builder.setOpaque(false);/*from  ww w .  j a  v a2 s. co m*/

    CellConstraints cc = new CellConstraints();

    JComponent cmp = builder.addSeparator(Messages.getString(languageLabel), cc.xyw(2, 1, 1));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    multiThreadingCheckBox = new JCheckBox(Messages.getString("MEncoderVideo.35"));
    multiThreadingCheckBox.setContentAreaFilled(false);
    if (configuration.isFfmpegMultithreading()) {
        multiThreadingCheckBox.setSelected(true);
    }
    multiThreadingCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setFfmpegMultithreading(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(multiThreadingCheckBox, cc.xy(2, 3));

    videoRemuxCheckBox = new JCheckBox(Messages.getString("FFmpeg.0"));
    videoRemuxCheckBox.setContentAreaFilled(false);
    if (configuration.isFFmpegMuxWhenCompatible()) {
        videoRemuxCheckBox.setSelected(true);
    }
    videoRemuxCheckBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setFFmpegMuxWhenCompatible(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(videoRemuxCheckBox, cc.xy(2, 5));

    return builder.getPanel();
}

From source file:net.pms.newgui.NavigationShareTab.java

public JComponent build() {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(PANEL_COL_SPEC, orientation);

    // Set basic layout
    FormLayout layout = new FormLayout(colSpec, PANEL_ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.border(Borders.DLU4);/*from  w  w w  . j  a va 2  s  .co m*/
    builder.opaque(true);

    CellConstraints cc = new CellConstraints();

    // Init all gui components
    initSimpleComponents(cc);
    sharedPanel = initSharedFoldersGuiComponents(cc).build();

    // Build gui with initialized components
    if (!configuration.isHideAdvancedOptions()) {
        JComponent cmp = builder.addSeparator(Messages.getString("FoldTab.13"),
                FormLayoutUtil.flip(cc.xyw(1, 1, 12), colSpec, orientation));
        cmp = (JComponent) cmp.getComponent(0);
        cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

        builder.add(GuiUtil.getPreferredSizeComponent(thumbgenCheckBox),
                FormLayoutUtil.flip(cc.xyw(1, 3, 3), colSpec, orientation));
        builder.addLabel(Messages.getString("NetworkTab.16"),
                FormLayoutUtil.flip(cc.xyw(4, 3, 2), colSpec, orientation));
        builder.add(seekpos, FormLayoutUtil.flip(cc.xy(6, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(image_thumb),
                FormLayoutUtil.flip(cc.xyw(9, 3, 4), colSpec, orientation));

        builder.addLabel(Messages.getString("FoldTab.26"),
                FormLayoutUtil.flip(cc.xyw(1, 5, 3), colSpec, orientation));
        builder.add(audiothumbnail, FormLayoutUtil.flip(cc.xyw(4, 5, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(mplayer_thumb),
                FormLayoutUtil.flip(cc.xyw(9, 5, 4), colSpec, orientation));

        builder.addLabel(Messages.getString("FoldTab.27"),
                FormLayoutUtil.flip(cc.xy(1, 7), colSpec, orientation));
        builder.add(defaultThumbFolder, FormLayoutUtil.flip(cc.xyw(4, 7, 2), colSpec, orientation));
        builder.add(select, FormLayoutUtil.flip(cc.xy(6, 7), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(dvdiso_thumb),
                FormLayoutUtil.flip(cc.xyw(9, 7, 4), colSpec, orientation));

        cmp = builder.addSeparator(Messages.getString("NetworkTab.59"),
                FormLayoutUtil.flip(cc.xyw(1, 9, 12), colSpec, orientation));
        cmp = (JComponent) cmp.getComponent(0);
        cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

        builder.addLabel(Messages.getString("FoldTab.18"),
                FormLayoutUtil.flip(cc.xyw(1, 11, 3), colSpec, orientation));
        builder.add(sortmethod, FormLayoutUtil.flip(cc.xyw(4, 11, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(ignorethewordthe),
                FormLayoutUtil.flip(cc.xyw(9, 11, 4), colSpec, orientation));

        builder.add(GuiUtil.getPreferredSizeComponent(prettifyfilenames),
                FormLayoutUtil.flip(cc.xyw(1, 13, 5), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(episodeTitles),
                FormLayoutUtil.flip(cc.xyw(9, 13, 4), colSpec, orientation));

        cmp = builder.addSeparator(Messages.getString("NetworkTab.60"),
                FormLayoutUtil.flip(cc.xyw(1, 15, 12), colSpec, orientation));
        cmp = (JComponent) cmp.getComponent(0);
        cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

        builder.add(GuiUtil.getPreferredSizeComponent(hideextensions),
                FormLayoutUtil.flip(cc.xyw(1, 17, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(hideengines),
                FormLayoutUtil.flip(cc.xyw(4, 17, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(hideemptyfolders),
                FormLayoutUtil.flip(cc.xyw(9, 17, 4), colSpec, orientation));

        builder.add(GuiUtil.getPreferredSizeComponent(itunes),
                FormLayoutUtil.flip(cc.xy(1, 19), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(iphoto),
                FormLayoutUtil.flip(cc.xyw(4, 19, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(aperture),
                FormLayoutUtil.flip(cc.xyw(9, 19, 4), colSpec, orientation));

        builder.add(GuiUtil.getPreferredSizeComponent(cacheenable),
                FormLayoutUtil.flip(cc.xy(1, 21), colSpec, orientation));
        builder.add(cachereset, FormLayoutUtil.flip(cc.xyw(4, 21, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderMediaLibrary),
                FormLayoutUtil.flip(cc.xyw(9, 21, 4), colSpec, orientation));

        builder.add(GuiUtil.getPreferredSizeComponent(archive),
                FormLayoutUtil.flip(cc.xyw(1, 23, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderServerSettings),
                FormLayoutUtil.flip(cc.xyw(4, 23, 3), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderTranscode),
                FormLayoutUtil.flip(cc.xyw(9, 23, 4), colSpec, orientation));

        builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderLiveSubtitles),
                FormLayoutUtil.flip(cc.xyw(1, 25, 3), colSpec, orientation));
        builder.addLabel(Messages.getString("FoldTab.37"),
                FormLayoutUtil.flip(cc.xyw(4, 25, 2), colSpec, orientation));
        builder.add(atzLimit, FormLayoutUtil.flip(cc.xy(6, 25), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderNewMedia),
                FormLayoutUtil.flip(cc.xyw(9, 25, 4), colSpec, orientation));

        builder.add(GuiUtil.getPreferredSizeComponent(resume),
                FormLayoutUtil.flip(cc.xy(1, 27), colSpec, orientation));
        builder.add(GuiUtil.getPreferredSizeComponent(isShowFolderRecentlyPlayed),
                FormLayoutUtil.flip(cc.xyw(9, 27, 4), colSpec, orientation));

        builder.addLabel(Messages.getString("FoldTab.72"),
                FormLayoutUtil.flip(cc.xy(1, 29), colSpec, orientation));
        builder.add(fullyPlayedAction, FormLayoutUtil.flip(cc.xyw(4, 29, 3), colSpec, orientation));
        builder.add(fullyPlayedOutputDirectory, FormLayoutUtil.flip(cc.xyw(9, 29, 2), colSpec, orientation));
        builder.add(selectFullyPlayedOutputDirectory,
                FormLayoutUtil.flip(cc.xyw(11, 29, 2), colSpec, orientation));

        builder.add(sharedPanel, FormLayoutUtil.flip(cc.xyw(1, 31, 12), colSpec, orientation));
    } else {
        builder.add(sharedPanel, FormLayoutUtil.flip(cc.xyw(1, 1, 12), colSpec, orientation));
    }

    builder.add(sharedPanel, FormLayoutUtil.flip(cc.xyw(1, 31, 12), colSpec, orientation));

    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;
}

From source file:net.pms.newgui.NavigationShareTab.java

private PanelBuilder initSharedFoldersGuiComponents(CellConstraints cc) {
    // Apply the orientation for the locale
    ComponentOrientation orientation = ComponentOrientation.getOrientation(PMS.getLocale());
    String colSpec = FormLayoutUtil.getColSpec(SHARED_FOLDER_COL_SPEC, orientation);

    FormLayout layoutFolders = new FormLayout(colSpec, SHARED_FOLDER_ROW_SPEC);
    PanelBuilder builderFolder = new PanelBuilder(layoutFolders);
    builderFolder.opaque(true);/*from w w w  . ja  v  a 2  s .  com*/

    JComponent cmp = builderFolder.addSeparator(Messages.getString("FoldTab.7"),
            FormLayoutUtil.flip(cc.xyw(1, 1, 7), colSpec, orientation));
    cmp = (JComponent) cmp.getComponent(0);
    cmp.setFont(cmp.getFont().deriveFont(Font.BOLD));

    folderTableModel = new SharedFoldersTableModel();
    sharedFolders = new JTable(folderTableModel);

    JPopupMenu popupMenu = new JPopupMenu();
    JMenuItem menuItemMarkPlayed = new JMenuItem(Messages.getString("FoldTab.75"));
    JMenuItem menuItemMarkUnplayed = new JMenuItem(Messages.getString("FoldTab.76"));

    menuItemMarkPlayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, true);
        }
    });

    menuItemMarkUnplayed.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String path = (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0);
            TableFilesStatus.setDirectoryFullyPlayed(path, false);
        }
    });

    popupMenu.add(menuItemMarkPlayed);
    popupMenu.add(menuItemMarkUnplayed);

    sharedFolders.setComponentPopupMenu(popupMenu);

    /* An attempt to set the correct row height adjusted for font scaling.
     * It sets all rows based on the font size of cell (0, 0). The + 4 is
     * to allow 2 pixels above and below the text. */
    DefaultTableCellRenderer cellRenderer = (DefaultTableCellRenderer) sharedFolders.getCellRenderer(0, 0);
    FontMetrics metrics = cellRenderer.getFontMetrics(cellRenderer.getFont());
    sharedFolders.setRowHeight(metrics.getLeading() + metrics.getMaxAscent() + metrics.getMaxDescent() + 4);
    sharedFolders.setIntercellSpacing(new Dimension(8, 2));

    final JPanel tmpsharedPanel = sharedPanel;

    addButton.setToolTipText(Messages.getString("FoldTab.9"));
    addButton.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.showOpenDialog((Component) e.getSource());
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                int firstSelectedRow = sharedFolders.getSelectedRow();
                if (firstSelectedRow >= 0) {
                    ((SharedFoldersTableModel) sharedFolders.getModel()).insertRow(firstSelectedRow,
                            new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                } else {
                    ((SharedFoldersTableModel) sharedFolders.getModel())
                            .addRow(new Object[] { chooser.getSelectedFile().getAbsolutePath(), true });
                }
            }
        }
    });
    builderFolder.add(addButton, FormLayoutUtil.flip(cc.xy(2, 3), colSpec, orientation));

    removeButton.setToolTipText(Messages.getString("FoldTab.36"));
    removeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int[] rows = sharedFolders.getSelectedRows();
            if (rows.length > 0) {
                if (rows.length > 1) {
                    if (JOptionPane.showConfirmDialog(tmpsharedPanel,
                            String.format(Messages.getString("SharedFolders.ConfirmRemove"), rows.length),
                            Messages.getString("Dialog.Confirm"), JOptionPane.YES_NO_OPTION,
                            JOptionPane.WARNING_MESSAGE) != JOptionPane.YES_OPTION) {
                        return;
                    }
                }
                for (int i = rows.length - 1; i >= 0; i--) {
                    PMS.get().getDatabase().removeMediaEntriesInFolder(
                            (String) sharedFolders.getValueAt(sharedFolders.getSelectedRow(), 0));
                    ((SharedFoldersTableModel) sharedFolders.getModel()).removeRow(rows[i]);
                }
            }
        }
    });
    builderFolder.add(removeButton, FormLayoutUtil.flip(cc.xy(3, 3), colSpec, orientation));

    arrowDownButton.setToolTipText(Messages.getString("SharedFolders.ArrowDown"));
    arrowDownButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 0; i < sharedFolders.getRowCount() - 1; i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i + 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i + 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i + 1, 1);
                    sharedFolders.changeSelection(i + 1, 1, false, false);

                    break;
                }
            }
        }
    });
    builderFolder.add(arrowDownButton, FormLayoutUtil.flip(cc.xy(4, 3), colSpec, orientation));

    arrowUpButton.setToolTipText(Messages.getString("SharedFolders.ArrowUp"));
    arrowUpButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            for (int i = 1; i < sharedFolders.getRowCount(); i++) {
                if (sharedFolders.isRowSelected(i)) {
                    Object value1 = sharedFolders.getValueAt(i, 0);
                    boolean value2 = (boolean) sharedFolders.getValueAt(i, 1);

                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 0), i, 0);
                    sharedFolders.setValueAt(value1, i - 1, 0);
                    sharedFolders.setValueAt(sharedFolders.getValueAt(i - 1, 1), i, 1);
                    sharedFolders.setValueAt(value2, i - 1, 1);
                    sharedFolders.changeSelection(i - 1, 1, false, false);

                    break;

                }
            }
        }
    });
    builderFolder.add(arrowUpButton, FormLayoutUtil.flip(cc.xy(5, 3), colSpec, orientation));

    scanButton.setToolTipText(Messages.getString("FoldTab.2"));
    scanBusyIcon.start();
    scanBusyDisabledIcon.start();
    scanButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (configuration.getUseCache()) {
                DLNAMediaDatabase database = PMS.get().getDatabase();

                if (database != null) {
                    if (database.isScanLibraryRunning()) {
                        int option = JOptionPane.showConfirmDialog(looksFrame, Messages.getString("FoldTab.10"),
                                Messages.getString("Dialog.Question"), JOptionPane.YES_NO_OPTION);
                        if (option == JOptionPane.YES_OPTION) {
                            database.stopScanLibrary();
                            looksFrame.setStatusLine(Messages.getString("FoldTab.41"));
                            scanButton.setEnabled(false);
                            scanButton.setToolTipText(Messages.getString("FoldTab.41"));
                        }
                    } else {
                        database.scanLibrary();
                        scanButton.setIcon(scanBusyIcon);
                        scanButton.setRolloverIcon(scanBusyRolloverIcon);
                        scanButton.setPressedIcon(scanBusyPressedIcon);
                        scanButton.setDisabledIcon(scanBusyDisabledIcon);
                        scanButton.setToolTipText(Messages.getString("FoldTab.40"));
                    }
                }
            }
        }
    });

    /*
     * Hide the scan button in basic mode since it's better to let it be done in
     * realtime.
     */
    if (!configuration.isHideAdvancedOptions()) {
        builderFolder.add(scanButton, FormLayoutUtil.flip(cc.xy(6, 3), colSpec, orientation));
    }

    scanButton.setEnabled(configuration.getUseCache());

    isScanSharedFoldersOnStartup = new JCheckBox(Messages.getString("NetworkTab.StartupScan"),
            configuration.isScanSharedFoldersOnStartup());
    isScanSharedFoldersOnStartup.setToolTipText(Messages.getString("NetworkTab.StartupScanTooltip"));
    isScanSharedFoldersOnStartup.setContentAreaFilled(false);
    isScanSharedFoldersOnStartup.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setScanSharedFoldersOnStartup((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    builderFolder.add(isScanSharedFoldersOnStartup, FormLayoutUtil.flip(cc.xy(7, 3), colSpec, orientation));

    updateSharedFolders();

    JScrollPane pane = new JScrollPane(sharedFolders);
    Dimension d = sharedFolders.getPreferredSize();
    pane.setPreferredSize(new Dimension(d.width, sharedFolders.getRowHeight() * 2));
    builderFolder.add(pane, FormLayoutUtil.flip(cc.xyw(1, 5, 7, CellConstraints.DEFAULT, CellConstraints.FILL),
            colSpec, orientation));

    return builderFolder;
}

From source file:net.pms.encoders.MEncoderVideo.java

@Override
public JComponent config() {
    // Apply the orientation for the locale
    Locale locale = new Locale(configuration.getLanguage());
    ComponentOrientation orientation = ComponentOrientation.getOrientation(locale);
    String colSpec = FormLayoutUtil.getColSpec(COL_SPEC, orientation);

    FormLayout layout = new FormLayout(colSpec, ROW_SPEC);
    PanelBuilder builder = new PanelBuilder(layout);
    builder.setBorder(Borders.EMPTY_BORDER);
    builder.setOpaque(false);//from w w w .j  av a 2s.  c  o  m

    CellConstraints cc = new CellConstraints();

    checkBox = new JCheckBox(Messages.getString("MEncoderVideo.0"));
    checkBox.setContentAreaFilled(false);

    if (configuration.getSkipLoopFilterEnabled()) {
        checkBox.setSelected(true);
    }

    checkBox.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setSkipLoopFilterEnabled((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    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"));
    mencodermt.setContentAreaFilled(false);

    if (configuration.getMencoderMT()) {
        mencodermt.setSelected(true);
    }

    mencodermt.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            configuration.setMencoderMT(mencodermt.isSelected());
        }
    });

    mencodermt.setEnabled(Platform.isWindows() || Platform.isMac());

    builder.add(mencodermt, FormLayoutUtil.flip(cc.xy(1, 3), colSpec, orientation));
    builder.add(checkBox, FormLayoutUtil.flip(cc.xyw(3, 3, 12), colSpec, orientation));

    noskip = new JCheckBox(Messages.getString("MEncoderVideo.2"));
    noskip.setContentAreaFilled(false);

    if (configuration.isMencoderNoOutOfSync()) {
        noskip.setSelected(true);
    }

    noskip.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderNoOutOfSync((e.getStateChange() == ItemEvent.SELECTED));
        }
    });

    builder.add(noskip, FormLayoutUtil.flip(cc.xy(1, 5), colSpec, orientation));

    JButton button = new JButton(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 java.awt.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 java.awt.Dimension(900, 450));

            JPanel customPanel = new JPanel(new BorderLayout());
            intelligentsync = new JCheckBox(Messages.getString("MEncoderVideo.3"));
            intelligentsync.setContentAreaFilled(false);

            if (configuration.isMencoderIntelligentSync()) {
                intelligentsync.setSelected(true);
            }

            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"));
    forcefps.setContentAreaFilled(false);
    if (configuration.isMencoderForceFps()) {
        forcefps.setSelected(true);
    }
    forcefps.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderForceFps(e.getStateChange() == ItemEvent.SELECTED);
        }
    });

    builder.add(forcefps, FormLayoutUtil.flip(cc.xyw(1, 7, 2), colSpec, orientation));

    yadif = new JCheckBox(Messages.getString("MEncoderVideo.26"));
    yadif.setContentAreaFilled(false);
    if (configuration.isMencoderYadif()) {
        yadif.setSelected(true);
    }
    yadif.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderYadif(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(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(scaler, FormLayoutUtil.flip(cc.xyw(3, 5, 7), 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);
    }

    builder.addLabel(Messages.getString("MEncoderVideo.6"),
            FormLayoutUtil.flip(cc.xy(1, 13), 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, 13, 13), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.93"),
            FormLayoutUtil.flip(cc.xy(1, 15), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.28") + " (%)", FormLayoutUtil
            .flip(cc.xy(1, 15, 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, 15), colSpec, orientation));

    builder.addLabel(Messages.getString("MEncoderVideo.30") + " (%)",
            FormLayoutUtil.flip(cc.xy(5, 15), 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, 15), colSpec, orientation));

    cmp = builder.addSeparator(Messages.getString("MEncoderVideo.8"),
            FormLayoutUtil.flip(cc.xyw(1, 17, 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, 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"));
    ass.setContentAreaFilled(false);
    ass.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            if (e != null) {
                configuration.setMencoderAss(e.getStateChange() == ItemEvent.SELECTED);
            }
        }
    });
    builder.add(ass, FormLayoutUtil.flip(cc.xy(1, 23), colSpec, orientation));
    ass.setSelected(configuration.isMencoderAss());
    ass.getItemListeners()[0].itemStateChanged(null);

    fc = new JCheckBox(Messages.getString("MEncoderVideo.21"));
    fc.setContentAreaFilled(false);
    fc.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderFontConfig(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(fc, FormLayoutUtil.flip(cc.xyw(3, 23, 5), colSpec, orientation));
    fc.setSelected(configuration.isMencoderFontConfig());

    assdefaultstyle = new JCheckBox(Messages.getString("MEncoderVideo.36"));
    assdefaultstyle.setContentAreaFilled(false);
    assdefaultstyle.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            configuration.setMencoderAssDefaultStyle(e.getStateChange() == ItemEvent.SELECTED);
        }
    });
    builder.add(assdefaultstyle, FormLayoutUtil.flip(cc.xyw(8, 23, 4), colSpec, orientation));
    assdefaultstyle.setSelected(configuration.isMencoderAssDefaultStyle());

    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);
                assdefaultstyle.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;
}

From source file:eu.crisis_economics.abm.dashboard.Page_Parameters.java

private void saveSubTree(@SuppressWarnings("rawtypes") final Enumeration children,
        final List<Parameter> parameterList, final List<SubmodelParameter> submodelParameterList,
        final Set<ParameterInfo> invalids) throws IOException {

    final ObjectFactory factory = new ObjectFactory();
    while (children.hasMoreElements()) {
        final DefaultMutableTreeNode node = (DefaultMutableTreeNode) children.nextElement();

        @SuppressWarnings("unchecked")
        final Pair<ParameterInfo, JComponent> userData = (Pair<ParameterInfo, JComponent>) node.getUserObject();
        final ParameterInfo parameterInfo = userData.getFirst();
        final JComponent valueContainer = userData.getSecond();

        Parameter parameter = null;
        SubmodelParameter submodelParameter = null;
        if (parameterInfo instanceof ISubmodelGUIInfo) {
            final ISubmodelGUIInfo sgi = (ISubmodelGUIInfo) parameterInfo;
            if (sgi.getParent() != null) {
                final DefaultMutableTreeNode parentNode = (DefaultMutableTreeNode) node.getParent();
                @SuppressWarnings("unchecked")
                final Pair<ParameterInfo, JComponent> parentUserData = (Pair<ParameterInfo, JComponent>) parentNode
                        .getUserObject();
                final SubmodelInfo parentParameterInfo = (SubmodelInfo) parentUserData.getFirst();
                if (invalids.contains(parentParameterInfo)
                        || !classEquals(parentParameterInfo.getActualType(), sgi.getParentValue())) {
                    invalids.add(parameterInfo);
                    continue;
                }/*from   ww w. j a  v  a  2 s.c o  m*/
            }
        }

        if (parameterInfo instanceof SubmodelInfo) {
            submodelParameter = factory.createSubmodelParameter();
            submodelParameter.setName(parameterInfo.getName());
        } else {
            parameter = factory.createParameter();
            parameter.setName(parameterInfo.getName());
        }

        if (parameterInfo.isBoolean()) {
            final JCheckBox checkBox = (JCheckBox) valueContainer;
            parameter.getContent().add(String.valueOf(checkBox.isSelected()));
        } else if (parameterInfo.isEnum()) {
            final JComboBox comboBox = (JComboBox) valueContainer;
            parameter.getContent().add(String.valueOf(comboBox.getSelectedItem()));
        } else if (parameterInfo instanceof MasonChooserParameterInfo) {
            final JComboBox comboBox = (JComboBox) valueContainer;
            parameter.getContent().add(String.valueOf(comboBox.getSelectedIndex()));
        } else if (parameterInfo instanceof SubmodelInfo) {
            final JComboBox comboBox = (JComboBox) ((JPanel) valueContainer).getComponent(0);
            final ClassElement selectedElement = (ClassElement) comboBox.getSelectedItem();

            if (selectedElement.clazz == null)
                throw new IOException("No type is selected for parameter "
                        + parameterInfo.getName().replaceAll("([A-Z])", " $1") + ".");

            submodelParameter.setType(selectedElement.clazz.getName());
            saveSubTree(node.children(), submodelParameter.getParameterList(),
                    submodelParameter.getSubmodelParameterList(), invalids);
        } else if (parameterInfo.isFile()) {
            final JTextField textField = (JTextField) valueContainer.getComponent(0);
            parameter.getContent().add(textField.getToolTipText());
        } else if (parameterInfo instanceof MasonIntervalParameterInfo) {
            final JTextField textField = (JTextField) valueContainer.getComponent(0);
            parameter.getContent().add(textField.getText().trim());
        } else {
            final JTextField textField = (JTextField) valueContainer;
            String text = String.valueOf(ParameterInfo.getValue(textField.getText(), parameterInfo.getType()));
            if ("String".equals(parameterInfo.getType()) && parameterInfo.getValue() == null)
                text = textField.getText().trim();
            parameter.getContent().add(text);
        }

        if (parameter != null)
            parameterList.add(parameter);
        else if (submodelParameter != null)
            submodelParameterList.add(submodelParameter);
    }
}