77 lines
2.9 KiB
Plaintext
77 lines
2.9 KiB
Plaintext
package org.ka2ddo.yaac.gui.io;
|
|
|
|
/*
|
|
* Copyright (C) 2011-2019 Andrew Pavlin, KA2DDO
|
|
* This file is part of YAAC (Yet Another APRS Client).
|
|
*
|
|
* YAAC is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* YAAC is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* and GNU Lesser General Public License along with YAAC. If not,
|
|
* see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
import org.ka2ddo.yaac.io.PortConfig;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.ItemEvent;
|
|
import java.awt.event.ItemListener;
|
|
import java.util.ResourceBundle;
|
|
|
|
/**
|
|
* This class implements the code needed to create with port configuration widgets to select
|
|
* AX.25 protocols should be permitted on a port.
|
|
* @author Andrew Pavlin, KA2DDO
|
|
*/
|
|
public class ProtocolSelectionControls implements ItemListener {
|
|
/**
|
|
* Create a generic set of controls for enabling or disabling the protocols to be supported
|
|
* over the asscoiated AX.25 port interface.
|
|
* @param msgBundle ResourceBundle for obtaining localized label translations
|
|
* @param cfg PortConfig.Cfg object to store protocol selection bits
|
|
* @return JPanel loaded with controls
|
|
*/
|
|
public static JPanel createWidgets(ResourceBundle msgBundle, PortConfig.Cfg cfg) {
|
|
JPanel p = new JPanel(new FlowLayout(FlowLayout.LEADING));
|
|
p.add(new JLabel(msgBundle.getString("configure.tab.Ports.Protocols")));
|
|
for (int bit = 0; bit <= PortConfig.MAX_PROTOCOL_BIT; bit++) {
|
|
JCheckBox cb;
|
|
int bitNum = 1 << bit;
|
|
if (msgBundle.containsKey("configure.tab.Ports.Protocols." + bit)) {
|
|
p.add(cb = new JCheckBox(msgBundle.getString("configure.tab.Ports.Protocols." + bit), (cfg.acceptableProtocolsMask & bitNum) != 0));
|
|
cb.addItemListener(new ProtocolSelectionControls(cfg, bitNum));
|
|
}
|
|
}
|
|
return p;
|
|
}
|
|
|
|
private final PortConfig.Cfg cfg;
|
|
private final int bitMask;
|
|
|
|
private ProtocolSelectionControls(PortConfig.Cfg cfg, int bitMask) {
|
|
this.cfg = cfg;
|
|
this.bitMask = bitMask;
|
|
}
|
|
|
|
/**
|
|
* DO NOT CALL. Handle state changes of an associated JCheckBox for the protocol selection controls.
|
|
* @param e ItemEvent identifying the checkbox
|
|
*/
|
|
public void itemStateChanged(ItemEvent e) {
|
|
if (e.getStateChange() == ItemEvent.SELECTED) {
|
|
cfg.acceptableProtocolsMask |= bitMask;
|
|
} else {
|
|
cfg.acceptableProtocolsMask &= ~bitMask;
|
|
}
|
|
}
|
|
}
|