Ignore:
Timestamp:
2016-11-16T00:46:26+01:00 (8 years ago)
Author:
donvip
Message:

checkstyle

Location:
applications/editors/josm/plugins/print
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/print/.project

    r32167 r33062  
    1616                        </arguments>
    1717                </buildCommand>
     18                <buildCommand>
     19                        <name>net.sf.eclipsecs.core.CheckstyleBuilder</name>
     20                        <arguments>
     21                        </arguments>
     22                </buildCommand>
    1823        </buildSpec>
    1924        <natures>
    2025                <nature>org.eclipse.jdt.core.javanature</nature>
     26                <nature>net.sf.eclipsecs.core.CheckstyleNature</nature>
    2127        </natures>
    2228</projectDescription>
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintAction.java

    r30707 r33062  
    1 /*
    2  *      PrintAction.java
    3  *
    4  *      Copyright 2011 Kai Pastor
    5  *
    6  *      This program is free software; you can redistribute it and/or modify
    7  *      it under the terms of the GNU General Public License as published by
    8  *      the Free Software Foundation; either version 2 of the License, or
    9  *      (at your option) any later version.
    10  *
    11  *      This program is distributed in the hope that it will be useful,
    12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  *      GNU General Public License for more details.
    15  *
    16  *      You should have received a copy of the GNU General Public License
    17  *      along with this program; if not, write to the Free Software
    18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    19  *      MA 02110-1301, USA.
    20  *
    21  *
    22  */
     1// License: GPL. For details, see LICENSE file.
    232package org.openstreetmap.josm.plugins.print;
    243
     
    3716 * The PrintAction controls basic printing of the MapView
    3817 * and takes care of reasonable temporary adjustments to the preferences.
     18 * @author Kai Pastor
    3919 */
    4020public class PrintAction extends JosmAction implements Runnable {
     
    4424     */
    4525    public PrintAction() {
    46         super(tr("Print..."), (String)null, tr("Print the map"),
     26        super(tr("Print..."), (String) null, tr("Print the map"),
    4727                Shortcut.registerShortcut("system:print", tr("File: {0}", tr("Print...")),
    4828                        KeyEvent.VK_P, Shortcut.CTRL), true, "print/print", true);
     
    6646     */
    6747    @Override
    68     public void run () {
     48    public void run() {
    6949        PrintPlugin.adjustPrefs();
    7050        PrintDialog window = new PrintDialog(Main.parent);
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java

    r32172 r33062  
    1 /*
    2  *      PrintDialog.java
    3  *     
    4  *      Copyright 2011 Kai Pastor
    5  *     
    6  *      This program is free software; you can redistribute it and/or modify
    7  *      it under the terms of the GNU General Public License as published by
    8  *      the Free Software Foundation; either version 2 of the License, or
    9  *      (at your option) any later version.
    10  *     
    11  *      This program is distributed in the hope that it will be useful,
    12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  *      GNU General Public License for more details.
    15  *     
    16  *      You should have received a copy of the GNU General Public License
    17  *      along with this program; if not, write to the Free Software
    18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    19  *      MA 02110-1301, USA.
    20  *     
    21  *     
    22  */
    23 
     1// License: GPL. For details, see LICENSE file.
    242package org.openstreetmap.josm.plugins.print;
    253
     
    8462/**
    8563 * A print dialog with preview
     64 * @author Kai Pastor
    8665 */
    8766public class PrintDialog extends JDialog implements ActionListener {
     
    9170     */
    9271    protected JTextField printerField;
    93    
     72
    9473    /**
    9574     * The media format name
    9675     */
    9776    protected JTextField paperField;
    98    
     77
    9978    /**
    10079     * The media orientation
     
    10685     */
    10786    protected JCheckBox previewCheckBox;
    108    
     87
    10988    /**
    11089     * The resolution in dpi for printing/preview
    11190     */
    11291    protected SpinnerNumberModel resolutionModel;
    113    
     92
    11493    /**
    11594     * The map scale
    11695     */
    11796    protected SpinnerNumberModel scaleModel;
    118    
     97
    11998    /**
    12099     * The page preview
    121100     */
    122101    protected PrintPreview printPreview;
    123    
     102
    124103    /**
    125104     * The map view for preview an printing
    126105     */
    127106    protected PrintableMapView mapView;
    128    
     107
    129108    /**
    130109     * The printer job
    131110     */
    132111    protected transient PrinterJob job;
    133    
     112
    134113    /**
    135114     * The custom printer job attributes
    136115     */
    137116    transient PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
    138    
    139     /** 
     117
     118    /**
    140119     * Create a new print dialog
    141      * 
     120     *
    142121     * @param parent the parent component
    143122     */
     
    154133        setMaximumSize(Toolkit.getDefaultToolkit().getScreenSize());
    155134    }
    156    
     135
    157136    /**
    158137     * Show or hide the dialog
    159      * 
     138     *
    160139     * Set the dialog size to reasonable values.
    161      * 
     140     *
    162141     * @param visible a flag indication the visibility of the dialog
    163142     */
     
    181160        } else if (isShowing()) { // Avoid IllegalComponentStateException like in #8775
    182161            new WindowGeometry(this).remember(getClass().getName() + ".geometry");
    183             Main.pref.put("print.preview.enabled",previewCheckBox.isSelected());
     162            Main.pref.put("print.preview.enabled", previewCheckBox.isSelected());
    184163        }
    185164        super.setVisible(visible);
     
    191170    public void build() {
    192171        setLayout(new GridBagLayout());
    193         final GBC std = GBC.std().insets(0,5,5,0);
     172        final GBC std = GBC.std().insets(0, 5, 5, 0);
    194173        std.fill = GBC.HORIZONTAL;
    195         final GBC twoColumns   = GBC.std().insets(0,5,5,0).span(2);
     174        final GBC twoColumns = GBC.std().insets(0, 5, 5, 0).span(2);
    196175        twoColumns.fill = GBC.HORIZONTAL;
    197         final GBC threeColumns = GBC.std().insets(0,5,5,0).span(3);
     176        final GBC threeColumns = GBC.std().insets(0, 5, 5, 0).span(3);
    198177        threeColumns.fill = GBC.HORIZONTAL;
    199        
     178
    200179        JLabel caption;
    201        
     180
    202181        int row = 0;
    203182        caption = new JLabel(tr("Printer")+":");
     
    228207
    229208        row++;
    230         add(GBC.glue(5,10), GBC.std(1,row).fill(GBC.VERTICAL));
    231        
     209        add(GBC.glue(5, 10), GBC.std(1, row).fill(GBC.VERTICAL));
     210
    232211        row++;
    233212        caption = new JLabel(tr("Scale")+":");
     
    247226                        try {
    248227                            scaleField.commitEdit();
    249                             Main.pref.put("print.map-scale",scaleModel.getNumber().toString());
     228                            Main.pref.put("print.map-scale", scaleModel.getNumber().toString());
    250229                            mapView.setFixedMapScale(scaleModel.getNumber().intValue());
    251230                            printPreview.repaint();
     
    266245        resolutionModel = new SpinnerNumberModel(
    267246          Main.pref.getInteger("print.resolution.dpi", PrintPlugin.DEF_RESOLUTION_DPI),
    268           30, 1200, 10 );
     247          30, 1200, 10);
    269248        final JSpinner resolutionField = new JSpinner(resolutionModel);
    270249        resolutionField.addChangeListener(new ChangeListener() {
     
    276255                        try {
    277256                            resolutionField.commitEdit();
    278                             Main.pref.put("print.resolution.dpi",resolutionModel.getNumber().toString());
     257                            Main.pref.put("print.resolution.dpi", resolutionModel.getNumber().toString());
    279258                            printPreview.repaint();
    280259                        } catch (ParseException pe) {
     
    286265        });
    287266        add(resolutionField, std.grid(GBC.RELATIVE, row));
    288        
     267
    289268        row++;
    290269        caption = new JLabel(tr("Map information")+":");
     
    307286                });
    308287            }
     288
    309289            @Override
    310290            public void removeUpdate(DocumentEvent evt) {
    311291                this.insertUpdate(evt);
    312292            }
     293
    313294            @Override
    314295            public void changedUpdate(DocumentEvent evt) {
     
    317298        });
    318299        JScrollPane attributionPane = new JScrollPane(attributionText);
    319         add(attributionPane, GBC.std().insets(0,5,5,0).span(3).fill(GBC.BOTH).weight(0.0,1.0).grid(2, row));
    320 
    321         row++;
    322         add(GBC.glue(5,10), GBC.std(1,row).fill(GBC.VERTICAL));
    323        
     300        add(attributionPane, GBC.std().insets(0, 5, 5, 0).span(3).fill(GBC.BOTH).weight(0.0, 1.0).grid(2, row));
     301
     302        row++;
     303        add(GBC.glue(5, 10), GBC.std(1, row).fill(GBC.VERTICAL));
     304
    324305        row++;
    325306        previewCheckBox = new JCheckBox(tr("Map Preview"));
    326         previewCheckBox.setSelected(Main.pref.getBoolean("print.preview.enabled",false));
     307        previewCheckBox.setSelected(Main.pref.getBoolean("print.preview.enabled", false));
    327308        previewCheckBox.setActionCommand("toggle-preview");
    328309        previewCheckBox.addActionListener(this);
     
    340321        zoomOutButton.addActionListener(this);
    341322        add(zoomOutButton, threeColumns.grid(2, row));
    342        
     323
    343324        row++;
    344325        JButton zoomToPageButton = new JButton(tr("Zoom To Page"));
     
    346327        zoomToPageButton.addActionListener(this);
    347328        add(zoomToPageButton, threeColumns.grid(2, row));
    348        
     329
    349330        row++;
    350331        JButton zoomToActualSize = new JButton(tr("Zoom To Actual Size"));
     
    352333        zoomToActualSize.addActionListener(this);
    353334        add(zoomToActualSize, threeColumns.grid(2, row));
    354        
     335
    355336        printPreview = new PrintPreview();
    356337        if (previewCheckBox.isSelected()) {
    357338            printPreview.setPrintable(mapView);
    358339        }
    359         JScrollPane previewPane = new JScrollPane(printPreview, 
     340        JScrollPane previewPane = new JScrollPane(printPreview,
    360341                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    361         previewPane.setPreferredSize(Main.main != null ? Main.map.mapView.getSize() : new Dimension(210,297));
    362         add(previewPane, GBC.std(0,0).span(1, GBC.RELATIVE).fill().weight(5.0,5.0));
     342        previewPane.setPreferredSize(Main.main != null ? Main.map.mapView.getSize() : new Dimension(210, 297));
     343        add(previewPane, GBC.std(0, 0).span(1, GBC.RELATIVE).fill().weight(5.0, 5.0));
    363344
    364345        row++;
     
    372353        cancelButton.addActionListener(this);
    373354        actionPanel.add(cancelButton);
    374         add(actionPanel, GBC.std(0,row).insets(5,5,5,5).span(GBC.REMAINDER).fill(GBC.HORIZONTAL));
    375     }
    376    
     355        add(actionPanel, GBC.std(0, row).insets(5, 5, 5, 5).span(GBC.REMAINDER).fill(GBC.HORIZONTAL));
     356    }
     357
    377358    /**
    378359     * Update the dialog fields from the underlying model
     
    386367        } else {
    387368            printerField.setText(service.getName());
    388             if (! attrs.containsKey(Media.class)) {
     369            if (!attrs.containsKey(Media.class)) {
    389370                attrs.add((Attribute) service.getDefaultAttributeValue(Media.class));
    390             } 
     371            }
    391372            if (attrs.containsKey(Media.class)) {
    392373                paperField.setText(attrs.get(Media.class).toString());
    393374            }
    394375
    395             if (! attrs.containsKey(OrientationRequested.class)) {
     376            if (!attrs.containsKey(OrientationRequested.class)) {
    396377                attrs.add((Attribute) service.getDefaultAttributeValue(OrientationRequested.class));
    397378            }
     
    400381            }
    401382
    402             if (! attrs.containsKey(MediaPrintableArea.class)) {
     383            if (!attrs.containsKey(MediaPrintableArea.class)) {
    403384                PageFormat pf = job.defaultPage();
    404385                attrs.add(new MediaPrintableArea(
    405                   (float)pf.getImageableX()/72f,
    406                   (float)pf.getImageableY()/72f,
    407                   (float)pf.getImageableWidth()/72f,
    408                   (float)pf.getImageableHeight()/72f,
    409                   MediaPrintableArea.INCH) );
    410             }
    411            
     386                  (float) pf.getImageableX()/72f,
     387                  (float) pf.getImageableY()/72f,
     388                  (float) pf.getImageableWidth()/72f,
     389                  (float) pf.getImageableHeight()/72f,
     390                  MediaPrintableArea.INCH));
     391            }
     392
    412393            PageFormat pf = job.getPageFormat(attrs);
    413394            printPreview.setPageFormat(pf);
    414395        }
    415396    }
    416    
     397
    417398    /**
    418399     * Handle user input
    419      * 
     400     *
    420401     * @param e an ActionEvent with one of the known commands
    421402     */
     
    470451
    471452    protected void savePrintSettings() {
    472         // Save only one printer service attribute: printer name 
     453        // Save only one printer service attribute: printer name
    473454        PrintService service = job.getPrintService();
    474455        if (service != null) {
     
    476457            for (Attribute a : service.getAttributes().toArray()) {
    477458                if ("printer-name".equals(a.getName()) && a instanceof TextSyntax) {
    478                     serviceAttributes.add(marshallPrintSetting(a, TextSyntax.class, ((TextSyntax)a).getValue()));
     459                    serviceAttributes.add(marshallPrintSetting(a, TextSyntax.class, ((TextSyntax) a).getValue()));
    479460                }
    480461            }
    481462            Main.pref.putArray("print.settings.service-attributes", serviceAttributes);
    482463        }
    483        
     464
    484465        // Save all request attributes
    485466        Collection<String> ignoredAttributes = Arrays.asList("media-printable-area");
     
    488469            Collection<String> setting = null;
    489470            if (a instanceof TextSyntax) {
    490                 setting = marshallPrintSetting(a, TextSyntax.class, ((TextSyntax)a).getValue());
     471                setting = marshallPrintSetting(a, TextSyntax.class, ((TextSyntax) a).getValue());
    491472            } else if (a instanceof EnumSyntax) {
    492                 setting = marshallPrintSetting(a, EnumSyntax.class, Integer.toString(((EnumSyntax)a).getValue()));
     473                setting = marshallPrintSetting(a, EnumSyntax.class, Integer.toString(((EnumSyntax) a).getValue()));
    493474            } else if (a instanceof IntegerSyntax) {
    494                 setting = marshallPrintSetting(a, IntegerSyntax.class, Integer.toString(((IntegerSyntax)a).getValue()));
     475                setting = marshallPrintSetting(a, IntegerSyntax.class, Integer.toString(((IntegerSyntax) a).getValue()));
    495476            } else if (!ignoredAttributes.contains(a.getName())) {
    496477                // TODO: Add support for DateTimeSyntax, SetOfIntegerSyntax, ResolutionSyntax if needed
     
    503484        Main.pref.putArray("print.settings.request-attributes", requestAttributes);
    504485    }
    505    
     486
    506487    protected Collection<String> marshallPrintSetting(Attribute a, Class<?> syntaxClass, String value) {
    507488        return new ArrayList<>(Arrays.asList(a.getCategory().getName(), a.getClass().getName(), syntaxClass.getName(), value));
    508489    }
    509    
     490
    510491    @SuppressWarnings("unchecked")
    511     protected Attribute unmarshallPrintSetting(Collection<String> setting) throws 
     492    protected Attribute unmarshallPrintSetting(Collection<String> setting) throws
    512493        ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    513        
     494
    514495        if (setting == null || setting.size() != 4) {
    515496            throw new IllegalArgumentException("Invalid setting: "+setting);
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPlugin.java

    r30173 r33062  
    1 /*
    2  *      PrintPlugin.java
    3  *     
    4  *      Copyright 2011 Kai Pastor
    5  *     
    6  *      This program is free software; you can redistribute it and/or modify
    7  *      it under the terms of the GNU General Public License as published by
    8  *      the Free Software Foundation; either version 2 of the License, or
    9  *      (at your option) any later version.
    10  *     
    11  *      This program is distributed in the hope that it will be useful,
    12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  *      GNU General Public License for more details.
    15  *     
    16  *      You should have received a copy of the GNU General Public License
    17  *      along with this program; if not, write to the Free Software
    18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    19  *      MA 02110-1301, USA.
    20  *     
    21  *     
    22  */
    23 
     1// License: GPL. For details, see LICENSE file.
    242package org.openstreetmap.josm.plugins.print;
    253
     
    3412
    3513/**
    36  * The PrintPlugin class implements the interface JOSM needs to 
     14 * The PrintPlugin class implements the interface JOSM needs to
    3715 * load extension.
     16 * @author Kai Pastor
    3817 */
    3918public class PrintPlugin extends Plugin {
     
    8463
    8564    /**
    86      * Enables/disables the print action in the GUI 
     65     * Enables/disables the print action in the GUI
    8766     * when a MapFrame gets shown or removed.
    8867     *
     
    9877    /**
    9978     * Temporary adjust the preferences for map printing
    100      * 
    101      * This will adjust some preferences such that elements which are 
    102      * not useful on paper will not be printed. This includes the 
    103      * following markup: downloaded area; node markers for connection, 
     79     *
     80     * This will adjust some preferences such that elements which are
     81     * not useful on paper will not be printed. This includes the
     82     * following markup: downloaded area; node markers for connection,
    10483     * selected, unselected, tagged state.
    105      * 
     84     *
    10685     * Changes will be undone by restorePrefs().
    10786     */
     
    11796        }
    11897    }
    119    
     98
    12099    /**
    121100     * Adjust a single preference.
    122      * 
     101     *
    123102     * Saves the existing value for later restorePref.
    124      * 
     103     *
    125104     * @param key the preference key
    126105     * @param the temporary new int value
     
    132111        Main.pref.putInteger(key, value);
    133112    }
    134    
     113
    135114    /**
    136115     * Adjust a single preference.
    137      * 
     116     *
    138117     * Saves the existing value for later restorePref.
    139      * 
     118     *
    140119     * @param key the preference key
    141120     * @param the temporary new boolean value
     
    147126        Main.pref.put(key, value);
    148127    }
    149    
     128
    150129    /**
    151130     * Adjust a single preference.
    152      * 
     131     *
    153132     * Saves the existing value for later restorePref.
    154      * 
     133     *
    155134     * @param key the preference key
    156135     * @param the temporary new String value
     
    162141        Main.pref.put(key, value);
    163142    }
    164    
     143
    165144    /**
    166145     * Undo temporary adjustments to the preferences made by adjustPrefs().
     
    178157        }
    179158    }
    180    
     159
    181160    /**
    182161     * Restore a single preference previously saved by adjustPref()
    183      * 
     162     *
    184163     * @param key the preference key to be restored
    185164     */
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintPreview.java

    r32169 r33062  
    1 /*
    2  *      PrintPreview.java
    3  *     
    4  *      Copyright 2011 Kai Pastor
    5  *     
    6  *      This program is free software; you can redistribute it and/or modify
    7  *      it under the terms of the GNU General Public License as published by
    8  *      the Free Software Foundation; either version 2 of the License, or
    9  *      (at your option) any later version.
    10  *     
    11  *      This program is distributed in the hope that it will be useful,
    12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  *      GNU General Public License for more details.
    15  *     
    16  *      You should have received a copy of the GNU General Public License
    17  *      along with this program; if not, write to the Free Software
    18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    19  *      MA 02110-1301, USA.
    20  *     
    21  *     
    22  */
    23 
     1// License: GPL. For details, see LICENSE file.
    242package org.openstreetmap.josm.plugins.print;
    253
     
    3715import java.awt.print.PrinterException;
    3816
     17import javax.swing.JPanel;
    3918import javax.swing.JViewport;
    40 import javax.swing.JPanel;
    4119import javax.swing.RepaintManager;
    4220
     
    4523/**
    4624 * A generic print preview component
    47  * 
    48  * Given a Printable, a PageFormat and a zoom factor, this component 
    49  * will render a scrollable and zoomable print preview. If no Printable 
    50  * is defined, it will fill the printable area of the page format in 
     25 *
     26 * Given a Printable, a PageFormat and a zoom factor, this component
     27 * will render a scrollable and zoomable print preview. If no Printable
     28 * is defined, it will fill the printable area of the page format in
    5129 * plain gray.
    52  * 
     30 *
    5331 * There is a special zoom-to-page condition where the component will
    5432 * automatically adjust the zoom level such that the whole page preview
    5533 * will just fit into the size of the component.
     34 * @author Kai Pastor
    5635 */
    5736class PrintPreview extends JPanel {
    58    
     37
    5938    /**
    6039     * The PageFormat chosen for printing (and preview)
    6140     */
    6241    protected transient PageFormat format;
    63    
     42
    6443    /**
    6544     * The current zoom factor for the preview
    6645     */
    6746    protected double zoom = 1.0;
    68    
    69     /**
    70      * If true, the preview is always zoomed such that 
     47
     48    /**
     49     * If true, the preview is always zoomed such that
    7150     * the whole page fits into the preview area.
    7251     */
    7352    protected boolean zoomToPage = true;
    74    
     53
    7554    /**
    7655     * When this flag is true, no painting operations will be performed.
    7756     */
    7857    protected boolean paintingDisabled;
    79    
     58
    8059    /**
    8160     * the printable object for rendering preview contents
    8261     */
    8362    protected transient Printable printable;
    84    
    85     /**
    86      * Constructs a new preview component 
    87      */
    88     public PrintPreview() {
     63
     64    /**
     65     * Constructs a new preview component
     66     */
     67    PrintPreview() {
    8968        super();
    9069    }
     
    9271    /**
    9372     * Constructs a new preview component for a printable
    94      * 
     73     *
    9574     * @param p the printable object for rendering preview contents, or null
    9675     */
    97     public PrintPreview(Printable p) {
     76    PrintPreview(Printable p) {
    9877        super();
    9978        printable = p;
     
    10281    /**
    10382     * Sets (and unsets) the printable object
    104      * 
     83     *
    10584     * @param p a printable object, or null
    10685     */
     
    10988        repaint();
    11089    }
    111    
     90
    11291    /**
    11392     * Sets the page format
    114      * 
     93     *
    11594     * @param format the PageFormat chosen for printing (and preview)
    11695     */
     
    12099        repaint();
    121100    }
    122    
     101
    123102    /**
    124103     * Sets the preview zoom relativ to the actual size
    125104     *
    126      * @param zoom the zoom factor 
     105     * @param zoom the zoom factor
    127106     */
    128107    public void setZoom(double zoom) {
    129108        setZoom(zoom, false);
    130109    }
    131    
     110
    132111    /**
    133112     * Zoom into the preview
    134      * 
     113     *
    135114     * Doubles the current zoom factor, if smaller than 5.0.
    136115     */
     
    141120        }
    142121    }
    143  
     122
    144123    /**
    145124     * Zoom out of the preview
    146      * 
     125     *
    147126     * Set the zoom factor to half its current value, if bigger than 0.1.
    148127     */
     
    156135    /**
    157136     * Zoom to fit the page size
    158      * 
     137     *
    159138     * Set the zoom factor such that the whole page fits into the preview area.
    160139     */
     
    178157     * Sets the preview zoom relativ to the actual size
    179158     *
    180      * @param zoom the zoom factor 
    181      * @param zoomToPage when set to true, the zoom factor will be 
     159     * @param zoom the zoom factor
     160     * @param zoomToPage when set to true, the zoom factor will be
    182161     *   adjusted on resize operations such that the whole page always
    183162     *   fits to the preview area.
     
    196175        this.zoomToPage = zoomToPage;
    197176        revalidate(); // Make JScrollPane aware of the change in size
    198         RepaintManager.currentManager(this).validateInvalidComponents(); 
     177        RepaintManager.currentManager(this).validateInvalidComponents();
    199178
    200179        Dimension dim = getZoomedPageDimension();
    201180        Rectangle view = getVisibleRect();
    202181
    203         view.x = (int)((0.5*oldView.width+oldView.x)/Math.max(oldView.width,oldDim.width)*Math.max(view.width,dim.width)-0.5*view.width);
    204         view.y = (int)((0.5*oldView.height+oldView.y)/Math.max(oldView.height,oldDim.height)*Math.max(view.height,dim.height)-0.5*view.height);
     182        view.x = (int) ((0.5*oldView.width+oldView.x) /
     183                Math.max(oldView.width, oldDim.width)*Math.max(view.width, dim.width)-0.5*view.width);
     184        view.y = (int) ((0.5*oldView.height+oldView.y) /
     185                Math.max(oldView.height, oldDim.height)*Math.max(view.height, dim.height)-0.5*view.height);
    205186
    206187        scrollRectToVisible(view);
     
    211192    /**
    212193     * Returns the actual current zoom
    213      * 
     194     *
    214195     * This factor might be different from the last explicitly set factor
    215196     * when zoomToPage is true.
    216      * 
    217      * @return the zoom factor 
     197     *
     198     * @return the zoom factor
    218199     */
    219200    public double getZoom() {
    220201        if (format != null && (zoomToPage || zoom < 0.01)) {
    221             // actually this is zoom-to-page 
     202            // actually this is zoom-to-page
    222203            Dimension dim = getParent().getSize();
    223204            int resolution = Toolkit.getDefaultToolkit().getScreenResolution();
     
    228209        return zoom;
    229210    }
    230        
     211
    231212    /**
    232213     * Get the current dimension of the page preview
    233      * 
     214     *
    234215     * @return dimension in pixels
    235216     */
     
    237218        int resolution = Toolkit.getDefaultToolkit().getScreenResolution();
    238219        double z = getZoom();
    239         int width = (int)(z * resolution * format.getWidth() / 72.0);
    240         int height = (int)(z * resolution * format.getHeight() / 72.0);
     220        int width = (int) (z * resolution * format.getWidth() / 72.0);
     221        int height = (int) (z * resolution * format.getHeight() / 72.0);
    241222        return new Dimension(width, height);
    242223    }
     
    244225    /**
    245226     * Get the current preferred size of the component
    246      * 
    247      * @return indicates a zero size when zoomToPage is active, 
     227     *
     228     * @return indicates a zero size when zoomToPage is active,
    248229     *   the zoomed page dimension otherwise
    249230     */
     
    251232    public Dimension getPreferredSize() {
    252233        if (format == null || zoomToPage || zoom < 0.01) {
    253             return new Dimension(0,0);
     234            return new Dimension(0, 0);
    254235        }
    255236        return getZoomedPageDimension();
     
    258239    /**
    259240     * Paints the component
    260      * 
    261      * This will do nothing, not even call super.paintComponent(g), if 
     241     *
     242     * This will do nothing, not even call super.paintComponent(g), if
    262243     * painting is disabled in this component.
    263      * 
     244     *
    264245     * @param g a Graphics to draw to
    265246     */
     
    279260        Dimension out = getZoomedPageDimension();
    280261        double scale = Math.min(
    281           out.getHeight()/format.getHeight() , out.getWidth()/format.getWidth() );
    282         double left = 0.5 * ((double)getWidth() - scale * format.getWidth());
    283         double top  = 0.5 * ((double)getHeight() - scale * format.getHeight());
    284        
     262          out.getHeight()/format.getHeight(), out.getWidth()/format.getWidth());
     263        double left = 0.5 * (getWidth() - scale * format.getWidth());
     264        double top = 0.5 * (getHeight() - scale * format.getHeight());
     265
    285266        g2d.translate(left, top);
    286267        g2d.setColor(Color.black);
     
    304285        } else {
    305286            g2d.setColor(Color.gray);
    306             g2d.fillRect(0, 0, (int)format.getWidth(), (int)format.getHeight());
     287            g2d.fillRect(0, 0, (int) format.getWidth(), (int) format.getHeight());
    307288        }
    308289
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableLayerManager.java

    r32965 r33062  
     1// License: GPL. For details, see LICENSE file.
    12package org.openstreetmap.josm.plugins.print;
    23
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintableMapView.java

    r32191 r33062  
    1 /*
    2  *      PrintableMapView.java
    3  *     
    4  *      Copyright 2011 Kai Pastor
    5  *     
    6  *      This program is free software; you can redistribute it and/or modify
    7  *      it under the terms of the GNU General Public License as published by
    8  *      the Free Software Foundation; either version 2 of the License, or
    9  *      (at your option) any later version.
    10  *     
    11  *      This program is distributed in the hope that it will be useful,
    12  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  *      GNU General Public License for more details.
    15  *     
    16  *      You should have received a copy of the GNU General Public License
    17  *      along with this program; if not, write to the Free Software
    18  *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
    19  *      MA 02110-1301, USA.
    20  *     
    21  *     
    22  */
    23 
     1// License: GPL. For details, see LICENSE file.
    242package org.openstreetmap.josm.plugins.print;
    253
     
    5533 * The PrintableMapView class implements a "Printable" perspective on
    5634 * the main MapView.
    57  *
     35 * @author Kai Pastor
    5836 */
    5937public class PrintableMapView extends MapView implements Printable {
    60    
     38
    6139    /**
    6240     * A fixed map scale if greater than zero.
    6341     */
    6442    protected int fixedMapScale = 0;
    65    
     43
    6644    /**
    6745     * The factor for scaling the printing graphics to the desired
     
    6947     */
    7048    protected double g2dFactor;
    71    
     49
    7250    /**
    7351     * The font size for text added by PrintableMapView
     
    8159        /* Initialize MapView with a dummy parent */
    8260        super(new PrintableLayerManager(), new JPanel(), null);
    83        
    84         /* Disable MapView's ComponentLister, 
     61
     62        /* Disable MapView's ComponentLister,
    8563         * as it will interfere with the main MapView. */
    86         ComponentListener listeners[] = getComponentListeners();
    87         for (int i=0; i<listeners.length; i++) {
     64        ComponentListener[] listeners = getComponentListeners();
     65        for (int i = 0; i < listeners.length; i++) {
    8866            removeComponentListener(listeners[i]);
    8967        }
     
    9270    /**
    9371     * Set a fixed map scale 1 : "scale"
    94      * 
     72     *
    9573     * @param scale the fixed map scale
    9674     */
     
    10280    /**
    10381     * Unset the fixed map scale
    104      * 
     82     *
    10583     * The map scaling will be chosen automatically such that the
    10684     * main windows map view fits on the page format.
     
    11189    }
    11290
    113     /** 
     91    /**
    11492     * Get the map scale that will be used for rendering
    115      */     
     93     */
    11694    public int getMapScale() {
    11795        if (fixedMapScale > 0 || g2dFactor == 0.0) {
     
    127105     * Initialize the PrintableMapView for a particular combination of
    128106     * main MapView, PageFormat and target resolution
    129      * 
     107     *
    130108     * @param pageformat the size and orientation of the page being drawn
    131109     */
     
    133111        int resolution = Main.pref.getInteger("print.resolution.dpi", PrintPlugin.DEF_RESOLUTION_DPI);
    134112        g2dFactor = 72.0/resolution;
    135         setSize((int)(pageFormat.getImageableWidth()/g2dFactor),(int)(pageFormat.getImageableHeight()/g2dFactor));
    136     }
    137    
    138     /**
    139      * Resizes this component. 
     113        setSize((int) (pageFormat.getImageableWidth()/g2dFactor), (int) (pageFormat.getImageableHeight()/g2dFactor));
     114    }
     115
     116    /**
     117     * Resizes this component.
    140118     */
    141119    @Override
     
    148126        }
    149127    }
    150            
    151     /**
    152      * Resizes this component. 
     128
     129    /**
     130     * Resizes this component.
    153131     */
    154132    @Override
     
    176154    /**
    177155     * Render a page for the printer
    178      * 
     156     *
    179157     * Implements java.awt.print.Printable.
    180158     *
    181159     * @param g the context into which the page is drawn
    182160     * @param pageFormat the size and orientation of the page being drawn
    183      * @param page the zero based index of the page to be drawn 
    184      * 
     161     * @param page the zero based index of the page to be drawn
     162     *
    185163     * @return PAGE_EXISTS for page==0 or NO_SUCH_PAGE for page>0
    186      * 
     164     *
    187165     * @throws PrinterException thrown when the print job is terminated
    188      * 
     166     *
    189167     */
    190168    @Override
     
    197175        initialize(pageFormat);
    198176
    199         Graphics2D g2d = (Graphics2D)g;
     177        Graphics2D g2d = (Graphics2D) g;
    200178        g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    201179        paintMap(g2d, pageFormat);
     
    204182        return PAGE_EXISTS;
    205183    }
    206    
    207     /** 
     184
     185    /**
    208186     * Paint the map
    209      * 
     187     *
    210188     * This implementation is derived from MapView's paint and
    211189     * from other JOSM core components.
    212      * 
     190     *
    213191     * @param g2d the graphics context to use for painting
    214192     * @param pageFormat the size and orientation of the page being drawn
     
    217195        AffineTransform at = g2d.getTransform();
    218196        g2d.scale(g2dFactor, g2dFactor);
    219        
     197
    220198        Bounds box = getRealBounds();
    221199        for (Layer l : getLayerManager().getVisibleLayersInZOrder()) {
    222200            if (l.getOpacity() < 1) {
    223                 g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER,(float)l.getOpacity()));
     201                g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) l.getOpacity()));
    224202            }
    225203            l.paint(g2d, this, box);
     
    230208    }
    231209
    232     /** 
     210    /**
    233211     * Paint a linear scale and a lexical scale
    234      * 
    235      * This implementation is derived from JOSM's MapScaler, 
     212     *
     213     * This implementation is derived from JOSM's MapScaler,
    236214     * NavigatableComponent and SystemOfMeasurement.
    237215     *
     
    253231        if (distMantissa <= 2.5) {
    254232            distScale = 2.5 / distMantissa;
    255         }
    256         else if (distMantissa <= 4.0) {
     233        } else if (distMantissa <= 4.0) {
    257234            distScale = 5.0 / distMantissa;
    258         }
    259         else {
     235        } else {
    260236            distScale = 10.0 / distMantissa;
    261237        }
     
    269245        /* offset from the left paper border to the left end of the bar */
    270246        Rectangle2D bound = g2d.getFontMetrics().getStringBounds("0", g2d);
    271         int xLeft = (int)(bound.getWidth()/2);
    272        
     247        int xLeft = (int) (bound.getWidth()/2);
     248
    273249        /* offset from the left paper border to the right label */
    274250        String rightLabel = som.getDistText(dist100px * distScale);
    275251        bound = g2d.getFontMetrics().getStringBounds(rightLabel, g2d);
    276252        int xRight = xLeft+(int) Math.max(0.95*x, x-bound.getWidth()/2);
    277        
     253
     254        // CHECKSTYLE.OFF: SingleSpaceSeparator
    278255        int h        = FONT_SIZE / 2; // raster, height of the bar
    279256        int yLexical = 3 * h;         // baseline of the lexical scale
    280257        int yBar     = 4 * h;         // top of the bar
    281258        int yLabel   = 8 * h;         // baseline of the labels
    282         int w  = (int)(distScale * 100.0);  // length of the bar
    283         int ws = (int)(distScale * 20.0);   // length of a segment
    284        
     259        int w  = (int) (distScale * 100.0);  // length of the bar
     260        int ws = (int) (distScale * 20.0);   // length of a segment
     261        // CHECKSTYLE.ON: SingleSpaceSeparator
     262
    285263        /* white background */
    286264        g2d.setColor(Color.WHITE);
    287265        g2d.fillRect(xLeft-1, yBar-1, w+2, h+2);
    288        
     266
    289267        /* black foreground */
    290268        g2d.setColor(Color.BLACK);
    291269        g2d.drawRect(xLeft, yBar, w, h);
    292270        g2d.fillRect(xLeft, yBar, ws, h);
    293         g2d.fillRect(xLeft+(int)(distScale * 40.0), yBar, ws, h);
     271        g2d.fillRect(xLeft+(int) (distScale * 40.0), yBar, ws, h);
    294272        g2d.fillRect(xLeft+w-ws, yBar, ws, h);
    295273        g2d.setFont(labelFont);
    296274        paintText(g2d, "0", 0, yLabel);
    297275        paintText(g2d, rightLabel, xRight, yLabel);
    298        
     276
    299277        /* lexical scale */
    300278        int mapScale = getMapScale();
     
    304282        g2d.setFont(scaleFront);
    305283        bound = g2d.getFontMetrics().getStringBounds(lexicalScale, g2d);
    306         int xLexical = Math.max(0, xLeft + (w - (int)bound.getWidth()) / 2);
     284        int xLexical = Math.max(0, xLeft + (w - (int) bound.getWidth()) / 2);
    307285        paintText(g2d, lexicalScale, xLexical, yLexical);
    308286    }
    309    
    310     /** 
     287
     288    /**
    311289     * Paint an attribution text
    312      * 
     290     *
    313291     * @param g2d the graphics context to use for painting
    314292     * @param pageFormat the size and orientation of the page being drawn
     
    316294    public void paintMapAttribution(Graphics2D g2d, PageFormat pageFormat) {
    317295        String text = Main.pref.get("print.attribution", AbstractOsmTileSource.DEFAULT_OSM_ATTRIBUTION);
    318        
     296
    319297        if (text == null) {
    320298            return;
    321299        }
    322            
     300
    323301        Font attributionFont = new Font("Arial", Font.PLAIN, FONT_SIZE * 8 / 10);
    324302        g2d.setFont(attributionFont);
     
    327305        int y = FONT_SIZE * 3 / 2;
    328306        int from = 0;
    329         int to = text.indexOf("\n", from);
     307        int to = text.indexOf('\n', from);
    330308        while (to >= from) {
    331309            String line = text.substring(from, to);
    332310
    333311            Rectangle2D bound = g2d.getFontMetrics().getStringBounds(line, g2d);
    334             int x = (int)((pageFormat.getImageableWidth() - bound.getWidth()) - FONT_SIZE/2);
    335            
     312            int x = (int) ((pageFormat.getImageableWidth() - bound.getWidth()) - FONT_SIZE/2);
     313
    336314            paintText(g2d, line, x, y);
    337315
    338             y   += FONT_SIZE * 5 / 4;
     316            y += FONT_SIZE * 5 / 4;
    339317            from = to + 1;
    340             to   = text.indexOf("\n", from);
    341         }
    342     }
    343    
     318            to = text.indexOf('\n', from);
     319        }
     320    }
     321
    344322    /**
    345323     * Paint a text.
    346      * 
     324     *
    347325     * This method will not only draw the letters but also a background which improves redability.
    348      * 
     326     *
    349327     * @param g2d the graphics context to use for painting
    350328     * @param text the text to be drawn
Note: See TracChangeset for help on using the changeset viewer.