draw9patch

16:35:26.646 INFO  jd.cli.Main - Decompiling draw9patch.jar
package com.android.draw9patch;

import com.android.draw9patch.ui.MainFrame;

final class Application$1
  implements Runnable
{
  Application$1(String[] paramArrayOfString) {}
  
  public void run()
  {
    String arg = val$args.length > 0 ? val$args[0] : null;
    MainFrame frame = new MainFrame(arg);
    frame.setDefaultCloseOperation(3);
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.Application.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch;

import com.android.draw9patch.ui.MainFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class Application
{
  private static void initUserInterface()
  {
    System.setProperty("apple.laf.useScreenMenuBar", "true");
    System.setProperty("com.apple.mrj.application.apple.menu.about.name", "Draw 9-patch");
    try
    {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    }
    catch (ClassNotFoundException e)
    {
      e.printStackTrace();
    }
    catch (InstantiationException e)
    {
      e.printStackTrace();
    }
    catch (IllegalAccessException e)
    {
      e.printStackTrace();
    }
    catch (UnsupportedLookAndFeelException e)
    {
      e.printStackTrace();
    }
  }
  
  public static void main(String... args)
  {
    initUserInterface();
    SwingUtilities.invokeLater(new Runnable()
    {
      public void run()
      {
        String arg = val$args.length > 0 ? val$args[0] : null;
        MainFrame frame = new MainFrame(arg);
        frame.setDefaultCloseOperation(3);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    });
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.Application
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.graphics;

import java.awt.Graphics;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.Raster;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

public class GraphicsUtilities
{
  public static BufferedImage loadCompatibleImage(URL resource)
    throws IOException
  {
    BufferedImage image = ImageIO.read(resource);
    if (image == null) {
      return null;
    }
    return toCompatibleImage(image);
  }
  
  public static BufferedImage createCompatibleImage(int width, int height)
  {
    return getGraphicsConfiguration().createCompatibleImage(width, height);
  }
  
  public static BufferedImage toCompatibleImage(BufferedImage image)
  {
    if (isHeadless()) {
      return image;
    }
    ColorModel colorModel = image.getColorModel();
    if ((colorModel != null) && (colorModel.equals(getGraphicsConfiguration().getColorModel()))) {
      return image;
    }
    BufferedImage compatibleImage = getGraphicsConfiguration().createCompatibleImage(image.getWidth(), image.getHeight(), image.getTransparency());
    
    Graphics g = compatibleImage.getGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    
    return compatibleImage;
  }
  
  public static BufferedImage createCompatibleImage(BufferedImage image, int width, int height)
  {
    return getGraphicsConfiguration().createCompatibleImage(width, height, image.getTransparency());
  }
  
  private static GraphicsConfiguration getGraphicsConfiguration()
  {
    GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    return environment.getDefaultScreenDevice().getDefaultConfiguration();
  }
  
  private static boolean isHeadless()
  {
    return GraphicsEnvironment.isHeadless();
  }
  
  public static BufferedImage createTranslucentCompatibleImage(int width, int height)
  {
    return getGraphicsConfiguration().createCompatibleImage(width, height, 3);
  }
  
  public static int[] getPixels(BufferedImage img, int x, int y, int w, int h, int[] pixels)
  {
    if ((w == 0) || (h == 0)) {
      return new int[0];
    }
    if (pixels == null) {
      pixels = new int[w * h];
    } else if (pixels.length < w * h) {
      throw new IllegalArgumentException("Pixels array must have a length >= w * h");
    }
    int imageType = img.getType();
    if ((imageType == 2) || (imageType == 1))
    {
      Raster raster = img.getRaster();
      return (int[])raster.getDataElements(x, y, w, h, pixels);
    }
    return img.getRGB(x, y, w, h, pixels, 0, w);
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.graphics.GraphicsUtilities
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import com.android.draw9patch.graphics.GraphicsUtilities;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class CorruptPatch
{
  public static List<Rectangle> findBadPatches(BufferedImage image, PatchInfo patchInfo)
  {
    List<Rectangle> corruptedPatches = new ArrayList();
    for (Rectangle patch : patches) {
      if (corruptPatch(image, patch)) {
        corruptedPatches.add(patch);
      }
    }
    for (Rectangle patch : horizontalPatches) {
      if (corruptHorizontalPatch(image, patch)) {
        corruptedPatches.add(patch);
      }
    }
    for (Rectangle patch : verticalPatches) {
      if (corruptVerticalPatch(image, patch)) {
        corruptedPatches.add(patch);
      }
    }
    return corruptedPatches;
  }
  
  private static boolean corruptPatch(BufferedImage image, Rectangle patch)
  {
    int[] pixels = GraphicsUtilities.getPixels(image, x, y, width, height, null);
    if (pixels.length > 0)
    {
      int reference = pixels[0];
      for (int pixel : pixels) {
        if (pixel != reference) {
          return true;
        }
      }
    }
    return false;
  }
  
  private static boolean corruptHorizontalPatch(BufferedImage image, Rectangle patch)
  {
    int[] reference = new int[height];
    int[] column = new int[height];
    reference = GraphicsUtilities.getPixels(image, x, y, 1, height, reference);
    for (int i = 1; i < width; i++)
    {
      column = GraphicsUtilities.getPixels(image, x + i, y, 1, height, column);
      if (!Arrays.equals(reference, column)) {
        return true;
      }
    }
    return false;
  }
  
  private static boolean corruptVerticalPatch(BufferedImage image, Rectangle patch)
  {
    int[] reference = new int[width];
    int[] row = new int[width];
    reference = GraphicsUtilities.getPixels(image, x, y, width, 1, reference);
    for (int i = 1; i < height; i++)
    {
      row = GraphicsUtilities.getPixels(image, x, y + i, width, 1, row);
      if (!Arrays.equals(reference, row)) {
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.CorruptPatch
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Paint;
import java.awt.Rectangle;
import javax.swing.JPanel;

class GradientPanel
  extends JPanel
{
  private static final int DARK_BLUE = 2107191;
  
  GradientPanel()
  {
    super(new BorderLayout());
  }
  
  protected void paintComponent(Graphics g)
  {
    Graphics2D g2 = (Graphics2D)g;
    Rectangle clip = g2.getClipBounds();
    Paint paint = g2.getPaint();
    
    g2.setPaint(new GradientPaint(0.0F, getHeight() * 0.22F, new Color(2107191), 0.0F, getHeight() * 0.9F, Color.BLACK));
    
    g2.fillRect(x, y, width, height);
    
    g2.setPaint(paint);
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.GradientPanel
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;

class ImageEditorPanel$1
  implements AncestorListener
{
  ImageEditorPanel$1(ImageEditorPanel paramImageEditorPanel) {}
  
  public void ancestorAdded(AncestorEvent event) {}
  
  public void ancestorRemoved(AncestorEvent event) {}
  
  public void ancestorMoved(AncestorEvent event)
  {
    this$0.removeAncestorListener(this);
    ImageEditorPanel.access$000(this$0);
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import javax.swing.JLabel;

class ImageEditorPanel$2
  implements ImageViewer.StatusBar
{
  ImageEditorPanel$2(ImageEditorPanel paramImageEditorPanel) {}
  
  public void setPointerLocation(int x, int y)
  {
    ImageEditorPanel.access$100(this$0).setText(x + " px");
    ImageEditorPanel.access$200(this$0).setText(y + " px");
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

class ImageEditorPanel$3
  implements ChangeListener
{
  ImageEditorPanel$3(ImageEditorPanel paramImageEditorPanel) {}
  
  public void stateChanged(ChangeEvent evt)
  {
    ImageEditorPanel.access$300(this$0).setZoom(((JSlider)evt.getSource()).getValue());
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

class ImageEditorPanel$4
  implements ChangeListener
{
  ImageEditorPanel$4(ImageEditorPanel paramImageEditorPanel) {}
  
  public void stateChanged(ChangeEvent evt)
  {
    ImageEditorPanel.access$400(this$0).setScale(((JSlider)evt.getSource()).getValue() / 100.0F);
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel.4
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;

class ImageEditorPanel$5
  implements ActionListener
{
  ImageEditorPanel$5(ImageEditorPanel paramImageEditorPanel) {}
  
  public void actionPerformed(ActionEvent event)
  {
    ImageEditorPanel.access$300(this$0).setLockVisible(((JCheckBox)event.getSource()).isSelected());
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel.5
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;

class ImageEditorPanel$6
  implements ActionListener
{
  ImageEditorPanel$6(ImageEditorPanel paramImageEditorPanel) {}
  
  public void actionPerformed(ActionEvent event)
  {
    ImageEditorPanel.access$300(this$0).setPatchesVisible(((JCheckBox)event.getSource()).isSelected());
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel.6
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JCheckBox;

class ImageEditorPanel$7
  implements ActionListener
{
  ImageEditorPanel$7(ImageEditorPanel paramImageEditorPanel) {}
  
  public void actionPerformed(ActionEvent event)
  {
    ImageEditorPanel.access$400(this$0).setPaddingVisible(((JCheckBox)event.getSource()).isSelected());
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel.7
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import com.android.draw9patch.graphics.GraphicsUtilities;
import java.awt.BorderLayout;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.TexturePaint;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Rectangle2D.Double;
import java.awt.image.BufferedImage;
import java.awt.image.RenderedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.swing.Box;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JSplitPane;
import javax.swing.JViewport;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class ImageEditorPanel
  extends JPanel
{
  private static final String EXTENSION_9PATCH = ".9.png";
  private String name;
  private BufferedImage image;
  private boolean is9Patch;
  private ImageViewer viewer;
  private StretchesViewer stretchesViewer;
  private JLabel xLabel;
  private JLabel yLabel;
  private TexturePaint texture;
  private JSlider zoomSlider;
  
  public ImageEditorPanel(MainFrame mainFrame, BufferedImage image, String name)
  {
    this.image = image;
    this.name = name;
    if (mainFrame != null) {
      setTransferHandler(new ImageTransferHandler(mainFrame));
    }
    setOpaque(false);
    setLayout(new BorderLayout());
    
    loadSupport();
    buildImageViewer();
    buildStatusPanel();
    
    checkImage();
    
    addAncestorListener(new AncestorListener()
    {
      public void ancestorAdded(AncestorEvent event) {}
      
      public void ancestorRemoved(AncestorEvent event) {}
      
      public void ancestorMoved(AncestorEvent event)
      {
        removeAncestorListener(this);
        ImageEditorPanel.this.synchronizeImageViewerZoomLevel();
      }
    });
  }
  
  private void synchronizeImageViewerZoomLevel()
  {
    zoomSlider.setValue(viewer.getZoom());
  }
  
  public ImageViewer getViewer()
  {
    return viewer;
  }
  
  private void loadSupport()
  {
    try
    {
      URL resource = getClass().getResource("/images/checker.png");
      BufferedImage checker = GraphicsUtilities.loadCompatibleImage(resource);
      texture = new TexturePaint(checker, new Rectangle2D.Double(0.0D, 0.0D, checker.getWidth(), checker.getHeight()));
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
  
  private void buildImageViewer()
  {
    viewer = new ImageViewer(this, texture, image, new ImageViewer.StatusBar()
    {
      public void setPointerLocation(int x, int y)
      {
        xLabel.setText(x + " px");
        yLabel.setText(y + " px");
      }
    });
    JSplitPane splitter = new JSplitPane();
    splitter.setContinuousLayout(true);
    splitter.setResizeWeight(0.8D);
    splitter.setBorder(null);
    
    JScrollPane scroller = new JScrollPane(viewer);
    scroller.setOpaque(false);
    scroller.setBorder(null);
    scroller.getViewport().setBorder(null);
    scroller.getViewport().setOpaque(false);
    
    splitter.setLeftComponent(scroller);
    splitter.setRightComponent(buildStretchesViewer());
    
    add(splitter);
  }
  
  private JComponent buildStretchesViewer()
  {
    stretchesViewer = new StretchesViewer(this, viewer, texture);
    JScrollPane scroller = new JScrollPane(stretchesViewer);
    scroller.setBorder(null);
    scroller.getViewport().setBorder(null);
    scroller.setHorizontalScrollBarPolicy(32);
    scroller.setVerticalScrollBarPolicy(22);
    return scroller;
  }
  
  private void buildStatusPanel()
  {
    JPanel status = new JPanel(new GridBagLayout());
    
    JLabel label = new JLabel();
    label.setText("Zoom: ");
    label.putClientProperty("JComponent.sizeVariant", "small");
    status.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0D, 0.0D, 22, 0, new Insets(0, 6, 0, 0), 0, 0));
    
    label = new JLabel();
    label.setText("100%");
    label.putClientProperty("JComponent.sizeVariant", "small");
    status.add(label, new GridBagConstraints(1, 0, 1, 1, 0.0D, 0.0D, 22, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    zoomSlider = new JSlider(1, 16, 8);
    
    zoomSlider.setSnapToTicks(true);
    zoomSlider.putClientProperty("JComponent.sizeVariant", "small");
    zoomSlider.addChangeListener(new ChangeListener()
    {
      public void stateChanged(ChangeEvent evt)
      {
        viewer.setZoom(((JSlider)evt.getSource()).getValue());
      }
    });
    status.add(zoomSlider, new GridBagConstraints(2, 0, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    JLabel maxZoomLabel = new JLabel();
    maxZoomLabel.putClientProperty("JComponent.sizeVariant", "small");
    maxZoomLabel.setText("800%");
    status.add(maxZoomLabel, new GridBagConstraints(3, 0, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    label = new JLabel();
    label.setText("Patch scale: ");
    label.putClientProperty("JComponent.sizeVariant", "small");
    status.add(label, new GridBagConstraints(0, 1, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 6, 0, 0), 0, 0));
    
    label = new JLabel();
    label.setText("2x");
    label.putClientProperty("JComponent.sizeVariant", "small");
    status.add(label, new GridBagConstraints(1, 1, 1, 1, 0.0D, 0.0D, 22, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    JSlider jSlider = new JSlider(200, 600, 200);
    jSlider.setSnapToTicks(true);
    jSlider.putClientProperty("JComponent.sizeVariant", "small");
    jSlider.addChangeListener(new ChangeListener()
    {
      public void stateChanged(ChangeEvent evt)
      {
        stretchesViewer.setScale(((JSlider)evt.getSource()).getValue() / 100.0F);
      }
    });
    status.add(jSlider, new GridBagConstraints(2, 1, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    maxZoomLabel = new JLabel();
    maxZoomLabel.putClientProperty("JComponent.sizeVariant", "small");
    maxZoomLabel.setText("6x");
    status.add(maxZoomLabel, new GridBagConstraints(3, 1, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    JCheckBox showLock = new JCheckBox("Show lock");
    showLock.setOpaque(false);
    showLock.setSelected(false);
    showLock.putClientProperty("JComponent.sizeVariant", "small");
    showLock.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent event)
      {
        viewer.setLockVisible(((JCheckBox)event.getSource()).isSelected());
      }
    });
    status.add(showLock, new GridBagConstraints(4, 0, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 12, 0, 0), 0, 0));
    
    JCheckBox showPatches = new JCheckBox("Show patches");
    showPatches.setOpaque(false);
    showPatches.putClientProperty("JComponent.sizeVariant", "small");
    showPatches.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent event)
      {
        viewer.setPatchesVisible(((JCheckBox)event.getSource()).isSelected());
      }
    });
    status.add(showPatches, new GridBagConstraints(4, 1, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 12, 0, 0), 0, 0));
    
    JCheckBox showPadding = new JCheckBox("Show content");
    showPadding.setOpaque(false);
    showPadding.putClientProperty("JComponent.sizeVariant", "small");
    showPadding.addActionListener(new ActionListener()
    {
      public void actionPerformed(ActionEvent event)
      {
        stretchesViewer.setPaddingVisible(((JCheckBox)event.getSource()).isSelected());
      }
    });
    status.add(showPadding, new GridBagConstraints(5, 0, 1, 1, 0.0D, 0.0D, 21, 0, new Insets(0, 12, 0, 0), 0, 0));
    
    status.add(Box.createHorizontalGlue(), new GridBagConstraints(6, 0, 1, 1, 1.0D, 1.0D, 21, 1, new Insets(0, 0, 0, 0), 0, 0));
    
    label = new JLabel("X: ");
    label.putClientProperty("JComponent.sizeVariant", "small");
    status.add(label, new GridBagConstraints(7, 0, 1, 1, 0.0D, 0.0D, 22, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    xLabel = new JLabel("0px");
    xLabel.putClientProperty("JComponent.sizeVariant", "small");
    status.add(xLabel, new GridBagConstraints(8, 0, 1, 1, 0.0D, 0.0D, 22, 0, new Insets(0, 0, 0, 6), 0, 0));
    
    label = new JLabel("Y: ");
    label.putClientProperty("JComponent.sizeVariant", "small");
    status.add(label, new GridBagConstraints(7, 1, 1, 1, 0.0D, 0.0D, 22, 0, new Insets(0, 0, 0, 0), 0, 0));
    
    yLabel = new JLabel("0px");
    yLabel.putClientProperty("JComponent.sizeVariant", "small");
    status.add(yLabel, new GridBagConstraints(8, 1, 1, 1, 0.0D, 0.0D, 22, 0, new Insets(0, 0, 0, 6), 0, 0));
    
    add(status, "South");
  }
  
  private void checkImage()
  {
    is9Patch = name.endsWith(".9.png");
    if (!is9Patch) {
      convertTo9Patch();
    } else {
      ensure9Patch();
    }
  }
  
  private void ensure9Patch()
  {
    int width = image.getWidth();
    int height = image.getHeight();
    for (int i = 0; i < width; i++)
    {
      int pixel = image.getRGB(i, 0);
      if ((pixel != 0) && (pixel != -16777216) && (pixel != -65536)) {
        image.setRGB(i, 0, 0);
      }
      pixel = image.getRGB(i, height - 1);
      if ((pixel != 0) && (pixel != -16777216) && (pixel != -65536)) {
        image.setRGB(i, height - 1, 0);
      }
    }
    for (int i = 0; i < height; i++)
    {
      int pixel = image.getRGB(0, i);
      if ((pixel != 0) && (pixel != -16777216) && (pixel != -65536)) {
        image.setRGB(0, i, 0);
      }
      pixel = image.getRGB(width - 1, i);
      if ((pixel != 0) && (pixel != -16777216) && (pixel != -65536)) {
        image.setRGB(width - 1, i, 0);
      }
    }
  }
  
  private void convertTo9Patch()
  {
    BufferedImage buffer = GraphicsUtilities.createTranslucentCompatibleImage(image.getWidth() + 2, image.getHeight() + 2);
    
    Graphics2D g2 = buffer.createGraphics();
    g2.drawImage(image, 1, 1, null);
    g2.dispose();
    
    image = buffer;
    viewer.setImage(image);
    name = (name.substring(0, name.lastIndexOf('.')) + ".9.png");
  }
  
  File chooseSaveFile()
  {
    if (is9Patch) {
      return new File(name);
    }
    JFileChooser chooser = new JFileChooser(name.substring(0, name.lastIndexOf(File.separatorChar)));
    
    chooser.setFileFilter(new PngFileFilter());
    int choice = chooser.showSaveDialog(this);
    if (choice == 0)
    {
      File file = chooser.getSelectedFile();
      if (!file.getAbsolutePath().endsWith(".9.png"))
      {
        String path = file.getAbsolutePath();
        if (path.endsWith(".png")) {
          path = path.substring(0, path.lastIndexOf(".png")) + ".9.png";
        } else {
          path = path + ".9.png";
        }
        name = path;
        is9Patch = true;
        return new File(path);
      }
      is9Patch = true;
      return file;
    }
    return null;
  }
  
  RenderedImage getImage()
  {
    return image;
  }
  
  public void dispose()
  {
    if (viewer != null) {
      viewer.dispose();
    }
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageEditorPanel
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.SwingWorker;
import javax.swing.TransferHandler;
import javax.swing.TransferHandler.TransferSupport;

class ImageTransferHandler
  extends TransferHandler
{
  private final MainFrame mainFrame;
  
  ImageTransferHandler(MainFrame mainFrame)
  {
    this.mainFrame = mainFrame;
  }
  
  public boolean importData(JComponent component, Transferable transferable)
  {
    try
    {
      for (DataFlavor flavor : transferable.getTransferDataFlavors())
      {
        if (flavor.isFlavorJavaFileListType())
        {
          Object data = transferable.getTransferData(DataFlavor.javaFileListFlavor);
          
          File file = (File)((List)data).get(0);
          mainFrame.open(file).execute();
          return true;
        }
        if ((flavor.isFlavorTextType()) && 
          (flavor.getRepresentationClass() == String.class))
        {
          String mime = flavor.getMimeType();
          DataFlavor flave = new DataFlavor(mime);
          Object data = transferable.getTransferData(flave);
          String path = convertPath(data.toString());
          mainFrame.open(new File(path)).execute();
          return true;
        }
      }
    }
    catch (UnsupportedFlavorException e) {}catch (MalformedURLException e)
    {
      e.printStackTrace();
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
    catch (Exception e)
    {
      e.printStackTrace();
    }
    return false;
  }
  
  private static String convertPath(String path)
  {
    if (path.startsWith("file://")) {
      path = path.substring("file://".length());
    }
    if (path.indexOf('\n') != -1) {
      path = path.substring(0, path.indexOf('\n'));
    }
    if (path.indexOf('\r') != -1) {
      path = path.substring(0, path.indexOf('\r'));
    }
    return path;
  }
  
  public boolean canImport(TransferHandler.TransferSupport support)
  {
    boolean isCopySupported = (0x1 & support.getSourceDropActions()) == 1;
    if (!isCopySupported) {
      return false;
    }
    for (DataFlavor flavor : support.getDataFlavors()) {
      if ((flavor.isFlavorJavaFileListType()) || (flavor.isFlavorTextType()))
      {
        support.setDropAction(1);
        return true;
      }
    }
    return false;
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageTransferHandler
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;

class ImageViewer$1
  implements AncestorListener
{
  ImageViewer$1(ImageViewer paramImageViewer) {}
  
  public void ancestorRemoved(AncestorEvent event) {}
  
  public void ancestorMoved(AncestorEvent event)
  {
    this$0.removeAncestorListener(this);
    ImageViewer.access$000(this$0);
  }
  
  public void ancestorAdded(AncestorEvent event) {}
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.1
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.Cursor;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;

class ImageViewer$2
  extends MouseAdapter
{
  ImageViewer$2(ImageViewer paramImageViewer) {}
  
  public void mousePressed(MouseEvent event)
  {
    ImageViewer.access$100(this$0, event);
    
    int x = ImageViewer.access$200(this$0, event.getX());
    int y = ImageViewer.access$300(this$0, event.getY());
    
    ImageViewer.access$400(this$0, x, y);
    if (ImageViewer.access$500(this$0) == ImageViewer.DrawMode.PATCH)
    {
      ImageViewer.access$600(this$0, x, y);
    }
    else
    {
      ImageViewer.access$700(this$0).clear();
      this$0.setCursor(Cursor.getDefaultCursor());
      this$0.repaint();
    }
  }
  
  public void mouseReleased(MouseEvent event)
  {
    int x = ImageViewer.access$200(this$0, event.getX());
    int y = ImageViewer.access$300(this$0, event.getY());
    
    ImageViewer.access$800(this$0);
    ImageViewer.access$900(this$0, x, y);
    
    ImageViewer.access$1000(this$0);
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.2
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;

class ImageViewer$3
  extends MouseMotionAdapter
{
  ImageViewer$3(ImageViewer paramImageViewer) {}
  
  public void mouseDragged(MouseEvent event)
  {
    int x = ImageViewer.access$200(this$0, event.getX());
    int y = ImageViewer.access$300(this$0, event.getY());
    if (!ImageViewer.access$1100(this$0, x, y)) {
      ImageViewer.access$1200(this$0, x, y);
    }
    ImageViewer.access$1300(this$0, x, y);
  }
  
  public void mouseMoved(MouseEvent event)
  {
    int x = ImageViewer.access$200(this$0, event.getX());
    int y = ImageViewer.access$300(this$0, event.getY());
    
    ImageViewer.access$1100(this$0, x, y);
    
    ImageViewer.access$1400(this$0, x, y);
    this$0.repaint();
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.3
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.util.List;

class ImageViewer$4
  extends ComponentAdapter
{
  ImageViewer$4(ImageViewer paramImageViewer) {}
  
  public void componentResized(ComponentEvent e)
  {
    ImageViewer.access$700(this$0).clear();
    ImageViewer.access$1500(this$0);
    this$0.repaint();
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.4
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.AWTEvent;
import java.awt.event.AWTEventListener;
import java.awt.event.KeyEvent;

class ImageViewer$5
  implements AWTEventListener
{
  ImageViewer$5(ImageViewer paramImageViewer) {}
  
  public void eventDispatched(AWTEvent event)
  {
    ImageViewer.access$1600(this$0, (KeyEvent)event);
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.5
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

class ImageViewer$6
  implements ActionListener
{
  ImageViewer$6(ImageViewer paramImageViewer) {}
  
  public void actionPerformed(ActionEvent event)
  {
    if (!ImageViewer.access$1700(this$0))
    {
      ImageViewer.access$1802(this$0, CorruptPatch.findBadPatches(ImageViewer.access$1900(this$0), ImageViewer.access$2000(this$0)));
      
      ImageViewer.access$2100(this$0).setText("Hide bad patches");
    }
    else
    {
      ImageViewer.access$2100(this$0).setText("Show bad patches");
      ImageViewer.access$1802(this$0, null);
    }
    this$0.repaint();
    ImageViewer.access$1702(this$0, !ImageViewer.access$1700(this$0));
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.6
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

class ImageViewer$7 {}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.7
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

 enum ImageViewer$DrawMode
{
  PATCH,  LAYOUT_BOUND,  ERASE;
  
  private ImageViewer$DrawMode() {}
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.DrawMode
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

 enum ImageViewer$Edge
{
  START,  END,  NONE;
  
  private ImageViewer$Edge() {}
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.Edge
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

public abstract interface ImageViewer$PatchUpdateListener
{
  public abstract void patchesUpdated();
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.PatchUpdateListener
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

public abstract interface ImageViewer$StatusBar
{
  public abstract void setPointerLocation(int paramInt1, int paramInt2);
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.StatusBar
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

 enum ImageViewer$UpdateRegion
{
  LEFT_PATCH,  TOP_PATCH,  RIGHT_PADDING,  BOTTOM_PADDING;
  
  private ImageViewer$UpdateRegion() {}
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.UpdateRegion
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

class ImageViewer$UpdateRegionInfo
{
  public final ImageViewer.UpdateRegion region;
  public final Pair<Integer> segment;
  
  private ImageViewer$UpdateRegionInfo(ImageViewer.UpdateRegion region, Pair<Integer> segment)
  {
    this.region = region;
    this.segment = segment;
  }
}

/* Location:
 * Qualified Name:     com.android.draw9patch.ui.ImageViewer.UpdateRegionInfo
 * Java Class Version: 6 (50.0)
 * JD-Core Version:    0.7.1
 */
package com.android.draw9patch.ui;

import java.awt.AWTEvent;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.Shape;
import java.awt.TexturePaint;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.Area;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;
import java.awt.geom.RoundRectangle2D.Float;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
import javax.swing.border.EmptyBorder;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;

public class ImageViewer
  extends JComponent
{
  private final Color CORRUPTED_COLOR = new Color(1.0F, 0.0F, 0.0F, 0.7F);
  private final Color LOCK_COLOR = new Color(0.0F, 0.0F, 0.0F, 0.7F);
  private final Color STRIPES_COLOR = new Color(1.0F, 0.0F, 0.0F, 0.5F);
  private final Color BACK_COLOR = UIManager.getColor("Panel.background").darker();
  private final Color HELP_COLOR = new Color(16777185);
  private final Color PATCH_COLOR = new Color(1.0F, 0.37F, 0.99F, 0.5F);
  private final Color PATCH_ONEWAY_COLOR = new Color(0.37F, 1.0F, 0.37F, 0.5F);
  private final Color HIGHLIGHT_REGION_COLOR = new Color(0.5F, 0.5F, 0.5F, 0.5F);
  private static final float STRIPES_WIDTH = 4.0F;
  private static final double STRIPES_SPACING = 6.0D;
  private static final int STRIPES_ANGLE = 45;
  private static final float IDEAL_IMAGE_FRACTION_OF_WINDOW = 0.7F;
  public static final int DEFAULT_ZOOM = 8;
  public static final int MIN_ZOOM = 1;
  public static final int MAX_ZOOM = 16;
  private final AWTEventListener mAwtKeyEventListener;
  private int zoom = 8;
  private boolean showPatches;
  private boolean showLock = false;
  private final TexturePaint texture;
  private final Container container;
  private final StatusBar statusBar;
  private final Dimension size;
  private boolean locked;
  private int lastPositionX;
  private int lastPositionY;
  private boolean showCursor;
  private JLabel helpLabel;
  private boolean eraseMode;
  private JButton checkButton;
  private List<Rectangle> corruptedPatches;
  private boolean showBadPatches;
  private JPanel helpPanel;
  private boolean drawingLine;
  private int lineFromX;
  private int lineFromY;
  private int lineToX;
  private int lineToY;
  private boolean showDrawingLine;
  private final List<Rectangle> hoverHighlightRegions = new ArrayList();
  private String toolTipText;
  private boolean isEditMode;
  private UpdateRegion editRegion;
  private final Pair<Integer> editSegment = new Pair(Integer.valueOf(0), Integer.valueOf(0));
  private final List<Rectangle> editHighlightRegions = new ArrayList();
  private Rectangle editPatchRegion = new Rectangle();
  private BufferedImage image;
  private PatchInfo patchInfo;
  
  private static enum DrawMode
  {
    PATCH,  LAYOUT_BOUND,  ERASE;
    
    private DrawMode() {}
  }
  
  private DrawMode currentMode = DrawMode.PATCH;
  private static final int EDGE_DELTA = 1;
  
  ImageViewer(Container container, TexturePaint texture, BufferedImage image, StatusBar statusBar)
  {
    this.container = container;
    this.texture = texture;
    this.image = image;
    this.statusBar = statusBar;
    
    setLayout(new GridBagLayout());
    helpPanel = new JPanel(new BorderLayout());
    helpPanel.setBorder(new EmptyBorder(0, 6, 0, 6));
    helpPanel.setBackground(HELP_COLOR);
    helpLabel = new JLabel("Press Shift to erase pixels. Press Control to draw layout bounds");
    
    helpLabel.putClientProperty("JComponent.sizeVariant", "small");
    
    helpLabel.setOpaque(true);
    helpLabel.setBackground(HELP_COLOR);
    helpPanel.add(helpLabel, "West");
    checkButton = new JButton("Show bad patches");
    checkButton.putClientProperty("JComponent.sizeVariant", "small");
    checkButton.putClientProperty("JButton.buttonType", "roundRect");
    helpPanel.add(checkButton, "East");
    
    add(helpPanel, new GridBagConstraints(0, 0, 1, 1, 1.0D, 1.0D, 23, 2, new Insets(0, 0, 0, 0), 0, 0));
    
    setOpaque(true);
    
    size = new Dimension(0, 0);
    
    addAncestorListener(new AncestorListener()
    {
      public void ancestorRemoved(AncestorEvent event) {}
      
      public void ancestorMoved(AncestorEvent event)
      {
        removeAncestorListener(this);
        ImageViewer.this.setDefaultZoom();
      }
      
      public void ancestorAdded(AncestorEvent event) {}
    });
    updatePatchInfo();
    
    addMouseListener(new MouseAdapter()
    {
      public void mousePressed(MouseEvent event)
      {
        ImageViewer.this.updateDrawMode(event);
        
        int x = ImageViewer.this.imageXCoordinate(event.getX());
        int y = ImageViewer.this.imageYCoordinate(event.getY());
        
        ImageViewer.this.startDrawingLine(x, y);
        if (currentMode == ImageViewer.DrawMode.PATCH)
        {
          ImageViewer.this.startEditingRegion(x, y);
        }
        else
        {
          hoverHighlightRegions.clear();
          setCursor(Cursor.getDefaultCursor());
          repaint();
        }
      }
      
      public void mouseReleased(MouseEvent event)
      {
        int x = ImageViewer.this.imageXCoordinate(event.getX());
        int y = ImageViewer.this.imageYCoordinate(event.getY());
        
        ImageViewer.this.endDrawingLine();
        ImageViewer.this.endEditingRegion(x, y);
        
        ImageViewer.this.resetDrawMode();
      }
    });
    addMouseMotionListener(new MouseMotionAdapter()
    {
      public void mouseDragged(MouseEvent event)
      {
        int x = ImageViewer.this.imageXCoordinate(event.getX());
        int y = ImageViewer.this.imageYCoordinate(event.getY());
        if (!ImageViewer.this.checkLockedRegion(x, y)) {
          ImageViewer.this.moveLine(x, y);
        }
        ImageViewer.this.updateEditRegion(x, y);
      }
      
      public void mouseMoved(MouseEvent event)
      {
        int x = ImageViewer.this.imageXCoordinate(event.getX());
        int y = ImageViewer.this.imageYCoordinate(event.getY());
        
        ImageViewer.this.checkLockedRegion(x, y);
        
        ImageViewer.this.updateHoverRegion(x, y);
        repa
1 2 3

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd