Example usage for javax.swing JTable getRowCount

List of usage examples for javax.swing JTable getRowCount

Introduction

In this page you can find the example usage for javax.swing JTable getRowCount.

Prototype

@BeanProperty(bound = false)
public int getRowCount() 

Source Link

Document

Returns the number of rows that can be shown in the JTable, given unlimited space.

Usage

From source file:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java

public void resetExample() {

    XYDataset dataset = createDataset(true);
    // System.out.println("resetExample num_series="+num_series);
    XYDataset[] ds1 = new XYDataset[num_series];
    ds1[0] = dataset;//from w w  w  .j  a  v a 2s  .  c o  m

    kernels = null;
    chart = createChart(ds1);
    refreshChartPanel();
    setChart();

    hasExample = true;
    //      convertor.dataset2Table((TimeSeriesCollection)dataset);            
    convertor.dataset2Table(dataset);
    JTable tempDataTable = convertor.getTable();

    resetTableRows(tempDataTable.getRowCount() + 1);
    resetTableColumns(tempDataTable.getColumnCount());

    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }

    columnModel = dataTable.getColumnModel();
    dataTable.setTableHeader(new EditableHeader(columnModel));

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }
    dataPanel.removeAll();
    dataPanel.add(new JScrollPane(dataTable));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);
    dataTable.doLayout();
    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();

    // do the mapping
    int columnCount = dataTable.getColumnCount();
    for (int i = 0; i < columnCount / 2; i++) {
        //System.out.println("mapping");
        addButtonIndependent();
        addButtonDependent();

    }

    getMapping();
    //   System.out.println("resetExample get called indepvar"+independentVarLength );
    updateStatus(url);
}

From source file:fll.subjective.SubjectiveFrame.java

/**
 * Set the tab and return behavior for a table.
 *///from   ww w  .j  a va2 s  .c  o  m
private void setupTabReturnBehavior(final JTable table) {
    final InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    // Have the enter key work the same as the tab key
    final KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
    final KeyStroke enter = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
    im.put(enter, im.get(tab));

    // Override the default tab behavior
    // Tab to the next editable cell. When no editable cells goto next cell.
    final Action oldTabAction = table.getActionMap().get(im.get(tab));
    final Action tabAction = new AbstractAction() {
        public void actionPerformed(final ActionEvent e) {
            if (null != oldTabAction) {
                oldTabAction.actionPerformed(e);
            }

            final JTable table = (JTable) e.getSource();
            final int rowCount = table.getRowCount();
            final int columnCount = table.getColumnCount();
            int row = table.getSelectedRow();
            int column = table.getSelectedColumn();

            // skip the no show when tabbing
            while (!table.isCellEditable(row, column) || table.getColumnClass(column) == Boolean.class) {
                column += 1;

                if (column == columnCount) {
                    column = 0;
                    row += 1;
                }

                if (row == rowCount) {
                    row = 0;
                }

                // Back to where we started, get out.
                if (row == table.getSelectedRow() && column == table.getSelectedColumn()) {
                    break;
                }
            }

            table.changeSelection(row, column, false, false);
        }
    };
    table.getActionMap().put(im.get(tab), tabAction);
}

From source file:modnlp.capte.AlignmentInterfaceWS.java

public JTable autoResizeColWidth(JTable table, DefaultTableModel model) {
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setModel(model);// w  w  w  .  j  a  v a  2s.  co m

    int margin = 5;

    for (int i = 0; i < table.getColumnCount(); i++) {
        int vColIndex = i;
        DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();
        TableColumn col = colModel.getColumn(vColIndex);
        int width = 0;

        // Get width of column header
        TableCellRenderer renderer = col.getHeaderRenderer();

        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
        }

        Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0,
                0);

        width = comp.getPreferredSize().width;

        // Get maximum width of column data
        for (int r = 0; r < table.getRowCount(); r++) {
            renderer = table.getCellRenderer(r, vColIndex);
            comp = renderer.getTableCellRendererComponent(table, table.getValueAt(r, vColIndex), false, false,
                    r, vColIndex);
            width = Math.max(width, comp.getPreferredSize().width);
        }

        // Add margin
        width += 2 * margin;

        // Set the width
        col.setPreferredWidth(width);
    }

    ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer())
            .setHorizontalAlignment(SwingConstants.LEFT);

    // table.setAutoCreateRowSorter(true);
    table.getTableHeader().setReorderingAllowed(false);

    return table;
}

From source file:com.smanempat.controller.ControllerEvaluation.java

