* validate default filenames in filechooser
* fixed a typo
This commit is contained in:
parent
2852bf5383
commit
a2beab245f
|
@ -29,6 +29,7 @@ public class FileTransferableMessageHandler implements MessageHandler {
|
|||
@Override
|
||||
public void handle(String topic, String... messages) {
|
||||
|
||||
// change panel
|
||||
MessageBus.getDefault().publish("panel", name);
|
||||
|
||||
List<File> files = new ArrayList<File>(messages.length);
|
||||
|
|
|
@ -25,8 +25,6 @@ import javax.swing.event.ListDataListener;
|
|||
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
import net.sourceforge.filebot.ui.FileBotPanel;
|
||||
import net.sourceforge.filebot.ui.FileTransferableMessageHandler;
|
||||
import net.sourceforge.tuned.MessageBus;
|
||||
|
||||
|
||||
public class RenamePanel extends FileBotPanel {
|
||||
|
@ -41,7 +39,7 @@ public class RenamePanel extends FileBotPanel {
|
|||
|
||||
private SimilarityPanel similarityPanel;
|
||||
|
||||
private ViewPortSynchroniser viewPortSynchroniser;
|
||||
private ViewPortSynchronizer viewPortSynchroniser;
|
||||
|
||||
|
||||
public RenamePanel() {
|
||||
|
@ -55,9 +53,9 @@ public class RenamePanel extends FileBotPanel {
|
|||
JList list1 = namesList.getListComponent();
|
||||
JList list2 = filesList.getListComponent();
|
||||
|
||||
new SelectionSynchroniser(list1, list2);
|
||||
new SelectionSynchronizer(list1, list2);
|
||||
|
||||
viewPortSynchroniser = new ViewPortSynchroniser((JViewport) list1.getParent(), (JViewport) list2.getParent());
|
||||
viewPortSynchroniser = new ViewPortSynchronizer((JViewport) list1.getParent(), (JViewport) list2.getParent());
|
||||
|
||||
similarityPanel = new SimilarityPanel(list1, list2);
|
||||
|
||||
|
@ -82,8 +80,6 @@ public class RenamePanel extends FileBotPanel {
|
|||
|
||||
namesList.getModel().addListDataListener(repaintOnDataChange);
|
||||
filesList.getModel().addListDataListener(repaintOnDataChange);
|
||||
|
||||
MessageBus.getDefault().addMessageHandler(getPanelName(), new FileTransferableMessageHandler(getPanelName(), namesList));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
|
||||
package net.sourceforge.filebot.ui.panel.rename;
|
||||
|
||||
|
||||
import javax.swing.JList;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
|
||||
class SelectionSynchroniser {
|
||||
|
||||
private JList list1;
|
||||
private JList list2;
|
||||
|
||||
private SelectionSynchronizeListener selectionSynchronizeListener1;
|
||||
private SelectionSynchronizeListener selectionSynchronizeListener2;
|
||||
|
||||
|
||||
public SelectionSynchroniser(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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
|
||||
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 ViewPortSynchroniser {
|
||||
|
||||
private JViewport viewport1;
|
||||
private JViewport viewport2;
|
||||
|
||||
private ViewPortSynchronizeListener viewPortSynchronizeListener1;
|
||||
private ViewPortSynchronizeListener viewPortSynchronizeListener2;
|
||||
|
||||
|
||||
public ViewPortSynchroniser(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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -69,9 +69,10 @@ public class SfvPanel extends FileBotPanel {
|
|||
private final SaveAction saveAction = new SaveAction(sfvTable) {
|
||||
|
||||
private int index;
|
||||
|
||||
private String name;
|
||||
|
||||
private File folder = null;
|
||||
|
||||
|
||||
@Override
|
||||
protected void save(File file) {
|
||||
|
@ -85,6 +86,12 @@ public class SfvPanel extends FileBotPanel {
|
|||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected File getDefaultFolder() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
SfvTableModel model = (SfvTableModel) sfvTable.getModel();
|
||||
|
@ -125,8 +132,10 @@ public class SfvPanel extends FileBotPanel {
|
|||
|
||||
name += ".sfv";
|
||||
|
||||
if (selected.isDirectory())
|
||||
name = new File(selected, name).getAbsolutePath();
|
||||
// selected is either a folder or a sfv file
|
||||
if (selected.isDirectory()) {
|
||||
folder = selected;
|
||||
}
|
||||
|
||||
super.actionPerformed(e);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import java.io.File;
|
|||
import javax.swing.AbstractAction;
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
import net.sourceforge.filebot.FileBotUtil;
|
||||
import net.sourceforge.filebot.resources.ResourceManager;
|
||||
|
||||
|
||||
|
@ -32,6 +33,11 @@ public class SaveAction extends AbstractAction {
|
|||
}
|
||||
|
||||
|
||||
protected File getDefaultFolder() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected boolean isSaveable() {
|
||||
return saveable.isSaveable();
|
||||
}
|
||||
|
@ -44,7 +50,8 @@ public class SaveAction extends AbstractAction {
|
|||
JFileChooser chooser = new JFileChooser();
|
||||
|
||||
chooser.setMultiSelectionEnabled(false);
|
||||
chooser.setSelectedFile(new File(getDefaultFileName()));
|
||||
|
||||
chooser.setSelectedFile(new File(getDefaultFolder(), FileBotUtil.validateFileName(getDefaultFileName())));
|
||||
|
||||
if (chooser.showSaveDialog(null) != JFileChooser.APPROVE_OPTION)
|
||||
return;
|
||||
|
|
|
@ -19,11 +19,6 @@ public class MessageBus {
|
|||
return instance;
|
||||
}
|
||||
|
||||
|
||||
private MessageBus() {
|
||||
|
||||
}
|
||||
|
||||
private final Map<String, List<MessageHandler>> handlers = new HashMap<String, List<MessageHandler>>() {
|
||||
|
||||
@Override
|
||||
|
@ -39,6 +34,11 @@ public class MessageBus {
|
|||
};
|
||||
|
||||
|
||||
private MessageBus() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public synchronized void addMessageHandler(String topic, MessageHandler handler) {
|
||||
List<MessageHandler> list = handlers.get(topic);
|
||||
|
||||
|
|
|
@ -2,10 +2,9 @@
|
|||
package net.sourceforge.tuned;
|
||||
|
||||
|
||||
import java.util.EventListener;
|
||||
|
||||
|
||||
public interface MessageHandler extends EventListener {
|
||||
public interface MessageHandler {
|
||||
|
||||
public void handle(String topic, String... messages);
|
||||
|
||||
|
|
Loading…
Reference in New Issue