Search in sources :

Example 1 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class DLNAResource method startPlaying.

/**
 * Plugin implementation. When this item is going to play, it will notify all the
 * StartStopListener objects available.
 *
 * @param rendererId
 * @param incomingRenderer
 *
 * @see StartStopListener
 */
public void startPlaying(final String rendererId, final RendererConfiguration incomingRenderer) {
    final String requestId = getRequestId(rendererId);
    synchronized (requestIdToRefcount) {
        Integer temp = requestIdToRefcount.get(requestId);
        if (temp == null) {
            temp = 0;
        }
        final Integer refCount = temp;
        requestIdToRefcount.put(requestId, refCount + 1);
        if (refCount == 0) {
            final DLNAResource self = this;
            Runnable r = new Runnable() {

                @Override
                public void run() {
                    InetAddress rendererIp;
                    try {
                        rendererIp = InetAddress.getByName(rendererId);
                        RendererConfiguration renderer;
                        if (incomingRenderer == null) {
                            renderer = RendererConfiguration.getRendererConfigurationBySocketAddress(rendererIp);
                        } else {
                            renderer = incomingRenderer;
                        }
                        String rendererName = "unknown renderer";
                        try {
                            renderer.setPlayingRes(self);
                            rendererName = renderer.getRendererName().replaceAll("\n", "");
                        } catch (NullPointerException e) {
                        }
                        if (!quietPlay()) {
                            LOGGER.info("Started playing " + getName() + " on your " + rendererName);
                            LOGGER.debug("The full filename of which is: " + getSystemName() + " and the address of the renderer is: " + rendererId);
                        }
                    } catch (UnknownHostException ex) {
                        LOGGER.debug("" + ex);
                    }
                    startTime = System.currentTimeMillis();
                    for (final ExternalListener listener : ExternalFactory.getExternalListeners()) {
                        if (listener instanceof StartStopListener) {
                            // run these asynchronously for slow handlers (e.g. logging, scrobbling)
                            Runnable fireStartStopEvent = new Runnable() {

                                @Override
                                public void run() {
                                    try {
                                        ((StartStopListener) listener).nowPlaying(media, self);
                                    } catch (Throwable t) {
                                        LOGGER.error("Notification of startPlaying event failed for StartStopListener {}", listener.getClass(), t);
                                    }
                                }
                            };
                            new Thread(fireStartStopEvent, "StartPlaying Event for " + listener.name()).start();
                        }
                    }
                }
            };
            new Thread(r, "StartPlaying Event").start();
        }
    }
}
Also used : StartStopListener(net.pms.external.StartStopListener) UnknownHostException(java.net.UnknownHostException) RendererConfiguration(net.pms.configuration.RendererConfiguration) ExternalListener(net.pms.external.ExternalListener) InetAddress(java.net.InetAddress)

Example 2 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class UPNPHelper method rendererFound.

@Override
protected Renderer rendererFound(Device d, String uuid) {
    // Create or retrieve an instance
    try {
        InetAddress socket = InetAddress.getByName(getURL(d).getHost());
        DeviceConfiguration r = (DeviceConfiguration) RendererConfiguration.getRendererConfigurationBySocketAddress(socket);
        RendererConfiguration ref = configuration.isRendererForceDefault() ? null : RendererConfiguration.getRendererConfigurationByUPNPDetails(getDeviceDetailsString(d));
        if (r != null && !r.isUpnpAllowed()) {
            LOGGER.debug("Upnp service is {} for \"{}\"", r.getUpnpModeString(), r);
            return null;
        } else if (r == null && ref != null && !ref.isUpnpAllowed()) {
            LOGGER.debug("Upnp service is {} for {} devices", ref.getUpnpModeString(), ref);
            return null;
        }
        // FIXME: when UpnpDetailsSearch is missing from the conf a upnp-advertising
        // renderer could register twice if the http server sees it first
        boolean distinct = r != null && StringUtils.isNotBlank(r.getUUID()) && !uuid.equals(r.getUUID());
        if (!distinct && r != null && (r.matchUPNPDetails(getDeviceDetailsString(d)) || !r.loaded)) {
            // Already seen by the http server
            if (ref != null && !ref.getUpnpDetailsString().equals(r.getUpnpDetailsString()) && ref.getLoadingPriority() >= r.getLoadingPriority()) {
                // The upnp-matched reference conf is different from the previous
                // http-matched conf and has equal or higher priority, so update.
                LOGGER.debug("Switching to preferred renderer: " + ref);
                r.inherit(ref);
            }
            // Update if we have a custom configuration for this uuid
            r.setUUID(uuid);
            // Make sure it's mapped
            rendererMap.put(uuid, "0", r);
            r.details = getDeviceDetails(d);
            // Update gui
            PMS.get().updateRenderer(r);
            LOGGER.debug("Found upnp service for \"{}\" with dlna details: {}", r, r.details);
        } else {
            // It's brand new
            r = (DeviceConfiguration) rendererMap.get(uuid, "0");
            if (ref != null) {
                r.inherit(ref);
            } else {
                // It's unrecognized: temporarily assign the default renderer but mark it as unloaded
                // so actual recognition can happen later once the http server receives a request.
                // This is to allow initiation of upnp playback before http recognition has occurred.
                r.inherit(r.getDefaultConf());
                r.loaded = false;
                LOGGER.debug("Marking upnp renderer \"{}\" at {} as unrecognized", r, socket);
            }
            if (r.associateIP(socket)) {
                r.details = getDeviceDetails(d);
                PMS.get().setRendererFound(r);
                LOGGER.debug("New renderer found: \"{}\" with dlna details: {}", r, r.details);
            }
        }
        return r;
    } catch (Exception e) {
        LOGGER.debug("Error initializing device " + getFriendlyName(d) + ": " + e);
        e.printStackTrace();
    }
    return null;
}
Also used : RendererConfiguration(net.pms.configuration.RendererConfiguration) DeviceConfiguration(net.pms.configuration.DeviceConfiguration) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class DbgPacker method poll.

