From: Harishankar Date: Thu, 2 Apr 2020 13:44:50 +0000 (+0530) Subject: Reporting Functionality - resizing columns to content width X-Git-Url: https://harishankar.org/repos/?a=commitdiff_plain;h=2d04b06ea9a39c05dd3db560f3fc573696c7e36e;p=habeas.git Reporting Functionality - resizing columns to content width Functionality to resize columns to content width in the report screen. --- diff --git a/src/habeas/MainFrame.form b/src/habeas/MainFrame.form index b91160d..1531f25 100644 --- a/src/habeas/MainFrame.form +++ b/src/habeas/MainFrame.form @@ -62,6 +62,14 @@ + + + + + + + + diff --git a/src/habeas/MainFrame.java b/src/habeas/MainFrame.java index 3e84430..070a7f7 100644 --- a/src/habeas/MainFrame.java +++ b/src/habeas/MainFrame.java @@ -39,6 +39,7 @@ public class MainFrame extends javax.swing.JFrame { jSeparator1 = new javax.swing.JPopupMenu.Separator(); menuGenerateRaisedBills = new javax.swing.JMenuItem(); menuNoticesReports = new javax.swing.JMenu(); + menuNoticesToBeDrafted = new javax.swing.JMenuItem(); menuNoticesClarificationPending = new javax.swing.JMenuItem(); menuNoticeDraftAwaitingApproval = new javax.swing.JMenuItem(); menuNoticesSentNotYetDelivered = new javax.swing.JMenuItem(); @@ -99,6 +100,14 @@ public class MainFrame extends javax.swing.JFrame { menuNoticesReports.setMnemonic('r'); menuNoticesReports.setText("Reports"); + menuNoticesToBeDrafted.setText("To Be Drafted..."); + menuNoticesToBeDrafted.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent evt) { + menuNoticesToBeDraftedActionPerformed(evt); + } + }); + menuNoticesReports.add(menuNoticesToBeDrafted); + menuNoticesClarificationPending.setMnemonic('c'); menuNoticesClarificationPending.setText("Clarifications pending..."); menuNoticesClarificationPending.addActionListener(new java.awt.event.ActionListener() { @@ -271,6 +280,23 @@ public class MainFrame extends javax.swing.JFrame { frm.setupReportTable(rep, REPORT_TITLE_CLARIFICATIONS_PENDING, cols, data); frm.setVisible(true); }//GEN-LAST:event_menuNoticesClarificationPendingActionPerformed + + private void menuNoticesToBeDraftedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuNoticesToBeDraftedActionPerformed + // TODO add your handling code here: + NoticesReportViewDialog frm = new NoticesReportViewDialog(this, false); + String cols[] = {"Reference Number", "Description", "Entrustment Date", + "Clarification Remarks", "Client" }; + int rep = 4; + ArrayList data = Utility.getReportData(rep, -1); + if (data == null) { + JOptionPane.showMessageDialog(this , ERROR_DISPLAYING_REPORT); + return; + } + frm.setupReportTable(rep, REPORT_TITLE_TO_BE_DRAFTED, cols, data); + frm.setVisible(true); + + }//GEN-LAST:event_menuNoticesToBeDraftedActionPerformed + private static final String REPORT_TITLE_TO_BE_DRAFTED = "To Be Drafted"; private static final String REPORT_TITLE_CLARIFICATIONS_PENDING = "Clarifications Pending"; private static final String REPORT_TITLE_DRAFTS_AWAITING_APPROVAL = "Drafts To Be Approved"; public static final String REPORT_TITLE_NOTICES_SENT_NOT_DELIVERED = "Notices Sent Not Yet Delivered"; @@ -327,6 +353,7 @@ public class MainFrame extends javax.swing.JFrame { private javax.swing.JMenuItem menuNoticesClarificationPending; private javax.swing.JMenu menuNoticesReports; private javax.swing.JMenuItem menuNoticesSentNotYetDelivered; + private javax.swing.JMenuItem menuNoticesToBeDrafted; private javax.swing.JMenu menuSettings; private javax.swing.JMenuItem menuStationery; // End of variables declaration//GEN-END:variables diff --git a/src/habeas/NoticesReportViewDialog.form b/src/habeas/NoticesReportViewDialog.form index 0cb16bc..2503a57 100644 --- a/src/habeas/NoticesReportViewDialog.form +++ b/src/habeas/NoticesReportViewDialog.form @@ -56,9 +56,9 @@ - + - + @@ -100,10 +100,14 @@ + + + + diff --git a/src/habeas/NoticesReportViewDialog.java b/src/habeas/NoticesReportViewDialog.java index 2636cbc..8852409 100644 --- a/src/habeas/NoticesReportViewDialog.java +++ b/src/habeas/NoticesReportViewDialog.java @@ -5,12 +5,17 @@ */ package habeas; +import java.awt.Component; import java.util.ArrayList; import javax.swing.JFileChooser; import javax.swing.JOptionPane; +import javax.swing.JTable; import javax.swing.filechooser.FileFilter; import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableCellRenderer; +import javax.swing.table.TableColumn; +import javax.swing.table.TableColumnModel; /** * @@ -77,7 +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) @@ -228,7 +235,6 @@ public class NoticesReportViewDialog extends javax.swing.JDialog { } }; tableReport.setModel(mdl); - tableReport.setComponentPopupMenu(popMenu); labelReportTitle.setText(title); populateReport (); @@ -242,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() { diff --git a/src/habeas/Utility.java b/src/habeas/Utility.java index d54ace3..9df1ab5 100644 --- a/src/habeas/Utility.java +++ b/src/habeas/Utility.java @@ -38,8 +38,11 @@ public class Utility { "SELECT ReferenceNumber, Description, EntrustmentDate, " + "ClarificationRemarks, ClientName FROM legalnotices INNER JOIN clients ON" - + " ClientId=clients.id WHERE ClarificationPending=1;" + + " ClientId=clients.id WHERE ClarificationPending=1;", + "SELECT ReferenceNumber, Description, EntrustmentDate, ClarificationRemarks" + + ", ClientName from legalnotices INNER JOIN clients ON ClientId=clients.id " + + "WHERE DraftCreated=0;" } ; private static final String[] REPORTS_FILTERED = { "SELECT ReferenceNumber, Description" @@ -57,7 +60,11 @@ public class Utility { "SELECT ReferenceNumber, Description, EntrustmentDate, " + "ClarificationRemarks, ClientName FROM legalnotices INNER JOIN clients ON" - + " ClientId=clients.id WHERE ClarificationPending=1 AND ClientId=?;" + + " ClientId=clients.id WHERE ClarificationPending=1 AND ClientId=?;", + + "SELECT ReferenceNumber, Description, EntrustmentDate, ClarificationRemarks" + + ", ClientName from legalnotices INNER JOIN clients ON ClientId=clients.id " + + "WHERE DraftCreated=0 AND ClientId=?;" } ; static void saveStationerySettings (String left_header,