/*
* Copyright (C) 2007 Tobias Winterhalter ([email protected])
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package dplayer;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import org.apache.log4j.PropertyConfigurator;
/**
* Collection of settings.
*
* @author Tobias Winterhalter
*/
public class Settings {
protected enum OsType {
GENERIC, LINUX, WIN
}
/**
* Name of properties file.
*/
private static final String FILENAME = "dplayer.properties";
/**
* Singleton instance, created at class loading time.
*/
private static final Settings sInstance = new Settings();
/**
* Property for main window's horizontal position on the screen (int value).
*/
public static final Property WINDOW_X = new Property("window.x", "0");
/**
* Property for main window's vertical position on the screen (int value).
*/
public static final Property WINDOW_Y = new Property("window.y", "0");
/**
* Property for main window's width (int value).
*/
public static final Property WINDOW_W = new Property("window.w", "640");
/**
* Property for main window's height (int value).
*/
public static final Property WINDOW_H = new Property("window.h", "480");
public static final Property WINDOW_MAXIMIZED = new Property("window.maximized", "false");
public static final Property WINDOW_MINIMIZED = new Property("window.minimized", "false");
public static final Property TABLE_COLUMN1_W = new Property("table.column1.w", "200");
public static final Property TABLE_COLUMN2_W = new Property("table.column2.w", "80");
public static final Property TREE_W = new Property("tree.w", "30");
public static final Property VOLUME = new Property("volume", "40");
public static final Property ROOTS = new Property("roots", "List of roots to be searched for music files.", "");
public static final Property MIXER = new Property("mixer", "Media mixer to use for volume control.", "xmix");
public static final Property PLAYER = new Property("player", "Media player to use for playback.", "mplayer");
public static final Property DISPLAY_SKIPPED = new Property("display.skipped", "Display (or hide) tracks that are marked to be skipped by player.", "false");
public static final Property DISPLAY_COVER = new Property("display.cover", "Try to display cover as background of track table.", "true");
public static final Property LOG_ROOT_LOGGER = new Property("log4j.rootLogger", "INFO, STDOUT");
public static final Property LOG_APPENDER = new Property("log4j.appender.STDOUT", "org.apache.log4j.ConsoleAppender");
public static final Property LOG_LAYOUT = new Property("log4j.appender.STDOUT.layout", "org.apache.log4j.PatternLayout");
public static final Property LOG_PATTERN = new Property("log4j.appender.STDOUT.layout.ConversionPattern", "%-4r %-5p [%t] %c - %m%n");
public static final Property CACHE_ENABLED = new Property("cache.enabled", "Enable caching of music file properties (e.g. tags, 'skip' flag, ...).", "true");
public static final Property CACHE_SONGS_FILE = new Property("cache.songs.file", "File for music file cache.", "songs.db");
public static final Property HISTORY_LAST_DIR = new Property("history.last.dir", "");
/*
* Define sections.
*/
static {
addSection("Manual settings.", 100, new Property[] {
ROOTS, PLAYER, MIXER, DISPLAY_SKIPPED, DISPLAY_COVER });
addSection("Cache settings.", 90, new Property[] {
CACHE_ENABLED, CACHE_SONGS_FILE });
addSection("Automatic settings - will be overwritten when application is closed.", 30, new Property[] {
VOLUME, TREE_W, TABLE_COLUMN1_W, TABLE_COLUMN2_W, WINDOW_X, WINDOW_Y, WINDOW_W, WINDOW_H, WINDOW_MAXIMIZED, WINDOW_MINIMIZED, HISTORY_LAST_DIR });
addSection("Log4j settings.", 0, new Property[] {
LOG_ROOT_LOGGER, LOG_APPENDER, LOG_LAYOUT, LOG_PATTERN });
}
/**
* Store actual list of properties.
*/
private final Properties mProperties;
/**
* Create and initialize (read from file) properties.
*/
protected Settings() {
mProperties = new Properties();
try {
mProperties.load(new FileInputStream(FILENAME));
PropertyConfigurator.configure(mProperties);
} catch (IOException e) {
// No properties file. Continue with defaults.
}
}
/**
* Save properties. Failure to save is not considered as serious problem
* and a warning message is logged only.
*/
public static void save() {
BufferedWriter out = null;
BufferedReader in = null;
try {
// Open new temporary output file. Make sure it doesn't exist already.
final File outFile = new File("~" + FILENAME);
if (outFile.exists()) {
if (!outFile.delete()) {
throw new IOException("Unable to delete temporary properties file " + outFile.getPath() + ".");
}
}
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile)));
// Open and read current properties file.
final File inFile = new File(FILENAME);
if (inFile.exists()) {
in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile)));
final Properties p = new Properties();
String line;
while ((line = in.readLine()) != null) {
// Keep empty lines and comments.
if (line.trim().length() == 0
|| line.startsWith("#")) {
out.write(line);
out.newLine();
}
// Parse line with property definition.
p.clear();
p.load(new ByteArrayInputStream(line.getBytes()));
for (Object key : p.keySet()) {
if (sInstance.mProperties.get(key) != null) {
// Output property with current value;
out.write((String) key + " = " + sInstance.mProperties.get(key));
out.newLine();
} else {
// Property seems to be removed. Don't output it anymore.
}
}
}
in.close();
// Note: New runtime properties are not supported and simply ignored.
} else {
// Write ne
没有合适的资源?快使用搜索试试~ 我知道了~
简约的java音乐播放器
共96个文件
java:35个
png:27个
so:16个
4星 · 超过85%的资源 需积分: 8 271 下载量 154 浏览量
2009-02-07
18:40:25
上传
评论 4
收藏 4.21MB ZIP 举报
温馨提示
简约的java音乐播放器 有研究或探讨的请加群:37424970 或联系本人MSN或邮箱:[email protected]
资源详情
资源评论
资源推荐
收起资源包目录
java音乐播放器.zip (96个子文件)
build.xml 4KB
dist
linux
launch4l-dplayer.xml 1KB
win
launch4j-dplayer.xml 1KB
dpalyer.ico 1KB
src
dplayer
Settings.java 17KB
ABOUT 2KB
model
DirectoryChangedListener.java 924B
Song.java 4KB
PlayerEventListener.java 1KB
cache
SongManager.java 3KB
CacheManager.java 1KB
Directory.java 8KB
PlayerEventAdapter.java 2KB
Location.java 1KB
RepeatMode.java 840B
Player.java 11KB
SongExt.java 3KB
PlayerList.java 4KB
media
MediaPlayerListener.java 936B
MediaPlayerFactory.java 2KB
MediaMixer.java 911B
MediaPlayer.java 1KB
MPlayer.java 7KB
MediaMixerFactory.java 1KB
TODO 983B
LICENSE 18KB
LICENSE_SHORT 660B
About.java 2KB
gui
Cursors.java 1KB
MainArea.java 14KB
Controller.java 6KB
icons
my-playback-start.png 444B
system-log-out.png 799B
my-repeat-none.png 359B
folder-open.png 535B
my-skip-backward.png 504B
my-playback-paused.png 270B
my-repeat-one.png 367B
my-skip-forward.png 509B
my-playback-stop.png 321B
my-shuffle-off.png 347B
dialog-warning.png 512B
dialog-information.png 666B
media-skip-backward.png 511B
my-shuffle-on.png 349B
list-remove.png 243B
face-monkey.png 786B
media-playback-stop.png 286B
media-playback-start.png 469B
my-playback-started.png 322B
dialog-error.png 697B
media-playback-pause.png 336B
media-eject.png 431B
list-add.png 384B
Icons.java 4KB
my-playback-pause.png 374B
my-repeat-all.png 360B
media-skip-forward.png 540B
view-refresh.png 848B
StatusBar.java 4KB
AboutDialog.java 8KB
Launcher.java 3KB
i18n
I18N.java 3KB
dplayer_de_DE.properties 761B
MenuFactory.java 8KB
Utils.java 2KB
ToolBar.java 11KB
TrayIcon.java 6KB
MainShell.java 9KB
widgets
LabelProgressBar.java 4KB
CommandFactory.java 9KB
lib
libswt-mozilla-gcc3-gtk-3236.so 77KB
libswt-glx-gtk-3236.so 10KB
libswt-mozilla-gtk-3236.so 76KB
swt-gdip-win32-3236.dll 72KB
swt-awt-win32-3236.dll 32KB
libswt-cairo-gtk-3236.so 38KB
libswt-mozilla18-profile-gtk-3236.so 17KB
libcairo-swt.so 260KB
libswt-mozilla18-profile-gcc3-gtk-3236.so 18KB
swt-wgl-win32-3236.dll 40KB
db4o-6.1-java5.jar 705KB
libswt-mozilla14-profile-gcc3-gtk-3236.so 35KB
log4j-1.2.8.jar 344KB
swt-win32-3236.dll 320KB
entagged-audioformats-0.15.jar 149KB
libswt-atk-gtk-3236.so 23KB
libswt-mozilla17-profile-gcc3-gtk-3236.so 20KB
libswt-gtk-3236.so 156KB
swt-win.jar 1.42MB
libswt-pi-gtk-3236.so 302KB
libswt-awt-gtk-3236.so 4KB
libswt-mozilla14-profile-gtk-3236.so 35KB
swt-linux.jar 1.36MB
libswt-gnome-gtk-3236.so 10KB
libswt-mozilla17-profile-gtk-3236.so 20KB
共 96 条
- 1
zhuseahui
- 粉丝: 63
- 资源: 419
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论2