X-Git-Url: https://harishankar.org/repos/?p=habeas.git;a=blobdiff_plain;f=src%2Fhabeas%2FNoticesReportViewDialog.java;h=8852409f511531cdc2cbfcbd7a90b46d40d49a84;hp=64f5536c580d61bab9668f0297db2c876d90f1f0;hb=2d04b06ea9a39c05dd3db560f3fc573696c7e36e;hpb=06a2c4c692e08fdc860e489c86f34b2fe64696d1 diff --git a/src/habeas/NoticesReportViewDialog.java b/src/habeas/NoticesReportViewDialog.java index 64f5536..8852409 100644 --- a/src/habeas/NoticesReportViewDialog.java +++ b/src/habeas/NoticesReportViewDialog.java @@ -5,6 +5,7 @@ */ package habeas; +import java.awt.Component; import java.util.ArrayList; import javax.swing.JFileChooser; import javax.swing.JOptionPane; @@ -12,7 +13,9 @@ import javax.swing.JTable; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel; -import javax.swing.table.TableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; /** * @@ -20,6 +23,7 @@ import javax.swing.table.TableModel; */ public class NoticesReportViewDialog extends javax.swing.JDialog { + private int currentReport; private String reportTitle; private String[] reportCols; private ArrayList reportData; @@ -78,6 +82,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { } )); + tableReport.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); + tableReport.setCellSelectionEnabled(true); + tableReport.setComponentPopupMenu(popMenu); jScrollPane2.setViewportView(tableReport); checkFilterByClient.setText("Filter by Client"); @@ -103,9 +110,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { .addContainerGap() .addComponent(checkFilterByClient, javax.swing.GroupLayout.PREFERRED_SIZE, 196, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(comboClients, javax.swing.GroupLayout.PREFERRED_SIZE, 322, javax.swing.GroupLayout.PREFERRED_SIZE) + .addComponent(comboClients, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) - .addComponent(buttonApply, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addComponent(buttonApply, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -144,15 +151,16 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { private void buttonApplyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonApplyActionPerformed // TODO add your handling code here: if (! checkFilterByClient.isSelected()) { - reportData = Utility.getPendingPaymentBills(-1); - if (reportData != null) + reportData = Utility.getReportData(currentReport, -1); + + if (reportData != null) populateReport(); } else { DBItem db = (DBItem)comboClients.getSelectedItem(); if (db == null) return; int selid = db.getKey(); - reportData = Utility.getPendingPaymentBills(selid); + reportData = Utility.getReportData(currentReport, selid); if (reportData != null) populateReport(); } @@ -214,8 +222,9 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { private javax.swing.JTable tableReport; // End of variables declaration//GEN-END:variables - public void setupReportTable(String title, String[] columns, + public void setupReportTable(int reportNum, String title, String[] columns, ArrayList data) { + currentReport = reportNum; reportTitle = title; reportCols = columns; reportData = data; @@ -226,7 +235,6 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { } }; tableReport.setModel(mdl); - tableReport.setComponentPopupMenu(popMenu); labelReportTitle.setText(title); populateReport (); @@ -240,8 +248,27 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { for (int j = 0; j < reportCols.length; j ++) row[j] = reportData.get(i+j); mdl.addRow (row); - } + // resize the column widths to content size + for (int i = 0; i < tableReport.getColumnCount(); i ++) { + + TableColumn clm = tableReport.getColumnModel().getColumn (i); + int preferredWidth = clm.getMinWidth()+10; + int maxWidth = 300; + int minWidth = 100; + for (int r = 0; r < tableReport.getRowCount(); r ++) { + TableCellRenderer rend = tableReport.getCellRenderer(r, i); + Component c = tableReport.prepareRenderer(rend, r, i); + int width = c.getPreferredSize().width + tableReport.getIntercellSpacing().width; + preferredWidth = Math.max (preferredWidth, width+10); + if (preferredWidth >= maxWidth) + { + preferredWidth = maxWidth; + break; + } + } + clm.setPreferredWidth(Math.max(minWidth, preferredWidth)); + } } private void populateClients() {