private double[][] evaluationModel(JTable tableResult, JTable tableConfMatrix, JLabel totalAccuracy,
        JTable tableTahunTesting, JTable tableDataSetTesting, String[] knnValue, int nilaiK, JPanel panelChart)
        throws SQLException {
    int actIPA = 0;
    int actIPS = 0;
    int trueIPA = 0;
    int falseIPA = 0;
    int trueIPS = 0;
    int falseIPS = 0;
    int classIPA = 0;
    int classIPS = 0;

    double recIPA;
    double recIPS;
    double preIPA;
    double preIPS;
    double accuracy;

    DefaultTableModel tableModelConf = (DefaultTableModel) tableConfMatrix.getModel();
    DefaultTableModel tableModelRes = (DefaultTableModel) tableResult.getModel();
    String[] tempJurusan = getJurusanTest(tableTahunTesting, tableDataSetTesting);

    if (tableModelRes.getRowCount() != 0) {
        tableModelRes.setRowCount(0);/*from  w  ww  .j  a v a 2  s .c  o m*/
    }

    for (int j = 0; j < tableDataSetTesting.getRowCount(); j++) {
        String nis = tableDataSetTesting.getValueAt(j, 0).toString();
        String jurusan = tempJurusan[j];
        String classified = knnValue[j];
        Object[] tableContent = { nis, jurusan, classified };
        tableModelRes.addRow(tableContent);
        tableResult.setModel(tableModelRes);
    }

    /*Hitung Jumlah Data Actual IPA dan IPS*/
    for (int j = 0; j < tempJurusan.length; j++) {
        if (tempJurusan[j].equals("IPA")) {
            actIPA = actIPA + 1;
        } else if (tempJurusan[j].equals("IPS")) {
            actIPS = actIPS + 1;
        }
    }

    /*Hitung Jumlah Data Classified IPA dan IPS*/
    for (int j = 0; j < knnValue.length; j++) {
        if (tableResult.getValueAt(j, 1).equals("IPA")) {
            if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) {
                trueIPA = trueIPA + 1;
            } else {
                falseIPS = falseIPS + 1;
            }
        } else if (tableResult.getValueAt(j, 1).equals("IPS")) {
            if (tableResult.getValueAt(j, 1).equals(tableResult.getValueAt(j, 2))) {
                trueIPS = trueIPS + 1;
            } else {
                falseIPA = falseIPA + 1;
            }
        }
    }
    //        System.out.println("trueIPA =" + trueIPA);
    //        System.out.println("falseIPA =" + falseIPA);
    //        System.out.println("falseIPS =" + falseIPS);
    //        System.out.println("trueIPS =" + trueIPS);

    /*Hitung Nilai Recall, Precision, dan Accuracy*/
    preIPA = (double) trueIPA / (trueIPA + falseIPA);
    preIPS = (double) trueIPS / (trueIPS + falseIPS);
    recIPA = (double) trueIPA / (trueIPA + falseIPS);
    recIPS = (double) trueIPS / (trueIPS + falseIPA);
    accuracy = (double) (trueIPA + trueIPS) / (trueIPA + trueIPS + falseIPA + falseIPS);

    /*Tampung Nilai Recall, Precision, dan Accuracy*/
    double[][] tempEval = new double[3][1];
    tempEval[0][0] = accuracy;
    tempEval[1][0] = recIPA;
    tempEval[2][0] = preIPA;

    /*Set Nilai TF, TN, FP, FN ke Tabel Confusion Matrix*/
    tableModelConf.setValueAt("Actual IPA", 0, 0);
    tableModelConf.setValueAt("Actual IPS", 1, 0);
    tableModelConf.setValueAt("Class Precision", 2, 0);
    tableModelConf.setValueAt(trueIPA, 0, 1);
    tableModelConf.setValueAt(falseIPS, 0, 2);
    tableModelConf.setValueAt(falseIPA, 1, 1);
    tableModelConf.setValueAt(trueIPS, 1, 2);

    /*Set Nilai Recall, Precision, dan Accuracy ke Tabel Confusion Matrix*/
    if (Double.isNaN(preIPA)) {
        tableModelConf.setValueAt("NaN" + " %", 2, 1);
    } else {
        tableModelConf.setValueAt(df.format(preIPA * 100) + " %", 2, 1);
    }
    if (Double.isNaN(preIPS)) {
        tableModelConf.setValueAt("NaN" + " %", 2, 2);
    } else {
        tableModelConf.setValueAt(df.format(preIPS * 100) + " %", 2, 2);
    }
    if (Double.isNaN(recIPA)) {
        tableModelConf.setValueAt("NaN" + " %", 0, 3);
    } else {
        tableModelConf.setValueAt(df.format(recIPA * 100) + " %", 0, 3);
    }
    if (Double.isNaN(recIPS)) {
        tableModelConf.setValueAt("NaN" + " %", 1, 3);
    } else {
        tableModelConf.setValueAt(df.format(recIPS * 100) + " %", 1, 3);
    }
    if (Double.isNaN(accuracy)) {
        totalAccuracy.setText("Overall Accuracy is " + "NaN" + " %");
    } else {
        totalAccuracy.setText("Overall Accuracy is " + df.format(accuracy * 100) + " %");
    }
    //        System.out.println("Recall IPA = " + recIPA);
    //        System.out.println("Recall IPA =" + recIPS);
    //        System.out.println("Precision IPA  = " + preIPA);
    //        System.out.println("Precision IPS  = " + preIPS);
    //        System.out.println("Overall Accuracy  = " + accuracy);
    return tempEval;
}

