Пример #1
0
 /** @return album name */
 public String getAlbumName() {
   String sAlbumlName = null;
   String sTemp = ""; // $NON-NLS-1$
   try {
     sTemp = tagImpl.getAlbumName().trim();
     if (Messages.getString("unknown_album")
         .equals(
             sTemp)) { // it is done to avoid duplicates unknown albums if the tag is the real
                       // string "unknown" in the current language  //$NON-NLS-1$
       sAlbumlName = "unknown_album"; // $NON-NLS-1$
     } else if (!"".equals(sTemp)) { // $NON-NLS-1$
       sAlbumlName = sTemp;
     }
   } catch (Exception e) {
     Log.error("103", fio.getName(), e); // $NON-NLS-1$
   }
   if (sAlbumlName == null) { // album tag cannot be found
     if (Boolean.valueOf(ConfigurationManager.getProperty(CONF_TAGS_USE_PARENT_DIR))
         .booleanValue()) {
       sAlbumlName =
           fio.getParentFile()
               .getName(); // if album is not found, take current dirtectory as album name
     } else {
       sAlbumlName = Messages.getString("unknown_album"); // album inconnu //$NON-NLS-1$
     }
   }
   sAlbumlName = Util.formatTag(sAlbumlName);
   return sAlbumlName;
 }
 /* (non-Javadoc)
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(ActionEvent ae) {
   if (ae.getSource().equals(this.okp.getOKButton())) {
     try {
       Message message = new Message();
       message.setSubject(jtfDesc.getText());
       ArrayList alTo = new ArrayList();
       alTo.add(FEEDBACK_EMAIL);
       message.setToAddrs(alTo);
       String sBody = ""; // $NON-NLS-1$
       sBody += "From: " + jtfFrom.getText() + '\n'; // $NON-NLS-1$
       sBody += "Subject: " + jtfDesc.getText() + '\n'; // $NON-NLS-1$
       sBody += "Details: " + jtaDetail.getText() + '\n'; // $NON-NLS-1$
       sBody += "Version: " + JAJUK_VERSION + '\n'; // $NON-NLS-1$
       sBody += System.getProperties().toString() + '\n';
       sBody += ConfigurationManager.getProperties().toString() + '\n';
       Iterator it = Log.getSpool();
       while (it.hasNext()) {
         sBody += it.next().toString() + '\n';
       }
       message.setBody(sBody);
       Desktop.mail(message);
       dispose();
     } catch (Exception e) {
       Messages.showErrorMessage("136"); // $NON-NLS-1$
       Log.error(e);
     }
   } else if (ae.getSource().equals(this.okp.getCancelButton())) {
     dispose();
   }
 }
Пример #3
0
 private static void setConfiguration(HttpURLConnection connection) {
   connection.setConnectTimeout(1000 * ConfigurationManager.getInt(CONF_NETWORK_CONNECTION_TO));
   // Google needs this
   connection.addRequestProperty(
       "Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*");
   connection.addRequestProperty("Accept-Language", "en-us");
   connection.addRequestProperty(
       "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
   connection.addRequestProperty("Connection", "Keep-Alive");
 }
 public void actionPerformed(ActionEvent ae) {
   // Ambience Configuration
   if (ambiencesCombo.getSelectedIndex() == 0) {
     // display the wizard
     AmbienceWizard ambience = new AmbienceWizard();
     ambience.show();
     // Reset combo to last selected item
     ambiencesCombo.removeActionListener(ambienceListener);
     Ambience defaultAmbience =
         AmbienceManager.getInstance()
             .getAmbience(ConfigurationManager.getProperty(CONF_DEFAULT_AMBIENCE));
     if (defaultAmbience != null) {
       for (int i = 0; i < ambiencesCombo.getItemCount(); i++) {
         if (((JLabel) ambiencesCombo.getItemAt(i))
             .getText()
             .equals(defaultAmbience.getName())) {
           ambiencesCombo.setSelectedIndex(i);
           break;
         }
       }
     } else {
       ambiencesCombo.setSelectedIndex(1);
     }
     ambiencesCombo.addActionListener(ambienceListener);
   }
   // Selected 'Any" ambience
   else if (ambiencesCombo.getSelectedIndex() == 1) {
     // reset default ambience
     ConfigurationManager.setProperty(CONF_DEFAULT_AMBIENCE, "");
     ObservationManager.notify(new Event(EventSubject.EVENT_AMBIENCES_SELECTION_CHANGE));
   } else { // Selected an ambience
     Ambience ambience =
         AmbienceManager.getInstance()
             .getAmbienceByName(((JLabel) ambiencesCombo.getSelectedItem()).getText());
     ConfigurationManager.setProperty(CONF_DEFAULT_AMBIENCE, ambience.getID());
     ObservationManager.notify(new Event(EventSubject.EVENT_AMBIENCES_SELECTION_CHANGE));
   }
 }
 /*
  * (non-Javadoc)
  *
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(final ActionEvent ae) {
   // do not run this in a separate thread because Player actions would die
   // with the thread
   try {
     if (ae.getSource() == jcbHistory) {
       HistoryItem hi;
       hi = History.getInstance().getHistoryItem(jcbHistory.getSelectedIndex());
       if (hi != null) {
         org.jajuk.base.File file = FileManager.getInstance().getFileByID(hi.getFileId());
         if (file != null) {
           try {
             FIFO.getInstance()
                 .push(
                     new StackItem(file, ConfigurationManager.getBoolean(CONF_STATE_REPEAT), true),
                     ConfigurationManager.getBoolean(CONF_OPTIONS_DEFAULT_ACTION_CLICK));
           } catch (JajukException je) {
             // can be thrown if file is null
           }
         } else {
           Messages.showErrorMessage(120);
           jcbHistory.setSelectedItem(null);
         }
       }
     } else if (ae.getSource().equals(jmiNoveltiesModeSong)) {
       ConfigurationManager.setProperty(CONF_NOVELTIES_MODE, MODE_TRACK);
     } else if (ae.getSource().equals(jmiNoveltiesModeAlbum)) {
       ConfigurationManager.setProperty(CONF_NOVELTIES_MODE, MODE_ALBUM);
     } else if (ae.getSource().equals(jmiShuffleModeSong)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_TRACK);
     } else if (ae.getSource().equals(jmiShuffleModeAlbum)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_ALBUM);
     } else if (ae.getSource().equals(jmiShuffleModeAlbum2)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_ALBUM2);
     } else if (ae.getSource().equals(jmiShuffleModeAlbum2)) {
       ConfigurationManager.setProperty(CONF_GLOBAL_RANDOM_MODE, MODE_ALBUM2);
     }
   } catch (Exception e) {
     Log.error(e);
   } finally {
     ObservationManager.notify(new Event(EventSubject.EVENT_PLAYLIST_REFRESH));
   }
 }
 /** Populate webradios */
 private void populateWebRadios() {
   try {
     // Update button tooltip
     ddbWebRadio.setToolTipText(WebRadioManager.getCurrentWebRadioTooltip());
     // Clear previous elements
     popupWebRadio.removeAll();
     // Add configure radios item
     ActionBase actionConf = ActionManager.getAction(JajukAction.CONFIGURE_WEBRADIOS);
     XCheckedButton jmiConf = new XCheckedButton(actionConf);
     // Set icon so it is correctly displayed after a selection
     jmiConf.setCheckedIcon((ImageIcon) actionConf.getValue(Action.SMALL_ICON));
     // The icon should be always displayed
     jmiConf.setIconAlwaysVisible(true);
     popupWebRadio.add(jmiConf);
     for (final WebRadio radio : WebRadioManager.getInstance().getWebRadios()) {
       XCheckedButton jmi = new XCheckedButton(radio.getName());
       jmi.addActionListener(
           new ActionListener() {
             public void actionPerformed(ActionEvent e) {
               ConfigurationManager.setProperty(CONF_DEFAULT_WEB_RADIO, radio.getName());
               // force to reselect the item
               populateWebRadios();
               // update action tooltip on main button with right item
               ActionBase action = ActionManager.getAction(JajukAction.WEB_RADIO);
               action.setShortDescription(
                   "<html>"
                       + Messages.getString("CommandJPanel.25")
                       + "<p><b>"
                       + radio.getName()
                       + "</b></p></html>");
             }
           });
       jmi.setSelected(
           ConfigurationManager.getProperty(CONF_DEFAULT_WEB_RADIO).equals(radio.getName()));
       // Show the check icon
       jmi.setDisplayCheck(true);
       popupWebRadio.add(jmi);
     }
   } catch (Exception e) {
     Log.error(e);
   }
 }
 /** Populate DJs */
 private void populateDJs() {
   try {
     ddbDDJ.setToolTipText(
         "<html>"
             + Messages.getString("CommandJPanel.18")
             + "<p><b>"
             + DigitalDJManager.getCurrentDJ()
             + "</b></html>");
     popupDDJ.removeAll();
     JMenuItem jmiNew = new JMenuItem(ActionManager.getAction(CONFIGURE_DJS));
     popupDDJ.add(jmiNew);
     Iterator<DigitalDJ> it = DigitalDJManager.getInstance().getDJs().iterator();
     while (it.hasNext()) {
       final DigitalDJ dj = it.next();
       JCheckBoxMenuItem jmi =
           new JCheckBoxMenuItem(dj.getName(), IconLoader.ICON_DIGITAL_DJ_16x16);
       jmi.addActionListener(
           new ActionListener() {
             public void actionPerformed(ActionEvent arg0) {
               ConfigurationManager.setProperty(CONF_DEFAULT_DJ, dj.getID());
               DigitalDJManager.setCurrentDJ(dj);
               // force to reselect the item
               populateDJs();
               // update action tooltip on main button with right item
               ActionBase action = ActionManager.getAction(JajukAction.DJ);
               action.setShortDescription(
                   "<html>"
                       + Messages.getString("CommandJPanel.18")
                       + "<p><b>"
                       + dj.getName()
                       + "</b></p></html>");
             }
           });
       popupDDJ.add(jmi);
       jmi.setSelected(ConfigurationManager.getProperty(CONF_DEFAULT_DJ).equals(dj.getID()));
     }
   } catch (Exception e) {
     Log.error(e);
   }
 }
 /** Populate ambiences combo */
 void populateAmbiences() {
   ambiencesCombo.removeActionListener(ambienceListener);
   ItemListener[] il = ambiencesCombo.getItemListeners();
   for (int i = 0; i < il.length; i++) {
     ambiencesCombo.removeItemListener(il[i]);
   }
   ambiencesCombo.removeAllItems();
   ambiencesCombo.addItem(
       new JLabel(
           Messages.getString("CommandJPanel.19"),
           IconLoader.ICON_CONFIGURATION,
           SwingConstants.LEFT));
   ambiencesCombo.addItem(
       new JLabel(
           "<html><i>" + Messages.getString("DigitalDJWizard.64") + "</i></html>",
           IconLoader.ICON_STYLE,
           SwingConstants.LEFT));
   // Add available ambiences
   for (final Ambience ambience : AmbienceManager.getInstance().getAmbiences()) {
     ambiencesCombo.addItem(
         new JLabel(ambience.getName(), IconLoader.ICON_STYLE, SwingConstants.LEFT));
   }
   // Select right item
   Ambience defaultAmbience =
       AmbienceManager.getInstance()
           .getAmbience(ConfigurationManager.getProperty(CONF_DEFAULT_AMBIENCE));
   if (defaultAmbience != null) {
     for (int i = 0; i < ambiencesCombo.getItemCount(); i++) {
       if (((JLabel) ambiencesCombo.getItemAt(i)).getText().equals(defaultAmbience.getName())) {
         ambiencesCombo.setSelectedIndex(i);
         break;
       }
     }
   } else {
     // or "any" ambience
     ambiencesCombo.setSelectedIndex(1);
   }
   ambiencesCombo.addActionListener(ambienceListener);
 }
 /*
  * (non-Javadoc)
  *
  * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
  */
 public void actionPerformed(ActionEvent arg0) {
   if (arg0.getSource() == jcbLanguage) {
     // update index
     ConfigurationManager.setProperty(
         CONF_WIKIPEDIA_LANGUAGE,
         Messages.getLocalForDesc((String) jcbLanguage.getSelectedItem()));
     // force launch wikipedia search for this language
     launchSearch(true);
   } else if (arg0.getSource() == jbAlbumSearch) {
     type = Type.ALBUM;
     // force event
     launchSearch(true);
   } else if (arg0.getSource() == jbAuthorSearch) {
     type = Type.AUTHOR;
     // force event
     launchSearch(true);
   } else if (arg0.getSource() == jbTrackSearch) {
     type = Type.TRACK;
     // force event
     launchSearch(true);
   }
 }
