Example usage for javax.swing.table DefaultTableModel DefaultTableModel

List of usage examples for javax.swing.table DefaultTableModel DefaultTableModel

Introduction

In this page you can find the example usage for javax.swing.table DefaultTableModel DefaultTableModel.

Prototype

public DefaultTableModel(Object[][] data, Object[] columnNames) 

Source Link

Document

Constructs a DefaultTableModel and initializes the table by passing data and columnNames to the setDataVector method.

Usage

From source file:com.emr.schemas.TableRelationsForm.java

/**
 * Constructor/*from   w ww . ja va2 s .c  o  m*/
 * @param tables {@link List} List of source tables
 */
public TableRelationsForm(List tables, SchemerMapper parent) {
    fileManager = null;
    dbManager = null;
    emrConn = null;
    this.parent = parent;
    this.tables = tables; //source tables

    //Create KenyaEMR DB connection
    fileManager = new FileManager();
    String[] settings = fileManager.getConnectionSettings("emr_database.properties", "emr");
    if (settings == null) {
        //Connection settings not found
        JOptionPane.showMessageDialog(null,
                "Database Settings not found. Please set the connection settings for the database first.",
                "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
        //Open KenyaEMRConnectionForm form
    } else {
        if (settings.length < 1) {
            JOptionPane.showMessageDialog(null,
                    "Database Settings not found. Please set the connection settings for the database first.",
                    "KenyaEMR Database settings", JOptionPane.ERROR_MESSAGE);
            //Open KenyaEMRConnectionForm form
        } else {
            //Connection settings are ok
            //We establish a connection
            dbManager = new DatabaseManager(settings[0], settings[1], settings[3], settings[4], settings[5]);
            emrConn = dbManager.getConnection();
            if (emrConn == null) {
                JOptionPane.showMessageDialog(null, "Test Connection Failed", "Connection Test",
                        JOptionPane.ERROR_MESSAGE);
            }
        }
    }

    //get all columns and add them to the columns list
    for (Object table : tables) {
        String tablename = (String) table;
        populateTableColumnsToList(tablename);
    }

    model = new DefaultTableModel(
            new Object[] { "Primary Table", "Column", "Reference Table", "Foreign Column" }, 10);

    initComponents();
    this.setClosable(true);
    foreignTables = tables;
    combo1 = new JComboBox();//Combobox for the primary tables
    combo2 = new JComboBox();
    combo3 = new JComboBox();
    combo4 = new JComboBox();
    combo1.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate primary table columns
                primaryColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo2_model = new DefaultComboBoxModel(
                        primaryColumns.toArray(new String[primaryColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo2_model);
                relationsTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(comboBox));

            }
        }
    });

    combo3.addItemListener(new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent event) {
            if (event.getStateChange() == ItemEvent.SELECTED) {
                String selectedTable = (String) event.getItem();
                //populate foreign table columns
                foreignColumns = getTableColumns(selectedTable);
                DefaultComboBoxModel combo3_model = new DefaultComboBoxModel(
                        foreignColumns.toArray(new String[foreignColumns.size()]));
                JComboBox comboBox = new JComboBox();
                comboBox.setModel(combo3_model);
                relationsTable.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(comboBox));
            }
        }
    });
    ComboBoxTableCellEditor primaryTableEditor = new ComboBoxTableCellEditor(tables, combo1);
    ComboBoxTableCellEditor primaryTableColumns = new ComboBoxTableCellEditor(primaryColumns, combo2);

    ComboBoxTableCellEditor foreignTableEditor = new ComboBoxTableCellEditor(foreignTables, combo3);//TODO: remove selected primary table from list

    ComboBoxTableCellEditor foreignTableColumns = new ComboBoxTableCellEditor(foreignColumns, combo4);
    relationsTable.getColumnModel().getColumn(0).setCellEditor(primaryTableEditor);
    relationsTable.getColumnModel().getColumn(1).setCellEditor(primaryTableColumns);
    relationsTable.getColumnModel().getColumn(2).setCellEditor(foreignTableEditor);
    relationsTable.getColumnModel().getColumn(3).setCellEditor(foreignTableColumns);

    columnsList.setCellRenderer(new CheckboxListCellRenderer());
    SourceTablesListener listSelectionListener = new SourceTablesListener(new JTextArea(), selected_columns);
    columnsList.addListSelectionListener(listSelectionListener);
    columnsList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    columnsList.setSelectionModel(new DefaultListSelectionModel() {
        @Override
        public void setSelectionInterval(int index0, int index1) {
            if (isSelectedIndex(index0))
                super.removeSelectionInterval(index0, index1);
            else
                super.addSelectionInterval(index0, index1);
        }
    });
}