From source file:com.mirth.connect.connectors.http.HttpSender.java

private Map<String, List<String>> getProperties(JTable table) {
    Map<String, List<String>> properties = new LinkedHashMap<String, List<String>>();

    for (int i = 0; i < table.getRowCount(); i++) {
        String key = (String) table.getValueAt(i, NAME_COLUMN);

        List<String> propertiesList = properties.get(key);

        if (propertiesList == null) {
            propertiesList = new ArrayList<String>();
            properties.put(key, propertiesList);
        }/*from w w  w.ja va 2  s.co  m*/

        propertiesList.add((String) table.getValueAt(i, VALUE_COLUMN));
    }

    return properties;
}

From source file:de.mendelson.comm.as2.client.AS2Gui.java

/**
 * Scrolls to an entry of the passed table
 *
 * @param table Table to to scroll in//from  ww w . j  a v  a  2s.  c  o  m
 * @param row Row to ensure visibility
 */
private void makeRowVisible(JTable table, int row) {
    if (table.getColumnCount() == 0) {
        return;
    }
    if (row < 0 || row >= table.getRowCount()) {
        throw new IllegalArgumentException("Requested ensure visible of row " + String.valueOf(row)
                + ", table has only " + table.getRowCount() + " rows.");
    }
    Rectangle visible = table.getVisibleRect();
    Rectangle cell = table.getCellRect(row, 0, true);
    if (cell.y < visible.y) {
        visible.y = cell.y;
        table.scrollRectToVisible(visible);
    } else if (cell.y + cell.height > visible.y + visible.height) {
        visible.y = cell.y + cell.height - visible.height;
        table.scrollRectToVisible(visible);
    }
}

From source file:frameworks.Masken.java

