Java 类javax.swing.undo.StateEdit 实例源码

项目:gcs    文件:ListOutline.java   
@Override
public void deleteSelection() {
    if (canDeleteSelection()) {
        OutlineModel model = getModel();
        StateEdit edit = new StateEdit(model, CLEAR_UNDO);
        Row[] rows = model.getSelectionAsList(true).toArray(new Row[0]);
        mDataFile.startNotify();
        model.removeSelection();
        for (int i = rows.length - 1; i >= 0; i--) {
            rows[i].removeFromParent();
        }
        if (model.getRowCount() > 0) {
            updateAllRows();
        }
        // Send it out again, since we have a few chicken-and-egg
        // scenarios to deal with... <sigh>
        mDataFile.notify(mRowSetChangedID, null);
        mDataFile.endNotify();
        edit.end();
        postUndo(edit);
    }
}
项目:toolkit    文件:Outline.java   
/**
 * Sort on a column.
 *
 * @param column The column to sort on.
 * @param ascending Pass in <code>true</code> for an ascending sort.
 * @param add Pass in <code>true</code> to add this column to the end of the sort order, or
 *            <code>false</code> to make this column the primary and only sort column.
 */
public void setSort(Column column, boolean ascending, boolean add) {
    StateEdit edit = new StateEdit(mModel, SORT_UNDO_TITLE);
    int count = mModel.getColumnCount();
    int i;

    if (!add) {
        for (i = 0; i < count; i++) {
            Column col = mModel.getColumnAtIndex(i);
            if (column == col) {
                col.setSortCriteria(0, ascending);
            } else {
                col.setSortCriteria(-1, col.isSortAscending());
            }
        }
    } else {
        if (column.getSortSequence() == -1) {
            int highest = -1;
            for (i = 0; i < count; i++) {
                int sortOrder = mModel.getColumnAtIndex(i).getSortSequence();
                if (sortOrder > highest) {
                    highest = sortOrder;
                }
            }
            column.setSortCriteria(highest + 1, ascending);
        } else {
            column.setSortCriteria(column.getSortSequence(), ascending);
        }
    }
    mModel.sort();
    edit.end();
    postUndo(edit);
}
项目:gcs    文件:SheetDockable.java   
/**
 * Adds rows to the sheet.
 *
 * @param rows The rows to add.
 */
public void addRows(List<Row> rows) {
    HashMap<ListOutline, StateEdit> map = new HashMap<>();
    HashMap<Outline, ArrayList<Row>> selMap = new HashMap<>();
    HashMap<Outline, ArrayList<ListRow>> nameMap = new HashMap<>();
    ListOutline outline = null;

    for (Row row : rows) {
        if (row instanceof Advantage) {
            outline = mSheet.getAdvantageOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Advantage(getDataFile(), (Advantage) row, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Technique) {
            outline = mSheet.getSkillOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Technique(getDataFile(), (Technique) row, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Skill) {
            outline = mSheet.getSkillOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Skill(getDataFile(), (Skill) row, true, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Spell) {
            outline = mSheet.getSpellOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Spell(getDataFile(), (Spell) row, true, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Equipment) {
            outline = mSheet.getEquipmentOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Equipment(getDataFile(), (Equipment) row, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Note) {
            outline = mSheet.getNoteOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Note(getDataFile(), (Note) row, true);
            addCompleteRow(outline, row, selMap);
        } else {
            row = null;
        }
        if (row instanceof ListRow) {
            ArrayList<ListRow> process = nameMap.get(outline);
            if (process == null) {
                process = new ArrayList<>();
                nameMap.put(outline, process);
            }
            addRowsToBeProcessed(process, (ListRow) row);
        }
    }
    for (ListOutline anOutline : map.keySet()) {
        OutlineModel model = anOutline.getModel();
        model.select(selMap.get(anOutline), false);
        StateEdit edit = map.get(anOutline);
        edit.end();
        anOutline.postUndo(edit);
        anOutline.scrollSelectionIntoView();
        anOutline.requestFocus();
    }
    if (!nameMap.isEmpty()) {
        EventQueue.invokeLater(new RowPostProcessor(nameMap));
    }
}
项目:gcs    文件:TemplateDockable.java   
/**
 * Adds rows to the display.
 *
 * @param rows The rows to add.
 */
public void addRows(List<Row> rows) {
    HashMap<ListOutline, StateEdit> map = new HashMap<>();
    HashMap<Outline, ArrayList<Row>> selMap = new HashMap<>();
    HashMap<Outline, ArrayList<ListRow>> nameMap = new HashMap<>();
    ListOutline outline = null;

    for (Row row : rows) {
        if (row instanceof Advantage) {
            outline = mTemplate.getAdvantageOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Advantage(getDataFile(), (Advantage) row, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Technique) {
            outline = mTemplate.getSkillOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Technique(getDataFile(), (Technique) row, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Skill) {
            outline = mTemplate.getSkillOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Skill(getDataFile(), (Skill) row, true, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Spell) {
            outline = mTemplate.getSpellOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Spell(getDataFile(), (Spell) row, true, true);
            addCompleteRow(outline, row, selMap);
        } else if (row instanceof Equipment) {
            outline = mTemplate.getEquipmentOutline();
            if (!map.containsKey(outline)) {
                map.put(outline, new StateEdit(outline.getModel(), ADD_ROWS));
            }
            row = new Equipment(getDataFile(), (Equipment) row, true);
            addCompleteRow(outline, row, selMap);
        } else {
            row = null;
        }
        if (row instanceof ListRow) {
            ArrayList<ListRow> process = nameMap.get(outline);

            if (process == null) {
                process = new ArrayList<>();
                nameMap.put(outline, process);
            }
            addRowsToBeProcessed(process, (ListRow) row);
        }
    }
    for (ListOutline anOutline : map.keySet()) {
        OutlineModel model = anOutline.getModel();

        model.select(selMap.get(anOutline), false);
        StateEdit edit = map.get(anOutline);
        edit.end();
        anOutline.postUndo(edit);
        anOutline.scrollSelectionIntoView();
        anOutline.requestFocus();
    }
    if (!nameMap.isEmpty()) {
        EventQueue.invokeLater(new RowPostProcessor(nameMap));
    }
}