private void poll() {
    // call the client callbacks
    for (ExternalListener listener : ExternalFactory.getExternalListeners()) {
        if (listener instanceof DebugPacker) {
            LOGGER.debug("Found client {}", listener.name());
            Object obj = ((DebugPacker) listener).dbgpack_cb();
            if (obj instanceof String) {
                add(((String) obj).split(","));
            } else if (obj instanceof String[]) {
                add((String[]) obj);
            }
        }
    }
    PmsConfiguration configuration = PMS.getConfiguration();
    // check dbgpack property in UMS.conf
    LOGGER.debug("Checking dbgpack property in UMS.conf");
    String f = (String) configuration.getCustomProperty("dbgpack");
    if (f != null) {
        add(f.split(","));
    }
    // add confs of connected renderers
    for (RendererConfiguration r : RendererConfiguration.getConnectedRenderersConfigurations()) {
        add(r.getFile());
        if (((DeviceConfiguration) r).isCustomized()) {
            add(((DeviceConfiguration) r).getParentFile());
        }
    }
    // add core items with the default logfile last (LinkedHashMap preserves insertion order)
    String profileDirectory = configuration.getProfileDirectory();
    // add virtual folders file if it exists
    String vfolders = configuration.getVirtualFoldersFile(null);
    if (StringUtils.isNotEmpty(vfolders)) {
        add(new File(profileDirectory, vfolders));
    }
    add(new File(profileDirectory, "WEB.conf"));
    add(new File(configuration.getProfilePath()));
    if (defaultLogFile != null && !defaultLogFile.isEmpty()) {
        add(new File(defaultLogFile + ".prev"));
        add(new File(defaultLogFile));
    }
}
Also used : PmsConfiguration(net.pms.configuration.PmsConfiguration) RendererConfiguration(net.pms.configuration.RendererConfiguration) DebugPacker(net.pms.external.DebugPacker) ExternalListener(net.pms.external.ExternalListener) DeviceConfiguration(net.pms.configuration.DeviceConfiguration) File(java.io.File)

Example 4 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration 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 5 with RendererConfiguration

use of net.pms.configuration.RendererConfiguration in project UniversalMediaServer by UniversalMediaServer.

the class GeneralTab method addRenderers.

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

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

Aggregations

RendererConfiguration (net.pms.configuration.RendererConfiguration)24 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)5 Test (org.junit.Test)5 InetAddress (java.net.InetAddress)4 DLNAMediaInfo (net.pms.dlna.DLNAMediaInfo)4 Format (net.pms.formats.Format)4 UnknownHostException (java.net.UnknownHostException)3 PmsConfiguration (net.pms.configuration.PmsConfiguration)3 WebRender (net.pms.configuration.WebRender)3 DLNAMediaAudio (net.pms.dlna.DLNAMediaAudio)3 ExternalListener (net.pms.external.ExternalListener)3 MPG (net.pms.formats.MPG)3 InetSocketAddress (java.net.InetSocketAddress)2 StringTokenizer (java.util.StringTokenizer)2 DeviceConfiguration (net.pms.configuration.DeviceConfiguration)2 InputFile (net.pms.dlna.InputFile)2 StartStopListener (net.pms.external.StartStopListener)2 MP3 (net.pms.formats.audio.MP3)2 KeyedComboBoxModel (net.pms.util.KeyedComboBoxModel)2