Пример #10
0
 /**
  * Force to refresh the album max rating, it is not done soon as it is pretty CPU consumming and
  * we don't need a track by track rating precision
  */
 public void refreshMaxRating() {
   // create a temporary table to remove unmounted albums
   // We consider an album as mounted if a least one track is mounted
   // This hashmap contains album-> album rates
   final HashMap<Album, Float> cacheRate =
       new HashMap<Album, Float>(AlbumManager.getInstance().getElementCount());
   // This hashmap contains album-> nb of tracks already taken into account
   // for average
   HashMap<Album, Integer> cacheNb =
       new HashMap<Album, Integer>(AlbumManager.getInstance().getElementCount());
   for (Track track : TrackManager.getInstance().getTracks()) {
     if (track.getPlayeableFile(ConfigurationManager.getBoolean(CONF_OPTIONS_HIDE_UNMOUNTED))
         != null) {
       float newRate = 0f;
       Integer nb = cacheNb.get(track.getAlbum());
       if (nb == null) {
         nb = 0;
       }
       Float previousRate = cacheRate.get(track.getAlbum());
       if (previousRate == null) {
         newRate = track.getRate();
       } else {
         newRate = ((previousRate * nb) + track.getRate()) / (nb + 1);
       }
       cacheNb.put(track.getAlbum(), nb + 1);
       cacheRate.put(track.getAlbum(), newRate);
     }
   }
   // OK, now keep only the highest score
   for (Album album : cacheRate.keySet()) {
     long value = Math.round(cacheRate.get(album));
     if (value > maxRate) {
       maxRate = value;
     }
   }
 }
