Skip to content

Commit

Permalink
First improvements on window position
Browse files Browse the repository at this point in the history
  • Loading branch information
ValentinHerrmann committed Feb 26, 2025
1 parent a57fcb8 commit 27474fb
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 37 deletions.
24 changes: 24 additions & 0 deletions BlueJCode/Blockly/BlocklyHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,35 @@ public void openBlockly(double x, double y)
}
}

private void moveBlocklyRight()
{
try
{
// Set JFrame to fill exactly the right half of the screen
//GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
//GraphicsDevice gd = ge.getDefaultScreenDevice();
Rectangle screenBounds = frame.getGraphicsConfiguration().getBounds();
int screenWidth = screenBounds.width;
int screenHeight = screenBounds.height;
Logging.log("Screen size: " + frame.getBounds().toString());

frame.setMaximumSize(new Dimension(screenWidth / 2, screenHeight));
frame.setBounds(screenWidth / 2, 0, screenWidth / 2, screenHeight);
Logging.log("New Blockly-Frame size: " + frame.getBounds().toString());
frame.setVisible(true);
}
catch (Exception ex)
{
Logging.log(ex.toString());
}
}

public void openBlockly()
{
try
{
openBlockly(-1,-1);
moveBlocklyRight();
}
catch(Exception ex)
{
Expand Down
50 changes: 25 additions & 25 deletions BlueJCode/Blockly/RestAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ class RestAPI
try
{
blockly = bHandler;
Logging.log(">>> RestAPI.RestAPI()");
Logging.logRest(">>> RestAPI.RestAPI()");
server = HttpServer.create(new InetSocketAddress(8081), 0);
}
catch(Exception e)
{
Logging.log(e.toString());
Logging.logRest(e.toString());
}
init();
Logging.log("<<< RestAPI.RestAPI()");
Logging.logRest("<<< RestAPI.RestAPI()");
}

private void init()
Expand Down Expand Up @@ -61,7 +61,7 @@ else if("POST".equals(exchange.getRequestMethod()))
}
catch(Exception e)
{
Logging.log(e.toString());
Logging.logRest(e.toString());
}

}
Expand Down Expand Up @@ -89,7 +89,7 @@ private String bodyToString(InputStream rawBody)
}
catch(Exception e)
{
Logging.log(e.getMessage());
Logging.logRest(e.getMessage());
}
return ret;
}
Expand All @@ -101,11 +101,11 @@ private void getAPIRights()
String cmd = "netsh http add urlacl url=http://localhost:8081/api/ user=Jeder";
Process process = Runtime.getRuntime().exec(String.format("cmd.exe /c " + cmd, "."));
process.waitFor();
Logging.log("Access granted");
Logging.logRest("Access granted");
}
catch(Exception e)
{
Logging.log("Access failed");
Logging.logRest("Access failed");
}
}

Expand All @@ -123,7 +123,7 @@ private HttpExchange cors(HttpExchange exchange)
}
catch(Exception e)
{
Logging.log(e.toString());
Logging.logRest(e.toString());
return null;
}
}
Expand All @@ -132,7 +132,7 @@ private void handleGet(HttpExchange exchange)
{
try
{
Logging.log(">>> GET");
Logging.logRest(">>> GET");


String responseText = blockly.getCurrentClassPrefix()
Expand All @@ -143,7 +143,7 @@ private void handleGet(HttpExchange exchange)

if(exchange==null)
{
Logging.log("Exchange is null. CORS failed.");
Logging.logRest("Exchange is null. CORS failed.");
return;
}

Expand All @@ -154,13 +154,13 @@ private void handleGet(HttpExchange exchange)
output.flush();


Logging.log(responseText);
Logging.logRest(responseText);

Logging.log("<<< GET Response: "+exchange.getResponseCode());
Logging.logRest("<<< GET Response: "+exchange.getResponseCode());
}
catch(Exception e)
{
Logging.log(e.toString());
Logging.logRest(e.toString());
}
}

Expand All @@ -172,12 +172,12 @@ private void handlePost(HttpExchange exchange)

String contentType = exchange.getRequestHeaders().getFirst("Content-type");// exchange.get

Logging.log(">>> POST: "+contentType);
Logging.logRest(">>> POST: "+contentType);

String data = bodyToString(exchange.getRequestBody());

Logging.log(contentType);
Logging.log("'"+data+"'");
Logging.logRest(contentType);
Logging.logRest("'"+data+"'");



Expand All @@ -196,12 +196,12 @@ private void handlePost(HttpExchange exchange)
output.write(responseText.getBytes());
output.flush();

Logging.log("<<< POST Response: " + code);
Logging.logRest("<<< POST Response: " + code);

}
catch(Exception e)
{
Logging.log(e.toString());
Logging.logRest(e.toString());
}
}

