List of usage examples for javax.swing.table DefaultTableModel getRowCount
public int getRowCount()
From source file:gtu._work.ui.SaveFileToPropertiesUI.java
private void initGUI() { try {/*from w w w. j a va2s.c o m*/ BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); this.setTitle("save file to properties"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("load", null, jPanel1, null); { jScrollPane2 = new JScrollPane(); jPanel1.add(jScrollPane2, BorderLayout.CENTER); { textArea = new JTextArea(); jScrollPane2.setViewportView(textArea); } } { jPanel2 = new JPanel(); jPanel1.add(jPanel2, BorderLayout.NORTH); jPanel2.setPreferredSize(new java.awt.Dimension(400, 40)); { addPropsFile = new JButton(); jPanel2.add(addPropsFile); addPropsFile.setText("load properties from file"); addPropsFile.setPreferredSize(new java.awt.Dimension(234, 30)); addPropsFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { props.load(new InputStreamReader(new FileInputStream(file), (String) openUnknowFilecharSet.getSelectedItem())); reloadPropertiesTable(); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } { openFile = new JButton(); jPanel2.add(openFile); openFile.setText("open unknow file"); openFile.setPreferredSize(new java.awt.Dimension(204, 30)); openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { String encode = (String) openUnknowFilecharSet.getSelectedItem(); BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(file), encode)); StringBuilder sb = new StringBuilder(); for (String line = null; (line = reader.readLine()) != null;) { sb.append(line + "\n"); } reader.close(); textArea.setText(textArea.getText() + "\n" + sb); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } { ComboBoxModel openUnknowFilecharSetModel = new DefaultComboBoxModel( new String[] { "BIG5", "UTF8" }); openUnknowFilecharSet = new JComboBox(); jPanel2.add(openUnknowFilecharSet); openUnknowFilecharSet.setModel(openUnknowFilecharSetModel); openUnknowFilecharSet.setPreferredSize(new java.awt.Dimension(73, 24)); } { appendTextAreaToProps = new JButton(); jPanel2.add(appendTextAreaToProps); appendTextAreaToProps.setText("append textarea to properties"); appendTextAreaToProps.setPreferredSize(new java.awt.Dimension(227, 30)); appendTextAreaToProps.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (StringUtils.isBlank(textArea.getText())) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("textArea is empty", "ERROR"); return; } try { BufferedReader reader = new BufferedReader( new StringReader(textArea.getText())); int pos = -1; String key = null; String value = null; for (String line = null; (line = reader.readLine()) != null;) { if ((pos = line.lastIndexOf("=")) != -1) { key = line.substring(0, pos); value = line.substring(pos + 1); props.put(key, value); } } reader.close(); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("append success!", "SUCCESS"); reloadPropertiesTable(); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("props edit", null, jPanel3, null); { jScrollPane1 = new JScrollPane(); jPanel3.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(629, 361)); { TableModel propsTableModel = new DefaultTableModel(); propsTable = new JTable(); jScrollPane1.setViewportView(propsTable); propsTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (propsTable.getRowCount() == 0) { return; } int rowPos = JTableUtil.newInstance(propsTable).getSelectedRow(); Object key = propsTable.getValueAt(rowPos, 0); Object value = propsTable.getValueAt(rowPos, 1); JMenuItem insertRowItem = JTableUtil.newInstance(propsTable) .jMenuItem_addRow(false, null); insertRowItem.setText("inert row..."); String rowInfo = "delete row : [" + key + "] = [" + value + "]"; JMenuItem delRowItem = JTableUtil.newInstance(propsTable) .jMenuItem_removeRow("are you sure remove row : \n" + rowInfo); delRowItem.setText(rowInfo); JPopupMenuUtil.newInstance(propsTable).applyEvent(evt) .addJMenuItem(insertRowItem, delRowItem).show(); } }); propsTable.setModel(propsTableModel); JTableUtil.defaultSetting(propsTable); } } { jPanel4 = new JPanel(); jPanel3.add(jPanel4, BorderLayout.SOUTH); jPanel4.setPreferredSize(new java.awt.Dimension(629, 45)); { clearProps = new JButton(); jPanel4.add(clearProps); clearProps.setText("clear properties"); clearProps.setPreferredSize(new java.awt.Dimension(182, 36)); clearProps.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { props.clear(); reloadPropertiesTable(); } }); } { savePropsToFile = new JButton(); jPanel4.add(savePropsToFile); savePropsToFile.setText("save properties to file"); savePropsToFile.setPreferredSize(new java.awt.Dimension(182, 36)); savePropsToFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { props.clear(); DefaultTableModel model = (DefaultTableModel) propsTable.getModel(); Object key = null; Object value = null; for (int ii = 0; ii < model.getRowCount(); ii++) { key = model.getValueAt(ii, 0); value = model.getValueAt(ii, 1); props.put(key, value); } props.store(new FileOutputStream(file), SaveFileToPropertiesUI.class.getSimpleName()); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("save completed!\n" + file, "SUCCESS"); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } } } pack(); this.setSize(798, 505); } catch (Exception e) { e.printStackTrace(); } }
From source file:gtu._work.ui.RegexCatchReplacer_Ebao.java
/** * @param fromPattern/*from w ww. j a v a2 s . c om*/ * ???pattern * @param toFormat * ??pattern * @param replaceText * ?? */ void replacer(String fromPattern, String toFormat, String replaceText) { try { Pattern pattern = Pattern.compile(fromPattern); Matcher matcher = pattern.matcher(replaceText); Map<String, Integer> tmap = new LinkedHashMap<String, Integer>(); String tempStr = null; for (; matcher.find();) { tempStr = toFormat.toString(); for (int ii = 0; ii <= matcher.groupCount(); ii++) { System.out.println(ii + " -- " + matcher.group(ii)); tempStr = tempStr.replaceAll("#" + ii + "#", Matcher.quoteReplacement(matcher.group(ii))); if (!tmap.containsKey(tempStr)) { tmap.put(tempStr, 0); } tmap.put(tempStr, tmap.get(tempStr) + 1); } } DefaultTableModel model = JTableUtil.createModel(true, "match", "count"); for (String str : tmap.keySet()) { model.addRow(new Object[] { str, tmap.get(str) }); } setTitle("total : " + model.getRowCount()); resultArea.setModel(model); // ebao? JTableUtil resultAreaUtil = JTableUtil.newInstance(resultArea); DefaultTableModel model2 = JTableUtil.createModel(true, "msgId", "Label"); boolean isExactSearch = exactEbaoSearchChk.isSelected(); ebaoTable.setModel(model2); for (int ii = 0; ii < model.getRowCount(); ii++) { String msgId = (String) resultAreaUtil.getRealValueAt(ii, 0); callEbaoMsgId(msgId, isExactSearch); } } catch (Exception ex) { JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(ex.getMessage(), getTitle()); ex.printStackTrace(); } }
From source file:gtu._work.ui.PropertyEditUI.java
void loadModelToProperties(Properties prop) { DefaultTableModel model = JTableUtil.newInstance(propTable).getModel(); for (int ii = 0; ii < model.getRowCount(); ii++) { String key = (String) model.getValueAt(ii, 1); String value = getChs2Big5((String) model.getValueAt(ii, 2)); System.out.println(key + " = " + value); prop.setProperty(key, value);//from w w w . j a v a 2 s .co m } }
From source file:UserInterface.ViewPatientJPanel.java
private void populateTable() { DefaultTableModel dtm = (DefaultTableModel) tblVitalSigns.getModel(); int rowCount = dtm.getRowCount(); for (int x = rowCount - 1; x >= 0; x--) { dtm.removeRow(x);/*from w w w .j a v a2 s . c om*/ } for (VitalSign vs : patient.vitalSignHistory.getVitalSignHistory()) { Object row[] = new Object[2]; row[0] = vs; row[1] = vs.getState(); dtm.addRow(row); } }
From source file:it.unifi.rcl.chess.traceanalysis.gui.TracePanel.java
private void phaseDetection() { final class Phase { int start; int end;//www . j a v a 2 s.c o m CHDistribution dist; double bound; public Phase(int start, int end) { this.start = start; this.end = end; } } double coverage = Double.parseDouble(txtPhasesCoverage.getText()); int wsize = Integer.parseInt(txtPhasesWSize.getText()); CHDistribution[] dists = trace.getPhases(coverage, wsize); CHDistribution curDist = null; CHDistribution lastDist = null; int iPhaseBegin, iPhaseEnd; Phase p = null; DefaultTableModel model = (DefaultTableModel) tablePhases.getModel(); while (model.getRowCount() > 0) { model.removeRow(0); } if (wsize > 1) { // ignore initial window model.addRow(new Object[] { 1, (wsize - 1), "{undefined}", "" }); } iPhaseBegin = 0; iPhaseEnd = 0; curDist = dists[0]; for (int i = 1; i < dists.length; i++) { lastDist = curDist; curDist = dists[i]; if (!curDist.equals(lastDist)) { // distribution is different from the previous: phase change p = new Phase(iPhaseBegin, iPhaseEnd + (wsize - 1)); p.dist = lastDist; p.bound = trace.getSubTrace(p.start, p.end).getBound(coverage); iPhaseBegin = i; iPhaseEnd = i; model.addRow(new Object[] { p.start + 1 + (wsize - 1), p.end + 1, p.dist.toString(), p.bound }); } else { // distribution is the same (also parameters), phase is extended iPhaseEnd++; } } p = new Phase(iPhaseBegin, iPhaseEnd + (wsize - 1)); p.dist = lastDist; p.bound = trace.getSubTrace(p.start, p.end).getBound(coverage); model.addRow(new Object[] { p.start + 1 + (wsize - 1), p.end + 1, p.dist.toString(), p.bound }); tablePhases.setModel(model); }
From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java
@Override public void run() { CSV2TableLoader tl = new CSV2TableLoader(this.ph, this.is); DefaultTableModel dtm; try {/*from w ww. ja v a2 s. c om*/ dtm = tl.call(); if (this.mode == CHART.XY) { XYSeriesCollection cd = new XYSeriesCollection(); for (int j = 0; j < dtm.getColumnCount(); j++) { XYSeries xys = new XYSeries(dtm.getColumnName(j)); for (int i = 0; i < dtm.getRowCount(); i++) { Object o = dtm.getValueAt(i, j); try { double d = Double.parseDouble(o.toString()); xys.add(i, d); Logger.getLogger(getClass().getName()).log(Level.INFO, "Adding {0} {1} {2}", new Object[] { i, d, dtm.getColumnName(j) }); } catch (Exception e) { } } cd.addSeries(xys); } XYLineAndShapeRenderer d = new XYLineAndShapeRenderer(true, false); XYPlot xyp = new XYPlot(cd, new NumberAxis("category"), new NumberAxis("value"), d); JFreeChart jfc = new JFreeChart(this.title, xyp); jtc.setChart(jfc); Logger.getLogger(getClass().getName()).info("creating chart done"); } else if (this.mode == CHART.MATRIX) { DefaultXYZDataset cd = new DefaultXYZDataset(); Logger.getLogger(getClass().getName()).log(Level.INFO, "Name of column 0: {0}", dtm.getColumnName(0)); if (dtm.getColumnName(0).isEmpty()) { Logger.getLogger(getClass().getName()).info("Removing column 0"); dtm = removeColumn(dtm, 0); } if (dtm.getColumnName(dtm.getColumnCount() - 1).equalsIgnoreCase("filename")) { dtm = removeColumn(dtm, dtm.getColumnCount() - 1); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { sb.append(dtm.getValueAt(i, j) + " "); } sb.append("\n"); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table before sorting: {0}", sb.toString()); // dtm = sort(dtm); StringBuilder sb2 = new StringBuilder(); for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { sb2.append(dtm.getValueAt(i, j) + " "); } sb2.append("\n"); } Logger.getLogger(getClass().getName()).log(Level.INFO, "Table after sorting: {0}", sb2.toString()); int rows = dtm.getRowCount(); int columns = dtm.getColumnCount(); Logger.getLogger(getClass().getName()).log(Level.INFO, "Storing {0} * {1} elements, {2} total!", new Object[] { columns, rows, rows * columns }); double[][] data = new double[3][(columns * rows)]; ArrayDouble.D1 dt = new ArrayDouble.D1((columns) * rows); double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; EvalTools.eqI(rows, columns, this); int k = 0; for (int i = 0; i < dtm.getRowCount(); i++) { for (int j = 0; j < dtm.getColumnCount(); j++) { Object o = dtm.getValueAt(i, j); try { double d = Double.parseDouble(o.toString()); if (d < min) { min = d; } if (d > max) { max = d; } data[0][k] = (double) i; data[1][k] = (double) j; data[2][k] = d; dt.set(k, d); k++; //System.out.println("Adding "+i+" "+d+" "+dtm.getColumnName(j)); } catch (Exception e) { } } //cd.addSeries(xys); } cd.addSeries(this.title, data); XYBlockRenderer xyb = new XYBlockRenderer(); GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max, ImageTools .rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv"))); xyb.setPaintScale(ps); final String[] colnames = new String[dtm.getColumnCount()]; for (int i = 0; i < colnames.length; i++) { colnames[i] = dtm.getColumnName(i); } NumberAxis na1 = new SymbolAxis("category", colnames); na1.setVerticalTickLabels(false); NumberAxis na2 = new SymbolAxis("category", colnames); na1.setVerticalTickLabels(true); XYPlot xyp = new XYPlot(cd, na1, na2, xyb); xyb.setSeriesToolTipGenerator(0, new XYToolTipGenerator() { @Override public String generateToolTip(XYDataset xyd, int i, int i1) { return "[" + colnames[xyd.getX(i, i1).intValue()] + ":" + colnames[xyd.getY(i, i1).intValue()] + "] = " + ((XYZDataset) xyd).getZValue(i, i1) + ""; } }); JFreeChart jfc = new JFreeChart(this.title, xyp); NumberAxis values = new NumberAxis("value"); values.setAutoRange(false); values.setRangeWithMargins(min, max); PaintScaleLegend psl = new PaintScaleLegend(ps, values); psl.setBackgroundPaint(jfc.getBackgroundPaint()); jfc.addSubtitle(psl); psl.setStripWidth(50); psl.setPadding(20, 20, 20, 20); psl.setHeight(200); psl.setPosition(RectangleEdge.RIGHT); jtc.setChart(jfc); } } catch (Exception ex) { Exceptions.printStackTrace(ex); } ph.finish(); }
From source file:gdt.jgui.tool.JEntityEditor.java
private void replaceTable(Core[] ca) { try {//from w w w .j a va 2 s.co m JScrollPane scrollPane = (JScrollPane) tabbedPane.getSelectedComponent(); JTable table = (JTable) scrollPane.getViewport().getView(); DefaultTableModel model = (DefaultTableModel) table.getModel(); while (model.getRowCount() > 0) model.removeRow(0); int cnt = ca.length; if (cnt < 1) return; for (int i = 0; i < cnt; i++) model.addRow(new String[] { ca[i].type, ca[i].name, ca[i].value }); } catch (Exception e) { LOGGER.severe(e.toString()); } }
From source file:area.math.nm.ui.GUIInterpolationJPanel.java
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed javax.swing.table.DefaultTableModel dtm = (javax.swing.table.DefaultTableModel) jTable1.getModel(); int nRow = dtm.getRowCount(), nCol = dtm.getColumnCount(); double[][] tableData = new double[nRow][nCol]; for (int i = 0; i < nRow; i++) for (int j = 0; j < nCol; j++) { if (dtm.getValueAt(i, j) != null) { tableData[i][j] = Double.parseDouble((String) dtm.getValueAt(i, j)); System.out.println(i + " " + j + " " + tableData[i][j]); } else tableData[i][j] = -100000; }//from w ww .j a v a2 s . com int size = 0; for (int i = 0; i < 10; i++) { if (tableData[i][1] == -100000 || tableData[i][0] == -100000) break; else size++; } double[] x = new double[size]; double[] y = new double[size]; for (int i = 0; i < size; i++) { x[i] = tableData[i][0]; y[i] = tableData[i][1]; } String option = (String) jComboBox1.getSelectedItem(); Interpolation ip = new Interpolation(); double input = Double.parseDouble(jTextField1.getText()); switch (option) { case "SplineInterpolator": String result = ip.splineInterpolation(x, y, input); JOptionPane.showMessageDialog(null, result); break; default: break; } }
From source file:userInterface.EnergySourceBoardSupervisor.ManageEnergyConsumptionsJPanel.java
public void populateCalculations() { int reading = 0; int hours = 0; float energyPerDay = 0; float energyPerMonth = 0; float energyPerYear = 0; DefaultTableModel dtm = (DefaultTableModel) applianceTable.getModel(); int count = dtm.getRowCount(); for (int row = count - 1; row >= 0; row--) { reading = (int) dtm.getValueAt(row, 2); hours = (int) dtm.getValueAt(row, 3); energyPerDay = energyPerDay + ((reading * hours) / 1000); }// w w w.jav a 2 s . c o m energyPerDayTxt.setText(String.valueOf(energyPerDay)); energyPerMonth = energyPerDay * 30; energyPerMonthTxt.setText(String.valueOf(energyPerMonth)); energyPerYear = energyPerDay * 365; energyPerYearTxt.setText(String.valueOf(energyPerYear)); }
From source file:com.mirth.connect.client.ui.panels.connectors.PollingSettingsPanel.java
private void clearProperties() { scheduleTypeComboBox.setSelectedItem(PollingType.INTERVAL.getDisplayName()); noStartPollRadioButton.setSelected(true); SimpleDateFormat dateFormat = new SimpleDateFormat("hh:mm aa"); pollingTimePicker.setDate(dateFormat.format(Calendar.getInstance().getTime())); DefaultTableModel model = (DefaultTableModel) cronJobsTable.getModel(); for (int index = model.getRowCount() - 1; index >= 0; index--) { model.removeRow(index);/*from w ww . java 2 s .c o m*/ } Vector<String> row = new Vector<String>(); if (channelContext) { pollingFrequencyTypeComboBox.setSelectedItem(POLLING_FREQUENCY_SECONDS); pollingFrequencyField.setText("5"); row.add(defaultCronJob); row.add("Run every 5 seconds."); } else { pollingFrequencyTypeComboBox.setSelectedItem(POLLING_FREQUENCY_HOURS); pollingFrequencyField.setText("1"); row.add("0 0 */1 * * ?"); row.add("Run hourly."); } model.addRow(row); cachedAdvancedConnectorProperties = new PollConnectorPropertiesAdvanced(); }