From source file:gdt.jgui.tool.JEntityEditor.java

private void showElement(Sack entity, String element$) {
    try {//from w  ww  .j a v  a  2 s .c  o m
        //      System.out.println("EntityEditor:showElement:"+element$);
        Core[] ca = null;
        if ("attributes".equals(element$))
            ca = entity.attributesGet();
        else
            ca = entity.elementGet(element$);
        final JTable table = new JTable();
        DefaultTableModel model = new DefaultTableModel(null, new String[] { "type", "name", "value" });
        table.setModel(model);
        table.getTableHeader().setDefaultRenderer(new SimpleHeaderRenderer());
        table.getTableHeader().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                int col = table.columnAtPoint(e.getPoint());
                String name = table.getColumnName(col);
                //              System.out.println("Column index selected " + col + " " + name);
                sort(name);
            }
        });
        JScrollPane scrollPane = new JScrollPane();
        tabbedPane.add(element$, scrollPane);
        scrollPane.add(table);
        scrollPane.setViewportView(table);
        if (ca != null)
            for (Core aCa : ca) {
                model.addRow(new String[] { aCa.type, aCa.name, aCa.value });
            }
    } catch (Exception e) {
        LOGGER.severe(e.toString());
    }
}

From source file:edu.ucla.stat.SOCR.motionchart.MotionMouseListener.java

protected JPanel getItemPanel(final JDialog dialog, XYItemEntity item, ChartMouseEvent event) {
    MotionDataSet dataset = (MotionDataSet) event.getChart().getXYPlot().getDataset();
    MotionTableModel model = dataset.getTableModel();
    DefaultTableModel tModel = new DefaultTableModel(2, 0);
    ArrayList<String> rowIds = new ArrayList<String>();

    Integer row = model.getKeyMap().get(dataset.getSeriesKey(item.getSeriesIndex())).get(item.getItem());
    rowIds.add(row + ":");

    int columnCount = model.getColumnCount();

    for (int c = 0; c < columnCount; c++) {
        tModel.addColumn(model.getColumnName(c));
        tModel.setValueAt(model.getValueAt(row, c), 0, c);
    }//from   ww  w.j a v  a 2s.c o m

    rowIds.add("Mappings:");

    Object category = dataset.getCategory(item.getSeriesIndex(), item.getItem());
    if (category != null) {
        tModel.setValueAt(category, 1, model.getCategoryMapping());
    }

    Object key = dataset.getSeriesKey(item.getSeriesIndex());
    if (key != null) {
        tModel.setValueAt(key, 1, model.getKeyMapping());
    }

    Object x = dataset.getX(item.getSeriesIndex(), item.getItem());
    if (x != null) {
        tModel.setValueAt(x, 1, model.getXAxisMapping());
    }

    Object y = dataset.getY(item.getSeriesIndex(), item.getItem());
    if (y != null) {
        tModel.setValueAt(y, 1, model.getYAxisMapping());
    }

    Object size = dataset.getSize(item.getSeriesIndex(), item.getItem());
    if (size != null) {
        tModel.setValueAt(size, 1, model.getSizeMapping());
    }

    Color color = dataset.getColor(item.getSeriesIndex(), item.getItem());
    if (color != null) {
        //String colorText = "RGB(" + color.getRed() + "," + color.getGreen() + "," + color.getBlue() + ")";
        tModel.setValueAt(color, 1, model.getColorMapping());
    }

    return getPanel(dialog, tModel, rowIds);
}

