Changeset 4689 in josm


Ignore:
Timestamp:
2011-12-21T22:55:54+01:00 (8 years ago)
Author:
stoecker
Message:

don't have multiple classes in one file

Location:
trunk/src/org/openstreetmap/josm/gui/history
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java

    r4602 r4689  
    88import java.util.Collections;
    99import java.util.HashSet;
    10 import java.util.List;
    1110import java.util.Observable;
    1211
     
    900899    }
    901900}
    902 
    903 /**
    904  * Simple model storing "diff cells" in a list. Could probably have used a DefaultTableModel instead..
    905  *
    906  * {@see NodeListDiffTableCellRenderer}
    907  */
    908 class DiffTableModel extends AbstractTableModel {
    909     private List<TwoColumnDiff.Item> rows;
    910 
    911     public void setRows(List<TwoColumnDiff.Item> rows) {
    912         this.rows = rows;
    913     }
    914 
    915     public DiffTableModel(List<TwoColumnDiff.Item> rows) {
    916         this.rows = rows;
    917     }
    918     public DiffTableModel() {
    919         this.rows = new ArrayList<TwoColumnDiff.Item>();
    920     }
    921     @Override
    922     public int getRowCount() {
    923         return rows.size();
    924     }
    925 
    926     @Override
    927     public int getColumnCount() {
    928         return 1;
    929     }
    930 
    931     @Override
    932     public TwoColumnDiff.Item getValueAt(int rowIndex, int columnIndex) {
    933         return rows.get(rowIndex);
    934     }
    935 }
    936 
    937 
    938 /// Feel free to move me somewhere else. Maybe a bit specific for josm.tools?
    939 /**
    940  * Produces a "two column diff" of two lists. (same as diff -y)
    941  *
    942  * Each list is annotated with the changes relative to the other, and "empty" cells are inserted so the lists are comparable item by item.
    943  *
    944  * diff on [1 2 3 4] [1 a 4 5] yields:
    945  *
    946  * item(SAME, 1)    item(SAME, 1)
    947  * item(CHANGED, 2) item(CHANGED, 2)
    948  * item(DELETED, 3) item(EMPTY)
    949  * item(SAME, 4)    item(SAME, 4)
    950  * item(EMPTY)      item(INSERTED, 5)
    951  *
    952  * @author olejorgenb
    953  */
    954 class TwoColumnDiff {
    955     public static class Item {
    956         public static final int INSERTED = 1;
    957         public static final int DELETED = 2;
    958         public static final int CHANGED = 3;
    959         public static final int SAME = 4;
    960         public static final int EMPTY = 5; // value should be null
    961         public Item(int state, Object value) {
    962             this.state = state;
    963             this.value = state == EMPTY ? null : value;
    964         }
    965 
    966         public final Object value;
    967         public final int state;
    968     }
    969 
    970     public ArrayList<Item> referenceDiff;
    971     public ArrayList<Item> currentDiff;
    972     Object[] reference;
    973     Object[] current;
    974 
    975     /**
    976      * The arguments will _not_ be modified
    977      */
    978     public TwoColumnDiff(Object[] reference, Object[] current) {
    979         this.reference = reference;
    980         this.current = current;
    981         referenceDiff = new ArrayList<Item>();
    982         currentDiff = new ArrayList<Item>();
    983         diff();
    984     }
    985     private void diff() {
    986         Diff diff = new Diff(reference, current);
    987         Diff.change script = diff.diff_2(false);
    988         twoColumnDiffFromScript(script, reference, current);
    989     }
    990 
    991     /**
    992      * The result from the diff algorithm is a "script" (a compressed description of the changes)
    993      * This method expands this script into a full two column description.
    994      */
    995     private void twoColumnDiffFromScript(Diff.change script, Object[] a, Object[] b) {
    996         int ia = 0;
    997         int ib = 0;
    998 
    999         while(script != null) {
    1000             int deleted = script.deleted;
    1001             int inserted = script.inserted;
    1002             while(ia < script.line0 && ib < script.line1){
    1003                 // System.out.println(" "+a[ia] + "\t "+b[ib]);
    1004                 Item cell = new Item(Item.SAME, a[ia]);
    1005                 referenceDiff.add(cell);
    1006                 currentDiff.add(cell);
    1007                 ia++;
    1008                 ib++;
    1009             }
    1010 
    1011             while(inserted > 0 || deleted > 0) {
    1012                 if(inserted > 0 && deleted > 0) {
    1013                     // System.out.println("="+a[ia] + "\t="+b[ib]);
    1014                     referenceDiff.add(new Item(Item.CHANGED, a[ia++]));
    1015                     currentDiff.add(new Item(Item.CHANGED, b[ib++]));
    1016                 } else if(inserted > 0) {
    1017                     // System.out.println("\t+" + b[ib]);
    1018                     referenceDiff.add(new Item(Item.EMPTY, null));
    1019                     currentDiff.add(new Item(Item.INSERTED, b[ib++]));
    1020                 } else if(deleted > 0) {
    1021                     // System.out.println("-"+a[ia]);
    1022                     referenceDiff.add(new Item(Item.DELETED, a[ia++]));
    1023                     currentDiff.add(new Item(Item.EMPTY, null));
    1024                 }
    1025                 inserted--;
    1026                 deleted--;
    1027             }
    1028             script = script.link;
    1029         }
    1030         while(ia < a.length && ib < b.length) {
    1031             // System.out.println((ia < a.length ? " "+a[ia]+"\t" : "\t") + (ib < b.length ? " "+b[ib] : ""));
    1032             referenceDiff.add(new Item(Item.SAME, a[ia++]));
    1033             currentDiff.add(new Item(Item.SAME, b[ib++]));
    1034         }
    1035     }
    1036 }
Note: See TracChangeset for help on using the changeset viewer.