diff options
author | Keiji Ariyama <keiji_ariyama@c-lis.co.jp> | 2011-01-23 03:33:45 +0900 |
---|---|---|
committer | Keiji Ariyama <keiji_ariyama@c-lis.co.jp> | 2011-01-30 03:02:58 +0900 |
commit | b2dd2b30115b24d42806f891856b6a032a97ab81 (patch) | |
tree | ab7151d702a48f16ddf6576d879b9e48e5e855cc /draw9patch | |
parent | 3a6b7dce85229abeb836605102913081caa078e1 (diff) | |
download | sdk-b2dd2b30115b24d42806f891856b6a032a97ab81.zip sdk-b2dd2b30115b24d42806f891856b6a032a97ab81.tar.gz sdk-b2dd2b30115b24d42806f891856b6a032a97ab81.tar.bz2 |
Fixes problem in "draw9patch tool".
If a big PNG image will be loading, HelpPanel hides ImageView.
This patch fix that problem.
Change-Id: I615705849b475e5b88daae7bef2af92cb5fa0657
Diffstat (limited to 'draw9patch')
-rw-r--r-- | draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java b/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java index 84b96a5..aac6145 100644 --- a/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java +++ b/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java @@ -30,6 +30,8 @@ import javax.swing.JFileChooser; import javax.swing.JSplitPane; import javax.swing.JButton; import javax.swing.border.EmptyBorder; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; import javax.swing.event.ChangeListener; import javax.swing.event.ChangeEvent; import java.awt.image.BufferedImage; @@ -697,7 +699,25 @@ class ImageEditorPanel extends JPanel { setOpaque(true); - setZoom(DEFAULT_ZOOM); + // Set dummy size. + // Exact size will be set by setZoom() in AncestorListener#ancestorMoved. + size = new Dimension(0, 0); + + addAncestorListener(new AncestorListener() { + @Override + public void ancestorRemoved(AncestorEvent event) { + } + @Override + public void ancestorMoved(AncestorEvent event) { + // Set exactly size. + viewer.setZoom(DEFAULT_ZOOM); + viewer.removeAncestorListener(this); + } + @Override + public void ancestorAdded(AncestorEvent event) { + } + }); + findPatches(); addMouseListener(new MouseAdapter() { @@ -843,7 +863,7 @@ class ImageEditorPanel extends JPanel { } int left = (getWidth() - size.width) / 2; - int top = (helpPanel.getHeight() + getHeight() - size.height) / 2; + int top = helpPanel.getHeight() + (getHeight() - size.height) / 2; x = (x - left) / zoom; y = (y - top) / zoom; @@ -869,7 +889,7 @@ class ImageEditorPanel extends JPanel { lastPositionY = y; int left = (getWidth() - size.width) / 2; - int top = (helpPanel.getHeight() + getHeight() - size.height) / 2; + int top = helpPanel.getHeight() + (getHeight() - size.height) / 2; x = (x - left) / zoom; y = (y - top) / zoom; @@ -903,7 +923,7 @@ class ImageEditorPanel extends JPanel { @Override protected void paintComponent(Graphics g) { int x = (getWidth() - size.width) / 2; - int y = (helpPanel.getHeight() + getHeight() - size.height) / 2; + int y = helpPanel.getHeight() + (getHeight() - size.height) / 2; Graphics2D g2 = (Graphics2D) g.create(); g2.setColor(BACK_COLOR); @@ -1008,7 +1028,11 @@ class ImageEditorPanel extends JPanel { int height = image.getHeight(); zoom = value; - size = new Dimension(width * zoom, height * zoom); + if (size.height == 0 || (getHeight() - size.height) == 0) { + size = new Dimension(width * zoom, height * zoom + helpPanel.getHeight()); + } else { + size = new Dimension(width * zoom, height * zoom); + } setSize(size); ImageEditorPanel.this.validate(); |