Some commenting and style guidelines stuff

This commit is contained in:
RyanTheAllmighty 2015-02-26 17:26:09 +11:00
parent bb100b9b7c
commit 11e7e1ac9f
5 changed files with 375 additions and 24 deletions

3
.gitignore vendored
View file

@ -7,7 +7,8 @@
!/macapp/
!/.gitignore
!/LICENSE
!/README.md
!/pom.xml
!/IntelliJ-Coding-Style.xml
!/README.md
!/STYLE.md
!/CHANGELOG.md

View file

@ -16,16 +16,9 @@ ATLauncher is a Launcher for Minecraft which integrates multiple different ModPa
[ATLauncher Twitter](http://twitter.com/ATLauncher)
### Coding Standards
### Coding Standards & Styling Guidelines
+ Please keep all line lengths to 120 characters and use 4 spaces rather than tab characters
+ Please keep all variables at the top of the class
+ Please keep all inner classes at the bottom
+ Please don't use star imports
+ Please mark all classes that are to be de/serialized with Gson with the @Json annotation for other developers
+ Please use the IntelliJ-Coding-Style.xml for the project (if using IntelliJ) in order to keep all formatting consistent
+ Please update the CHANGELOG.md file when fixing/adding something so it's easier to keep track of than git commits. Feel free to add in a 'by MyUsername' to the end of the changes you've made.
+ Please don't do large commits. My preference is a single commit for a single fix/addition rather than bundled up commits.
Please see the STYLE.md file for coding standards and style guidelines.
### Building

31
STYLE.md Normal file
View file

@ -0,0 +1,31 @@
ATLauncher Coding Standards & Styling Guidelines
====================================
So if you wish to submit any Pull Requests, please follow these coding standards. Styling guidelines are just how I like to have things styled, mainly relating to doc blocks and comments.
### Coding Standards
+ Please keep all line lengths to 120 characters and use 4 spaces rather than tab characters.
+ Please keep all variables at the top of the class.
+ Please keep all inner classes at the bottom.
+ Please don't use star imports.
+ Please mark all classes that are to be de/serialized with Gson with the @Json annotation for other developers.
+ Please use the IntelliJ-Coding-Style.xml for the project (if using IntelliJ) in order to keep all formatting consistent.
+ Please update the CHANGELOG.md file when fixing/adding something so it's easier to keep track of than git commits. Feel free to add in a 'by MyUsername' to the end of the changes you've made.
+ Please don't do large commits. My preference is a single commit for a single fix/addition rather than bundled up commits.
### Styling Guidelines
+ Make sure all doc block information has a full stop at the end.
+ Make sure all doc block @ elements don't have a full stop at the end.
+ Make sure all comments not in doc blocks end in a full stop.
+ Make sure there is a blank line between any main doc block information and any @elements.
#### Example
// Some comment. Which ends in a full stop.
/**
* Where the magic happens. Notice I end in a full stop.
*
* @param arguments all the arguments passed in from the command line, notice I don't end in a full stop
*/

View file

@ -56,30 +56,103 @@ import java.util.concurrent.Executors;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
/**
* Main entry point for the application, Java runs the main method here when the application is launched.
*/
public class App {
/**
* The taskpool used to quickly add in tasks to do in the background.
*/
public static final ExecutorService TASKPOOL = Executors.newFixedThreadPool(2);
/**
* The instance of toaster to show popups in the bottom right.
*/
public static final Toaster TOASTER = Toaster.instance();
/**
* The tray menu shown in the notification area or whatever it's called in non Windows OS.
*/
public static TrayMenu TRAY_MENU = new TrayMenu();
/**
* If the launcher was just updated and this is it's first time loading after the update. This is used to check for
* when there are possible issues in which the user may have to download the update manually.
*/
public static boolean wasUpdated = false;
/**
* This is used to turn on experimental JSON support. JSON is replacing XML when it comes to loading pack version
* information and installing packs. It's a much better system, but still in test and only enable when the command
* line argument shown below.
* <p/>
* --json=experimental
*/
public static boolean experimentalJson = false;
/**
* This controls if GZIP is used when downloading files through the launcher. It's used as a debugging tool and is
* enabled with the command line argument shown below.
* <p/>
* --usegzip=false
*/
public static boolean useGzipForDownloads = true;
/**
* This allows skipping the Minecraft version downloading which grabs all the Minecraft versions from Mojang so the
* launcher can know ahead of time what Minecraft versions there are and how to install them. Can be turned on to
* skip the downloading with the below command line argument.
* <p/>
* --skip-minecraft-version-downloads
*/
public static boolean skipMinecraftVersionDownloads = false;
/**
* This allows skipping the system tray intergation so that the launcher doesn't even try to show the icon and menu
* etc, in the users system tray. It can be skipped with the below command line argument.
* <p/>
* --skip-tray-integration
*/
public static boolean skipTrayIntegration = false;
public static String autoLaunch = null;
/**
* This is the Settings instance which holds all the users settings and alot of methods relating to getting things
* done.
*
* @TODO This should probably be switched to be less large and have less responsibility.
*/
public static Settings settings;
/**
* This is the theme used by the launcher. By default it uses the default theme until the theme can be created and
* loaded.
* <p/>
* For more information on themeing, please see https://atl.pw/theme
*/
public static Theme THEME = Theme.DEFAULT_THEME;
static {
/**
* Sets up where all uncaught exceptions go to.
*/
Thread.setDefaultUncaughtExceptionHandler(new ExceptionStrainer());
}
/**
* Where the magic happens.
*
* @param args all the arguments passed in from the command line
*/
public static void main(String[] args) {
Locale.setDefault(Locale.ENGLISH); // Set English as the default locale
// Set English as the default locale. CodeChickenLib(?) has some issues when not using this on some systems.
Locale.setDefault(Locale.ENGLISH);
// Prefer to use IPv4
System.setProperty("java.net.preferIPv4Stack", "true");
String autoLaunch = null;
if (args != null) {
for (String arg : args) {
String[] parts = arg.split("=");
@ -116,7 +189,7 @@ public class App {
} else if (parts[0].equalsIgnoreCase("--skip-minecraft-version-downloads")) {
skipMinecraftVersionDownloads = true;
LogManager.debug("Skipping Minecraft version downloads! This may cause issues, only use it as " +
"directed by" + Constants.LAUNCHER_NAME + " staff!", true);
"directed by" + Constants.LAUNCHER_NAME + " staff!", true);
} else if (parts[0].equalsIgnoreCase("--skip-tray-integration")) {
skipTrayIntegration = true;
LogManager.debug("Skipping tray integration!", true);
@ -145,20 +218,30 @@ public class App {
}
}
}
settings = new Settings(); // Setup the Settings and wait for it to finish
// Setup the Settings and wait for it to finish.
settings = new Settings();
final SplashScreen ss = new SplashScreen();
// Load and show the splash screen while we load other things.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
ss.setVisible(true);
}
});
// Load the theme and style everything.
loadTheme();
settings.loadConsole(); // Load console AFTER L&F
// Load the console, making sure it's after the theme and L&F has been loaded otherwise bad results may occur.
settings.loadConsole();
if (settings.enableTrayIcon() && !skipTrayIntegration) {
try {
trySystemTrayIntegration(); // Try to enable the tray icon
// Try to enable the tray icon.
trySystemTrayIntegration();
} catch (Exception e) {
settings.logStackTrace(e);
}
@ -167,24 +250,30 @@ public class App {
LogManager.info("ATLauncher Version: " + Constants.VERSION);
LogManager.info("Operating System: " + System.getProperty("os.name"));
LogManager.info("RAM Available: " + Utils.getMaximumRam() + "MB");
if (settings.isUsingCustomJavaPath()) {
LogManager.warn("Custom Java Path Set!");
} else if (settings.isUsingMacApp()) {
// If the user is using the Mac Application, then we forcibly set the java path if they have none set.
File oracleJava = new File("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java");
if (oracleJava.exists() && oracleJava.canExecute()) {
settings.setJavaPath("/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home");
LogManager.warn("Launcher Forced Custom Java Path Set!");
}
}
LogManager.info("Java Version: " + Utils.getActualJavaVersion());
LogManager.info("Java Path: " + settings.getJavaPath());
LogManager.info("64 Bit Java: " + Utils.is64Bit());
LogManager.info("Launcher Directory: " + settings.getBaseDir());
LogManager.info("Using Theme: " + THEME);
// Now for some Mac specific stuff, mainly just setting the name of the application and icon.
if (Utils.isMac()) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
System.setProperty("com.apple.mrj.application.apple.menu.about.name", Constants.LAUNCHER_NAME + " " + Constants.VERSION);
System.setProperty("com.apple.mrj.application.apple.menu.about.name", Constants.LAUNCHER_NAME + " " +
Constants.VERSION);
try {
Class util = Class.forName("com.apple.eawt.Application");
Method getApplication = util.getMethod("getApplication", new Class[0]);
@ -199,6 +288,7 @@ public class App {
}
if (settings.enableConsole()) {
// Show the console if enabled.
settings.getConsole().setVisible(true);
}
@ -229,6 +319,9 @@ public class App {
new LauncherFrame(open); // Open the Launcher
}
/**
* Loads the theme and applies the theme's settings to the look and feel.
*/
public static void loadTheme() {
File themeFile = settings.getThemeFile();
if (themeFile != null) {
@ -265,6 +358,11 @@ public class App {
}
}
/**
* Sets the look and feel to be that of nimbus which is the base.
*
* @throws Exception
*/
private static void setLAF() throws Exception {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if (info.getName().equalsIgnoreCase("nimbus")) {
@ -273,6 +371,11 @@ public class App {
}
}
/**
* This modifies the look and feel based upon the theme loaded.
*
* @throws Exception
*/
private static void modifyLAF() throws Exception {
THEME.apply();
ToolTipManager.sharedInstance().setDismissDelay(15000);
@ -287,6 +390,11 @@ public class App {
}
}
/**
* This tries to create the system tray menu.
*
* @throws Exception
*/
private static void trySystemTrayIntegration() throws Exception {
if (SystemTray.isSupported()) {
SystemTray tray = SystemTray.getSystemTray();
@ -309,6 +417,10 @@ public class App {
}
}
/**
* This creates some integration files so the launcher can work with other applications by storing some properties
* about itself and it's location in a set location.
*/
public static void integrate() {
try {
File f = new File(new File(System.getProperty("user.home")), ".atl.properties");

View file

@ -15,7 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.atlauncher.gui.theme;
import com.atlauncher.LogManager;
@ -29,6 +28,9 @@ import java.awt.Color;
import java.awt.Font;
public final class Theme {
/**
* This is the default theme used by the launcher incase all else fails and it cannot read the theme from disk.
*/
public static final Theme DEFAULT_THEME = new Theme(Constants.LAUNCHER_NAME, "RyanTheAllmighty", true, new Color(40, 45, 50)
, new Color(255, 255, 255), new Color(0, 0, 0), new Color(0, 136, 204), new Color(100, 100, 200), new
Color(80, 170, 107), new Color(50, 55, 60), new Color(50, 55, 60), new Color(30, 35, 40), new Color(255,
@ -36,34 +38,148 @@ public final class Theme {
76), new Color(238, 34, 34), new Color(255, 0, 255), "SansSerif", "SansSerif", "Oswald-Regular",
"SansSerif");
// Meta
/**
* This is the name of the theme.
*/
private final String name;
/**
* This is the themes authors name.
*/
private final String author;
// Flags
/**
* This determines if the tabs should be shown on the right or not. If false the tabs will show on the left hand
* side of the launcher rather than the default of being on the right hand side of the launcher.
*/
private final boolean tabsOnRight;
// Colors
/**
* This is the base colour.
*/
private final Color baseColor;
/**
* This is the text colour.
*/
private final Color textColor;
/**
* This is the button colour.
*/
private final Color buttonColor;
/**
* This is the selection colour.
*/
private final Color selectionColor;
/**
* This is the dropdown selection colour.
*/
private final Color dropdownSelectionColor;
/**
* This is the hover boarder colour.
*/
private final Color hoverBorderColor;
/**
* This is the mod selection background colour.
*/
private final Color modSelectionBGColor;
/**
* This is the mod info colour.
*/
private final Color modInfoColor;
/**
* This is the tab background colour.
*/
private final Color tabBackgroundColor;
/**
* This is the normal instance colour.
*/
private final Color normalInstanceColor;
/**
* This is the corrupted instance colour.
*/
private final Color corruptedInstanceColor;
/**
* This is the console text colour.
*/
private final Color consoleTextColor;
/**
* This is the console log info colour.
*/
private final Color logInfoColor;
/**
* This is the console log warning colour.
*/
private final Color logWarnColor;
/**
* This is the console log error colour.
*/
private final Color logErrorColor;
/**
* This is the console log debug colour.
*/
private final Color logDebugColor;
// Fonts
private final String defaultFont, consoleFont, tabFont, buttonFont;
/**
* This is the default font.
*/
private final String defaultFont;
/**
* This is the console font.
*/
private final String consoleFont;
/**
* This is the tab font.
*/
private final String tabFont;
/**
* This is the button font.
*/
private final String buttonFont;
/**
* This is the constructor which takes in all the values for a theme. Used in creating the default theme.
* @param name the name of the theme
* @param author the author of the theme
* @param tabsOnRight if tabs should be displayed on the right of the launcher
* @param baseColor the base colour
* @param textColor the text colour
* @param buttonColor the button colour
* @param selectionColor the selection colour
* @param dropdownSelectionColor the dropdown selection colour
* @param hoverBorderColor the hover boarder colour
* @param modSelectionBGColor the mod selection background colour
* @param modInfoColor the mod info colour
* @param tabBackgroundColor the tab background colour
* @param normalInstanceColor the normal instance colour
* @param corruptedInstanceColor the corrupted instance colour
* @param consoleTextColor the console text colour
* @param logInfoTextColor the console log info colour
* @param logWarnColor the console log warning colour
* @param logErrorColor the console log error colour
* @param logDebugColor the console log debug colour
* @param defaultFont the default font
* @param consoleFont the console font
* @param tabFont the tab font
* @param buttonFont the button font
*/
private Theme(String name, String author, boolean tabsOnRight, Color baseColor, Color textColor, Color
buttonColor, Color selectionColor, Color dropdownSelectionColor, Color hoverBorderColor, Color
modSelectionBGColor, Color modInfoColor, Color tabBackgroundColor, Color normalInstanceColor, Color
@ -96,6 +212,9 @@ public final class Theme {
this.buttonFont = buttonFont;
}
/**
* Apply the themes values to the UIManager.
*/
public void apply() {
try {
UIManager.put("control", this.baseColor);
@ -119,6 +238,11 @@ public final class Theme {
}
}
/**
* Gets the default font.
*
* @return the default font
*/
public Font getDefaultFont() {
if (this.defaultFont == null) {
LogManager.error("The default font for the theme you're using is corrupt!");
@ -127,6 +251,11 @@ public final class Theme {
return Resources.makeFont(this.defaultFont);
}
/**
* Gets the console font.
*
* @return the console font
*/
public Font getConsoleFont() {
if (this.consoleFont == null) {
LogManager.error("The console font for the theme you're using is corrupt!");
@ -135,6 +264,11 @@ public final class Theme {
return Resources.makeFont(this.consoleFont);
}
/**
* Gets the tab font.
*
* @return the tab font
*/
public Font getTabFont() {
if (this.tabFont == null) {
LogManager.error("The tab font for the theme you're using is corrupt!");
@ -143,6 +277,11 @@ public final class Theme {
return Resources.makeFont(this.tabFont);
}
/**
* Gets the button font.
*
* @return the button font
*/
public Font getButtonFont() {
if (this.buttonFont == null) {
LogManager.error("The button font for the theme you're using is corrupt!");
@ -151,10 +290,20 @@ public final class Theme {
return Resources.makeFont(this.buttonFont);
}
/**
* Gets if the tabs on the launcher should be shown on the right or not.
*
* @return true if the tabs should show on the right or false if they should show on the left
*/
public boolean tabsOnRight() {
return this.tabsOnRight;
}
/**
* Gets the console text colour.
*
* @return console text colour
*/
public Color getConsoleTextColor() {
if (this.consoleTextColor == null) {
LogManager.error("The console text colour for the theme you're using is corrupt!");
@ -163,6 +312,11 @@ public final class Theme {
return this.consoleTextColor;
}
/**
* Gets the selection colour.
*
* @return selection colour
*/
public Color getSelectionColor() {
if (this.selectionColor == null) {
LogManager.error("The selection colour for the theme you're using is corrupt!");
@ -171,6 +325,11 @@ public final class Theme {
return this.selectionColor;
}
/**
* Gets the hover border colour.
*
* @return hover border colour
*/
public Color getHoverBorderColor() {
if (this.hoverBorderColor == null) {
LogManager.error("The border hover colour for the theme you're using is corrupt!");
@ -179,6 +338,11 @@ public final class Theme {
return this.hoverBorderColor;
}
/**
* Gets the mod info colour.
*
* @return mod info colour
*/
public Color getModInfoColor() {
if (this.modInfoColor == null) {
LogManager.error("The mod info colour for the theme you're using is corrupt!");
@ -187,6 +351,11 @@ public final class Theme {
return this.modInfoColor;
}
/**
* Gets the base colour.
*
* @return base colour
*/
public Color getBaseColor() {
if (this.baseColor == null) {
LogManager.error("The base colour for the theme you're using is corrupt!");
@ -195,6 +364,11 @@ public final class Theme {
return this.baseColor;
}
/**
* Gets the corrupted instance colour.
*
* @return corrupted instance colour
*/
public Color getCorruptedInstanceColor() {
if (this.corruptedInstanceColor == null) {
LogManager.error("The corrupted instance text colour for the theme you're using is corrupt!");
@ -203,6 +377,11 @@ public final class Theme {
return this.corruptedInstanceColor;
}
/**
* Gets the normal instance colour.
*
* @return normal instance colour
*/
public Color getNormalInstanceColor() {
if (this.normalInstanceColor == null) {
LogManager.error("The normal instance text colour for the theme you're using is corrupt!");
@ -211,6 +390,11 @@ public final class Theme {
return this.normalInstanceColor;
}
/**
* Gets the mod selection background colour.
*
* @return mod selection background colour
*/
public Color getModSelectionBackgroundColor() {
if (this.modSelectionBGColor == null) {
LogManager.error("The mod selection background colour for the theme you're using is corrupt!");
@ -219,6 +403,11 @@ public final class Theme {
return this.modSelectionBGColor;
}
/**
* Gets the tab background colour.
*
* @return tab background colour
*/
public Color getTabBackgroundColor() {
if (this.tabBackgroundColor == null) {
LogManager.error("The tab background colour for the theme you're using is corrupt!");
@ -227,6 +416,11 @@ public final class Theme {
return this.tabBackgroundColor;
}
/**
* Gets the log info colour.
*
* @return log info colour
*/
public Color getLogInfoColor() {
if (this.logInfoColor == null) {
LogManager.error("The log info colour for the theme you're using is corrupt!");
@ -235,6 +429,11 @@ public final class Theme {
return this.logInfoColor;
}
/**
* Gets the log error colour.
*
* @return log error colour
*/
public Color getLogErrorColor() {
if (this.logErrorColor == null) {
LogManager.error("The log error colour for the theme you're using is corrupt!");
@ -243,6 +442,11 @@ public final class Theme {
return this.logErrorColor;
}
/**
* Gets the log warning colour.
*
* @return log warning colour
*/
public Color getLogWarnColor() {
if (this.logWarnColor == null) {
LogManager.error("The log warning colour for the theme you're using is corrupt!");
@ -251,6 +455,11 @@ public final class Theme {
return this.logWarnColor;
}
/**
* Gets the log debug colour.
*
* @return log debug colour
*/
public Color getLogDebugColor() {
if (this.logDebugColor == null) {
LogManager.error("The log debug colour for the theme you're using is corrupt!");
@ -259,9 +468,14 @@ public final class Theme {
return this.logDebugColor;
}
/**
* Returns the name and author of this theme.
*
* @return the name and author of this theme
*/
@Override
public String toString() {
if (this.name == null || this.author == null) {
if (this.name == null || this.name.isEmpty() || this.author == null || this.author.isEmpty()) {
LogManager.error("The name and/or author for the theme you're using is corrupt!");
return "Unknown by Unknown";
}