Skip to content

Commit

Permalink
Better OSX integration
Browse files Browse the repository at this point in the history
  • Loading branch information
santiagolizardo committed Nov 13, 2016
1 parent 26df199 commit 276312a
Show file tree
Hide file tree
Showing 17 changed files with 229 additions and 76 deletions.
24 changes: 24 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

## [1.4.9] - 2016-11-13

### Added

- Better menubar integration on MacOS
- Validation of number of lines improved (negative numbers are rejected)
- Better menubar integration on Mac OS X

### Changed

- URLs pointing to SourceForge updated to point to Github

### Fixed

- Broken unit test

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.santiagolizardo.neocommander</groupId>
<artifactId>NeoCommander</artifactId>
<version>1.4.8</version>
<version>1.4.9</version>
<packaging>jar</packaging>
<name>NeoCommander</name>
<url>https://github.com/santiagolizardo/neocommander</url>
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/santiagolizardo/madcommander/AppConstants.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* This file is part of MadCommander, a file manager with two panels.
*
* MadCommander is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MadCommander is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MadCommander. If not, see <http://www.gnu.org/licenses/>.
*/
package com.santiagolizardo.madcommander;

public final class AppConstants {

private AppConstants() {

}

public final static String APP_NAME = "NeoCommander";
public final static String APP_VERSION = "1.4.9";
public final static String APP_URL = "https://github.com/santiagolizardo/neocommander";
public final static String DOWNLOAD_URL = "https://github.com/santiagolizardo/neocommander/releases";

}
15 changes: 13 additions & 2 deletions src/main/java/com/santiagolizardo/madcommander/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import com.santiagolizardo.madcommander.config.ConfigHandler;
import com.santiagolizardo.madcommander.resources.languages.Translator;
import com.santiagolizardo.madcommander.services.LoggingServices;
import com.santiagolizardo.madcommander.util.Os;
import com.santiagolizardo.madcommander.util.OsDetector;
import com.santiagolizardo.madcommander.util.gui.SwingUtil;
import java.io.IOException;

Expand All @@ -42,15 +44,24 @@ public static void main(String[] args) {
final ConfigData configData = configHandler.read();

Translator.start(configData.getLanguage());

// LockManager.check();

try {
if (OsDetector.get().equals(Os.Osx)) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", AppConstants.APP_NAME);
}
} catch(Exception e) {
System.err.println(e.getMessage());
}

