1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-22 15:58:52 -05:00

* changed static class Factor to proper enum Direction

* some cleanup
This commit is contained in:
Reinhard Pointner 2009-01-25 01:27:40 +00:00
parent ac9473ff07
commit 9fd13dceae
7 changed files with 79 additions and 363 deletions

View File

@ -3,13 +3,14 @@ package net.sourceforge.filebot.ui;
import static net.sourceforge.filebot.Settings.getApplicationName;
import static net.sourceforge.tuned.ui.notification.Direction.NORTH;
import static net.sourceforge.tuned.ui.notification.Direction.SOUTH;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import javax.swing.Icon;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import net.sourceforge.filebot.ResourceManager;
@ -25,7 +26,7 @@ public class NotificationLoggingHandler extends Handler {
public NotificationLoggingHandler() {
this(new NotificationManager(new QueueNotificationLayout(SwingConstants.NORTH, SwingConstants.SOUTH)));
this(new NotificationManager(new QueueNotificationLayout(NORTH, SOUTH)));
}

View File

@ -1,58 +0,0 @@
package net.sourceforge.filebot.ui.panel.subtitle;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.event.ListEvent;
import ca.odell.glazedlists.event.ListEventListener;
import ca.odell.glazedlists.matchers.AbstractMatcherEditor;
import ca.odell.glazedlists.matchers.Matcher;
public class LanguageMatcherEditor extends AbstractMatcherEditor<SubtitlePackage> {
private final EventList<Language> languages;
public LanguageMatcherEditor(LanguageSelectionPanel languageSelectionPanel) {
this(languageSelectionPanel.getSelected());
currentMatcher = new LanguageMatcher(this.languages);
}
public LanguageMatcherEditor(EventList<Language> languages) {
this.languages = languages;
languages.addListEventListener(new LanguageSelectionListener());
}
private class LanguageSelectionListener implements ListEventListener<Language> {
@Override
public void listChanged(ListEvent<Language> listChanges) {
boolean insert = false;
boolean delete = false;
while (listChanges.next()) {
int type = listChanges.getType();
insert |= (type == ListEvent.INSERT);
delete |= (type == ListEvent.DELETE);
}
if (insert || delete) {
Matcher<SubtitlePackage> matcher = new LanguageMatcher(languages);
if (insert && !delete) {
fireRelaxed(matcher);
} else if (!insert && delete) {
fireConstrained(matcher);
} else {
fireChanged(matcher);
}
}
}
}
}

View File

@ -13,7 +13,6 @@ import javax.swing.JScrollPane;
import ca.odell.glazedlists.BasicEventList;
import ca.odell.glazedlists.EventList;
import ca.odell.glazedlists.FilterList;
import ca.odell.glazedlists.ObservableElementList;
import ca.odell.glazedlists.swing.EventListModel;
@ -22,12 +21,9 @@ public class SubtitlePackagePanel extends JComponent {
private final EventList<SubtitlePackage> model = new BasicEventList<SubtitlePackage>();
private final LanguageSelectionPanel languageSelection = new LanguageSelectionPanel(model);
public SubtitlePackagePanel() {
setLayout(new BorderLayout());
add(languageSelection, BorderLayout.NORTH);
add(new JScrollPane(createList()), BorderLayout.CENTER);
}
@ -38,8 +34,7 @@ public class SubtitlePackagePanel extends JComponent {
protected JList createList() {
FilterList<SubtitlePackage> filterList = new FilterList<SubtitlePackage>(model, new LanguageMatcherEditor(languageSelection));
ObservableElementList<SubtitlePackage> observableList = new ObservableElementList<SubtitlePackage>(filterList, new SubtitlePackageConnector());
ObservableElementList<SubtitlePackage> observableList = new ObservableElementList<SubtitlePackage>(model, new SubtitlePackageConnector());
JList list = new JList(new EventListModel<SubtitlePackage>(observableList));
@ -74,7 +69,7 @@ public class SubtitlePackagePanel extends JComponent {
}
private class SubtitlePackageListener implements PropertyChangeListener {
protected class SubtitlePackageListener implements PropertyChangeListener {
private final SubtitlePackage subtitlePackage;
@ -91,126 +86,4 @@ public class SubtitlePackagePanel extends JComponent {
}
/*
private void updateLanguageFilterButtonPanel() {
SortedSet<String> languages = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
for (int i = 0; i < unfilteredModel.getSize(); i++) {
SubtitlePackage subtitle = (SubtitlePackage) unfilteredModel.getElementAt(i);
languages.add(subtitle.getLanguageName());
}
languageFilterPanel.removeAll();
for (String language : languages) {
LanguageFilterButton languageFilterButton = createLanguageFilterButton(language);
languageFilterButton.addItemListener(new LanguageFilterItemListener(language));
languageFilterPanel.add(languageFilterButton);
}
}
private void updateFilteredModel() {
SimpleListModel model = new SimpleListModel();
for (int i = 0; i < unfilteredModel.getSize(); i++) {
SubtitlePackage subtitle = (SubtitlePackage) unfilteredModel.getElementAt(i);
if (isLanguageSelected(subtitle.getLanguageName())) {
model.add(subtitle);
}
}
super.setModel(model);
}
public boolean isLanguageSelected(String language) {
return !languageFilterSelection.containsKey(language) || languageFilterSelection.get(language);
}
public void setLanguageSelected(String language, boolean selected) {
languageFilterSelection.put(language, selected);
Settings.getSettings().asBooleanMap(Settings.SUBTITLE_LANGUAGE).put(language, selected);
}
private LanguageFilterButton createLanguageFilterButton(String language) {
Locale locale = LanguageResolver.getDefault().getLocale(language);
boolean selected = isLanguageSelected(language);
if (locale != null)
return new LanguageFilterButton(locale, selected);
else
return new LanguageFilterButton(language, selected);
}
private class LanguageFilterItemListener implements ItemListener {
private final String language;
public LanguageFilterItemListener(String language) {
this.language = language;
}
@Override
public void itemStateChanged(ItemEvent e) {
boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
setLanguageSelected(language, selected);
updateFilteredModel();
}
};
private class LanguageFilterButton extends JToggleButton {
public LanguageFilterButton(Locale locale, boolean selected) {
this(locale.getDisplayLanguage(Locale.ENGLISH), ResourceManager.getFlagIcon(locale.getLanguage()), selected);
}
public LanguageFilterButton(String language, boolean selected) {
this(language, ResourceManager.getFlagIcon(null), selected);
}
public LanguageFilterButton(String language, Icon icon, boolean selected) {
super(icon, selected);
setToolTipText(language);
setContentAreaFilled(false);
setFocusPainted(false);
setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
}
@Override
protected void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
// make transparent if not selected
if (!isSelected()) {
AlphaComposite composite = AlphaComposite.SrcOver.derive(0.2f);
g2d.setComposite(composite);
}
super.paintComponent(g2d);
}
}
*/
}

View File

@ -0,0 +1,33 @@
package net.sourceforge.tuned.ui.notification;
import javax.swing.SwingConstants;
public enum Direction {
CENTER(0, 0, 0.5, 0.5, SwingConstants.CENTER),
NORTH(0, -1, 0.5, 0.0, SwingConstants.NORTH),
NORTH_EAST(1, -1, 1.0, 0.0, SwingConstants.NORTH_EAST),
EAST(1, 0, 1.0, 0.5, SwingConstants.EAST),
SOUTH_EAST(1, 1, 1.0, 1.0, SwingConstants.SOUTH_EAST),
SOUTH(0, 1, 0.5, 1.0, SwingConstants.SOUTH),
SOUTH_WEST(-1, 1, 0.0, 1.0, SwingConstants.SOUTH_WEST),
WEST(-1, 0, 0.0, 0.5, SwingConstants.WEST),
NORTH_WEST(-1, -1, 0.0, 0.0, SwingConstants.NORTH_WEST);
public final int vx;
public final int vy;
public final double ax;
public final double ay;
public final int swingConstant;
private Direction(int vx, int vy, double ax, double ay, int swingConstant) {
this.vx = vx;
this.vy = vy;
this.ax = ax;
this.ay = ay;
this.swingConstant = swingConstant;
}
}

View File

@ -1,127 +0,0 @@
package net.sourceforge.tuned.ui.notification;
import javax.swing.SwingConstants;
class Factor implements SwingConstants {
public final double fx;
public final double fy;
public Factor(double fx, double fy) {
this.fx = fx;
this.fy = fy;
}
static Factor getOrientationFactor(int orientation) {
double fx = 0;
double fy = 0;
switch (orientation) {
case NORTH_WEST:
fx = 0;
fy = 0;
break;
case NORTH:
fx = 0.5;
fy = 0;
break;
case NORTH_EAST:
fx = 1;
fy = 0;
break;
case WEST:
fx = 0;
fy = 0.5;
break;
case EAST:
fx = 1;
fy = 0.5;
break;
case SOUTH_WEST:
fx = 0;
fy = 1;
break;
case SOUTH:
fx = 0.5;
fy = 1;
break;
case SOUTH_EAST:
fx = 1;
fy = 1;
break;
case CENTER:
fx = 0.5;
fy = 0.5;
}
return new Factor(fx, fy);
}
static Factor getDirectionFactor(int direction) {
double fx = 0;
double fy = 0;
switch (direction) {
case NORTH_WEST:
fx = -1;
fy = -1;
break;
case NORTH:
fx = 0;
fy = -1;
break;
case NORTH_EAST:
fx = 1;
fy = -1;
break;
case WEST:
fx = -1;
fy = 0;
break;
case EAST:
fx = 1;
fy = 0;
break;
case SOUTH_WEST:
fx = -1;
fy = 1;
break;
case SOUTH:
fx = 0;
fy = 1;
break;
case SOUTH_EAST:
fx = 1;
fy = 1;
break;
case CENTER:
fx = 0;
fy = 0;
}
return new Factor(fx, fy);
}
}

View File

@ -6,24 +6,25 @@
package net.sourceforge.tuned.ui.notification;
import static net.sourceforge.tuned.ui.notification.Direction.SOUTH_EAST;
import static net.sourceforge.tuned.ui.notification.Direction.WEST;
import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import java.util.ArrayList;
import java.util.ListIterator;
import javax.swing.SwingConstants;
import java.util.List;
public class QueueNotificationLayout implements NotificationLayout, SwingConstants {
public class QueueNotificationLayout implements NotificationLayout {
private ArrayList<NotificationWindow> notificationList = new ArrayList<NotificationWindow>();
private final List<NotificationWindow> notifications = new ArrayList<NotificationWindow>();
private int orientation;
private int direction;
private int growAnchor;
private final Direction alignment;
private final Direction direction;
private final Direction growAnchor;
public QueueNotificationLayout() {
@ -31,30 +32,28 @@ public class QueueNotificationLayout implements NotificationLayout, SwingConstan
}
public QueueNotificationLayout(int orientation, int direction) {
this.orientation = orientation;
this.growAnchor = orientation;
public QueueNotificationLayout(Direction alignment, Direction direction) {
this.alignment = alignment;
this.growAnchor = alignment;
this.direction = direction;
}
public QueueNotificationLayout(int orientation, int direction, int growAnchor) {
this.orientation = orientation;
public QueueNotificationLayout(Direction orientation, Direction direction, Direction growAnchor) {
this.alignment = orientation;
this.direction = direction;
this.growAnchor = growAnchor;
}
private Point getBaseAnchor(Dimension screen, Insets insets) {
Factor f = Factor.getOrientationFactor(orientation);
Point p = new Point();
screen.height -= insets.top + insets.bottom;
screen.width -= insets.left + insets.right;
p.x = (int) (f.fx * screen.width);
p.y = (int) (f.fy * screen.height);
p.x = (int) (alignment.ax * screen.width);
p.y = (int) (alignment.ay * screen.height);
p.x += insets.left;
p.y += insets.top;
@ -64,28 +63,27 @@ public class QueueNotificationLayout implements NotificationLayout, SwingConstan
private Point getLocation(Point anchor, Dimension size) {
Factor f = Factor.getOrientationFactor(growAnchor);
Point p = new Point();
p.x = (int) (anchor.x - size.width * f.fx);
p.y = (int) (anchor.y - size.height * f.fy);
p.x = (int) (anchor.x - size.width * growAnchor.ax);
p.y = (int) (anchor.y - size.height * growAnchor.ay);
return p;
}
private Point getNextAnchor(Point anchor, Dimension size) {
Factor f = Factor.getDirectionFactor(direction);
Point p = new Point();
p.x = (int) (anchor.x + size.width * f.fx);
p.y = (int) (anchor.y + size.height * f.fy);
p.x = anchor.x + size.width * direction.vx;
p.y = anchor.y + size.height * direction.vy;
return p;
}
public void add(NotificationWindow notification) {
notificationList.add(notification);
notifications.add(notification);
align(notification.getGraphicsConfiguration());
}
@ -96,14 +94,11 @@ public class QueueNotificationLayout implements NotificationLayout, SwingConstan
Point anchor = getBaseAnchor(screen, insets);
ListIterator<NotificationWindow> i = notificationList.listIterator();
while (i.hasNext()) {
NotificationWindow n = i.next();
Dimension size = n.getSize();
for (NotificationWindow window : notifications) {
Dimension size = window.getSize();
Point p = getLocation(anchor, size);
n.setLocation(p);
window.setLocation(p);
anchor = getNextAnchor(anchor, size);
}
@ -111,7 +106,7 @@ public class QueueNotificationLayout implements NotificationLayout, SwingConstan
public void remove(NotificationWindow notification) {
if (notificationList.remove(notification)) {
if (notifications.remove(notification)) {
align(notification.getGraphicsConfiguration());
}
}

View File

@ -6,17 +6,18 @@
package net.sourceforge.tuned.ui.notification;
import static net.sourceforge.tuned.ui.notification.Direction.NORTH;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Toolkit;
import javax.swing.SwingConstants;
public class SimpleNotificationLayout implements NotificationLayout, SwingConstants {
public class SimpleNotificationLayout implements NotificationLayout {
private NotificationWindow currentNotification;
private int orientation;
private Direction alignment;
public SimpleNotificationLayout() {
@ -24,21 +25,19 @@ public class SimpleNotificationLayout implements NotificationLayout, SwingConsta
}
public SimpleNotificationLayout(int orientation) {
this.orientation = orientation;
public SimpleNotificationLayout(Direction alignment) {
this.alignment = alignment;
}
private Point getBaseAnchor(Dimension screen, Insets insets) {
Factor f = Factor.getOrientationFactor(orientation);
Point p = new Point();
screen.height -= insets.top + insets.bottom;
screen.width -= insets.left + insets.right;
p.x = (int) (f.fx * screen.width);
p.y = (int) (f.fy * screen.height);
p.x = (int) (alignment.ax * screen.width);
p.y = (int) (alignment.ay * screen.height);
p.x += insets.left;
p.y += insets.top;
@ -48,11 +47,10 @@ public class SimpleNotificationLayout implements NotificationLayout, SwingConsta
private Point getLocation(Point anchor, Dimension size) {
Factor f = Factor.getOrientationFactor(orientation);
Point p = new Point();
p.x = (int) (anchor.x - size.width * f.fx);
p.y = (int) (anchor.y - size.height * f.fy);
p.x = (int) (anchor.x - size.width * alignment.ax);
p.y = (int) (anchor.y - size.height * alignment.ay);
return p;
}
@ -66,8 +64,9 @@ public class SimpleNotificationLayout implements NotificationLayout, SwingConsta
Point anchor = getBaseAnchor(screen, insets);
notification.setLocation(getLocation(anchor, size));
if (currentNotification != null)
if (currentNotification != null) {
currentNotification.close();
}
currentNotification = notification;
}