Changeset 23192 in osm for applications/editors/josm/plugins/alignways
- Timestamp:
- 2010-09-15T18:59:53+02:00 (15 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 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;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 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;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 @Override54 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 }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 @Override66 public void exitMode() {67 super.exitMode();68 setCurrentState(noneSelected);69 Main.map.mapView.removeMouseListener(this);70 AlignWaysPlugin.getAwAction().setEnabled(false);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 @Override74 public void mouseClicked(MouseEvent e) {73 @Override 74 public void mouseClicked(MouseEvent e) { 75 75 76 boolean ctrlPressed = (e.getModifiers() & ActionEvent.CTRL_MASK) != 0;77 boolean altPressed = (e.getModifiers() & (ActionEvent.ALT_MASK | InputEvent.ALT_GRAPH_MASK)) != 0;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 if (e.getButton() == MouseEvent.BUTTON1) {79 if (e.getButton() == MouseEvent.BUTTON1) { 80 80 81 if (altPressed) {82 currentState.altLClick(this);81 if (altPressed) { 82 currentState.altLClick(this); 83 83 84 } else {85 Point clickedPoint = new Point(e.getX(), e.getY());84 } else { 85 Point clickedPoint = new Point(e.getX(), e.getY()); 86 86 87 if (!ctrlPressed) {88 // Alignee could change87 if (!ctrlPressed) { 88 // Alignee could change 89 89 90 if (awSegs.algnUpdate(clickedPoint)) {91 currentState.leftClick(this);92 }90 if (awSegs.algnUpdate(clickedPoint)) { 91 currentState.leftClick(this); 92 } 93 93 94 } else {95 // Reference could change96 if (awSegs.refUpdate(clickedPoint)) {97 currentState.ctrlLClick(this);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 // Activate the Align Ways button if we have enough selections104 if (currentState == bothSelected) {105 AlignWaysPlugin.getAwAction().setEnabled(true);106 } else {107 AlignWaysPlugin.getAwAction().setEnabled(false);108 }109 Main.map.mapView.repaint();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 * @param currentState114 * One of the AlignWays states115 */116 public void setCurrentState(AlignWaysState currentState) {117 this.currentState = currentState;118 currentState.setHelpText();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 if (currentState == noneSelected) {121 awSegs.cleanupWays();122 // FIX: getCurrentDataSet may return null when the editable layer had123 // already been removed by JOSM. This happens e.g. when the user closes124 // JOSM while AlignWays mode is still active.125 if (getCurrentDataSet() != null) {126 getCurrentDataSet().clearSelection();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 * @return the noneSelected133 */134 public AlignWaysState getNoneSelected() {135 return noneSelected;136 }131 /** 132 * @return the noneSelected 133 */ 134 public AlignWaysState getNoneSelected() { 135 return noneSelected; 136 } 137 137 138 /**139 * @return the referenceSelected140 */141 public AlignWaysState getReferenceSelected() {142 return referenceSelected;143 }138 /** 139 * @return the referenceSelected 140 */ 141 public AlignWaysState getReferenceSelected() { 142 return referenceSelected; 143 } 144 144 145 /**146 * @return the aligneeSelected147 */148 public AlignWaysState getAligneeSelected() {149 return aligneeSelected;150 }145 /** 146 * @return the aligneeSelected 147 */ 148 public AlignWaysState getAligneeSelected() { 149 return aligneeSelected; 150 } 151 151 152 /**153 * @return the bothSelected154 */155 public AlignWaysState getBothSelected() {156 return bothSelected;157 }152 /** 153 * @return the bothSelected 154 */ 155 public AlignWaysState getBothSelected() { 156 return bothSelected; 157 } 158 158 159 /**160 * @return the current state161 */162 public AlignWaysState getCurrentState() {163 return currentState;164 }159 /** 160 * @return the current state 161 */ 162 public AlignWaysState getCurrentState() { 163 return currentState; 164 } 165 165 166 private void showTips() {166 private void showTips() { 167 167 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 cup173 JDialog tipDialog = tipPane.createDialog(Main.parent, tr("AlignWays Tips"));174 // ((Frame)tipDialog.getOwner()).setIconImage(new ImageIcon(getClass().getResource("/images/blank.png")).getImage());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 tipDialog.setResizable(true);177 tipDialog.setVisible(true);178 tipShown = true;176 tipDialog.setResizable(true); 177 tipDialog.setVisible(true); 178 tipShown = true; 179 179 180 tipDialog.dispose();180 tipDialog.dispose(); 181 181 182 Main.pref.put("alignways.showtips", !atd.isChkBoxSelected());182 Main.pref.put("alignways.showtips", !atd.isChkBoxSelected()); 183 183 184 }184 } 185 185 }
Note:
See TracChangeset
for help on using the changeset viewer.