/*
* We put the main frame in the event-dispatching thread
*/
SwingUtilities.invokeLater(() -> {
SwingUtil.setSystemLookAndFeel();

MainWindow app = new MainWindow();
app.setConfigData(configData);
app.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
@SuppressWarnings("serial")
public class MainWindow extends JFrame {

public final static String APP_NAME = "NeoCommander";
public final static String APP_VERSION = "1.4.8";
public final static String APP_URL = "https://github.com/santiagolizardo/neocommander";

private static final Logger LOGGER = Logger.getLogger(MainWindow.class
.getName());

Expand All @@ -75,7 +71,7 @@ public class MainWindow extends JFrame {
public MainWindow() {
super();

setTitle(APP_NAME + " " + APP_VERSION);
setTitle(AppConstants.APP_NAME + " " + AppConstants.APP_VERSION);
setIconImage(IconFactory.newIcon("icon.png").getImage());

currentPanel = Position.Left;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.santiagolizardo.madcommander.dialogs;

import com.santiagolizardo.madcommander.AppConstants;
import javax.swing.JLabel;

import com.santiagolizardo.madcommander.MainWindow;
Expand Down Expand Up @@ -61,10 +62,10 @@ private void defineLayout() {
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

String headlineText = String.format("<h1>%s <em>v%s</em></h1>",
MainWindow.APP_NAME, MainWindow.APP_VERSION);
AppConstants.APP_NAME, AppConstants.APP_VERSION);
String infoText = String.format("<p>%s</p>", String.format(
Translator.tr("More info about the project at <a href=\"%s\">%s</a>."),
MainWindow.APP_URL, MainWindow.APP_URL));
AppConstants.APP_URL, AppConstants.APP_URL));
String creditsText = ResourcesLoader.readResource(AboutDialog.class,
"credits.html");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.santiagolizardo.madcommander.dialogs.progressive;

import com.santiagolizardo.madcommander.AppConstants;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
Expand Down Expand Up @@ -68,7 +69,7 @@ public AbstractProgressDialog(MainWindow mainWindow) {

this.mainWindow = mainWindow;

setTitle(MainWindow.APP_NAME);
setTitle(AppConstants.APP_NAME);
setModal(true);
setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
setResizable(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.santiagolizardo.madcommander.menu;

import com.santiagolizardo.madcommander.AppConstants;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
Expand Down Expand Up @@ -69,7 +70,7 @@ public void actionPerformed(ActionEvent ev) {
Object source = ev.getSource();

if (source == visitJavaCommanderWebSite) {
SystemUtil.browse(this, MainWindow.APP_URL);
SystemUtil.browse(this, AppConstants.APP_URL);
} else if (source == checkForUpdate) {
UpdateManager.checkForUpdate();
} else if (source == aboutJavaCommander) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package com.santiagolizardo.madcommander.util;

import com.santiagolizardo.madcommander.AppConstants;
import java.io.File;
import java.io.IOException;
import java.util.logging.Logger;
Expand All @@ -25,9 +26,9 @@

/**
* Controls if the application can run multiple instances at the same time.
*
*
* @author Santiago Lizardo
*
*
*/
public final class LockManager {

Expand All @@ -43,7 +44,7 @@ public static void check() throws IOException {
if (!allowInstances) {
String tempDir = System.getProperty("java.io.tmpdir");
String lockPath = tempDir.concat(File.separator)
.concat(MainWindow.APP_NAME).concat(".lock");
.concat(AppConstants.APP_NAME).concat(".lock");
LOGGER.info(lockPath);

File lock = new File(lockPath);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* This file is part of MadCommander, a file manager with two panels.
*
* MadCommander is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MadCommander is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MadCommander. If not, see <http://www.gnu.org/licenses/>.
*/
package com.santiagolizardo.madcommander.util;

public class OsDetector {

private static Os currentOs = null;

public static void reset() {
currentOs = null;
}

public static Os get() throws Exception {
if (null != currentOs) {
return currentOs;
}
final String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains("windows")) {
currentOs = Os.Windows;
} else if (osName.contains("linux")) {
currentOs = Os.Linux;
} else if (osName.contains("osx") || osName.contains("os x")) {
currentOs = Os.Osx;
}
if (currentOs == null) {
throw new Exception("Unable to recognize OS with name: " + osName);
}
return currentOs;
}
}
57 changes: 21 additions & 36 deletions src/main/java/com/santiagolizardo/madcommander/util/SystemUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,29 @@
import java.io.IOException;
import java.net.URISyntaxException;


public class SystemUtil {

public static Os getOs() {
String osName = System.getProperty("os.name").toLowerCase();
if(osName.contains("windows")) {
return Os.Windows;
}
if(osName.contains("linux")) {
return Os.Linux;
}
if(osName.contains("osx")) {
return Os.Osx;
}
return null;
}

public static void execute(Component component, String command) {
Runtime runtime = Runtime.getRuntime();
String[] args = new String[3];
args[0] = "cmd.exe";
args[1] = "/C";
args[2] = command;

try {
runtime.exec(args);
} catch (IOException e) {
DialogFactory.showErrorMessage(component, e.getMessage());
}
}
public static void execute(Component component, String command) {
Runtime runtime = Runtime.getRuntime();
String[] args = new String[3];
args[0] = "cmd.exe";
args[1] = "/C";
args[2] = command;

try {
runtime.exec(args);
} catch (IOException e) {
DialogFactory.showErrorMessage(component, e.getMessage());
}
}

public static void browse(Component component, String address) {
Desktop desktop = Desktop.getDesktop();
public static void browse(Component component, String address) {
Desktop desktop = Desktop.getDesktop();

try {
desktop.browse(new URI(address));
} catch (URISyntaxException | IOException e) {
System.err.println(e.getMessage());
}
}
try {
desktop.browse(new URI(address));
} catch (URISyntaxException | IOException e) {
System.err.println(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@
*/
package com.santiagolizardo.madcommander.util;

import com.santiagolizardo.madcommander.AppConstants;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;

import com.santiagolizardo.madcommander.MainWindow;
import com.santiagolizardo.madcommander.util.gui.DialogFactory;
import java.io.IOException;


public final class UpdateManager extends Thread {

public final static String DOWNLOAD_URL = "http://sourceforge.net/projects/madcommander/files/";

public static void checkForUpdate() {
UpdateManager updateManager = new UpdateManager();
Expand All @@ -38,26 +36,25 @@ private UpdateManager() {

}

@Override
public void run() {
try {
URL url = new URL("http://madcommander.sourceforge.net/version.html");
InputStreamReader reader = new InputStreamReader(url.openStream());
BufferedReader buffer = new BufferedReader(reader);
String version = buffer.readLine();
buffer.close();
reader.close();
int serverVersion = Integer.valueOf(version.replaceAll("\\.", ""))
.intValue();
int currentVersion = Integer.valueOf(
MainWindow.APP_VERSION.replaceAll("\\.", "")).intValue();
String version;
try (InputStreamReader reader = new InputStreamReader(url.openStream()); BufferedReader buffer = new BufferedReader(reader)) {
version = buffer.readLine();
}
int serverVersion = Integer
.parseInt(version.replaceAll("\\.", ""));
int currentVersion = Integer.parseInt(AppConstants.APP_VERSION.replaceAll("\\.", ""));
if (serverVersion > currentVersion) {
StringBuilder text = new StringBuilder();
text.append("New version \"");
text.append(version);
text
.append("\" available.\n\nDo you want to go to the download site?\n");
if (DialogFactory.showQuestionDialog(null, text.toString())) {
SystemUtil.browse(null, DOWNLOAD_URL);
SystemUtil.browse(null, AppConstants.DOWNLOAD_URL);
}
} else if (serverVersion <= currentVersion) {
DialogFactory.showInformationMessage(null,
Expand Down
Loading

0 comments on commit 276312a

Please sign in to comment.