1 /* 2 * aTunes 3 * Copyright (C) Alex Aranda, Sylvain Gaudard and contributors 4 * 5 * See http://www.atunes.org/wiki/index.php?title=Contributing for information about contributors 6 * 7 * http://www.atunes.org 8 * http://sourceforge.net/projects/atunes 9 * 10 * This program is free software; you can redistribute it and/or 11 * modify it under the terms of the GNU General Public License 12 * as published by the Free Software Foundation; either version 2 13 * of the License, or (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU General Public License for more details. 19 */ 20 21 package net.sourceforge.atunes.gui.views.dialogs.properties; 22 23 import java.awt.GridBagConstraints; 24 import java.awt.GridBagLayout; 25 import java.awt.Insets; 26 import java.awt.event.ActionEvent; 27 import java.awt.event.ActionListener; 28 29 import javax.swing.JButton; 30 import javax.swing.JLabel; 31 import javax.swing.JPanel; 32 33 import net.sourceforge.atunes.kernel.modules.tags.EditTagDialogController; 34 import net.sourceforge.atunes.model.IAudioObject; 35 import net.sourceforge.atunes.model.IBeanFactory; 36 import net.sourceforge.atunes.model.IControlsBuilder; 37 import net.sourceforge.atunes.model.IFileManager; 38 import net.sourceforge.atunes.model.IFrame; 39 import net.sourceforge.atunes.model.ILocalAudioObject; 40 import net.sourceforge.atunes.model.ILookAndFeel; 41 import net.sourceforge.atunes.model.IUnknownObjectChecker; 42 import net.sourceforge.atunes.utils.I18nUtils; 43 import net.sourceforge.atunes.utils.StringUtils; 44 import net.sourceforge.atunes.utils.TimeUtils; 45 46 /** 47 * The properties dialog for audio files 48 */ 49 public final class LocalAudioObjectPropertiesDialog extends 50 AudioObjectPropertiesDialog { 51 52 private static final long serialVersionUID = 7504320983331038543L; 53 54 private JLabel pictureLabel; 55 private ProviderLabel fileNameLabel; 56 private ProviderLabel pathLabel; 57 private ProviderLabel songLabel; 58 private ProviderLabel artistLabel; 59 private ProviderLabel albumArtistLabel; 60 private JLabel composerLabel; 61 private ProviderLabel albumLabel; 62 private JLabel durationLabel; 63 private JLabel trackLabel; 64 private JLabel discNumberLabel; 65 private JLabel yearLabel; 66 private JLabel genreLabel; 67 private JLabel bitrateLabel; 68 private JLabel frequencyLabel; 69 private ILocalAudioObject file; 70 71 private IUnknownObjectChecker unknownObjectChecker; 72 73 private IBeanFactory beanFactory; 74 75 private IFileManager fileManager; 76 77 /** 78 * @param fileManager 79 */ setFileManager(final IFileManager fileManager)80 public void setFileManager(final IFileManager fileManager) { 81 this.fileManager = fileManager; 82 } 83 84 /** 85 * @param beanFactory 86 */ setBeanFactory(final IBeanFactory beanFactory)87 public void setBeanFactory(final IBeanFactory beanFactory) { 88 this.beanFactory = beanFactory; 89 } 90 91 /** 92 * @param unknownObjectChecker 93 */ setUnknownObjectChecker( final IUnknownObjectChecker unknownObjectChecker)94 public void setUnknownObjectChecker( 95 final IUnknownObjectChecker unknownObjectChecker) { 96 this.unknownObjectChecker = unknownObjectChecker; 97 } 98 99 /** 100 * Instantiates a new audio file properties dialog. 101 * 102 * @param frame 103 * @param controlsBuilder 104 */ LocalAudioObjectPropertiesDialog(final IFrame frame, final IControlsBuilder controlsBuilder)105 LocalAudioObjectPropertiesDialog(final IFrame frame, 106 final IControlsBuilder controlsBuilder) { 107 super(frame, controlsBuilder); 108 } 109 110 @Override setAudioObject(final IAudioObject audioObject)111 public void setAudioObject(final IAudioObject audioObject) { 112 if (audioObject instanceof ILocalAudioObject) { 113 this.file = (ILocalAudioObject) audioObject; 114 addContent(getLookAndFeel()); 115 setContent(); 116 this.pack(); 117 } else { 118 throw new IllegalArgumentException("Not a ILocalAudioObject"); 119 } 120 } 121 122 /** 123 * @param file 124 */ setFile(final ILocalAudioObject file)125 public void setFile(final ILocalAudioObject file) { 126 this.file = file; 127 setTitle(getTitleText(file)); 128 } 129 130 /** 131 * Gives a title for dialog. 132 * 133 * @param file 134 * the file 135 * 136 * @return title for dialog 137 */ getTitleText(final ILocalAudioObject file)138 private String getTitleText(final ILocalAudioObject file) { 139 return StringUtils.getString(I18nUtils.getString("INFO_OF_FILE"), " ", 140 this.fileManager.getFileName(file)); 141 } 142 143 /** 144 * Adds the content. 145 * 146 * @param lookAndFeel 147 */ addContent(final ILookAndFeel lookAndFeel)148 private void addContent(final ILookAndFeel lookAndFeel) { 149 JPanel panel = new JPanel(new GridBagLayout()); 150 151 this.pictureLabel = new JLabel(); 152 this.songLabel = new ProviderLabel(new SongProvider(), 153 getControlsBuilder()); 154 this.songLabel.setFont(lookAndFeel.getPropertiesDialogBigFont()); 155 this.artistLabel = new ProviderLabel(new ArtistProvider( 156 this.unknownObjectChecker), getControlsBuilder()); 157 this.artistLabel.setFont(lookAndFeel.getPropertiesDialogBigFont()); 158 this.albumArtistLabel = new ProviderLabel(new AlbumArtistProvider( 159 this.unknownObjectChecker), getControlsBuilder()); 160 this.albumArtistLabel.setFont(lookAndFeel.getPropertiesDialogBigFont()); 161 this.albumLabel = new ProviderLabel(new AlbumProvider( 162 this.unknownObjectChecker), getControlsBuilder()); 163 this.albumLabel.setFont(lookAndFeel.getPropertiesDialogBigFont()); 164 this.fileNameLabel = new ProviderLabel(new FileNameProvider( 165 this.fileManager), getControlsBuilder()); 166 this.pathLabel = new ProviderLabel(new FilePathProvider( 167 this.fileManager), getControlsBuilder()); 168 this.durationLabel = new JLabel(); 169 this.trackLabel = new JLabel(); 170 this.discNumberLabel = new JLabel(); 171 this.genreLabel = new JLabel(); 172 this.yearLabel = new JLabel(); 173 this.composerLabel = new JLabel(); 174 this.bitrateLabel = new JLabel(); 175 this.frequencyLabel = new JLabel(); 176 177 JButton editTagsButton = new JButton(); 178 editTagsButton.setText(I18nUtils.getString("EDIT_TAG")); 179 editTagsButton.addActionListener(new ActionListener() { 180 @Override 181 public void actionPerformed(final ActionEvent evt) { 182 EditTagDialogController ctl = LocalAudioObjectPropertiesDialog.this.beanFactory 183 .getBean(EditTagDialogController.class); 184 ctl.editFiles(java.util.Collections 185 .singletonList(LocalAudioObjectPropertiesDialog.this.file)); 186 } 187 }); 188 189 setLayout(panel, editTagsButton); 190 191 add(panel); 192 } 193 194 /** 195 * @param panel 196 * @param editTagsButton 197 */ setLayout(final JPanel panel, final JButton editTagsButton)198 private void setLayout(final JPanel panel, final JButton editTagsButton) { 199 GridBagConstraints c = new GridBagConstraints(); 200 c.gridx = 0; 201 c.gridy = 0; 202 c.gridheight = 4; 203 c.insets = new Insets(15, 20, 5, 0); 204 c.anchor = GridBagConstraints.CENTER; 205 c.fill = GridBagConstraints.NONE; 206 panel.add(this.pictureLabel, c); 207 208 c.gridx = 1; 209 c.gridy = 0; 210 c.gridheight = 1; 211 c.weightx = 1; 212 c.fill = GridBagConstraints.HORIZONTAL; 213 c.insets = new Insets(15, 20, 0, 20); 214 panel.add(this.songLabel, c); 215 216 c.gridy = 1; 217 panel.add(this.artistLabel, c); 218 219 c.gridy = 2; 220 panel.add(this.albumArtistLabel, c); 221 222 c.gridy = 3; 223 panel.add(this.albumLabel, c); 224 225 c.gridy = 4; 226 panel.add(this.fileNameLabel, c); 227 228 c.gridy = 5; 229 panel.add(this.pathLabel, c); 230 231 c.gridy = 6; 232 panel.add(this.durationLabel, c); 233 234 c.gridy = 7; 235 panel.add(this.trackLabel, c); 236 237 c.gridy = 8; 238 panel.add(this.discNumberLabel, c); 239 240 c.gridy = 9; 241 panel.add(this.genreLabel, c); 242 243 c.gridy = 10; 244 panel.add(this.yearLabel, c); 245 246 c.gridy = 11; 247 panel.add(this.composerLabel, c); 248 249 c.gridy = 12; 250 panel.add(this.bitrateLabel, c); 251 252 c.gridy = 13; 253 panel.add(this.frequencyLabel, c); 254 255 c.gridx = 0; 256 c.gridy = 14; 257 c.insets = new Insets(10, 5, 15, 10); 258 c.gridwidth = 2; 259 c.fill = GridBagConstraints.NONE; 260 panel.add(editTagsButton, c); 261 } 262 263 /** 264 * Fill picture. 265 */ fillPicture()266 private void fillPicture() { 267 FillPictureBackgroundWorker worker = this.beanFactory 268 .getBean(FillPictureBackgroundWorker.class); 269 worker.setPictureLabel(this.pictureLabel); 270 worker.setFile(this.file); 271 worker.execute(); 272 } 273 274 /** 275 * Sets the content. 276 */ setContent()277 private void setContent() { 278 fillPicture(); 279 this.songLabel.fillText(this.file); 280 this.artistLabel.fillText(this.file); 281 this.albumArtistLabel.fillText(this.file); 282 this.albumLabel.fillText(this.file); 283 this.fileNameLabel.fillText(this.file); 284 this.pathLabel.fillText(this.file); 285 286 this.durationLabel 287 .setText(getHtmlFormatted(I18nUtils.getString("DURATION"), 288 TimeUtils.secondsToHoursMinutesSeconds(this.file 289 .getDuration()))); 290 this.trackLabel.setText(getHtmlFormatted( 291 I18nUtils.getString("TRACK"), 292 this.file.getTrackNumber() > 0 ? String.valueOf(this.file 293 .getTrackNumber()) : "-")); 294 this.discNumberLabel.setText(getHtmlFormatted( 295 I18nUtils.getString("DISC_NUMBER"), 296 this.file.getDiscNumber() > 0 ? String.valueOf(this.file 297 .getDiscNumber()) : "-")); 298 this.genreLabel.setText(getHtmlFormatted( 299 I18nUtils.getString("GENRE"), 300 StringUtils.isEmpty(this.file 301 .getGenre(this.unknownObjectChecker)) ? "-" : this.file 302 .getGenre(this.unknownObjectChecker))); 303 this.yearLabel.setText(getHtmlFormatted( 304 I18nUtils.getString("YEAR"), 305 StringUtils.getNumberOrZero(this.file 306 .getYear(this.unknownObjectChecker)) > 0 ? this.file 307 .getYear(this.unknownObjectChecker) : "-")); 308 this.composerLabel.setText(getHtmlFormatted(I18nUtils 309 .getString("COMPOSER"), StringUtils.isEmpty(this.file 310 .getComposer()) ? "-" : this.file.getComposer())); 311 this.bitrateLabel.setText(getHtmlFormatted(I18nUtils 312 .getString("BITRATE"), StringUtils.getString( 313 Long.toString(this.file.getBitrate()), " Kbps"))); 314 this.frequencyLabel.setText(getHtmlFormatted( 315 I18nUtils.getString("FREQUENCY"), 316 StringUtils.getString( 317 Integer.toString(this.file.getFrequency()), " Hz"))); 318 } 319 } 320