Changeset 26666 in osm
- Timestamp:
- 2011-09-17T19:40:13+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/turnrestrictions/src/org/openstreetmap/josm/plugins/turnrestrictions/editor/RelationMemberTable.java
r23526 r26666 39 39 40 40 /** 41 * RelationMemberTable is the table for editing the raw member list of 41 * RelationMemberTable is the table for editing the raw member list of 42 42 * a turn restriction. 43 * 43 * 44 44 */ 45 45 public class RelationMemberTable extends JTable { 46 static private final Logger logger = Logger.getLogger(RelationMemberTable.class.getName());47 48 46 private TurnRestrictionEditorModel model; 49 47 private DeleteAction actDelete; … … 52 50 private MoveDownAction actMoveDown; 53 51 private TransferHandler transferHandler; 54 52 55 53 public RelationMemberTable(TurnRestrictionEditorModel model) { 56 54 super( … … 67 65 // register the popup menu launcher 68 66 addMouseListener(new TablePopupLauncher()); 69 67 70 68 // transfer handling 71 69 setDragEnabled(true); 72 70 setTransferHandler(new RelationMemberTransferHandler()); 73 71 setDropTarget(new RelationMemberTableDropTarget()); 74 72 75 73 // initialize the delete action 76 74 // … … 78 76 model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actDelete); 79 77 registerKeyboardAction(actDelete, KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,0), WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 80 78 81 79 // initialize the paste action (will be used in the popup, the action map already includes 82 // the standard paste action for transfer handling) 80 // the standard paste action for transfer handling) 83 81 actPaste = new PasteAction(); 84 82 85 83 actMoveUp = new MoveUpAction(); 86 84 model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actMoveUp); 87 85 registerKeyboardAction(actMoveUp,actMoveUp.getKeyStroke(), WHEN_FOCUSED); 88 86 89 87 actMoveDown = new MoveDownAction(); 90 88 model.getRelationMemberEditorModel().getRowSelectionModel().addListSelectionListener(actMoveDown); … … 93 91 94 92 /** 95 * The action for deleting the selected table cells 96 * 93 * The action for deleting the selected table cells 94 * 97 95 */ 98 96 class DeleteAction extends AbstractAction implements ListSelectionListener{ … … 104 102 updateEnabledState(); 105 103 } 106 104 107 105 public void updateEnabledState() { 108 106 setEnabled(model.getRelationMemberEditorModel().getRowSelectionModel().getMinSelectionIndex()>=0); … … 116 114 updateEnabledState(); 117 115 } 118 } 119 116 } 117 120 118 /** 121 119 * The action for pasting into the relation member table 122 * 120 * 123 121 */ 124 class PasteAction extends AbstractAction{ 122 class PasteAction extends AbstractAction{ 125 123 public PasteAction() { 126 124 putValue(NAME, tr("Paste")); … … 130 128 updateEnabledState(); 131 129 } 132 130 133 131 public void updateEnabledState() { 134 132 DataFlavor[] flavors = Toolkit.getDefaultToolkit().getSystemClipboard().getAvailableDataFlavors(); … … 156 154 } catch(UnsupportedFlavorException e){ 157 155 e.printStackTrace(); 158 } 159 } 160 } 161 162 class MoveDownAction extends AbstractAction implements ListSelectionListener{ 156 } 157 } 158 } 159 160 class MoveDownAction extends AbstractAction implements ListSelectionListener{ 163 161 private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, KeyEvent.ALT_DOWN_MASK); 164 162 public MoveDownAction(){ … … 169 167 updateEnabledState(); 170 168 } 171 169 172 170 public void actionPerformed(ActionEvent e) { 173 171 model.getRelationMemberEditorModel().moveDownSelected(); … … 177 175 setEnabled(model.getRelationMemberEditorModel().canMoveDown()); 178 176 } 179 177 180 178 public void valueChanged(ListSelectionEvent e) { 181 updateEnabledState(); 179 updateEnabledState(); 182 180 } 183 181 public KeyStroke getKeyStroke() { … … 185 183 } 186 184 } 187 185 188 186 class MoveUpAction extends AbstractAction implements ListSelectionListener{ 189 187 private KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_UP, KeyEvent.ALT_DOWN_MASK); … … 196 194 updateEnabledState(); 197 195 } 198 196 199 197 public void actionPerformed(ActionEvent e) { 200 198 model.getRelationMemberEditorModel().moveUpSelected(); … … 204 202 setEnabled(model.getRelationMemberEditorModel().canMoveUp()); 205 203 } 206 204 207 205 public void valueChanged(ListSelectionEvent e) { 208 updateEnabledState(); 206 updateEnabledState(); 209 207 } 210 208 public KeyStroke getKeyStroke() { … … 212 210 } 213 211 } 214 212 215 213 class TablePopupLauncher extends PopupMenuLauncher { 216 214 @Override … … 222 220 } 223 221 new PopupMenu().show(RelationMemberTable.this, evt.getX(), evt.getY()); 224 } 225 } 226 222 } 223 } 224 227 225 class PopupMenu extends JPopupMenu { 228 226 public PopupMenu() { … … 237 235 } 238 236 } 239 237 240 238 /** 241 * The transfer handler for the relation member table. 239 * The transfer handler for the relation member table. 242 240 * 243 241 */ 244 242 class RelationMemberTransferHandler extends TransferHandler { 245 243 246 244 @Override 247 245 public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { … … 266 264 } catch(UnsupportedFlavorException e){ 267 265 e.printStackTrace(); 268 } 266 } 269 267 return false; 270 268 } … … 275 273 } 276 274 } 277 275 278 276 /** 279 277 * A custom drop target for the relation member table. During dragging we need to 280 * disable colum selection model. 278 * disable colum selection model. 281 279 * 282 280 */ 283 class RelationMemberTableDropTarget extends DropTarget{ 284 private boolean dropAccepted = false; 285 281 class RelationMemberTableDropTarget extends DropTarget{ 282 private boolean dropAccepted = false; 283 286 284 /** 287 285 * Replies true if {@code transferFlavors} includes the data flavor {@link PrimitiveIdTransferable#PRIMITIVE_ID_LIST_FLAVOR}. … … 295 293 } 296 294 return false; 297 } 298 295 } 296 299 297 public synchronized void dragEnter(DropTargetDragEvent dtde) { 300 298 if (isSupportedFlavor(dtde.getCurrentDataFlavors())) { 301 299 if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) != 0){ 302 dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); 300 dtde.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE); 303 301 setColumnSelectionAllowed(false); 304 302 dropAccepted = true; … … 310 308 } 311 309 } 312 310 313 311 public synchronized void dragExit(DropTargetEvent dte) { 314 312 setColumnSelectionAllowed(true); 315 313 dropAccepted = false; 316 314 } 317 315 318 316 @Override 319 317 public synchronized void dragOver(DropTargetDragEvent dtde) { … … 322 320 if (row >= 0 && row != selectedRow){ 323 321 getSelectionModel().setSelectionInterval(row, row); 324 } 322 } 325 323 } 326 324 327 325 public synchronized void drop(DropTargetDropEvent dtde) { 328 326 try { 329 if (!dropAccepted) return; 327 if (!dropAccepted) return; 330 328 if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) { 331 329 return; … … 347 345 } 348 346 } 349 347 350 348 public synchronized void dropActionChanged(DropTargetDragEvent dtde) { 351 349 if ((dtde.getSourceActions() & DnDConstants.ACTION_COPY_OR_MOVE) == 0) {
Note:
See TracChangeset
for help on using the changeset viewer.