public boolean maskenInstall(JTable table, JTextArea jTLog, EDPSession session, String LinuxUser,
        String LinuxPass, String Host) {
    try {//from   w w w  . ja  va 2  s. com
        ByteArrayOutputStream error = new ByteArrayOutputStream();
        StringBuilder fromServer = new StringBuilder();
        StringBuilder screenls = new StringBuilder();
        StringBuilder screenlsstring = new StringBuilder();
        String maskennummer;
        String fromServerString = "";
        String[] fromServerArray;
        String resourcesServerString = "";
        String[] resourcesServerArray;
        ArrayList datei = new ArrayList();
        String prio = "";
        String xmlziel = "";
        String resourcesziel = "";
        int masksearch = 0;
        int sshexitstatus = 0;
        File file = null;
        int zielzeile = 0;
        String tabellekopf = "";
        boolean failure = false;
        int firstcell = 0;
        int lastcell = 0;
        boolean newpanenotebook = true;

        //SSh Verbindung zum Mandanten ffnen
        SshClient sshclient = new SshClient();
        sshclient.connect(LinuxUser, LinuxPass, Host, 22);

        jTLog.append("----------Maskenimport----------\n");

        jTLog.append("Vorhandene Masken aus Mandanten ermittelt\n");
        jTLog.paint(jTLog.getGraphics());
        //Dateinamen erzeugen
        for (int i = 0; i < table.getRowCount(); i++) {
            //Fehlerflag auf true setzen
            failure = true;
            xmlziel = table.getValueAt(i, 2).toString().replace(table.getValueAt(i, 0).toString(),
                    table.getValueAt(i, 1).toString());
            xmlziel = table.getValueAt(i, 2).toString();
            resourcesziel = table.getValueAt(i, 3).toString().replace(table.getValueAt(i, 0).toString(),
                    table.getValueAt(i, 1).toString());
            maskennummer = table.getValueAt(i, 1).toString();

            // hab ich eine ZD und ein Masken TGZ?      
            if (table.getValueAt(i, 3).equals("TGZ")) {
                xmlziel = table.getValueAt(i, 2).toString();
                prio = xmlziel.substring(xmlziel.indexOf(".") + 1, xmlziel.lastIndexOf("."));
                prio = prio.substring(prio.indexOf(".") + 1, prio.length());
                // Dann kann ich die Maske einfach auf den Serverv kopieren
                file = new File(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 2).toString());
                sshexitstatus = sshclient.sendfile(file.toString(), xmlziel);
                jTLog.append("Neue Maske " + maskennummer + prio + " wird hochgeladen\n");
                jTLog.paint(jTLog.getGraphics());
                // und importieren
                jTLog.append("Neue Maske " + maskennummer + prio + " wird im Mandanten importiert\n");
                jTLog.paint(jTLog.getGraphics());
                sshexitstatus = sshclient.sendcommand(
                        "eval `sh denv.sh`;screen_import.sh -n " + maskennummer + " -p " + prio + " " + xmlziel,
                        error, fromServer);

                // und generieren
                jTLog.append("Neue Maske " + maskennummer + prio + " wird generiert\n");
                jTLog.paint(jTLog.getGraphics());
                // Maske generieren
                maskegenerieren(session, maskennummer, prio);

                jTLog.append(error.toString());
                jTLog.paint(jTLog.getGraphics());
                // Kein ZD und kein TGZ File, also muss die Maske integriert werden
            } else {
                datei.clear();
                prio = xmlziel.substring(xmlziel.indexOf(".") + 1, xmlziel.lastIndexOf("."));
                prio = prio.substring(prio.indexOf(".") + 1, prio.indexOf("-"));
                //Tabelle oder Kopf
                tabellekopf = xmlziel.substring(xmlziel.lastIndexOf(".") - 1, xmlziel.lastIndexOf("."));
                if (tabellekopf.equals("Z")) {
                    tabellekopf = "_T.xml";
                } else {
                    tabellekopf = "_M.xml";
                }
                // Maske individualisieren falls notwendig
                individuelleMaskePruefen(session, maskennummer, prio, jTLog);
                // Maske sichern mit screen_export
                jTLog.append(
                        "Maske " + maskennummer + " " + prio + " wird gesichert und kann mit screen_import -n "
                                + maskennummer + " -p " + prio + " screen_restauriert werden\n");
                jTLog.paint(jTLog.getGraphics());
                sshexitstatus = sshclient.sendcommand(
                        "eval `sh denv.sh`;screen_export.sh -n " + maskennummer + " -p " + prio, error,
                        fromServer);

                //Tmp leeren
                File tmpdir = new File("tmp");
                if (tmpdir.exists() && (tmpdir.isDirectory())) {
                    deleteDir(tmpdir);

                }
                new File("tmp").mkdir();

                // Masken.tgz abholen
                jTLog.append("Maske " + maskennummer + " " + prio + " wird geladen\n");
                jTLog.paint(jTLog.getGraphics());
                String servermaske = "./screen." + maskennummer + "." + prio + ".tgz";

                sshexitstatus = sshclient.getfile(servermaske, "tmp\\");
                if (sshexitstatus == -1) {// Maske wurde erfolgreich geladen

                    //Maske einlesen
                    jTLog.append("Maske " + maskennummer + " " + prio + " wird ausgepackt\n");
                    jTLog.paint(jTLog.getGraphics());
                    //tgz lokal auspacken
                    uncompressTarGZ(new File("tmp\\screen." + maskennummer + "." + prio + ".tgz"),
                            new File("tmp\\"));
                    // tgz lschen
                    new File("tmp\\screen." + maskennummer + "." + prio + ".tgz").delete();
                    String changemaske = "screen_" + maskennummer + "_" + prio + tabellekopf;
                    //Maske einlesen
                    jTLog.append("Maske " + maskennummer + " " + prio + " wird erweitert\n");
                    jTLog.paint(jTLog.getGraphics());
                    BufferedReader inservermaske = null;
                    inservermaske = new BufferedReader(new FileReader("tmp\\screens\\screen_" + maskennummer
                            + "\\" + prio + "\\screen_" + maskennummer + "_" + prio + tabellekopf));
                    BufferedReader inmaske = null;
                    inmaske = new BufferedReader(
                            new FileReader(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 2).toString()));
                    PrintWriter outservermaske = new PrintWriter(
                            new BufferedWriter(new FileWriter("tmp\\screens\\screen_" + maskennummer + "\\"
                                    + prio + "\\Xscreen_" + maskennummer + "_" + prio + tabellekopf)));
                    int lineNr = 0;
                    zielzeile = 0;
                    firstcell = 0;
                    lastcell = 0;
                    String line = inservermaske.readLine();
                    while (line != null) {

                        datei.add(line);
                        if (line.contains("<cell") && (firstcell == 0))
                            firstcell = lineNr;
                        if (line.contains("</layout.grid") && (firstcell != 0))
                            lastcell = lineNr;
                        if (line.contains("</pane.notebook>")) {
                            zielzeile = lineNr;
                            newpanenotebook = false;
                        }
                        lineNr++;

                        line = inservermaske.readLine();
                    }
                    inservermaske.close();

                    // Raus schreiben der Datei
                    for (int izeilen = 0; izeilen < lineNr - 1; izeilen++) {
                        outservermaske.print(datei.get(izeilen) + "\n");
                        if ((zielzeile == 0) && (firstcell == izeilen)) {
                            outservermaske.print(
                                    "<layout.notebook>\n<pane.notebook msgId=\"b825893d-f00a-4500-ae24-c2fe5364ae0e\">\n <layout.grid>\n"
                                            + "      <cell gridX=\"0\" gridY=\"0\">\n");
                        }
                        if ((zielzeile == 0) && (lastcell == izeilen)) {
                            outservermaske.print("</pane.notebook>\n");
                            zielzeile = izeilen;
                        }

                        if ((izeilen == zielzeile) && (zielzeile != 0)) {
                            line = inmaske.readLine();
                            while (line != null) {
                                // Zuerst die Datei einlesen und jede Zeile raus schreiben
                                outservermaske.print(line + "\n");
                                line = inmaske.readLine();

                            }
                            if (newpanenotebook)
                                outservermaske.print("</layout.notebook>\n </cell>\n </layout.grid> \n");
                        }
                    }
                    outservermaske.close();

                    // Neue Datei nun auf die alte kopieren
                    Files.move(
                            Paths.get("tmp\\screens\\screen_" + maskennummer + "\\" + prio + "\\Xscreen_"
                                    + maskennummer + "_" + prio + tabellekopf),
                            Paths.get("tmp\\screens\\screen_" + maskennummer + "\\" + prio + "\\screen_"
                                    + maskennummer + "_" + prio + tabellekopf),
                            REPLACE_EXISTING);

                    // Resources Dateien anschauen
                    // Append an die Resources.language
                    // sshexitstatus = sshclient.sendcommand("cat  ./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW  >> ./screens/screen_" + maskennummer + "/" + prio + "/Resources.language", error, fromServer);
                    String resourcesstring = FileUtils.readFileToString(
                            new File(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 3).toString()),
                            "utf-8");
                    FileWriter fw = new FileWriter(new File(
                            "tmp\\screens\\screen_" + maskennummer + "\\" + prio + "\\Resources.language"),
                            true);
                    fw.write(resourcesstring);//appends the string to the file
                    if (newpanenotebook)
                        fw.write("b825893d-f00a-4500-ae24-c2fe5364ae0e=Allgemein\n");
                    fw.close();
                    //An Resources_*  den String auch noch anhngen
                    // dazu erst mal die Dateien suchen
                    Path dir = Paths.get("tmp\\screens\\screen_" + maskennummer + "\\" + prio);
                    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir, "Resources_*")) {
                        for (Path resourcesfile : stream) {
                            fw = new FileWriter(resourcesfile.toFile(), true);
                            fw.write(resourcesstring);//appends the string to the file
                            if (newpanenotebook)
                                fw.write("b825893d-f00a-4500-ae24-c2fe5364ae0e=Allgemein\n");
                            fw.close();
                        }
                    }

                    // Tgz wieder erzeugen
                    createTarGzip("tmp\\", "tmp\\screen." + maskennummer + "." + prio + ".tgz");
                    // Maske wieder auf Server schieben

                    sshexitstatus = sshclient.sendfile("\\tmp\\screen." + maskennummer + "." + prio + ".tgz",
                            "screen." + maskennummer + "." + prio + ".tgz");
                    jTLog.append("Neue Maske " + maskennummer + prio + " wird hochgeladen\n");
                    jTLog.paint(jTLog.getGraphics());
                    // und importieren
                    jTLog.append("Neue Maske " + maskennummer + prio + " wird im Mandanten importiert\n");
                    jTLog.paint(jTLog.getGraphics());
                    sshexitstatus = sshclient
                            .sendcommand(
                                    "eval `sh denv.sh`;screen_import.sh -n " + maskennummer + " -p " + prio
                                            + " " + "screen." + maskennummer + "." + prio + ".tgz",
                                    error, fromServer);

                    // und generieren
                    jTLog.append("Neue Maske " + maskennummer + prio + " wird generiert\n");
                    jTLog.paint(jTLog.getGraphics());
                    // Maske generieren
                    maskegenerieren(session, maskennummer, prio);

                    jTLog.append(error.toString());
                    jTLog.paint(jTLog.getGraphics());

                }
                /*
                //Alter Weg
                // Maske abholen
                jTLog.append("Maske " + maskennummer + " " + prio + " wird geladen\n");
                jTLog.paint(jTLog.getGraphics());
                //String servermaske = "./screens/screen_" + maskennummer + "/" + prio + "/screen_" + maskennummer + "_" + prio + "_M.xml";
                servermaske = "./screens/screen_" + maskennummer + "/" + prio + "/screen_" + maskennummer + "_" + prio + tabellekopf;
                        
                sshexitstatus = sshclient.getfile(servermaske, "tmp\\" + maskennummer + prio + ".xml");
                if (sshexitstatus == -1) {// Maske wurde erfolgreich geladen
                //Maske einlesen
                jTLog.append("Maske " + maskennummer + " " + prio + " wird erweitert\n");
                jTLog.paint(jTLog.getGraphics());
                        
                BufferedReader inservermaske = null;
                inservermaske = new BufferedReader(new FileReader("tmp\\" + maskennummer + prio + ".xml"));
                BufferedReader inmaske = null;
                inmaske = new BufferedReader(new FileReader(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 2).toString()));
                PrintWriter outservermaske = new PrintWriter(new BufferedWriter(new FileWriter("tmp\\" + maskennummer + prio + "X.xml")));
                int lineNr = 0;
                String line = inservermaske.readLine();
                while (line != null) {
                        
                    datei.add(line);
                        
                    if (line.contains("</pane.notebook>")) {
                        zielzeile = lineNr;
                    }
                    lineNr++;
                        
                    line = inservermaske.readLine();
                }
                inservermaske.close();
                        
                // Raus schreiben der Datei
                for (int izeilen = 0; izeilen < lineNr - 1; izeilen++) {
                    outservermaske.print(datei.get(izeilen) + "\n");
                    if (izeilen == zielzeile) {
                        line = inmaske.readLine();
                        while (line != null) {
                            // Zuerst die Datei einlesen und jede Zeile raus schreiben
                            outservermaske.print(line + "\n");
                            line = inmaske.readLine();
                        
                        }
                    }
                }
                outservermaske.close();
                        
                //Datei zurck zum server schicken
                jTLog.append("Maske " + maskennummer + " " + prio + " wird gesendet\n");
                jTLog.paint(jTLog.getGraphics());
                sshexitstatus = sshclient.sendfile("tmp\\" + maskennummer + prio + "X.xml", servermaske);
                if (sshexitstatus == -1) {// Maske wurde auf Server bertragen
                    // Jetzt noch die Resources Datei an die Resources auf dem server anhngen
                    sshexitstatus = sshclient.sendfile(GlobalVars.dir + "\\Masken\\" + table.getValueAt(i, 3).toString(), "./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW");
                    if (sshexitstatus == -1) {
                        sshexitstatus = sshclient.sendcommand("cat  ./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW  >> ./screens/screen_" + maskennummer + "/" + prio + "/Resources.language", error, fromServer);
                        //Resources wurde auf Server bertragen  
                         jTLog.append(error.toString());
                        jTLog.paint(jTLog.getGraphics());
                        if (sshexitstatus==0)
                        {
                           sshexitstatus = sshclient.sendcommand("ls screens/screen_" + maskennummer + "/" + prio + "/Resources_* -l", error, fromServer);
                           jTLog.append(error.toString());
                            jTLog.paint(jTLog.getGraphics());
                        if (sshexitstatus == 0) {
                                    
                            resourcesServerString = fromServer.toString();
                            resourcesServerArray = resourcesServerString.split("\n");
                            ///Bisher alles gut gelaufen, deswegen failure auf false setzen
                            failure = false;
                            for (int iresources = 0; iresources < resourcesServerArray.length; iresources++) {
                                if (resourcesServerArray[iresources].toString().contains("Resources")) {
                                    sshexitstatus = sshclient.sendcommand("cat  ./screens/screen_" + maskennummer + "/" + prio + "/ResourcesFW  >>" + resourcesServerArray[iresources].toString().substring(resourcesServerArray[iresources].lastIndexOf(" "), resourcesServerArray[iresources].length()), error, fromServer);
                                    if (sshexitstatus != 0) {
                                        failure = true;
                                    }
                                    jTLog.append(error.toString());
                                    jTLog.paint(jTLog.getGraphics());
                                }
                        
                            }
                        
                            jTLog.append("Maske " + maskennummer + " " + prio + " wird generiert\n");
                        
                            // Maske nun noch generieren
                            maskegenerieren(session, maskennummer, prio); 
                        }
                               
                                
                        }
                        
                    }
                        
                }
                        
                }*/
                if (failure) {

                    //Alte Maske wieder importieren 
                    //  jTLog.append(error.toString());
                    //  jTLog.append("Gesicherte Maske wird wieder installiert !!! manuelle Nacharbeit notwendig!!!\n");
                    //  jTLog.paint(jTLog.getGraphics());
                    //  sshexitstatus = sshclient.sendcommand("eval `sh denv.sh`;screen_import.sh -n " + maskennummer + " -p " + prio+" screen."+maskennummer+"."+prio+".tgz", error, fromServer);
                }

            }

        }

    } catch (JSchException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    } catch (InterruptedException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SftpException ex) {
        Logger.getLogger(Masken.class.getName()).log(Level.SEVERE, null, ex);
    }
    return true;
}

