Sprachdatei integriert

PluginActivity hinzugefügt
LookAndFeel geändert

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@3 ebf7c1c2-ba36-0410-9fe8-c592906822b4
This commit is contained in:
astaldo 2007-08-03 11:25:22 +00:00
parent c44a78b069
commit fcb8b0284e
10 changed files with 388 additions and 40 deletions

View File

@ -0,0 +1,6 @@
label.tab.download = Download Liste
label.tab.plugin_activity = Plugin Aktivitäten
label.tab.download.column_link = Download
label.tab.download.column_host = Host
label.tab.plugin_activity.column_plugin = Name
label.tab.plugin_activity.column_progress = Fortschritt

29
build.xml Normal file
View File

@ -0,0 +1,29 @@
<project default="jar" basedir=".">
<property name="cls" value="bin" />
<target name="jar">
<manifest file="Manifest.MF">
<attribute name="Created-By" value="astaldo"/>
<attribute name="Main-Class" value="jd.Main"/>
</manifest>
<jar jarfile="JDownloader.jar" manifest="Manifest.MF">
<fileset dir="${cls}">
<include name = "**/*.class" />
<exclude name = "jd/plugins/decrypt/**"/>
<exclude name = "jd/plugins/host/**"/>
</fileset>
<fileset dir="." includes="GIF/**"/>
<fileset dir="." includes="*.properties"/>
</jar>
<delete file="Manifest.MF" failonerror="false" />
<jar jarfile="JDownloaderPlugins.jar">
<fileset dir="${cls}">
<include name = "jd/plugins/decrypt/**"/>
<include name = "jd/plugins/host/**"/>
</fileset>
<fileset dir="." includes="META-INF/services/*"/>
</jar>
</target>
</project>

View File

@ -1,6 +1,11 @@
package jd;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import jd.gui.MainWindow;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;
/**
* Start der Applikation
*
@ -12,6 +17,11 @@ public class Main {
main.go();
}
private void go(){
try {
UIManager.setLookAndFeel(new WindowsLookAndFeel());
}
catch (UnsupportedLookAndFeelException e) {}
MainWindow mainWindow = new MainWindow();
mainWindow.setVisible(true);
}

View File

@ -19,12 +19,11 @@ import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.JToolBar;
import javax.swing.event.TableModelEvent;
import jd.plugins.DownloadLink;
import jd.plugins.Plugin;
@ -42,6 +41,10 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
private static final long serialVersionUID = 3966433144683787356L;
private static final StringSelection JDOWNLOADER_ID = new StringSelection("JDownloader active");
/**
* Die Menüleiste
*/
private JMenuBar menuBar = new JMenuBar();
/**
* Toolleiste für Knöpfe
*/
@ -49,15 +52,11 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
/**
* Tabelle mit den Downloadlinks
*/
private DownloadLinkTable downloadLinkTable = new DownloadLinkTable();
private TabDownloadLinks downloadLinks = new TabDownloadLinks();
/**
* Scrollkomponente für die Tabelle
*/
private JScrollPane scrollPane = new JScrollPane(downloadLinkTable);
/**
* Fortschrittsanzeige
*/
private JProgressBar progressBar = new JProgressBar();
private JScrollPane scrollPane = new JScrollPane(downloadLinks);
/**
* Hier werden alle vorhandenen Plugins zum Dekodieren von Links gespeichert
*/
@ -73,12 +72,16 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
/**
* Logger für Meldungen des Programmes
*/
private Logger logger = Logger.getLogger(Plugin.LOGGER_NAME);
private JTabbedPane tabbedPane = new JTabbedPane();
private JPanel panelForDownloadTable = new JPanel();
private JPanel panelForPluginsHost = new JPanel();
private JPanel panelForPluginsDecrypt = new JPanel();
private Logger logger = Plugin.getLogger();
/**
* Komponente, die den Fortschritt aller Plugins anzeigt
*/
private TabPluginActivity tabPluginActivity = new TabPluginActivity();
/**
* TabbedPane
*/
private JTabbedPane tabbedPane = new JTabbedPane();
private JPanel panelForDownloadTable = new JPanel();
private JButton start;
/**
* Das Hauptfenster wird erstellt
@ -100,11 +103,8 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
panelForDownloadTable = new JPanel(new BorderLayout());
panelForDownloadTable.add(scrollPane);
tabbedPane.addTab("Downloads", panelForDownloadTable);
tabbedPane.addTab("Anbieter-Plugins", panelForPluginsHost);
tabbedPane.addTab("Entschlüssel-Plugins", panelForPluginsDecrypt);
progressBar.setStringPainted(true);
tabbedPane.addTab(Utilities.getResourceString("label.tab.download"), panelForDownloadTable);
tabbedPane.addTab(Utilities.getResourceString("label.tab.plugin_activity"), tabPluginActivity);
start = new JButton(images.get("start"));
start.setFocusPainted(false);start.setBorderPainted(false);
@ -115,7 +115,7 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
setLayout(new GridBagLayout());
Utilities.addToGridBag(this, toolBar, 0, 0, 1, 1, 0, 0, null, GridBagConstraints.HORIZONTAL, GridBagConstraints.NORTH);
Utilities.addToGridBag(this, tabbedPane, 0, 1, 1, 1, 1, 1, null, GridBagConstraints.BOTH, GridBagConstraints.CENTER);
Utilities.addToGridBag(this, progressBar, 0, 2, 1, 1, 1, 1, null, GridBagConstraints.HORIZONTAL, GridBagConstraints.SOUTH);
setJMenuBar(menuBar);
}
/**
* Die Bilder werden aus der JAR Datei nachgeladen
@ -138,6 +138,8 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
PluginForDecrypt p = (PluginForDecrypt) iterator.next();
pluginsForDecrypt.add(p);
p.addPluginListener(this);
p.addPluginListener(tabPluginActivity);
logger.info("Decrypt-Plugin:"+p.getPluginName());
}
//Danach die Plugins der verschiedenen Anbieter
@ -147,22 +149,14 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
PluginForHost p = (PluginForHost) iterator.next();
pluginsForHost.add(p);
p.addPluginListener(this);
p.addPluginListener(tabPluginActivity);
logger.info("Host-Plugin:"+p.getPluginName());
}
}
/**
* Reagiert auf Pluginevents
*/
public void pluginEvent(PluginEvent event) {
switch(event.getEventID()){
case PluginEvent.PLUGIN_PROGRESS_MAX:
progressBar.setMaximum((Integer)event.getParameter());
repaint();
break;
case PluginEvent.PLUGIN_PROGRESS_INCREASE:
progressBar.setValue(progressBar.getValue()+1);
repaint();
break;
}
}
public void lostOwnership(Clipboard clipboard, Transferable contents) {
new ClipboardHandler().start();
@ -245,8 +239,8 @@ public class MainWindow extends JFrame implements PluginListener, ClipboardOwner
}
if(links!=null && links.size()>0){
downloadLinkTable.addLinks(links);
downloadLinkTable.tableChanged(new TableModelEvent(downloadLinkTable.getModel()));
downloadLinks.addLinks(links);
downloadLinks.fireTableChanged();
}
}
}

View File

@ -2,6 +2,7 @@ package jd.gui;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;
@ -12,7 +13,7 @@ import jd.plugins.DownloadLink;
*
* @author astaldo
*/
public class DownloadLinkTable extends JTable{
public class TabDownloadLinks extends JPanel{
/**
* serialVersionUID
*/
@ -20,13 +21,15 @@ public class DownloadLinkTable extends JTable{
/**
* Dieser Vector enthält alle Downloadlinks
*/
private JTable table;
private Vector<DownloadLink> allLinks = new Vector<DownloadLink>();
/**
* Erstellt eine neue Tabelle
*/
public DownloadLinkTable(){
public TabDownloadLinks(){
super();
setModel(new InternalTableModel());
table = new JTable();
table.setModel(new InternalTableModel());
}
/**
* Hier werden Links zu dieser Tabelle hinzugefügt.
@ -35,7 +38,10 @@ public class DownloadLinkTable extends JTable{
*/
public void addLinks(Vector<DownloadLink> links){
allLinks.addAll(links);
tableChanged(new TableModelEvent(getModel()));
table.tableChanged(new TableModelEvent(table.getModel()));
}
public void fireTableChanged(){
table.tableChanged(new TableModelEvent(table.getModel()));
}
/**
* Dieses TableModel sorgt dafür, daß die Daten der Downloadlinks korrekt dargestellt werden
@ -47,11 +53,13 @@ public class DownloadLinkTable extends JTable{
* serialVersionUID
*/
private static final long serialVersionUID = -357970066822953957L;
private String labelLink = Utilities.getResourceString("label.tab.download.column_link");
private String labelHost = Utilities.getResourceString("label.tab.download.column_host");
@Override
public String getColumnName(int column) {
switch(column){
case 0: return "DL Link";
case 1: return "Host";
case 0: return labelLink;
case 1: return labelHost;
}
return null;
}

View File

@ -0,0 +1,179 @@
package jd.gui;
import java.awt.BorderLayout;
import java.awt.Component;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.event.TableModelEvent;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableCellRenderer;
import jd.plugins.Plugin;
import jd.plugins.event.PluginEvent;
import jd.plugins.event.PluginListener;
/**
* Diese Klasse zeigt alle Fortschritte von momenten aktiven Plugins an.
*
* @author astaldo
*/
public class TabPluginActivity extends JPanel implements PluginListener{
/**
* serialVersionUID
*/
private static final long serialVersionUID = -8537543161116653345L;
/**
* Die Tabelle für die Pluginaktivitäten
*/
private JTable table;
/**
* Hier werden alle Fortschritte der Plugins gespeichert
*/
private Vector<PluginProgress> pluginProgresses = new Vector<PluginProgress>();
public TabPluginActivity(){
setLayout(new BorderLayout());
table = new JTable();
table.setModel(new InternalTableModel());
table.getColumn(table.getColumnName(1)).setCellRenderer(new ProgressBarRenderer());
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);
}
/**
* Hier kann man auf Ereignisse der Plugins reagieren
*/
public void pluginEvent(PluginEvent event) {
PluginProgress pluginProgress = null;
// Gibts das Plugin bereits?
for(int i=0;i<pluginProgresses.size();i++){
if(pluginProgresses.elementAt(i).plugin == event.getSource()){
pluginProgress = pluginProgresses.elementAt(i);
break;
}
}
// Falls nicht, muß ein beschreibendes Objekt neu angelegt werden
if(pluginProgress == null){
pluginProgress = new PluginProgress(event.getSource());
pluginProgresses.add(pluginProgress);
}
//Hier werden die Ereignisse interpretiert
switch(event.getEventID()){
case PluginEvent.PLUGIN_PROGRESS_MAX:
pluginProgress.setMaximum((Integer)event.getParameter());
break;
case PluginEvent.PLUGIN_PROGRESS_INCREASE:
pluginProgress.increaseValue();
break;
case PluginEvent.PLUGIN_PROGRESS_FINISH:
break;
}
table.tableChanged(new TableModelEvent(table.getModel()));
}
/**
* Das TableModel ist notwendig, um die Daten darzustellen
*
* @author astaldo
*/
private class InternalTableModel extends AbstractTableModel{
/**
* serialVersionUID
*/
private static final long serialVersionUID = 8135707376690458846L;
/**
* Bezeichnung der Spalte für den Pluginnamen
*/
private String labelColumnName = Utilities.getResourceString("label.tab.plugin_activity.column_plugin");
/**
* Bezeichnung der Spalte für die Fortschrittsanzeige
*/
private String labelColumnProgress = Utilities.getResourceString("label.tab.plugin_activity.column_progress");
public Class<?> getColumnClass(int columnIndex) {
switch(columnIndex){
case 0: return String.class;
case 1: return JProgressBar.class;
}
return String.class;
}
public int getColumnCount() {
return 2;
}
public int getRowCount() {
return pluginProgresses.size();
}
public Object getValueAt(int rowIndex, int columnIndex) {
PluginProgress p = pluginProgresses.elementAt(rowIndex);
switch(columnIndex){
case 0: return p.plugin.getPluginName();
case 1: return p.progressBar;
}
return null;
}
public String getColumnName(int column) {
switch(column){
case 0: return labelColumnName;
case 1: return labelColumnProgress;
}
return super.getColumnName(column);
}
}
/**
* Diese Klasse sorgt lediglich dafür, die Informationen zum Fortschritt eines Plugin festzuhalten
*
* @author astaldo
*/
private class PluginProgress{
/**
* Das Plugin, für das die Informationen gelten
*/
private Plugin plugin;
/**
* Eine Fortschrittsanzeige
*/
private JProgressBar progressBar;
/**
* Der aktuelle Wert
*/
private int value;
public PluginProgress(Plugin plugin){
this(plugin,0,0);
}
public PluginProgress(Plugin plugin, int value, int maximum){
this.plugin = plugin;
this.progressBar = new JProgressBar();
this.progressBar.setMaximum(maximum);
this.progressBar.setValue(value);
this.progressBar.setStringPainted(true);
}
/**
* Legt das Maximum der Fortschrittsanzeige fest
*
* @param maximum Maximum-Wert
*/
public void setMaximum(int maximum){
this.progressBar.setMaximum(maximum);
}
/**
* Erhöht die Fortschrittsanzeige um eins
*/
public void increaseValue(){
this.value++;
this.progressBar.setValue(value);
}
}
/**
* Diese Klasse zeichnet eine JProgressBar in der Tabelle
*
* @author astaldo
*/
private class ProgressBarRenderer implements TableCellRenderer{
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
return (JProgressBar)value;
}
}
}

View File

@ -6,8 +6,13 @@ import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.io.File;
import java.io.FileFilter;
import java.util.Locale;
import java.util.ResourceBundle;
public class Utilities {
private static ResourceBundle resourceBundle = null;
private static Locale locale = null;
public static FilterJAR filterJar = new FilterJAR();
/**
@ -68,6 +73,21 @@ public class Utilities {
cons.ipady = iPadY;
cont.add(comp, cons);
}
/**
* Liefert eine Zeichenkette aus dem aktuellen ResourceBundle zurück
*
* @param key Identifier der gewünschten Zeichenkette
* @return Die gewünschte Zeichnenkette
*/
public static String getResourceString(String key){
if(resourceBundle== null){
if(locale == null){
locale = Locale.getDefault();
}
resourceBundle = ResourceBundle.getBundle("LanguagePack", locale);
}
return resourceBundle.getString(key);
}
private static class FilterJAR implements FileFilter{

View File

@ -0,0 +1,75 @@
package jd.plugins;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.text.MessageFormat;
import java.util.Date;
import java.util.logging.LogRecord;
import java.util.logging.SimpleFormatter;
/**
* Mit dieser Klasse können die Logmeldungen anders dargestellt werden.
* Der Code wurde hauptsächlich aus SimpleFormatter übernommen.
* Lediglich die Format Methode wurde ein wenig umgestellt.
*
* @author astaldo
*
*/
public class LogFormatter extends SimpleFormatter{
Date dat = new Date();
private MessageFormat formatter;
private final static String format = "{0,date} {0,time}";
private Object args[] = new Object[1];
// Line separator string. This is the value of the line.separator
// property at the moment that the SimpleFormatter was created.
private String lineSeparator = (String) java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
@Override
public synchronized String format(LogRecord record) {
StringBuffer sb = new StringBuffer();
// Minimize memory allocations here.
dat.setTime(record.getMillis());
args[0] = dat;
StringBuffer text = new StringBuffer();
if (formatter == null) {
formatter = new MessageFormat(format);
}
formatter.format(args, text, null);
sb.append(text);
sb.append(" - ");
sb.append(record.getLevel().getLocalizedName());
sb.append(" [");
if (record.getSourceClassName() != null) {
sb.append(record.getSourceClassName());
}
else {
sb.append(record.getLoggerName());
}
if (record.getSourceMethodName() != null) {
sb.append("(");
sb.append(record.getSourceMethodName());
sb.append(")");
}
sb.append("] ");
String message = formatMessage(record);
sb.append("-> ");
sb.append(message);
sb.append(lineSeparator);
if (record.getThrown() != null) {
try {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
record.getThrown().printStackTrace(pw);
pw.close();
sb.append(sw.toString());
}
catch (Exception ex) {}
}
return sb.toString();
}
}

View File

@ -12,12 +12,17 @@ import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Iterator;
import java.util.Vector;
import java.util.logging.ConsoleHandler;
import java.util.logging.Formatter;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import jd.plugins.event.PluginEvent;
import jd.plugins.event.PluginListener;
/**
* Diese abstrakte Klasse steuert den Zugriff auf weitere Plugins.
* Alle Plugins müssen von dieser Klasse abgeleitet werden.
@ -78,11 +83,32 @@ public abstract class Plugin{
/**
* Ein Logger, um Meldungen darzustellen
*/
private Logger logger = Logger.getLogger(Plugin.LOGGER_NAME);
private static Logger logger = null;
protected Plugin(){
pluginListener = new Vector<PluginListener>();
}
/**
* Liefert die Klasse zurück, mit der Nachrichten ausgegeben werden können
* Falls dieser Logger nicht existiert, wird ein neuer erstellt
*
* @return LogKlasse
*/
public static Logger getLogger(){
if (logger == null){
logger = Logger.getLogger(Plugin.LOGGER_NAME,"LanguagePack");
Formatter formatter = new LogFormatter();
logger.setUseParentHandlers(false);
Handler console = new ConsoleHandler();
console.setLevel(Level.ALL);
console.setFormatter(formatter);
logger.addHandler(console);
logger.setLevel(Level.ALL);
}
return logger;
}
/**
* Hier wird geprüft, ob das Plugin diesen Text oder einen Teil davon handhaben kann.
* Dazu wird einfach geprüft, ob ein Treffer des Patterns vorhanden ist.

View File

@ -12,7 +12,8 @@ public class PluginEvent extends AWTEvent{
public static final int PLUGIN_PROGRESS_MAX = 1;
public static final int PLUGIN_PROGRESS_INCREASE = 2;
public static final int PLUGIN_CRYPT_LINKS_DECRYPTED = 3;
public static final int PLUGIN_PROGRESS_FINISH = 3;
public static final int PLUGIN_CRYPT_LINKS_DECRYPTED = 4;
private Plugin source;
private int eventID;