[prev in list] [next in list] [prev in thread] [next in thread] 

List:       jedit-cvs
Subject:    [ jEdit-commits ] SF.net SVN: jedit:[24506] jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog. java
From:       kerik-sf () users ! sourceforge ! net
Date:       2016-08-18 11:05:57
Message-ID: E1baL96-00035C-Sh () sfs-ml-2 ! v29 ! ch3 ! sourceforge ! com
[Download RAW message or body]

Revision: 24506
          http://sourceforge.net/p/jedit/svn/24506
Author:   kerik-sf
Date:     2016-08-18 11:05:56 +0000 (Thu, 18 Aug 2016)
Log Message:
-----------
better printer page setup dialog margin handling for mm

fix NFE, ClassCastException, due to forced integer NumericTextField
in the mm case.

Modified Paths:
--------------
    jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java

Modified: jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java
===================================================================
--- jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java	2016-08-17 21:50:14 UTC \
                (rev 24505)
+++ jEdit/trunk/org/gjt/sp/jedit/print/PrinterDialog.java	2016-08-18 11:05:56 UTC \
(rev 24506) @@ -51,6 +51,7 @@
 
 // Technical guide on the Java printing system:
 // https://docs.oracle.com/javase/7/docs/technotes/guides/jps/spec/JPSTOC.fm.html
+@SuppressWarnings("serial")
 public class PrinterDialog extends JDialog implements ListSelectionListener
 {
 
@@ -85,7 +86,7 @@
     private boolean reversePrinting = false;
 
 
-    public PrinterDialog( View owner, PrintRequestAttributeSet attributes, boolean \
pageSetupOnly ) +    public PrinterDialog( View owner, PrintRequestAttributeSet \
attributes, final boolean pageSetupOnly )  {
         super( owner, Dialog.ModalityType.APPLICATION_MODAL );
         try
@@ -913,25 +914,28 @@
             paperPanel.add( orientation );
             
             int units = getUnits();
+            boolean unitIsMM = units == MediaPrintableArea.MM;
             Margins margins = (Margins)attributes.get(Margins.class);
-            float[] marginValues = margins == null ? new float[]{1.0f, 1.0f, 1.0f, \
                1.0f} : margins.getMargins(units);
-            float topMargin = marginValues[0];
-            float leftMargin = marginValues[1];
-            float rightMargin = marginValues[2];
-            float bottomMargin = marginValues[3];
+            // FIXME: use the value from the printer, otherwise we put invalid \
values by default, +            // depending on its print area.
+            int defaultMargin = unitIsMM ? 15 : 1;
+            float[] marginValues = margins == null ? new float[]{defaultMargin, \
defaultMargin, defaultMargin, defaultMargin} : margins.getMargins(units);  
             JPanel marginPanel = new JPanel( new VariableGridLayout( \
VariableGridLayout.FIXED_NUM_COLUMNS, 2, 6, 6 ) );  marginPanel.setBorder( \
BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder( \
BorderFactory.createEtchedBorder(), jEdit.getProperty( "print.dialog.Margins", \
                "Margins" ) ), BorderFactory.createEmptyBorder( 11, 11, 11, 11 ) ) );
-            topMarginField = new NumericTextField( Float.toString( topMargin ), \
                true, units == MediaPrintableArea.MM );
-            topMarginField.addFocusListener( PageSetupPanel.this );
-            leftMarginField = new NumericTextField( Float.toString( leftMargin ), \
                true, units == MediaPrintableArea.MM );
-            leftMarginField.addFocusListener( PageSetupPanel.this );
-            rightMarginField = new NumericTextField( Float.toString( rightMargin ), \
                true, units == MediaPrintableArea.MM );
-            rightMarginField.addFocusListener( PageSetupPanel.this );
-            bottomMarginField = new NumericTextField( Float.toString( bottomMargin \
                ), true, units == MediaPrintableArea.MM );
-            bottomMarginField.addFocusListener( PageSetupPanel.this );
 
-            String unitsLabel = units == MediaPrintableArea.MM ? " (mm)" : " (in)";
+            NumericTextField[] marginFields = new NumericTextField[4];
+            for(int i=0;i<4;i++){
+                String marginS = unitIsMM? Integer.toString( (int)marginValues[i] ) \
: Float.toString( marginValues[i] ); +                marginFields[i] = new \
NumericTextField(marginS, true, unitIsMM); +                \
marginFields[i].addFocusListener( PageSetupPanel.this ); +            }
+            topMarginField = marginFields[0];
+            leftMarginField = marginFields[1];
+            rightMarginField = marginFields[2];
+            bottomMarginField = marginFields[3];
+
+            String unitsLabel = unitIsMM ? " (mm)" : " (in)";
             marginPanel.add( new JLabel( jEdit.getProperty( "print.dialog.Top", \
"Top" ) + unitsLabel ) );  marginPanel.add( topMarginField );
             marginPanel.add( new JLabel( jEdit.getProperty( "print.dialog.Left", \
"Left" ) + unitsLabel ) ); @@ -1074,10 +1078,10 @@
                 as.add( ( OrientationRequested )orientation.getSelectedItem() );
             }
 
-            float topMargin = ((Float)topMarginField.getValue()).floatValue();
-            float leftMargin = ((Float)leftMarginField.getValue()).floatValue();
-            float rightMargin = ((Float)rightMarginField.getValue()).floatValue();
-            float bottomMargin = ((Float)bottomMarginField.getValue()).floatValue();
+            float topMargin = topMarginField.getValue().floatValue();
+            float leftMargin = leftMarginField.getValue().floatValue();
+            float rightMargin = rightMarginField.getValue().floatValue();
+            float bottomMargin = bottomMarginField.getValue().floatValue();
             Margins margins = new Margins(topMargin, leftMargin, rightMargin, \
bottomMargin);  as.add(margins);
 
@@ -1146,10 +1150,10 @@
             float paperHeight = mediaSize.getY(units);
             
             // get the user desired margins
-            float topMargin = ((Float)topMarginField.getValue()).floatValue();
-            float leftMargin = ((Float)leftMarginField.getValue()).floatValue();
-            float rightMargin = ((Float)rightMarginField.getValue()).floatValue();
-            float bottomMargin = ((Float)bottomMarginField.getValue()).floatValue();
+            float topMargin = topMarginField.getValue().floatValue();
+            float leftMargin = leftMarginField.getValue().floatValue();
+            float rightMargin = rightMarginField.getValue().floatValue();
+            float bottomMargin = bottomMarginField.getValue().floatValue();
             
             // get the selected orientation and adjust the margins and width/height
             OrientationRequested orientationRequested = \
(OrientationRequested)orientation.getSelectedItem();

This was sent by the SourceForge.net collaborative development platform, the world's \
largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
jEdit-CVS mailing list
jEdit-CVS@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jedit-cvs


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic