001// License: GPL. For details, see LICENSE file.
002package org.openstreetmap.josm.plugins.streetside.gui;
003
004import java.awt.BorderLayout;
005import java.awt.Component;
006import java.util.List;
007
008import org.openstreetmap.josm.gui.SideButton;
009import org.openstreetmap.josm.gui.dialogs.ToggleDialog;
010import org.openstreetmap.josm.plugins.streetside.gui.imageinfo.StreetsideViewerPanel;
011
012/**
013 * Toggle dialog that shows an image and some buttons.
014 *
015 * @author nokutu
016 */
017
018public final class StreetsideViewerDialog extends ToggleDialog
019                 {
020
021        private static final long serialVersionUID = -8983900297628236197L;
022
023        private static final String BASE_TITLE = "360° Streetside Viewer";
024
025        private static StreetsideViewerDialog instance;
026
027        /**
028         * Object containing the shown image and that handles zoom and drag
029         */
030        private StreetsideViewerPanel streetsideViewerPanel;
031
032        private StreetsideViewerDialog() {
033          super(StreetsideViewerDialog.BASE_TITLE, "streetside-viewer", "Open Streetside Viewer window",
034                                null, 200, true, StreetsidePreferenceSetting.class);
035                streetsideViewerPanel = new StreetsideViewerPanel();
036                createLayout(streetsideViewerPanel, true, null);
037        }
038
039        /**
040         * Returns the unique instance of the class.
041         *
042         * @return The unique instance of the class.
043         */
044        public static synchronized StreetsideViewerDialog getInstance() {
045                if (StreetsideViewerDialog.instance == null) {
046                        StreetsideViewerDialog.instance = new StreetsideViewerDialog();
047                }
048                return StreetsideViewerDialog.instance;
049        }
050
051        /**
052         * @return true, iff the singleton instance is present
053         */
054        public static boolean hasInstance() {
055                return StreetsideViewerDialog.instance != null;
056        }
057
058        /**
059         * Destroys the unique instance of the class.
060         */
061        public static synchronized void destroyInstance() {
062                StreetsideViewerDialog.instance = null;
063        }
064
065        /**
066         * Creates the layout of the dialog.
067         *
068         * @param data
069         *            The content of the dialog
070         * @param buttons
071         *            The buttons where you can click
072         */
073        public void createLayout(Component data, List<SideButton> buttons) {
074                removeAll();
075                createLayout(data, true, buttons);
076                add(titleBar, BorderLayout.NORTH);
077        }
078
079        public StreetsideViewerPanel getStreetsideViewerPanel() {
080                return streetsideViewerPanel;
081        }
082}