private int getNbColumns() { int i = 0; for (BarGraph bar : eltList) { if (bar.getChkBox().isSelected()) { i++; } } return i; }
/** * Show graph. * * @param v the v */ public void showGraph(View v) { switch (v.getId()) { case R.id.BarGraph: BarGraph bar = new BarGraph(); Intent barIntent = bar.getIntent(getApplicationContext()); // startActivity(bar.getIntent(getApplicationContext())); startActivity(barIntent); break; } }
private Color[] getBackColors() { Color[] backColors = new Color[nbColToGraph]; int i = 0; for (BarGraph bar : eltList) { if (bar.getChkBox().isSelected()) { backColors[i] = bar.getBackColor(); i++; } } return backColors; }
private String[] getLegendLabels() { String[] legends = new String[nbColToGraph]; int i = 0; for (BarGraph bar : eltList) { if (bar.getChkBox().isSelected()) { legends[i] = bar.getLabel(); i++; } } return legends; }
private JButton createColorBarButton(BarGraph barGraph, int index) { // Button JButton colorBtn = new JButton(); colorBtn.setName(String.valueOf(index)); colorBtn.setFont(FONT_SMALL); colorBtn.addActionListener(this); colorBtn.setBackground(barGraph.getBackColor()); return colorBtn; }
@Override public void draw(Graphics g, int index1, int index2) { // draw containers if (hasContainers(index1, index2)) { System.out.println("Has containers"); Image buffer = _panel.createImage(_panel.getWidth() - 6, _panel.getHeight() / 2 - 6); Graphics2D bufferGraphics = (Graphics2D) buffer.getGraphics(); bufferGraphics.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); bufferGraphics.setColor(Color.white); bufferGraphics.fillRect(0, 0, _panel.getWidth(), _panel.getHeight() / 2); drawContainers(bufferGraphics, index1, index2); BAR_GRAPH.addImage(buffer); } BAR_GRAPH.drawBuckets(true); BAR_GRAPH.draw(g, index1, index2); BAR_GRAPH.addImage(null); }
private JPanel createGraphColumnPane() { JPanel colPanel = new JPanel(); colPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0)); JLabel label = new JLabel(JMeterUtils.getResString("aggregate_graph_columns_to_display")); // $NON-NLS-1$ colPanel.add(label); for (BarGraph bar : eltList) { colPanel.add(bar.getChkBox()); colPanel.add(createColorBarButton(bar, eltList.indexOf(bar))); } colPanel.add(Box.createRigidArea(new Dimension(5, 0))); chooseForeColor.setFont(FONT_SMALL); colPanel.add(chooseForeColor); chooseForeColor.addActionListener(this); JPanel optionsPanel = new JPanel(); optionsPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); optionsPanel.add(createGraphFontValuePane()); optionsPanel.add(drawOutlinesBar); optionsPanel.add(numberShowGrouping); optionsPanel.add(valueLabelsVertical); JPanel barPane = new JPanel(new BorderLayout()); barPane.add(colPanel, BorderLayout.NORTH); barPane.add(Box.createRigidArea(new Dimension(0, 3)), BorderLayout.CENTER); barPane.add(optionsPanel, BorderLayout.SOUTH); JPanel columnPane = new JPanel(new BorderLayout()); columnPane.setBorder( BorderFactory.createTitledBorder( BorderFactory.createEtchedBorder(), JMeterUtils.getResString("aggregate_graph_column_settings"))); // $NON-NLS-1$ columnPane.add(barPane, BorderLayout.NORTH); columnPane.add(Box.createRigidArea(new Dimension(0, 3)), BorderLayout.CENTER); columnPane.add(createGraphSelectionSubPane(), BorderLayout.SOUTH); return columnPane; }
public double[][] getData() { if (model.getRowCount() > 1) { int count = model.getRowCount() - 1; int size = nbColToGraph; double[][] data = new double[size][count]; int s = 0; int cpt = 0; for (BarGraph bar : eltList) { if (bar.getChkBox().isSelected()) { int col = model.findColumn((String) columnsList.getItemAt(cpt)); for (int idx = 0; idx < count; idx++) { data[s][idx] = ((Number) model.getValueAt(idx, col)).doubleValue(); } s++; } cpt++; } return data; } // API expects null, not empty array return null; }
@Override public void actionPerformed(ActionEvent event) { boolean forceReloadData = false; final Object eventSource = event.getSource(); if (eventSource == displayButton) { actionMakeGraph(); } else if (eventSource == saveGraph) { saveGraphToFile = true; try { ActionRouter.getInstance() .getAction(ActionNames.SAVE_GRAPHICS, SaveGraphics.class.getName()) .doAction(new ActionEvent(this, 1, ActionNames.SAVE_GRAPHICS)); } catch (Exception e) { log.error(e.getMessage()); } } else if (eventSource == saveTable) { JFileChooser chooser = FileDialoger.promptToSaveFile("statistics.csv"); // $NON-NLS-1$ if (chooser == null) { return; } FileWriter writer = null; try { writer = new FileWriter(chooser.getSelectedFile()); // TODO Charset ? CSVSaveService.saveCSVStats( getAllTableData(), writer, saveHeaders.isSelected() ? COLUMNS : null); } catch (FileNotFoundException e) { log.warn(e.getMessage()); } catch (IOException e) { log.warn(e.getMessage()); } finally { JOrphanUtils.closeQuietly(writer); } } else if (eventSource == chooseForeColor) { Color color = JColorChooser.showDialog( null, JMeterUtils.getResString("aggregate_graph_choose_color"), // $NON-NLS-1$ colorBarGraph); if (color != null) { colorForeGraph = color; } } else if (eventSource == syncWithName) { graphTitle.setText(namePanel.getName()); } else if (eventSource == dynamicGraphSize) { // if use dynamic graph size is checked, we disable the dimension fields if (dynamicGraphSize.isSelected()) { graphWidth.setEnabled(false); graphHeight.setEnabled(false); } else { graphWidth.setEnabled(true); graphHeight.setEnabled(true); } } else if (eventSource == columnSelection) { if (columnSelection.isSelected()) { columnMatchLabel.setEnabled(true); applyFilterBtn.setEnabled(true); caseChkBox.setEnabled(true); regexpChkBox.setEnabled(true); } else { columnMatchLabel.setEnabled(false); applyFilterBtn.setEnabled(false); caseChkBox.setEnabled(false); regexpChkBox.setEnabled(false); // Force reload data forceReloadData = true; } } // Not 'else if' because forceReloadData if (eventSource == applyFilterBtn || forceReloadData) { if (columnSelection.isSelected() && columnMatchLabel.getText() != null && columnMatchLabel.getText().length() > 0) { pattern = createPattern(columnMatchLabel.getText()); } else if (forceReloadData) { pattern = null; matcher = null; } if (getFile() != null && getFile().length() > 0) { clearData(); FilePanel filePanel = (FilePanel) getFilePanel(); filePanel.actionPerformed(event); } } else if (eventSource instanceof JButton) { // Changing color for column JButton btn = ((JButton) eventSource); if (btn.getName() != null) { try { BarGraph bar = eltList.get(Integer.parseInt(btn.getName())); Color color = JColorChooser.showDialog(null, bar.getLabel(), bar.getBackColor()); if (color != null) { bar.setBackColor(color); btn.setBackground(bar.getBackColor()); } } catch (NumberFormatException nfe) { } // nothing to do } } }