From source file:edu.ku.brc.specify.tasks.subpane.ESResultsTablePanel.java

/**
 * @param table//from  w ww .j  a v  a 2  s.  c o  m
 * @param model
 */
protected void autoResizeColWidth(final JTable table, final DefaultTableModel model) {
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setModel(model);

    int margin = 5;

    DefaultTableColumnModel colModel = (DefaultTableColumnModel) table.getColumnModel();

    int preferredWidthTotal = 0;
    int renderedWidthTotal = 0;
    int[] colWidths = new int[table.getColumnCount()];
    int[] strWidths = new int[table.getColumnCount()];
    for (int i = 0; i < table.getColumnCount(); i++) {
        int vColIndex = i;
        TableColumn col = colModel.getColumn(vColIndex);
        int width = 0;

        TableCellRenderer headerRenderer = col.getHeaderRenderer();
        if (headerRenderer instanceof JLabel) {
            ((JLabel) headerRenderer).setHorizontalAlignment(SwingConstants.CENTER);
        }

        // Get width of column header
        TableCellRenderer renderer = col.getCellRenderer();
        if (renderer == null) {
            renderer = table.getTableHeader().getDefaultRenderer();
        }

        Component comp = renderer.getTableCellRendererComponent(table, col.getHeaderValue(), false, false, 0,
                0);

        width = comp.getPreferredSize().width;

        // Get maximum width of column data
        int strWidth = 0;
        boolean isString = model.getColumnClass(i) == String.class;
        for (int r = 0; r < table.getRowCount(); r++) {
            renderer = table.getCellRenderer(r, vColIndex);
            Object objVal = table.getValueAt(r, vColIndex);
            if (isString && objVal != null) {
                strWidth = Math.max(strWidth, ((String) objVal).length());
            }
            comp = renderer.getTableCellRendererComponent(table, objVal, false, false, r, vColIndex);
            width = Math.max(width, comp.getPreferredSize().width);
        }

        // Add margin
        width += 2 * margin;

        preferredWidthTotal += col.getPreferredWidth();
        colWidths[i] = width;
        strWidths[i] = strWidth;

        renderedWidthTotal += width;
    }

    if (renderedWidthTotal > preferredWidthTotal) {
        for (int i = 0; i < table.getColumnCount(); i++) {
            TableColumn col = colModel.getColumn(i);
            TableCellRenderer renderer = col.getCellRenderer();
            if (renderer != null) {
                ((JLabel) renderer).setHorizontalAlignment(
                        strWidths[i] > 20 ? SwingConstants.LEFT : SwingConstants.CENTER);
                //((JLabel)renderer).setHorizontalAlignment(SwingConstants.LEFT);
            }

            if (model.getColumnCount() > 3 && renderedWidthTotal > preferredWidthTotal) {
                col.setPreferredWidth(colWidths[i]);
            }
        }
    }

    ((DefaultTableCellRenderer) table.getTableHeader().getDefaultRenderer())
            .setHorizontalAlignment(SwingConstants.LEFT);

    // table.setAutoCreateRowSorter(true);
    table.getTableHeader().setReorderingAllowed(false);
}

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

