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

📄 glomorunthread.java

📁 无线网络仿真工具Glomosim2.03
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    } // end run        private void showSimulation(BufferedReader br)                throws IOException, InterruptedException {        String line;        StringTokenizer strTokenizer;        int type;        while ((line = br.readLine()) != null) {            if( simState == ABORT_STATE){ // abort the simulation                 killSubProcess();                 break;            }            else if(simState == STEP_STATE){ // step the simulation                 simState = STOP_STATE;            }            else if(simState == STOP_STATE){ // stop the simulation                 synchronized(this){                     while (simState == STOP_STATE){                         wait();                     }                 }            }            if( simState == ABORT_STATE){ // abort the simulation                 killSubProcess();                 break;            }            strTokenizer = new StringTokenizer(line);            // blank line            if(strTokenizer.hasMoreTokens() == false) {                continue;            }            try {                type = Integer.parseInt(strTokenizer.nextToken());            } catch (NumberFormatException ne) {                // if first word of line is not an enum, ignore the line                continue;            }                        playLine(type, strTokenizer);        }    }    private void playLine(int type, StringTokenizer strTokenizer)                throws IOException, InterruptedException {        int x, y, id, idDest, numNodes, txRange, thickness;        long time;        Color nodeColor, connectionColor, txColor;        Graphics gContext = gCanvas.getGraphics();        // display simtime if different from old simtime        if (type != INITIALIZE) {            time = Long.parseLong(strTokenizer.nextToken());            if (time != currentSimTime) {                toolBarPanel.setSimTime(time);                currentSimTime = time;            }        }        switch (type) {        case INITIALIZE:            numNodes = Integer.parseInt(strTokenizer.nextToken());            if (nodeArraySet == false) {                mobileNodes = new GlomoMobileNode[numNodes];                nodeArraySet = true;            }            id = Integer.parseInt(strTokenizer.nextToken());            x = Integer.parseInt(strTokenizer.nextToken());            y = Integer.parseInt(strTokenizer.nextToken());            txRange = Integer.parseInt(strTokenizer.nextToken());            nodeColor = colors[Byte.parseByte(strTokenizer.nextToken())];            connectionColor = colors[Byte.parseByte(strTokenizer.nextToken())];            if (showDemoColorsOption == true) {                int[] nodeRGB = (int[]) demoColorHtbl.get("Node Color");                int[] conRGB = (int[]) demoColorHtbl.get("Connection Color");                Color node = new Color(nodeRGB[0], nodeRGB[1], nodeRGB[2]);                Color connection = new Color(conRGB[0], conRGB[1], conRGB[2]);                mobileNodes[id] = new GlomoMobileNode(id, x,                                    y, txRange,                                    gCanvas,                                    node, connection, showTxRangeOption,                                    showNodeConnectionsOption);            }            else {                mobileNodes[id] = new GlomoMobileNode(id, x,                                        y, txRange,                                        gCanvas,                                        nodeColor, connectionColor,                                        showTxRangeOption,                                        showNodeConnectionsOption);            }            nodesSetSoFar++;            if (nodesSetSoFar == numNodes) {                for (int i=0; i < mobileNodes.length; i++) {                    mobileNodes[i].createInitialConnections(mobileNodes);                }                gCanvas.setNodes(mobileNodes, this);                // important: the order of the following two statements must NOT                // be changed; otherwise, deadlock may sometimes occur                initialWaiting = true;                gCanvas.repaint();                // the reason for waiting is to make sure that the canvas is                // repainted BEFORE the simulation continues; gCanvas sets                // initialWaiting to false                synchronized(this) {                    while (initialWaiting == true) {                        wait();                    }                }            }            break;        case MOVE_NODE:            id = Integer.parseInt(strTokenizer.nextToken());            x = Integer.parseInt(strTokenizer.nextToken());            y = Integer.parseInt(strTokenizer.nextToken());            mobileNodes[id].eraseAllConnections(gContext);            mobileNodes[id].eraseNode(gContext, numIterations);            mobileNodes[id].setLocation(                               new Point(x, y));            mobileNodes[id].updateConnections(mobileNodes);            mobileNodes[id].drawNode(gContext);            mobileNodes[id].drawAllConnections(gContext);            break;        case DRAW_BROADCAST:            id = Integer.parseInt(strTokenizer.nextToken());            txColor = colors[Byte.parseByte(strTokenizer.nextToken())];            if (showDemoColorsOption == true) {                int[] rgb = (int[]) demoColorHtbl.get("Broadcast Color");                Color c = new Color(rgb[0], rgb[1], rgb[2]);                mobileNodes[id].drawBroadcast(gContext, c, numIterations);            }            else {                mobileNodes[id].drawBroadcast(gContext, txColor, numIterations);            }            break;        case DRAW_LINE:            id = Integer.parseInt(strTokenizer.nextToken());            idDest = Integer.parseInt(strTokenizer.nextToken());            txColor = colors[Byte.parseByte(strTokenizer.nextToken())];            if (showDemoColorsOption == true) {                int[] rgb = (int[]) demoColorHtbl.get("Line Color");                Color demoLineColor = new Color(rgb[0], rgb[1], rgb[2]);                mobileNodes[id].drawLine(mobileNodes[idDest], demoLineColor,                                         gContext, numIterations);            }            else {                mobileNodes[id].drawLine(mobileNodes[idDest], txColor,                                         gContext, numIterations);            }            break;        case DRAW_THICKLINE:            id = Integer.parseInt(strTokenizer.nextToken());            idDest = Integer.parseInt(strTokenizer.nextToken());            thickness = Integer.parseInt(strTokenizer.nextToken());            txColor = colors[Byte.parseByte(strTokenizer.nextToken())];            if (showDemoColorsOption == true) {                int[] rgb = (int[]) demoColorHtbl.get("Line Color");                Color demoLineColor = new Color(rgb[0], rgb[1], rgb[2]);                mobileNodes[id].drawThickLine(mobileNodes[idDest], thickness,                                        demoLineColor, gContext, numIterations);            }            else {                mobileNodes[id].drawThickLine(mobileNodes[idDest], thickness,                                              txColor, gContext, numIterations);            }            break;        case DRAW_LINK:            id = Integer.parseInt(strTokenizer.nextToken());            idDest = Integer.parseInt(strTokenizer.nextToken());            txColor = colors[Byte.parseByte(strTokenizer.nextToken())];            if (showDemoColorsOption == true) {                int[] rgb = (int[]) demoColorHtbl.get("Link Color");                Color demoLinkColor = new Color(rgb[0], rgb[1], rgb[2]);                mobileNodes[id].drawLink(mobileNodes[idDest], demoLinkColor,                                         gContext);            }            else {                mobileNodes[id].drawLink(mobileNodes[idDest], txColor,                                         gContext);            }            break;        case ERASE_LINK:            id = Integer.parseInt(strTokenizer.nextToken());            idDest = Integer.parseInt(strTokenizer.nextToken());            mobileNodes[id].eraseLink(mobileNodes[idDest], gContext);            break;        default:            killSubProcess();            System.err.println("Error! Unrecognized gui command!");            System.exit(-1);        } // end switch(type)        gContext.dispose();    } // end playLine    public void actionPerformed(ActionEvent e) {        String command = e.getActionCommand();        if (command.equals("Cancel")) {            killSubProcess();               menuBar.resetMenuAndToolBars();            runDialog.setVisible(false);        }        else if (command.equals("Ok")) {            runDialog.setVisible(false);        }    }    public void killSubProcess() {        if(proc != null){            proc.destroy();             proc = null;        }    }}

⌨️ 快捷键说明

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