* forgot to add renamed files again

This commit is contained in:
Reinhard Pointner 2008-03-20 20:12:27 +00:00
parent 414ab43cc3
commit 05eecdedd5
2 changed files with 140 additions and 0 deletions

View File

@ -0,0 +1,70 @@
package net.sourceforge.filebot.ui.panel.rename;
import javax.swing.JList;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
class SelectionSynchronizer {
private JList list1;
private JList list2;
private SelectionSynchronizeListener selectionSynchronizeListener1;
private SelectionSynchronizeListener selectionSynchronizeListener2;
public SelectionSynchronizer(JList list1, JList list2) {
this.list1 = list1;
this.list2 = list2;
selectionSynchronizeListener1 = new SelectionSynchronizeListener(list2);
selectionSynchronizeListener2 = new SelectionSynchronizeListener(list1);
setEnabled(true);
}
public void setEnabled(boolean enabled) {
// remove listeners to avoid adding them multiple times
list1.removeListSelectionListener(selectionSynchronizeListener1);
list2.removeListSelectionListener(selectionSynchronizeListener2);
// if enabled add them again
if (enabled) {
list1.addListSelectionListener(selectionSynchronizeListener1);
list2.addListSelectionListener(selectionSynchronizeListener2);
}
}
private static class SelectionSynchronizeListener implements ListSelectionListener {
private JList target;
public SelectionSynchronizeListener(JList to) {
this.target = to;
}
public void valueChanged(ListSelectionEvent e) {
JList source = (JList) e.getSource();
int index = source.getSelectedIndex();
if (target.getModel().getSize() > index) {
if (index != target.getSelectedIndex()) {
target.setSelectedIndex(index);
}
target.ensureIndexIsVisible(index);
} else {
target.clearSelection();
}
}
}
}

View File

@ -0,0 +1,70 @@
package net.sourceforge.filebot.ui.panel.rename;
import java.awt.Point;
import javax.swing.JViewport;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
class ViewPortSynchronizer {
private JViewport viewport1;
private JViewport viewport2;
private ViewPortSynchronizeListener viewPortSynchronizeListener1;
private ViewPortSynchronizeListener viewPortSynchronizeListener2;
public ViewPortSynchronizer(JViewport viewport1, JViewport viewport2) {
this.viewport1 = viewport1;
this.viewport2 = viewport2;
viewPortSynchronizeListener1 = new ViewPortSynchronizeListener(viewport2);
viewPortSynchronizeListener2 = new ViewPortSynchronizeListener(viewport1);
setEnabled(true);
}
public void setEnabled(boolean enabled) {
// remove listeners to avoid adding them multiple times
viewport1.removeChangeListener(viewPortSynchronizeListener1);
viewport2.removeChangeListener(viewPortSynchronizeListener2);
// if enabled add them again
if (enabled) {
viewport1.addChangeListener(viewPortSynchronizeListener1);
viewport2.addChangeListener(viewPortSynchronizeListener2);
}
}
private static class ViewPortSynchronizeListener implements ChangeListener {
private JViewport target;
public ViewPortSynchronizeListener(JViewport target) {
this.target = target;
}
@Override
public void stateChanged(ChangeEvent e) {
JViewport source = (JViewport) e.getSource();
Point viewPosition = source.getViewPosition();
// return if both viewports have the same view position
if (viewPosition.equals(target.getViewPosition()))
return;
target.setViewPosition(viewPosition);
target.repaint();
}
}
}