forked from I2P_Developers/i2p.i2p
format (shendaras)
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
@@ -26,22 +28,22 @@ public class CliInstall extends Install {
|
||||
}
|
||||
|
||||
public void startOptCategory(String s) {
|
||||
_out.println("* "+s+"\n");
|
||||
_out.println("* " + s + "\n");
|
||||
}
|
||||
|
||||
public void finishOptions() {}
|
||||
public void finishOptions() {
|
||||
}
|
||||
|
||||
public void handleOption(int number, String question,
|
||||
String def, String type) {
|
||||
public void handleOption(int number, String question, String def, String type) {
|
||||
Object value;
|
||||
while(true) {
|
||||
while (true) {
|
||||
String answer;
|
||||
_out.print(question+(def == null?"": (" ["+def+"]"))+": ");
|
||||
_out.print(question + (def == null ? "" : (" [" + def + "]")) + ": ");
|
||||
answer = readLine();
|
||||
if ("".equals(answer) && def != null) {
|
||||
answer = def;
|
||||
}
|
||||
if (setOption(number,answer)) break;
|
||||
if (setOption(number, answer)) break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +65,7 @@ public class CliInstall extends Install {
|
||||
private boolean readBool(boolean defaultYes) {
|
||||
String str = readLine().toLowerCase();
|
||||
if ("".equals(str)) return defaultYes;
|
||||
return "yes".equals(str) || "y".equals(str) || "true".equals(str)
|
||||
|| "ok".equals(str) || "sure".equals(str)
|
||||
return "yes".equals(str) || "y".equals(str) || "true".equals(str) || "ok".equals(str) || "sure".equals(str)
|
||||
|| "whatever".equals(str);
|
||||
}
|
||||
}
|
||||
@@ -33,17 +33,16 @@ public class FetchSeeds {
|
||||
URL source = new URL(sourceURL);
|
||||
URLConnection con = source.openConnection();
|
||||
in = con.getInputStream();
|
||||
BufferedReader br = new BufferedReader
|
||||
(new InputStreamReader(in));
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
String line;
|
||||
while ((line = br.readLine())!= null) {
|
||||
while ((line = br.readLine()) != null) {
|
||||
int pos = line.indexOf(" <a href=\"routerInfo-");
|
||||
if (pos == -1) continue;
|
||||
line=line.substring(pos+10);
|
||||
pos=line.indexOf("\"");
|
||||
line = line.substring(pos + 10);
|
||||
pos = line.indexOf("\"");
|
||||
if (pos == -1) continue;
|
||||
line=line.substring(0,pos);
|
||||
fetchFile(new File(destination, line), sourceURL+line);
|
||||
line = line.substring(0, pos);
|
||||
fetchFile(new File(destination, line), sourceURL + line);
|
||||
System.out.println(line);
|
||||
}
|
||||
br.close();
|
||||
@@ -53,19 +52,21 @@ public class FetchSeeds {
|
||||
//ex.printStackTrace();
|
||||
return false;
|
||||
} finally {
|
||||
if (in != null) try { in.close(); } catch (IOException ioe) {}
|
||||
if (in != null) try {
|
||||
in.close();
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void fetchFile(File destFile, String fileURL)
|
||||
throws IOException {
|
||||
public static void fetchFile(File destFile, String fileURL) throws IOException {
|
||||
URL url = new URL(fileURL);
|
||||
InputStream in = url.openStream();
|
||||
OutputStream out = new FileOutputStream(destFile);
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len=in.read(buf)) != -1) {
|
||||
out.write(buf,0,len);
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.flush();
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.CardLayout;
|
||||
@@ -24,18 +26,18 @@ import java.util.StringTokenizer;
|
||||
|
||||
public class GUIInstall extends Install {
|
||||
|
||||
static final GridBagConstraints gbcLeft=new GridBagConstraints();
|
||||
static final GridBagConstraints gbcRight=new GridBagConstraints();
|
||||
static final GridBagConstraints gbcBottom=new GridBagConstraints();
|
||||
static final GridBagConstraints gbcLeft = new GridBagConstraints();
|
||||
static final GridBagConstraints gbcRight = new GridBagConstraints();
|
||||
static final GridBagConstraints gbcBottom = new GridBagConstraints();
|
||||
static {
|
||||
gbcLeft.anchor=GridBagConstraints.EAST;
|
||||
gbcRight.fill=GridBagConstraints.HORIZONTAL;
|
||||
gbcRight.gridwidth=GridBagConstraints.REMAINDER;
|
||||
gbcRight.weightx=1.0;
|
||||
gbcBottom.weighty=1.0;
|
||||
gbcBottom.gridwidth=GridBagConstraints.REMAINDER;
|
||||
gbcBottom.fill=GridBagConstraints.BOTH;
|
||||
gbcBottom.insets=new Insets(4,4,4,4);
|
||||
gbcLeft.anchor = GridBagConstraints.EAST;
|
||||
gbcRight.fill = GridBagConstraints.HORIZONTAL;
|
||||
gbcRight.gridwidth = GridBagConstraints.REMAINDER;
|
||||
gbcRight.weightx = 1.0;
|
||||
gbcBottom.weighty = 1.0;
|
||||
gbcBottom.gridwidth = GridBagConstraints.REMAINDER;
|
||||
gbcBottom.fill = GridBagConstraints.BOTH;
|
||||
gbcBottom.insets = new Insets(4, 4, 4, 4);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -43,7 +45,7 @@ public class GUIInstall extends Install {
|
||||
}
|
||||
|
||||
private InstallFrame frame;
|
||||
boolean installing=false;
|
||||
boolean installing = false;
|
||||
ArrayList categories = new ArrayList();
|
||||
InstallCategory currentCategory = null;
|
||||
|
||||
@@ -52,14 +54,12 @@ public class GUIInstall extends Install {
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
public GUIInstall() {
|
||||
frame = new InstallFrame();
|
||||
}
|
||||
|
||||
public void showStatus(String s) {
|
||||
if (!installing)
|
||||
throw new RuntimeException("Not installing yet!");
|
||||
if (!installing) throw new RuntimeException("Not installing yet!");
|
||||
frame.showStatus(s);
|
||||
}
|
||||
|
||||
@@ -81,8 +81,7 @@ public class GUIInstall extends Install {
|
||||
System.out.println("Starting install...");
|
||||
}
|
||||
|
||||
public void handleOption(int number, String question,
|
||||
String def, String type) {
|
||||
public void handleOption(int number, String question, String def, String type) {
|
||||
currentCategory.addOption(number, question, def, type);
|
||||
}
|
||||
|
||||
@@ -93,9 +92,9 @@ public class GUIInstall extends Install {
|
||||
|
||||
private class ConfirmFrame extends Dialog {
|
||||
private boolean result;
|
||||
private ConfirmFrame(Frame parent, String msg,
|
||||
boolean defaultYes) {
|
||||
super(parent,"Installer question",true);
|
||||
|
||||
private ConfirmFrame(Frame parent, String msg, boolean defaultYes) {
|
||||
super(parent, "Installer question", true);
|
||||
setBackground(Color.lightGray);
|
||||
setLayout(new BorderLayout());
|
||||
TextArea ta;
|
||||
@@ -119,7 +118,7 @@ public class GUIInstall extends Install {
|
||||
// java 1.4
|
||||
//setLocationRelativeTo(parent);
|
||||
show();
|
||||
(defaultYes?b1:b2).requestFocus();
|
||||
(defaultYes ? b1 : b2).requestFocus();
|
||||
}
|
||||
|
||||
private boolean getResult() {
|
||||
@@ -132,32 +131,45 @@ public class GUIInstall extends Install {
|
||||
add(new InfoOption(s));
|
||||
}
|
||||
|
||||
public void addOption(int number, String question,
|
||||
String def, String type) {
|
||||
public void addOption(int number, String question, String def, String type) {
|
||||
add(new RealOption(number, question, def, type));
|
||||
}
|
||||
}
|
||||
|
||||
private interface InstallOption {
|
||||
public Component getComponent1();
|
||||
|
||||
public Component getComponent2();
|
||||
|
||||
public boolean setValue();
|
||||
|
||||
public String getQuestion();
|
||||
}
|
||||
|
||||
private class InfoOption extends Panel implements InstallOption {
|
||||
|
||||
public InfoOption(String s) {
|
||||
super(new GridLayout(0,1,0,0));
|
||||
for(StringTokenizer st = new StringTokenizer(s,"\n");
|
||||
st.hasMoreTokens();) {
|
||||
super(new GridLayout(0, 1, 0, 0));
|
||||
for (StringTokenizer st = new StringTokenizer(s, "\n"); st.hasMoreTokens();) {
|
||||
add(new Label(st.nextToken()));
|
||||
}
|
||||
}
|
||||
public Component getComponent1() { return null;}
|
||||
public Component getComponent2() { return this;}
|
||||
public boolean setValue() {return true;}
|
||||
public String getQuestion() { return "<no question>";}
|
||||
|
||||
public Component getComponent1() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public Component getComponent2() {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean setValue() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getQuestion() {
|
||||
return "<no question>";
|
||||
}
|
||||
}
|
||||
|
||||
private class RealOption implements InstallOption {
|
||||
@@ -167,26 +179,34 @@ public class GUIInstall extends Install {
|
||||
private Label l;
|
||||
private TextField t;
|
||||
|
||||
public RealOption(int number, String question,
|
||||
String def, String type) {
|
||||
public RealOption(int number, String question, String def, String type) {
|
||||
this.number = number;
|
||||
l = new Label(question);
|
||||
t = new TextField(def);
|
||||
this.def=def;
|
||||
this.question=question;
|
||||
this.def = def;
|
||||
this.question = question;
|
||||
// type is not needed yet
|
||||
}
|
||||
|
||||
public void reset() {t.setText(def);}
|
||||
public void reset() {
|
||||
t.setText(def);
|
||||
}
|
||||
|
||||
public String getQuestion() { return question; }
|
||||
public String getQuestion() {
|
||||
return question;
|
||||
}
|
||||
|
||||
public boolean setValue() {
|
||||
return GUIInstall.this.setOption(number, t.getText());
|
||||
}
|
||||
|
||||
public Component getComponent1() { return l;}
|
||||
public Component getComponent2() { return t;}
|
||||
public Component getComponent1() {
|
||||
return l;
|
||||
}
|
||||
|
||||
public Component getComponent2() {
|
||||
return t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -205,18 +225,18 @@ public class GUIInstall extends Install {
|
||||
Button b;
|
||||
setLayout(new BorderLayout());
|
||||
add("Center", cats = new Panel(cl = new CardLayout()));
|
||||
cats.add("Start", p= new Panel(new BorderLayout()));
|
||||
cats.add("Start", p = new Panel(new BorderLayout()));
|
||||
p.add("Center", new Label("Loading installer..."));
|
||||
cats.add("Install", p= new Panel(new BorderLayout()));
|
||||
p.add("Center", log=new TextArea("Installing...\n\n"));
|
||||
cats.add("Install", p = new Panel(new BorderLayout()));
|
||||
p.add("Center", log = new TextArea("Installing...\n\n"));
|
||||
log.setEditable(false);
|
||||
add("South", p = new Panel(new FlowLayout()));
|
||||
p.add(b = new Button("<< Back"));
|
||||
b.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
if (current > 0) {
|
||||
current --;
|
||||
cl.show(cats,""+current);
|
||||
current--;
|
||||
cl.show(cats, "" + current);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -225,17 +245,17 @@ public class GUIInstall extends Install {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
if (current != -1) {
|
||||
if (!saveCurrent()) return;
|
||||
current ++;
|
||||
current++;
|
||||
if (current == categoryPanels.length) {
|
||||
cl.show(cats,"Install");
|
||||
cl.show(cats, "Install");
|
||||
current = -1;
|
||||
synchronized(InstallFrame.this) {
|
||||
installing=true;
|
||||
windowOpen=false;
|
||||
synchronized (InstallFrame.this) {
|
||||
installing = true;
|
||||
windowOpen = false;
|
||||
InstallFrame.this.notify();
|
||||
}
|
||||
} else {
|
||||
cl.show(cats,""+current);
|
||||
cl.show(cats, "" + current);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -251,7 +271,7 @@ public class GUIInstall extends Install {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
setSize(600,450);
|
||||
setSize(600, 450);
|
||||
|
||||
// java 1.4
|
||||
//setLocationRelativeTo(null);
|
||||
@@ -259,8 +279,9 @@ public class GUIInstall extends Install {
|
||||
}
|
||||
|
||||
public void showStatus(String s) {
|
||||
log.append(s+"\n");
|
||||
log.append(s + "\n");
|
||||
}
|
||||
|
||||
public void showOptError(String s) {
|
||||
if (current == -1) throw new RuntimeException("No options here!");
|
||||
categoryPanels[current].showError(s);
|
||||
@@ -273,15 +294,14 @@ public class GUIInstall extends Install {
|
||||
categoryPanels = new CategoryPanel[categories.size()];
|
||||
//build a panel for each category
|
||||
Iterator it = categories.iterator();
|
||||
for (int i=0; it.hasNext(); i++) {
|
||||
cats.add(""+i, categoryPanels[i] =
|
||||
new CategoryPanel((InstallCategory)it.next()));
|
||||
for (int i = 0; it.hasNext(); i++) {
|
||||
cats.add("" + i, categoryPanels[i] = new CategoryPanel((InstallCategory) it.next()));
|
||||
}
|
||||
current = 0;
|
||||
cl.show(cats,"0");
|
||||
cl.show(cats, "0");
|
||||
// wait till config is complete
|
||||
synchronized(this) {
|
||||
while(windowOpen) {
|
||||
synchronized (this) {
|
||||
while (windowOpen) {
|
||||
try {
|
||||
wait();
|
||||
} catch (InterruptedException ex) {
|
||||
@@ -303,36 +323,33 @@ public class GUIInstall extends Install {
|
||||
|
||||
public CategoryPanel(InstallCategory ic) {
|
||||
super(new GridBagLayout());
|
||||
this.ic=ic;
|
||||
this.ic = ic;
|
||||
for (Iterator it = ic.iterator(); it.hasNext();) {
|
||||
InstallOption io = (InstallOption) it.next();
|
||||
Component c1 = io.getComponent1(),
|
||||
c2 = io.getComponent2();
|
||||
Component c1 = io.getComponent1(), c2 = io.getComponent2();
|
||||
if (c1 != null) add(c1, gbcLeft);
|
||||
add(c2, gbcRight);
|
||||
}
|
||||
add (errorBox = new TextArea(), gbcBottom);
|
||||
add(errorBox = new TextArea(), gbcBottom);
|
||||
errorBox.setEditable(false);
|
||||
}
|
||||
|
||||
private InstallOption currentOption;
|
||||
|
||||
public boolean saveOptions() {
|
||||
errorBox.setText("Saving options...\n\n");
|
||||
for (Iterator it = ic.iterator(); it.hasNext();) {
|
||||
InstallOption io = (InstallOption) it.next();
|
||||
currentOption=io;
|
||||
currentOption = io;
|
||||
if (!io.setValue()) return false;
|
||||
currentOption= null;
|
||||
currentOption = null;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void showError(String s) {
|
||||
if (currentOption==null) {
|
||||
throw new RuntimeException("No option to test");
|
||||
}
|
||||
errorBox.append("While setting \""+currentOption.getQuestion()+
|
||||
"\":\n"+s+"\n\n");
|
||||
if (currentOption == null) { throw new RuntimeException("No option to test"); }
|
||||
errorBox.append("While setting \"" + currentOption.getQuestion() + "\":\n" + s + "\n\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user