Index: /applications/editors/josm/plugins/piclayer/build.xml
===================================================================
--- /applications/editors/josm/plugins/piclayer/build.xml	(revision 27121)
+++ /applications/editors/josm/plugins/piclayer/build.xml	(revision 27122)
@@ -22,5 +22,5 @@
 -->
 <project name="PicLayer" default="dist" basedir=".">
-    <property name="commit.message" value="PicLayer rewritten - lots changed"/>
+    <property name="commit.message" value="PicLayer - toolbar buttons are hidden when layer is not active"/>
     <property name="plugin.main.version" value="4549"/>
     <!--
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ActionVisibilityChangeMenu.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ActionVisibilityChangeMenu.java	(revision 27121)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ActionVisibilityChangeMenu.java	(revision 27122)
@@ -10,5 +10,4 @@
 
 import org.openstreetmap.josm.Main;
-import org.openstreetmap.josm.gui.IconToggleButton;
 
 enum PicActions {MOVE_PICTURE, MOVE_POINT, TRANSFORM_POINT, SCALEX, SCALEY, SCALEXY, SHEAR, ROTATE}
@@ -16,34 +15,28 @@
 @SuppressWarnings("serial")
 public class ActionVisibilityChangeMenu extends JMenu {
-	public ActionVisibilityChangeMenu() {
-		super(tr("Change visibility of controls"));
+    public ActionVisibilityChangeMenu() {
+        super(tr("Change visibility of controls"));
 
-		add(new SwitchVisibilityMenuItem("Move Picture", "piclayer.actionvisibility.move", PicLayerPlugin.movePictureButton, true));
-		add(new SwitchVisibilityMenuItem("Move Point", "piclayer.actionvisibility.movepoint", PicLayerPlugin.movePointButton, true));
-		add(new SwitchVisibilityMenuItem("Transform Point", "piclayer.actionvisibility.transformpoint", PicLayerPlugin.transformPointButton, true));
-		add(new SwitchVisibilityMenuItem("Rotate", "piclayer.actionvisibility.rotate", PicLayerPlugin.rotatePictureButton, false));
-		add(new SwitchVisibilityMenuItem("Scale X", "piclayer.actionvisibility.scalex", PicLayerPlugin.scalexPictureButton, false));
-		add(new SwitchVisibilityMenuItem("Scale Y", "piclayer.actionvisibility.scaley", PicLayerPlugin.scaleyPictureButton, false));
-		add(new SwitchVisibilityMenuItem("Scale", "piclayer.actionvisibility.scale", PicLayerPlugin.scalexyPictureButton, false));
-		add(new SwitchVisibilityMenuItem("Shear", "piclayer.actionvisibility.shear", PicLayerPlugin.shearPictureButton, false));
-	}
+        for (int i = 0;i < PicLayerPlugin.buttonList.size(); i++) {
+            add(new SwitchVisibilityMenuItem(PicLayerPlugin.buttonList.get(i)));
+        }
+    }
 }
 
 @SuppressWarnings("serial")
 class SwitchVisibilityMenuItem extends JCheckBoxMenuItem {
-	public SwitchVisibilityMenuItem(String name, final String key, final IconToggleButton button, final boolean def) {
-		super();
-		setSelected(Main.pref.getBoolean(key, def));
-		button.setVisible(isSelected());
-		setAction(new AbstractAction() {
-			@Override
-			public void actionPerformed(ActionEvent e) {
-				boolean val = !Main.pref.getBoolean(key, def);
-				Main.pref.put(key, val);
-				SwitchVisibilityMenuItem.this.setSelected(val);
-				button.setVisible(val);
-			}
-		});
-		setText(name);
-	}
+    public SwitchVisibilityMenuItem(final PicToggleButton button) {
+        super();
+        setSelected(Main.pref.getBoolean(button.getVisibilityKey(), button.getDefVisibility()));
+        setAction(new AbstractAction() {
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                boolean val = !Main.pref.getBoolean(button.getVisibilityKey(), button.getDefVisibility());
+                Main.pref.put(button.getVisibilityKey(), val);
+                SwitchVisibilityMenuItem.this.setSelected(val);
+                button.setVisible(val);
+            }
+        });
+        setText(tr(button.getBtnName()));
+    }
 }
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java	(revision 27121)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java	(revision 27122)
@@ -25,4 +25,6 @@
 
 import java.awt.event.KeyEvent;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.JMenu;
@@ -46,4 +48,5 @@
 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.MovePointAction;
 import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.TransformPointAction;