From source file:simulation.AureoZauleckAnsLab2.java

/**
 *
 *//*  www.ja v  a2 s .c o  m*/
public AureoZauleckAnsLab2() {
    // TODO code application logic here
    Scanner sc = new Scanner(System.in);
    String choice_s = "";
    int choice = 0;

    do {
        DisplayMenu();
        choice_s = sc.next();
        String title = "";
        Scanner s = new Scanner(System.in);
        //test input
        if (IsNumber(choice_s)) {
            choice = Convert(choice_s);
        } else {
            do {
                System.out.println("Please enter a number only.");
                choice_s = sc.next();
            } while (!IsNumber(choice_s));
            choice = Convert(choice_s);
        }

        if (choice == 1) {
            System.out.println("*** CATEGORICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            //sc = new Scanner(System.in);               
            title = s.nextLine();
            System.out.println("this is the title:  " + title);

            ArrayList a = new ArrayList<>();
            ArrayList<Double> percentages = new ArrayList<>();
            ArrayList<ArrayList> all;
            a = GetData();

            Collections.sort(a);
            all = Stratified(a);
            System.out.println("GROUPED DATA:  " + all);
            System.out.println("size  " + all.size());

            double percent = 0.0, sum = 0.0;
            for (int i = 0; i < all.size(); i++) {

                ArrayList inner = new ArrayList<>();
                inner = all.get(i);
                //System.out.println(inner);

                int inner_n = inner.size();
                percent = GetPercentage(N, inner_n);
                percentages.add(percent);
                sum += percent;
                System.out.println("" + inner.get(0) + "\t" + "        " + percent);
            }
            System.out.println("\t" + "total   " + Math.ceil(sum));
            System.out.println("all = " + all);

            JFrame frame = new JFrame();
            //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);                        
            JTable table = new JTable();
            table.setModel(new DefaultTableModel((int) (all.size() + 2), 2));

            table.setValueAt("VALUE LABELS", 0, 0);
            table.setValueAt("PERCENTAGE", 0, 1);

            table.setValueAt("TOTAL = 100%", (int) (all.size() + 1), 1);

            for (int i = 0; i < all.size(); i++) {
                table.setValueAt(all.get(i).get(0), i + 1, 0);

                table.setValueAt(new DecimalFormat("#.##").format(percentages.get(i)), i + 1, 1);

            }

            JScrollPane scrollPane = new JScrollPane(table);
            scrollPane.setBorder(BorderFactory.createTitledBorder(title));
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setSize(300, 150);
            frame.setVisible(true);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                System.out.println("GENERATE GRAPH?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");

                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest = sc.next();

                if (IsNumber(typeTest)) {
                    testT = Convert(typeTest);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest = sc.next();
                    } while (!IsNumber(typeTest));

                    testT = Convert(typeTest);
                }
                type = testT;
            } while (type < 1 || type > 2);

            if (type == 1) {
                DefaultPieDataset dataset = new DefaultPieDataset();
                for (int i = 0; i < all.size(); i++) {
                    dataset.setValue(
                            all.get(i).get(0).toString() + " = "
                                    + new DecimalFormat("#.##").format(percentages.get(i)) + "%",
                            percentages.get(i));
                }
                JFreeChart chart = ChartFactory.createPieChart(title, // chart title 
                        dataset, // data    
                        true, // include legend   
                        true, false);
                ChartPanel chartPanel = new ChartPanel(chart);
                chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
                JFrame l = new JFrame();

                l.setContentPane(chartPanel);
                l.setSize(400, 400);
                l.setVisible(true);

            } else {
                //do nothing?
            }

            int type2 = 0, testT2 = 0;
            String typeTest2 = "";
            do {
                System.out.println("REDISPLAY TABLE?");
                System.out.println("[1] YES");
                System.out.println("[2] NO");
                System.out.println();
                System.out.println("Please pick a number from the choices above.");

                typeTest2 = sc.next();

                if (IsNumber(typeTest2)) {
                    testT2 = Convert(typeTest2);
                } else {
                    do {
                        System.out.println("Please enter a number only.");
                        typeTest2 = sc.next();
                    } while (!IsNumber(typeTest2));

                    testT2 = Convert(typeTest2);
                }
                type2 = testT2;
            } while (type2 < 1 || type2 > 2);

            if (type2 == 1) {
                DisplayTable(all, percentages, title);
            } else {
                //do nothing?
            }

        } else if (choice == 2) {

            System.out.println("*** NUMERICAL ***");
            System.out.println();
            System.out.println("TITLE(title of data set)");
            title = s.nextLine();

            System.out.println("this is the title  " + title);

            ArrayList<Double> a = new ArrayList<>();
            //ArrayList<ArrayList> all; 
            //a = GetData2();

            double[] arr = { 70, 36, 43, 69, 82, 48, 34, 62, 35, 15, 59, 139, 46, 37, 42, 30, 55, 56, 36, 82,
                    38, 89, 54, 25, 35, 24, 22, 9, 55, 19 };

            /*    
                double[] arr = {112, 100, 127,120,134,118,105,110,109,112,
                110, 118, 117, 116, 118, 122, 114, 114, 105, 109,
                107, 112, 114, 115, 118, 117, 118, 122, 106, 110,
                116, 108, 110, 121, 113, 120, 119, 111, 104, 111,
                120, 113, 120, 117, 105, 110, 118, 112, 114, 114};
             */
            N = arr.length;
            double t = 0.0;
            for (int i = 0; i < N; i++) {
                a.add(arr[i]);
            }

            Collections.sort(a);
            System.out.println("sorted a " + a);
            double min = (double) a.get(0);
            double max = (double) a.get(N - 1);

            System.out.println("Min" + min);
            System.out.println("Max" + max);

            double k = Math.ceil(1 + 3.322 * Math.log10(N));
            System.out.println("K " + k);

            double range = GetRange(min, max);
            System.out.println("Range " + range);

            double width = Math.ceil(range / k);
            //todo, i ceiling sa 1st decimal point
            System.out.println("Width " + width);

            ArrayList<Double> cl = new ArrayList<>();
            cl.add(min);
            double rest;
            for (int i = 1; i < k; i++) {
                cl.add(min += width);
            }

            ArrayList<Double> cl2 = new ArrayList<>();
            double cl2min = cl.get(1) - 1;
            cl2.add(cl2min);
            for (int i = 1; i < k; i++) {
                cl2.add(cl2min += width);
            }

            System.out.println("cl 1 " + cl);
            System.out.println("cl 2 " + cl2);

            ArrayList<Double> tlcl = new ArrayList<>();
            double tlclmin = cl.get(0) - Multiplier(cl.get(0));
            tlcl.add(tlclmin);
            for (int i = 1; i < k; i++) {
                tlcl.add(tlclmin += width);
            }

            ArrayList<Double> tucl = new ArrayList<>();
            double tuclmin = cl2.get(0) + Multiplier(cl2.get(0));
            tucl.add(tuclmin);
            for (int i = 1; i < k; i++) {
                tucl.add(tuclmin += width);
            }
            System.out.println("tlcl 1 " + tlcl);
            System.out.println("tucl 2 " + tucl);
            System.out.println("N " + N);

            ArrayList<Double> midList = new ArrayList<>();
            double mid = (cl.get(0) + cl2.get(0)) / 2;
            midList.add(mid);
            for (int i = 1; i < k; i++) {
                midList.add((tlcl.get(i) + tucl.get(i)) / 2);
            }

            for (int i = 0; i < k; i++) {
                System.out.println((tlcl.get(i) + tucl.get(i)) / 2);
            }

            System.out.println("mid" + midList);

            ArrayList<ArrayList<Double>> freq = new ArrayList<>();

            double ctr = 0.0;
            for (int j = 0; j < k; j++) {
                for (int i = 0; i < N; i++) {
                    if ((a.get(i) >= tlcl.get(j)) && (a.get(i) <= tucl.get(j))) {
                        freq.add(new ArrayList<Double>());
                        freq.get(j).add(a.get(i));
                    }
                }
            }

            ArrayList<Double> freqSize = new ArrayList<>();
            double size = 0.0;
            for (int i = 0; i < k; i++) {
                size = (double) freq.get(i).size();
                freqSize.add(size);
            }

            ArrayList<Double> freqPercent = new ArrayList<>();
            for (int i = 0; i < k; i++) {

                freqPercent.add(freqSize.get(i) / N * 100);
            }

            ArrayList<Double> cfs = new ArrayList<>();
            double cf = freqSize.get(0);
            cfs.add(cf);
            for (int i = 1; i < k; i++) {
                cf = freqSize.get(i) + cfs.get(i - 1);
                cfs.add(cf);
            }

            double sum = 0.0;
            for (int i = 1; i < cfs.size(); i++) {
                sum += cfs.get(i);
            }

            ArrayList<Double> cps = new ArrayList<>();
            double cp = 0.0;
            for (int i = 0; i < k; i++) {
                cp = (cfs.get(i) / N) * 100;
                cps.add(cp);
            }

            System.out.println("T o t a l: " + sum);
            System.out.println(cfs);
            System.out.println(cps);

            System.out.println("frequency list " + freq);

            System.out.println("frequency sizes " + freqSize);
            System.out.println("frequency percentages " + freqPercent);

            System.out.println();
            System.out.println(title);

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(cl.get(i) + " - " + cl2.get(i) + "\t" + tlcl.get(i) + " - " + tucl.get(i)
                        + "\t" + midList.get(i) + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //2
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }
            //3
            System.out.println("CLASS LIMITS" + "\t" + "T C L" + "\t" + "MID" + "\t" + "FREQ" + "\t" + "PERCENT"
                    + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println("<=" + cl2.get(i) + "\t\t" + " - " + "\t" + " - " + "\t" + freq.get(i).size()
                        + "\t" + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            System.out.println("CLASS LIMITS" + "\t" + "T CLASS LIMITS" + "\t" + "MID" + "\t" + "FREQ" + "\t"
                    + "PERCENT" + "\t" + "CF" + "\t" + "CP");
            for (int i = 0; i < k; i++) {
                System.out.println(">=" + cl.get(i) + " and <=" + cl2.get(i) + "\t" + " - " + "\t" + " - "
                        + "\t" + freq.get(i).size() + "\t"
                        + new DecimalFormat("#.##").format(freqPercent.get(i)) + "\t" + cfs.get(i) + "\t"
                        + new DecimalFormat("#.##").format(cps.get(i)));
            }

            DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);

            int type = 0, testT = 0;
            String typeTest = "";
            do {
                do {

                    System.out.println();
                    System.out.println("GENERATE GRAPH?");
                    System.out.println("[1] YES");
                    System.out.println("[2] NO");
                    System.out.println();
                    System.out.println("Please pick a number from the choices above.");

                    typeTest = sc.next();

                    if (IsNumber(typeTest)) {
                        testT = Convert(typeTest);
                    } else {
                        do {
                            System.out.println("Please enter a number only.");
                            typeTest = sc.next();
                        } while (!IsNumber(typeTest));

                        testT = Convert(typeTest);
                    }
                    type = testT;
                } while (type < 1 || type > 2);

                if (type == 1) {
                    int bins = (int) k;
                    System.out.println();
                    System.out.println("You may input a label for your X axis:");
                    String x = "";
                    x = s.nextLine();
                    createHistogram(a, bins, title, x);

                    int type2 = 0, testT2 = 0;
                    String typeTest2 = "";
                    do {
                        System.out.println();
                        System.out.println("REDISPLAY TABLE?");
                        System.out.println("[1] YES");
                        System.out.println("[2] NO");
                        System.out.println();
                        System.out.println("Please pick a number from the choices above.");

                        typeTest2 = sc.next();

                        if (IsNumber(typeTest2)) {
                            testT2 = Convert(typeTest2);
                        } else {
                            do {
                                System.out.println("Please enter a number only.");
                                typeTest2 = sc.next();
                            } while (!IsNumber(typeTest2));

                            testT2 = Convert(typeTest2);
                        }
                        type2 = testT2;
                    } while ((type2 < 1 || type2 > 2) && type != 2);

                    if (type2 == 1) {

                        DisplayTables(k, cl, cl2, tlcl, tucl, midList, freq, freqPercent, cfs, cps, title);
                    } else {
                        //do nothing?
                    }
                }
            } while (type != 2);

        } else if (choice == 3) {
            System.out.println("*** QUIT ***");
        }

    } while (choice != 3);

    System.out.println("Thank you for your time.");
    s = new Simulation();

}

