Package net.pms.util

Examples of net.pms.util.KeyedComboBoxModel$ComboBoxItemPair


    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));
    ypos = 7; // we hardcode here (promise last time)
    builder.addLabel(Messages.getString("NetworkTab.0"), FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
    final KeyedComboBoxModel kcbm = new KeyedComboBoxModel(new Object[] {
        "ar", "bg", "ca", "zhs", "zht", "cz", "da", "nl", "en", "en_uk", "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 (US)", "English (UK)",
        "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;
    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() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {
          configuration.setLanguage((String) kcbm.getSelectedKey());
        }
      }
    });

    builder.add(langs, FormLayoutUtil.flip(cc.xyw(3, ypos, 7), 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(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(autoStart, FormLayoutUtil.flip(cc.xyw(3, ypos, 7), colSpec, orientation));
    }
    ypos += 2;

    if (!configuration.isHideAdvancedOptions()) {
      CustomJButton service = new CustomJButton(Messages.getString("NetworkTab.4"));
      service.setToolTipText(Messages.getString("NetworkTab.63"));
      service.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          if (PMS.get().installWin32Service()) {
            LOGGER.info(Messages.getString("PMS.41"));
            JOptionPane.showMessageDialog(
              looksFrame,
              Messages.getString("NetworkTab.11") +
              Messages.getString("NetworkTab.12"),
              Messages.getString("Dialog.Information"),
              JOptionPane.INFORMATION_MESSAGE
            );
          } else {
            JOptionPane.showMessageDialog(
              looksFrame,
              Messages.getString("NetworkTab.14"),
              Messages.getString("Dialog.Error"),
              JOptionPane.ERROR_MESSAGE
            );
          }
        }
      });
      builder.add(service, FormLayoutUtil.flip(cc.xy(1, ypos), colSpec, orientation));
      if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) {
        service.setEnabled(false);
      }

      CustomJButton serviceUninstall = new CustomJButton(Messages.getString("GeneralTab.2"));
      serviceUninstall.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
          PMS.get().uninstallWin32Service();
          LOGGER.info(Messages.getString("GeneralTab.3"));
          JOptionPane.showMessageDialog(
            looksFrame,
            Messages.getString("GeneralTab.3"),
            Messages.getString("Dialog.Information"),
            JOptionPane.INFORMATION_MESSAGE
          );
        }
      });
      builder.add(serviceUninstall, FormLayoutUtil.flip(cc.xy(3, ypos), colSpec, orientation));
      if (System.getProperty(LooksFrame.START_SERVICE) != null || !Platform.isWindows()) {
        serviceUninstall.setEnabled(false);
      }
      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(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());
      }
    });
    builder.add(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(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(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) {
      sortRendererConfiurationsByName(allConfs);     
      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);
    }

    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 java.awt.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 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());
View Full Code Here


  private KeyedComboBoxModel createNetworkInterfacesModel() {
    List<String> keys = NetworkConfiguration.getInstance().getKeys();
    List<String> names = NetworkConfiguration.getInstance().getDisplayNames();
    keys.add(0, "");
    names.add(0, "");
    final KeyedComboBoxModel networkInterfaces = new KeyedComboBoxModel(keys.toArray(), names.toArray());
    return networkInterfaces;
  }
View Full Code Here

          nameValues.add(renderer.getRendererName());
        }
      }
    }

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

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

    renderers.addItemListener(new ItemListener() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {
          LOGGER.info("Setting renderer default: \"" + renderersKcbm.getSelectedKey() + "\"");
          configuration.setRendererDefault((String) renderersKcbm.getSelectedKey());
        }
      }
    });
  }
