Search in sources :

Example 1 with ScanResult

use of jack.rm.files.ScanResult in project rom-manager by Jakz.

the class ClonesDialog method activate.

public void activate(GameSet set, Set<ScanResult> clones) {
    this.set = set;
    this.keep.clear();
    this.clones.clear();
    // TODO: probably requires to be rewritten almost totally to manage multiple roms per game
    Set<Rom> romClones = clones.stream().map(c -> c.rom).collect(Collectors.toSet());
    this.clones = new ArrayList<>(clones);
    this.clones.addAll(set.stream().flatMap(g -> g.stream()).filter(r -> romClones.contains(r)).map(r -> new ScanResult(r, r.handle())).collect(Collectors.toList()));
    Collections.sort(this.clones);
    this.keep = this.clones.stream().collect(Collectors.toMap(c -> c, c -> false));
    this.colors = romClones.stream().collect(Collectors.toMap(c -> c, c -> colorGenerator.getColor()));
    updateStatus();
    model.fireChanges();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
    Dialogs.showWarning("Clones Found", colors.size() + " clones have been found,\nplease specify which entries you want to keep", this);
}
Also used : Color(java.awt.Color) NimbusBooleanCellRenderer(com.pixbits.lib.ui.table.renderers.NimbusBooleanCellRenderer) Arrays(java.util.Arrays) JDialog(javax.swing.JDialog) HashMap(java.util.HashMap) TableCellRenderer(javax.swing.table.TableCellRenderer) SwingConstants(javax.swing.SwingConstants) Handle(com.pixbits.lib.io.archive.handles.Handle) ArrayList(java.util.ArrayList) GameSet(com.github.jakz.romlib.data.set.GameSet) PastelColorGenerator(com.pixbits.lib.ui.color.PastelColorGenerator) ArchiveHandle(com.pixbits.lib.io.archive.handles.ArchiveHandle) Map(java.util.Map) AbstractTableModel(javax.swing.table.AbstractTableModel) BorderLayout(java.awt.BorderLayout) LinkedList(java.util.LinkedList) JComboBox(javax.swing.JComboBox) Rom(com.github.jakz.romlib.data.game.Rom) BinaryHandle(com.pixbits.lib.io.archive.handles.BinaryHandle) ScanResult(jack.rm.files.ScanResult) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) NestedArchiveHandle(com.pixbits.lib.io.archive.handles.NestedArchiveHandle) Frame(java.awt.Frame) JButton(javax.swing.JButton) Predicate(java.util.function.Predicate) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) JScrollPane(javax.swing.JScrollPane) List(java.util.List) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JLabel(javax.swing.JLabel) ColorGenerator(com.pixbits.lib.ui.color.ColorGenerator) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) JTable(javax.swing.JTable) Collections(java.util.Collections) Main(jack.rm.Main) JPanel(javax.swing.JPanel) GameSetManager(jack.rm.data.romset.GameSetManager) Rom(com.github.jakz.romlib.data.game.Rom) ScanResult(jack.rm.files.ScanResult)

Example 2 with ScanResult

use of jack.rm.files.ScanResult in project rom-manager by Jakz.

the class ClonesDialog method autoChoose.

public void autoChoose(ClonePolicy policy, ClonePriority priority) {
    if (policy == ClonePolicy.AUTO_SELECT_ALL)
        this.keep = this.clones.stream().collect(Collectors.toMap(c -> c, c -> false));
    List<List<ScanResult>> results = new ArrayList<>();
    LinkedList<ScanResult> current = null;
    /* create a list for each rom with clones */
    boolean alreadySet = false;
    for (ScanResult result : this.clones) {
        if (current == null || !current.peekLast().rom.equals(result.rom)) {
            if (current != null && !alreadySet)
                results.add(current);
            alreadySet = false;
            current = new LinkedList<>();
        }
        current.add(result);
        alreadySet |= keep.get(result);
    }
    if (current != null && !alreadySet)
        results.add(current);
    for (List<ScanResult> list : results) {
        ScanResult result = chooseBestClone(list, policy, priority);
        keep.put(result, true);
    }
    model.fireChanges();
    updateStatus();
}
Also used : Color(java.awt.Color) NimbusBooleanCellRenderer(com.pixbits.lib.ui.table.renderers.NimbusBooleanCellRenderer) Arrays(java.util.Arrays) JDialog(javax.swing.JDialog) HashMap(java.util.HashMap) TableCellRenderer(javax.swing.table.TableCellRenderer) SwingConstants(javax.swing.SwingConstants) Handle(com.pixbits.lib.io.archive.handles.Handle) ArrayList(java.util.ArrayList) GameSet(com.github.jakz.romlib.data.set.GameSet) PastelColorGenerator(com.pixbits.lib.ui.color.PastelColorGenerator) ArchiveHandle(com.pixbits.lib.io.archive.handles.ArchiveHandle) Map(java.util.Map) AbstractTableModel(javax.swing.table.AbstractTableModel) BorderLayout(java.awt.BorderLayout) LinkedList(java.util.LinkedList) JComboBox(javax.swing.JComboBox) Rom(com.github.jakz.romlib.data.game.Rom) BinaryHandle(com.pixbits.lib.io.archive.handles.BinaryHandle) ScanResult(jack.rm.files.ScanResult) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) NestedArchiveHandle(com.pixbits.lib.io.archive.handles.NestedArchiveHandle) Frame(java.awt.Frame) JButton(javax.swing.JButton) Predicate(java.util.function.Predicate) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) JScrollPane(javax.swing.JScrollPane) List(java.util.List) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JLabel(javax.swing.JLabel) ColorGenerator(com.pixbits.lib.ui.color.ColorGenerator) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) JTable(javax.swing.JTable) Collections(java.util.Collections) Main(jack.rm.Main) JPanel(javax.swing.JPanel) GameSetManager(jack.rm.data.romset.GameSetManager) ScanResult(jack.rm.files.ScanResult) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List)