From source file:com.mirth.connect.client.ui.browsers.message.MessageBrowserAdvancedFilter.java

private void initContentSearchTable() {
    contentSearchTable//  w ww  .  j av a  2 s.c o m
            .setModel(new DefaultTableModel(new Object[][] {}, new String[] { "Content Type", "Contains" }) {
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return true;
                }
            });

    contentSearchTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    contentSearchTable.setDragEnabled(false);
    contentSearchTable.setSortable(false);
    contentSearchTable.getTableHeader().setReorderingAllowed(false);

    contentSearchTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            deleteContentSearchButton.setEnabled(getSelectedRow(contentSearchTable) != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        contentSearchTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    TableColumn column = contentSearchTable.getColumnModel().getColumn(0);
    column.setCellRenderer(new MirthComboBoxTableCellRenderer(ContentType.getDisplayValues()));
    column.setCellEditor(new MirthComboBoxTableCellEditor(contentSearchTable, ContentType.getDisplayValues(), 1,
            false, null));
    column.setMinWidth(CONTENT_TYPE_COLUMN_WIDTH);
    column.setMaxWidth(CONTENT_TYPE_COLUMN_WIDTH);

    deleteContentSearchButton.setEnabled(false);
}

From source file:pl.piotrsukiennik.jbrain.gui.ModelPanel.java

