| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
|
| 21 |
|
package org.xmlhammer.gui.util; |
| 22 |
|
|
| 23 |
|
import javax.swing.JComboBox; |
| 24 |
|
import javax.swing.undo.AbstractUndoableEdit; |
| 25 |
|
|
| 26 |
|
import org.xmlhammer.gui.Page; |
| 27 |
|
import org.xmlhammer.gui.history.HistoryComboBox; |
| 28 |
|
|
| 29 |
|
public class UndoableComboBoxEdit extends AbstractUndoableEdit { |
| 30 |
|
private static final long serialVersionUID = 8615885869967750791L; |
| 31 |
|
|
| 32 |
10604 |
private Object current = null; |
| 33 |
10604 |
private Object previous = null; |
| 34 |
10604 |
private Page page = null; |
| 35 |
10604 |
private JComboBox combo = null; |
| 36 |
|
|
| 37 |
|
public UndoableComboBoxEdit(Page page, JComboBox combo, Object current, Object previous) { |
| 38 |
10604 |
super(); |
| 39 |
|
|
| 40 |
10604 |
this.page = page; |
| 41 |
10604 |
this.combo = combo; |
| 42 |
10604 |
this.current = current; |
| 43 |
10604 |
this.previous = previous; |
| 44 |
10604 |
} |
| 45 |
|
|
| 46 |
|
public void undo() { |
| 47 |
0 |
super.undo(); |
| 48 |
|
|
| 49 |
0 |
page.getProjectView().getOverviewPanel().selectNode(page); |
| 50 |
0 |
combo.requestFocusInWindow(); |
| 51 |
0 |
combo.setSelectedItem(previous); |
| 52 |
|
|
| 53 |
0 |
if (combo.isEditable() && previous != null) { |
| 54 |
0 |
combo.getEditor().setItem(previous); |
| 55 |
0 |
} else if (previous == null && combo instanceof HistoryComboBox) { |
| 56 |
0 |
combo.getEditor().setItem(((HistoryComboBox)combo).getEmptyValue()); |
| 57 |
|
} |
| 58 |
0 |
} |
| 59 |
|
|
| 60 |
|
public void redo() { |
| 61 |
0 |
super.redo(); |
| 62 |
|
|
| 63 |
0 |
page.getProjectView().getOverviewPanel().selectNode(page); |
| 64 |
0 |
combo.requestFocusInWindow(); |
| 65 |
0 |
combo.setSelectedItem(current); |
| 66 |
|
|
| 67 |
0 |
if (combo.isEditable() && current != null) { |
| 68 |
0 |
combo.getEditor().setItem(current); |
| 69 |
0 |
} else if (current == null && combo instanceof HistoryComboBox) { |
| 70 |
0 |
combo.getEditor().setItem(((HistoryComboBox)combo).getEmptyValue()); |
| 71 |
|
} |
| 72 |
0 |
} |
| 73 |
|
|
| 74 |
|
public String getUndoPresentationName() { |
| 75 |
0 |
return "Set "+previous.toString(); |
| 76 |
|
} |
| 77 |
|
|
| 78 |
|
public String getRedoPresentationName() { |
| 79 |
0 |
return "Reset "+current.toString(); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
public String toString() { |
| 83 |
10604 |
StringBuffer buffer = new StringBuffer("ComboBoxEdit Undo "); |
| 84 |
|
|
| 85 |
10604 |
if ( previous != null) { |
| 86 |
5608 |
buffer.append(previous.toString()); |
| 87 |
5608 |
} else { |
| 88 |
4996 |
buffer.append("null"); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
10604 |
buffer.append(" Redo "); |
| 92 |
|
|
| 93 |
10604 |
if ( current != null) { |
| 94 |
6338 |
buffer.append(current.toString()); |
| 95 |
6338 |
} else { |
| 96 |
4266 |
buffer.append("null"); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
10604 |
return buffer.toString(); |
| 100 |
|
} |
| 101 |
|
} |