- Timestamp:
- 2014-03-19T01:01:04+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/pair/relation/RelationMemberTableCellEditor.java
r6084 r6912 13 13 import org.openstreetmap.josm.gui.widgets.JosmTextField; 14 14 15 16 15 /** 17 16 * {@link TableCellEditor} for the role column in a table for {@link RelationMember}s. 18 * 17 * @since 1631 19 18 */ 20 public class RelationMemberTableCellEditor extends AbstractCellEditor implements TableCellEditor {19 public class RelationMemberTableCellEditor extends AbstractCellEditor implements TableCellEditor { 21 20 22 21 private final JosmTextField editor; … … 54 53 return editor.getText(); 55 54 } 56 57 55 } -
trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictDecisionEditor.java
r6084 r6912 9 9 import javax.swing.table.TableCellEditor; 10 10 11 import org.openstreetmap.josm.gui.util. TableCellEditorSupport;11 import org.openstreetmap.josm.gui.util.CellEditorSupport; 12 12 import org.openstreetmap.josm.gui.widgets.JosmComboBox; 13 13 14 14 public class RelationMemberConflictDecisionEditor extends JosmComboBox implements TableCellEditor { 15 15 16 /** 17 * Constructs a new {@code RelationMemberConflictDecisionEditor}. 18 */ 16 19 public RelationMemberConflictDecisionEditor() { 17 20 super(RelationMemberConflictDecisionType.values()); 18 21 setOpaque(true); 19 22 setRenderer(new RelationMemberConflictDecisionRenderer()); 20 tableCellEditorSupport = new TableCellEditorSupport(this);23 tableCellEditorSupport = new CellEditorSupport(this); 21 24 } 25 22 26 /* --------------------------------------------------------------------------------- */ 23 27 /* TableCellEditor */ … … 30 34 } 31 35 32 private TableCellEditorSupport tableCellEditorSupport;36 private final CellEditorSupport tableCellEditorSupport; 33 37 private RelationMemberConflictDecisionType originalValue; 34 38 -
trunk/src/org/openstreetmap/josm/gui/io/ActionFlagsTableCell.java
r6104 r6912 10 10 import java.awt.event.ActionListener; 11 11 import java.util.EventObject; 12 import java.util.concurrent.CopyOnWriteArrayList;13 12 14 13 import javax.swing.AbstractAction; … … 18 17 import javax.swing.JTable; 19 18 import javax.swing.event.CellEditorListener; 20 import javax.swing.event.ChangeEvent;21 19 import javax.swing.table.TableCellEditor; 22 20 import javax.swing.table.TableCellRenderer; 23 21 22 import org.openstreetmap.josm.gui.util.CellEditorSupport; 24 23 import org.openstreetmap.josm.tools.GBC; 25 24 … … 30 29 * 31 30 * Intended usage is like this: 32 * ActionFlagsTableCell aftc = new ActionFlagsTableCell(); 33 * col = new TableColumn(0); 34 * col.setCellRenderer(aftc); 35 * col.setCellEditor(aftc); 31 * <code> 32 * <br>ActionFlagsTableCell aftc = new ActionFlagsTableCell(); 33 * <br>col = new TableColumn(0); 34 * <br>col.setCellRenderer(aftc); 35 * <br>col.setCellEditor(aftc); 36 * </code> 36 37 */ 37 38 class ActionFlagsTableCell extends JPanel implements TableCellRenderer, TableCellEditor { 38 pr otectedfinal JCheckBox[] checkBoxes = new JCheckBox[2];39 private CopyOnWriteArrayList<CellEditorListener> listeners;39 private final JCheckBox[] checkBoxes = new JCheckBox[2]; 40 private final CellEditorSupport cellEditorSupport = new CellEditorSupport(this); 40 41 41 42 private ActionListener al = new ActionListener() { 42 43 @Override 43 44 public void actionPerformed(ActionEvent e) { 44 fireEditingStopped();45 cellEditorSupport.fireEditingStopped(); 45 46 } 46 47 }; 47 48 48 49 public ActionFlagsTableCell() { 49 super();50 listeners = new CopyOnWriteArrayList<CellEditorListener>();51 52 50 checkBoxes[0] = new JCheckBox(tr("Upload")); 53 51 checkBoxes[1] = new JCheckBox(tr("Save")); … … 63 61 public void actionPerformed(ActionEvent e) { 64 62 b.setSelected(!b.isSelected()); 65 fireEditingStopped();63 cellEditorSupport.fireEditingStopped(); 66 64 } 67 65 }); … … 94 92 @Override 95 93 public void addCellEditorListener(CellEditorListener l) { 96 if (l != null) { 97 listeners.addIfAbsent(l); 98 } 99 } 100 101 protected void fireEditingCanceled() { 102 for (CellEditorListener l: listeners) { 103 l.editingCanceled(new ChangeEvent(this)); 104 } 105 } 106 107 protected void fireEditingStopped() { 108 for (CellEditorListener l: listeners) { 109 l.editingStopped(new ChangeEvent(this)); 110 } 94 cellEditorSupport.addCellEditorListener(l); 111 95 } 112 96 113 97 @Override 114 98 public void cancelCellEditing() { 115 fireEditingCanceled();99 cellEditorSupport.fireEditingCanceled(); 116 100 } 117 101 … … 131 115 @Override 132 116 public void removeCellEditorListener(CellEditorListener l) { 133 listeners.remove(l);117 cellEditorSupport.removeCellEditorListener(l); 134 118 } 135 119 … … 141 125 @Override 142 126 public boolean stopCellEditing() { 143 fireEditingStopped();127 cellEditorSupport.fireEditingStopped(); 144 128 return true; 145 129 } -
trunk/src/org/openstreetmap/josm/gui/io/LayerNameAndFilePathTableCell.java
r6889 r6912 14 14 import java.io.File; 15 15 import java.util.EventObject; 16 import java.util.concurrent.CopyOnWriteArrayList;17 16 18 17 import javax.swing.AbstractAction; … … 23 22 import javax.swing.JTable; 24 23 import javax.swing.event.CellEditorListener; 25 import javax.swing.event.ChangeEvent;26 24 import javax.swing.table.TableCellEditor; 27 25 import javax.swing.table.TableCellRenderer; 28 26 29 27 import org.openstreetmap.josm.actions.SaveActionBase; 28 import org.openstreetmap.josm.gui.util.CellEditorSupport; 29 import org.openstreetmap.josm.gui.widgets.JosmTextField; 30 30 import org.openstreetmap.josm.tools.GBC; 31 import org.openstreetmap.josm.gui.widgets.JosmTextField;32 31 33 32 class LayerNameAndFilePathTableCell extends JPanel implements TableCellRenderer, TableCellEditor { … … 43 42 private static final GBC defaultCellStyle = GBC.eol().fill(GBC.HORIZONTAL).insets(2, 0, 2, 0); 44 43 45 private CopyOnWriteArrayList<CellEditorListener> listeners;44 private final CellEditorSupport cellEditorSupport = new CellEditorSupport(this); 46 45 private File value; 47 46 … … 71 70 btnFileChooser.setPreferredSize(new Dimension(20, 19)); 72 71 btnFileChooser.setOpaque(true); 73 74 listeners = new CopyOnWriteArrayList<CellEditorListener>();75 72 } 76 73 … … 93 90 } 94 91 95 /** renderer used while the file path is being edited **/ 96 @Override 97 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, 98 int row, int column) { 92 @Override 93 public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { 99 94 removeAll(); 100 95 SaveLayerInfo info = (SaveLayerInfo)value; … … 182 177 @Override 183 178 public void addCellEditorListener(CellEditorListener l) { 184 if (l != null) { 185 listeners.addIfAbsent(l); 186 } 187 } 188 189 protected void fireEditingCanceled() { 190 for (CellEditorListener l: listeners) { 191 l.editingCanceled(new ChangeEvent(this)); 192 } 193 } 194 195 protected void fireEditingStopped() { 196 for (CellEditorListener l: listeners) { 197 l.editingStopped(new ChangeEvent(this)); 198 } 179 cellEditorSupport.addCellEditorListener(l); 199 180 } 200 181 201 182 @Override 202 183 public void cancelCellEditing() { 203 fireEditingCanceled();184 cellEditorSupport.fireEditingCanceled(); 204 185 } 205 186 … … 216 197 @Override 217 198 public void removeCellEditorListener(CellEditorListener l) { 218 listeners.remove(l);199 cellEditorSupport.removeCellEditorListener(l); 219 200 } 220 201 … … 231 212 value = new File(tfFilename.getText()); 232 213 } 233 fireEditingStopped();214 cellEditorSupport.fireEditingStopped(); 234 215 return true; 235 216 } -
trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompletingTextField.java
r6890 r6912 20 20 21 21 import org.openstreetmap.josm.Main; 22 import org.openstreetmap.josm.gui.util. TableCellEditorSupport;22 import org.openstreetmap.josm.gui.util.CellEditorSupport; 23 23 import org.openstreetmap.josm.gui.widgets.JosmTextField; 24 24 25 26 25 /** 27 * AutoCompletingTextField is a ntext field with autocompletion behaviour. It26 * AutoCompletingTextField is a text field with autocompletion behaviour. It 28 27 * can be used as table cell editor in {@link JTable}s. 29 28 * … … 31 30 * managed in a {@link AutoCompletionList}. 32 31 * 33 * 32 * @since 1762 34 33 */ 35 34 public class AutoCompletingTextField extends JosmTextField implements ComboBoxEditor, TableCellEditor { … … 42 41 class AutoCompletionDocument extends PlainDocument { 43 42 44 /**45 * inserts a string at a specific position46 *47 */48 43 @Override 49 44 public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { … … 126 121 protected AutoCompletionList autoCompletionList = null; 127 122 128 /**129 * creates the default document model for this editor130 *131 */132 123 @Override 133 124 protected Document createDefaultModel() { … … 156 147 } 157 148 ); 158 tableCellEditorSupport = new TableCellEditorSupport(this);159 } 160 161 /** 162 * constructor149 tableCellEditorSupport = new CellEditorSupport(this); 150 } 151 152 /** 153 * Constructs a new {@code AutoCompletingTextField}. 163 154 */ 164 155 public AutoCompletingTextField() { … … 166 157 } 167 158 159 /** 160 * Constructs a new {@code AutoCompletingTextField}. 161 * @param columns the number of columns to use to calculate the preferred width; 162 * if columns is set to zero, the preferred width will be whatever naturally results from the component implementation 163 */ 168 164 public AutoCompletingTextField(int columns) { 169 165 super(columns); … … 178 174 179 175 /** 180 * 176 * Returns the auto completion list. 181 177 * @return the auto completion list; may be null, if no auto completion list is set 182 178 */ … … 186 182 187 183 /** 188 * sets the auto completion list184 * Sets the auto completion list. 189 185 * @param autoCompletionList the auto completion list; if null, auto completion is 190 186 * disabled … … 226 222 /* ------------------------------------------------------------------------------------ */ 227 223 228 private TableCellEditorSupport tableCellEditorSupport;224 private CellEditorSupport tableCellEditorSupport; 229 225 private String originalValue; 230 226 … … 246 242 tableCellEditorSupport.removeCellEditorListener(l); 247 243 } 244 248 245 @Override 249 246 public void cancelCellEditing() { 250 247 restoreOriginalValue(); 251 248 tableCellEditorSupport.fireEditingCanceled(); 252 253 249 } 254 250 -
trunk/src/org/openstreetmap/josm/gui/util/CellEditorSupport.java
r6909 r6912 6 6 import java.util.List; 7 7 8 import javax.swing.CellEditor; 8 9 import javax.swing.event.CellEditorListener; 9 10 import javax.swing.event.ChangeEvent; 10 11 11 public class TableCellEditorSupport { 12 private Object editor; 13 private List<CellEditorListener> listeners; 12 /** 13 * Utility class used to ease implementation of {@link CellEditor} interface, 14 * or one of its sub-interfaces, for classes that cannot extend {@link javax.swing.AbstractCellEditor}. 15 * @since 6912 16 */ 17 public class CellEditorSupport { 18 private final CellEditor editor; 19 private final List<CellEditorListener> listeners; 14 20 15 public TableCellEditorSupport(Object editor) { 21 /** 22 * Constructs a new {@code CellEditorSupport}. 23 * @param editor The cell editor backed by this 24 */ 25 public CellEditorSupport(CellEditor editor) { 16 26 this.editor = editor; 17 listeners = new LinkedList<CellEditorListener>();27 this.listeners = new LinkedList<CellEditorListener>(); 18 28 } 19 29 … … 24 34 } 25 35 26 public void addCellEditorListener(CellEditorListener l) { 36 /** 37 * Worker for {@link CellEditor#addCellEditorListener(CellEditorListener)} method. 38 * @param l the CellEditorListener 39 */ 40 public final void addCellEditorListener(CellEditorListener l) { 27 41 synchronized (this) { 28 42 if (l != null && ! listeners.contains(l)) { … … 31 45 } 32 46 } 33 public void removeCellEditorListener(CellEditorListener l) { 47 48 /** 49 * Worker for {@link CellEditor#removeCellEditorListener(CellEditorListener)} method. 50 * @param l the CellEditorListener 51 */ 52 public final void removeCellEditorListener(CellEditorListener l) { 34 53 synchronized (this) { 35 54 if (l != null &&listeners.contains(l)) { … … 39 58 } 40 59 41 public void fireEditingCanceled() { 60 /** 61 * Fires "editing canceled" event to listeners. 62 */ 63 public final void fireEditingCanceled() { 42 64 for (CellEditorListener listener: getListeners()) { 43 65 listener.editingCanceled(new ChangeEvent(editor)); … … 45 67 } 46 68 47 public void fireEditingStopped() { 69 /** 70 * Fires "editing stopped" event to listeners. 71 */ 72 public final void fireEditingStopped() { 48 73 for (CellEditorListener listener: getListeners()) { 49 74 listener.editingStopped(new ChangeEvent(editor));
Note:
See TracChangeset
for help on using the changeset viewer.