Пример #11
0
  public void initUI() {
    // Search
    double[][] sizeSearch = new double[][] {{3, TableLayout.PREFERRED, 3, 100}, {25}};
    JPanel jpSearch = new JPanel(new TableLayout(sizeSearch));
    sbSearch = new SearchBox(CommandJPanel.this);
    JLabel jlSearch = new JLabel(IconLoader.ICON_SEARCH);
    jlSearch.setToolTipText(Messages.getString("CommandJPanel.23"));
    // Clear search text when clicking on the search icon
    jlSearch.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseClicked(MouseEvent e) {
            sbSearch.setText("");
          }
        });
    jpSearch.add(jlSearch, "1,0");
    jpSearch.add(sbSearch, "3,0");

    // History
    JPanel jpHistory = new JPanel();
    jcbHistory = new SteppedComboBox();
    JLabel jlHistory = new JLabel(IconLoader.ICON_HISTORY);
    jlHistory.setToolTipText(Messages.getString("CommandJPanel.0"));
    // - Increase rating button
    ActionBase actionIncRate = ActionManager.getAction(JajukAction.INC_RATE);
    actionIncRate.setName(null);
    final JPopupMenu jpmIncRating = new JPopupMenu();
    for (int i = 1; i <= 10; i++) {
      final int j = i;
      JMenuItem jmi = new JMenuItem("+" + i);
      if (ConfigurationManager.getInt(CONF_INC_RATING) == i) {
        jmi.setFont(FontManager.getInstance().getFont(JajukFont.BOLD));
      }
      // Store selected value
      jmi.addActionListener(
          new ActionListener() {
            public void actionPerformed(ActionEvent e) {
              ConfigurationManager.setProperty(CONF_INC_RATING, "" + j);
            }
          });
      jpmIncRating.add(jmi);
    }
    jbIncRate =
        new DropDownButton(IconLoader.ICON_INC_RATING) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return jpmIncRating;
          }
        };
    jbIncRate.setAction(actionIncRate);
    // we use a combo box model to make sure we get good performances after
    // rebuilding the entire model like after a refresh
    jcbHistory.setModel(new DefaultComboBoxModel(History.getInstance().getHistory()));
    // None selection because if we start in stop mode, a selection of the
    // first item will not launch the track because the selected item is
    // still the same and no action event is thrown (Java >= 1.6)
    jcbHistory.setSelectedItem(null);
    int iWidth = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 2);
    // size of popup
    jcbHistory.setPopupWidth(iWidth);
    // size of the combo itself, keep it! as text can be very long
    jcbHistory.setPreferredSize(new Dimension(250, 25));
    jcbHistory.setMinimumSize(new Dimension(0, 25));
    jcbHistory.setToolTipText(Messages.getString("CommandJPanel.0"));
    jcbHistory.addActionListener(CommandJPanel.this);
    JToolBar jtbIncRate = new JToolBar();
    jtbIncRate.setFloatable(false);
    jbIncRate.addToToolBar(jtbIncRate);
    double[][] sizeHistory =
        new double[][] {
          {3, TableLayout.PREFERRED, 3, TableLayout.FILL, 10, TableLayout.PREFERRED}, {25}
        };
    jpHistory.setLayout(new TableLayout(sizeHistory));
    jpHistory.add(jlHistory, "1,0");
    jpHistory.add(jcbHistory, "3,0");
    jpHistory.add(jtbIncRate, "5,0");

    // Mode toolbar
    // we need an inner toolbar to apply size properly
    JToolBar jtbModes = new JToolBar();
    jtbModes.setBorder(null);
    // make it not floatable as this behavior is managed by vldocking
    jtbModes.setFloatable(false);
    jtbModes.setRollover(true);
    jbRepeat =
        new JajukToggleButton(ActionManager.getAction(JajukAction.REPEAT_MODE_STATUS_CHANGE));
    jbRepeat.setSelected(ConfigurationManager.getBoolean(CONF_STATE_REPEAT));
    jbRandom =
        new JajukToggleButton(ActionManager.getAction(JajukAction.SHUFFLE_MODE_STATUS_CHANGED));
    jbRandom.setSelected(ConfigurationManager.getBoolean(CONF_STATE_SHUFFLE));
    jbContinue =
        new JajukToggleButton(ActionManager.getAction(JajukAction.CONTINUE_MODE_STATUS_CHANGED));
    jbContinue.setSelected(ConfigurationManager.getBoolean(CONF_STATE_CONTINUE));
    jbIntro = new JajukToggleButton(ActionManager.getAction(JajukAction.INTRO_MODE_STATUS_CHANGED));
    jbIntro.setSelected(ConfigurationManager.getBoolean(CONF_STATE_INTRO));
    jtbModes.add(jbRepeat);
    jtbModes.addSeparator();
    jtbModes.add(jbRandom);
    jtbModes.addSeparator();
    jtbModes.add(jbContinue);
    jtbModes.addSeparator();
    jtbModes.add(jbIntro);

    // Volume
    jpVolume = new JPanel();
    ActionUtil.installKeystrokes(
        jpVolume,
        ActionManager.getAction(JajukAction.DECREASE_VOLUME),
        ActionManager.getAction(JajukAction.INCREASE_VOLUME));

    jpVolume.setLayout(new BoxLayout(jpVolume, BoxLayout.X_AXIS));
    int iVolume = (int) (100 * ConfigurationManager.getFloat(CONF_VOLUME));
    if (iVolume > 100) { // can occur in some undefined cases
      iVolume = 100;
    }
    jsVolume = new JSlider(0, 100, iVolume);
    jpVolume.add(jsVolume);
    jpVolume.add(Box.createHorizontalStrut(5));
    jpVolume.add(jbMute);
    jsVolume.setToolTipText(Messages.getString("CommandJPanel.14"));
    jsVolume.addChangeListener(CommandJPanel.this);
    jsVolume.addMouseWheelListener(CommandJPanel.this);

    // Special functions toolbar
    // Ambience combo
    ambiencesCombo = new SteppedComboBox();
    iWidth = (int) (Toolkit.getDefaultToolkit().getScreenSize().getWidth() / 4);
    ambiencesCombo.setPopupWidth(iWidth);
    ambiencesCombo.setFont(FontManager.getInstance().getFont(JajukFont.BOLD_L));
    // size of the combo itself
    ambiencesCombo.setRenderer(
        new BasicComboBoxRenderer() {
          private static final long serialVersionUID = -6943363556191659895L;

          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            JLabel jl = (JLabel) value;
            setIcon(jl.getIcon());
            setText(jl.getText());
            return this;
          }
        });
    ambiencesCombo.setToolTipText(Messages.getString("DigitalDJWizard.66"));
    populateAmbiences();
    ambienceListener = new AmbienceListener();
    ambiencesCombo.addActionListener(ambienceListener);
    jtbSpecial = new JToolBar();
    jtbSpecial.setBorder(null);
    jtbSpecial.setRollover(true);
    jtbSpecial.setFloatable(false);
    ddbGlobalRandom =
        new DropDownButton(IconLoader.ICON_SHUFFLE_GLOBAL) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupGlobalRandom;
          }
        };
    ddbGlobalRandom.setAction(ActionManager.getAction(JajukAction.SHUFFLE_GLOBAL));
    popupGlobalRandom = new JPopupMenu();
    // Global shuffle
    jmiShuffleModeSong = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.20"));
    jmiShuffleModeSong.addActionListener(this);
    // album / album
    jmiShuffleModeAlbum = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.21"));
    jmiShuffleModeAlbum.addActionListener(this);
    // Shuffle album / album
    jmiShuffleModeAlbum2 = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.22"));
    jmiShuffleModeAlbum2.addActionListener(this);
    if (ConfigurationManager.getProperty(CONF_GLOBAL_RANDOM_MODE).equals(MODE_TRACK)) {
      jmiShuffleModeSong.setSelected(true);
    } else if (ConfigurationManager.getProperty(CONF_GLOBAL_RANDOM_MODE).equals(MODE_ALBUM2)) {
      jmiShuffleModeAlbum2.setSelected(true);
    } else {
      jmiShuffleModeAlbum.setSelected(true);
    }
    ButtonGroup bgGlobalRandom = new ButtonGroup();
    bgGlobalRandom.add(jmiShuffleModeSong);
    bgGlobalRandom.add(jmiShuffleModeAlbum);
    bgGlobalRandom.add(jmiShuffleModeAlbum2);
    popupGlobalRandom.add(jmiShuffleModeSong);
    popupGlobalRandom.add(jmiShuffleModeAlbum);
    popupGlobalRandom.add(jmiShuffleModeAlbum2);
    ddbGlobalRandom.setText(""); // no text visible

    jbBestof = new JajukButton(ActionManager.getAction(JajukAction.BEST_OF));

    ddbNovelties =
        new DropDownButton(IconLoader.ICON_NOVELTIES) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupNovelties;
          }
        };
    ddbNovelties.setAction(ActionManager.getAction(JajukAction.NOVELTIES));
    popupNovelties = new JPopupMenu();
    jmiNoveltiesModeSong = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.20"));
    jmiNoveltiesModeSong.addActionListener(this);
    jmiNoveltiesModeAlbum = new JRadioButtonMenuItem(Messages.getString("CommandJPanel.22"));
    jmiNoveltiesModeAlbum.addActionListener(this);
    if (ConfigurationManager.getProperty(CONF_NOVELTIES_MODE).equals(MODE_TRACK)) {
      jmiNoveltiesModeSong.setSelected(true);
    } else {
      jmiNoveltiesModeAlbum.setSelected(true);
    }
    ButtonGroup bgNovelties = new ButtonGroup();
    bgNovelties.add(jmiNoveltiesModeSong);
    bgNovelties.add(jmiNoveltiesModeAlbum);
    popupNovelties.add(jmiNoveltiesModeSong);
    popupNovelties.add(jmiNoveltiesModeAlbum);
    ddbNovelties.setText(""); // no text visible

    jbNorm = new JajukButton(ActionManager.getAction(FINISH_ALBUM));
    popupDDJ = new JPopupMenu();
    ddbDDJ =
        new DropDownButton(IconLoader.ICON_DIGITAL_DJ) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupDDJ;
          }
        };
    ddbDDJ.setAction(ActionManager.getAction(JajukAction.DJ));
    populateDJs();
    // no text visible
    ddbDDJ.setText("");

    popupWebRadio = new XJPopupMenu(Main.getWindow());
    ddbWebRadio =
        new DropDownButton(IconLoader.ICON_WEBRADIO) {
          private static final long serialVersionUID = 1L;

          @Override
          protected JPopupMenu getPopupMenu() {
            return popupWebRadio;
          }
        };
    ddbWebRadio.setAction(ActionManager.getAction(JajukAction.WEB_RADIO));
    populateWebRadios();
    // no text
    ddbWebRadio.setText("");

    ddbDDJ.addToToolBar(jtbSpecial);
    ddbNovelties.addToToolBar(jtbSpecial);
    ddbGlobalRandom.addToToolBar(jtbSpecial);
    jtbSpecial.add(jbBestof);
    jtbSpecial.add(jbNorm);

    // Radio tool bar
    JToolBar jtbWebRadio = new JToolBar();
    jtbWebRadio.setBorder(null);
    jtbWebRadio.setRollover(true);
    jtbWebRadio.setFloatable(false);
    ddbWebRadio.addToToolBar(jtbWebRadio);

    // Play toolbar
    JToolBar jtbPlay = new JToolBar();
    jtbPlay.setBorder(null);
    jtbPlay.setFloatable(false);
    // add some space to get generic size
    jtbPlay.setRollover(true);
    ActionUtil.installKeystrokes(
        jtbPlay, ActionManager.getAction(NEXT_ALBUM), ActionManager.getAction(PREVIOUS_ALBUM));
    jbPrevious = new JajukButton(ActionManager.getAction(PREVIOUS_TRACK));
    jbNext = new JajukButton(ActionManager.getAction(NEXT_TRACK));
    jbRew = new JPressButton(ActionManager.getAction(REWIND_TRACK));
    jbPlayPause = new JajukButton(ActionManager.getAction(PLAY_PAUSE_TRACK));
    jbStop = new JajukButton(ActionManager.getAction(STOP_TRACK));
    jbFwd = new JPressButton(ActionManager.getAction(FAST_FORWARD_TRACK));

    jtbPlay.add(jbPrevious);
    jtbPlay.add(jbRew);
    jtbPlay.add(jbPlayPause);
    jtbPlay.add(jbStop);
    jtbPlay.add(jbFwd);
    jtbPlay.add(jbNext);

    // Add items
    FormLayout layout =
        new FormLayout(
            // --columns
            "3dlu,fill:min(10dlu;p):grow(0.5), 3dlu, "
                + // ambience
                "left:p, 2dlu"
                + // smart toolbar
                ", min(0dlu;p):grow(0.04), 3dlu,"
                + // glue
                " right:p, 10dlu, "
                + // search /modes
                "fill:p, 5dlu, "
                + // history/player
                "fill:min(60dlu;p):grow(0.2),3dlu", // volume/part of
            // history
            // --rows
            "2dlu, p, 2dlu, p, 2dlu"); // rows
    PanelBuilder builder = new PanelBuilder(layout); // , new
    // FormDebugPanel() );
    CellConstraints cc = new CellConstraints();
    // Add items
    builder.add(jtbWebRadio, cc.xyw(2, 2, 3)); // grid width = 3
    builder.add(ambiencesCombo, cc.xy(2, 4));
    builder.add(jtbSpecial, cc.xy(4, 4));
    builder.add(jpSearch, cc.xyw(6, 2, 4));
    builder.add(jpHistory, cc.xyw(10, 2, 4));
    builder.add(jtbModes, cc.xy(8, 4));
    builder.add(jtbPlay, cc.xy(10, 4));
    builder.add(jpVolume, cc.xy(12, 4));
    JPanel p = builder.getPanel();
    setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
    add(p);
    // register to player events
    ObservationManager.register(CommandJPanel.this);

    // if a track is playing, display right state
    if (FIFO.getInstance().getCurrentFile() != null) {
      // update initial state
      update(
          new Event(
              EventSubject.EVENT_PLAYER_PLAY,
              ObservationManager.getDetailsLastOccurence(EventSubject.EVENT_PLAYER_PLAY)));
      // update the history bar
      update(new Event(EventSubject.EVENT_FILE_LAUNCHED));
      // check if some track has been launched before the view has been
      // displayed
      update(new Event(EventSubject.EVENT_HEART_BEAT));
    }
    // start timer
    timer.start();
  }