View Full Code Here

        configuration.setImageThumbnailsEnabled((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    // Audio thumbnails import
    final KeyedComboBoxModel thumbKCBM = new KeyedComboBoxModel(new Object[]{"0", "1", "2"}, new Object[]{Messages.getString("FoldTab.35"), Messages.getString("FoldTab.23"), Messages.getString("FoldTab.24")});
    audiothumbnail = new JComboBox(thumbKCBM);
    audiothumbnail.setEditable(false);

    thumbKCBM.setSelectedKey("" + configuration.getAudioThumbnailMethod());

    audiothumbnail.addItemListener(new ItemListener() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {

          try {
            configuration.setAudioThumbnailMethod(Integer.parseInt((String) thumbKCBM.getSelectedKey()));
          } catch (NumberFormatException nfe) {
            LOGGER.debug("Could not parse audio thumbnail method from \"" + thumbKCBM.getSelectedKey() + "\"");
          }

        }
      }
    });

    // Alternate video cover art folder
    defaultThumbFolder = new JTextField(configuration.getAlternateThumbFolder());
    defaultThumbFolder.addKeyListener(new KeyAdapter() {
      @Override
      public void keyReleased(KeyEvent e) {
        configuration.setAlternateThumbFolder(defaultThumbFolder.getText());
      }
    });

    // Alternate video cover art folder button
    select = new CustomJButton("...");
    select.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        JFileChooser chooser;
        try {
          chooser = new JFileChooser();
        } catch (Exception ee) {
          chooser = new JFileChooser(new RestrictedFileSystemView());
        }
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
        if (returnVal == JFileChooser.APPROVE_OPTION) {
          defaultThumbFolder.setText(chooser.getSelectedFile().getAbsolutePath());
          configuration.setAlternateThumbFolder(chooser.getSelectedFile().getAbsolutePath());
        }
      }
    });

    // Hide Server Settings folder
    hidevideosettings = new JCheckBox(Messages.getString("FoldTab.38"), configuration.getHideVideoSettings());
    hidevideosettings.setContentAreaFilled(false);
    hidevideosettings.addItemListener(new ItemListener() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideVideoSettings((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

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

    // Hide cache folder
    hidemedialibraryfolder = new JCheckBox(Messages.getString("FoldTab.32"), configuration.isHideMediaLibraryFolder());
    hidemedialibraryfolder.setContentAreaFilled(false);
    hidemedialibraryfolder.addItemListener(new ItemListener() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideMediaLibraryFolder((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

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

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

    // Reset cache
    cachereset = new CustomJButton(Messages.getString("NetworkTab.18"));
    cachereset.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        int option = JOptionPane.showConfirmDialog(
          looksFrame,
          Messages.getString("NetworkTab.13") + Messages.getString("NetworkTab.19"),
          Messages.getString("Dialog.Question"),
          JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
          PMS.get().getDatabase().init(true);
        }

      }
    });
    cachereset.setEnabled(configuration.getUseCache());

    // Hide file extensions
    hideextensions = new JCheckBox(Messages.getString("FoldTab.5"), configuration.isHideExtensions());
    hideextensions.setContentAreaFilled(false);
    if (configuration.isPrettifyFilenames()) {
      hideextensions.setEnabled(false);
    }
    hideextensions.addItemListener(new ItemListener() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideExtensions((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

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

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

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

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

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

    // File order
    final KeyedComboBoxModel kcbm = new KeyedComboBoxModel(
      new Object[]{
        String.valueOf(UMSUtils.SORT_LOC_SENS)// alphabetical
        String.valueOf(UMSUtils.SORT_LOC_NAT),   // natural sort
        String.valueOf(UMSUtils.SORT_INS_ASCII), // ASCIIbetical
        String.valueOf(UMSUtils.SORT_MOD_NEW),   // newest first
        String.valueOf(UMSUtils.SORT_MOD_OLD),   // oldest first
        String.valueOf(UMSUtils.SORT_RANDOM),    // random
        String.valueOf(UMSUtils.SORT_NO_SORT)    // no sorting
      },
      new Object[]{
        Messages.getString("FoldTab.15"),
        Messages.getString("FoldTab.22"),
        Messages.getString("FoldTab.20"),
        Messages.getString("FoldTab.16"),
        Messages.getString("FoldTab.17"),
        Messages.getString("FoldTab.58"),
        Messages.getString("FoldTab.62")
      }
    );
    sortmethod = new JComboBox(kcbm);
    sortmethod.setEditable(false);
    kcbm.setSelectedKey("" + configuration.getSortMethod(null));

    sortmethod.addItemListener(new ItemListener() {
      @Override
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {

          try {
            configuration.setSortMethod(Integer.parseInt((String) kcbm.getSelectedKey()));
          } catch (NumberFormatException nfe) {
            LOGGER.debug("Could not parse sort method from \"" + kcbm.getSelectedKey() + "\"");
          }

        }
      }
    });
View Full Code Here

    if (configuration.getImageThumbnailsEnabled()) {
      image_thumb.setSelected(true);
    }

    // AudioThumbnailMethod
    final KeyedComboBoxModel thumbKCBM = new KeyedComboBoxModel(new Object[]{"0", "1", "2"}, new Object[]{Messages.getString("FoldTab.35"), Messages.getString("FoldTab.23"), Messages.getString("FoldTab.24")});
    audiothumbnail = new JComboBox(thumbKCBM);
    audiothumbnail.setEditable(false);

    thumbKCBM.setSelectedKey("" + configuration.getAudioThumbnailMethod());

    audiothumbnail.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {

          try {
            configuration.setAudioThumbnailMethod(Integer.parseInt((String) thumbKCBM.getSelectedKey()));
          } catch (NumberFormatException nfe) {
            logger.debug("Could not parse audio thumbnail method from \"" + thumbKCBM.getSelectedKey() + "\"");
          }

        }
      }
    });

    // AlternateThumbFolder
    defaultThumbFolder = new JTextField(configuration.getAlternateThumbFolder());
    defaultThumbFolder.addKeyListener(new KeyAdapter() {
      @Override
      public void keyReleased(KeyEvent e) {
        configuration.setAlternateThumbFolder(defaultThumbFolder.getText());
      }
    });


    // AlternateThumbFolder: select
    select = new JButton("...");
    select.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        JFileChooser chooser = null;
        try {
          chooser = new JFileChooser();
        } catch (Exception ee) {
          chooser = new JFileChooser(new RestrictedFileSystemView());
        }
        chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        int returnVal = chooser.showDialog((Component) e.getSource(), Messages.getString("FoldTab.28"));
        if (returnVal == JFileChooser.APPROVE_OPTION) {
          defaultThumbFolder.setText(chooser.getSelectedFile().getAbsolutePath());
          configuration.setAlternateThumbFolder(chooser.getSelectedFile().getAbsolutePath());
        }
      }
    });

    // HideVideoSettings
    hidevideosettings = new JCheckBox(Messages.getString("FoldTab.6"));
    hidevideosettings.setContentAreaFilled(false);
    if (configuration.getHideVideoSettings()) {
      hidevideosettings.setSelected(true);
    }
    hidevideosettings.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideVideoSettings((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    hidetranscode = new JCheckBox(Messages.getString("FoldTab.33"));
    hidetranscode.setContentAreaFilled(false);
    if (configuration.getHideTranscodeEnabled()) {
      hidetranscode.setSelected(true);
    }
    hidetranscode.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideTranscodeEnabled((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    hidemedialibraryfolder = new JCheckBox(Messages.getString("FoldTab.32"));
    hidemedialibraryfolder.setContentAreaFilled(false);
    if (configuration.isHideMediaLibraryFolder()) {
      hidemedialibraryfolder.setSelected(true);
    }
    hidemedialibraryfolder.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideMediaLibraryFolder((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    archive = new JCheckBox(Messages.getString("NetworkTab.1"));
    archive.setContentAreaFilled(false);
    archive.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setArchiveBrowsing(e.getStateChange() == ItemEvent.SELECTED);
      }
    });
    if (configuration.isArchiveBrowsing()) {
      archive.setSelected(true);
    }

    cachereset = new JButton(Messages.getString("NetworkTab.18"));

    cacheenable = new JCheckBox(Messages.getString("NetworkTab.17"));
    cacheenable.setContentAreaFilled(false);
    cacheenable.setSelected(configuration.getUseCache());
    cacheenable.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setUseCache((e.getStateChange() == ItemEvent.SELECTED));
        cachereset.setEnabled(configuration.getUseCache());
        if ((LooksFrame) PMS.get().getFrame() != null) {
          ((LooksFrame) PMS.get().getFrame()).getFt().setScanLibraryEnabled(configuration.getUseCache());
        }
      }
    });

    cachereset.addActionListener(new ActionListener() {
      @Override
      public void actionPerformed(ActionEvent e) {
        int option = JOptionPane.showConfirmDialog(
          (Component) PMS.get().getFrame(),
          Messages.getString("NetworkTab.13") + Messages.getString("NetworkTab.19"),
          Messages.getString("Dialog.Question"),
          JOptionPane.YES_NO_OPTION);
        if (option == JOptionPane.YES_OPTION) {
          PMS.get().getDatabase().init(true);
        }

      }
    });
    cachereset.setEnabled(configuration.getUseCache());

    // HideExtensions
    hideextensions = new JCheckBox(Messages.getString("FoldTab.5"));
    hideextensions.setContentAreaFilled(false);
    if (configuration.isHideExtensions()) {
      hideextensions.setSelected(true);
    }
    hideextensions.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideExtensions((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    // HideEngineNames
    hideengines = new JCheckBox(Messages.getString("FoldTab.8"));
    hideengines.setContentAreaFilled(false);
    if (configuration.isHideEngineNames()) {
      hideengines.setSelected(true);
    }
    hideengines.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideEngineNames((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    // HideEmptyFolders
    hideemptyfolders = new JCheckBox(Messages.getString("FoldTab.31"));
    hideemptyfolders.setContentAreaFilled(false);
    if (configuration.isHideEmptyFolders()) {
      hideemptyfolders.setSelected(true);
    }
    hideemptyfolders.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setHideEmptyFolders((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    // ItunesEnabled
    itunes = new JCheckBox(Messages.getString("FoldTab.30"));
    itunes.setContentAreaFilled(false);
    if (configuration.isShowItunesLibrary()) {
      itunes.setSelected(true);
    }
    if (!(Platform.isMac() || Platform.isWindows())) {
      itunes.setEnabled(false);
    }
    itunes.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setShowItunesLibrary((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    // IphotoEnabled
    iphoto = new JCheckBox(Messages.getString("FoldTab.29"));
    iphoto.setContentAreaFilled(false);
    if (configuration.isShowIphotoLibrary()) {
      iphoto.setSelected(true);
    }
    if (!Platform.isMac()) {
      iphoto.setEnabled(false);
    }
    iphoto.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setShowIphotoLibrary((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    // ApertureEnabled
    aperture = new JCheckBox(Messages.getString("FoldTab.34"));
    aperture.setContentAreaFilled(false);
    if (configuration.isShowApertureLibrary()) {
      aperture.setSelected(true);
    }
    if (!Platform.isMac()) {
      aperture.setEnabled(false);
    }
    aperture.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        configuration.setShowApertureLibrary((e.getStateChange() == ItemEvent.SELECTED));
      }
    });

    // sort method
    final KeyedComboBoxModel kcbm = new KeyedComboBoxModel(
      new Object[]{
        "0", // alphabetical
        "4", // natural sort
        "3", // ASCIIbetical
        "1", // newest first
        "2", // oldest first
        "5"  // random
      },
      new Object[]{
        Messages.getString("FoldTab.15"),
        Messages.getString("FoldTab.22"),
        Messages.getString("FoldTab.20"),
        Messages.getString("FoldTab.16"),
        Messages.getString("FoldTab.17"),
        Messages.getString("FoldTab.36")
      }
    );
    sortmethod = new JComboBox(kcbm);
    sortmethod.setEditable(false);
    kcbm.setSelectedKey("" + configuration.getSortMethod());

    sortmethod.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {

          try {
            configuration.setSortMethod(Integer.parseInt((String) kcbm.getSelectedKey()));
          } catch (NumberFormatException nfe) {
            logger.debug("Could not parse sort method from \"" + kcbm.getSelectedKey() + "\"");
          }

        }
      }
    });
View Full Code Here

        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) {
      sortRendererConfiurationsByName(allConfs);     
      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);
    }
View Full Code Here

  private KeyedComboBoxModel createNetworkInterfacesModel() {
    List<String> keys = NetworkConfiguration.getInstance().getKeys();
    List<String> names = NetworkConfiguration.getInstance().getDisplayNames();
    keys.add(0, "");
    names.add(0, "");
    final KeyedComboBoxModel networkInterfaces = new KeyedComboBoxModel(keys.toArray(), names.toArray());
    return networkInterfaces;
  }
View Full Code Here

          nameValues.add(renderer.getRendererName());
        }
      }
    }
   
    final KeyedComboBoxModel renderersKcbm = new KeyedComboBoxModel(
        (Object[]) keyValues.toArray(new Object[keyValues.size()]),
        (Object[]) nameValues.toArray(new Object[nameValues.size()]));
    renderers.setModel(renderersKcbm);
    renderers.setEditable(false);
    String defaultRenderer = configuration.getRendererDefault();
    renderersKcbm.setSelectedKey(defaultRenderer);
   
    if (renderers.getSelectedIndex() == -1) {
      renderers.setSelectedIndex(0);
    }

    renderers.addItemListener(new ItemListener() {
      public void itemStateChanged(ItemEvent e) {
        if (e.getStateChange() == ItemEvent.SELECTED) {
          logger.info("Setting renderer default: \"" + renderersKcbm.getSelectedKey() + "\"");
          configuration.setRendererDefault((String) renderersKcbm.getSelectedKey());
        }
      }
    });
  }
View Full Code Here

TOP

Related Classes of net.pms.util.KeyedComboBoxModel$ComboBoxItemPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.