Example 3 with ScanResult

use of jack.rm.files.ScanResult in project rom-manager by Jakz.

the class ClonesDialog method chooseBestClone.

public ScanResult chooseBestClone(List<ScanResult> results, ClonePolicy policy, ClonePriority priority) {
    if (priority != ClonePriority.ANY) {
        List<ScanResult> filtered = results.stream().filter(r -> r.handle.getClass() == priority.type).collect(Collectors.toList());
        if (!filtered.isEmpty())
            results = filtered;
    }
    boolean hasRenamer = setManager.settings(set).getRenamer() != null;
    boolean hasMover = setManager.settings(set).getFolderOrganizer() != null;
    Predicate<ScanResult> predicateAny = e -> true;
    Predicate<ScanResult> predicateCorrectFolder = e -> !hasMover || setManager.settings(set).romsPath.resolve(e.rom.game().getCorrectFolder()).equals(e.handle.path().getParent());
    Predicate<ScanResult> predicateCorrectName = e -> !hasRenamer || e.rom.game().getCorrectName().equals(e.handle.path().getFileName().toString());
    Predicate<ScanResult> predicateCorrectNameAndFolder = predicateCorrectName.and(predicateCorrectFolder);
    List<Predicate<ScanResult>> predicates = Arrays.asList(predicateCorrectNameAndFolder, predicateCorrectName, predicateCorrectFolder, predicateAny);
    Optional<ScanResult> optional = Optional.empty();
    for (Predicate<ScanResult> predicate : predicates) if ((optional = results.stream().filter(predicate).findFirst()).isPresent())
        break;
    ScanResult chosen = optional.get();
    return chosen;
}
Also used : Color(java.awt.Color) NimbusBooleanCellRenderer(com.pixbits.lib.ui.table.renderers.NimbusBooleanCellRenderer) Arrays(java.util.Arrays) JDialog(javax.swing.JDialog) HashMap(java.util.HashMap) TableCellRenderer(javax.swing.table.TableCellRenderer) SwingConstants(javax.swing.SwingConstants) Handle(com.pixbits.lib.io.archive.handles.Handle) ArrayList(java.util.ArrayList) GameSet(com.github.jakz.romlib.data.set.GameSet) PastelColorGenerator(com.pixbits.lib.ui.color.PastelColorGenerator) ArchiveHandle(com.pixbits.lib.io.archive.handles.ArchiveHandle) Map(java.util.Map) AbstractTableModel(javax.swing.table.AbstractTableModel) BorderLayout(java.awt.BorderLayout) LinkedList(java.util.LinkedList) JComboBox(javax.swing.JComboBox) Rom(com.github.jakz.romlib.data.game.Rom) BinaryHandle(com.pixbits.lib.io.archive.handles.BinaryHandle) ScanResult(jack.rm.files.ScanResult) BoxLayout(javax.swing.BoxLayout) JComponent(javax.swing.JComponent) NestedArchiveHandle(com.pixbits.lib.io.archive.handles.NestedArchiveHandle) Frame(java.awt.Frame) JButton(javax.swing.JButton) Predicate(java.util.function.Predicate) Set(java.util.Set) BorderFactory(javax.swing.BorderFactory) Component(java.awt.Component) Collectors(java.util.stream.Collectors) JScrollPane(javax.swing.JScrollPane) List(java.util.List) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JLabel(javax.swing.JLabel) ColorGenerator(com.pixbits.lib.ui.color.ColorGenerator) JCheckBox(javax.swing.JCheckBox) Optional(java.util.Optional) JTable(javax.swing.JTable) Collections(java.util.Collections) Main(jack.rm.Main) JPanel(javax.swing.JPanel) GameSetManager(jack.rm.data.romset.GameSetManager) ScanResult(jack.rm.files.ScanResult) Predicate(java.util.function.Predicate)

Aggregations

Rom (com.github.jakz.romlib.data.game.Rom)3 GameSet (com.github.jakz.romlib.data.set.GameSet)3 ArchiveHandle (com.pixbits.lib.io.archive.handles.ArchiveHandle)3 BinaryHandle (com.pixbits.lib.io.archive.handles.BinaryHandle)3 Handle (com.pixbits.lib.io.archive.handles.Handle)3 NestedArchiveHandle (com.pixbits.lib.io.archive.handles.NestedArchiveHandle)3 ColorGenerator (com.pixbits.lib.ui.color.ColorGenerator)3 PastelColorGenerator (com.pixbits.lib.ui.color.PastelColorGenerator)3 NimbusBooleanCellRenderer (com.pixbits.lib.ui.table.renderers.NimbusBooleanCellRenderer)3 Main (jack.rm.Main)3 GameSetManager (jack.rm.data.romset.GameSetManager)3 ScanResult (jack.rm.files.ScanResult)3 BorderLayout (java.awt.BorderLayout)3 Color (java.awt.Color)3 Component (java.awt.Component)3 Frame (java.awt.Frame)3 ArrayList (java.util.ArrayList)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 HashMap (java.util.HashMap)3