Пример #12
0
 /* (non-Javadoc)
  * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
  */
 public void actionPerformed(final ActionEvent e) {
   // no thread, nothing requires long execution time and a SwingWorker is not adapted
   if (e.getActionCommand().equals(EVENT_EXIT)) {
     Main.exit(0);
   } else if (e.getActionCommand().equals(EVENT_OPEN_FILE)) {
     JajukFileChooser jfchooser = new JajukFileChooser();
     int returnVal = jfchooser.showOpenDialog(Main.getWindow());
     if (returnVal == JFileChooser.APPROVE_OPTION) {
       java.io.File[] files = jfchooser.getSelectedFiles();
       FIFO.getInstance().clear(); // stop all currently played tracks
       ArrayList alFiles = new ArrayList();
       for (int i = 0; i < files.length; i++) {
         if (Util.getExtension(files[i]).equals(EXT_PLAYLIST)) {
           BasicPlaylistFile bplf = new BasicPlaylistFile(files[i]);
           try {
             alFiles.addAll(bplf.getBasicFiles());
           } catch (JajukException je) {
             Log.error(je);
           }
         } else {
           alFiles.add(new BasicFile(files[i]));
         }
       }
       FIFO.getInstance().push(alFiles, false);
     }
   } else if (e.getActionCommand().equals(EVENT_REPEAT_MODE_STATUS_CHANGED)) {
     boolean bContinue = ConfigurationManager.getBoolean(CONF_STATE_CONTINUE);
     if (bContinue) {
       // Repeat and continue can't be set together, so deselect repeat mode
       ConfigurationManager.setProperty(CONF_STATE_CONTINUE, Boolean.toString(!bContinue));
       JajukJMenuBar.getInstance().jcbmiContinue.setSelected(false);
       CommandJPanel.getInstance().jbContinue.setBorder(BorderFactory.createRaisedBevelBorder());
     }
     boolean b = ConfigurationManager.getBoolean(CONF_STATE_REPEAT);
     ConfigurationManager.setProperty(CONF_STATE_REPEAT, Boolean.toString(!b));
     JajukJMenuBar.getInstance().jcbmiRepeat.setSelected(!b);
     if (!b == true) { // enabled button
       CommandJPanel.getInstance().jbRepeat.setBorder(BorderFactory.createLoweredBevelBorder());
       // set the forced repeat track to repeat over it even with others tracks in the fifo
       FIFO.getInstance().forceRepeat(FIFO.getInstance().getCurrentFile());
     } else { // disable repeat mode
       CommandJPanel.getInstance().jbRepeat.setBorder(BorderFactory.createRaisedBevelBorder());
       FIFO.getInstance().forceRepeat(null); // reset forced
     }
   } else if (e.getActionCommand().equals(EVENT_SHUFFLE_MODE_STATUS_CHANGED)) {
     boolean b = ConfigurationManager.getBoolean(CONF_STATE_SHUFFLE);
     ConfigurationManager.setProperty(CONF_STATE_SHUFFLE, Boolean.toString(!b));
     JajukJMenuBar.getInstance().jcbmiShuffle.setSelected(!b);
     if (!b == true) { // enabled button
       CommandJPanel.getInstance().jbRandom.setBorder(BorderFactory.createLoweredBevelBorder());
       FIFO.getInstance().shuffle(); // shuffle current selection
     } else {
       CommandJPanel.getInstance().jbRandom.setBorder(BorderFactory.createRaisedBevelBorder());
     }
   } else if (e.getActionCommand().equals(EVENT_CONTINUE_MODE_STATUS_CHANGED)) {
     boolean bRepeat = ConfigurationManager.getBoolean(CONF_STATE_REPEAT);
     if (bRepeat) {
       // Repeat and continue can't be set together, so deselect repeat mode
       ConfigurationManager.setProperty(CONF_STATE_REPEAT, Boolean.toString(!bRepeat));
       JajukJMenuBar.getInstance().jcbmiRepeat.setSelected(false);
       CommandJPanel.getInstance().jbRepeat.setBorder(BorderFactory.createRaisedBevelBorder());
     }
     boolean b = ConfigurationManager.getBoolean(CONF_STATE_CONTINUE);
     ConfigurationManager.setProperty(CONF_STATE_CONTINUE, Boolean.toString(!b));
     JajukJMenuBar.getInstance().jcbmiContinue.setSelected(!b);
     if (!b == true) { // enabled button
       CommandJPanel.getInstance().jbContinue.setBorder(BorderFactory.createLoweredBevelBorder());
     } else {
       CommandJPanel.getInstance().jbContinue.setBorder(BorderFactory.createRaisedBevelBorder());
     }
   } else if (e.getActionCommand().equals(EVENT_INTRO_MODE_STATUS_CHANGED)) {
     boolean b =
         Boolean.valueOf(ConfigurationManager.getProperty(CONF_STATE_INTRO)).booleanValue();
     ConfigurationManager.setProperty(CONF_STATE_INTRO, Boolean.toString(!b));
     JajukJMenuBar.getInstance().jcbmiIntro.setSelected(!b);
     if (!b == true) { // enabled button
       CommandJPanel.getInstance().jbIntro.setBorder(BorderFactory.createLoweredBevelBorder());
     } else {
       CommandJPanel.getInstance().jbIntro.setBorder(BorderFactory.createRaisedBevelBorder());
     }
   } else if (e.getActionCommand().equals(EVENT_VIEW_SHOW_STATUS_CHANGED_REQUEST)) {
     if (((JCheckBoxMenuItem) e.getSource()).isSelected()) { // show view request
       ViewManager.notify(
           EVENT_VIEW_SHOW_REQUEST,
           (IView) JajukJMenuBar.getInstance().hmCheckboxView.get(e.getSource()));
     } else {
       ViewManager.notify(
           EVENT_VIEW_CLOSE_REQUEST,
           (IView) JajukJMenuBar.getInstance().hmCheckboxView.get(e.getSource()));
     }
   } else if (EVENT_HELP_REQUIRED.equals(e.getActionCommand())) {
     PerspectiveManager.setCurrentPerspective(PERSPECTIVE_NAME_HELP);
   }
 }
