mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 06:39:54 +01:00
Moved defunct invitation and installer code to sandpit repo.
This commit is contained in:
@@ -3,9 +3,7 @@
|
|||||||
<classpathentry excluding=".gitignore|build.xml" kind="src" path="api"/>
|
<classpathentry excluding=".gitignore|build.xml" kind="src" path="api"/>
|
||||||
<classpathentry excluding=".gitignore|build.xml" kind="src" path="components"/>
|
<classpathentry excluding=".gitignore|build.xml" kind="src" path="components"/>
|
||||||
<classpathentry kind="src" path="i18n"/>
|
<classpathentry kind="src" path="i18n"/>
|
||||||
<classpathentry kind="src" path="installer"/>
|
|
||||||
<classpathentry kind="src" path="test"/>
|
<classpathentry kind="src" path="test"/>
|
||||||
<classpathentry excluding=".gitignore|build.xml" kind="src" path="ui"/>
|
|
||||||
<classpathentry excluding=".gitignore|build.xml" kind="src" path="util"/>
|
<classpathentry excluding=".gitignore|build.xml" kind="src" path="util"/>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||||
<classpathentry kind="lib" path="lib/guice-3.0-no_aop.jar"/>
|
<classpathentry kind="lib" path="lib/guice-3.0-no_aop.jar"/>
|
||||||
|
|||||||
@@ -1,25 +0,0 @@
|
|||||||
package net.sf.briar.api.invitation;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/** A progress callback for creating an invitation. */
|
|
||||||
public interface InvitationCallback {
|
|
||||||
|
|
||||||
/** Returns true if the process has been cancelled by the user. */
|
|
||||||
boolean isCancelled();
|
|
||||||
|
|
||||||
void copyingFile(File f);
|
|
||||||
|
|
||||||
void encryptingFile(File f);
|
|
||||||
|
|
||||||
void created(List<File> files);
|
|
||||||
|
|
||||||
void error(String message);
|
|
||||||
|
|
||||||
void notFound(File f);
|
|
||||||
|
|
||||||
void notDirectory(File f);
|
|
||||||
|
|
||||||
void notAllowed(File f);
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package net.sf.briar.api.invitation;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/** Provides the parameters for creating an invitation. */
|
|
||||||
public interface InvitationParameters {
|
|
||||||
|
|
||||||
boolean shouldCreateExe();
|
|
||||||
|
|
||||||
boolean shouldCreateJar();
|
|
||||||
|
|
||||||
char[] getPassword();
|
|
||||||
|
|
||||||
File getChosenLocation();
|
|
||||||
|
|
||||||
File getSetupDat();
|
|
||||||
}
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package net.sf.briar.api.invitation;
|
|
||||||
|
|
||||||
public interface InvitationWorkerFactory {
|
|
||||||
|
|
||||||
Runnable createWorker(InvitationCallback callback,
|
|
||||||
InvitationParameters parameters);
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package net.sf.briar.api.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/** A progress callback for the installation process. */
|
|
||||||
public interface SetupCallback {
|
|
||||||
|
|
||||||
/** Returns true if the process has been cancelled by the user. */
|
|
||||||
boolean isCancelled();
|
|
||||||
|
|
||||||
void extractingFile(File f);
|
|
||||||
|
|
||||||
void copyingFile(File f);
|
|
||||||
|
|
||||||
void installed(File f);
|
|
||||||
|
|
||||||
void error(String message);
|
|
||||||
|
|
||||||
void notFound(File f);
|
|
||||||
|
|
||||||
void notDirectory(File f);
|
|
||||||
|
|
||||||
void notAllowed(File f);
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package net.sf.briar.api.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
/** Provides the parameters for the installation process. */
|
|
||||||
public interface SetupParameters {
|
|
||||||
|
|
||||||
File getChosenLocation();
|
|
||||||
|
|
||||||
long getExeHeaderSize();
|
|
||||||
}
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
package net.sf.briar.api.setup;
|
|
||||||
|
|
||||||
public interface SetupWorkerFactory {
|
|
||||||
|
|
||||||
Runnable createWorker(SetupCallback callback, SetupParameters parameters);
|
|
||||||
}
|
|
||||||
@@ -10,7 +10,6 @@
|
|||||||
<include name='api/net/sf/briar/**'/>
|
<include name='api/net/sf/briar/**'/>
|
||||||
<include name='components/net/sf/briar/**'/>
|
<include name='components/net/sf/briar/**'/>
|
||||||
<include name='installer/net/sf/briar/**'/>
|
<include name='installer/net/sf/briar/**'/>
|
||||||
<include name='ui/net/sf/briar/**'/>
|
|
||||||
<include name='util/net/sf/briar/**'/>
|
<include name='util/net/sf/briar/**'/>
|
||||||
</fileset>
|
</fileset>
|
||||||
</javadoc>
|
</javadoc>
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
package net.sf.briar.invitation;
|
|
||||||
|
|
||||||
import net.sf.briar.api.invitation.InvitationWorkerFactory;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
|
|
||||||
public class InvitationModule extends AbstractModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {
|
|
||||||
bind(InvitationWorkerFactory.class).to(
|
|
||||||
InvitationWorkerFactoryImpl.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,107 +0,0 @@
|
|||||||
package net.sf.briar.invitation;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
|
||||||
import net.sf.briar.api.db.DbException;
|
|
||||||
import net.sf.briar.api.invitation.InvitationCallback;
|
|
||||||
import net.sf.briar.api.invitation.InvitationParameters;
|
|
||||||
import net.sf.briar.api.protocol.Transport;
|
|
||||||
import net.sf.briar.api.serial.Writer;
|
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
|
||||||
import net.sf.briar.util.FileUtils;
|
|
||||||
|
|
||||||
class InvitationWorker implements Runnable {
|
|
||||||
|
|
||||||
private final InvitationCallback callback;
|
|
||||||
private final InvitationParameters parameters;
|
|
||||||
private final DatabaseComponent db;
|
|
||||||
private final WriterFactory writerFactory;
|
|
||||||
|
|
||||||
InvitationWorker(final InvitationCallback callback,
|
|
||||||
InvitationParameters parameters, DatabaseComponent db,
|
|
||||||
WriterFactory writerFactory) {
|
|
||||||
this.callback = callback;
|
|
||||||
this.parameters = parameters;
|
|
||||||
this.db = db;
|
|
||||||
this.writerFactory = writerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
File dir = parameters.getChosenLocation();
|
|
||||||
assert dir != null;
|
|
||||||
if(!dir.exists()) {
|
|
||||||
callback.notFound(dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!dir.isDirectory()) {
|
|
||||||
callback.notDirectory(dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!dir.canWrite()) {
|
|
||||||
callback.notAllowed(dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
List<File> files = new ArrayList<File>();
|
|
||||||
try {
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
files.add(createInvitationDat(dir));
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
if(parameters.shouldCreateExe()) files.add(createBriarExe(dir));
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
if(parameters.shouldCreateJar()) files.add(createBriarJar(dir));
|
|
||||||
} catch(IOException e) {
|
|
||||||
callback.error(e.toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
callback.created(files);
|
|
||||||
}
|
|
||||||
|
|
||||||
private File createInvitationDat(File dir) throws IOException {
|
|
||||||
char[] password = parameters.getPassword();
|
|
||||||
assert password != null;
|
|
||||||
Arrays.fill(password, (char) 0);
|
|
||||||
File invitationDat = new File(dir, "invitation.dat");
|
|
||||||
callback.encryptingFile(invitationDat);
|
|
||||||
// FIXME: Create a real invitation
|
|
||||||
Collection<Transport> transports;
|
|
||||||
try {
|
|
||||||
transports = db.getLocalTransports();
|
|
||||||
} catch(DbException e) {
|
|
||||||
throw new IOException(e.toString());
|
|
||||||
}
|
|
||||||
FileOutputStream out = new FileOutputStream(invitationDat);
|
|
||||||
Writer w = writerFactory.createWriter(out);
|
|
||||||
w.writeList(transports);
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
return invitationDat;
|
|
||||||
}
|
|
||||||
|
|
||||||
private File createBriarExe(File dir) throws IOException {
|
|
||||||
File f = new File(dir, "briar.exe");
|
|
||||||
copyInstaller(f);
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
private File createBriarJar(File dir) throws IOException {
|
|
||||||
File f = new File(dir, "briar.jar");
|
|
||||||
copyInstaller(f);
|
|
||||||
return f;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyInstaller(File dest) throws IOException {
|
|
||||||
File src = parameters.getSetupDat();
|
|
||||||
if(!src.exists() || !src.isFile())
|
|
||||||
throw new IOException("File not found: " + src.getPath());
|
|
||||||
callback.copyingFile(dest);
|
|
||||||
FileUtils.copy(src, dest);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package net.sf.briar.invitation;
|
|
||||||
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
|
||||||
import net.sf.briar.api.invitation.InvitationCallback;
|
|
||||||
import net.sf.briar.api.invitation.InvitationParameters;
|
|
||||||
import net.sf.briar.api.invitation.InvitationWorkerFactory;
|
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
|
||||||
|
|
||||||
import com.google.inject.Inject;
|
|
||||||
|
|
||||||
class InvitationWorkerFactoryImpl implements InvitationWorkerFactory {
|
|
||||||
|
|
||||||
private final DatabaseComponent databaseComponent;
|
|
||||||
private final WriterFactory writerFactory;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
InvitationWorkerFactoryImpl(DatabaseComponent databaseComponent,
|
|
||||||
WriterFactory writerFactory) {
|
|
||||||
this.databaseComponent = databaseComponent;
|
|
||||||
this.writerFactory = writerFactory;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Runnable createWorker(InvitationCallback callback,
|
|
||||||
InvitationParameters parameters) {
|
|
||||||
return new InvitationWorker(callback, parameters, databaseComponent,
|
|
||||||
writerFactory);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
package net.sf.briar.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.PrintStream;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.setup.SetupCallback;
|
|
||||||
import net.sf.briar.api.setup.SetupParameters;
|
|
||||||
import net.sf.briar.util.FileUtils;
|
|
||||||
import net.sf.briar.util.OsUtils;
|
|
||||||
import net.sf.briar.util.ZipUtils;
|
|
||||||
|
|
||||||
class SetupWorker implements Runnable {
|
|
||||||
|
|
||||||
// FIXME: Change this when we have a main class
|
|
||||||
private static final String MAIN_CLASS = "net.sf.briar.ui.FIXME";
|
|
||||||
|
|
||||||
private final SetupCallback callback;
|
|
||||||
private final SetupParameters parameters;
|
|
||||||
private final I18n i18n;
|
|
||||||
private final File jar;
|
|
||||||
private final ZipUtils.Callback unzipCallback;
|
|
||||||
|
|
||||||
SetupWorker(final SetupCallback callback, SetupParameters parameters,
|
|
||||||
I18n i18n, File jar) {
|
|
||||||
this.parameters = parameters;
|
|
||||||
this.callback = callback;
|
|
||||||
this.i18n = i18n;
|
|
||||||
this.jar = jar;
|
|
||||||
unzipCallback = new ZipUtils.Callback() {
|
|
||||||
public void processingFile(File f) {
|
|
||||||
callback.extractingFile(f);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run() {
|
|
||||||
// Don't try to proceed if we're running from Eclipse
|
|
||||||
if(!jar.isFile()) {
|
|
||||||
callback.error("Not running from jar");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File dir = parameters.getChosenLocation();
|
|
||||||
assert dir != null;
|
|
||||||
if(!dir.exists()) {
|
|
||||||
callback.notFound(dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!dir.isDirectory()) {
|
|
||||||
callback.notDirectory(dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String[] list = dir.list();
|
|
||||||
if(list == null || !dir.canWrite()) {
|
|
||||||
callback.notAllowed(dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// If the chosen directory isn't empty, install to a subdirectory
|
|
||||||
if(list.length != 0) {
|
|
||||||
dir = new File(dir, "Briar");
|
|
||||||
if(!dir.exists() && !dir.mkdir()) {
|
|
||||||
callback.notAllowed(dir);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Everything but the launchers will go in the Data directory
|
|
||||||
File data = new File(dir, "Data");
|
|
||||||
if(!data.exists() && !data.mkdir()) {
|
|
||||||
callback.notAllowed(data);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
copyInstaller(jar, data);
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
// Only extract the Windows JRE, jars and fonts
|
|
||||||
extractFiles(jar, data, "^jre/.*|.*\\.jar$|.*\\.ttf$");
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
createLaunchers(dir);
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
// Save the chosen locale for the first launch
|
|
||||||
i18n.saveLocale(dir);
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
// Installation succeeded - delete the installer
|
|
||||||
jar.deleteOnExit();
|
|
||||||
} catch(IOException e) {
|
|
||||||
callback.error(e.toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(callback.isCancelled()) return;
|
|
||||||
callback.installed(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a copy of the installer for use in future invitations
|
|
||||||
private void copyInstaller(File jar, File dir) throws IOException {
|
|
||||||
File dest = new File(dir, "setup.dat");
|
|
||||||
callback.copyingFile(dest);
|
|
||||||
FileUtils.copy(jar, dest);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract files matching the given regex from the jar
|
|
||||||
private void extractFiles(File jar, File dir, String regex)
|
|
||||||
throws IOException {
|
|
||||||
FileInputStream in = new FileInputStream(jar);
|
|
||||||
in.skip(parameters.getExeHeaderSize());
|
|
||||||
ZipUtils.unzipStream(in, dir, regex, unzipCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create launchers for Windows, Mac and Linux
|
|
||||||
private void createLaunchers(File dir) throws IOException {
|
|
||||||
createWindowsLauncher(dir);
|
|
||||||
File mac = createMacLauncher(dir);
|
|
||||||
File lin = createLinuxLauncher(dir);
|
|
||||||
// If the OS supports chmod, make the Mac and Linux launchers executable
|
|
||||||
if(!OsUtils.isWindows()) {
|
|
||||||
String[] chmod = { "chmod", "u+x", mac.getName(), lin.getName() };
|
|
||||||
ProcessBuilder p = new ProcessBuilder(chmod);
|
|
||||||
p.directory(dir);
|
|
||||||
p.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private File createWindowsLauncher(File dir) throws IOException {
|
|
||||||
File launcher = new File(dir, "run-windows.vbs");
|
|
||||||
PrintStream out = new PrintStream(new FileOutputStream(launcher));
|
|
||||||
out.print("Set Shell = CreateObject(\"WScript.Shell\")\r\n");
|
|
||||||
out.print("Shell.Run \"Data\\jre\\bin\\javaw -ea -cp Data\\* "
|
|
||||||
+ MAIN_CLASS + "\", 0\r\n");
|
|
||||||
out.print("Set Shell = Nothing\r\n");
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
return launcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
// FIXME: If this pops up a terminal window, the Mac launcher may need
|
|
||||||
// to be a jar
|
|
||||||
private File createMacLauncher(File dir) throws IOException {
|
|
||||||
File launcher = new File(dir, "run-mac.command");
|
|
||||||
PrintStream out = new PrintStream(new FileOutputStream(launcher));
|
|
||||||
out.print("#!/bin/sh\n");
|
|
||||||
out.print("cd \"$(dirname \"$0\")\"\n");
|
|
||||||
out.print("java -ea -cp 'Data/*' " + MAIN_CLASS + "\n");
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
return launcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
private File createLinuxLauncher(File dir) throws IOException {
|
|
||||||
File launcher = new File(dir, "run-linux.sh");
|
|
||||||
PrintStream out = new PrintStream(new FileOutputStream(launcher));
|
|
||||||
out.print("#!/bin/sh\n");
|
|
||||||
out.print("cd \"$(dirname \"$0\")\"\n");
|
|
||||||
out.print("java -ea -cp 'Data/*' " + MAIN_CLASS + "\n");
|
|
||||||
out.flush();
|
|
||||||
out.close();
|
|
||||||
return launcher;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
package net.sf.briar.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.security.CodeSource;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.setup.SetupCallback;
|
|
||||||
import net.sf.briar.api.setup.SetupParameters;
|
|
||||||
import net.sf.briar.api.setup.SetupWorkerFactory;
|
|
||||||
import net.sf.briar.util.FileUtils;
|
|
||||||
|
|
||||||
// Needs to be public for installer
|
|
||||||
public class SetupWorkerFactoryImpl implements SetupWorkerFactory {
|
|
||||||
|
|
||||||
private final I18n i18n;
|
|
||||||
|
|
||||||
public SetupWorkerFactoryImpl(I18n i18n) {
|
|
||||||
this.i18n = i18n;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Runnable createWorker(SetupCallback callback,
|
|
||||||
SetupParameters parameters) {
|
|
||||||
CodeSource c = FileUtils.class.getProtectionDomain().getCodeSource();
|
|
||||||
File jar = new File(c.getLocation().getPath());
|
|
||||||
assert jar.exists();
|
|
||||||
return new SetupWorker(callback, parameters, i18n, jar);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<project name='dependencies'>
|
<project name='dependencies'>
|
||||||
<dirname property='depend.root' file='${ant.file.dependencies}'/>
|
<dirname property='depend.root' file='${ant.file.dependencies}'/>
|
||||||
<target name='depend.all' depends='depend.components, depend.ui'/>
|
<target name='depend.all' depends='depend.components'/>
|
||||||
<target name='depend.api'>
|
<target name='depend.api'>
|
||||||
<ant dir='${depend.root}/api' target='compile'
|
<ant dir='${depend.root}/api' target='compile'
|
||||||
inheritAll='false'/>
|
inheritAll='false'/>
|
||||||
@@ -13,16 +13,11 @@
|
|||||||
<ant dir='${depend.root}/test' target='compile'
|
<ant dir='${depend.root}/test' target='compile'
|
||||||
inheritAll='false'/>
|
inheritAll='false'/>
|
||||||
</target>
|
</target>
|
||||||
<target name='depend.ui' depends='depend.api, depend.util'>
|
|
||||||
<ant dir='${depend.root}/ui' target='compile'
|
|
||||||
inheritAll='false'/>
|
|
||||||
</target>
|
|
||||||
<target name='depend.util'>
|
<target name='depend.util'>
|
||||||
<ant dir='${depend.root}/util' target='compile'
|
<ant dir='${depend.root}/util' target='compile'
|
||||||
inheritAll='false'/>
|
inheritAll='false'/>
|
||||||
</target>
|
</target>
|
||||||
<target name='depend-clean.all'
|
<target name='depend-clean.all' depends='depend-clean.components'/>
|
||||||
depends='depend-clean.components, depend-clean.ui'/>
|
|
||||||
<target name='depend-clean.api'>
|
<target name='depend-clean.api'>
|
||||||
<ant dir='${depend.root}/api' target='clean'
|
<ant dir='${depend.root}/api' target='clean'
|
||||||
inheritAll='false'/>
|
inheritAll='false'/>
|
||||||
@@ -37,11 +32,6 @@
|
|||||||
<ant dir='${depend.root}/test' target='clean'
|
<ant dir='${depend.root}/test' target='clean'
|
||||||
inheritAll='false'/>
|
inheritAll='false'/>
|
||||||
</target>
|
</target>
|
||||||
<target name='depend-clean.ui'
|
|
||||||
depends='depend-clean.api, depend-clean.util'>
|
|
||||||
<ant dir='${depend.root}/ui' target='clean'
|
|
||||||
inheritAll='false'/>
|
|
||||||
</target>
|
|
||||||
<target name='depend-clean.util'>
|
<target name='depend-clean.util'>
|
||||||
<ant dir='${depend.root}/util' target='clean'
|
<ant dir='${depend.root}/util' target='clean'
|
||||||
inheritAll='false'/>
|
inheritAll='false'/>
|
||||||
|
|||||||
@@ -1,39 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import javax.swing.UIManager;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.FontManager;
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.setup.SetupParameters;
|
|
||||||
import net.sf.briar.api.setup.SetupWorkerFactory;
|
|
||||||
import net.sf.briar.i18n.FontManagerImpl;
|
|
||||||
import net.sf.briar.i18n.I18nImpl;
|
|
||||||
import net.sf.briar.setup.SetupWorkerFactoryImpl;
|
|
||||||
import net.sf.briar.util.FileUtils;
|
|
||||||
import net.sf.briar.util.OsUtils;
|
|
||||||
|
|
||||||
public class SetupMain {
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
if(OsUtils.isWindows() || OsUtils.isMac())
|
|
||||||
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
|
||||||
|
|
||||||
FontManager fontManager = new FontManagerImpl();
|
|
||||||
I18n i18n = new I18nImpl(fontManager);
|
|
||||||
SetupWorkerFactory workerFactory = new SetupWorkerFactoryImpl(i18n);
|
|
||||||
SetupWizard wizard = new SetupWizard(i18n);
|
|
||||||
new LanguagePanel(wizard, fontManager, i18n);
|
|
||||||
new AlreadyInstalledPanel(wizard, i18n);
|
|
||||||
new InstructionsPanel(wizard, i18n);
|
|
||||||
LocationPanel locationPanel = new LocationPanel(wizard, i18n);
|
|
||||||
SetupParameters parameters = new SetupParametersImpl(locationPanel);
|
|
||||||
new SetupWorkerPanel(wizard, workerFactory, parameters, i18n);
|
|
||||||
|
|
||||||
File dir = new File(FileUtils.getBriarDirectory(), "Data");
|
|
||||||
fontManager.initialize(Locale.getDefault(), dir);
|
|
||||||
wizard.display();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
#FIXME: Replace this with an ant script
|
|
||||||
|
|
||||||
rm -rf temp briar.zip
|
|
||||||
mkdir temp
|
|
||||||
cd bin
|
|
||||||
for dir in api/i18n api/setup i18n setup util ui/setup ui/wizard
|
|
||||||
do
|
|
||||||
mkdir -p ../temp/net/sf/briar/$dir
|
|
||||||
cp net/sf/briar/$dir/*.class ../temp/net/sf/briar/$dir
|
|
||||||
done
|
|
||||||
jar cf ../temp/main.jar net *.properties
|
|
||||||
cd ..
|
|
||||||
cp i18n/*.properties i18n/*.ttf temp
|
|
||||||
cp lib/*.jar temp
|
|
||||||
cp -r windows-jre temp/jre
|
|
||||||
cp lib/setup.vbs temp
|
|
||||||
mkdir temp/META-INF
|
|
||||||
cp lib/installer.manifest temp/META-INF/MANIFEST.MF
|
|
||||||
cd temp
|
|
||||||
echo '$AUTORUN$>start /b briar.tmp\\setup.vbs' | zip -z -r ../briar.zip META-INF net jre *.jar *.properties *.ttf setup.vbs
|
|
||||||
cd ..
|
|
||||||
cat lib/unzipsfx.exe briar.zip > briar.exe
|
|
||||||
rm -rf temp briar.zip
|
|
||||||
@@ -24,7 +24,6 @@
|
|||||||
<test name='net.sf.briar.db.DatabaseCleanerImplTest'/>
|
<test name='net.sf.briar.db.DatabaseCleanerImplTest'/>
|
||||||
<test name='net.sf.briar.db.DatabaseComponentImplTest'/>
|
<test name='net.sf.briar.db.DatabaseComponentImplTest'/>
|
||||||
<test name='net.sf.briar.i18n.I18nTest'/>
|
<test name='net.sf.briar.i18n.I18nTest'/>
|
||||||
<test name='net.sf.briar.invitation.InvitationWorkerTest'/>
|
|
||||||
<test name='net.sf.briar.lifecycle.ShutdownManagerImplTest'/>
|
<test name='net.sf.briar.lifecycle.ShutdownManagerImplTest'/>
|
||||||
<test name='net.sf.briar.lifecycle.WindowsShutdownManagerImplTest'/>
|
<test name='net.sf.briar.lifecycle.WindowsShutdownManagerImplTest'/>
|
||||||
<test name='net.sf.briar.plugins.PluginManagerImplTest'/>
|
<test name='net.sf.briar.plugins.PluginManagerImplTest'/>
|
||||||
@@ -47,7 +46,6 @@
|
|||||||
<test name='net.sf.briar.protocol.simplex.SimplexConnectionReadWriteTest'/>
|
<test name='net.sf.briar.protocol.simplex.SimplexConnectionReadWriteTest'/>
|
||||||
<test name='net.sf.briar.serial.ReaderImplTest'/>
|
<test name='net.sf.briar.serial.ReaderImplTest'/>
|
||||||
<test name='net.sf.briar.serial.WriterImplTest'/>
|
<test name='net.sf.briar.serial.WriterImplTest'/>
|
||||||
<test name='net.sf.briar.setup.SetupWorkerTest'/>
|
|
||||||
<test name='net.sf.briar.transport.ConnectionReaderImplTest'/>
|
<test name='net.sf.briar.transport.ConnectionReaderImplTest'/>
|
||||||
<test name='net.sf.briar.transport.ConnectionRecogniserImplTest'/>
|
<test name='net.sf.briar.transport.ConnectionRecogniserImplTest'/>
|
||||||
<test name='net.sf.briar.transport.ConnectionRegistryImplTest'/>
|
<test name='net.sf.briar.transport.ConnectionRegistryImplTest'/>
|
||||||
|
|||||||
@@ -1,184 +0,0 @@
|
|||||||
package net.sf.briar.invitation;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.sf.briar.BriarTestCase;
|
|
||||||
import net.sf.briar.TestUtils;
|
|
||||||
import net.sf.briar.api.db.DatabaseComponent;
|
|
||||||
import net.sf.briar.api.db.DbException;
|
|
||||||
import net.sf.briar.api.invitation.InvitationCallback;
|
|
||||||
import net.sf.briar.api.invitation.InvitationParameters;
|
|
||||||
import net.sf.briar.api.protocol.Transport;
|
|
||||||
import net.sf.briar.api.protocol.TransportId;
|
|
||||||
import net.sf.briar.api.protocol.TransportIndex;
|
|
||||||
import net.sf.briar.api.serial.Writer;
|
|
||||||
import net.sf.briar.api.serial.WriterFactory;
|
|
||||||
|
|
||||||
import org.jmock.Expectations;
|
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class InvitationWorkerTest extends BriarTestCase {
|
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
testDir.mkdirs();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHaltsIfDestinationDoesNotExist() {
|
|
||||||
final File nonExistent = new File(testDir, "does.not.exist");
|
|
||||||
Mockery context = new Mockery();
|
|
||||||
final InvitationCallback callback =
|
|
||||||
context.mock(InvitationCallback.class);
|
|
||||||
final InvitationParameters params =
|
|
||||||
context.mock(InvitationParameters.class);
|
|
||||||
final DatabaseComponent database =
|
|
||||||
context.mock(DatabaseComponent.class);
|
|
||||||
final WriterFactory writerFactory = context.mock(WriterFactory.class);
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(params).getChosenLocation();
|
|
||||||
will(returnValue(nonExistent));
|
|
||||||
oneOf(callback).notFound(nonExistent);
|
|
||||||
}});
|
|
||||||
|
|
||||||
new InvitationWorker(callback, params, database, writerFactory).run();
|
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
|
||||||
File[] children = testDir.listFiles();
|
|
||||||
assertNotNull(children);
|
|
||||||
assertEquals(0, children.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHaltsIfDestinationIsNotADirectory() throws IOException {
|
|
||||||
final File exists = new File(testDir, "exists");
|
|
||||||
TestUtils.createFile(exists, "foo");
|
|
||||||
assertFalse(exists.isDirectory());
|
|
||||||
Mockery context = new Mockery();
|
|
||||||
final InvitationCallback callback =
|
|
||||||
context.mock(InvitationCallback.class);
|
|
||||||
final InvitationParameters params =
|
|
||||||
context.mock(InvitationParameters.class);
|
|
||||||
final DatabaseComponent database =
|
|
||||||
context.mock(DatabaseComponent.class);
|
|
||||||
final WriterFactory writerFactory = context.mock(WriterFactory.class);
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(params).getChosenLocation();
|
|
||||||
will(returnValue(exists));
|
|
||||||
oneOf(callback).notDirectory(exists);
|
|
||||||
}});
|
|
||||||
|
|
||||||
new InvitationWorker(callback, params, database, writerFactory).run();
|
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
|
||||||
File[] children = testDir.listFiles();
|
|
||||||
assertNotNull(children);
|
|
||||||
assertEquals(1, children.length);
|
|
||||||
assertEquals(exists, children[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreatesExe() throws IOException, DbException {
|
|
||||||
testInstallerCreation(true, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreatesJar() throws IOException, DbException {
|
|
||||||
testInstallerCreation(false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreatesBoth() throws IOException, DbException {
|
|
||||||
testInstallerCreation(true, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreatesNeither() throws IOException, DbException {
|
|
||||||
testInstallerCreation(false, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void testInstallerCreation(final boolean createExe,
|
|
||||||
final boolean createJar) throws IOException, DbException {
|
|
||||||
TransportId transportId = new TransportId(TestUtils.getRandomId());
|
|
||||||
TransportIndex transportIndex = new TransportIndex(13);
|
|
||||||
Transport transport = new Transport(transportId, transportIndex,
|
|
||||||
Collections.singletonMap("foo", "bar"));
|
|
||||||
final Collection<Transport> transports =
|
|
||||||
Collections.singletonList(transport);
|
|
||||||
final File setup = new File(testDir, "setup.dat");
|
|
||||||
TestUtils.createFile(setup, "foo bar baz");
|
|
||||||
final File invitation = new File(testDir, "invitation.dat");
|
|
||||||
final File exe = new File(testDir, "briar.exe");
|
|
||||||
final File jar = new File(testDir, "briar.jar");
|
|
||||||
assertTrue(setup.exists());
|
|
||||||
assertFalse(invitation.exists());
|
|
||||||
assertFalse(exe.exists());
|
|
||||||
assertFalse(jar.exists());
|
|
||||||
final List<File> expectedFiles = new ArrayList<File>();
|
|
||||||
expectedFiles.add(invitation);
|
|
||||||
if(createExe) expectedFiles.add(exe);
|
|
||||||
if(createJar) expectedFiles.add(jar);
|
|
||||||
Mockery context = new Mockery();
|
|
||||||
final InvitationCallback callback =
|
|
||||||
context.mock(InvitationCallback.class);
|
|
||||||
final InvitationParameters params =
|
|
||||||
context.mock(InvitationParameters.class);
|
|
||||||
final DatabaseComponent database =
|
|
||||||
context.mock(DatabaseComponent.class);
|
|
||||||
final WriterFactory writerFactory = context.mock(WriterFactory.class);
|
|
||||||
final Writer writer = context.mock(Writer.class);
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(params).getChosenLocation();
|
|
||||||
will(returnValue(testDir));
|
|
||||||
allowing(callback).isCancelled();
|
|
||||||
will(returnValue(false));
|
|
||||||
oneOf(params).getPassword();
|
|
||||||
will(returnValue(new char[] {'x', 'y', 'z', 'z', 'y'}));
|
|
||||||
oneOf(callback).encryptingFile(invitation);
|
|
||||||
oneOf(database).getLocalTransports();
|
|
||||||
will(returnValue(transports));
|
|
||||||
oneOf(writerFactory).createWriter(with(any(OutputStream.class)));
|
|
||||||
will(returnValue(writer));
|
|
||||||
oneOf(writer).writeList(transports);
|
|
||||||
oneOf(params).shouldCreateExe();
|
|
||||||
will(returnValue(createExe));
|
|
||||||
oneOf(params).shouldCreateJar();
|
|
||||||
will(returnValue(createJar));
|
|
||||||
if(createExe) {
|
|
||||||
oneOf(params).getSetupDat();
|
|
||||||
will(returnValue(setup));
|
|
||||||
oneOf(callback).copyingFile(exe);
|
|
||||||
}
|
|
||||||
if(createJar) {
|
|
||||||
oneOf(params).getSetupDat();
|
|
||||||
will(returnValue(setup));
|
|
||||||
oneOf(callback).copyingFile(jar);
|
|
||||||
}
|
|
||||||
oneOf(callback).created(expectedFiles);
|
|
||||||
}});
|
|
||||||
|
|
||||||
new InvitationWorker(callback, params, database, writerFactory).run();
|
|
||||||
|
|
||||||
assertTrue(invitation.exists());
|
|
||||||
assertEquals(createExe, exe.exists());
|
|
||||||
assertEquals(createJar, jar.exists());
|
|
||||||
if(createExe) assertEquals(exe.length(), setup.length());
|
|
||||||
if(createJar) assertEquals(jar.length(), setup.length());
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
TestUtils.deleteTestDirectory(testDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,171 +0,0 @@
|
|||||||
package net.sf.briar.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
import net.sf.briar.BriarTestCase;
|
|
||||||
import net.sf.briar.TestUtils;
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.setup.SetupCallback;
|
|
||||||
import net.sf.briar.api.setup.SetupParameters;
|
|
||||||
import net.sf.briar.util.ZipUtils;
|
|
||||||
|
|
||||||
import org.jmock.Expectations;
|
|
||||||
import org.jmock.Mockery;
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
public class SetupWorkerTest extends BriarTestCase {
|
|
||||||
|
|
||||||
private static final int HEADER_SIZE = 1234;
|
|
||||||
|
|
||||||
private final File testDir = TestUtils.getTestDirectory();
|
|
||||||
private final File jar = new File(testDir, "test.jar");
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws IOException {
|
|
||||||
testDir.mkdirs();
|
|
||||||
jar.createNewFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHaltsIfNotRunningFromJar() {
|
|
||||||
Mockery context = new Mockery();
|
|
||||||
final SetupCallback callback = context.mock(SetupCallback.class);
|
|
||||||
SetupParameters params = context.mock(SetupParameters.class);
|
|
||||||
I18n i18n = context.mock(I18n.class);
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(callback).error("Not running from jar");
|
|
||||||
}});
|
|
||||||
|
|
||||||
new SetupWorker(callback, params, i18n, testDir).run();
|
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
|
||||||
File[] children = testDir.listFiles();
|
|
||||||
assertNotNull(children);
|
|
||||||
assertEquals(1, children.length);
|
|
||||||
assertEquals(jar, children[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHaltsIfDestinationDoesNotExist() {
|
|
||||||
final File nonExistent = new File(testDir, "does.not.exist");
|
|
||||||
Mockery context = new Mockery();
|
|
||||||
final SetupCallback callback = context.mock(SetupCallback.class);
|
|
||||||
final SetupParameters params = context.mock(SetupParameters.class);
|
|
||||||
I18n i18n = context.mock(I18n.class);
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(params).getChosenLocation();
|
|
||||||
will(returnValue(nonExistent));
|
|
||||||
oneOf(callback).notFound(nonExistent);
|
|
||||||
}});
|
|
||||||
|
|
||||||
new SetupWorker(callback, params, i18n, jar).run();
|
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
|
||||||
File[] children = testDir.listFiles();
|
|
||||||
assertNotNull(children);
|
|
||||||
assertEquals(1, children.length);
|
|
||||||
assertEquals(jar, children[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testHaltsIfDestinationIsNotADirectory() {
|
|
||||||
Mockery context = new Mockery();
|
|
||||||
final SetupCallback callback = context.mock(SetupCallback.class);
|
|
||||||
final SetupParameters params = context.mock(SetupParameters.class);
|
|
||||||
I18n i18n = context.mock(I18n.class);
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(params).getChosenLocation();
|
|
||||||
will(returnValue(jar));
|
|
||||||
oneOf(callback).notDirectory(jar);
|
|
||||||
}});
|
|
||||||
|
|
||||||
new SetupWorker(callback, params, i18n, jar).run();
|
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
|
||||||
File[] children = testDir.listFiles();
|
|
||||||
assertNotNull(children);
|
|
||||||
assertEquals(1, children.length);
|
|
||||||
assertEquals(jar, children[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testCreatesExpectedFiles() throws IOException {
|
|
||||||
final File setupDat = new File(testDir, "Briar/Data/setup.dat");
|
|
||||||
final File jreFoo = new File(testDir, "Briar/Data/jre/foo");
|
|
||||||
final File fooJar = new File(testDir, "Briar/Data/foo.jar");
|
|
||||||
final File fooTtf = new File(testDir, "Briar/Data/foo.ttf");
|
|
||||||
final File fooXyz = new File(testDir, "Briar/Data/foo.xyz");
|
|
||||||
createJar();
|
|
||||||
|
|
||||||
Mockery context = new Mockery();
|
|
||||||
final SetupCallback callback = context.mock(SetupCallback.class);
|
|
||||||
final SetupParameters params = context.mock(SetupParameters.class);
|
|
||||||
final I18n i18n = context.mock(I18n.class);
|
|
||||||
context.checking(new Expectations() {{
|
|
||||||
oneOf(params).getChosenLocation();
|
|
||||||
will(returnValue(testDir));
|
|
||||||
allowing(callback).isCancelled();
|
|
||||||
will(returnValue(false));
|
|
||||||
oneOf(callback).copyingFile(setupDat);
|
|
||||||
oneOf(params).getExeHeaderSize();
|
|
||||||
will(returnValue((long) HEADER_SIZE));
|
|
||||||
oneOf(callback).extractingFile(jreFoo);
|
|
||||||
oneOf(callback).extractingFile(fooJar);
|
|
||||||
oneOf(callback).extractingFile(fooTtf);
|
|
||||||
oneOf(i18n).saveLocale(new File(testDir, "Briar"));
|
|
||||||
oneOf(callback).installed(new File(testDir, "Briar"));
|
|
||||||
}});
|
|
||||||
|
|
||||||
new SetupWorker(callback, params, i18n, jar).run();
|
|
||||||
|
|
||||||
context.assertIsSatisfied();
|
|
||||||
assertTrue(setupDat.exists());
|
|
||||||
assertTrue(setupDat.isFile());
|
|
||||||
assertEquals(jar.length(), setupDat.length());
|
|
||||||
assertTrue(jreFoo.exists());
|
|
||||||
assertTrue(jreFoo.isFile());
|
|
||||||
assertEquals("one one one".length(), jreFoo.length());
|
|
||||||
assertTrue(fooJar.exists());
|
|
||||||
assertTrue(fooJar.isFile());
|
|
||||||
assertEquals("two two two".length(), fooJar.length());
|
|
||||||
assertTrue(fooTtf.exists());
|
|
||||||
assertTrue(fooTtf.isFile());
|
|
||||||
assertEquals("three three three".length(), fooTtf.length());
|
|
||||||
assertFalse(fooXyz.exists());
|
|
||||||
assertTrue(new File(testDir, "Briar/run-windows.vbs").exists());
|
|
||||||
assertTrue(new File(testDir, "Briar/run-mac.command").exists());
|
|
||||||
assertTrue(new File(testDir, "Briar/run-linux.sh").exists());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createJar() throws IOException {
|
|
||||||
FileOutputStream out = new FileOutputStream(jar);
|
|
||||||
byte[] header = new byte[HEADER_SIZE];
|
|
||||||
out.write(header);
|
|
||||||
ZipOutputStream zip = new ZipOutputStream(out);
|
|
||||||
File temp = new File(testDir, "temp");
|
|
||||||
TestUtils.createFile(temp, "one one one");
|
|
||||||
ZipUtils.copyToZip("jre/foo", temp, zip);
|
|
||||||
temp.delete();
|
|
||||||
TestUtils.createFile(temp, "two two two");
|
|
||||||
ZipUtils.copyToZip("foo.jar", temp, zip);
|
|
||||||
temp.delete();
|
|
||||||
TestUtils.createFile(temp, "three three three");
|
|
||||||
ZipUtils.copyToZip("foo.ttf", temp, zip);
|
|
||||||
temp.delete();
|
|
||||||
TestUtils.createFile(temp, "four four four");
|
|
||||||
ZipUtils.copyToZip("foo.xyz", temp, zip);
|
|
||||||
temp.delete();
|
|
||||||
zip.flush();
|
|
||||||
zip.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
TestUtils.deleteTestDirectory(testDir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
1
ui/.gitignore
vendored
1
ui/.gitignore
vendored
@@ -1 +0,0 @@
|
|||||||
/build
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
<project name='ui' default='depend'>
|
|
||||||
<import file='../build-common.xml'/>
|
|
||||||
</project>
|
|
||||||
@@ -1,94 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
|
|
||||||
import javax.swing.ButtonGroup;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
import net.sf.briar.ui.wizard.WizardPanel;
|
|
||||||
|
|
||||||
class ExistingUserPanel extends WizardPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8536392615847105689L;
|
|
||||||
|
|
||||||
private final Stri18ng question, yes, no, unknown;
|
|
||||||
private final JLabel label;
|
|
||||||
private final JRadioButton yesButton, noButton, unknownButton;
|
|
||||||
|
|
||||||
ExistingUserPanel(Wizard wizard, I18n i18n) {
|
|
||||||
super(wizard, "ExistingUser");
|
|
||||||
question = new Stri18ng("INVITATION_EXISTING_USER", i18n);
|
|
||||||
yes = new Stri18ng("YES", i18n);
|
|
||||||
no = new Stri18ng("NO", i18n);
|
|
||||||
unknown = new Stri18ng("UNKNOWN", i18n);
|
|
||||||
label = new JLabel(question.html());
|
|
||||||
Dimension d = wizard.getPreferredSize();
|
|
||||||
label.setPreferredSize(new Dimension(d.width - 50, 50));
|
|
||||||
label.setVerticalAlignment(SwingConstants.TOP);
|
|
||||||
add(label);
|
|
||||||
yesButton = new JRadioButton(yes.tr());
|
|
||||||
noButton = new JRadioButton(no.tr());
|
|
||||||
unknownButton = new JRadioButton(unknown.tr());
|
|
||||||
ButtonGroup group = new ButtonGroup();
|
|
||||||
group.add(yesButton);
|
|
||||||
group.add(noButton);
|
|
||||||
group.add(unknownButton);
|
|
||||||
unknownButton.setSelected(true);
|
|
||||||
JPanel buttonPanel = new JPanel(new GridLayout(3, 1));
|
|
||||||
buttonPanel.add(yesButton);
|
|
||||||
buttonPanel.add(noButton);
|
|
||||||
buttonPanel.add(unknownButton);
|
|
||||||
add(buttonPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
label.setText(question.html());
|
|
||||||
label.setFont(uiFont);
|
|
||||||
yesButton.setText(yes.tr());
|
|
||||||
yesButton.setFont(uiFont);
|
|
||||||
noButton.setText(no.tr());
|
|
||||||
noButton.setFont(uiFont);
|
|
||||||
unknownButton.setText(unknown.tr());
|
|
||||||
unknownButton.setFont(uiFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(true);
|
|
||||||
wizard.setNextButtonEnabled(true);
|
|
||||||
wizard.setFinished(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
wizard.showPanel("Intro");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
if(shouldCreateInstaller()) wizard.showPanel("OperatingSystem");
|
|
||||||
else wizard.showPanel("Password");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldCreateInstaller() {
|
|
||||||
return !yesButton.isSelected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,42 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.TextPanel;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
|
|
||||||
class IntroPanel extends TextPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 2428034340183141779L;
|
|
||||||
|
|
||||||
IntroPanel(Wizard wizard, I18n i18n) {
|
|
||||||
super(wizard, "Intro", new Stri18ng("INVITATION_INTRO", i18n));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(false);
|
|
||||||
wizard.setNextButtonEnabled(true);
|
|
||||||
wizard.setFinished(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
wizard.showPanel("ExistingUser");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import net.sf.briar.api.invitation.InvitationParameters;
|
|
||||||
import net.sf.briar.util.FileUtils;
|
|
||||||
|
|
||||||
class InvitationParametersImpl implements InvitationParameters {
|
|
||||||
|
|
||||||
private final ExistingUserPanel existingUserPanel;
|
|
||||||
private final OperatingSystemPanel osPanel;
|
|
||||||
private final PasswordPanel passwordPanel;
|
|
||||||
private final LocationPanel locationPanel;
|
|
||||||
|
|
||||||
InvitationParametersImpl(ExistingUserPanel existingUserPanel,
|
|
||||||
OperatingSystemPanel osPanel, PasswordPanel passwordPanel,
|
|
||||||
LocationPanel locationPanel) {
|
|
||||||
this.existingUserPanel = existingUserPanel;
|
|
||||||
this.osPanel = osPanel;
|
|
||||||
this.passwordPanel = passwordPanel;
|
|
||||||
this.locationPanel = locationPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldCreateExe() {
|
|
||||||
return existingUserPanel.shouldCreateInstaller()
|
|
||||||
&& osPanel.shouldCreateExe();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean shouldCreateJar() {
|
|
||||||
return existingUserPanel.shouldCreateInstaller()
|
|
||||||
&& osPanel.shouldCreateJar();
|
|
||||||
}
|
|
||||||
|
|
||||||
public char[] getPassword() {
|
|
||||||
return passwordPanel.getPassword();
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getChosenLocation() {
|
|
||||||
return locationPanel.getChosenDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getSetupDat() {
|
|
||||||
return FileUtils.getBriarDirectory();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
|
|
||||||
class InvitationWizard extends Wizard {
|
|
||||||
|
|
||||||
private static final int WIDTH = 400, HEIGHT = 300;
|
|
||||||
|
|
||||||
InvitationWizard(I18n i18n) {
|
|
||||||
super(i18n, new Stri18ng("INVITATION_TITLE", i18n), WIDTH, HEIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void display() {
|
|
||||||
showPanel("Intro");
|
|
||||||
super.display();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.api.invitation.InvitationCallback;
|
|
||||||
import net.sf.briar.api.invitation.InvitationParameters;
|
|
||||||
import net.sf.briar.api.invitation.InvitationWorkerFactory;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
import net.sf.briar.ui.wizard.WorkerPanel;
|
|
||||||
import net.sf.briar.util.StringUtils;
|
|
||||||
|
|
||||||
class InvitationWorkerPanel extends WorkerPanel implements InvitationCallback {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3668512976295525240L;
|
|
||||||
|
|
||||||
private static final int MAX_LINE_LENGTH = 40;
|
|
||||||
|
|
||||||
private final InvitationWorkerFactory workerFactory;
|
|
||||||
private final InvitationParameters parameters;
|
|
||||||
private final Stri18ng copying, encrypting, created, giveToContact;
|
|
||||||
private final Stri18ng aborted, error, notFound, notDir, notAllowed;
|
|
||||||
|
|
||||||
InvitationWorkerPanel(Wizard wizard, InvitationWorkerFactory workerFactory,
|
|
||||||
InvitationParameters parameters, I18n i18n) {
|
|
||||||
super(wizard, "InvitationWorker",
|
|
||||||
new Stri18ng("INVITATION_PROGRESS_BEGIN", i18n),
|
|
||||||
new Stri18ng("CANCELLING", i18n));
|
|
||||||
this.workerFactory = workerFactory;
|
|
||||||
this.parameters = parameters;
|
|
||||||
copying = new Stri18ng("COPYING_FILE", i18n);
|
|
||||||
encrypting = new Stri18ng("ENCRYPTING_FILE", i18n);
|
|
||||||
created = new Stri18ng("INVITATION_CREATED", i18n);
|
|
||||||
giveToContact = new Stri18ng("INVITATION_GIVE_TO_CONTACT", i18n);
|
|
||||||
aborted = new Stri18ng("INVITATION_ABORTED", i18n);
|
|
||||||
error = new Stri18ng("INVITATION_ERROR", i18n);
|
|
||||||
notFound = new Stri18ng("DIRECTORY_NOT_FOUND", i18n);
|
|
||||||
notDir = new Stri18ng("FILE_NOT_DIRECTORY", i18n);
|
|
||||||
notAllowed = new Stri18ng("DIRECTORY_NOT_WRITABLE", i18n);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancelled() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finished() {
|
|
||||||
wizard.setFinished(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Runnable getWorker() {
|
|
||||||
return workerFactory.createWorker(this, parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyingFile(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = copying.html(path);
|
|
||||||
displayProgress(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void encryptingFile(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = encrypting.html(path);
|
|
||||||
displayProgress(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void created(List<File> files) {
|
|
||||||
StringBuilder s = new StringBuilder();
|
|
||||||
for(File f : files) {
|
|
||||||
if(s.length() > 0) s.append("<br>");
|
|
||||||
s.append(StringUtils.tail(f.getPath(), MAX_LINE_LENGTH));
|
|
||||||
}
|
|
||||||
String filenames = s.toString();
|
|
||||||
String html = created.html(filenames, giveToContact.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String message) {
|
|
||||||
String html = error.html(message, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notFound(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = notFound.html(path, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notDirectory(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = notDir.html(path, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notAllowed(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = notAllowed.html(path, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.DirectoryChooserPanel;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
|
|
||||||
class LocationPanel extends DirectoryChooserPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 3788640725729516888L;
|
|
||||||
|
|
||||||
LocationPanel(Wizard wizard, I18n i18n) {
|
|
||||||
super(wizard, "Location", "Password", "InvitationWorker",
|
|
||||||
new Stri18ng("INVITATION_LOCATION_TITLE", i18n),
|
|
||||||
new Stri18ng("INVITATION_LOCATION_TEXT", i18n), i18n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,102 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
|
|
||||||
import javax.swing.ButtonGroup;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
import net.sf.briar.ui.wizard.WizardPanel;
|
|
||||||
|
|
||||||
class OperatingSystemPanel extends WizardPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8370132633634629466L;
|
|
||||||
|
|
||||||
private final Stri18ng question, windows, mac, linux, unknown;
|
|
||||||
private final JLabel questionLabel;
|
|
||||||
private final JRadioButton windowsButton, macButton, linuxButton;
|
|
||||||
private final JRadioButton unknownButton;
|
|
||||||
|
|
||||||
OperatingSystemPanel(Wizard wizard, I18n i18n) {
|
|
||||||
super(wizard, "OperatingSystem");
|
|
||||||
question = new Stri18ng("INVITATION_OPERATING_SYSTEM", i18n);
|
|
||||||
windows = new Stri18ng("WINDOWS", i18n);
|
|
||||||
mac = new Stri18ng("MAC", i18n);
|
|
||||||
linux = new Stri18ng("LINUX", i18n);
|
|
||||||
unknown = new Stri18ng("UNKNOWN", i18n);
|
|
||||||
questionLabel = new JLabel(question.html());
|
|
||||||
Dimension d = wizard.getPreferredSize();
|
|
||||||
questionLabel.setPreferredSize(new Dimension(d.width - 50, 50));
|
|
||||||
questionLabel.setVerticalAlignment(SwingConstants.TOP);
|
|
||||||
add(questionLabel);
|
|
||||||
windowsButton = new JRadioButton(windows.tr());
|
|
||||||
macButton = new JRadioButton(mac.tr());
|
|
||||||
linuxButton = new JRadioButton(linux.tr());
|
|
||||||
unknownButton = new JRadioButton(unknown.tr());
|
|
||||||
ButtonGroup group = new ButtonGroup();
|
|
||||||
group.add(windowsButton);
|
|
||||||
group.add(macButton);
|
|
||||||
group.add(linuxButton);
|
|
||||||
group.add(unknownButton);
|
|
||||||
unknownButton.setSelected(true);
|
|
||||||
JPanel buttonPanel = new JPanel(new GridLayout(4, 1));
|
|
||||||
buttonPanel.add(windowsButton);
|
|
||||||
buttonPanel.add(macButton);
|
|
||||||
buttonPanel.add(linuxButton);
|
|
||||||
buttonPanel.add(unknownButton);
|
|
||||||
add(buttonPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
questionLabel.setText(question.html());
|
|
||||||
questionLabel.setFont(uiFont);
|
|
||||||
windowsButton.setText(windows.tr());
|
|
||||||
windowsButton.setFont(uiFont);
|
|
||||||
macButton.setText(mac.tr());
|
|
||||||
macButton.setFont(uiFont);
|
|
||||||
linuxButton.setText(linux.tr());
|
|
||||||
linuxButton.setFont(uiFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(true);
|
|
||||||
wizard.setNextButtonEnabled(true);
|
|
||||||
wizard.setFinished(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
wizard.showPanel("ExistingUser");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
wizard.showPanel("Password");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldCreateExe() {
|
|
||||||
return windowsButton.isSelected() || unknownButton.isSelected();
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean shouldCreateJar() {
|
|
||||||
return !windowsButton.isSelected();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.FlowLayout;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.event.KeyAdapter;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JPasswordField;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
import net.sf.briar.ui.wizard.WizardPanel;
|
|
||||||
|
|
||||||
class PasswordPanel extends WizardPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -1012132977732308293L;
|
|
||||||
|
|
||||||
private final ExistingUserPanel existingUserPanel;
|
|
||||||
private final Stri18ng intro, enterPassword, confirmPassword;
|
|
||||||
private final JLabel introLabel, enterPasswordLabel, confirmPasswordLabel;
|
|
||||||
private final JPasswordField password1, password2;
|
|
||||||
|
|
||||||
PasswordPanel(Wizard wizard, ExistingUserPanel existingUserPanel,
|
|
||||||
I18n i18n) {
|
|
||||||
super(wizard, "Password");
|
|
||||||
this.existingUserPanel = existingUserPanel;
|
|
||||||
intro = new Stri18ng("INVITATION_PASSWORD", i18n);
|
|
||||||
enterPassword = new Stri18ng("ENTER_PASSWORD", i18n);
|
|
||||||
confirmPassword = new Stri18ng("CONFIRM_PASSWORD", i18n);
|
|
||||||
introLabel = new JLabel(intro.html());
|
|
||||||
Dimension d = wizard.getPreferredSize();
|
|
||||||
introLabel.setPreferredSize(
|
|
||||||
new Dimension(d.width - 50, d.height - 140));
|
|
||||||
introLabel.setVerticalAlignment(SwingConstants.TOP);
|
|
||||||
add(introLabel);
|
|
||||||
JPanel panel1 = new JPanel(new FlowLayout(FlowLayout.LEADING));
|
|
||||||
enterPasswordLabel = new JLabel(enterPassword.tr());
|
|
||||||
enterPasswordLabel.setPreferredSize(
|
|
||||||
new Dimension((d.width - 60) / 2, 20));
|
|
||||||
password1 = new JPasswordField();
|
|
||||||
password1.addKeyListener(new KeyAdapter() {
|
|
||||||
@Override
|
|
||||||
public void keyReleased(KeyEvent e) {
|
|
||||||
checkPasswords();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
password1.setPreferredSize(new Dimension((d.width - 60) / 2, 20));
|
|
||||||
panel1.add(enterPasswordLabel);
|
|
||||||
panel1.add(password1);
|
|
||||||
add(panel1);
|
|
||||||
JPanel panel2 = new JPanel(new FlowLayout(FlowLayout.LEADING));
|
|
||||||
confirmPasswordLabel = new JLabel(confirmPassword.tr());
|
|
||||||
confirmPasswordLabel.setPreferredSize(
|
|
||||||
new Dimension((d.width - 60) / 2, 20));
|
|
||||||
password2 = new JPasswordField();
|
|
||||||
password2.addKeyListener(new KeyAdapter() {
|
|
||||||
@Override
|
|
||||||
public void keyReleased(KeyEvent e) {
|
|
||||||
checkPasswords();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
password2.setPreferredSize(new Dimension((d.width - 60) / 2, 20));
|
|
||||||
panel2.add(confirmPasswordLabel);
|
|
||||||
panel2.add(password2);
|
|
||||||
add(panel2);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
introLabel.setText(intro.html());
|
|
||||||
introLabel.setFont(uiFont);
|
|
||||||
enterPasswordLabel.setText(enterPassword.tr());
|
|
||||||
enterPasswordLabel.setFont(uiFont);
|
|
||||||
confirmPasswordLabel.setText(confirmPassword.tr());
|
|
||||||
confirmPasswordLabel.setFont(uiFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkPasswords() {
|
|
||||||
wizard.setNextButtonEnabled(passwordsMatch());
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean passwordsMatch() {
|
|
||||||
char[] p1 = password1.getPassword();
|
|
||||||
char[] p2 = password2.getPassword();
|
|
||||||
assert p1 != null && p2 != null;
|
|
||||||
boolean ok = p1.length > 3 && p2.length > 3 && Arrays.equals(p1, p2);
|
|
||||||
Arrays.fill(p1, (char) 0);
|
|
||||||
Arrays.fill(p2, (char) 0);
|
|
||||||
return ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(true);
|
|
||||||
wizard.setNextButtonEnabled(false);
|
|
||||||
wizard.setFinished(false);
|
|
||||||
password1.setText("");
|
|
||||||
password2.setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
if(existingUserPanel.shouldCreateInstaller())
|
|
||||||
wizard.showPanel("OperatingSystem");
|
|
||||||
else wizard.showPanel("ExistingUser");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
wizard.showPanel("Location");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public char[] getPassword() {
|
|
||||||
if(passwordsMatch()) return password1.getPassword();
|
|
||||||
else return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package net.sf.briar.ui.invitation;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.invitation.InvitationParameters;
|
|
||||||
import net.sf.briar.api.invitation.InvitationWorkerFactory;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
public class UiInvitationModule extends AbstractModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {}
|
|
||||||
|
|
||||||
@Provides @Singleton
|
|
||||||
InvitationWizard getInvitationWizard(I18n i18n,
|
|
||||||
InvitationWorkerFactory workerFactory) {
|
|
||||||
InvitationWizard wizard = new InvitationWizard(i18n);
|
|
||||||
new IntroPanel(wizard, i18n);
|
|
||||||
ExistingUserPanel userPanel = new ExistingUserPanel(wizard, i18n);
|
|
||||||
OperatingSystemPanel osPanel = new OperatingSystemPanel(wizard, i18n);
|
|
||||||
PasswordPanel passwordPanel =
|
|
||||||
new PasswordPanel(wizard, userPanel, i18n);
|
|
||||||
LocationPanel locationPanel = new LocationPanel(wizard, i18n);
|
|
||||||
InvitationParameters parameters = new InvitationParametersImpl(
|
|
||||||
userPanel, osPanel, passwordPanel, locationPanel);
|
|
||||||
new InvitationWorkerPanel(wizard, workerFactory, parameters, i18n);
|
|
||||||
return wizard;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,95 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import javax.swing.ButtonGroup;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.JRadioButton;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.WizardPanel;
|
|
||||||
|
|
||||||
class AlreadyInstalledPanel extends WizardPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 7908954905165031678L;
|
|
||||||
|
|
||||||
private final Stri18ng question, yes, no;
|
|
||||||
private final JLabel label;
|
|
||||||
private final JRadioButton yesButton, noButton;
|
|
||||||
|
|
||||||
AlreadyInstalledPanel(SetupWizard wizard, I18n i18n) {
|
|
||||||
super(wizard, "AlreadyInstalled");
|
|
||||||
question = new Stri18ng("SETUP_ALREADY_INSTALLED", i18n);
|
|
||||||
yes = new Stri18ng("YES", i18n);
|
|
||||||
no = new Stri18ng("NO", i18n);
|
|
||||||
label = new JLabel(question.html());
|
|
||||||
Dimension d = wizard.getPreferredSize();
|
|
||||||
label.setPreferredSize(new Dimension(d.width - 50, 50));
|
|
||||||
label.setVerticalAlignment(SwingConstants.TOP);
|
|
||||||
add(label);
|
|
||||||
yesButton = new JRadioButton(yes.tr());
|
|
||||||
yesButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
AlreadyInstalledPanel.this.wizard.setNextButtonEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
noButton = new JRadioButton(no.tr());
|
|
||||||
noButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
AlreadyInstalledPanel.this.wizard.setNextButtonEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
ButtonGroup group = new ButtonGroup();
|
|
||||||
group.add(yesButton);
|
|
||||||
group.add(noButton);
|
|
||||||
JPanel buttonPanel = new JPanel(new GridLayout(2, 1));
|
|
||||||
buttonPanel.add(yesButton);
|
|
||||||
buttonPanel.add(noButton);
|
|
||||||
add(buttonPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
label.setText(question.html());
|
|
||||||
label.setFont(uiFont);
|
|
||||||
yesButton.setText(yes.tr());
|
|
||||||
yesButton.setFont(uiFont);
|
|
||||||
noButton.setText(no.tr());
|
|
||||||
noButton.setFont(uiFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(true);
|
|
||||||
wizard.setNextButtonEnabled(yesButton.isSelected() || noButton.isSelected());
|
|
||||||
wizard.setFinished(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
wizard.showPanel("Language");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
if(yesButton.isSelected()) wizard.showPanel("Instructions");
|
|
||||||
else if(noButton.isSelected()) wizard.showPanel("Location");
|
|
||||||
else assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.TextPanel;
|
|
||||||
|
|
||||||
class InstructionsPanel extends TextPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8730283083962607067L;
|
|
||||||
|
|
||||||
InstructionsPanel(SetupWizard wizard, I18n i18n) {
|
|
||||||
super(wizard, "Instructions", new Stri18ng("SETUP_INSTRUCTIONS", i18n));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(true);
|
|
||||||
wizard.setNextButtonEnabled(false);
|
|
||||||
wizard.setFinished(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
wizard.showPanel("AlreadyInstalled");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,140 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import java.awt.Component;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import javax.swing.JComboBox;
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JList;
|
|
||||||
import javax.swing.ListCellRenderer;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.FontManager;
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.WizardPanel;
|
|
||||||
|
|
||||||
class LanguagePanel extends WizardPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 6692353522360807409L;
|
|
||||||
|
|
||||||
// FIXME: Does this have to be hardcoded?
|
|
||||||
// Not static because we want the fonts to be loaded first
|
|
||||||
private final Language english = new Language("English", "en");
|
|
||||||
private final Language[] languages = new Language[] {
|
|
||||||
new Language("\u0627\u0644\u0639\u0631\u0628\u064a\u0629", "ar"),
|
|
||||||
new Language("\u0f60\u0f51\u0f72\u0f60\u0f72\u0f0b\u0f66\u0f90\u0f7c\u0f62\u0f0d", "bo"),
|
|
||||||
new Language("\u4e2d\u6587\uff08\u7b80\u4f53\uff09", "cn"),
|
|
||||||
english,
|
|
||||||
new Language("\u0641\u0627\u0631\u0633\u06cc", "fa"),
|
|
||||||
new Language("\u05e2\u05d1\u05e8\u05d9\u05ea", "he"),
|
|
||||||
new Language("\u65e5\u672c\u8a9e", "ja"),
|
|
||||||
new Language("\ud55c\uad6d\uc5b4", "ko"),
|
|
||||||
new Language("\u1006\u102f\u102d\u1010\u1032\u1037", "my"),
|
|
||||||
new Language("\u0420\u0443\u0441\u0441\u043a\u0438\u0439", "ru"),
|
|
||||||
new Language("Igpay Atinlay", "pg"),
|
|
||||||
new Language("\u0e44\u0e17\u0e22", "th"),
|
|
||||||
new Language("Ti\u1ebfng Vi\u1ec7t", "vi"),
|
|
||||||
};
|
|
||||||
|
|
||||||
private final FontManager fontManager;
|
|
||||||
private final Stri18ng language;
|
|
||||||
private final JLabel label;
|
|
||||||
private final JComboBox comboBox;
|
|
||||||
|
|
||||||
LanguagePanel(SetupWizard wizard, FontManager fontManager,
|
|
||||||
final I18n i18n) {
|
|
||||||
super(wizard, "Language");
|
|
||||||
this.fontManager = fontManager;
|
|
||||||
language = new Stri18ng("SETUP_LANGUAGE", i18n);
|
|
||||||
label = new JLabel(language.html());
|
|
||||||
Dimension d = wizard.getPreferredSize();
|
|
||||||
label.setPreferredSize(new Dimension(d.width - 50, d.height - 120));
|
|
||||||
label.setVerticalAlignment(SwingConstants.TOP);
|
|
||||||
add(label);
|
|
||||||
comboBox = new JComboBox();
|
|
||||||
for(Language l : languages) comboBox.addItem(l);
|
|
||||||
comboBox.setRenderer(new LanguageRenderer());
|
|
||||||
comboBox.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
Language l = (Language) comboBox.getSelectedItem();
|
|
||||||
i18n.setLocale(new Locale(l.code));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
add(comboBox);
|
|
||||||
comboBox.setSelectedItem(english);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
label.setText(language.html());
|
|
||||||
label.setFont(uiFont);
|
|
||||||
comboBox.setFont(uiFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(false);
|
|
||||||
wizard.setNextButtonEnabled(true);
|
|
||||||
wizard.setFinished(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
wizard.showPanel("AlreadyInstalled");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static class Language {
|
|
||||||
|
|
||||||
private final String name, code;
|
|
||||||
|
|
||||||
private Language(String name, String code) {
|
|
||||||
this.name = name;
|
|
||||||
this.code = code;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LanguageRenderer extends JLabel implements ListCellRenderer {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 8562749521807769004L;
|
|
||||||
|
|
||||||
LanguageRenderer() {
|
|
||||||
setHorizontalAlignment(SwingConstants.CENTER);
|
|
||||||
setVerticalAlignment(SwingConstants.CENTER);
|
|
||||||
setPreferredSize(new Dimension(100, 20));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Component getListCellRendererComponent(JList list, Object value,
|
|
||||||
int index, boolean isSelected, boolean cellHasFocus) {
|
|
||||||
Language language = (Language) value;
|
|
||||||
setText(language.name);
|
|
||||||
setFont(fontManager.getFontForLanguage(language.code));
|
|
||||||
if(isSelected) {
|
|
||||||
setBackground(list.getSelectionBackground());
|
|
||||||
setForeground(list.getSelectionForeground());
|
|
||||||
} else {
|
|
||||||
setBackground(list.getBackground());
|
|
||||||
setForeground(list.getForeground());
|
|
||||||
}
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.DirectoryChooserPanel;
|
|
||||||
|
|
||||||
class LocationPanel extends DirectoryChooserPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -8831098591612528860L;
|
|
||||||
|
|
||||||
LocationPanel(SetupWizard wizard, I18n i18n) {
|
|
||||||
super(wizard, "Location", "AlreadyInstalled", "SetupWorker",
|
|
||||||
new Stri18ng("SETUP_LOCATION_TITLE", i18n),
|
|
||||||
new Stri18ng("SETUP_LOCATION_TEXT", i18n), i18n);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import net.sf.briar.api.setup.SetupParameters;
|
|
||||||
|
|
||||||
class SetupParametersImpl implements SetupParameters {
|
|
||||||
|
|
||||||
private static final int EXE_HEADER_SIZE = 62976;
|
|
||||||
|
|
||||||
private final LocationPanel locationPanel;
|
|
||||||
|
|
||||||
SetupParametersImpl(LocationPanel locationPanel) {
|
|
||||||
this.locationPanel = locationPanel;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getChosenLocation() {
|
|
||||||
return locationPanel.getChosenDirectory();
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getExeHeaderSize() {
|
|
||||||
return EXE_HEADER_SIZE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.ui.wizard.Wizard;
|
|
||||||
|
|
||||||
class SetupWizard extends Wizard {
|
|
||||||
|
|
||||||
private static int WIDTH = 400, HEIGHT = 300;
|
|
||||||
|
|
||||||
SetupWizard(I18n i18n) {
|
|
||||||
super(i18n, new Stri18ng("SETUP_TITLE", i18n), WIDTH, HEIGHT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void display() {
|
|
||||||
showPanel("Language");
|
|
||||||
super.display();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
import net.sf.briar.api.setup.SetupCallback;
|
|
||||||
import net.sf.briar.api.setup.SetupParameters;
|
|
||||||
import net.sf.briar.api.setup.SetupWorkerFactory;
|
|
||||||
import net.sf.briar.ui.wizard.WorkerPanel;
|
|
||||||
import net.sf.briar.util.StringUtils;
|
|
||||||
|
|
||||||
class SetupWorkerPanel extends WorkerPanel implements SetupCallback {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 6596714579098160155L;
|
|
||||||
|
|
||||||
private static final int MAX_LINE_LENGTH = 40;
|
|
||||||
|
|
||||||
private final SetupWorkerFactory workerFactory;
|
|
||||||
private final SetupParameters parameters;
|
|
||||||
private final Stri18ng extracting, copying, installed, uninstall;
|
|
||||||
private final Stri18ng aborted, error, notFound, notDir, notAllowed;
|
|
||||||
|
|
||||||
SetupWorkerPanel(SetupWizard wizard, SetupWorkerFactory workerFactory,
|
|
||||||
SetupParameters parameters, I18n i18n) {
|
|
||||||
super(wizard, "SetupWorker",
|
|
||||||
new Stri18ng("SETUP_PROGRESS_BEGIN", i18n),
|
|
||||||
new Stri18ng("CANCELLING", i18n));
|
|
||||||
this.workerFactory = workerFactory;
|
|
||||||
this.parameters = parameters;
|
|
||||||
extracting = new Stri18ng("EXTRACTING_FILE", i18n);
|
|
||||||
copying = new Stri18ng("COPYING_FILE", i18n);
|
|
||||||
installed = new Stri18ng("SETUP_INSTALLED", i18n);
|
|
||||||
uninstall = new Stri18ng("SETUP_UNINSTALL", i18n);
|
|
||||||
aborted = new Stri18ng("SETUP_ABORTED", i18n);
|
|
||||||
error = new Stri18ng("SETUP_ERROR", i18n);
|
|
||||||
notFound = new Stri18ng("DIRECTORY_NOT_FOUND", i18n);
|
|
||||||
notDir = new Stri18ng("FILE_NOT_DIRECTORY", i18n);
|
|
||||||
notAllowed = new Stri18ng("DIRECTORY_NOT_WRITABLE", i18n);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cancelled() {
|
|
||||||
System.exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void finished() {
|
|
||||||
wizard.setFinished(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Runnable getWorker() {
|
|
||||||
return workerFactory.createWorker(this, parameters);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isCancelled() {
|
|
||||||
return cancelled.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void extractingFile(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = extracting.html(path);
|
|
||||||
displayProgress(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void copyingFile(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = copying.html(path);
|
|
||||||
displayProgress(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void installed(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = installed.html(path, uninstall.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void error(String message) {
|
|
||||||
String html = error.html(message, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notFound(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = notFound.html(path, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notDirectory(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = notDir.html(path, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void notAllowed(File f) {
|
|
||||||
String path = StringUtils.tail(f.getPath(), MAX_LINE_LENGTH);
|
|
||||||
String html = notAllowed.html(path, aborted.tr());
|
|
||||||
done(html);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package net.sf.briar.ui.setup;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.FontManager;
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.setup.SetupParameters;
|
|
||||||
import net.sf.briar.api.setup.SetupWorkerFactory;
|
|
||||||
|
|
||||||
import com.google.inject.AbstractModule;
|
|
||||||
import com.google.inject.Provides;
|
|
||||||
import com.google.inject.Singleton;
|
|
||||||
|
|
||||||
public class UiSetupModule extends AbstractModule {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void configure() {}
|
|
||||||
|
|
||||||
@Provides @Singleton
|
|
||||||
SetupWizard getSetupWizard(I18n i18n, FontManager fontManager,
|
|
||||||
SetupWorkerFactory workerFactory) {
|
|
||||||
SetupWizard wizard = new SetupWizard(i18n);
|
|
||||||
new LanguagePanel(wizard, fontManager, i18n);
|
|
||||||
new AlreadyInstalledPanel(wizard, i18n);
|
|
||||||
new InstructionsPanel(wizard, i18n);
|
|
||||||
LocationPanel locationPanel = new LocationPanel(wizard, i18n);
|
|
||||||
SetupParameters parameters = new SetupParametersImpl(locationPanel);
|
|
||||||
new SetupWorkerPanel(wizard, workerFactory, parameters, i18n);
|
|
||||||
return wizard;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package net.sf.briar.ui.wizard;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import javax.swing.JFileChooser;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
|
|
||||||
public class DirectoryChooserPanel extends TextPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 6692353522360807409L;
|
|
||||||
|
|
||||||
private final String prevId, nextId;
|
|
||||||
private final Stri18ng title;
|
|
||||||
private final I18n i18n;
|
|
||||||
private volatile File chosenDirectory = null;
|
|
||||||
|
|
||||||
protected DirectoryChooserPanel(Wizard wizard, String id, String prevId,
|
|
||||||
String nextId, Stri18ng title, Stri18ng text, I18n i18n) {
|
|
||||||
super(wizard, id, text);
|
|
||||||
this.prevId = prevId;
|
|
||||||
this.nextId = nextId;
|
|
||||||
this.title = title;
|
|
||||||
this.i18n = i18n;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
wizard.setBackButtonEnabled(true);
|
|
||||||
wizard.setNextButtonEnabled(true);
|
|
||||||
wizard.setFinished(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void backButtonPressed() {
|
|
||||||
wizard.showPanel(prevId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void nextButtonPressed() {
|
|
||||||
JFileChooser chooser;
|
|
||||||
String home = System.getProperty("user.home");
|
|
||||||
if(home == null) chooser = new JFileChooser();
|
|
||||||
else chooser = new JFileChooser(home);
|
|
||||||
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
|
||||||
chooser.setDialogTitle(title.tr());
|
|
||||||
chooser.setComponentOrientation(i18n.getComponentOrientation());
|
|
||||||
int result = chooser.showSaveDialog(this);
|
|
||||||
if(result == JFileChooser.APPROVE_OPTION) {
|
|
||||||
File dir = chooser.getSelectedFile();
|
|
||||||
assert dir != null;
|
|
||||||
assert dir.exists();
|
|
||||||
assert dir.isDirectory();
|
|
||||||
chosenDirectory = dir;
|
|
||||||
wizard.showPanel(nextId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
wizard.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void finishButtonPressed() {
|
|
||||||
assert false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getChosenDirectory() {
|
|
||||||
return chosenDirectory;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package net.sf.briar.ui.wizard;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
|
|
||||||
public abstract class TextPanel extends WizardPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -3046102503813671049L;
|
|
||||||
|
|
||||||
private final Stri18ng text;
|
|
||||||
private final JLabel label;
|
|
||||||
|
|
||||||
protected TextPanel(Wizard wizard, String id, Stri18ng text) {
|
|
||||||
super(wizard, id);
|
|
||||||
this.text = text;
|
|
||||||
label = new JLabel(text.html());
|
|
||||||
Dimension d = wizard.getPreferredSize();
|
|
||||||
label.setPreferredSize(new Dimension(d.width - 50, d.height - 80));
|
|
||||||
label.setVerticalAlignment(SwingConstants.TOP);
|
|
||||||
add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
label.setText(text.html());
|
|
||||||
label.setFont(uiFont);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,180 +0,0 @@
|
|||||||
package net.sf.briar.ui.wizard;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.CardLayout;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.FlowLayout;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.awt.Insets;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.WindowAdapter;
|
|
||||||
import java.awt.event.WindowEvent;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import javax.swing.Box;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
import javax.swing.JFrame;
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.border.EmptyBorder;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
|
|
||||||
public class Wizard implements I18n.Listener {
|
|
||||||
|
|
||||||
private final I18n i18n;
|
|
||||||
private final Stri18ng title, back, next, cancel, finish;
|
|
||||||
private final Map<String, WizardPanel> panels;
|
|
||||||
private final JPanel cardPanel;
|
|
||||||
private final CardLayout cardLayout;
|
|
||||||
private final JButton backButton, nextButton, cancelButton;
|
|
||||||
private final JFrame frame;
|
|
||||||
private final Object finishedLock = new Object();
|
|
||||||
private WizardPanel currentPanel = null;
|
|
||||||
private volatile boolean finished = false;
|
|
||||||
|
|
||||||
public Wizard(I18n i18n, Stri18ng title, int width, int height) {
|
|
||||||
this.i18n = i18n;
|
|
||||||
this.title = title;
|
|
||||||
back = new Stri18ng("BACK", i18n);
|
|
||||||
next = new Stri18ng("NEXT", i18n);
|
|
||||||
cancel = new Stri18ng("CANCEL", i18n);
|
|
||||||
finish = new Stri18ng("FINISH", i18n);
|
|
||||||
panels = new HashMap<String, WizardPanel>();
|
|
||||||
cardPanel = new JPanel();
|
|
||||||
cardPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
|
|
||||||
cardLayout = new CardLayout();
|
|
||||||
cardPanel.setLayout(cardLayout);
|
|
||||||
|
|
||||||
backButton = new JButton(back.tr());
|
|
||||||
backButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
backButtonPressed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
nextButton = new JButton(next.tr());
|
|
||||||
nextButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
nextButtonPressed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
cancelButton = new JButton(cancel.tr());
|
|
||||||
cancelButton.addActionListener(new ActionListener() {
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
closeButtonPressed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JPanel buttonPanel = new JPanel();
|
|
||||||
buttonPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
|
|
||||||
buttonPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
|
|
||||||
buttonPanel.add(backButton);
|
|
||||||
buttonPanel.add(Box.createHorizontalStrut(10));
|
|
||||||
buttonPanel.add(nextButton);
|
|
||||||
buttonPanel.add(Box.createHorizontalStrut(30));
|
|
||||||
buttonPanel.add(cancelButton);
|
|
||||||
|
|
||||||
frame = new JFrame(title.tr());
|
|
||||||
frame.setPreferredSize(new Dimension(width, height));
|
|
||||||
frame.setResizable(false);
|
|
||||||
frame.addWindowListener(new WindowAdapter() {
|
|
||||||
@Override
|
|
||||||
public void windowClosing(WindowEvent e) {
|
|
||||||
closeButtonPressed();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
frame.getContentPane().add(cardPanel, BorderLayout.CENTER);
|
|
||||||
frame.getContentPane().add(buttonPanel, BorderLayout.SOUTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
backButton.setText(back.tr());
|
|
||||||
backButton.setFont(uiFont);
|
|
||||||
nextButton.setText(next.tr());
|
|
||||||
nextButton.setFont(uiFont);
|
|
||||||
synchronized(finishedLock) {
|
|
||||||
if(finished) cancelButton.setText(finish.tr());
|
|
||||||
else cancelButton.setText(cancel.tr());
|
|
||||||
}
|
|
||||||
cancelButton.setFont(uiFont);
|
|
||||||
frame.setTitle(title.tr());
|
|
||||||
for(WizardPanel panel : panels.values()) panel.localeChanged(uiFont);
|
|
||||||
frame.applyComponentOrientation(i18n.getComponentOrientation());
|
|
||||||
SwingUtilities.updateComponentTreeUI(frame);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void display() {
|
|
||||||
assert currentPanel != null;
|
|
||||||
i18n.addListener(this);
|
|
||||||
frame.pack();
|
|
||||||
frame.setLocationRelativeTo(null); // Centre of the screen
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void close() {
|
|
||||||
i18n.removeListener(this);
|
|
||||||
frame.setVisible(false);
|
|
||||||
frame.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerPanel(String id, WizardPanel panel) {
|
|
||||||
assert currentPanel == null;
|
|
||||||
WizardPanel old = panels.put(id, panel);
|
|
||||||
assert old == null;
|
|
||||||
cardPanel.add(id, panel);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void showPanel(String id) {
|
|
||||||
currentPanel = panels.get(id);
|
|
||||||
assert currentPanel != null;
|
|
||||||
cardLayout.show(cardPanel, id);
|
|
||||||
currentPanel.display();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBackButtonEnabled(boolean enabled) {
|
|
||||||
backButton.setEnabled(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNextButtonEnabled(boolean enabled) {
|
|
||||||
nextButton.setEnabled(enabled);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFinished(boolean finished) {
|
|
||||||
synchronized(finishedLock) {
|
|
||||||
this.finished = finished;
|
|
||||||
if(finished) {
|
|
||||||
nextButton.setEnabled(false);
|
|
||||||
cancelButton.setText(finish.tr());
|
|
||||||
} else cancelButton.setText(cancel.tr());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Dimension getPreferredSize() {
|
|
||||||
return frame.getPreferredSize();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void backButtonPressed() {
|
|
||||||
assert SwingUtilities.isEventDispatchThread();
|
|
||||||
assert currentPanel != null;
|
|
||||||
currentPanel.backButtonPressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void nextButtonPressed() {
|
|
||||||
assert SwingUtilities.isEventDispatchThread();
|
|
||||||
assert currentPanel != null;
|
|
||||||
currentPanel.nextButtonPressed();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void closeButtonPressed() {
|
|
||||||
assert SwingUtilities.isEventDispatchThread();
|
|
||||||
assert currentPanel != null;
|
|
||||||
cancelButton.setEnabled(false);
|
|
||||||
synchronized(finishedLock) {
|
|
||||||
if(finished) currentPanel.finishButtonPressed();
|
|
||||||
else currentPanel.cancelButtonPressed();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
package net.sf.briar.ui.wizard;
|
|
||||||
|
|
||||||
import javax.swing.JPanel;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.I18n;
|
|
||||||
|
|
||||||
public abstract class WizardPanel extends JPanel implements I18n.Listener {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 8657047449339969485L;
|
|
||||||
|
|
||||||
protected final Wizard wizard;
|
|
||||||
|
|
||||||
protected WizardPanel(Wizard wizard, String id) {
|
|
||||||
this.wizard = wizard;
|
|
||||||
wizard.registerPanel(id, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void display();
|
|
||||||
|
|
||||||
protected abstract void backButtonPressed();
|
|
||||||
|
|
||||||
protected abstract void nextButtonPressed();
|
|
||||||
|
|
||||||
protected abstract void cancelButtonPressed();
|
|
||||||
|
|
||||||
protected abstract void finishButtonPressed();
|
|
||||||
}
|
|
||||||
@@ -1,90 +0,0 @@
|
|||||||
package net.sf.briar.ui.wizard;
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.Font;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import javax.swing.JLabel;
|
|
||||||
import javax.swing.JProgressBar;
|
|
||||||
import javax.swing.SwingConstants;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
import net.sf.briar.api.i18n.Stri18ng;
|
|
||||||
|
|
||||||
public abstract class WorkerPanel extends WizardPanel {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -3761407066345183330L;
|
|
||||||
|
|
||||||
private final Stri18ng starting, cancelling;
|
|
||||||
private final JLabel label;
|
|
||||||
private final JProgressBar progress;
|
|
||||||
private final AtomicBoolean started;
|
|
||||||
|
|
||||||
protected final AtomicBoolean cancelled;
|
|
||||||
|
|
||||||
protected WorkerPanel(Wizard wizard, String id, Stri18ng starting,
|
|
||||||
Stri18ng cancelling) {
|
|
||||||
super(wizard, id);
|
|
||||||
this.starting = starting;
|
|
||||||
this.cancelling = cancelling;
|
|
||||||
label = new JLabel(starting.html());
|
|
||||||
Dimension d = wizard.getPreferredSize();
|
|
||||||
label.setPreferredSize(new Dimension(d.width - 50, d.height - 120));
|
|
||||||
label.setVerticalAlignment(SwingConstants.TOP);
|
|
||||||
add(label);
|
|
||||||
progress = new JProgressBar();
|
|
||||||
progress.setIndeterminate(true);
|
|
||||||
progress.setPreferredSize(new Dimension(d.width - 50, 20));
|
|
||||||
add(progress);
|
|
||||||
started = new AtomicBoolean(false);
|
|
||||||
cancelled = new AtomicBoolean(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void localeChanged(Font uiFont) {
|
|
||||||
label.setText(starting.html());
|
|
||||||
label.setFont(uiFont);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void cancelled();
|
|
||||||
|
|
||||||
public abstract void finished();
|
|
||||||
|
|
||||||
protected abstract Runnable getWorker();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void display() {
|
|
||||||
if(!started.getAndSet(true)) {
|
|
||||||
wizard.setBackButtonEnabled(false);
|
|
||||||
wizard.setNextButtonEnabled(false);
|
|
||||||
wizard.setFinished(false);
|
|
||||||
new Thread(getWorker()).start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void cancelButtonPressed() {
|
|
||||||
if(!cancelled.getAndSet(true)) {
|
|
||||||
wizard.setBackButtonEnabled(false);
|
|
||||||
wizard.setNextButtonEnabled(false);
|
|
||||||
label.setText(cancelling.html());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void displayProgress(final String message) {
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
label.setText("<html>" + message + "</html>");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void done(final String message) {
|
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
progress.setVisible(false);
|
|
||||||
label.setText("<html>" + message + "</html>");
|
|
||||||
finished();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user