Skip to content
Snippets Groups Projects

dev_prefereences to master

313 files
+ 19948
705
Compare changes
  • Side-by-side
  • Inline

Files

@@ -11,22 +11,27 @@ import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.Set;
import processing.app.Editor;
import processing.app.PreferencesData;
import com.ardublock.ui.listener.OpenblocksFrameListener;
import edu.mit.blocks.controller.WorkspaceController;
import edu.mit.blocks.renderable.RenderableBlock;
import edu.mit.blocks.workspace.Workspace;
public class Context
{
public final static String LANG_DTD_PATH = "/com/ardublock/block/lang_def.dtd";
public final static String ARDUBLOCK_LANG_PATH = "/com/ardublock/block/ardublock.xml";
public final static String ARDUBLOCK_LANG_RESOURCE_BUNDLE = "com/ardublock/block/ardublock";
public final static String DEFAULT_ARDUBLOCK_PROGRAM_PATH = "/com/ardublock/defaultProgram.abp";
public final static String DEFAULT_ARDUBLOCK_PREFRENCES_PATH = "/com/ardublock/defaultArduBlockPreferences.txt";
public final static String ARDUINO_VERSION_UNKNOWN = "unknown";
public final boolean isNeedAutoFormat = true;
@@ -44,7 +49,6 @@ public class Context
//TODO change AppName? by letsgoING
final public static String APP_NAME = "ArduBlock";
//TODO: ADD saveDefaultArdublockProgram()
private Editor editor;
@@ -81,6 +85,11 @@ public class Context
private Context()
{
//set default values to preferences.txt
if(!PreferencesData.has("ardublock")){
setDefaultPreferences();
}
workspaceController = new WorkspaceController();
resetWorkspace();
workspace = workspaceController.getWorkspace();
@@ -112,7 +121,19 @@ public class Context
}
workspaceController.resetWorkspace();
workspaceController.resetLanguage();
workspaceController.setLangResourceBundle(ResourceBundle.getBundle(ARDUBLOCK_LANG_RESOURCE_BUNDLE));//"com/ardublock/block/ardublock"));
if(PreferencesData.getBoolean("ardublock.cstyle")) {
if(Locale.getDefault().equals(Locale.GERMANY)) {
workspaceController.setLangResourceBundle(ResourceBundle.getBundle(ARDUBLOCK_LANG_RESOURCE_BUNDLE, Locale.GERMAN));
} else if(Locale.getDefault().equals(Locale.ENGLISH)) {
workspaceController.setLangResourceBundle(ResourceBundle.getBundle(ARDUBLOCK_LANG_RESOURCE_BUNDLE, Locale.UK));
} else {
workspaceController.setLangResourceBundle(ResourceBundle.getBundle(ARDUBLOCK_LANG_RESOURCE_BUNDLE));
}
} else {
workspaceController.setLangResourceBundle(ResourceBundle.getBundle(ARDUBLOCK_LANG_RESOURCE_BUNDLE));
}
workspaceController.setStyleList(list);
workspaceController.setLangDefDtd(this.getClass().getResourceAsStream(LANG_DTD_PATH));
workspaceController.setLangDefStream(this.getClass().getResourceAsStream(ARDUBLOCK_LANG_PATH));
@@ -125,21 +146,26 @@ public class Context
}
private void loadDefaultArdublockProgram()
{
{
workspaceController.resetWorkspace();
String loadPath = "";
try {
//TODO: set defaultFileName in ardublock.properties
loadPath = new File(URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8")).getParentFile().getPath()+ File.separator +"defaultProgram.abp";
} catch (UnsupportedEncodingException e2) {
} catch (Exception e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
//e2.printStackTrace();
System.out.println("No default programm.");
}
try {
workspaceController.loadProjectFromPath(loadPath);
} catch (IOException e1) {
if(PreferencesData.get("ardublock.workspace.mode").contains("custom") || PreferencesData.get("ardublock.workspace.mode").contains("page") || PreferencesData.get("ardublock.workspace.mode").contains("default") ) {
workspaceController.loadProjectFromPath(loadPath, PreferencesData.get("ardublock.workspace.mode"));
}else {
workspaceController.loadProjectFromPath(loadPath, "default");
}
} catch (Exception e1) {
try {
InputStream is = getClass().getResourceAsStream(DEFAULT_ARDUBLOCK_PROGRAM_PATH);
InputStreamReader isr = new InputStreamReader(is);
@@ -154,16 +180,37 @@ public class Context
br.close();
isr.close();
is.close();
workspaceController.loadProject(defaultFileString, null , "default");
} catch (IOException e) {
try {
if(PreferencesData.get("ardublock.workspace.mode").contains("custom") || PreferencesData.get("ardublock.workspace.mode").contains("page") || PreferencesData.get("ardublock.workspace.mode").contains("default") ) {
workspaceController.loadProject(defaultFileString, null , PreferencesData.get("ardublock.workspace.mode"));
} else {
workspaceController.loadProject(defaultFileString, null , "default");
}
} catch (Exception e) {
workspaceController.loadProject(defaultFileString, null , "default");
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
private void setDefaultPreferences() {//letsgoING
PreferencesData.setBoolean("ardublock", true);
PreferencesData.setBoolean("ardublock.cstyle", false);
PreferencesData.setBoolean("ardublock.autosave", true);
//PreferencesData.set("ardublock.ui.language", "DE"); //TODO: implement
PreferencesData.set("ardublock.workspace.mode", "default"); //"default" / "custom" / "page"
PreferencesData.setInteger("ardublock.workspace.zoom", 10); // float values between
//PreferencesData.set("ardublock.workspace.code", "simple"); //TODO: implement
}
//determine OS
private OsType determineOsType()
{
@@ -187,8 +234,20 @@ public class Context
public File getArduinoFile(String name)
{
String path = System.getProperty("user.dir");
//String path = System.getProperty("user.dir");
String path = null;
try {
path = new File(URLDecoder.decode(getClass().getProtectionDomain().getCodeSource().getLocation().getFile(), "UTF-8")).getParentFile().getPath();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
path = path + File.separatorChar+".."+ File.separatorChar+".."+ File.separatorChar+".."+ File.separatorChar; //from tools/ArduBlockTool/tool/ to Arduino-root
//TODO: check on MAC and WIN
/*
if (osType.equals(OsType.MAC))
{
String javaroot = System.getProperty("javaroot");
@@ -196,7 +255,7 @@ public class Context
{
path = javaroot;
}
}
}*/
File workingDir = new File(path);
return new File(workingDir, name);
}
@@ -235,6 +294,7 @@ public class Context
{
for (RenderableBlock rb : highlightBlockSet)
{
rb.getBlock().setBad(false); //reset bad-state after error - added by letsgoING
rb.updateInSearchResults(false);
}
highlightBlockSet.clear();
Loading