Example usage for javax.swing JToggleButton JToggleButton

List of usage examples for javax.swing JToggleButton JToggleButton

Introduction

In this page you can find the example usage for javax.swing JToggleButton JToggleButton.

Prototype

public JToggleButton(String text, Icon icon, boolean selected) 

Source Link

Document

Creates a toggle button with the specified text, image, and selection state.

Usage

From source file:es.emergya.ui.gis.CustomMapView.java

public CustomMapView() {
    super();/* w w  w  .  j  a  v a  2  s  . c o  m*/
    menu = new MainMenu();
    contentPane.add(panel, BorderLayout.CENTER);

    // iniciar los controles mostrar/ocultar capas
    layerControls = new LinkedList<JToggleButton>();

    JToggleButton botonMostrarOcultarBotones = new JToggleButton(getI18n().getString("map.layers.hideButtons"),
            LogicConstants.getIcon("capas_button_mostrar"), false);
    botonMostrarOcultarBotones.setSelected(true);
    botonMostrarOcultarBotones.setActionCommand("#hide");
    // b.setVerticalTextPosition(SwingConstants.BOTTOM);
    // b.setHorizontalTextPosition(SwingConstants.CENTER);
    botonMostrarOcultarBotones.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JToggleButton b = (JToggleButton) e.getSource();
            if (e.getActionCommand().equals("#hide")) {
                layerControlPanel.removeAll();
                layerControlPanel.add(Box.createHorizontalStrut(10));
                layerControlPanel.add(b);
                b.setActionCommand("#show");
                b.setText(getI18n().getString("map.layers.showButtons"));
            } else {
                layerControlPanel.removeAll();
                layerControlPanel.add(Box.createHorizontalStrut(10));
                for (JToggleButton bt : layerControls) {
                    layerControlPanel.add(bt);
                    layerControlPanel.add(Box.createHorizontalGlue());
                }
                b.setActionCommand("#hide");
                b.setText(getI18n().getString("map.layers.hideButtons"));
            }
            layerControlPanel.updateUI();
        }
    });
    layerControls.add(botonMostrarOcultarBotones);

    final JToggleButton botonTodoasLasCapas = new JToggleButton(getI18n().getString("map.layers.allLayers"),
            LogicConstants.getIcon("capas_button_mostrar"), false);
    layerDialog = new LayerSelectionDialog(this);
    layerDialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            botonTodoasLasCapas.setSelected(false);
        }
    });
    botonTodoasLasCapas.setSelected(false);
    botonTodoasLasCapas.setActionCommand("#all");
    // all.setVerticalTextPosition(SwingConstants.BOTTOM);
    // all.setHorizontalTextPosition(SwingConstants.CENTER);
    botonTodoasLasCapas.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            layerDialog.setLocationRelativeTo((Component) e.getSource());
            layerDialog.setVisible(!layerDialog.isShowing());
        }
    });
    layerControls.add(botonTodoasLasCapas);

    layerControlPanel = new JPanel();
    layerControlPanel.setLayout(new BoxLayout(layerControlPanel, BoxLayout.X_AXIS));

    Main.main.menu = this.menu;
    toolbar = new ToolbarPreferences();
    toolbar.refreshToolbarControl();
    // toolbar.control.updateUI();
    // contentPane.add(toolbar.control, BorderLayout.NORTH);

    contentPane.updateUI();
    panel.updateUI();
}

From source file:es.emergya.ui.gis.CustomMapView.java

@Override
public void addLayer(Layer layer, boolean showOnButtonList, int pos) {
    if (layer instanceof MapViewerLayer) {
        minZoom = Math.max(((MapViewerLayer) layer).getMinZoomLevel(), getMinZoom());
        maxZoom = Math.min(((MapViewerLayer) layer).getMaxZoomLevel(), getMaxZoom());
        if (zoomFactor > maxZoom || zoomFactor < minZoom) {
            zoomFactor = (maxZoom + minZoom) / 2;
        }//from   w w  w.  java  2  s  .c  o m
        zoomTo(center, zoom2Scale(zoomFactor));
    }
    if (showOnButtonList) {
        JToggleButton b = new JToggleButton(layer.name,
                LogicConstants.getIcon("capas_button_" + layer.name.toLowerCase()), layer.visible);
        // b.setVerticalTextPosition(SwingConstants.BOTTOM);
        // b.setHorizontalTextPosition(SwingConstants.CENTER);
        b.setActionCommand(layer.name);
        b.addActionListener(layerControlListener);
        layerControls.add(b);
        layerControlPanel.removeAll();
        layerControlPanel.add(Box.createHorizontalStrut(10));
        for (JToggleButton bt : layerControls) {
            layerControlPanel.add(bt);
            layerControlPanel.add(Box.createHorizontalGlue());
        }
        layerControlPanel.updateUI();
    }

    super.addLayer(layer, pos);
}

From source file:es.emergya.ui.gis.CustomMapView.java

@Override
public void addLayer(Layer layer, boolean showOnButtonList, String icon) {
    if (layer instanceof MapViewerLayer) {
        minZoom = Math.max(((MapViewerLayer) layer).getMinZoomLevel(), getMinZoom());
        maxZoom = Math.min(((MapViewerLayer) layer).getMaxZoomLevel(), getMaxZoom());
        if (zoomFactor > maxZoom || zoomFactor < minZoom) {
            zoomFactor = (maxZoom + minZoom) / 2;
        }//from w w  w  .j a  va 2  s. c o m
        zoomTo(center, zoom2Scale(zoomFactor));
    }
    if (showOnButtonList) {
        JToggleButton b = new JToggleButton(layer.name, LogicConstants.getIcon(icon), layer.visible);
        // b.setVerticalTextPosition(SwingConstants.BOTTOM);
        // b.setHorizontalTextPosition(SwingConstants.CENTER);
        b.setActionCommand(layer.name);
        b.addActionListener(layerControlListener);
        layerControls.add(b);
        layerControlPanel.removeAll();
        layerControlPanel.add(Box.createHorizontalStrut(10));
        for (JToggleButton bt : layerControls) {
            layerControlPanel.add(bt);
            layerControlPanel.add(Box.createHorizontalGlue());
        }
        layerControlPanel.updateUI();
    }

    super.addLayer(layer);
}