From 524367ee02d870c6aa66ab5cb17083cddf01ddfd Mon Sep 17 00:00:00 2001 From: j-dimension Date: Sun, 15 Dec 2024 23:45:06 +0100 Subject: [PATCH] code cleanup --- .../viewer/PdfImageScrollingPanel.java | 39 +++++++++++++------ .../client/editors/files/InvoiceDialog.java | 9 +---- .../jlawyer/client/mail/EmailInboxPanel.java | 3 -- .../jlawyer/client/mail/FolderContainer.java | 38 +++++++++++------- .../jlawyer/client/mail/LoadFolderAction.java | 23 ----------- .../persistence/MailboxAccessFacade.java | 9 ++--- .../persistence/MailboxSetupFacade.java | 3 +- 7 files changed, 59 insertions(+), 65 deletions(-) diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java index c39cbc72..813103c5 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/documents/viewer/PdfImageScrollingPanel.java @@ -681,7 +681,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.HashMap; -import java.util.logging.Level; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JOptionPane; @@ -1098,9 +1097,15 @@ private void sliderZoomStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FI width = (int) (width / (297f / 210f)); } - BufferedImage scaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); + BufferedImage scaledImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = scaledImage.createGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + //g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g2d.drawImage(img, 0, 0, width, height, null); g2d.dispose(); @@ -1235,7 +1240,7 @@ private synchronized void renderContent(int currentIndex, int fromPageIndex, int rendering = true; for (int i = fromIndex; i <= toIndex; i++) { try { - BufferedImage buffImg = pdfRenderer.renderImageWithDPI(i, dpi, ImageType.RGB); + BufferedImage buffImg = pdfRenderer.renderImageWithDPI(i, dpi, ImageType.ARGB); orgImage.put(i, saveBufferedImage(buffImg)); // need to subtract the height of the page navigation buttons, but // the panel has not been layed out yet, so there is no height we could query @@ -1252,9 +1257,15 @@ private synchronized void renderContent(int currentIndex, int fromPageIndex, int } // todo: check for landscape mode and display those pages with lower height - BufferedImage scaledImage = new BufferedImage(width1, height1, BufferedImage.TYPE_INT_RGB); + BufferedImage scaledImage = new BufferedImage(width1, height1, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = scaledImage.createGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + //g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g2d.drawImage(buffImg, 0, 0, width1, height1, null); g2d.dispose(); @@ -1316,10 +1327,10 @@ public static int calculateDpi(int totalPages) { int minDpi = 120; // macOS has a default scale factor of 2 - assume HiDPI for all Macs - if(SystemUtils.isMacOs()) { + if (SystemUtils.isMacOs()) { return 300; } - + String uiScale = System.getProperty("sun.java2d.uiScale"); try { if (uiScale != null && Double.parseDouble(uiScale) > 1.0) { @@ -1330,7 +1341,7 @@ public static int calculateDpi(int totalPages) { } catch (Throwable t) { log.warn("unable to get UI scale factor", t); } - + if (totalPages <= 20) { return 200; } @@ -1515,9 +1526,15 @@ public void rotatePage(int[] pageIndexes, int degrees) { width1 = (int) (width1 / (297f / 210f)); } - BufferedImage bi2 = new BufferedImage(width1, height1, BufferedImage.TYPE_INT_RGB); + BufferedImage bi2 = new BufferedImage(width1, height1, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = bi2.createGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + //g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); + g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); + g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY); + g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); + g2d.drawImage(rotated, 0, 0, width1, height1, null); g2d.dispose(); diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java index 9e5561f7..b169d95a 100644 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/editors/files/InvoiceDialog.java @@ -2253,23 +2253,18 @@ private StyledCalculationTable getTimesheetSummaryAsTable(List personMillis=new HashMap(); - HashMap personTotal=new HashMap(); + HashMap personMillis=new HashMap<>(); + HashMap personTotal=new HashMap<>(); for (TimesheetPosition pos : posList) { long millis=pos.getStopped().getTime() - pos.getStarted().getTime(); diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java index 4ef2cb29..0bfdb139 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/EmailInboxPanel.java @@ -910,7 +910,6 @@ private void connect(boolean showErrorDialogOnFailure, MailboxSetup ms) throws E server = ms.getEmailInServer(); if(ms.isMsExchange()) { - //String authToken = MsExchangeUtils.getAuthToken(ms.getTenantId(), ms.getClientId(), ms.getClientSecret(), ms.getEmailInUser(), emailInPwd); String authToken = EmailUtils.getOffice365AuthToken(ms.getId()); props.put("mail.imaps.sasl.enable", "true"); props.put("mail.imaps.port", "993"); @@ -932,7 +931,6 @@ private void connect(boolean showErrorDialogOnFailure, MailboxSetup ms) throws E store = session.getStore("imaps"); // server should be outlook.office365.com this.stores.put(ms, store); - //store.connect(server, ms.getEmailInUser(), "Bearer " + authToken); store.connect(server, ms.getEmailInUser(), authToken); } else { @@ -2604,7 +2602,6 @@ private void displayMessage() { ClientSettings settings = ClientSettings.getInstance(); try { DefaultMutableTreeNode selNode = (DefaultMutableTreeNode) this.treeFolders.getSelectionPath().getLastPathComponent(); - //MailboxSetup ms = EmailUtils.getMailboxSetup(msgC.getMessage()); MailboxSetup ms = this.getMailboxSetup(selNode); this.mailContentUI.setMessage(msgC, ms); diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java index 95b50b1b..72ddc461 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/FolderContainer.java @@ -689,6 +689,8 @@ public class FolderContainer { private long cachedUnreadUpdated = -1; private int cachedUnread = -1; private int cachedTotal = -1; + + private String mappedName=null; private static final Logger log = Logger.getLogger(FolderContainer.class.getName()); private static final HashMap folderNameMapping = new HashMap<>(); @@ -791,30 +793,40 @@ public String toString() { if (this.cachedToStringUpdated == -1 || ((System.currentTimeMillis() - cachedToStringUpdated) > this.getRetentionTime())) { try { - String name = this.folder.getName(); + if (this.mappedName == null) { + this.mappedName = this.folder.getName(); - Set mapKey = folderNameMapping.keySet(); - Iterator mIt = mapKey.iterator(); - while (mIt.hasNext()) { - String k = mIt.next().toString(); - if (k.equalsIgnoreCase(name)) { - name = folderNameMapping.get(k); - break; + Set mapKey = folderNameMapping.keySet(); + Iterator mIt = mapKey.iterator(); + while (mIt.hasNext()) { + String k = mIt.next().toString(); + if (k.equalsIgnoreCase(this.mappedName)) { + this.mappedName = folderNameMapping.get(k); + break; + } } } - int msgCount = this.folder.getMessageCount(); - //int msgCount = this.getUnreadMessageCount(); + int msgCount=this.folder.getMessageCount(); + cachedToStringUpdated = System.currentTimeMillis(); if (msgCount < 0) { - cachedToString = name; + cachedToString = this.mappedName; } else { - cachedToString = name + " (" + msgCount + ")"; + cachedToString = this.mappedName + " (" + msgCount + ")"; } } catch (Exception ex) { log.error(ex); - cachedToString = this.folder.getName(); + + // only set to folder name if not initialized + if(cachedToString==null) { + if(this.mappedName==null) + cachedToString = this.folder.getName(); + else + cachedToString = this.mappedName; + } + cachedToStringUpdated = System.currentTimeMillis(); } } diff --git a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java index e68502e2..c01827f6 100755 --- a/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java +++ b/j-lawyer-client/src/com/jdimension/jlawyer/client/mail/LoadFolderAction.java @@ -743,19 +743,9 @@ public int getMin() { @Override public boolean execute() throws Exception { try { - //long start=System.currentTimeMillis(); - if (!(f.getFolder().isOpen())) { f.getFolder().open(Folder.READ_WRITE); } -// try { -// if (EmailUtils.isIMAP(f)) { -// f.expunge(); -// } -// } catch (Throwable t) { -// log.error("Could not expunge folder", t); -// } - //System.out.println("load 20 = " + (System.currentTimeMillis() - start)); ClientSettings cs = ClientSettings.getInstance(); String restriction = cs.getConfiguration(ClientSettings.CONF_MAIL_DOWNLOADRESTRICTION, "" + LoadFolderRestriction.RESTRICTION_50); @@ -791,7 +781,6 @@ public boolean execute() throws Exception { break; } - //System.out.println("load 30 = " + (System.currentTimeMillis() - start)); Message[] messages = null; FlagTerm notDeleted = new FlagTerm(new Flags(Flags.Flag.DELETED), false); if (StringUtils.isEmpty(this.searchTerm)) { @@ -799,7 +788,6 @@ public boolean execute() throws Exception { // Combine unread filter with notDeleted filter FlagTerm unread = new FlagTerm(new Flags(Flags.Flag.SEEN), false); AndTerm filter = new AndTerm(unread, notDeleted); - //messages = f.getFolder().search(filter, messages); messages = f.getFolder().search(filter); } else { messages = f.getFolder().getMessages(fromIndex, toIndex); @@ -828,8 +816,6 @@ public boolean execute() throws Exception { .limit(maxQuantity+1) .toArray(Message[]::new); - //System.out.println("load 40 = " + (System.currentTimeMillis() - start)); - if (f.getFolder() instanceof UIDFolder) { // get all the UIDs FetchProfile fpUid = new FetchProfile(); @@ -837,22 +823,18 @@ public boolean execute() throws Exception { f.getFolder().fetch(messages, fpUid); } - //System.out.println("load 50 = " + (System.currentTimeMillis() - start)); Message[] uncachedMessages = f.getUncachedMessages(messages); - //System.out.println("load 60 = " + (System.currentTimeMillis() - start)); FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.FLAGS); f.getFolder().fetch(uncachedMessages, fp); - //System.out.println("load 70 = " + (System.currentTimeMillis() - start)); f.addCachedMessages(uncachedMessages); messages=f.getCachedMessages(messages); - //System.out.println("load 80 = " + (System.currentTimeMillis() - start)); HashMap decodedMap = new HashMap<>(); final int indexMax = messages.length - 1; ArrayList tableRows = new ArrayList<>(); @@ -926,7 +908,6 @@ public boolean execute() throws Exception { Object[] newRow = new Object[]{new MessageContainer(msg, msg.getSubject(), msg.isSet(Flags.Flag.SEEN)), from, toString, sentString}; tableRows.add(newRow); - //if (((i % 100) == 0 && i > 0) || i == (messages.length - 1) || (i == (messages.length - 1) && i<100 && messages.length>maxQuantity)) { if (((i % 100) == 0 && i > 0) || i == (messages.length - 1)) { final int currentIndex = i; @@ -958,9 +939,6 @@ public boolean execute() throws Exception { } } - //System.out.println("load 90 = " + (System.currentTimeMillis() - start)); - - SwingUtilities.invokeLater(() -> { try { table.getRowSorter().toggleSortOrder(this.sortCol); @@ -971,7 +949,6 @@ public boolean execute() throws Exception { ComponentUtils.autoSizeColumns(table, 0); }); - //System.out.println("load 100 = " + (System.currentTimeMillis() - start)); new Thread(() -> { try { Thread.sleep(5000); diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxAccessFacade.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxAccessFacade.java index e414fc4f..efeaacc3 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxAccessFacade.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxAccessFacade.java @@ -692,8 +692,7 @@ public MailboxAccessFacade() { @Override public MailboxAccess findByUserAndMailbox(String principalId, String mailboxId) { try { - MailboxAccess gm = (MailboxAccess) em.createNamedQuery("MailboxAccess.findByPrincipalIdAndMailboxId").setParameter("principalId", principalId).setParameter("mailboxId", mailboxId).getSingleResult(); - return gm; + return (MailboxAccess) em.createNamedQuery("MailboxAccess.findByPrincipalIdAndMailboxId").setParameter("principalId", principalId).setParameter("mailboxId", mailboxId).getSingleResult(); } catch (NoResultException nre) { return null; } @@ -703,8 +702,7 @@ public MailboxAccess findByUserAndMailbox(String principalId, String mailboxId) @Override public List findByUser(String principalId) { try { - List gm = (List) em.createNamedQuery("MailboxAccess.findByPrincipalId").setParameter("principalId", principalId).getResultList(); - return gm; + return (List) em.createNamedQuery("MailboxAccess.findByPrincipalId").setParameter("principalId", principalId).getResultList(); } catch (NoResultException nre) { return null; } @@ -714,8 +712,7 @@ public List findByUser(String principalId) { @Override public List findByMailbox(String mailboxId) { try { - List gm = (List) em.createNamedQuery("MailboxAccess.findByMailboxId").setParameter("mailboxId", mailboxId).getResultList(); - return gm; + return (List) em.createNamedQuery("MailboxAccess.findByMailboxId").setParameter("mailboxId", mailboxId).getResultList(); } catch (NoResultException nre) { return new ArrayList<>(); } diff --git a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxSetupFacade.java b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxSetupFacade.java index 951f480c..4884e748 100644 --- a/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxSetupFacade.java +++ b/j-lawyer-server/j-lawyer-server-ejb/src/java/com/jdimension/jlawyer/persistence/MailboxSetupFacade.java @@ -692,8 +692,7 @@ protected EntityManager getEntityManager() { @Override public List findByMsExchange(boolean exchange) { try { - List gm = (List) em.createNamedQuery("MailboxSetup.findByMsExchange").setParameter("msExchange", exchange).getResultList(); - return gm; + return (List) em.createNamedQuery("MailboxSetup.findByMsExchange").setParameter("msExchange", exchange).getResultList(); } catch (NoResultException nre) { return new ArrayList<>(); }