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

📄 glomomenubar.java

📁 无线网络仿真工具Glomosim2.03
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }        else {            messageDialog.setMessage("", "Unkown action!");        }    }    public void itemStateChanged(ItemEvent ie) {        Object item = ie.getSource();        if(item == toolBarMenuItem)        {            if(ie.getStateChange() == ItemEvent.SELECTED)            {                toolBarPanel.setVisible(true);            }            else            {                toolBarPanel.setVisible(false);            }        }        else if(item == statusBarMenuItem)        {            if(ie.getStateChange() == ItemEvent.SELECTED)            {                 statusPanel.setVisible(true);            }            else            {                 statusPanel.setVisible(false);            }        }    }    public boolean setGuiOptions(String executeString,                                  boolean guiRadio, boolean guiRouting){        boolean setGuiOption = false;        boolean setRadioOption = false;        boolean setRoutingOption = false;        if(executeString == null){            return(false);        }               // get the file name of config file.         String tmpString = executeString.trim();        if(tmpString == ""){            return(false);        }        int pos = tmpString.indexOf(' ');        if(pos == -1){            return(false);        }        String configFileName = tmpString.substring(pos);        configFileName = configFileName.trim();        // open config file        try{            RandomAccessFile configFile = new RandomAccessFile(configFileName, "rw");            //read all line from config file             Vector configFileLines = new Vector();            String aLine;            while((aLine = configFile.readLine()) != null){                configFileLines.addElement(aLine);            }            // write lines into config file and modify gui options            configFile.seek(0);            configFile.setLength(0);            for( int i=0; i< configFileLines.size(); i++){                aLine = ((String)configFileLines.elementAt(i)).trim();                 if(aLine.indexOf(GUI_OPTION) == 0){  // gui option                    configFile.writeBytes(GUI_OPTION + "   YES\n");                    setGuiOption = true;                }                else if(aLine.indexOf(GUI_RADIO) == 0){  // gui radio option                    if(guiRadio){                        configFile.writeBytes(GUI_RADIO + "    YES\n");                    }                    else                    {                        configFile.writeBytes(GUI_RADIO + "    NO\n");                    }                    setRadioOption = true;                }                else if(aLine.indexOf(GUI_ROUTING) == 0){  // gui routing                    if(guiRouting){                        configFile.writeBytes(GUI_ROUTING + "  YES\n");                    }                    else                    {                        configFile.writeBytes(GUI_ROUTING + "  NO\n");                    }                    setRoutingOption = true;                }                else                {                    configFile.writeBytes(configFileLines.elementAt(i) + "\n");                }            }               if(!setGuiOption){                configFile.writeBytes(GUI_OPTION + "   YES\n");            }            if(!setRadioOption){                if(guiRadio){                    configFile.writeBytes(GUI_RADIO + "    YES\n");                }                else                {                    configFile.writeBytes(GUI_RADIO + "    NO\n");                }            }            if(!setRoutingOption){                if(guiRouting){                    configFile.writeBytes(GUI_ROUTING + "  YES\n");                }                else                {                    configFile.writeBytes(GUI_ROUTING + "  NO\n");                }            }            configFile.close();        } catch (FileNotFoundException e){            messageDialog.setMessage("File Error", "Can not open config file");            return(false);        } catch (IOException e){            messageDialog.setMessage("File Error", "Write config file error");        } finally{}        return(true);    }    public void setMagnification(int m){        if((m >= 1) && (m<=4)){            magnification = m;            switch(m){                case 1 : setZoomItems(oneMenuItem);                         break;                case 2 : setZoomItems(twoMenuItem);                         break;                case 3 : setZoomItems(threeMenuItem);                         break;                case 4 : setZoomItems(fourMenuItem);                         break;            }            gCanvas.setMagnification(m);            gCanvas.repaint();         }    }    public void setZoomItems(JRadioButtonMenuItem rbmi) {        oneMenuItem.setSelected(false);        twoMenuItem.setSelected(false);        threeMenuItem.setSelected(false);        fourMenuItem.setSelected(false);        rbmi.setSelected(true);    }    public void selectBackgroundColor() {        Color newColor = colorChooser.showDialog(parent,                             "Choose Background Color",                             bgColor);        if((newColor != null) && (newColor != bgColor))        {            bgColor = newColor;            gCanvas.setBackgroundColor(bgColor);        }    }    public void setRunSettings() {        writeTraceMenuItem.setEnabled(false);        playBackMenuItem.setEnabled(false);    }    public void setPlayBackSettings() {        writeTraceMenuItem.setEnabled(false);        playBackMenuItem.setEnabled(false);        toolBarPanel.setEnabledButtons(true);        abortMenuItem.setEnabled(true);    }    public void resetMenuAndToolBars() {        toolBarPanel.setEnabledButtons(false);        writeTraceMenuItem.setEnabled(true);        playBackMenuItem.setEnabled(true);        abortMenuItem.setEnabled(false);    }    private void initInputDialog(JDialog inputDialog) {        inputDialog.setResizable(true);        inputDialog.getContentPane().setLayout(new GridLayout(0, 2));        gCanvas.setBackgroundColor(bgColor);        boolean showTxRangeOption = guiOptionsDialog.getShowTxRangeOption();        boolean showNodeConnectionsOption =                        guiOptionsDialog.getShowNodeConnectionsOption();        boolean showDemoColorsOption =                        guiOptionsDialog.getShowDemoColorsOption();        Hashtable cHtbl = guiOptionsDialog.getColorHtbl();        if(runThread != null){ // To kill old simulation            if(runThread.isAlive()){                runThread.abortSim();                runThread = null;            }        }        runThread = new GlomoRunThread(executableName, parent, gCanvas, this,                       statusPanel, toolBarPanel, traceOption,                        showTxRangeOption,                       showNodeConnectionsOption, showDemoColorsOption, cHtbl);        runThread.setMagnification(magnification);        toolBarPanel.setRunThread(runThread);        if (traceOption == GlomoRunThread.REAL_TIME) {            inputDialog.setTitle("Run Simulation in Real Time");            executable = new JLabel("Executable:");            execTF = new JTextField(executableName);            inputDialog.getContentPane().add(executable);            inputDialog.getContentPane().add(execTF);        }        else if (traceOption == GlomoRunThread.WRITE_TRACE) {            inputDialog.setTitle("Create Trace File of Simulation");            executable = new JLabel("Executable:");            execTF = new JTextField(executableName);            inputDialog.getContentPane().add(executable);            inputDialog.getContentPane().add(execTF);        }        else {            inputDialog.setTitle("Play Back Trace File");        }        traceFile = new JLabel("Trace File:");        traceTF = new JTextField(traceFileName);        okInputButton = new JButton("OK");        okInputButton.addActionListener(this);        cancelInputButton = new JButton("Cancel");        cancelInputButton.addActionListener(this);        if (traceOption != GlomoRunThread.REAL_TIME) {            inputDialog.getContentPane().add(traceFile);            inputDialog.getContentPane().add(traceTF);        }        if ((traceOption == GlomoRunThread.REAL_TIME) ||            (traceOption == GlomoRunThread.WRITE_TRACE)){            guiRadioOption = new JCheckBox("Show Radio Layer");            guiRadioOption.setSelected(guiRadio);            inputDialog.getContentPane().add(guiRadioOption);            guiRoutingOption = new JCheckBox("Show Network Layer");            guiRoutingOption.setSelected(guiRouting);            inputDialog.getContentPane().add(guiRoutingOption);        }               inputDialog.getContentPane().add(okInputButton);        inputDialog.getContentPane().add(cancelInputButton);        inputDialog.pack();        inputDialog.addWindowListener(                        new GlomoWindowHandler(GlomoWindowHandler.CLOSE));    }}class GlomoAboutDialog extends JDialog implements ActionListener {    private JLabel message;    private JButton okButton;    public GlomoAboutDialog(JFrame parent) {        super(parent, "About GloMoSim Visualization Tool", true);        setResizable(true);        getContentPane().setLayout(new GridLayout(0, 1));        message = new JLabel("GloMoSim Visualization Tool", JLabel.CENTER);        getContentPane().add(message);        message = new JLabel("Version 1.1, 1999", JLabel.CENTER);        getContentPane().add(message);        message = new JLabel("by Addison Lee", JLabel.CENTER);        getContentPane().add(message);        message = new JLabel("Upgraded by Kaixin Xu", JLabel.CENTER);        getContentPane().add(message);        message = new JLabel("Go UCLA Bruins!", JLabel.CENTER);        getContentPane().add(message);        okButton = new JButton("OK");        okButton.addActionListener(this);        JPanel okPanel = new JPanel();        okPanel.add(okButton);         getContentPane().add(okPanel);        pack();        addWindowListener(new GlomoWindowHandler(GlomoWindowHandler.CLOSE));    }    public void actionPerformed(ActionEvent e) {        setVisible(false);    }}class GlomoContentsDialog extends JDialog implements ActionListener {    GlomoMessageDialog messageDialog;    public GlomoContentsDialog(JFrame parent, GlomoMessageDialog gmDialog) {        super(parent, "Help Contents", false);        messageDialog = gmDialog;        setResizable(true);        getContentPane().setLayout(new BorderLayout());         JTextArea helpPad = new JTextArea("", 40, 80);        helpPad.setFont(new Font("Monospaced", Font.PLAIN, 12));        String fileName = "vis_help.txt";        try {            FileReader fr = new FileReader(fileName);            char[] buf = new char[(int) (new File(fileName)).length()];            fr.read(buf);            fr.close();            helpPad.setText(String.valueOf(buf));        } catch(FileNotFoundException fnfe) {            messageDialog.setMessage("", "Help: " + fileName + " not found!");        } catch(IOException ioe) {            messageDialog.setMessage("", "Help: IOException occurred!");         }        JScrollPane sp = new JScrollPane(helpPad);        getContentPane().add(sp, BorderLayout.CENTER);        JPanel p = new JPanel();        JButton cancelButton = new JButton("Cancel");        cancelButton.addActionListener(this);        p.add(cancelButton);        getContentPane().add(p, BorderLayout.SOUTH);        pack();        addWindowListener(new GlomoWindowHandler(GlomoWindowHandler.CLOSE));    }    public void actionPerformed(ActionEvent e)    {        String clicked = e.getActionCommand();        if (clicked.equals("Cancel")) {

⌨️ 快捷键说明

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