diff --git a/LanguagePack_de.properties b/LanguagePack_de.properties new file mode 100644 index 0000000000..0ca7725986 --- /dev/null +++ b/LanguagePack_de.properties @@ -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 \ No newline at end of file diff --git a/build.xml b/build.xml new file mode 100644 index 0000000000..6ac1e7a356 --- /dev/null +++ b/build.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/jd/Main.java b/jd/Main.java index fc541cbf10..d0fcd7ab66 100644 --- a/jd/Main.java +++ b/jd/Main.java @@ -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); } diff --git a/jd/gui/MainWindow.java b/jd/gui/MainWindow.java index 3d7b1ebd28..caddfa049b 100644 --- a/jd/gui/MainWindow.java +++ b/jd/gui/MainWindow.java @@ -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(); } } } diff --git a/jd/gui/DownloadLinkTable.java b/jd/gui/TabDownloadLinks.java similarity index 71% rename from jd/gui/DownloadLinkTable.java rename to jd/gui/TabDownloadLinks.java index ef1fe2b3ae..5c293b28c6 100644 --- a/jd/gui/DownloadLinkTable.java +++ b/jd/gui/TabDownloadLinks.java @@ -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 allLinks = new Vector(); /** * 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 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; } diff --git a/jd/gui/TabPluginActivity.java b/jd/gui/TabPluginActivity.java new file mode 100644 index 0000000000..15c6eeb3a2 --- /dev/null +++ b/jd/gui/TabPluginActivity.java @@ -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 pluginProgresses = new Vector(); + 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 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; + } + + } +} diff --git a/jd/gui/Utilities.java b/jd/gui/Utilities.java index 271567582c..f2a70bb29c 100644 --- a/jd/gui/Utilities.java +++ b/jd/gui/Utilities.java @@ -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{ diff --git a/jd/plugins/LogFormatter.java b/jd/plugins/LogFormatter.java new file mode 100644 index 0000000000..2b24775c16 --- /dev/null +++ b/jd/plugins/LogFormatter.java @@ -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(); + } +} diff --git a/jd/plugins/Plugin.java b/jd/plugins/Plugin.java index 9acebbfdde..1b62a136b0 100644 --- a/jd/plugins/Plugin.java +++ b/jd/plugins/Plugin.java @@ -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(); } + /** + * 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. diff --git a/jd/plugins/event/PluginEvent.java b/jd/plugins/event/PluginEvent.java index eb106909ac..6c3d467284 100644 --- a/jd/plugins/event/PluginEvent.java +++ b/jd/plugins/event/PluginEvent.java @@ -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;