protected TableModel convert2Model(ConnectionsDTO connectionsDTO) {
    String[] layers = connectionsDTO.getLayers();
    double[][] connections = connectionsDTO.getConnections();
    DefaultTableModel tableModel = new DefaultTableModel(layers.length, layers.length + 1);
    for (int i = 0; i < layers.length; i++) {
        tableModel.setValueAt(layers[i], i, 0);
    }//  w  w  w. j  av  a2 s .co  m
    for (int i = 0; i < connections.length; i++) {
        for (int j = 0; j < connections.length; j++) {
            double connection = connections[i][j];
            if (connection != 0) {
                tableModel.setValueAt(connections[i][j], i, j + 1);
            }
        }
    }
    List<String> labels = new ArrayList<String>();
    labels.add("");
    labels.addAll(Arrays.asList(connectionsDTO.getLayers()));
    tableModel.setColumnIdentifiers(labels.toArray());
    return tableModel;
}

From source file:instance.gui.InstanceGUI.java

private void createSnapshotTable() {
    snapshotModel = new DefaultTableModel(new String[][] {}, snapshotTableColumns);
    snapshotTable = new JTable(snapshotModel) {
        private static final long serialVersionUID = 6454534842446167244L;

        public boolean isCellEditable(int rowIndex, int colIndex) {
            return false;
        }/* ww  w  . j  a  va2s  . co  m*/
    };

    snapshotTable.addMouseListener(snapshotPopupListener);
    snapshotTable.getColumnModel().getColumn(0).setPreferredWidth(20);
    JScrollPane pane = new JScrollPane(snapshotTable);
    snapshotSection.add(pane);
}

