Content of file cpd.xml

<?xml version="1.0" encoding="UTF-8"?>
<pmd-cpd>
   <duplication lines="113" tokens="387">
      <file column="1" endcolumn="3" endline="165" line="53"
            path="/var/jenkins_home/jobs/Mistral_Metrics/workspace/modules/Examples/HistogramViewerExample/src/main/java/it/tidalwave/mistral/example/AbstractViewerPanel.java"/>
      <file column="1" endcolumn="3" endline="165" line="53"
            path="/var/jenkins_home/jobs/Mistral_Metrics/workspace/modules/Examples/ViewerExample/src/main/java/it/tidalwave/mistral/example/AbstractViewerPanel.java"/>
      <codefragment><![CDATA[public class AbstractViewerPanel extends JPanel
  {
    protected final EditableImageRenderer imageRenderer = new EditableImageRenderer();

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    public void loadImage (final String fileName)
            throws MalformedURLException
      {
        try // used during development
          {
            final var file = Path.of("../../../www/images/" + fileName);

            if (Files.exists(file) && Files.isReadable(file))
              {
                loadImage(file);
              }

            else
              {
                throw new FileNotFoundException(file.toString());
              }
          }
        catch (Exception e)
          {
            // used by the deployed examples
            loadImage(new URL("https://mistral.dev.java.net/images/" + fileName));
          }
      }

    /*******************************************************************************************************************
     *
     *
     ******************************************************************************************************************/
    protected void loadImage (final Object input)
      {
        final var label = new JLabel("Loading " + input + "...");
        label.setForeground(Color.WHITE);
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setFont(new Font("sansserif", Font.BOLD, 14));

        final var overlay = new Overlay()
          {
            @Override
            public boolean isVisible()
              {
                return true;
              }

            @Override
            public void paint (final Graphics2D g, final EditableImageRenderer imageRenderer)
              {
                label.setBounds(imageRenderer.getBounds());
                label.paint(g);
              }
          };

//        final OverlaidPanel overlay = new OverlaidPanel();
//        overlay.setLayout(new BorderLayout());
//        overlay.add(label, BorderLayout.CENTER);

        imageRenderer.addOverlay(overlay);
        imageRenderer.repaint(); // FIXME: should not be needed

        // A SwingWorker would be good here
        final var loaderThread = new Thread(() ->
          {
            try
              {
                final var image = EditableImage.create(new ReadOp(input));

                SwingUtilities.invokeLater(() ->
                                            {
                                              imageRenderer.setImage(image);
                                              imageRenderer.removeOverlay(overlay);
                                              final var hMargin = image.getWidth() / 4;
                                              final var vMargin = image.getHeight() / 4;
                                              imageRenderer.setMargin(new Insets(vMargin, hMargin, vMargin, hMargin));
                                              onImageLoaded(image);
                                            });
              }
            catch (final Throwable e)
              {
                SwingUtilities.invokeLater(() ->
                                            {
                                              label.setText(e.toString());
                                              imageRenderer.repaint(); // FIXME: should not be needed
should not be needed
// imageRenderer.removeOverlay(overlay); e.printStackTrace(); final var message = "<html>Cannot load the image.<br>An Internet connection is required.</html>"; final var title = "Error"; JOptionPane.showMessageDialog(AbstractViewerPanel.this, message, title, JOptionPane.ERROR_MESSAGE); }); } }); loaderThread.start(); } /******************************************************************************************************************* * * ******************************************************************************************************************/ protected void onImageLoaded (final EditableImage image) { } }]]></codefragment> </duplication> <duplication lines="19" tokens="141"> <file column="72" endcolumn="22" endline="507" line="489" path="/var/jenkins_home/jobs/Mistral_Metrics/workspace/modules/Core/src/main/java/it/tidalwave/image/java2d/Java2DUtils.java"/> <file column="71" endcolumn="22" endline="538" line="520" path="/var/jenkins_home/jobs/Mistral_Metrics/workspace/modules/Core/src/main/java/it/tidalwave/image/java2d/Java2DUtils.java"/> <codefragment><![CDATA[ private static String toString (final SinglePixelPackedSampleModel sampleModel) { final var buffer = new StringBuilder(); buffer.append(sampleModel.getClass().getName()); buffer.append("[width: "); buffer.append(sampleModel.getWidth()); buffer.append(", height: "); buffer.append(sampleModel.getHeight()); buffer.append(", numBands: "); buffer.append(sampleModel.getNumBands()); buffer.append(", dataType: "); buffer.append(sampleModel.getDataType()); buffer.append(", scanlineStride: "); buffer.append(sampleModel.getScanlineStride()); buffer.append(", transferType: "); buffer.append(sampleModel.getTransferType()); buffer.append(", numDataElements: "); buffer.append(sampleModel.getNumDataElements()); buffer.append(", bitMasks: ");]]></codefragment> </duplication> </pmd-cpd>