import be.nikiroo.utils.ui.ListModel.Predicate;
import be.nikiroo.utils.ui.ListenerItem;
import be.nikiroo.utils.ui.ListenerPanel;
+import be.nikiroo.utils.ui.UIUtils;
public class ImporterFrame extends JFrame implements ListenerItem {
static public final String IMPORTED = "imported";
- private ListenerPanel root = new ListenerPanel();
+ private ListenerPanel root;
private ListModel<ImporterItem> data;
private String filter = "";
public ImporterFrame() {
+ root = new ListenerPanel();
setLayout(new BorderLayout());
root.setLayout(new BorderLayout());
- this.add(root);
+ this.add(UIUtils.scroll(root, false));
JList6<ImporterItem> list = new JList6<ImporterItem>();
data = new ListModel<ImporterItem>(list);
.removeItemIf(new Predicate<ImporterItem>() {
@Override
public boolean test(ImporterItem item) {
- return item.isDone();
+ return item.isDone(false);
}
});
*/
public void imprtFile(final Container parent) {
+ Progress pg = new Progress();
JFileChooser fc = new JFileChooser();
if (fc.showOpenDialog(parent) != JFileChooser.CANCEL_OPTION) {
Object url = fc.getSelectedFile().getAbsolutePath();
if (url != null && !url.toString().isEmpty()) {
- Progress pg = new Progress();
- add(pg, "File", fc.getSelectedFile().getName());
-
+ final ImporterItem item = add(pg, "File",
+ fc.getSelectedFile().getName());
Actions.imprt(parent, url.toString(), pg, new Runnable() {
@Override
public void run() {
+ item.setDone(true);
+ fireActionPerformed(IMPORTED);
+ }
+ }, new Runnable() {
+ @Override
+ public void run() {
+ item.setFailed(true);
+ item.setDone(true);
fireActionPerformed(IMPORTED);
}
});
}
if (url != null && !url.isEmpty()) {
- add(pg, basename, null);
-
+ final ImporterItem item = add(pg, basename, null);
Actions.imprt(parent, url, pg, new Runnable() {
@Override
public void run() {
+ item.setDone(true);
+ fireActionPerformed(IMPORTED);
+ }
+ }, new Runnable() {
+ @Override
+ public void run() {
+ item.setFailed(true);
+ item.setDone(true);
fireActionPerformed(IMPORTED);
}
});
}
}
- private void add(Progress pg, final String basename, String storyName) {
+ private ImporterItem add(Progress pg, final String basename,
+ String storyName) {
final ImporterItem item = new ImporterItem(pg, basename, storyName);
item.addActionListener(new ActionListener() {
@Override
data.addItem(item);
filter();
+
+ return item;
}
private void filter() {
private boolean hovered;
private boolean selected;
private boolean done;
+ private boolean failed;
private JLabel labelName;
private JLabel labelAction;
}
}
- public boolean isDone() {
- return done;
+ public boolean isDone(boolean acceptFailure) {
+ return done && (acceptFailure || !failed);
}
public void setDone(boolean done) {
if (this.done != done) {
this.done = done;
- if (done) {
- labelAction.setForeground(Color.green.darker());
- labelAction
- .setFont(labelAction.getFont().deriveFont(Font.BOLD));
- } else {
- labelAction.setForeground(Color.gray);
- labelAction
- .setFont(labelAction.getFont().deriveFont(Font.PLAIN));
- }
+ setHighlight();
+ }
+ }
+
+ public boolean isFailed() {
+ return failed;
+ }
+
+ public void setFailed(boolean failed) {
+ if (this.failed != failed) {
+ this.failed = failed;
+ setHighlight();
+ }
+ }
+
+ private void setHighlight() {
+ Color highlight = null;
+ if (failed) {
+ highlight = Color.red.darker();
+ } else if (done) {
+ highlight = Color.green.darker();
+ }
+
+ if (highlight != null) {
+ labelAction.setForeground(highlight);
+ labelAction.setFont(labelAction.getFont().deriveFont(Font.BOLD));
+ } else {
+ labelAction.setForeground(Color.gray);
+ labelAction.setFont(labelAction.getFont().deriveFont(Font.PLAIN));
}
}
public void progress(Progress notUsed, String currentAction) {
currentAction = currentAction == null ? "" : currentAction;
String currentStoryName = null;
-
- MetaData meta = (MetaData)pg.get("meta");
+
+ MetaData meta = (MetaData) pg.get("meta");
if (meta != null) {
currentStoryName = meta.getTitle();
}
-
+
if (pg.getRelativeProgress() != progress
|| !action.equals(currentAction)
|| !storyName.equals(currentStoryName)) {