Changeset 23192 in osm for applications/editors/josm/plugins/alignways/src/org
- Timestamp:
- 2010-09-15T18:59:53+02:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/alignways/src/org/openstreetmap/josm/plugins/alignways/AlignWaysMode.java
r23165 r23192 28 28 public class AlignWaysMode extends MapMode /* implements MapViewPaintable */{ 29 29 30 31 32 33 34 35 36 37 30 private static final long serialVersionUID = -1090955708412011141L; 31 private final AlignWaysState noneSelected; 32 private final AlignWaysState referenceSelected; 33 private final AlignWaysState aligneeSelected; 34 private final AlignWaysState bothSelected; 35 private AlignWaysState currentState; 36 private AlignWaysSegmentMgr awSegs; 37 boolean tipShown; 38 38 39 40 41 42 43 44 45 46 47 48 49 39 public AlignWaysMode(MapFrame mapFrame, String name, String desc) { 40 super(tr(name), "alignways.png", tr(desc), 41 Shortcut.registerShortcut("mapmode:alignways", 42 tr("Mode: {0}", tr("Align Ways")), 43 KeyEvent.VK_N, Shortcut.GROUP_EDIT, Shortcut.SHIFT_DEFAULT), 44 mapFrame, Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); 45 noneSelected = new AlignWaysSelNoneState(); 46 referenceSelected = new AlignWaysSelRefState(); 47 aligneeSelected = new AlignWaysSelAlgnState(); 48 bothSelected = new AlignWaysSelBothState(); 49 tipShown = false; 50 50 51 51 } 52 52 53 54 55 56 57 58 59 60 61 62 63 53 @Override 54 public void enterMode() { 55 super.enterMode(); 56 boolean showTips = Boolean.parseBoolean(Main.pref.get("alignways.showtips", "true")); 57 if ((showTips) && (!tipShown)) { 58 showTips(); 59 } 60 awSegs = AlignWaysSegmentMgr.getInstance(Main.map.mapView); 61 Main.map.mapView.addMouseListener(this); 62 setCurrentState(noneSelected); 63 } 64 64 65 66 67 68 69 70 71 65 @Override 66 public void exitMode() { 67 super.exitMode(); 68 setCurrentState(noneSelected); 69 Main.map.mapView.removeMouseListener(this); 70 AlignWaysPlugin.getAwAction().setEnabled(false); 71 } 72 72 73 74 73 @Override 74 public void mouseClicked(MouseEvent e) { 75 75 76 77 76 boolean ctrlPressed = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0; 77 boolean altPressed = (e.getModifiers() & (ActionEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK)) != 0; 78 78 79 79 if (e.getButton() == MouseEvent.BUTTON1) { 80 80 81 82 81 if (altPressed) { 82 currentState.altLClick(this); 83 83 84 85 84 } else { 85 Point clickedPoint = new Point(e.getX(), e.getY()); 86 86 87 88 87 if (!ctrlPressed) { 88 // Alignee could change 89 89 90 91 92 90 if (awSegs.algnUpdate(clickedPoint)) { 91 currentState.leftClick(this); 92 } 93 93 94 95 96 97 98 99 100 101 94 } else { 95 // Reference could change 96 if (awSegs.refUpdate(clickedPoint)) { 97 currentState.ctrlLClick(this); 98 } 99 } 100 } 101 } 102 102 103 104 105 106 107 108 109 110 103 // Activate the Align Ways button if we have enough selections 104 if (currentState == bothSelected) { 105 AlignWaysPlugin.getAwAction().setEnabled(true); 106 } else { 107 AlignWaysPlugin.getAwAction().setEnabled(false); 108 } 109 Main.map.mapView.repaint(); 110 } 111 111 112 113 114 115 116 117 118 112 /** 113 * @param currentState 114 * One of the AlignWays states 115 */ 116 public void setCurrentState(AlignWaysState currentState) { 117 this.currentState = currentState; 118 currentState.setHelpText(); 119 119 120 121 122 123 124 125 126 127 128 129 120 if (currentState == noneSelected) { 121 awSegs.cleanupWays(); 122 // FIX: getCurrentDataSet may return null when the editable layer had 123 // already been removed by JOSM. This happens e.g. when the user closes 124 // JOSM while AlignWays mode is still active. 125 if (getCurrentDataSet() != null) { 126 getCurrentDataSet().clearSelection(); 127 } 128 } 129 } 130 130 131 132 133 134 135 136 131 /** 132 * @return the noneSelected 133 */ 134 public AlignWaysState getNoneSelected() { 135 return noneSelected; 136 } 137 137 138 139 140 141 142 143 138 /** 139 * @return the referenceSelected 140 */ 141 public AlignWaysState getReferenceSelected() { 142 return referenceSelected; 143 } 144 144 145 146 147 148 149 150 145 /** 146 * @return the aligneeSelected 147 */ 148 public AlignWaysState getAligneeSelected() { 149 return aligneeSelected; 150 } 151 151 152 153 154 155 156 157 152 /** 153 * @return the bothSelected 154 */ 155 public AlignWaysState getBothSelected() { 156 return bothSelected; 157 } 158 158 159 160 161 162 163 164 159 /** 160 * @return the current state 161 */ 162 public AlignWaysState getCurrentState() { 163 return currentState; 164 } 165 165 166 166 private void showTips() { 167 167 168 169 170 171 172 173 174 168 AlignWaysTipsPanel atd = new AlignWaysTipsPanel(); 169 Object[] okButton = {tr("I''m ready!")}; 170 JOptionPane tipPane = new JOptionPane(atd, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, okButton, okButton[0]); 171 // JDialog tipDialog = tipPane.createDialog(null, tr("AlignWays Tips")); 172 // Take Main.map as frame as it's better to inherit its icon than the default Java cup 173 JDialog tipDialog = tipPane.createDialog(Main.parent, tr("AlignWays Tips")); 174 // ((Frame)tipDialog.getOwner()).setIconImage(new ImageIcon(getClass().getResource("/images/blank.png")).getImage()); 175 175 176 177 178 176 tipDialog.setResizable(true); 177 tipDialog.setVisible(true); 178 tipShown = true; 179 179 180 180 tipDialog.dispose(); 181 181 182 182 Main.pref.put("alignways.showtips", !atd.isChkBoxSelected()); 183 183 184 184 } 185 185 }
Note:
See TracChangeset
for help on using the changeset viewer.