import griffon.core.GriffonApplication import groovy.util.logging.Log import net.i2p.util.SystemVersion import org.codehaus.griffon.runtime.core.AbstractLifecycleHandler import com.muwire.core.Core import com.muwire.core.MuWireSettings import javax.annotation.Nonnull import javax.inject.Inject import javax.swing.JTable import static griffon.util.GriffonApplicationUtils.isMacOSX import static groovy.swing.SwingBuilder.lookAndFeel @Log class Initialize extends AbstractLifecycleHandler { @Inject Initialize(@Nonnull GriffonApplication application) { super(application) } @Override void execute() { log.info "Loading home dir" def portableHome = System.getProperty("portable.home") def home = portableHome == null ? selectHome() : portableHome home = new File(home) if (!home.exists()) { log.info("creating home dir $home") home.mkdirs() } application.context.put("muwire-home", home.getAbsolutePath()) def guiPropsFile = new File(home, "gui.properties") if (guiPropsFile.exists()) { Properties props = new Properties() guiPropsFile.withInputStream { props.load(it) } log.info("settting user-specified lnf ${props['lnf']}") lookAndFeel(props["lnf"]) } else { log.info "will try default lnfs" if (isMacOSX()) { lookAndFeel('nimbus') // otherwise the file chooser doesn't open??? } else { lookAndFeel('system', 'gtk') } } } private static String selectHome() { def home = new File(System.properties["user.home"]) def defaultHome = new File(home, ".MuWire") if (defaultHome.exists()) return defaultHome.getAbsolutePath() if (SystemVersion.isMac()) { def library = new File(home, "Library") def appSupport = new File(library, "Application Support") def muwire = new File(appSupport,"MuWire") return muwire.getAbsolutePath() } if (SystemVersion.isWindows()) { def appData = new File(home,"AppData") def roaming = new File(appData, "Roaming") def muwire = new File(roaming, "MuWire") return muwire.getAbsolutePath() } defaultHome.getAbsolutePath() } }