Changeset 27122 in osm for applications/editors/josm


Ignore:
Timestamp:
2011-11-22T17:06:36+01:00 (13 years ago)
Author:
larry0ua
Message:

'PicLayer - toolbar buttons are hidden when layer is not active'

Location:
applications/editors/josm/plugins/piclayer
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/piclayer/build.xml

    r27120 r27122  
    2222-->
    2323<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"/>
    2525    <property name="plugin.main.version" value="4549"/>
    2626    <!--
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/ActionVisibilityChangeMenu.java

    r27120 r27122  
    1010
    1111import org.openstreetmap.josm.Main;
    12 import org.openstreetmap.josm.gui.IconToggleButton;
    1312
    1413enum PicActions {MOVE_PICTURE, MOVE_POINT, TRANSFORM_POINT, SCALEX, SCALEY, SCALEXY, SHEAR, ROTATE}
     
    1615@SuppressWarnings("serial")
    1716public class ActionVisibilityChangeMenu extends JMenu {
    18         public ActionVisibilityChangeMenu() {
    19                 super(tr("Change visibility of controls"));
     17    public ActionVisibilityChangeMenu() {
     18        super(tr("Change visibility of controls"));
    2019
    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    }
    3024}
    3125
    3226@SuppressWarnings("serial")
    3327class 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    }
    4942}
  • applications/editors/josm/plugins/piclayer/src/org/openstreetmap/josm/plugins/piclayer/PicLayerPlugin.java

    r27120 r27122  
    2525
    2626import java.awt.event.KeyEvent;
     27import java.util.ArrayList;
     28import java.util.List;
    2729
    2830import javax.swing.JMenu;
     
    4648import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.MovePointAction;
    4749import org.openstreetmap.josm.plugins.piclayer.actions.transform.affine.TransformPointAction;
     50import org.openstreetmap.josm.plugins.piclayer.layer.PicLayerAbstract;
    4851
    4952/**
     
    5255public class PicLayerPlugin extends Plugin implements LayerChangeListener {
    5356
    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;
    6458
    6559    // Plugin menu
     
    106100            ShearPictureAction shearPictureAction = new ShearPictureAction(newFrame);
    107101            // 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            }
    128116
    129117            if (actionVisibility == null)
     
    132120    }
    133121
    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.
    136124     */
    137125    @Override
    138126    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        }
    139138    }
    140139
Note: See TracChangeset for help on using the changeset viewer.