Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
j-dimension committed Dec 15, 2024
1 parent ee860bb commit 524367e
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2253,32 +2253,27 @@ private StyledCalculationTable getTimesheetSummaryAsTable(List<TimesheetPosition
}

StyledCalculationTable ct = new StyledCalculationTable();
SimpleDateFormat dfDateTime = null;
DecimalFormat currencyFormat=null;
if ("EN".equalsIgnoreCase(language)) {
ct.addHeaders("Person", "Duration", "Total");
dfDateTime = new SimpleDateFormat("MM/dd/yyyy");
currencyFormat=new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.US));
} else if ("FR".equalsIgnoreCase(language)) {
ct.addHeaders("Personne", "Durée", "Somme");
dfDateTime = new SimpleDateFormat("dd/MM/yyyy");
currencyFormat=new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.FRANCE));
} else if ("NL".equalsIgnoreCase(language)) {
ct.addHeaders("Persoon", "Tijd", "Totaal");
dfDateTime = new SimpleDateFormat("dd-MM-yyyy");
currencyFormat=new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(new Locale("nl", "NL")));
} else {
ct.addHeaders("Person", "Dauer", "Total");
dfDateTime = new SimpleDateFormat("dd.MM.yyyy");
currencyFormat=new DecimalFormat("#,##0.00", DecimalFormatSymbols.getInstance(Locale.GERMANY));
}

if (ServerSettings.getInstance().getSettingAsBoolean("plugins.global.tableproperties.table.emptyRows", true)) {
ct.addRow("", "", "");
}

HashMap<String,Long> personMillis=new HashMap();
HashMap<String,BigDecimal> personTotal=new HashMap();
HashMap<String,Long> personMillis=new HashMap<>();
HashMap<String,BigDecimal> personTotal=new HashMap<>();
for (TimesheetPosition pos : posList) {

long millis=pos.getStopped().getTime() - pos.getStarted().getTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 {
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> folderNameMapping = new HashMap<>();
Expand Down Expand Up @@ -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();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -791,15 +781,13 @@ 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)) {
if (currentRestriction.getRestriction() == LoadFolderRestriction.RESTRICTION_UNREAD) {
// 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);
Expand Down Expand Up @@ -828,31 +816,25 @@ 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();
fpUid.add(UIDFolder.FetchProfileItem.UID);
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<String, String> decodedMap = new HashMap<>();
final int indexMax = messages.length - 1;
ArrayList<Object[]> tableRows = new ArrayList<>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -703,8 +702,7 @@ public MailboxAccess findByUserAndMailbox(String principalId, String mailboxId)
@Override
public List<MailboxAccess> findByUser(String principalId) {
try {
List<MailboxAccess> gm = (List<MailboxAccess>) em.createNamedQuery("MailboxAccess.findByPrincipalId").setParameter("principalId", principalId).getResultList();
return gm;
return (List<MailboxAccess>) em.createNamedQuery("MailboxAccess.findByPrincipalId").setParameter("principalId", principalId).getResultList();
} catch (NoResultException nre) {
return null;
}
Expand All @@ -714,8 +712,7 @@ public List<MailboxAccess> findByUser(String principalId) {
@Override
public List<MailboxAccess> findByMailbox(String mailboxId) {
try {
List<MailboxAccess> gm = (List<MailboxAccess>) em.createNamedQuery("MailboxAccess.findByMailboxId").setParameter("mailboxId", mailboxId).getResultList();
return gm;
return (List<MailboxAccess>) em.createNamedQuery("MailboxAccess.findByMailboxId").setParameter("mailboxId", mailboxId).getResultList();
} catch (NoResultException nre) {
return new ArrayList<>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -692,8 +692,7 @@ protected EntityManager getEntityManager() {
@Override
public List<MailboxSetup> findByMsExchange(boolean exchange) {
try {
List<MailboxSetup> gm = (List<MailboxSetup>) em.createNamedQuery("MailboxSetup.findByMsExchange").setParameter("msExchange", exchange).getResultList();
return gm;
return (List<MailboxSetup>) em.createNamedQuery("MailboxSetup.findByMsExchange").setParameter("msExchange", exchange).getResultList();
} catch (NoResultException nre) {
return new ArrayList<>();
}
Expand Down

0 comments on commit 524367e

Please sign in to comment.