Initial commit with new directory structure.

This commit is contained in:
akwizgran
2011-06-21 18:01:28 +01:00
commit cd4f99df3d
98 changed files with 5811 additions and 0 deletions

1
ui/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
/build

3
ui/build.xml Normal file
View File

@@ -0,0 +1,3 @@
<project name='ui' default='compile'>
<import file='../build-common.xml'/>
</project>

View File

@@ -0,0 +1,94 @@
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();
}
}

View File

@@ -0,0 +1,42 @@
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;
}
}

View File

@@ -0,0 +1,50 @@
package net.sf.briar.ui.invitation;
import java.io.File;
import net.sf.briar.api.i18n.FontManager;
import net.sf.briar.api.invitation.InvitationParameters;
import com.google.inject.Inject;
class InvitationParametersImpl implements InvitationParameters {
private final ExistingUserPanel existingUserPanel;
private final OperatingSystemPanel osPanel;
private final PasswordPanel passwordPanel;
private final LocationPanel locationPanel;
private final FontManager fontManager;
@Inject
InvitationParametersImpl(ExistingUserPanel existingUserPanel,
OperatingSystemPanel osPanel, PasswordPanel passwordPanel,
LocationPanel locationPanel, FontManager fontManager) {
this.existingUserPanel = existingUserPanel;
this.osPanel = osPanel;
this.passwordPanel = passwordPanel;
this.locationPanel = locationPanel;
this.fontManager = fontManager;
}
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 String[] getBundledFontFilenames() {
return fontManager.getBundledFontFilenames();
}
}

View File

@@ -0,0 +1,19 @@
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);
}
public void display() {
showPanel("Intro");
super.display();
}
}

View File

@@ -0,0 +1,123 @@
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);
}
}

View File

@@ -0,0 +1,20 @@
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;
import com.google.inject.Inject;
class LocationPanel extends DirectoryChooserPanel {
private static final long serialVersionUID = 3788640725729516888L;
@Inject
LocationPanel(Wizard wizard, I18n i18n) {
super(wizard, "Location", "Password", "InvitationWorker",
new Stri18ng("INVITATION_LOCATION_TITLE", i18n),
new Stri18ng("INVITATION_LOCATION_TEXT", i18n), i18n);
}
}

View File

@@ -0,0 +1,105 @@
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;
import com.google.inject.Inject;
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;
@Inject
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();
}
}

View File

@@ -0,0 +1,135 @@
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;
import com.google.inject.Inject;
public 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;
@Inject
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;
}
}

View File

@@ -0,0 +1,32 @@
package net.sf.briar.ui.invitation;
import net.sf.briar.api.i18n.FontManager;
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, FontManager fontManager,
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, fontManager);
new InvitationWorkerPanel(wizard, workerFactory, parameters, i18n);
return wizard;
}
}

View File

@@ -0,0 +1,95 @@
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;
}
}

View File

@@ -0,0 +1,41 @@
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);
}
}

View File

@@ -0,0 +1,140 @@
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;
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;
}
}
}

View File

@@ -0,0 +1,16 @@
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;
public 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);
}
}

View File

@@ -0,0 +1,25 @@
package net.sf.briar.ui.setup;
import java.io.File;
import net.sf.briar.api.i18n.FontManager;
import net.sf.briar.api.setup.SetupParameters;
class SetupParametersImpl implements SetupParameters {
private final LocationPanel locationPanel;
private final FontManager fontManager;
SetupParametersImpl(LocationPanel locationPanel, FontManager fontManager) {
this.locationPanel = locationPanel;
this.fontManager = fontManager;
}
public File getChosenLocation() {
return locationPanel.getChosenDirectory();
}
public String[] getBundledFontFilenames() {
return fontManager.getBundledFontFilenames();
}
}

View File

@@ -0,0 +1,19 @@
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;
public class SetupWizard extends Wizard {
private static int WIDTH = 400, HEIGHT = 300;
SetupWizard(I18n i18n) {
super(i18n, new Stri18ng("SETUP_TITLE", i18n), WIDTH, HEIGHT);
}
public void display() {
showPanel("Language");
super.display();
}
}

View File

@@ -0,0 +1,116 @@
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);
}
}

View File

@@ -0,0 +1,30 @@
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, fontManager);
new SetupWorkerPanel(wizard, workerFactory, parameters, i18n);
return wizard;
}
}

View File

@@ -0,0 +1,73 @@
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;
}
}

View File

@@ -0,0 +1,32 @@
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);
}
}

View File

@@ -0,0 +1,179 @@
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() {
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();
}
}
}

View File

@@ -0,0 +1,27 @@
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();
}

View File

@@ -0,0 +1,90 @@
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();
}
});
}
}