Klasse Zeichenfenster ausgelagert

This commit is contained in:
ngb
2022-07-25 17:35:46 +02:00
parent 4f958cd57c
commit 55014c8eec

View File

@@ -13,7 +13,6 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.logging.Level;
public class Zeichenfenster extends JFrame { public class Zeichenfenster extends JFrame {
@@ -52,7 +51,7 @@ public class Zeichenfenster extends JFrame {
*/ */
private GraphicsDevice displayDevice; private GraphicsDevice displayDevice;
private int width, height; private int canvasWidth, canvasHeight;
/** /**
* Höhe und Breite der Zeichenmaschine, bevor sie mit * Höhe und Breite der Zeichenmaschine, bevor sie mit
@@ -114,15 +113,14 @@ public class Zeichenfenster extends JFrame {
this.setIconImages(icons); this.setIconImages(icons);
} }
} catch( IllegalArgumentException | IOException e ) { } catch( IllegalArgumentException | IOException e ) {
LOG.warn(e, "Could not load image icons: %s", e.getMessage()); LOG.warn("Could not load image icons: %s", e.getMessage());
} catch( SecurityException | UnsupportedOperationException macex ) { } catch( SecurityException | UnsupportedOperationException macex ) {
// Dock Icon in macOS konnte nicht gesetzt werden :( // Dock Icon in macOS konnte nicht gesetzt werden :(
LOG.warn(macex, "Could not set dock icon: %s", macex.getMessage()); LOG.warn("Could not set dock icon: %s", macex.getMessage());
} }
java.awt.Rectangle bounds = getScreenBounds(); this.canvasWidth = width;
this.width = bounds.width; this.canvasHeight = height;
this.height = bounds.height;
// Fenster zusammenbauen, auf dem Bildschirm zentrieren ... // Fenster zusammenbauen, auf dem Bildschirm zentrieren ...
this.pack(); this.pack();
@@ -134,8 +132,8 @@ public class Zeichenfenster extends JFrame {
this.canvas = canvas; this.canvas = canvas;
this.add(canvas, 0); this.add(canvas, 0);
this.width = canvas.getWidth(); this.canvasWidth = canvas.getWidth();
this.height = canvas.getHeight(); this.canvasHeight = canvas.getHeight();
this.pack(); this.pack();
} }
@@ -145,7 +143,7 @@ public class Zeichenfenster extends JFrame {
public java.awt.Rectangle getCanvasBounds() { public java.awt.Rectangle getCanvasBounds() {
java.awt.Insets insets = getInsets(); java.awt.Insets insets = getInsets();
return new java.awt.Rectangle(insets.top, insets.left, width, height); return new java.awt.Rectangle(insets.top, insets.left, canvasWidth, canvasHeight);
} }
/** /**
@@ -153,9 +151,10 @@ public class Zeichenfenster extends JFrame {
*/ */
public final void centerFrame() { public final void centerFrame() {
java.awt.Rectangle bounds = getScreenBounds(); java.awt.Rectangle bounds = getScreenBounds();
java.awt.Insets insets = getInsets();
this.setLocation( this.setLocation(
(int) (bounds.x + (bounds.width - this.getWidth()) / 2.0), (int) (bounds.x + (bounds.width - canvasWidth) / 2.0 - insets.left),
(int) (bounds.y + (bounds.height - this.getHeight()) / 2.0) (int) (bounds.y + (bounds.height - canvasHeight) / 2.0- insets.top)
); );
} }
@@ -169,18 +168,18 @@ public class Zeichenfenster extends JFrame {
initialHeight = Math.min(newHeight, bounds.height - insets.top - insets.bottom); initialHeight = Math.min(newHeight, bounds.height - insets.top - insets.bottom);
setFullscreen(false); setFullscreen(false);
} else { } else {
width = Math.min(newWidth, bounds.width - insets.left - insets.right); canvasWidth = Math.min(newWidth, bounds.width - insets.left - insets.right);
height = Math.min(newHeight, bounds.height - insets.top - insets.bottom); canvasHeight = Math.min(newHeight, bounds.height - insets.top - insets.bottom);
if( canvas != null ) { if( canvas != null ) {
canvas.setSize(width, height); canvas.setSize(canvasWidth, canvasHeight);
} }
// this.pack(); /*super.setSize(
super.setSize(
width + insets.left + insets.right, width + insets.left + insets.right,
height + insets.top + insets.bottom height + insets.top + insets.bottom
); );*/
super.pack();
} }
} }