Skip to content

Commit

Permalink
Set resistor style based on user's browser's language preference
Browse files Browse the repository at this point in the history
  • Loading branch information
sharpie7 committed Oct 29, 2016
1 parent 4553df0 commit 913abe2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ You can link to the full page version of the application using the link shown ab

If you want to embed the application in another page then use an iframe with the src being the full-page version.

You can add query parameters to link to the full page version to change it's startup behaviour. The following are supported:
You can add query parameters to link to change the applications startup behaviour. The following are supported:
```
.../circuitjs1.html?cct=<string> // Load the circuit from the URL (like the # in the Java version)
.../circuitjs1.html?startCircuit=<filename> // Loads the circuit named "filename" from the "Circuits" directory
.../circuitjs1.html?euroResistors=<true|false>
.../circuitjs1.html?euroResistors=<true|false> // Set to true to force "Euro" style resistors. If not specified the resistor style will be based on the user's browser's language preferences
.../circuitjs1.html?usResistors=<true|false> // Set to true to force "US" style resistors. If not specified the resistor style will be based on the user's browser's language preferences
.../circuitjs1.html?whiteBackground=<true|false>
.../circuitjs1.html?conventionalCurrent=<true|false>
```
Expand Down
47 changes: 38 additions & 9 deletions src/com/lushprojects/circuitjs1/client/CirSim.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.Window.Navigator;
import com.google.gwt.i18n.shared.DefaultDateTimeFormatInfo;


public class CirSim implements MouseDownHandler, MouseMoveHandler, MouseUpHandler,
Expand Down Expand Up @@ -319,7 +320,8 @@ public void init() {
// String useFrameStr = null;
boolean printable = false;
boolean convention = true;
boolean euro = false;
boolean euroRes = false;
boolean usRes = false;
MenuBar m;

CircuitElm.initClass(this);
Expand Down Expand Up @@ -354,7 +356,8 @@ public void init() {
// pause = Integer.parseInt(param);
startCircuit = qp.getValue("startCircuit");
startLabel = qp.getValue("startLabel");
euro = qp.getBooleanValue("euroResistors", false);
euroRes = qp.getBooleanValue("euroResistors", false);
usRes = qp.getBooleanValue("usResistors", false);
// useFrameStr = qp.getValue("useFrame");
// String x = applet.getParameter("whiteBackground");
// if (x != null && x.equalsIgnoreCase("true"))
Expand All @@ -366,12 +369,7 @@ public void init() {
convention = qp.getBooleanValue("conventionalCurrent", true);
} catch (Exception e) { }

// boolean euro = (euroResistor != null && euroResistor.equalsIgnoreCase("true"));
// useFrame = (useFrameStr == null || !useFrameStr.equalsIgnoreCase("false"));
// if (useFrame)
// main = this;
// else
// main = applet;


String os = Navigator.getPlatform();
isMac = (os.toLowerCase().contains("mac"));
Expand Down Expand Up @@ -514,7 +512,12 @@ public void init() {
}
}));
m.addItem(euroResistorCheckItem = new CheckboxMenuItem("European Resistors"));
euroResistorCheckItem.setState(euro);
if (euroRes)
euroResistorCheckItem.setState(true);
else if (usRes)
euroResistorCheckItem.setState(false);
else
euroResistorCheckItem.setState(!weAreInUS());
m.addItem(printableCheckItem = new CheckboxMenuItem("White Background",
new Command() { public void execute(){
int i;
Expand Down Expand Up @@ -4633,6 +4636,32 @@ public void updateModels() {
for (i = 0; i != elmList.size(); i++)
elmList.get(i).updateModels();
}

native void jsConsoleLog(String message) /*-{
try {
console.log(message);
} catch (e) {
}
}-*/;


native boolean weAreInUS() /*-{
try {
l=window.navigator.language ;
if (l.length > 2) {
l = l.slice(-2);
return (l == "US" || l=="CA");
} else {
return 0;
}
} catch (e) { return 0;
}
}-*/;

}





0 comments on commit 913abe2

Please sign in to comment.