Changeset 32170 in osm


Ignore:
Timestamp:
2016-05-12T00:36:30+02:00 (8 years ago)
Author:
donvip
Message:

fix sonar warnings

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/print/src/org/openstreetmap/josm/plugins/print/PrintDialog.java

    r32144 r32170  
    130130     * The printer job
    131131     */
    132     protected PrinterJob job;
     132    protected transient PrinterJob job;
    133133   
    134134    /**
    135135     * The custom printer job attributes
    136136     */
    137     PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
     137    transient PrintRequestAttributeSet attrs = new HashPrintRequestAttributeSet();
    138138   
    139139    /**
     
    152152        updateFields();
    153153        pack();
    154         //setMinimumSize(getPreferredSize());
    155154        setMaximumSize(Toolkit.getDefaultToolkit().getScreenSize());
    156155    }
     
    241240        final JSpinner scaleField = new JSpinner(scaleModel);
    242241        scaleField.addChangeListener(new ChangeListener() {
     242            @Override
    243243            public void stateChanged(ChangeEvent evt) {
    244244                SwingUtilities.invokeLater(new Runnable() {
     245                    @Override
    245246                    public void run() {
    246247                        try {
     
    249250                            mapView.setFixedMapScale(scaleModel.getNumber().intValue());
    250251                            printPreview.repaint();
    251                         }
    252                         catch (ParseException pe) {
    253                             ; // NOP
     252                        } catch (ParseException pe) {
     253                            Main.error(pe);
    254254                        }
    255255                    }
     
    269269        final JSpinner resolutionField = new JSpinner(resolutionModel);
    270270        resolutionField.addChangeListener(new ChangeListener() {
     271            @Override
    271272            public void stateChanged(ChangeEvent evt) {
    272273                SwingUtilities.invokeLater(new Runnable() {
     274                    @Override
    273275                    public void run() {
    274276                        try {
     
    276278                            Main.pref.put("print.resolution.dpi",resolutionModel.getNumber().toString());
    277279                            printPreview.repaint();
    278                         }
    279                         catch (ParseException pe) {
    280                             ; // NOP
     280                        } catch (ParseException pe) {
     281                            Main.error(pe);
    281282                        }
    282283                    }
     
    296297        attributionText.setWrapStyleWord(true);
    297298        attributionText.getDocument().addDocumentListener(new DocumentListener() {
     299            @Override
    298300            public void insertUpdate(DocumentEvent evt) {
    299301                SwingUtilities.invokeLater(new Runnable() {
     302                    @Override
    300303                    public void run() {
    301304                        Main.pref.put("print.attribution", attributionText.getText());
     
    304307                });
    305308            }
     309            @Override
    306310            public void removeUpdate(DocumentEvent evt) {
    307311                this.insertUpdate(evt);
    308312            }
     313            @Override
    309314            public void changedUpdate(DocumentEvent evt) {
    310                 ; // NOP
     315                // NOP
    311316            }
    312317        });
     
    352357            printPreview.setPrintable(mapView);
    353358        }
    354         JScrollPane previewPane = new JScrollPane(printPreview, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
     359        JScrollPane previewPane = new JScrollPane(printPreview,
     360                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    355361        previewPane.setPreferredSize(Main.main != null ? Main.map.mapView.getSize() : new Dimension(210,297));
    356362        add(previewPane, GBC.std(0,0).span(1, GBC.RELATIVE).fill().weight(5.0,5.0));
     
    378384            paperField.setText("-");
    379385            orientationField.setText("-");
    380         }
    381         else {
     386        } else {
    382387            printerField.setText(service.getName());
    383388            if (! attrs.containsKey(Media.class)) {
     
    398403                PageFormat pf = job.defaultPage();
    399404                attrs.add(new MediaPrintableArea(
    400                   (float)pf.getImageableX()/72,(float)pf.getImageableY()/72,
    401                   (float)pf.getImageableWidth()/72,(float)pf.getImageableHeight()/72,
     405                  (float)pf.getImageableX()/72f,
     406                  (float)pf.getImageableY()/72f,
     407                  (float)pf.getImageableWidth()/72f,
     408                  (float)pf.getImageableHeight()/72f,
    402409                  MediaPrintableArea.INCH) );
    403410            }
     
    413420     * @param e an ActionEvent with one of the known commands
    414421     */
     422    @Override
    415423    public void actionPerformed(ActionEvent e) {
    416424        String cmd = e.getActionCommand();
    417         if (cmd.equals("printer-dialog")) {
     425        if ("printer-dialog".equals(cmd)) {
    418426            if (job.printDialog(attrs)) {
    419427                updateFields();
    420428                savePrintSettings();
    421429            }
    422         }
    423         else if (cmd.equals("toggle-preview")) {
     430        } else if ("toggle-preview".equals(cmd)) {
    424431            Main.pref.put("print.preview.enabled", previewCheckBox.isSelected());
    425             if (previewCheckBox.isSelected() == true) {
     432            if (previewCheckBox.isSelected()) {
    426433                printPreview.setPrintable(mapView);
    427             }
    428             else {
     434            } else {
    429435                printPreview.setPrintable(null);
    430436            }
    431         }
    432         else if (cmd.equals("zoom-in")) {
     437        } else if ("zoom-in".equals(cmd)) {
    433438            printPreview.zoomIn();
    434         }
    435         else if (cmd.equals("zoom-out")) {
     439        } else if ("zoom-out".equals(cmd)) {
    436440            printPreview.zoomOut();
    437         }
    438         else if (cmd.equals("zoom-to-page")) {
     441        } else if ("zoom-to-page".equals(cmd)) {
    439442            printPreview.zoomToPage();
    440         }
    441         else if (cmd.equals("zoom-to-actual-size")) {
     443        } else if ("zoom-to-actual-size".equals(cmd)) {
    442444            printPreview.setZoom(1.0);
    443         }
    444         else if (cmd.equals("print")) {
     445        } else if ("print".equals(cmd)) {
    445446            try {
    446447                job.print(attrs);
    447             }
    448             catch (PrinterAbortException ex) {
     448            } catch (PrinterAbortException ex) {
    449449                String msg = ex.getLocalizedMessage();
    450450                if (msg.length() == 0) {
     
    454454                  tr("Printing stopped"),
    455455                  JOptionPane.WARNING_MESSAGE);
    456             }
    457             catch (PrinterException ex) {
     456            } catch (PrinterException ex) {
    458457                String msg = ex.getLocalizedMessage();
    459458                if (msg == null || msg.length() == 0) {
     
    465464            }
    466465            dispose();
    467         }
    468         else if (cmd.equals("cancel")) {
     466        } else if ("cancel".equals(cmd)) {
    469467            dispose();
    470468        }
     
    512510    @SuppressWarnings("unchecked")
    513511    protected Attribute unmarshallPrintSetting(Collection<String> setting) throws
    514         IllegalArgumentException, ClassNotFoundException, SecurityException, NoSuchMethodException,
    515         InstantiationException, IllegalAccessException, InvocationTargetException {
     512        ClassNotFoundException, NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
    516513       
    517514        if (setting == null || setting.size() != 4) {
     
    551548                    job.setPrintService(PrintServiceLookup.lookupPrintServices(null, new HashPrintServiceAttributeSet(a))[0]);
    552549                }
    553             } catch (Exception e) {
     550            } catch (PrinterException | ReflectiveOperationException e) {
    554551                Main.warn(e.getClass().getSimpleName()+": "+e.getMessage());
    555552            }
     
    558555            try {
    559556                attrs.add(unmarshallPrintSetting(setting));
    560             } catch (Exception e) {
     557            } catch (ReflectiveOperationException e) {
    561558                Main.warn(e.getClass().getSimpleName()+": "+e.getMessage());
    562559            }
     
    564561    }
    565562}
    566 
Note: See TracChangeset for help on using the changeset viewer.