Пример #13
0
  /** First time wizard */
  public FirstTimeWizard() {
    super(Main.getWindow(), true); // make it modal
    setTitle(Messages.getString("FirstTimeWizard.0")); // $NON-NLS-1$
    setLocation(org.jajuk.Main.getWindow().getX() + 200, org.jajuk.Main.getWindow().getY() + 200);
    int iX_SEPARATOR = 5;
    int iY_SEPARATOR = 10;
    jlLeftIcon = new JLabel(Util.getResizedImage(Util.getIcon(IMAGES_SPLASHSCREEN), 300, 200));
    jpRightPanel = new JPanel();
    jlWelcome = new JLabel(Messages.getString("FirstTimeWizard.1")); // $NON-NLS-1$
    jlFileSelection = new JLabel(Messages.getString("FirstTimeWizard.2")); // $NON-NLS-1$
    jbFileSelection = new JButton(Util.getIcon(ICON_OPEN_FILE));
    jtfFileSelected = new JTextField(""); // $NON-NLS-1$
    jtfFileSelected.setForeground(Color.BLUE);
    jtfFileSelected.setEditable(false);
    jbFileSelection.addActionListener(this);
    jcbAutoCover = new JCheckBox(Messages.getString("FirstTimeWizard.3")); // $NON-NLS-1$
    // can't change auto-cover if not first connection
    if (ConfigurationManager.getBoolean(CONF_FIRST_CON)) {
      jcbAutoCover.setSelected(true);
    } else {
      jcbAutoCover.setVisible(false);
    }
    jcbHelp = new JCheckBox(Messages.getString("FirstTimeWizard.4")); // $NON-NLS-1$
    // buttons
    jpButtons = new JPanel();
    jpButtons.setLayout(new FlowLayout(FlowLayout.CENTER));
    jbOk = new JButton(Messages.getString("OK")); // $NON-NLS-1$
    jbOk.setEnabled(false);
    jbOk.addActionListener(this);
    jbCancel = new JButton(Messages.getString("Cancel")); // $NON-NLS-1$
    jbCancel.addActionListener(this);
    jpButtons.add(jbOk);
    jpButtons.add(jbCancel);
    double sizeRight[][] = {
      {0.99, iX_SEPARATOR},
      {
        iY_SEPARATOR,
        60,
        iY_SEPARATOR,
        30,
        iY_SEPARATOR,
        20,
        iY_SEPARATOR,
        40,
        iY_SEPARATOR,
        20,
        iY_SEPARATOR,
        40
      }
    };

    FlowLayout flSelection = new FlowLayout(FlowLayout.LEFT);
    JPanel jpFileSelection = new JPanel();
    jpFileSelection.setLayout(flSelection);
    jpFileSelection.add(jbFileSelection);
    jpFileSelection.add(Box.createHorizontalStrut(10));
    jpFileSelection.add(jlFileSelection);

    jpRightPanel.setLayout(new TableLayout(sizeRight));
    jpRightPanel.add(jlWelcome, "0,1"); // $NON-NLS-1$
    jpRightPanel.add(jpFileSelection, "0,3"); // $NON-NLS-1$
    jpRightPanel.add(jtfFileSelected, "0,5"); // $NON-NLS-1$
    jpRightPanel.add(jcbAutoCover, "0,7"); // $NON-NLS-1$
    jpRightPanel.add(jcbHelp, "0,9"); // $NON-NLS-1$
    jpRightPanel.add(jpButtons, "0,11"); // $NON-NLS-1$
    double size[][] = {{20, TableLayout.PREFERRED, 30, TableLayout.PREFERRED}, {0.99}};
    jpMain = (JPanel) getContentPane();
    jpMain.setLayout(new TableLayout(size));
    jpMain.add(jlLeftIcon, "1,0"); // $NON-NLS-1$
    jpMain.add(jpRightPanel, "3,0"); // $NON-NLS-1$
    getRootPane().setDefaultButton(jbOk);
  }