Expand All @@ -211,15 +211,15 @@ private int handlePost_Xml(String code)
{
try
{
Logging.log(">>> RestAPI.handlePost_Xml(...)");
Logging.logRest(">>> RestAPI.handlePost_Xml(...)");
blockly.incomingXmlCode(code);
Logging.log("<<< RestAPI.handlePost_Xml(...): 200");
Logging.logRest("<<< RestAPI.handlePost_Xml(...): 200");
return 200;
}
catch(Exception e)
{
Logging.log(e.toString());
Logging.log("<<< RestAPI.handlePost_Xml(...): 400");
Logging.logRest(e.toString());
Logging.logRest("<<< RestAPI.handlePost_Xml(...): 400");
return 400;
}
}
Expand All @@ -228,13 +228,13 @@ void terminate()
{
try
{
Logging.log(">>> RestAPI.terminate()");
Logging.logRest(">>> RestAPI.terminate()");
server.stop(0);
Logging.log("<<< RestAPI.terminate()");
Logging.logRest("<<< RestAPI.terminate()");
}
catch(Exception e)
{
Logging.log(e.toString());
Logging.logRest(e.toString());
}
}

Expand Down
6 changes: 1 addition & 5 deletions BlueJCode/CodeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public void open()
{
activeInstance = this;
BlocklyHandler.Instance().openBlockly();
editor.setVisible(true);
}
catch (Exception e)
{
Expand Down Expand Up @@ -136,12 +137,7 @@ public void writeJavaCodeToFile(String code)
try
{
editor.loadFile();
Logging.log("File loaded");
editor.getBClass().compile(false);
Logging.log("Compiled");

//Logging.log("Window: "+editor.getBClass().getPackage().getWindow().getTitle());
//editor.getBClass().getPackage().getWindow().requestFocus();
}
catch (ProjectNotOpenException e)
{
Expand Down
29 changes: 23 additions & 6 deletions BlueJCode/Logging.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

public class Logging {
private File file = null;
private File restFile = null;
private static Logging instance = null;
private final static List<String> preInstantiationLogs = new ArrayList<String>();

Expand All @@ -34,17 +35,23 @@ private Logging(String path)
System.out.println("Opening log-file at:\t" + dir + "\\BBE.log");
(new File(dir)).mkdirs();
this.file = new File(dir + "/BBE.log");
this.restFile = new File(dir + "/restCommunication.log");

try {
if (this.file.createNewFile()) {
System.out.println("File created successfully");
System.out.println("BBE File created successfully");
} else {
System.out.println("File opened successfully");
System.out.println("BBE File opened successfully");
}
if (this.restFile.createNewFile()) {
System.out.println("Rest File created successfully");
} else {
System.out.println("Rest File opened successfully");
}
instance = this;
log("---------- Logging instantiated for BBE Version " + Config.Version() + " ----------");

writeToFile(String.join(System.lineSeparator(), preInstantiationLogs));
writeToFile(String.join(System.lineSeparator(), preInstantiationLogs), this.file);

} catch (IOException var3) {
System.out.println("FAILED");
Expand All @@ -66,7 +73,17 @@ public static void log(StackTraceElement[] e)
}
}

public static void logRest(String text)
{
log(text, Instance().restFile);
}

public static void log(String text)
{
log(text, Instance().file);
}

private static void log(String text, File f)
{
String dateTime = LocalDateTime.now().toString();
String thread = Thread.currentThread().getName();
Expand All @@ -79,18 +96,18 @@ public static void log(String text)
System.out.println("Logging not yet instantiated, logs are stored.");
preInstantiationLogs.add(log);
} else {
Instance().writeToFile(log);
Instance().writeToFile(log, f);
}
}
}

private void writeToFile(String log)
private void writeToFile(String log, File f)
{
if(Config.LogActive())
{
try
{
BufferedWriter br = new BufferedWriter(new FileWriter(Instance().file, true));
BufferedWriter br = new BufferedWriter(new FileWriter(f, true));
br.write(log);
br.close();
}
Expand Down
44 changes: 43 additions & 1 deletion BlueJCode/MenuBuilder.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package BlueJCode;
import bluej.extensions2.*;
import javafx.event.*;
import javafx.geometry.Rectangle2D;
import javafx.scene.control.*;
import javafx.stage.Screen;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.stage.Window;
Expand Down Expand Up @@ -62,11 +64,12 @@ public EventHandler openBlocklyEvent()


CodeHandler.setActiveInstance(curClass);
closeAllWindowsExceptMain();
//closeAllWindowsExceptMain();
//Blocklyfenster
try
{
CodeHandler.getCodeHandler(curClass).open();
moveBlueJWindowsToLeft();
}
catch(Exception ex)
{
Expand All @@ -76,6 +79,45 @@ public EventHandler openBlocklyEvent()
};
}

public void moveBlueJWindowsToLeft() {

try
{
Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
double screenWidth = screenBounds.getWidth();
double screenHeight = screenBounds.getHeight();

//BlueJfenster
for(Window bjwindow : Stage.getWindows())
{
if(bjwindow instanceof Stage)
{
try
{
Stage stage = (Stage)bjwindow;

// Set the stage to fill the left half of the screen
stage.setX(0);
stage.setY(0);
stage.setWidth(screenWidth / 2);
stage.setHeight(screenHeight);
stage.setMaximized(false);
}
catch(Exception e)
{
Logging.log(e.toString());
Logging.log(e.getStackTrace());
}
}
}
}
catch (Exception e)
{
Logging.log(e.toString());
Logging.log(e.getStackTrace());
}
}

public void notifyPostClassMenu(BClass bc, MenuItem mi)
{
System.out.println("Post on Class menu");
Expand Down

0 comments on commit 27474fb

Please sign in to comment.