Changeset 27122 in osm for applications/editors/josm
- Timestamp:
- 2011-11-22T17:06:36+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/piclayer
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/piclayer/build.xml
r27120 r27122 22 22 --> 23 23 <project name="PicLayer" default="dist" basedir="."> 24 <property name="commit.message" value="PicLayer rewritten - lots changed"/>24 <property name="commit.message" value="PicLayer - toolbar buttons are hidden when layer is not active"/> 25 25 <property name="plugin.main.version" value="4549"/> 26 26 <!-- -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ActionVisibilityChangeMenu.java
r27120 r27122 10 10 11 11 import org.openstreetmap.josm.Main; 12 import org.openstreetmap.josm.gui.IconToggleButton;13 12 14 13 enum PicActions {MOVE_PICTURE, MOVE_POINT, TRANSFORM_POINT, SCALEX, SCALEY, SCALEXY, SHEAR, ROTATE} … … 16 15 @SuppressWarnings("serial") 17 16 public class ActionVisibilityChangeMenu extends JMenu { 18 19 17 public ActionVisibilityChangeMenu() { 18 super(tr("Change visibility of controls")); 20 19 21 add(new SwitchVisibilityMenuItem("Move Picture", "piclayer.actionvisibility.move", PicLayerPlugin.movePictureButton, true)); 22 add(new SwitchVisibilityMenuItem("Move Point", "piclayer.actionvisibility.movepoint", PicLayerPlugin.movePointButton, true)); 23 add(new SwitchVisibilityMenuItem("Transform Point", "piclayer.actionvisibility.transformpoint", PicLayerPlugin.transformPointButton, true)); 24 add(new SwitchVisibilityMenuItem("Rotate", "piclayer.actionvisibility.rotate", PicLayerPlugin.rotatePictureButton, false)); 25 add(new SwitchVisibilityMenuItem("Scale X", "piclayer.actionvisibility.scalex", PicLayerPlugin.scalexPictureButton, false)); 26 add(new SwitchVisibilityMenuItem("Scale Y", "piclayer.actionvisibility.scaley", PicLayerPlugin.scaleyPictureButton, false)); 27 add(new SwitchVisibilityMenuItem("Scale", "piclayer.actionvisibility.scale", PicLayerPlugin.scalexyPictureButton, false)); 28 add(new SwitchVisibilityMenuItem("Shear", "piclayer.actionvisibility.shear", PicLayerPlugin.shearPictureButton, false)); 29 } 20 for (int i = 0;i < PicLayerPlugin.buttonList.size(); i++) { 21 add(new SwitchVisibilityMenuItem(PicLayerPlugin.buttonList.get(i))); 22 } 23 } 30 24 } 31 25 32 26 @SuppressWarnings("serial") 33 27 class SwitchVisibilityMenuItem extends JCheckBoxMenuItem { 34 public SwitchVisibilityMenuItem(String name, final String key, final IconToggleButton button, final boolean def) { 35 super(); 36 setSelected(Main.pref.getBoolean(key, def)); 37 button.setVisible(isSelected()); 38 setAction(new AbstractAction() { 39 @Override 40 public void actionPerformed(ActionEvent e) { 41 boolean val = !Main.pref.getBoolean(key, def); 42 Main.pref.put(key, val); 43 SwitchVisibilityMenuItem.this.setSelected(val); 44 button.setVisible(val); 45 } 46 }); 47 setText(name); 48 } 28 public SwitchVisibilityMenuItem(final PicToggleButton button) { 29 super(); 30 setSelected(Main.pref.getBoolean(button.getVisibilityKey(), button.getDefVisibility())); 31 setAction(new AbstractAction() { 32 @Override 33 public void actionPerformed(ActionEvent e) { 34 boolean val = !Main.pref.getBoolean(button.getVisibilityKey(), button.getDefVisibility()); 35 Main.pref.put(button.getVisibilityKey(), val); 36 SwitchVisibilityMenuItem.this.setSelected(val); 37 button.setVisible(val); 38 } 39 }); 40 setText(tr(button.getBtnName())); 41 } 49 42 } -
applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
r27120 r27122 25 25 26 26 import java.awt.event.KeyEvent; 27 import java.util.ArrayList; 28 import java.util.List; 27 29 28 30 import javax.swing.JMenu; … … 46 48 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.MovePointAction; 47 49 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.TransformPointAction; 50 import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract; 48 51 49 52 /** … … 52 55 public class PicLayerPlugin extends Plugin implements LayerChangeListener { 53 56 54 55 // Toolbar buttons 56 static IconToggleButton movePictureButton = null; 57 static IconToggleButton movePointButton = null; 58 static IconToggleButton transformPointButton = null; 59 static IconToggleButton rotatePictureButton = null; 60 static IconToggleButton scalexPictureButton = null; 61 static IconToggleButton scaleyPictureButton = null; 62 static IconToggleButton scalexyPictureButton = null; 63 static IconToggleButton shearPictureButton = null; 57 public static List<PicToggleButton> buttonList = null; 64 58 65 59 // Plugin menu … … 106 100 ShearPictureAction shearPictureAction = new ShearPictureAction(newFrame); 107 101 // Create plugin buttons and add them to the toolbar 108 movePictureButton = new IconToggleButton(movePictureAction); 109 movePointButton = new IconToggleButton(movePointAction); 110 transformPointButton = new IconToggleButton(transformPointAction); 111 rotatePictureButton = new IconToggleButton(rotatePictureAction); 112 scalexyPictureButton = new IconToggleButton(scaleXYPictureAction); 113 scalexPictureButton = new IconToggleButton(scaleXPictureAction); 114 scaleyPictureButton = new IconToggleButton(scaleYPictureAction); 115 shearPictureButton = new IconToggleButton(shearPictureAction); 116 newFrame.addMapMode(movePictureButton); 117 newFrame.addMapMode(movePointButton); 118 newFrame.addMapMode(transformPointButton); 119 newFrame.addMapMode(rotatePictureButton); 120 newFrame.addMapMode(scalexyPictureButton); 121 newFrame.addMapMode(scalexPictureButton); 122 newFrame.addMapMode(scaleyPictureButton); 123 newFrame.addMapMode(shearPictureButton); 124 // newFrame.toolGroup.add(m_movePictureButton); 125 // newFrame.toolGroup.add(m_rotatePictureButton); 126 // newFrame.toolGroup.add(m_scalePictureButton); 127 // Show them by default 102 103 buttonList = new ArrayList<PicToggleButton>(7); 104 buttonList.add(new PicToggleButton(movePictureAction, "Move Picture", "piclayer.actionvisibility.move", true)); 105 buttonList.add(new PicToggleButton(movePointAction, "Move Point", "piclayer.actionvisibility.movepoint", true)); 106 buttonList.add(new PicToggleButton(transformPointAction, "Transform Point", "piclayer.actionvisibility.transformpoint", true)); 107 buttonList.add(new PicToggleButton(rotatePictureAction, "Rotate", "piclayer.actionvisibility.rotate", false)); 108 buttonList.add(new PicToggleButton(scaleXYPictureAction, "Scale", "piclayer.actionvisibility.scale", false)); 109 buttonList.add(new PicToggleButton(scaleXPictureAction, "Scale X", "piclayer.actionvisibility.scalex", false)); 110 buttonList.add(new PicToggleButton(scaleYPictureAction, "Scale Y", "piclayer.actionvisibility.scaley", false)); 111 buttonList.add(new PicToggleButton(shearPictureAction, "Shear", "piclayer.actionvisibility.shear", false)); 112 113 for(IconToggleButton btn : buttonList) { 114 newFrame.addMapMode(btn); 115 } 128 116 129 117 if (actionVisibility == null) … … 132 120 } 133 121 134 135 * The toolbar buttons shall be active only when the PicLayer is active.122 /** 123 * The toolbar buttons shall be active and visible only when the PicLayer is active. 136 124 */ 137 125 @Override 138 126 public void activeLayerChange(Layer oldLayer, Layer newLayer) { 127 boolean oldPic = oldLayer instanceof PicLayerAbstract; 128 boolean newPic = newLayer instanceof PicLayerAbstract; 129 // actually that should be not enough - JOSM should hide all buttons that are disabled for current layer! 130 if (oldPic && !newPic || oldLayer == null && !newPic) { // leave picture layer - hide all controls 131 for (PicToggleButton btn : buttonList) 132 btn.setVisible(false); 133 } 134 if (!oldPic && newPic) { // enter picture layer - reset visibility of controls 135 for (PicToggleButton btn : buttonList) 136 btn.readVisible(); 137 } 139 138 } 140 139
Note:
See TracChangeset
for help on using the changeset viewer.