Home | History | Annotate | Download | only in ui
      1 package com.android.draw9patch.ui;
      2 
      3 import com.android.draw9patch.graphics.GraphicsUtilities;
      4 
      5 import javax.swing.JComponent;
      6 import java.awt.image.BufferedImage;
      7 import java.awt.Graphics;
      8 import java.io.IOException;
      9 import java.net.URL;/*
     10  * Copyright (C) 2008 The Android Open Source Project
     11  *
     12  * Licensed under the Apache License, Version 2.0 (the "License");
     13  * you may not use this file except in compliance with the License.
     14  * You may obtain a copy of the License at
     15  *
     16  *      http://www.apache.org/licenses/LICENSE-2.0
     17  *
     18  * Unless required by applicable law or agreed to in writing, software
     19  * distributed under the License is distributed on an "AS IS" BASIS,
     20  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     21  * See the License for the specific language governing permissions and
     22  * limitations under the License.
     23  */
     24 
     25 class OpenFilePanel extends JComponent {
     26     private BufferedImage dropHere;
     27 
     28     OpenFilePanel(MainFrame mainFrame) {
     29         setOpaque(false);
     30         loadSupportImage();
     31         setTransferHandler(new ImageTransferHandler(mainFrame));
     32     }
     33 
     34     private void loadSupportImage() {
     35         try {
     36             URL resource = getClass().getResource("/images/drop.png");
     37             dropHere = GraphicsUtilities.loadCompatibleImage(resource);
     38         } catch (IOException e) {
     39             e.printStackTrace();
     40         }
     41     }
     42 
     43     @Override
     44     protected void paintComponent(Graphics g) {
     45         int x = (getWidth() - dropHere.getWidth()) / 2;
     46         int y = (getHeight() - dropHere.getHeight()) / 2;
     47 
     48         g.drawImage(dropHere, x, y, null);
     49     }
     50 
     51 }
     52