Skip to content

Commit

Permalink
add application support, useful for writing package apps supported th…
Browse files Browse the repository at this point in the history
…rough BEAST appstore
  • Loading branch information
rbouckaert committed Mar 28, 2016
1 parent 7e64724 commit d8b52bb
Show file tree
Hide file tree
Showing 13 changed files with 694 additions and 2 deletions.
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<property name="srcBeast2" location="${beast2path}/src" />
<property name="beast2classpath" location="${beast2path}/build" />
<property name="Add_on_dir" value="${release_dir}/add-on" />
<property name="version" value="1.4.0" />
<property name="version" value="1.5.0" />

<import file="${beast2path}/build.xml" />

Expand Down
84 changes: 84 additions & 0 deletions src/beast/app/beauti/FileInputEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package beast.app.beauti;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;

import beast.app.draw.InputEditor;
import beast.app.util.Utils;
import beast.core.BEASTInterface;
import beast.core.Input;


/** for opening files for reading
* use OutFile when you need a file for writing
*/
public class FileInputEditor extends InputEditor.Base {

private static final long serialVersionUID = 1L;

@Override
public Class<?> type() {
return File.class;
}

public FileInputEditor(BeautiDoc doc) {
super(doc);
}

@Override
public void init(Input<?> input, BEASTInterface plugin, int itemNr, ExpandOption bExpandOption, boolean bAddButtons) {
super.init(input, plugin, itemNr, bExpandOption, bAddButtons);
if (input.get() == null) {
m_entry.setText("[[none]]");
} else {
m_entry.setText(((File) m_input.get()).getName());
}

JButton button = new JButton("browse");
button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
File defaultFile;
if (m_input.get() != null && ((File) m_input.get()).exists()) {
defaultFile = (File) m_input.get();
} else {
defaultFile = new File(Beauti.g_sDir);
}
File file = Utils.getLoadFile(m_input.getTipText(), defaultFile, "All files", "");
try {
m_entry.setText(file.getName());
m_input.setValue(file, m_beastObject);
String path = file.getPath();
Beauti.g_sDir = path;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
add(button);
}

@Override
protected void setValue(Object o) {
String file = o.toString();
if (file.equals("")) {
return;
}
String fileSep = System.getProperty("file.separator");
String origFile = ((File) m_input.get()).getAbsolutePath();
if (origFile.indexOf(fileSep) >= 0 && file.indexOf(fileSep) < 0) {
if (origFile.contains(origFile)) {
file = origFile.substring(0, origFile.lastIndexOf(fileSep) + 1) + file;
}
}
m_input.setValue(file, m_beastObject);
}


}
78 changes: 78 additions & 0 deletions src/beast/app/beauti/LogFileInputEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package beast.app.beauti;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;

import beast.app.draw.InputEditor;
import beast.app.util.LogFile;
import beast.app.util.Utils;
import beast.core.BEASTInterface;
import beast.core.Input;

public class LogFileInputEditor extends InputEditor.Base {

private static final long serialVersionUID = 1L;

@Override
public Class<?> type() {
return LogFile.class;
}

public LogFileInputEditor(BeautiDoc doc) {
super(doc);
}

@Override
public void init(Input<?> input, BEASTInterface plugin, int itemNr, ExpandOption bExpandOption, boolean bAddButtons) {
super.init(input, plugin, itemNr, bExpandOption, bAddButtons);
m_entry.setText(((File) m_input.get()).getName());

JButton button = new JButton("browse");
button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
File defaultFile;
if (((File) m_input.get()).exists()) {
defaultFile = (File) m_input.get();
} else {
defaultFile = new File(Beauti.g_sDir);
}
File file = Utils.getLoadFile(m_input.getTipText(), defaultFile, "trace files", "log");
if (file != null)
file = new LogFile(file.getPath());
try {
m_entry.setText(file.getName());
m_input.setValue(file, m_beastObject);
String path = file.getPath();
Beauti.g_sDir = path;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
add(button);
}

@Override
protected void setValue(Object o) {
String file = o.toString();
if (file.equals("")) {
return;
}
String fileSep = System.getProperty("file.separator");
String origFile = ((File) m_input.get()).getAbsolutePath();
if (origFile.indexOf(fileSep) >= 0 && file.indexOf(fileSep) < 0) {
if (origFile.contains(origFile)) {
file = origFile.substring(0, origFile.lastIndexOf(fileSep) + 1) + file;
}
}
m_input.setValue(file, m_beastObject);
}


}
82 changes: 82 additions & 0 deletions src/beast/app/beauti/OutFileInputEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package beast.app.beauti;



import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;

import beast.app.util.OutFile;
import beast.app.util.Utils;
import beast.core.BEASTInterface;
import beast.core.Input;
import beast.app.draw.InputEditor;

public class OutFileInputEditor extends InputEditor.Base {

private static final long serialVersionUID = 1L;

@Override
public Class<?> type() {
return OutFile.class;
}

public OutFileInputEditor(BeautiDoc doc) {
super(doc);
}

@Override
public void init(Input<?> input, BEASTInterface plugin, int itemNr, ExpandOption bExpandOption, boolean bAddButtons) {
super.init(input, plugin, itemNr, bExpandOption, bAddButtons);
m_entry.setText(((File) m_input.get()).getName());

JButton button = new JButton("browse");
button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
File defaultFile;
if (((File) m_input.get()).exists()) {
defaultFile = (File) m_input.get();
} else {
defaultFile = new File(Beauti.g_sDir);
}
File file = Utils.getSaveFile(m_input.getTipText(), defaultFile, "All files", "");
if (file != null)
file = new OutFile(file.getPath());
try {
m_entry.setText(file.getName());
m_input.setValue(file, m_beastObject);
String path = file.getPath();
Beauti.g_sDir = path;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
add(button);
}


@Override
protected void setValue(Object o) {
String file = o.toString();
if (file.equals("")) {
return;
}
String fileSep = System.getProperty("file.separator");
String origFile = ((File) m_input.get()).getAbsolutePath();
if (origFile.indexOf(fileSep) >= 0 && file.indexOf(fileSep) < 0) {
if (origFile.contains(origFile)) {
file = origFile.substring(0, origFile.lastIndexOf(fileSep) + 1) + file;
}
}
m_input.setValue(file, m_beastObject);
}



}
79 changes: 79 additions & 0 deletions src/beast/app/beauti/TreeFileInputEditor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package beast.app.beauti;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;

import javax.swing.JButton;

import beast.app.draw.InputEditor;
import beast.app.util.XMLFile;
import beast.app.util.Utils;
import beast.core.BEASTInterface;
import beast.core.Input;

public class TreeFileInputEditor extends InputEditor.Base {

private static final long serialVersionUID = 1L;

@Override
public Class<?> type() {
return XMLFile.class;
}

public TreeFileInputEditor(BeautiDoc doc) {
super(doc);
}

@Override
public void init(Input<?> input, BEASTInterface plugin, int itemNr, ExpandOption bExpandOption, boolean bAddButtons) {
super.init(input, plugin, itemNr, bExpandOption, bAddButtons);
m_entry.setText(((File) m_input.get()).getName());

JButton button = new JButton("browse");
button.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent arg0) {
File defaultFile;
if (((File) m_input.get()).exists()) {
defaultFile = (File) m_input.get();
} else {
defaultFile = new File(Beauti.g_sDir);
}
File file = Utils.getLoadFile(m_input.getTipText(), defaultFile, "tree files", "trees");
if (file != null) {
file = new XMLFile(file.getPath());
}
try {
m_entry.setText(file.getName());
m_input.setValue(file, m_beastObject);
String path = file.getPath();
Beauti.g_sDir = path;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
add(button);
}

@Override
protected void setValue(Object o) {
String file = o.toString();
if (file.equals("")) {
return;
}
String fileSep = System.getProperty("file.separator");
String origFile = ((File) m_input.get()).getAbsolutePath();
if (origFile.indexOf(fileSep) >= 0 && file.indexOf(fileSep) < 0) {
if (origFile.contains(origFile)) {
file = origFile.substring(0, origFile.lastIndexOf(fileSep) + 1) + file;
}
}
m_input.setValue(file, m_beastObject);
}


}
Loading

0 comments on commit d8b52bb

Please sign in to comment.