Skip to content

Commit

Permalink
Remove deprecated awt apple extension
Browse files Browse the repository at this point in the history
Closes: #10
  • Loading branch information
ghusta committed Nov 30, 2023
1 parent 54b10da commit 51c1673
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 57 deletions.
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,6 @@
<version>1.6.0</version>
</dependency>

<!-- Apple java extensions (to use a custom icon in the Mac Dock) -->
<dependency>
<groupId>com.apple</groupId>
<artifactId>AppleJavaExtensions</artifactId>
<version>1.4</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down
60 changes: 26 additions & 34 deletions src/main/java/com/nilhcem/fakesmtp/FakeSMTP.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
package com.nilhcem.fakesmtp;

import java.awt.EventQueue;
import java.awt.Toolkit;
import java.net.InetAddress;
import java.net.URL;
import java.net.UnknownHostException;

import javax.swing.UIManager;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.ParseException;

import com.apple.eawt.Application;
import com.nilhcem.fakesmtp.core.ArgsHandler;
import com.nilhcem.fakesmtp.core.Configuration;
import com.nilhcem.fakesmtp.core.exception.UncaughtExceptionHandler;
import com.nilhcem.fakesmtp.gui.MainFrame;
import com.nilhcem.fakesmtp.server.SMTPServerHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.cli.ParseException;

import javax.swing.*;
import java.awt.*;
import java.net.InetAddress;
import java.net.UnknownHostException;

/**
* Entry point of the application.
Expand All @@ -27,6 +22,12 @@
@Slf4j
public final class FakeSMTP {

public static final String OS_NAME = System.getProperty("os.name", "");
/**
* See : org.apache.commons.lang3.SystemUtils#IS_OS_MAC
*/
public static final boolean IS_OS_MAC = OS_NAME.startsWith("Mac");

private FakeSMTP() {
throw new UnsupportedOperationException();
}
Expand Down Expand Up @@ -75,31 +76,22 @@ public static void main(final String[] args) {
System.setProperty("mail.mime.decodetext.strict", "false");
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler());

EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
try {
URL envelopeImage = getClass().getResource(Configuration.INSTANCE.get("application.icon.path"));
if (envelopeImage != null) {
Application.getApplication().setDockIconImage(Toolkit.getDefaultToolkit().getImage(envelopeImage));
}
} catch (RuntimeException e) {
log.debug("Error: {} - This is probably because we run on a non-Mac platform and these components are not implemented", e.getMessage());
} catch (Exception e) {
log.error("", e);
}

EventQueue.invokeLater(() -> {
if (IS_OS_MAC) {
// see (written in 2003) : https://www.oracle.com/technical-resources/articles/javase/javatomac.html
// see also : https://bugs.openjdk.org/browse/JDK-8188085
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", Configuration.INSTANCE.get("application.name"));
UIManager.put("swing.boldMetal", Boolean.FALSE);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
log.error("", e);
}

new MainFrame();
}
UIManager.put("swing.boldMetal", Boolean.FALSE);
try {
// see : https://docs.oracle.com/javase/tutorial/uiswing/lookandfeel/
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
log.error("", e);
}

new MainFrame();
});
}
}
Expand Down
18 changes: 2 additions & 16 deletions src/main/java/com/nilhcem/fakesmtp/gui/info/NbReceivedLabel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@
import com.nilhcem.fakesmtp.model.UIModel;
import com.nilhcem.fakesmtp.server.MailSaver;

import com.apple.eawt.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import lombok.extern.slf4j.Slf4j;

/**
* Label class to display the number of received emails.
*
* @author Nilhcem
* @since 1.0
*/
@Slf4j
public final class NbReceivedLabel implements Observer {

private static final Logger LOGGER = LoggerFactory.getLogger(NbReceivedLabel.class);

private final JLabel nbReceived = new JLabel("0");

/**
Expand Down Expand Up @@ -64,22 +61,11 @@ public void update(Observable o, Object arg) {
String countMsgStr = Integer.toString(countMsg);

model.setNbMessageReceived(countMsg);
updateDockIconBadge(countMsgStr);
nbReceived.setText(countMsgStr);
} else if (o instanceof ClearAllButton) {
UIModel.INSTANCE.setNbMessageReceived(0);
updateDockIconBadge("");
nbReceived.setText("0");
}
}

private void updateDockIconBadge(String badgeValue) {
try {
Application.getApplication().setDockIconBadge(badgeValue);
} catch (RuntimeException e) {
LOGGER.debug("Error: {} - This is probably because we run on a non-Mac platform and these components are not implemented", e.getMessage());
} catch (Exception e) {
LOGGER.error("", e);
}
}
}

0 comments on commit 51c1673

Please sign in to comment.