private void initSourceMapTable(Map<String, Object> sourceMap) {
    Object[][] data = new Object[sourceMap.size()][2];
    int i = 0;/*from www  .  ja  v  a  2s  .c  o  m*/

    for (Entry<String, Object> entry : sourceMap.entrySet()) {
        data[i][0] = entry.getKey();
        data[i][1] = entry.getValue();
        i++;
    }

    sourceMapTable = new MirthTable();

    sourceMapTable.setModel(new RefreshTableModel(data, new Object[] { "Variable", "Value" }) {
        @Override
        public boolean isCellEditable(int row, int column) {
            return true;
        }
    });

    sourceMapTable.setDragEnabled(false);
    sourceMapTable.setRowSelectionAllowed(true);
    sourceMapTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    sourceMapTable.setRowHeight(UIConstants.ROW_HEIGHT);
    sourceMapTable.setFocusable(false);
    sourceMapTable.setOpaque(true);
    sourceMapTable.getTableHeader().setResizingAllowed(false);
    sourceMapTable.getTableHeader().setReorderingAllowed(false);
    sourceMapTable.setSortable(true);

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

    sourceMapTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent evt) {
            if (!evt.getValueIsAdjusting()) {
                deleteButton.setEnabled(sourceMapTable.getSelectedRow() > -1);
            }
        }
    });

    class SourceMapTableCellEditor extends AbstractCellEditor implements TableCellEditor {
        private JTable table;
        private int column;
        private JTextField textField;
        private Object originalValue;
        private String newValue;

        public SourceMapTableCellEditor(JTable table, int column) {
            super();
            this.table = table;
            this.column = column;
            textField = new JTextField();
            textField.addFocusListener(new FocusAdapter() {
                @Override
                public void focusGained(FocusEvent e) {
                    textField.setCaretPosition(textField.getText().length());
                }
            });
        }

        @Override
        public boolean isCellEditable(EventObject evt) {
            if (evt == null) {
                return false;
            }
            if (evt instanceof MouseEvent) {
                return ((MouseEvent) evt).getClickCount() >= 2;
            }
            return true;
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row,
                int column) {
            originalValue = value;
            newValue = null;
            textField.setText(String.valueOf(value));
            return textField;
        }

        @Override
        public Object getCellEditorValue() {
            if (newValue != null) {
                return newValue;
            } else {
                return originalValue;
            }
        }

        @Override
        public boolean stopCellEditing() {
            if (!valueChanged()) {
                super.cancelCellEditing();
            } else {
                newValue = textField.getText();
            }
            return super.stopCellEditing();
        }

        private boolean valueChanged() {
            String value = textField.getText();
            if (StringUtils.isBlank(value)) {
                return false;
            }

            for (int i = 0; i < table.getRowCount(); i++) {
                Object tableValue = table.getValueAt(i, column);
                if (tableValue != null && String.valueOf(tableValue).equals(value)) {
                    return false;
                }
            }

            return true;
        }
    }

    sourceMapTable.getColumnModel().getColumn(0).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 0));
    sourceMapTable.getColumnModel().getColumn(1).setCellEditor(new SourceMapTableCellEditor(sourceMapTable, 1));

    sourceMapScrollPane.setViewportView(sourceMapTable);
    deleteButton.setEnabled(false);
}

