1010
1111package com .CDPrintable .MusicBrainzResources ;
1212
13+ import com .CDPrintable .ConfigManager ;
14+
1315import javax .swing .*;
1416import java .awt .*;
1517import java .awt .image .BufferedImage ;
1820
1921public class MusicBrainzLabelGenerator implements Printable {
2022 private final ArrayList <MusicBrainzFinalizedRelease > finalizedReleaseList ;
21- public int LABEL_WIDTH ;
22- public int LABEL_MAX_HEIGHT ;
23+ public double labelWidth ;
24+ public double labelMaxHeight ;
2325 public int dpiX ;
2426 public int dpiY ;
2527 public int marginTop ;
2628 public int marginBottom ;
2729 public int marginLeft ;
2830 public int marginRight ;
29- private int fontSize = 10 ;
30- public double pageWidth = 8.5 ;
31- public double pageHeight = 11 ;
32-
33- public int getFontSize () {
34- return fontSize ;
35- }
36-
37- public void setFontSize (int fontSize ) {
38- this .fontSize = fontSize ;
39- }
31+ private double fontSize ;
32+ public double pageWidth ;
33+ public double pageHeight ;
34+ public String fontName ;
4035
4136 public MusicBrainzLabelGenerator () {
4237 double [] dpi = getDPI ();
4338 this .dpiX = (int ) dpi [0 ];
4439 this .dpiY = (int ) dpi [1 ];
4540
46- this .LABEL_WIDTH = 4 * dpiX ; // Example: 1 inch width
47- this .LABEL_MAX_HEIGHT = 2 * dpiY ; // Example: 1 inch height
41+ this .labelWidth = ConfigManager . getDoubleProperty ( "labelWidth" , 4 ) * dpiX ;
42+ this .labelMaxHeight = ConfigManager . getDoubleProperty ( "labelMaxHeight" , 2 ) * dpiY ;
4843
4944 finalizedReleaseList = new ArrayList <>();
5045 System .out .println ("DPI: dpiX=" + dpiX + ", dpiY=" + dpiY );
51- System .out .println ("Label dimensions: " + LABEL_WIDTH + "x" + LABEL_MAX_HEIGHT );
46+ System .out .println ("Label dimensions: " + labelWidth + "x" + labelMaxHeight );
5247
5348 double [] margins = getMargins ();
5449 this .marginTop = (int ) margins [0 ];
5550 this .marginBottom = (int ) margins [1 ];
5651 this .marginLeft = (int ) margins [2 ];
5752 this .marginRight = (int ) margins [3 ];
5853 System .out .println ("Margins: " + margins [0 ] + "x" + margins [1 ] + "x" + margins [2 ] + "x" + margins [3 ]);
59- }
6054
61- public int getLabelWidth () {
62- return LABEL_WIDTH ;
63- }
55+ this .fontSize = ConfigManager .getDoubleProperty ("fontSize" , 10 );
56+ this .pageWidth = ConfigManager .getDoubleProperty ("pageWidth" , 8.5 );
57+ this .pageHeight = ConfigManager .getDoubleProperty ("pageHeight" , 11 );
58+ this .fontName = ConfigManager .getProperty ("fontName" , "Arial" );
6459
65- public void setLabelWidth (int labelWidth ) {
66- LABEL_WIDTH = labelWidth * dpiX ;
67- }
68-
69- public int getLabelMaxHeight () {
70- return LABEL_MAX_HEIGHT ;
71- }
72-
73- public void setLabelMaxHeight (int labelMaxHeight ) {
74- LABEL_MAX_HEIGHT = labelMaxHeight * dpiY ;
7560 }
7661
7762 @ Override
@@ -80,7 +65,7 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
8065 g2d .translate (pageFormat .getImageableX (), pageFormat .getImageableY ());
8166 g2d .setColor (Color .BLACK );
8267
83- Font font = new Font ("Arial" , Font .PLAIN , fontSize );
68+ Font font = new Font (fontName , Font .PLAIN , ( int ) fontSize );
8469 g2d .setFont (font );
8570 FontMetrics fontMetrics = g2d .getFontMetrics ();
8671
@@ -98,11 +83,11 @@ public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) {
9883 for (MusicBrainzTrack track : release .getTracks ()) {
9984 String line = track .getTrackNumber () + ". " + track .getTitle () + " " ;
10085 // Split stuff up IF the line gets too long
101- if (fontMetrics .stringWidth (lineBuilder + line ) > LABEL_WIDTH ) {
86+ if (fontMetrics .stringWidth (lineBuilder + line ) > labelWidth ) {
10287 releaseLines .add (lineBuilder .toString ());
10388 lineBuilder .delete (0 , lineBuilder .length ());
10489 }
105- if (releaseLines .size () * fontMetrics .getHeight () >= LABEL_MAX_HEIGHT ) {break ;}
90+ if (releaseLines .size () * fontMetrics .getHeight () >= labelMaxHeight ) {break ;}
10691 lineBuilder .append (line );
10792 }
10893 if (!lineBuilder .isEmpty ()) {
@@ -259,4 +244,51 @@ public void displayPagesAsImages() {
259244 }
260245 }
261246
247+ public double getLabelWidth () {
248+ return labelWidth ;
249+ }
250+
251+ public void setLabelWidth (double labelWidth ) {
252+ this .labelWidth = labelWidth ;
253+ }
254+
255+ public double getLabelMaxHeight () {
256+ return labelMaxHeight ;
257+ }
258+
259+ public void setLabelMaxHeight (double labelMaxHeight ) {
260+ this .labelMaxHeight = labelMaxHeight ;
261+ }
262+
263+ public double getFontSize () {
264+ return fontSize ;
265+ }
266+
267+ public void setFontSize (double fontSize ) {
268+ this .fontSize = fontSize ;
269+ }
270+
271+ public double getPageWidth () {
272+ return pageWidth ;
273+ }
274+
275+ public void setPageWidth (double pageWidth ) {
276+ this .pageWidth = pageWidth ;
277+ }
278+
279+ public double getPageHeight () {
280+ return pageHeight ;
281+ }
282+
283+ public void setPageHeight (double pageHeight ) {
284+ this .pageHeight = pageHeight ;
285+ }
286+
287+ public String getFontName () {
288+ return fontName ;
289+ }
290+
291+ public void setFontName (String fontName ) {
292+ this .fontName = fontName ;
293+ }
262294}
0 commit comments