Ignore:
Timestamp:
2012-12-20T22:43:02+01:00 (12 years ago)
Author:
jttt
Message:

use diff to show relation members in history dialog, jump to first change when different version is selected

File:
1 edited

Legend:

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

    r4689 r5627  
    33/// Feel free to move me somewhere else. Maybe a bit specific for josm.tools?
    44
     5import java.awt.Color;
    56import java.util.ArrayList;
    67
     8import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType;
    79import org.openstreetmap.josm.tools.Diff;
    810
     
    2426class TwoColumnDiff {
    2527    public static class Item {
    26         public static final int INSERTED = 1;
    27         public static final int DELETED = 2;
    28         public static final int CHANGED = 3;
    29         public static final int SAME = 4;
    30         public static final int EMPTY = 5; // value should be null
    31         public Item(int state, Object value) {
     28
     29        public enum DiffItemType {
     30            INSERTED(new Color(0xDD, 0xFF, 0xDD)), DELETED(new Color(255,197,197)), CHANGED(new Color(255,234,213)),
     31            SAME(new Color(234,234,234)), EMPTY(new Color(234,234,234));
     32
     33            private final Color color;
     34            private DiffItemType(Color color) {
     35                this.color = color;
     36            }
     37            public Color getColor() {
     38                return color;
     39            }
     40        }
     41
     42        public Item(DiffItemType state, Object value) {
    3243            this.state = state;
    33             this.value = state == EMPTY ? null : value;
     44            this.value = state == DiffItemType.EMPTY ? null : value;
    3445        }
    3546
    3647        public final Object value;
    37         public final int state;
     48        public final DiffItemType state;
    3849    }
    3950
     
    7283            while(ia < script.line0 && ib < script.line1){
    7384                // System.out.println(" "+a[ia] + "\t "+b[ib]);
    74                 Item cell = new Item(Item.SAME, a[ia]);
     85                Item cell = new Item(DiffItemType.SAME, a[ia]);
    7586                referenceDiff.add(cell);
    7687                currentDiff.add(cell);
     
    8293                if(inserted > 0 && deleted > 0) {
    8394                    // System.out.println("="+a[ia] + "\t="+b[ib]);
    84                     referenceDiff.add(new Item(Item.CHANGED, a[ia++]));
    85                     currentDiff.add(new Item(Item.CHANGED, b[ib++]));
     95                    referenceDiff.add(new Item(DiffItemType.CHANGED, a[ia++]));
     96                    currentDiff.add(new Item(DiffItemType.CHANGED, b[ib++]));
    8697                } else if(inserted > 0) {
    8798                    // System.out.println("\t+" + b[ib]);
    88                     referenceDiff.add(new Item(Item.EMPTY, null));
    89                     currentDiff.add(new Item(Item.INSERTED, b[ib++]));
     99                    referenceDiff.add(new Item(DiffItemType.EMPTY, null));
     100                    currentDiff.add(new Item(DiffItemType.INSERTED, b[ib++]));
    90101                } else if(deleted > 0) {
    91102                    // System.out.println("-"+a[ia]);
    92                     referenceDiff.add(new Item(Item.DELETED, a[ia++]));
    93                     currentDiff.add(new Item(Item.EMPTY, null));
     103                    referenceDiff.add(new Item(DiffItemType.DELETED, a[ia++]));
     104                    currentDiff.add(new Item(DiffItemType.EMPTY, null));
    94105                }
    95106                inserted--;
     
    100111        while(ia < a.length && ib < b.length) {
    101112            // System.out.println((ia < a.length ? " "+a[ia]+"\t" : "\t") + (ib < b.length ? " "+b[ib] : ""));
    102             referenceDiff.add(new Item(Item.SAME, a[ia++]));
    103             currentDiff.add(new Item(Item.SAME, b[ib++]));
     113            referenceDiff.add(new Item(DiffItemType.SAME, a[ia++]));
     114            currentDiff.add(new Item(DiffItemType.SAME, b[ib++]));
    104115        }
    105116    }
Note: See TracChangeset for help on using the changeset viewer.