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)));
}
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)));
}
Aggregations