From source file:edu.ucla.stat.SOCR.chart.Chart.java

public void updateExample(ChartExampleData example) {
    //  reset();//www .  j  a  v a2  s .  c o  m

    hasExample = true;
    JTable tempDataTable = example.getExample();

    /* if(tempDataTable.getRowCount()>dataTable.getRowCount())
    appendTableRows(tempDataTable.getRowCount()-dataTable.getRowCount());
       else   */
    resetTableRows(tempDataTable.getRowCount());

    for (int i = 0; i < tempDataTable.getColumnCount(); i++) {
        columnModel.getColumn(i).setHeaderValue(tempDataTable.getColumnName(i));
        //  System.out.println("updateExample tempDataTable["+i+"] = " +tempDataTable.getColumnName(i));
    }
    dTableHeader = new EditableHeader(columnModel);
    dataTable.setTableHeader(dTableHeader);

    for (int i = 0; i < tempDataTable.getRowCount(); i++)
        for (int j = 0; j < tempDataTable.getColumnCount(); j++) {
            dataTable.setValueAt(tempDataTable.getValueAt(i, j), i, j);
        }
    dataPanel.removeAll();
    JScrollPane tablePanel = new JScrollPane(dataTable);
    tablePanel.setRowHeaderView(headerTable);
    dataPanel.add(tablePanel);
    dataPanel.add(new JScrollPane(summaryPanel));
    dataTable.setGridColor(Color.gray);
    dataTable.setShowGrid(true);

    // this is a fix for the BAD SGI Java VM - not up to date as of dec. 22, 2003
    try {
        dataTable.setDragEnabled(true);
    } catch (Exception e) {
    }

    dataPanel.validate();
    //updateStatus("Example updated, please redo the mapping and update the chart");
}