📄 combobar.java
字号:
package view;//Copyright (C) 2008 Harald Unander, Wang Wenjuan//// This file is part of WlanTV.//// WlanTV is free software: you can redistribute it and/or modify// it under the terms of the GNU General Public License as published by// the Free Software Foundation, either version 3 of the License, or// (at your option) any later version.//// WlanTV 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// along with WlanTV. If not, see <http://www.gnu.org/licenses/>.import java.awt.event.ItemListener;import java.util.ArrayList;import javax.swing.JComboBox;import javax.swing.JPanel;import main.Main;import model.Packet;import model.Packet.CH_MODES;@SuppressWarnings("serial")public class ComboBar extends JPanel { View parent; private StaDropDown staDropDown; private ApDropDown apDropDown; private ModeDropDown modeDropDown; private RssiDropDown rssiDropDown; private DirDropDown dirDropDown; private ChannelDropDown channelDropDown; private FillPayloadLenDropDown fillPayloadLenDropDown; private FillAccessTimeDropDown fillAccessTimeDropDown; ArrayList<String> staList; ArrayList<String> apList; private ItemListener dropDownHandler; public ComboBar(View parent, ItemListener dropDownHandler) { this.parent = parent; this.dropDownHandler = dropDownHandler; add(modeDropDown = new ModeDropDown(dropDownHandler)); add(rssiDropDown = new RssiDropDown(dropDownHandler)); add(channelDropDown = new ChannelDropDown(dropDownHandler)); add(dirDropDown = new DirDropDown(dropDownHandler)); add(fillPayloadLenDropDown = new FillPayloadLenDropDown(dropDownHandler)); add(fillAccessTimeDropDown = new FillAccessTimeDropDown(dropDownHandler)); update(null, null); } static public enum DIRECTION { normal("Both"), uplink("Uplink"), downlink("Downlink"); private final String s; DIRECTION(String s) { this.s = s; } public String toString() { return s; } } public void update(ArrayList<String> apList, ArrayList<String> staList) { this.apList = apList; this.staList = staList; if (staDropDown != null) remove(staDropDown); add(staDropDown = new StaDropDown(dropDownHandler)); if (apDropDown != null) remove(apDropDown); add(apDropDown = new ApDropDown(dropDownHandler)); } class ModeDropDown extends JComboBox { public ModeDropDown(ItemListener handler) { super(CH_MODES.values()); setSelectedItem(Main.properties.getProperty("channel.type", "auto")); setToolTipText("Override channel type"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } class StaDropDown extends JComboBox { public StaDropDown(ItemListener handler) { super(getStaList()); setToolTipText("STA Filter"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } class ApDropDown extends JComboBox { public ApDropDown(ItemListener handler) { super(getApList()); setToolTipText("AP Filter"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } class RssiDropDown extends JComboBox { public RssiDropDown(ItemListener handler) { super(getRssiList()); setToolTipText("RSSI filter"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } class DirDropDown extends JComboBox { public DirDropDown(ItemListener handler) { super(DIRECTION.values()); setToolTipText("Show data unicast both directions or selected direction only"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } class ChannelDropDown extends JComboBox { public ChannelDropDown(ItemListener handler) { super(getChannelList()); setToolTipText("Channel filter"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } class FillPayloadLenDropDown extends JComboBox { public FillPayloadLenDropDown(ItemListener handler) { super(getFillPayloadLenList()); setToolTipText("Payload length of reconstructed packets (also length of packets added to fill up channel)"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } class FillAccessTimeDropDown extends JComboBox { public FillAccessTimeDropDown(ItemListener handler) { super(getFillAccessTimeList()); setToolTipText("Override access time for free bandwidth calculations"); addItemListener(handler); setActionCommand(this.getClass().getSimpleName()); } } private String[] getStaList() { ArrayList<String> list = new ArrayList<String>(); list.add("STA"); if (staList != null) list.addAll(staList); return list.toArray(new String[list.size()]); } private String[] getApList() { ArrayList<String> list = new ArrayList<String>(); list.add("AP"); if (apList != null) list.addAll(apList); return list.toArray(new String[list.size()]); } private static String[] getRssiList() { ArrayList<String> list = new ArrayList<String>(); list.add("RSSI"); for (int i = 100; i > -100; i -= 10) list.add(Integer.toString(i)); return list.toArray(new String[list.size()]); } private static String[] getChannelList() { ArrayList<String> list = new ArrayList<String>(); list.add("Ch"); for (int i = 1; i <= 13; i++) list.add(Integer.toString(i)); return list.toArray(new String[list.size()]); } private static String[] getFillPayloadLenList() { String[] s = { "AutoFillLen", "100", "200", "500", "1000", "1470" }; return s; } private String[] getFillAccessTimeList() { ArrayList<String> list = new ArrayList<String>(); list.add("AutoAccessTime"); for (int i = 10; i < 400; i += 10) list.add(Integer.toString(i)); return list.toArray(new String[list.size()]); } public int getRssiFilterValue() { String s = rssiDropDown.getSelectedItem().toString(); if (!s.equals("RSSI")) return Integer.parseInt(s); else return 0; } public CH_MODES getModeValue() { return (CH_MODES) modeDropDown.getSelectedItem(); } public int getChannelFilterValue() { String s = channelDropDown.getSelectedItem().toString(); if (!s.equals("Ch")) return Integer.parseInt(s); else return 0; } public long getStaFilterValue() { String s = staDropDown.getSelectedItem().toString(); if (!s.equals("STA")) return Packet.macToLong(s.split(" ")[0]); else return 0; } public long getApFilterValue() { String s = apDropDown.getSelectedItem().toString(); if (!s.equals("AP")) return Packet.macToLong(s); else return 0; } public int getFillPayloadLenValue() { String s = fillPayloadLenDropDown.getSelectedItem().toString(); if (s.equals("AutoFillLen")) return parent.getDefaultFillPayloadLength(); else return Integer.parseInt(s); } public int getFillAccessTimeValue() { String s = fillAccessTimeDropDown.getSelectedItem().toString(); if (s.equals("AutoAccessTime")) return 0; else return Integer.parseInt(s); } public DIRECTION getDirValue() { return (DIRECTION) dirDropDown.getSelectedItem(); } public void setAdvancedMenu(boolean on) { fillPayloadLenDropDown.setVisible(on); fillAccessTimeDropDown.setVisible(on); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -