aboutsummaryrefslogtreecommitdiffstats
path: root/draw9patch/src
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-05 14:34:30 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-05 14:34:30 -0800
commit81e838f82b1f61e9fd6cdb4cb8121d67498417f8 (patch)
tree4391b25fab1662c549aee09937939fd92bb0e7f4 /draw9patch/src
parent55a2c71f27d3e0b8344597c7f281e687cb7aeb1b (diff)
downloadsdk-81e838f82b1f61e9fd6cdb4cb8121d67498417f8.zip
sdk-81e838f82b1f61e9fd6cdb4cb8121d67498417f8.tar.gz
sdk-81e838f82b1f61e9fd6cdb4cb8121d67498417f8.tar.bz2
auto import from //depot/cupcake/@136594
Diffstat (limited to 'draw9patch/src')
-rw-r--r--draw9patch/src/com/android/draw9patch/Application.java5
-rw-r--r--draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java13
-rw-r--r--draw9patch/src/com/android/draw9patch/ui/MainFrame.java14
3 files changed, 24 insertions, 8 deletions
diff --git a/draw9patch/src/com/android/draw9patch/Application.java b/draw9patch/src/com/android/draw9patch/Application.java
index c7c6aaf..68c792a 100644
--- a/draw9patch/src/com/android/draw9patch/Application.java
+++ b/draw9patch/src/com/android/draw9patch/Application.java
@@ -40,11 +40,12 @@ public class Application {
}
}
- public static void main(String... args) {
+ public static void main(final String... args) {
initUserInterface();
SwingUtilities.invokeLater(new Runnable() {
public void run() {
- MainFrame frame = new MainFrame();
+ String arg = args.length > 0 ? args[0] : null;
+ MainFrame frame = new MainFrame(arg);
frame.setDefaultCloseOperation(MainFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
diff --git a/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java b/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java
index 86c801f..6901c98 100644
--- a/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java
+++ b/draw9patch/src/com/android/draw9patch/ui/ImageEditorPanel.java
@@ -651,6 +651,7 @@ class ImageEditorPanel extends JPanel {
private int lastPositionX;
private int lastPositionY;
+ private int currentButton;
private boolean showCursor;
private JLabel helpLabel;
@@ -687,16 +688,20 @@ class ImageEditorPanel extends JPanel {
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent event) {
- paint(event.getX(), event.getY(), event.isShiftDown() ? MouseEvent.BUTTON3 :
- event.getButton());
+ // Store the button here instead of retrieving it again in MouseDragged
+ // below, because on linux, calling MouseEvent.getButton() for the drag
+ // event returns 0, which appears to be technically correct (no button
+ // changed state).
+ currentButton = event.isShiftDown() ? MouseEvent.BUTTON3 : event.getButton();
+ paint(event.getX(), event.getY(), currentButton);
}
});
addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent event) {
if (!checkLockedRegion(event.getX(), event.getY())) {
- paint(event.getX(), event.getY(), event.isShiftDown() ? MouseEvent.BUTTON3 :
- event.getButton());
+ // use the stored button, see note above
+ paint(event.getX(), event.getY(), currentButton);
}
}
diff --git a/draw9patch/src/com/android/draw9patch/ui/MainFrame.java b/draw9patch/src/com/android/draw9patch/ui/MainFrame.java
index 9ffd93e..d5b6409 100644
--- a/draw9patch/src/com/android/draw9patch/ui/MainFrame.java
+++ b/draw9patch/src/com/android/draw9patch/ui/MainFrame.java
@@ -40,14 +40,24 @@ public class MainFrame extends JFrame {
private JMenuItem saveMenuItem;
private ImageEditorPanel imageEditor;
- public MainFrame() throws HeadlessException {
+ public MainFrame(String path) throws HeadlessException {
super("Draw 9-patch");
buildActions();
buildMenuBar();
buildContent();
- showOpenFilePanel();
+ if (path == null) {
+ showOpenFilePanel();
+ } else {
+ try {
+ File file = new File(path);
+ BufferedImage img = GraphicsUtilities.loadCompatibleImage(file.toURI().toURL());
+ showImageEditor(img, file.getAbsolutePath());
+ } catch (Exception ex) {
+ showOpenFilePanel();
+ }
+ }
// pack();
setSize(1024, 600);