+import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract;
 
 /**
@@ -52,14 +55,5 @@
 public class PicLayerPlugin extends Plugin implements LayerChangeListener {
 
-
-    // Toolbar buttons
-    static IconToggleButton movePictureButton = null;
-    static IconToggleButton movePointButton = null;
-    static IconToggleButton transformPointButton = null;
-    static IconToggleButton rotatePictureButton = null;
-    static IconToggleButton scalexPictureButton = null;
-    static IconToggleButton scaleyPictureButton = null;
-    static IconToggleButton scalexyPictureButton = null;
-    static IconToggleButton shearPictureButton = null;
+    public static List<PicToggleButton> buttonList = null;
 
     // Plugin menu
@@ -106,24 +100,18 @@
             ShearPictureAction shearPictureAction = new ShearPictureAction(newFrame);
             // Create plugin buttons and add them to the toolbar
-            movePictureButton = new IconToggleButton(movePictureAction);
-            movePointButton = new IconToggleButton(movePointAction);
-            transformPointButton = new IconToggleButton(transformPointAction);
-            rotatePictureButton = new IconToggleButton(rotatePictureAction);
-            scalexyPictureButton = new IconToggleButton(scaleXYPictureAction);
-            scalexPictureButton = new IconToggleButton(scaleXPictureAction);
-            scaleyPictureButton = new IconToggleButton(scaleYPictureAction);
-            shearPictureButton = new IconToggleButton(shearPictureAction);
-            newFrame.addMapMode(movePictureButton);
-            newFrame.addMapMode(movePointButton);
-            newFrame.addMapMode(transformPointButton);
-            newFrame.addMapMode(rotatePictureButton);
-            newFrame.addMapMode(scalexyPictureButton);
-            newFrame.addMapMode(scalexPictureButton);
-            newFrame.addMapMode(scaleyPictureButton);
-            newFrame.addMapMode(shearPictureButton);
-//            newFrame.toolGroup.add(m_movePictureButton);
-//            newFrame.toolGroup.add(m_rotatePictureButton);
-//            newFrame.toolGroup.add(m_scalePictureButton);
-            // Show them by default
+
+            buttonList = new ArrayList<PicToggleButton>(7);
+            buttonList.add(new PicToggleButton(movePictureAction, "Move Picture", "piclayer.actionvisibility.move", true));
+            buttonList.add(new PicToggleButton(movePointAction, "Move Point", "piclayer.actionvisibility.movepoint", true));
+            buttonList.add(new PicToggleButton(transformPointAction, "Transform Point", "piclayer.actionvisibility.transformpoint", true));
+            buttonList.add(new PicToggleButton(rotatePictureAction, "Rotate", "piclayer.actionvisibility.rotate", false));
+            buttonList.add(new PicToggleButton(scaleXYPictureAction, "Scale", "piclayer.actionvisibility.scale", false));
+            buttonList.add(new PicToggleButton(scaleXPictureAction, "Scale X", "piclayer.actionvisibility.scalex", false));
+            buttonList.add(new PicToggleButton(scaleYPictureAction, "Scale Y", "piclayer.actionvisibility.scaley", false));
+            buttonList.add(new PicToggleButton(shearPictureAction, "Shear", "piclayer.actionvisibility.shear", false));
+
+            for(IconToggleButton btn : buttonList) {
+                newFrame.addMapMode(btn);
+            }
 
             if (actionVisibility == null)
@@ -132,9 +120,20 @@
     }
 
-	/**
-     * The toolbar buttons shall be active only when the PicLayer is active.
+    /**
+     * The toolbar buttons shall be active and visible only when the PicLayer is active.
      */
     @Override
     public void activeLayerChange(Layer oldLayer, Layer newLayer) {
+        boolean oldPic = oldLayer instanceof PicLayerAbstract;
+        boolean newPic = newLayer instanceof PicLayerAbstract;
+        // actually that should be not enough - JOSM should hide all buttons that are disabled for current layer!
+        if (oldPic && !newPic || oldLayer == null && !newPic) { // leave picture layer - hide all controls
+            for (PicToggleButton btn : buttonList)
+                btn.setVisible(false);
+        }
+        if (!oldPic && newPic) { // enter picture layer - reset visibility of controls
+            for (PicToggleButton btn : buttonList)
+                btn.readVisible();
+        }
     }
 
Index: /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicToggleButton.java
===================================================================
--- /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicToggleButton.java	(revision 27122)
+++ /applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicToggleButton.java	(revision 27122)
@@ -0,0 +1,37 @@
+package org.openstreetmap.josm.plugins.piclayer;
+
+import javax.swing.Action;
+
+import org.openstreetmap.josm.Main;
+import org.openstreetmap.josm.gui.IconToggleButton;
+
+@SuppressWarnings("serial")
+public class PicToggleButton extends IconToggleButton {
+
+
+    public PicToggleButton(Action action, String btnName, String visibilityKey, boolean defVisibility) {
+        super(action);
+        this.btnName = btnName;
+        this.visibilityKey = visibilityKey;
+        this.defVisibility = defVisibility;
+    }
+
+    private final String visibilityKey;
+    protected final String btnName;
+    private boolean defVisibility;
+
+    public String getVisibilityKey() {
+        return visibilityKey;
+    }
+    public String getBtnName() {
+        return btnName;
+    }
+    public boolean getDefVisibility() {
+        return defVisibility;
+    }
+
+    public void readVisible() {
+        setVisible(Main.pref.getBoolean(getVisibilityKey(), getDefVisibility()));
+    }
+
+}