Пример #14
0
 public void actionPerformed(ActionEvent e) {
   if (e.getSource() == jbCancel) {
     dispose(); // close window
   } else if (e.getSource() == jbFileSelection) {
     JajukFileChooser jfc = new JajukFileChooser(new JajukFileFilter(true, false));
     jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
     jfc.setDialogTitle(Messages.getString("FirstTimeWizard.5")); // $NON-NLS-1$
     jfc.setMultiSelectionEnabled(false);
     int returnVal = jfc.showOpenDialog(this);
     if (returnVal == JFileChooser.APPROVE_OPTION) {
       fDir = jfc.getSelectedFile();
       // check device availibility
       String sCode =
           DeviceManager.getInstance()
               .checkDeviceAvailablity(
                   fDir.getName(), 0, fDir.getAbsolutePath(), fDir.getAbsolutePath());
       if (!sCode.equals("0")) { // $NON-NLS-1$
         Messages.showErrorMessage(sCode);
         jbOk.setEnabled(false);
         return;
       }
       jtfFileSelected.setText(fDir.getAbsolutePath());
       jbOk.setEnabled(true);
       jbOk.grabFocus();
     }
   } else if (e.getSource() == jbOk) {
     /*Set perspective to display. We differentiate first connection or not because
     during first connection, perspectives are not yet initialized, so we just tell it whish
     perspective to use at startup*/
     if (ConfigurationManager.getBoolean(CONF_FIRST_CON)) {
       if (jcbHelp.isSelected()) {
         // set parameter perspective
         Main.setDefaultPerspective(PERSPECTIVE_NAME_HELP);
       } else {
         // set physical perspective
         Main.setDefaultPerspective(PERSPECTIVE_NAME_PHYSICAL);
       }
     } else {
       // go to help perspective if required
       if (jcbHelp.isSelected()) {
         // set parameter perspective
         PerspectiveManager.setCurrentPerspective(PERSPECTIVE_NAME_HELP);
       }
     }
     // Set auto cover property
     ConfigurationManager.setProperty(
         CONF_COVERS_AUTO_COVER, Boolean.toString(jcbAutoCover.isSelected()));
     // Create a directory device
     Device device =
         DeviceManager.getInstance().registerDevice(fDir.getName(), 0, fDir.getAbsolutePath());
     device.setProperty(XML_DEVICE_MOUNT_POINT, fDir.getAbsolutePath());
     device.setProperty(XML_DEVICE_AUTO_MOUNT, true);
     // as we don't know type of device, no auto-refresh (can cause network bandwith use for
     // network drive)
     device.setProperty(XML_DEVICE_AUTO_REFRESH, 0d);
     try {
       device.refresh(true);
     } catch (Exception e2) {
       Log.error("112", device.getName(), e2); // $NON-NLS-1$
       Messages.showErrorMessage("112", device.getName()); // $NON-NLS-1$
     }
     // exit
     dispose();
   }
 }
