001    /*
002     * This file is part of muCommander, http://www.mucommander.com
003     * Copyright (C) 2002-2008 Maxence Bernard
004     *
005     * muCommander is free software; you can redistribute it and/or modify
006     * it under the terms of the GNU General Public License as published by
007     * the Free Software Foundation; either version 3 of the License, or
008     * (at your option) any later version.
009     *
010     * muCommander is distributed in the hope that it will be useful,
011     * but WITHOUT ANY WARRANTY; without even the implied warranty of
012     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
013     * GNU General Public License for more details.
014     *
015     * You should have received a copy of the GNU General Public License
016     * along with this program.  If not, see <http://www.gnu.org/licenses/>.
017     */
018    
019    package com.mucommander.ui.button;
020    
021    import com.mucommander.ui.icon.IconManager;
022    
023    import javax.swing.*;
024    
025    /**
026     * ArrowButton is a button displaying an arrow icon pointing to a specified direction (up/down/left/right).
027     * The direction of the arrow can be changed at any time using {@link #setArrowDirection(int)}.
028     *
029     * @author Maxence Bernard
030     */
031    public class ArrowButton extends JButton {
032    
033        public final static int UP_DIRECTION = 0;
034        public final static int DOWN_DIRECTION = 1;
035        public final static int LEFT_DIRECTION = 2;
036        public final static int RIGHT_DIRECTION = 3;
037    
038        private final static String ICONS[] = {
039            "arrow_up.png",
040            "arrow_down.png",
041            "arrow_left.png",
042            "arrow_right.png"
043        };
044    
045    
046        /**
047         * Creates a new ArrowButton with no initial arrow icon.
048         */
049        public ArrowButton() {
050        }
051    
052        /**
053         * Creates a new ArrowButton showing an arrow icon pointing to the specified direction.
054         */
055        public ArrowButton(int direction) {
056            setArrowDirection(direction);
057        }
058    
059        /**
060         * Creates a new ArrowButton using the specified Action and showing an arrow icon pointing to the specified direction.
061         */
062        public ArrowButton(Action action, int direction) {
063            super(action);
064    
065            setArrowDirection(direction);
066        }
067    
068    
069        /**
070         * Changes the direction of the arrow icon to the specified one.
071         *
072         * @param direction can have one of the following values: {@link #UP_DIRECTION}, {@link #DOWN_DIRECTION},
073         * {@link #LEFT_DIRECTION} or {@link #RIGHT_DIRECTION}
074         */
075        public void setArrowDirection(int direction) {
076            setIcon(IconManager.getIcon(IconManager.COMMON_ICON_SET, ICONS[direction]));
077        }
078    }