X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fmain%2FMain.java;h=329cbcffe0a2d0c408ee1e81bfa313c3bb9b7b5a;hb=fca5e518c135176295464a9e2ab7a65729a0e32c;hp=383aa0c18472028470505f5badd9d1d93349a193;hpb=c785ca4d7b634f79e1f30202915633aa92e4152c;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/main/Main.java b/src/net/pterodactylus/jsite/main/Main.java index 383aa0c..329cbcf 100644 --- a/src/net/pterodactylus/jsite/main/Main.java +++ b/src/net/pterodactylus/jsite/main/Main.java @@ -19,6 +19,21 @@ package net.pterodactylus.jsite.main; +import java.io.File; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.swing.UIManager; +import javax.swing.UIManager.LookAndFeelInfo; + +import net.pterodactylus.jsite.core.CoreImpl; +import net.pterodactylus.jsite.core.NodeManager; +import net.pterodactylus.jsite.core.RequestManager; +import net.pterodactylus.jsite.gui.SwingInterface; +import net.pterodactylus.jsite.project.ProjectManager; +import net.pterodactylus.util.logging.Logging; + /** * Main class that is called by the VM. * @@ -34,6 +49,73 @@ public class Main { * The command-line arguments */ public static void main(String[] args) { + new Main().start(); + } + + /** + * Starts the core and the default {@link SwingInterface}. + */ + private void start() { + Logging.setup("jSite"); + + CoreImpl core = new CoreImpl(); + + String configDirectory = System.getProperty("user.home") + File.separator + ".jSite"; + + NodeManager nodeManager = new NodeManager("jSite-" + Version.getVersion(), configDirectory); + core.setNodeManager(nodeManager); + nodeManager.addNodeListener(core); + + ProjectManager projectManager = new ProjectManager(configDirectory); + core.setProjectManager(projectManager); + projectManager.setNodeManager(nodeManager); + + RequestManager requestManager = new RequestManager(); + core.setRequestManager(requestManager); + nodeManager.addNodeListener(requestManager); + requestManager.setNodeManager(nodeManager); + requestManager.addRequestListener(core); + + SwingInterface swingInterface = new SwingInterface(core, configDirectory); + core.addCoreListener(swingInterface); + Logging.addLoggingListener(swingInterface); + + core.start(); + } + + /** + * Tries to load the class with the given name and includes the look & feel + * in the UIManager, if it exists. + * + * @param name + * The name of the look & feel + * @param className + * The name of the look & feel’s main class + */ + @SuppressWarnings("unused") + private void addLookAndFeel(String name, String className) { + addLookAndFeels(new LookAndFeelInfo(name, className)); + } + + /** + * Tries to load each look & feel and adds it to the list of installed look & + * feels. + * + * @see UIManager#setInstalledLookAndFeels(LookAndFeelInfo[]) + * @param lookAndFeelInfos + * The look & feels to add + */ + private void addLookAndFeels(LookAndFeelInfo... lookAndFeelInfos) { + List allLookAndFeelInfos = new ArrayList(Arrays.asList(UIManager.getInstalledLookAndFeels())); + for (LookAndFeelInfo lookAndFeelInfo: lookAndFeelInfos) { + try { + Class.forName(lookAndFeelInfo.getClassName()); + allLookAndFeelInfos.add(lookAndFeelInfo); + } catch (ClassNotFoundException e) { + /* okay, it doesn't exist, ignore. */ + } + } + UIManager.setInstalledLookAndFeels(allLookAndFeelInfos.toArray(new LookAndFeelInfo[0])); } }