List of usage examples for javax.swing JTable setModel
@BeanProperty(description = "The model that is the source of the data for this view.") public void setModel(final TableModel dataModel)
From source file:app.RunApp.java
/** * Generates TableModel for Box Diagrams * //from www .j a v a2 s . c o m * @param jtable Table * @param dataset Multi-label dataset * @return Generated TableModel */ private TableModel boxplotTableModel(JTable jtable) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("Diagram"); Object[] row = new Object[1]; row[0] = "#Examples per label"; tableModel.addRow(row); row[0] = "#Examples per labelset"; tableModel.addRow(row); jtable.setModel(tableModel); return jtable.getModel(); }
From source file:app.RunApp.java
/** * Fill the table with coefficient values * /*from w w w. j a v a 2 s .co m*/ * @param dataset * @param pairs * @param type */ private void fillTableCoefficients(MultiLabelInstances dataset, String type) { double[][] pairLabelValues; //coocurrence values table if (type.equals("coocurrence")) { pairLabelValues = ChartUtils.getCoocurrences(dataset); coocurrenceCoefficients = pairLabelValues; } //heatmap values table else { pairLabelValues = getHeatMapCoefficients(); heatmapCoefficients = pairLabelValues.clone(); } /** **/ data = new Object[pairLabelValues.length][pairLabelValues.length + 1]; column = new Object[data.length + 1]; if (type.equals("coocurrence")) { for (int i = 0; i < pairLabelValues.length; i++) { for (int j = 0; j < pairLabelValues.length; j++) { if (j == 0) { data[i][j] = dataset.getLabelNames()[i]; } else if (i == (j - 1)) { data[i][j] = ""; } else if (j > i) { data[i][j] = ""; } else { if (pairLabelValues[j - 1][i] <= 0.0) { data[i][j] = ""; } else { data[i][j] = (int) pairLabelValues[j - 1][i]; } } } } } else { for (int i = 0; i < pairLabelValues.length; i++) { for (int j = 0; j < pairLabelValues.length + 1; j++) { if (j == 0) { data[i][j] = dataset.getLabelNames()[i]; } else { if (pairLabelValues[j - 1][i] <= 0.0) { data[i][j] = ""; } else { NumberFormat formatter = new DecimalFormat("#0.000"); data[i][j] = formatter.format(pairLabelValues[j - 1][i]).replace(",", "."); } } } } } for (int i = 0; i < column.length; i++) { if (i == 0) { column[i] = "Labels"; } else { column[i] = (dataset.getLabelNames()[i - 1]); } } AbstractTableModel1 fixedModel = new AbstractTableModel1(data, column); AbstractTableModel2 model = new AbstractTableModel2(data, column); JTable temp, fixedTable_temp; JPanel jpanel_temp; if (type.equals("coocurrence")) { temp = jTableCoocurrences; jpanel_temp = panelCoOcurrenceValues; fixedTable_temp = fixedTableCoocurrences; } else { temp = jTableHeatmap; jpanel_temp = panelHeatmapValues; fixedTable_temp = fixedTableHeatmap; } fixedTable_temp.setModel(fixedModel); temp.setModel(model); JScrollPane scroll = new JScrollPane(temp); JViewport viewport = new JViewport(); viewport.setView(fixedTable_temp); viewport.setPreferredSize(fixedTable_temp.getPreferredSize()); scroll.setRowHeaderView(viewport); scroll.setBounds(20, 20, 780, 390); scroll.setCorner(JScrollPane.UPPER_LEFT_CORNER, fixedTable_temp.getTableHeader()); temp.setBorder(BorderFactory.createLineBorder(Color.black)); jpanel_temp.remove(0); jpanel_temp.add(scroll, BorderLayout.CENTER, 0); }
From source file:app.RunApp.java
/** * Generates TableModel for IR intra class * /*from w w w.j av a2 s. c om*/ * @param jtable * @return */ private TableModel irIntraClassTableModel(JTable jtable) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("Label"); tableModel.addColumn("IR"); Object[] row = new Object[2]; String truncate; for (int i = 0; i < imbalancedLabels.length; i++) { truncate = Double.toString(imbalancedLabels[i].getIRIntraClass()); row[0] = imbalancedLabels[i].getName(); row[1] = MetricUtils.getValueFormatted(truncate, 3); tableModel.addRow(row); } jtable.setModel(tableModel); TableColumnModel tcm = jtable.getColumnModel(); tcm.getColumn(0).setPreferredWidth(80); tcm.getColumn(1).setPreferredWidth(50); return jtable.getModel(); }
From source file:app.RunApp.java
/** * Generates TableModel for IR inter class * /*from ww w . jav a 2s .com*/ * @param jtable * @return */ private TableModel irInterClassTableModel(JTable jtable) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("Label"); tableModel.addColumn("IR"); Object[] row = new Object[2]; String truncate; IRInterClass = MetricUtils.getIRInterClassValues(labelAppearances); int temp = IRInterClass.length - 1; for (int i = temp; i >= 0; i--) { truncate = Double.toString(IRInterClass[i]); row[0] = labelAppearances[i].getName(); row[1] = MetricUtils.getValueFormatted(truncate, 3); tableModel.addRow(row); } jtable.setModel(tableModel); TableColumnModel tcm = jtable.getColumnModel(); tcm.getColumn(0).setPreferredWidth(80); tcm.getColumn(1).setPreferredWidth(50); return jtable.getModel(); }
From source file:app.RunApp.java
/** * Generates TableModel for attributes/*from ww w . ja v a 2 s . c o m*/ * * @param jtable Table * @param dataset Multi-label dataset * @return Generated TableModel */ private TableModel attributesTableModel(JTable jtable, MultiLabelInstances dataset) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("Attribute"); Object[] row = new Object[1]; Instances instances = dataset.getDataSet(); int numLabels = dataset.getNumLabels(); int numAttributes = instances.numAttributes() - numLabels; Attribute att; for (int i = 0; i < numAttributes; i++) { att = instances.attribute(i); if (att.isNumeric()) { row[0] = att.name(); tableModel.addRow(row); } } jtable.setModel(tableModel); return jtable.getModel(); }
From source file:app.RunApp.java
/** * Generate TableModel for label frequency * // ww w. j ava 2 s .c o m * @param jtable Table * @param dataset Multi-label dataset * @return Generated TableModel */ private TableModel labelFrequencyTableModel(JTable jtable, MultiLabelInstances dataset) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("Label"); tableModel.addColumn("# Examples"); tableModel.addColumn("Frequency"); Object[] row = new Object[3]; ImbalancedFeature current; double freq; String truncate; for (int i = 0; i < dataset.getNumLabels(); i++) { current = labelAppearances[i]; row[0] = current.getName(); freq = current.getAppearances() * 1.0 / dataset.getNumInstances(); row[1] = current.getAppearances(); truncate = Double.toString(freq); row[2] = MetricUtils.truncateValue(truncate, 4); tableModel.addRow(row); } jtable.setModel(tableModel); TableColumnModel tcm = jtable.getColumnModel(); tcm.getColumn(0).setPreferredWidth(80); tcm.getColumn(1).setPreferredWidth(70); tcm.getColumn(2).setPreferredWidth(70); return jtable.getModel(); }
From source file:app.RunApp.java
/** * Generates TableModel for frequency values * //from w w w . ja va 2s.com * @param jtable Table * @param dataset Multi-label dataset * @return Generated TableModel */ private TableModel frequencyTableModel(JTable jtable, MultiLabelInstances dataset) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("Label"); tableModel.addColumn("# Examples"); tableModel.addColumn("Frequency"); Object[] row = new Object[3]; ImbalancedFeature current; double freq; String truncate; for (int i = 0; i < dataset.getNumLabels(); i++) { current = labelAppearances[i]; row[0] = current.getName(); freq = current.getAppearances() * 1.0 / dataset.getNumInstances(); row[1] = current.getAppearances(); truncate = Double.toString(freq); row[2] = MetricUtils.getValueFormatted(truncate, 4); tableModel.addRow(row); } jtable.setModel(tableModel); TableColumnModel tcm = jtable.getColumnModel(); tcm.getColumn(0).setPreferredWidth(80); tcm.getColumn(1).setPreferredWidth(70); tcm.getColumn(2).setPreferredWidth(50); return jtable.getModel(); }
From source file:app.RunApp.java
/** * Generates TableModel for labels per example values * //from www . jav a 2s. co m * @param jtable Table * @param labelsPerExample Number of labels per example * @return Generated TableModel */ private TableModel labelsPerExampleTableModel(JTable jtable, HashMap<Integer, Integer> labelsPerExample) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("# Labels"); tableModel.addColumn("# Examples"); tableModel.addColumn("Frequency"); Object[] row = new Object[3]; double freq; int freqCurrent; String truncate; int max = Utils.maxKey(labelsPerExample); for (int i = 0; i <= max; i++) { freqCurrent = 0; if (labelsPerExample.get(i) != null) { freqCurrent = labelsPerExample.get(i); } freq = freqCurrent * 1.0 / dataset.getNumInstances(); row[0] = i; row[1] = freqCurrent; truncate = Double.toString(freq); row[2] = MetricUtils.getValueFormatted(truncate, 4); tableModel.addRow(row); } jtable.setModel(tableModel); TableColumnModel tcm = jtable.getColumnModel(); tcm.getColumn(0).setPreferredWidth(80); tcm.getColumn(1).setPreferredWidth(50); tcm.getColumn(2).setPreferredWidth(70); return jtable.getModel(); }
From source file:app.RunApp.java
/** * Generates TableModel for imbalanced data * /*from w w w . j a va 2 s. c om*/ * @param jtable Table * @param dataset Multi-label dataset * @return Generated TableModel */ private TableModel imbalancedTableModel(JTable jtable, MultiLabelInstances dataset) { DefaultTableModel tableModel = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //This causes all cells to be not editable return false; } }; tableModel.addColumn("Label"); tableModel.addColumn("IR intra class"); tableModel.addColumn("IR inter class"); tableModel.addColumn("STDEV intra class"); imbalancedLabels = MetricUtils.sortImbalancedDataByIRIntraClass(imbalancedLabels); Object[] row = new Object[4]; double std; String truncate; ImbalancedFeature current; for (int i = 0; i < dataset.getNumLabels(); i++) { current = imbalancedLabels[i]; row[0] = current.getName(); truncate = Double.toString(current.getIRIntraClass()); row[1] = MetricUtils.truncateValue(truncate, 5); truncate = Double.toString(current.getIRInterClass()); row[2] = MetricUtils.truncateValue(truncate, 5); std = Math.sqrt(current.getVariance()); row[3] = MetricUtils.truncateValue(std, 4); tableModel.addRow(row); } jtable.setModel(tableModel); TableColumnModel tcm = jtable.getColumnModel(); tcm.getColumn(0).setPreferredWidth(100); tcm.getColumn(1).setPreferredWidth(20); tcm.getColumn(2).setPreferredWidth(80); tcm.getColumn(3).setPreferredWidth(40); return jtable.getModel(); }
From source file:interfaces.InterfazPrincipal.java
private void botonGenerarReporteClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botonGenerarReporteClienteActionPerformed // TODO add your handling code here: try {//from w ww. j av a 2s . c o m if (clienteReporteClienteFechaFinal.getSelectedDate().getTime() .compareTo(clienteReporteClienteFechaInicial.getSelectedDate().getTime()) < 0) { JOptionPane.showMessageDialog(this, "La fecha final debe ser posterior al dia de inicio"); } else { final ArrayList<Integer> listaIDFlujos = new ArrayList<>(); final JDialog dialogoEditar = new JDialog(); dialogoEditar.setTitle("Reporte cliente"); dialogoEditar.setSize(350, 610); dialogoEditar.setResizable(false); JPanel panelDialogo = new JPanel(); panelDialogo.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); //c.fill = GridBagConstraints.HORIZONTAL; JLabel ediitarTextoPrincipalDialogo = new JLabel("Informe cliente"); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.insets = new Insets(10, 45, 10, 10); Font textoGrande = new Font("Arial", 1, 18); ediitarTextoPrincipalDialogo.setFont(textoGrande); panelDialogo.add(ediitarTextoPrincipalDialogo, c); final JTable tablaDialogo = new JTable(); DefaultTableModel modeloTabla = new DefaultTableModel() { @Override public boolean isCellEditable(int row, int column) { //all cells false return false; } }; ; modeloTabla.addColumn("Factura"); modeloTabla.addColumn("Tipo Flujo"); modeloTabla.addColumn("Fecha"); modeloTabla.addColumn("Valor"); //Llenar tabla ControladorFlujoFactura controladorFlujoFactura = new ControladorFlujoFactura(); ArrayList<String[]> flujosCliente = controladorFlujoFactura.getTodosFlujo_Factura( " where factura_id in (select factura_id from Factura where cliente_id = " + String.valueOf(jTextFieldIdentificacionClienteReporte.getText()) + ") order by factura_id"); // {"flujo_id","factura_id","tipo_flujo","fecha","valor"}; ArrayList<Calendar> fechasFlujos = new ArrayList<>(); for (int i = 0; i < flujosCliente.size(); i++) { String fila[] = new String[4]; String[] objeto = flujosCliente.get(i); fila[0] = objeto[1]; fila[1] = objeto[2]; fila[2] = objeto[3]; fila[3] = objeto[4]; //Filtrar, mirar las fechas String[] partirEspacios = objeto[3].split("\\s"); //El primer string es la fecha sin hora //Ahora esparamos por - String[] tomarAgeMesDia = partirEspacios[0].split("-"); //Realizar filtro int ageConsulta = Integer.parseInt(tomarAgeMesDia[0]); int mesConsulta = Integer.parseInt(tomarAgeMesDia[1]); int diaConsulta = Integer.parseInt(tomarAgeMesDia[2]); //Obtenemos dias, mes y ao de la consulta //Inicial int anioInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.YEAR); int mesInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.MONTH) + 1; int diaInicial = clienteReporteClienteFechaFinal.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Final int anioFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.YEAR); int mesFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.MONTH) + 1; int diaFinal = clienteReporteClienteFechaInicial.getSelectedDate().get(Calendar.DAY_OF_MONTH); //Construir fechas Calendar fechaDeLaBD = new GregorianCalendar(ageConsulta, mesConsulta, diaConsulta); //Set year, month, day) Calendar fechaInicialRango = new GregorianCalendar(anioInicial, mesInicial, diaInicial); Calendar fechaFinalRango = new GregorianCalendar(anioFinal, mesFinal, diaFinal); if (fechaDeLaBD.compareTo(fechaInicialRango) <= 0 && fechaDeLaBD.compareTo(fechaFinalRango) >= 0) { fechasFlujos.add(fechaDeLaBD); modeloTabla.addRow(fila); } } if (modeloTabla.getRowCount() > 0) { tablaDialogo.setModel(modeloTabla); tablaDialogo.getColumn("Factura").setMinWidth(80); tablaDialogo.getColumn("Tipo Flujo").setMinWidth(80); tablaDialogo.getColumn("Fecha").setMinWidth(90); tablaDialogo.getColumn("Valor").setMinWidth(80); tablaDialogo.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane scroll = new JScrollPane(tablaDialogo); scroll.setPreferredSize(new Dimension(330, 150)); c.gridx = 0; c.gridy = 1; c.gridwidth = 1; c.insets = new Insets(0, 0, 0, 0); panelDialogo.add(scroll, c); TimeSeries localTimeSeries = new TimeSeries("Compras del cliente en el periodo"); Map listaAbonos = new HashMap(); for (int i = 0; i < modeloTabla.getRowCount(); i++) { listaIDFlujos.add(Integer.parseInt(flujosCliente.get(i)[0])); if (modeloTabla.getValueAt(i, 1).equals("abono")) { Calendar fechaFlujo = fechasFlujos.get(i); double valor = Double.parseDouble(String.valueOf(modeloTabla.getValueAt(i, 3))); int anoDato = fechaFlujo.get(Calendar.YEAR); int mesDato = fechaFlujo.get(Calendar.MONTH) + 1; int diaDato = fechaFlujo.get(Calendar.DAY_OF_MONTH); Day FechaDato = new Day(diaDato, mesDato, anoDato); if (listaAbonos.get(FechaDato) != null) { double valorAbono = (double) listaAbonos.get(FechaDato); listaAbonos.remove(FechaDato); listaAbonos.put(FechaDato, valorAbono + valor); } else { listaAbonos.put(FechaDato, valor); } } } Double maximo = 0.0; Iterator iterator = listaAbonos.keySet().iterator(); while (iterator.hasNext()) { Day key = (Day) iterator.next(); Double value = (double) listaAbonos.get(key); maximo = Math.max(maximo, value); localTimeSeries.add(key, value); } //localTimeSeries.add(); TimeSeriesCollection datos = new TimeSeriesCollection(localTimeSeries); JFreeChart chart = ChartFactory.createTimeSeriesChart("Compras del cliente en el periodo", // Title "Tiempo", // x-axis Label "Total ($)", // y-axis Label datos, // Dataset true, // Show Legend true, // Use tooltips false // Configure chart to generate URLs? ); /*Altering the graph */ XYPlot plot = (XYPlot) chart.getPlot(); plot.setAxisOffset(new RectangleInsets(5.0, 10.0, 10.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); NumberAxis numberAxis = (NumberAxis) plot.getRangeAxis(); numberAxis.setRange(new Range(0, maximo * 1.2)); Font font = new Font("Dialog", Font.PLAIN, 9); numberAxis.setTickLabelFont(font); numberAxis.setLabelFont(font); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("dd-MM-yyyy")); axis.setAutoTickUnitSelection(false); axis.setVerticalTickLabels(true); axis.setTickLabelFont(font); axis.setLabelFont(font); LegendTitle leyendaChart = chart.getLegend(); leyendaChart.setItemFont(font); Font fontTitulo = new Font("Dialog", Font.BOLD, 12); TextTitle tituloChart = chart.getTitle(); tituloChart.setFont(fontTitulo); ChartPanel CP = new ChartPanel(chart); Dimension D = new Dimension(330, 300); CP.setPreferredSize(D); CP.setVisible(true); c.gridx = 0; c.gridy = 2; c.gridwidth = 1; c.insets = new Insets(10, 0, 0, 0); panelDialogo.add(CP, c); c.gridx = 0; c.gridy = 3; c.gridwidth = 1; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(10, 30, 0, 0); JButton botonCerrar = new JButton("Cerrar"); botonCerrar.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dialogoEditar.dispose(); } }); panelDialogo.add(botonCerrar, c); JButton botonGenerarPDF = new JButton("Guardar archivo"); botonGenerarPDF.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.guardarDocumentoDialogo(dialogoEditar, listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 100, 0, 0); panelDialogo.add(botonGenerarPDF, c); JButton botonImprimir = new JButton("Imprimir"); botonImprimir.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ReporteFlujosCliente reporteFlujosCliente = new ReporteFlujosCliente(); reporteFlujosCliente.imprimirFlujo(listaIDFlujos, Integer.parseInt(jTextFieldIdentificacionClienteReporte.getText()), clienteReporteClienteFechaInicial.getSelectedDate(), clienteReporteClienteFechaFinal.getSelectedDate()); } }); c.insets = new Insets(10, 230, 0, 0); panelDialogo.add(botonImprimir, c); dialogoEditar.add(panelDialogo); dialogoEditar.setVisible(true); } else { JOptionPane.showMessageDialog(this, "El cliente no registra movimientos en el rango de fechas seleccionado"); } } } catch (Exception e) { JOptionPane.showMessageDialog(this, "Debe seleccionar un da inicial y final de fechas"); } }