⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glomomenubar.java

📁 无线网络仿真工具Glomosim2.03
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            setVisible(false);        }        else {            messageDialog.setMessage("", "Help: Invalid Action!");        }    }}class GlomoStatsDialog extends JDialog implements ActionListener {    private JButton showStatsButton, cancelButton;    private GlomoMessageDialog messageDialog;    private JCheckBox statsCheckBoxes[];    private JTextArea statsPad;    //private String directoryName = "../bin";    private String directoryName = "";    private File statsFile = new File("GLOMO.STAT");    private String titleBar = "GloMoSim Statistics File: ";    private BufferedReader brStats;     private JFrame parent;    public GlomoStatsDialog(JFrame f, GlomoMessageDialog gmDialog)    {        super(f, "View Stats...", true);        parent = f;        messageDialog = gmDialog;        setResizable(true);        getContentPane().setLayout(new BorderLayout());        statsPad = new JTextArea("", 40, 100);        statsPad.setFont(new Font("Monospaced", Font.PLAIN, 12));        JScrollPane  sp = new JScrollPane(statsPad);        JPanel buttonPanel = new JPanel(new GridLayout(1, 2));        showStatsButton = new JButton("Show Stats");        showStatsButton.addActionListener(this);        cancelButton = new JButton("Cancel");        cancelButton.addActionListener(this);        buttonPanel.add(showStatsButton);        buttonPanel.add(cancelButton);        getContentPane().add(sp, BorderLayout.CENTER);        getContentPane().add(buttonPanel, BorderLayout.SOUTH);        pack();        addWindowListener(new GlomoWindowHandler(GlomoWindowHandler.CLOSE));    }    public void formatStats() throws FileNotFoundException, IOException {        String line, word;        StringTokenizer strTokenizer;        Hashtable statsHtbl = new Hashtable(statsCheckBoxes.length);        for (int i=0; i < statsCheckBoxes.length; i++) {             if (statsCheckBoxes[i].isSelected() == true) {                statsHtbl.put(statsCheckBoxes[i].getText() + ",", "0");            }        }        statsPad.setText("");        brStats = new BufferedReader(new FileReader(statsFile));        while ((line = brStats.readLine()) != null) {            strTokenizer = new StringTokenizer (line);             // incorrect line format or blank line            if(strTokenizer.countTokens() < 5) {                continue;            }            // skip over the first three fields in the stats file            strTokenizer.nextToken();            strTokenizer.nextToken();            word = strTokenizer.nextToken();            // check for proper file format            if (word.equals("Layer:") != true) {                messageDialog.setMessage("", "Wrong format for Stats file!");                break;            }            word = strTokenizer.nextToken();            // check if we want to show this type of statistic            if (statsHtbl.containsKey(word) == true) {                statsPad.append(line + "\n");            }        }        statsPad.revalidate();    }    public void openFile() throws IOException, NumberFormatException    {        JFileChooser fc = new JFileChooser();        fc.setCurrentDirectory(new File(directoryName));        fc.setSelectedFile(statsFile);        int returnVal = fc.showOpenDialog(parent);        if (returnVal == JFileChooser.APPROVE_OPTION) {            statsFile = fc.getSelectedFile();            setTitle(titleBar + statsFile.getName());            directoryName = fc.getCurrentDirectory().getName();            brStats = new BufferedReader(new FileReader(statsFile));            String word, line;            int oldNodeNum = -1, newNodeNum = -1;            boolean firstLine = true;            Vector statsCheckBoxVec = new Vector();            while ((line = brStats.readLine()) != null) {                StringTokenizer strTokenizer = new StringTokenizer (line);                                 if(strTokenizer.countTokens() < 5) {                    continue;                }                strTokenizer.nextToken();                word = strTokenizer.nextToken();                if (word.endsWith(",")) {                    word = word.substring(0, word.length() - 1);                }                newNodeNum = Integer.parseInt(word);                if (firstLine == true) {                    firstLine = false;                    oldNodeNum = newNodeNum;                }                if (oldNodeNum != newNodeNum) {                    break;                }                oldNodeNum = newNodeNum;                word = strTokenizer.nextToken();                if (word.equals("Layer:") != true) {                    messageDialog.setMessage("","Wrong format for Stats file!");                    break;                }                word = strTokenizer.nextToken();                word = word.substring(0, word.length() - 1);                if (statsCheckBoxVec.contains(word) == false) {                    statsCheckBoxVec.addElement(word);                }            }            JPanel optionPanel = new JPanel(new GridLayout(0, 1));            statsCheckBoxes = new JCheckBox[statsCheckBoxVec.size()];            for (int i=0; i < statsCheckBoxes.length ; i++) {                 statsCheckBoxes[i] = new JCheckBox(                                    (String) statsCheckBoxVec.elementAt(i));                optionPanel.add(statsCheckBoxes[i]);             }            getContentPane().add(optionPanel, BorderLayout.WEST);            pack();            setVisible(true);        }    }    public void actionPerformed(ActionEvent e)    {        Object clicked = e.getSource();        if (clicked == showStatsButton) {            try {                formatStats();            } catch (FileNotFoundException fnfe) {                messageDialog.setMessage(                        "", "File not found!");            } catch (IOException ioe) {                messageDialog.setMessage(                        "", "IO Error occured while processing stats file!");            }        }        else if (clicked == cancelButton) {            setVisible(false);         }    }}class GlomoGuiOptionsDialog extends JDialog        implements ActionListener, ItemListener, AdjustmentListener {    private GlomoMessageDialog messageDialog;    private JCheckBox showTxRangeCb, showNodeConnectionsCb, showDemoColorsCb;    private Hashtable rgbHtbl;    private JComboBox displayType;    private JPanel demoCanvas;    private JScrollBar redSb, greenSb, blueSb;    private JLabel redLabel, greenLabel, blueLabel;    private JButton okButton;    private GridBagLayout gbLayout;    private GridBagConstraints gbConstraints;    public GlomoGuiOptionsDialog(JFrame parent, GlomoMessageDialog gmDialog) {        super(parent, "Options Dialog...", true);        messageDialog = gmDialog;        setResizable(true);        gbLayout = new GridBagLayout();        gbConstraints = new GridBagConstraints();        //gbConstraints.weightx = 1;        //gbConstraints.weighty = 1;        gbConstraints.gridwidth = 1;        gbConstraints.gridheight = 1;        gbConstraints.fill = GridBagConstraints.BOTH;        getContentPane().setLayout(gbLayout);        // boolean options        addComponent(new JLabel("Show Transmission Range:"), 4, 0);        showTxRangeCb = new JCheckBox("", false);        addComponent(showTxRangeCb, 4, 1);        addComponent(new JLabel("Show Node Connections:"), 5, 0);        showNodeConnectionsCb = new JCheckBox("", false);        addComponent(showNodeConnectionsCb, 5, 1);        addComponent(new JLabel("Use Demo Colors:"), 6, 0);        showDemoColorsCb = new JCheckBox("", false);        addComponent(showDemoColorsCb, 6, 1);        // Hash table for storing rgb values of the different display types        rgbHtbl = new Hashtable(5);        rgbHtbl.put("Node Color", new int[] {255, 0, 0});        rgbHtbl.put("Line Color", new int[] {0, 255, 0});        rgbHtbl.put("Link Color", new int[] {0, 0, 255});        rgbHtbl.put("Broadcast Color", new int[] {0, 255, 0});        rgbHtbl.put("Connection Color", new int[] {0, 0, 255});        // choice menu for the different display types        displayType = new JComboBox();        for (Enumeration e = rgbHtbl.keys(); e.hasMoreElements() == true;) {            displayType.addItem((String) e.nextElement());        }        displayType.addItemListener(this);        addComponent(displayType, 7, 0);        // canvas to display rgb color of selected display type        demoCanvas = new JPanel();        demoCanvas.setPreferredSize(new Dimension(10, 10));        String key = (String)displayType.getSelectedItem();        int[] rgb = (int[]) rgbHtbl.get(key);        demoCanvas.setBackground(new Color(rgb[0], rgb[1], rgb[2]));//        demoCanvas.repaint();        addComponent(demoCanvas, 7, 1);        redSb = new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 255);        redSb.addAdjustmentListener(this);        redLabel = new JLabel(String.valueOf(redSb.getValue()));        greenSb = new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 255);        greenSb.addAdjustmentListener(this);        greenLabel = new JLabel(String.valueOf(greenSb.getValue()));        blueSb = new JScrollBar(JScrollBar.HORIZONTAL, 0, 1, 0, 255);        blueSb.addAdjustmentListener(this);        blueLabel = new JLabel(String.valueOf(blueSb.getValue()));        addComponent(redSb, 8, 0);        addComponent(new JLabel(" r"), 8, 1);        addComponent(redLabel, 9, 0);        addComponent(greenSb, 10, 0);        addComponent(new JLabel(" g"), 10, 1);        addComponent(greenLabel, 11, 0);        addComponent(blueSb, 12, 0);        addComponent(new JLabel(" b"), 12, 1);        addComponent(blueLabel, 13, 0);        okButton = new JButton("OK");        okButton.addActionListener(this);        addComponent(okButton, 14, 0);        pack();        addWindowListener(new GlomoWindowHandler(GlomoWindowHandler.CLOSE));    }    public void addComponent(JComponent c, int row, int column) {        gbConstraints.gridx = column;        gbConstraints.gridy = row;        gbLayout.setConstraints(c, gbConstraints);        getContentPane().add(c);    }    public boolean getShowTxRangeOption() {        return showTxRangeCb.isSelected();    }    public boolean getShowNodeConnectionsOption() {        return showNodeConnectionsCb.isSelected();    }    public boolean getShowDemoColorsOption() {        return showDemoColorsCb.isSelected();    }    public Hashtable getColorHtbl() {        return rgbHtbl;    }    // updates scrollbars and canvas to reflect the rgb of the selected item    public void itemStateChanged(ItemEvent ie) {        //String key = (String)((JComboBox) ie.getSource()).getSelectedItem();        int[] rgb = (int[]) rgbHtbl.get((String)displayType.getSelectedItem());        redSb.setValue(rgb[0]);        greenSb.setValue(rgb[1]);        blueSb.setValue(rgb[2]);        redLabel.setText(String.valueOf(rgb[0]));        greenLabel.setText(String.valueOf(rgb[1]));        blueLabel.setText(String.valueOf(rgb[2]));        demoCanvas.setBackground(new Color(rgb[0], rgb[1], rgb[2]));//        validate();    }        // updates the rgb values of the currently selected item    public void adjustmentValueChanged(AdjustmentEvent ae) {        Adjustable colorSb = ae.getAdjustable();        Vector colorVec;        int r = redSb.getValue();        int g = greenSb.getValue();        int b = blueSb.getValue();        int[] rgb = (int[]) rgbHtbl.get((String)displayType.getSelectedItem());        if (colorSb == redSb) {            redLabel.setText(String.valueOf(r));            rgb[0] = r;        }        else if (colorSb == greenSb) {            greenLabel.setText(String.valueOf(g));            rgb[1] = g;        }        else if (colorSb == blueSb) {            blueLabel.setText(String.valueOf(b));            rgb[2] = b;        }        else {            messageDialog.setMessage("", "Error! Invalid adjustable!");        }        demoCanvas.setBackground(new Color(r, g, b));//        validate();    }    public void actionPerformed(ActionEvent e) {        Object action = e.getSource();        if (action == okButton) {            setVisible(false);        }        else {            messageDialog.setMessage("", "Error! Invalid ActionEvent!");        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -