Search in sources :

Example 1 with ToggleButtonModel

use of javax.swing.JToggleButton.ToggleButtonModel in project josm by openstreetmap.

the class MapPaintDialog method build.

protected void build() {
    model = new StylesModel();
    cbWireframe = new JCheckBox();
    JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL);
    wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN));
    wfLabel.setLabelFor(cbWireframe);
    cbWireframe.setModel(new ToggleButtonModel() {

        @Override
        public void setSelected(boolean b) {
            super.setSelected(b);
            tblStyles.setEnabled(!b);
            onoffAction.updateEnabledState();
            upAction.updateEnabledState();
            downAction.updateEnabledState();
        }
    });
    cbWireframe.addActionListener(e -> MainApplication.getMenu().wireFrameToggleAction.actionPerformed(null));
    cbWireframe.setBorder(new EmptyBorder(new Insets(1, 1, 1, 1)));
    tblStyles = new ScrollableTable(model);
    tblStyles.setSelectionModel(selectionModel);
    tblStyles.addMouseListener(new PopupMenuHandler());
    tblStyles.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    tblStyles.setBackground(UIManager.getColor("Panel.background"));
    tblStyles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    tblStyles.setTableHeader(null);
    tblStyles.getColumnModel().getColumn(0).setMaxWidth(1);
    tblStyles.getColumnModel().getColumn(0).setResizable(false);
    tblStyles.getColumnModel().getColumn(0).setCellRenderer(new MyCheckBoxRenderer());
    tblStyles.getColumnModel().getColumn(1).setCellRenderer(new StyleSourceRenderer());
    tblStyles.setShowGrid(false);
    tblStyles.setIntercellSpacing(new Dimension(0, 0));
    JPanel p = new JPanel(new GridBagLayout());
    p.add(cbWireframe, GBC.std(0, 0));
    p.add(wfLabel, GBC.std(1, 0).weight(1, 0));
    p.add(tblStyles, GBC.std(0, 1).span(2).fill());
    reloadAction = new ReloadAction();
    onoffAction = new OnOffAction();
    upAction = new MoveUpDownAction(false);
    downAction = new MoveUpDownAction(true);
    selectionModel.addListSelectionListener(onoffAction);
    selectionModel.addListSelectionListener(reloadAction);
    selectionModel.addListSelectionListener(upAction);
    selectionModel.addListSelectionListener(downAction);
    // Toggle style on Enter and Spacebar
    InputMapUtils.addEnterAction(tblStyles, onoffAction);
    InputMapUtils.addSpacebarAction(tblStyles, onoffAction);
    createLayout(p, true, Arrays.asList(new SideButton(onoffAction, false), new SideButton(upAction, false), new SideButton(downAction, false), new SideButton(PREFERENCE_ACTION, false)));
}
Also used : JPanel(javax.swing.JPanel) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) ToggleButtonModel(javax.swing.JToggleButton.ToggleButtonModel) Dimension(java.awt.Dimension) ScrollableTable(org.openstreetmap.josm.gui.widgets.ScrollableTable) JCheckBox(javax.swing.JCheckBox) SideButton(org.openstreetmap.josm.gui.SideButton) EmptyBorder(javax.swing.border.EmptyBorder)

Example 2 with ToggleButtonModel

use of javax.swing.JToggleButton.ToggleButtonModel in project josm by JOSM.

the class MapPaintDialog method build.

protected void build() {
    model = new StylesModel();
    cbWireframe = new JCheckBox();
    JLabel wfLabel = new JLabel(tr("Wireframe View"), ImageProvider.get("dialogs/mappaint", "wireframe_small"), JLabel.HORIZONTAL);
    wfLabel.setFont(wfLabel.getFont().deriveFont(Font.PLAIN));
    wfLabel.setLabelFor(cbWireframe);
    cbWireframe.setModel(new ToggleButtonModel() {

        @Override
        public void setSelected(boolean b) {
            super.setSelected(b);
            tblStyles.setEnabled(!b);
            onoffAction.updateEnabledState();
            upAction.updateEnabledState();
            downAction.updateEnabledState();
        }
    });
    cbWireframe.addActionListener(e -> MainApplication.getMenu().wireFrameToggleAction.actionPerformed(null));
    cbWireframe.setBorder(new EmptyBorder(new Insets(1, 1, 1, 1)));
    tblStyles = new ScrollableTable(model);
    tblStyles.setSelectionModel(selectionModel);
    tblStyles.addMouseListener(new PopupMenuHandler());
    tblStyles.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    tblStyles.setBackground(UIManager.getColor("Panel.background"));
    tblStyles.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    tblStyles.setTableHeader(null);
    tblStyles.getColumnModel().getColumn(0).setMaxWidth(1);
    tblStyles.getColumnModel().getColumn(0).setResizable(false);
    tblStyles.getColumnModel().getColumn(0).setCellRenderer(new MyCheckBoxRenderer());
    tblStyles.getColumnModel().getColumn(1).setCellRenderer(new StyleSourceRenderer());
    tblStyles.setShowGrid(false);
    tblStyles.setIntercellSpacing(new Dimension(0, 0));
    JPanel p = new JPanel(new GridBagLayout());
    p.add(cbWireframe, GBC.std(0, 0));
    p.add(wfLabel, GBC.std(1, 0).weight(1, 0));
    p.add(tblStyles, GBC.std(0, 1).span(2).fill());
    reloadAction = new ReloadAction();
    onoffAction = new OnOffAction();
    upAction = new MoveUpDownAction(false);
    downAction = new MoveUpDownAction(true);
    selectionModel.addListSelectionListener(onoffAction);
    selectionModel.addListSelectionListener(reloadAction);
    selectionModel.addListSelectionListener(upAction);
    selectionModel.addListSelectionListener(downAction);
    // Toggle style on Enter and Spacebar
    InputMapUtils.addEnterAction(tblStyles, onoffAction);
    InputMapUtils.addSpacebarAction(tblStyles, onoffAction);
    createLayout(p, true, Arrays.asList(new SideButton(onoffAction, false), new SideButton(upAction, false), new SideButton(downAction, false), new SideButton(PREFERENCE_ACTION, false)));
}
Also used : JPanel(javax.swing.JPanel) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) ToggleButtonModel(javax.swing.JToggleButton.ToggleButtonModel) Dimension(java.awt.Dimension) ScrollableTable(org.openstreetmap.josm.gui.widgets.ScrollableTable) JCheckBox(javax.swing.JCheckBox) SideButton(org.openstreetmap.josm.gui.SideButton) EmptyBorder(javax.swing.border.EmptyBorder)

Aggregations

Dimension (java.awt.Dimension)2 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 JCheckBox (javax.swing.JCheckBox)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 ToggleButtonModel (javax.swing.JToggleButton.ToggleButtonModel)2 EmptyBorder (javax.swing.border.EmptyBorder)2 SideButton (org.openstreetmap.josm.gui.SideButton)2 ScrollableTable (org.openstreetmap.josm.gui.widgets.ScrollableTable)2