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

📄 statgraphvisualizer.java

📁 测试工具
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
			}
		}
		row.addSample(res);
		((SamplingStatCalculator) tableRows.get(TOTAL_ROW_LABEL)).addSample(res);
		model.fireTableDataChanged();
	}

	/**
	 * Clears this visualizer and its model, and forces a repaint of the table.
	 */
	public void clearData() {
		model.clearData();
		tableRows.clear();
		tableRows.put(TOTAL_ROW_LABEL, new SamplingStatCalculator(TOTAL_ROW_LABEL));
		model.addRow(tableRows.get(TOTAL_ROW_LABEL));
	}

	// overrides AbstractVisualizer
	// forces GUI update after sample file has been read
	public TestElement createTestElement() {
		TestElement t = super.createTestElement();

		// sleepTill = 0;
		return t;
	}

	/**
	 * Main visualizer setup.
	 */
	private void init() {
		this.setLayout(new BorderLayout());

		// MAIN PANEL
		JPanel mainPanel = new JPanel();
		Border margin = new EmptyBorder(10, 10, 5, 10);
        Border margin2 = new EmptyBorder(10, 10, 5, 10);
        
		mainPanel.setBorder(margin);
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
		mainPanel.add(makeTitlePanel());

		myJTable = new JTable(model);
		myJTable.setPreferredScrollableViewportSize(new Dimension(500, 80));
		RendererUtils.applyRenderers(myJTable, RENDERERS);
		myScrollPane = new JScrollPane(myJTable);
        
        graph = new VerticalPanel();
        graph.setBorder(margin2);


        JLabel graphLabel = new JLabel(JMeterUtils.getResString("aggregate_graph")); //$NON-NLS-1$
        graphPanel = new AxisGraph();
        graphPanel.setPreferredSize(new Dimension(defaultWidth,defaultHeight));

        // horizontal panel for the buttons
        HorizontalPanel buttonpanel = new HorizontalPanel();
        buttonpanel.add(columns);
        buttonpanel.add(displayButton);
        buttonpanel.add(saveGraph);
        buttonpanel.add(saveTable);
        
        graph.add(graphLabel);
        graph.add(graphTitle);
        graph.add(maxLengthXAxisLabel);
        graph.add(graphWidth);
        graph.add(graphHeight);
        graph.add(buttonpanel);
        graph.add(graphPanel);

        displayButton.addActionListener(this);
        saveGraph.addActionListener(this);
        saveTable.addActionListener(this);
        graphScroll = new JScrollPane(graph);
        graphScroll.setAutoscrolls(true);

        spane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        spane.setLeftComponent(myScrollPane);
        spane.setRightComponent(graphScroll);
        spane.setResizeWeight(.2);
        spane.setContinuousLayout(true);

        this.add(mainPanel, BorderLayout.NORTH);
        this.add(spane,BorderLayout.CENTER);
	}
    
    public void makeGraph() {
        String wstr = graphWidth.getText();
        String hstr = graphHeight.getText();
        String lstr = maxLengthXAxisLabel.getText();
        if (wstr.length() == 0) {
            wstr = "450";//$NON-NLS-1$
        }
        if (hstr.length() == 0) {
            hstr = "250";//$NON-NLS-1$
        }
        if (lstr.length() == 0) {
            lstr = "20";//$NON-NLS-1$
        }
        int width = Integer.parseInt(wstr);
        int height = Integer.parseInt(hstr);
        int maxLength = Integer.parseInt(lstr);

        graphPanel.setData(this.getData());
        graphPanel.setHeight(height);
        graphPanel.setWidth(width);
        graphPanel.setTitle(graphTitle.getText());
        graphPanel.setMaxLength(maxLength);
        graphPanel.setXAxisLabels(getAxisLabels());
        graphPanel.setXAxisTitle(columns.getText());
        graphPanel.setYAxisLabels(this.yAxisLabel);
        graphPanel.setYAxisTitle(this.yAxisTitle);

        graphPanel.setPreferredSize(new Dimension(width,height));
        graph.setSize(new Dimension(graph.getWidth(), height + 120));
        spane.repaint();
    }
    
    public double[][] getData() {
        if (model.getRowCount() > 1) {
            int count = model.getRowCount() -1;
            int col = model.findColumn(columns.getText());
            double[][] data = new double[1][count];
            for (int idx=0; idx < count; idx++) {
                data[0][idx] = ((Number)model.getValueAt(idx,col)).doubleValue();
            }
            return data;
        }
		return new double[][]{ { 250, 45, 36, 66, 145, 80, 55  } };
    }
    
    public String[] getAxisLabels() {
        if (model.getRowCount() > 1) {
            int count = model.getRowCount() -1;
            String[] labels = new String[count];
            for (int idx=0; idx < count; idx++) {
                labels[idx] = (String)model.getValueAt(idx,0);
            }
            return labels;
        }
		return new String[]{ "/", "/samples", "/jsp-samples", "/manager", "/manager/status", "/hello", "/world" };
    }
    
    /**
     * We use this method to get the data, since we are using
     * ObjectTableModel, so the calling getDataVector doesn't 
     * work as expected.
     * @return the data from the model
     */
    public Vector getAllTableData() {
        Vector data = new Vector();
        if (model.getRowCount() > 0) {
            for (int rw=0; rw < model.getRowCount(); rw++) {
                int cols = model.getColumnCount();
                Vector column = new Vector();
                data.add(column);
                for (int idx=0; idx < cols; idx++) {
                    Object val = model.getValueAt(rw,idx);
                    column.add(val);
                }
            }
        }
        return data;
    }
    
    public void actionPerformed(ActionEvent event) {
        if (event.getSource() == displayButton) {
            makeGraph();
        } else if (event.getSource() == saveGraph) {
            saveGraphToFile = true;
            try {
                ActionRouter.getInstance().getAction(
                        ActionNames.SAVE_GRAPHICS,SaveGraphics.class.getName()).doAction(
                                new ActionEvent(this,1,ActionNames.SAVE_GRAPHICS));
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (event.getSource() == saveTable) {
            JFileChooser chooser = FileDialoger.promptToSaveFile(
                    "statistics.csv");		//$NON-NLS-1$
            File output = chooser.getSelectedFile();
            FileWriter writer = null;
            try {
                writer = new FileWriter(output);
                Vector data = this.getAllTableData();
                CSVSaveService.saveCSVStats(data,writer);
            } catch (FileNotFoundException e) {
                log.warn(e.getMessage());
            } catch (IOException e) {
                log.warn(e.getMessage());
            } finally {
                JOrphanUtils.closeQuietly(writer);
            }
        }
    }
    
    public JComponent getPrintableComponent() {
        if (saveGraphToFile == true) {
            saveGraphToFile = false;
            graphPanel.setBounds(graphPanel.getLocation().x,graphPanel.getLocation().y,
                    graphPanel.width,graphPanel.height);
            return graphPanel;
        }
		return this;
    }
}

⌨️ 快捷键说明

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