From source file:com.mirth.connect.client.ui.attachments.RegexAttachmentDialog.java

private void initInboundReplacementTable() {
    inboundReplacementTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    DefaultTableModel model = new DefaultTableModel(new Object[][] {},
            new String[] { "Replace All", "Replace With" }) {
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }//w  ww.  j  av a  2 s.  c  om
    };

    inboundReplacementTable.setSortable(false);
    inboundReplacementTable.getTableHeader().setReorderingAllowed(false);
    inboundReplacementTable.setModel(model);

    inboundReplacementTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            inboundDeleteButton.setEnabled(inboundReplacementTable.getSelectedRow() != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        inboundReplacementTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    inboundDeleteButton.setEnabled(false);
}

From source file:com.vgi.mafscaling.OpenLoop.java

private void createRunTables(JPanel dataRunPanel) {
    GridBagConstraints gbc_run = new GridBagConstraints();
    gbc_run.anchor = GridBagConstraints.PAGE_START;
    gbc_run.insets = new Insets(0, 2, 0, 2);
    for (int i = 0; i < RunCount; ++i) {
        runTables[i] = new JTable();
        JTable table = runTables[i];
        table.getTableHeader().setReorderingAllowed(false);
        table.setModel(new DefaultTableModel(RunRowsCount, 3));
        table.setColumnSelectionAllowed(true);
        table.setCellSelectionEnabled(true);
        table.setBorder(new LineBorder(new Color(0, 0, 0)));
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        table.getColumnModel().getColumn(0)
                .setHeaderValue("<html><center>Engine<br>Speed<br>(RPM)<br></center></html>");
        table.getColumnModel().getColumn(1)
                .setHeaderValue("<html><center>MAF<br>Sensor<br>Voltage<br></center></html>");
        table.getColumnModel().getColumn(2)
                .setHeaderValue("<html><center>AFR<br>Error<br>%<br></center></html>");
        Utils.initializeTable(table, ColumnWidth);
        excelAdapter.addTable(table, true, false);

        gbc_run.gridx = i;//from ww  w .  j  a v  a 2  s  .  co m
        gbc_run.gridy = 0;
        dataRunPanel.add(table.getTableHeader(), gbc_run);
        gbc_run.gridy = 1;
        dataRunPanel.add(table, gbc_run);
    }
}

From source file:com.mirth.connect.client.ui.RegexAttachmentDialog.java

private void initOutboundReplacementTable() {
    DefaultTableModel model = new DefaultTableModel(new Object[][] {},
            new String[] { "Replace All", "Replace With" }) {
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
        }/*from w  ww .j a v  a  2s .com*/

        @Override
        public void setValueAt(Object value, int row, int column) {
            if (!value.equals(getValueAt(row, column))) {
                parent.setSaveEnabled(true);
            }

            super.setValueAt(value, row, column);
        }
    };

    outboundReplacementTable.setSortable(false);
    outboundReplacementTable.getTableHeader().setReorderingAllowed(false);
    outboundReplacementTable.setModel(model);

    outboundReplacementTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent evt) {
            outboundDeleteButton.setEnabled(outboundReplacementTable.getSelectedRow() != -1);
        }
    });

    if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) {
        outboundReplacementTable.setHighlighters(HighlighterFactory
                .createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR));
    }

    outboundDeleteButton.setEnabled(false);
}