List of usage examples for javax.swing JTable getValueAt
public Object getValueAt(int row, int column)
row
and column
. From source file:com.intuit.tank.proxy.ProxyApp.java
private JPanel getTransactionTable() { JPanel frame = new JPanel(new BorderLayout()); model = new TransactionTableModel(); final JTable table = new TransactionTable(model); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter);//from www.j a va 2 s . c o m final JPopupMenu pm = new JPopupMenu(); JMenuItem item = new JMenuItem("Delete Selected"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { int response = JOptionPane.showConfirmDialog(ProxyApp.this, "Are you sure you want to delete " + selectedRows.length + " Transactions?", "Confirm Delete", JOptionPane.YES_NO_OPTION); if (response == JOptionPane.YES_OPTION) { int[] correctedRows = new int[selectedRows.length]; for (int i = selectedRows.length; --i >= 0;) { int row = selectedRows[i]; int index = (Integer) table.getValueAt(row, 0) - 1; correctedRows[i] = index; } Arrays.sort(correctedRows); for (int i = correctedRows.length; --i >= 0;) { int row = correctedRows[i]; Transaction transaction = model.getTransactionForIndex(row); if (transaction != null) { model.removeTransaction(transaction, row); isDirty = true; saveAction.setEnabled(isDirty && !stopAction.isEnabled()); } } } } } }); pm.add(item); table.add(pm); table.addMouseListener(new MouseAdapter() { boolean pressed = false; public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { Point p = e.getPoint(); int row = table.rowAtPoint(p); int index = (Integer) table.getValueAt(row, 0) - 1; Transaction transaction = model.getTransactionForIndex(index); if (transaction != null) { detailsTF.setText(transaction.toString()); detailsTF.setCaretPosition(0); detailsDialog.setVisible(true); } } } /** * @{inheritDoc */ @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { pressed = true; int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } /** * @{inheritDoc */ @Override public void mouseReleased(MouseEvent e) { if (!pressed && e.isPopupTrigger()) { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 0) { pm.show(e.getComponent(), e.getX(), e.getY()); } } } }); JScrollPane pane = new JScrollPane(table); frame.add(pane, BorderLayout.CENTER); JPanel panel = new JPanel(new BorderLayout()); JLabel label = new JLabel("Filter: "); panel.add(label, BorderLayout.WEST); final JLabel countLabel = new JLabel(" Count: 0 "); panel.add(countLabel, BorderLayout.EAST); final JTextField filterText = new JTextField(""); filterText.addKeyListener(new KeyAdapter() { public void keyTyped(KeyEvent e) { String text = filterText.getText(); if (text.length() == 0) { sorter.setRowFilter(null); } else { try { sorter.setRowFilter(RowFilter.regexFilter(text)); countLabel.setText(" Count: " + sorter.getViewRowCount() + " "); } catch (PatternSyntaxException pse) { System.err.println("Bad regex pattern"); } } } }); panel.add(filterText, BorderLayout.CENTER); frame.add(panel, BorderLayout.NORTH); return frame; }
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 www . j av a 2 s . co 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:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
protected void emptyResultsTable() { String[] resultsHeading = new String[2]; resultsHeading[0] = "Kernel"; resultsHeading[1] = "Resutls"; String[][] results = new String[1][2]; JTable tempResultsTable = new JTable(results, resultsHeading); resetRTableRows(tempResultsTable.getRowCount()); for (int i = 0; i < tempResultsTable.getRowCount(); i++) for (int j = 0; j < tempResultsTable.getColumnCount(); j++) { for (int s = 0; s < num_series; s++) { resultsTables[s].setValueAt(tempResultsTable.getValueAt(i, j), i, j); }/*from ww w. java 2 s .c o m*/ } }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);//from w w w . ja va 2s .c o m table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
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 . java 2s . c o 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.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 .j a v a 2 s . c o m propertiesList.add((String) table.getValueAt(i, VALUE_COLUMN)); } return properties; }
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 ww w.ja v a 2s . c om*/ 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:edu.ucla.stat.SOCR.chart.demo.SOCR_EM_MixtureModelChartDemo.java
protected void setTable(XYDataset ds) { // update results table after segment //System.out.println("setTable get called"); //printDataset(ds); if (segment_flag) { // System.out.println("settable: setting segment resultTable"); resultsTables = new CustomJTable[num_series]; for (int s = 0; s < num_series; s++) { resultsTables[s] = mEMexperiment[s].getResultsTable(); }/*from w w w .j a v a 2s. c om*/ } else { convertor.dataset2Table((XYDataset) ds); 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++) { String v = (String) tempDataTable.getValueAt(i, j); //if (v!="null" && v!="NaN") dataTable.setValueAt(v, i, j); } } //no segment // int columnCount = dataTable.getColumnCount(); //attention this is a quick fix for losted mapping, need revisit!!!!! for (int i = 0; i < num_series; i++) { //System.out.println("mapping"); addButtonIndependent(); addButtonDependent(); } setTablePane(); // don't bring graph to the front if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) != ALL) { // tabbedPanelContainer.setSelectedIndex(tabbedPanelContainer.indexOfComponent(graphPanel)); } else { setMixPanel(); } }
From source file:frameworks.Masken.java
public boolean maskenInstall(JTable table, JTextArea jTLog, EDPSession session, String LinuxUser, String LinuxPass, String Host) { try {//from w ww. j a v a 2 s . co m 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// w w w.j a v a2s . 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); }