Пример #15
0
  /*
   * (non-Javadoc)
   *
   * @see org.jajuk.ui.views.IView#populate()
   */
  public void initUI() {
    jlLanguage = new JLabel(Messages.getString("WikipediaView.1"));
    jcbLanguage = new JComboBox();
    for (String sDesc : Messages.getDescs()) {
      jcbLanguage.addItem(sDesc);
    }
    // get stored language
    jcbLanguage.setSelectedItem(
        Messages.getDescForLocal(ConfigurationManager.getProperty(CONF_WIKIPEDIA_LANGUAGE)));
    jcbLanguage.addActionListener(this);
    // Buttons
    ActionBase aCopy = ActionManager.getAction(JajukAction.COPY_TO_CLIPBOARD);
    jbCopy = new JButton(aCopy);
    jbLaunchInExternalBrowser = new JButton(ActionManager.getAction(JajukAction.LAUNCH_IN_BROWSER));
    // Remove text inside the buttons
    jbLaunchInExternalBrowser.setText(null);
    jbCopy.setText(null);
    ButtonGroup bg = new ButtonGroup();
    jbAuthorSearch = new JToggleButton(IconLoader.ICON_AUTHOR, false);
    jbAuthorSearch.setToolTipText(Messages.getString("WikipediaView.5"));
    // Select author search (default)
    jbAuthorSearch.setSelected(true);
    jbAuthorSearch.addActionListener(this);
    jbAlbumSearch = new JToggleButton(IconLoader.ICON_ALBUM, true);
    jbAlbumSearch.setToolTipText(Messages.getString("WikipediaView.6"));
    jbAlbumSearch.addActionListener(this);
    jbTrackSearch = new JToggleButton(IconLoader.ICON_TRACK, false);
    jbTrackSearch.setToolTipText(Messages.getString("WikipediaView.7"));
    jbTrackSearch.addActionListener(this);
    // Group this three mutual exclusive buttons
    bg.add(jbAuthorSearch);
    bg.add(jbAlbumSearch);
    bg.add(jbTrackSearch);

    JToolBar jtb = new JToolBar();
    jtb.setFloatable(false);
    jtb.setRollover(true);
    jtb.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
    // Add items
    jtb.add(jbAuthorSearch);
    jtb.add(jbAlbumSearch);
    jtb.add(jbTrackSearch);
    jtb.addSeparator();
    jtb.add(jbCopy);
    jtb.add(jbLaunchInExternalBrowser);
    jtb.addSeparator();
    jtb.add(jcbLanguage);

    JPanel jpCommand = new JPanel();
    jpCommand.setBorder(BorderFactory.createEtchedBorder());
    jpCommand.setLayout(new FlowLayout(FlowLayout.LEFT));
    jpCommand.add(jtb);

    // global layout
    double size[][] = {{2, TableLayout.FILL, 5}, {TableLayout.PREFERRED, 5, TableLayout.FILL}};
    setLayout(new TableLayout(size));
    browser = new JajukHtmlPanel();
    add(jpCommand, "1,0");
    add(browser, "1,2");

    // Display default page at startup is none track launch
    // avoid to launch this if a track is playing
    // to avoid thread concurrency
    if (FIFO.getInstance().getCurrentFile() == null) {
      reset();
    }

    // subscriptions to events
    ObservationManager.register(WikipediaView.this);

    // force event
    update(
        new Event(
            EventSubject.EVENT_FILE_LAUNCHED,
            ObservationManager.getDetailsLastOccurence(EventSubject.EVENT_FILE_LAUNCHED)));
  }