Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/memoire/dja/DjaImage.java


1   /**
2    * @modification $Date: 2001/12/03 16:28:08 $
3    * @statut       unstable
4    * @file         DjaImage.java
5    * @version      0.36
6    * @author       Guillaume Desnoix
7    * @email        guillaume@desnoix.com
8    * @license      GNU General Public License 2 (GPL2)
9    * @copyright    1998-2001 Guillaume Desnoix
10   */
11  
12  package com.memoire.dja;
13  
14  import com.memoire.fu.*;
15  import com.memoire.dnd.*;
16  import com.memoire.bu.*;
17  import com.memoire.dja.*;
18  import com.memoire.mst.*;
19  
20  
21  import java.awt.*;
22  import java.awt.event.*;
23  import java.awt.image.*;
24  import javax.swing.*;
25  import javax.swing.border.*;
26  
27  public class DjaImage
28         extends DjaForm
29  {
30    public DjaImage(String _text, Image _image)
31    {
32      super(_text,SOUTH);
33      setForeground(null);
34      setBackground(null);
35      setImage(_image);
36    }
37  
38    public DjaImage(Image _image)
39    {
40      this(null,_image);
41    }
42  
43    public DjaImage()
44    {
45      this(null,null);
46    }
47  
48    private transient Image image_;
49    public Image getImage() { return image_; }
50    public void setImage(Image _image)
51    {
52      image_=_image;
53      if(image_!=null)
54      {
55        setWidth(image_.getWidth(HELPER));
56        setHeight(image_.getHeight(HELPER));
57      }
58    }
59  
60    /*
61    public void setSize(Dimension _size)
62    {
63      Dimension s=_size.getSize();
64  
65      if(image_!=null)
66      {
67        s.width =Math.max(s.width ,image_.getWidth (HELPER));
68        s.height=Math.max(s.height,image_.getHeight(HELPER));
69      }
70      super.setSize(s);
71    }
72    */
73  
74    public DjaAnchor[] getAnchors()
75    {
76      int x=getX();
77      int y=getY();
78      int w=getWidth();
79      int h=getHeight();
80  
81      DjaAnchor[] r=new DjaAnchor[4];
82      r[0]=new DjaAnchor(this,0,NORTH,x+w/2,y);
83      r[1]=new DjaAnchor(this,1,EAST ,x+w-1,y+h/2);
84      r[2]=new DjaAnchor(this,2,SOUTH,x+w/2,y+h-1);
85      r[3]=new DjaAnchor(this,3,WEST ,x    ,y+h/2);
86      return r;
87    }
88  
89    public void paintObject(Graphics _g)
90    {
91      int x=getX();
92      int y=getY();
93      int w=getWidth();
94      int h=getHeight();
95  
96      Color fg=getForeground();
97      Color bg=getBackground();
98  
99      if(bg!=null)
100     {
101       DjaGraphics.setColor(_g,bg);
102       DjaGraphics.fillRect(_g,x,y,w,h);
103     }
104 
105     if(fg!=null)
106     {
107       DjaGraphics.BresenhamParams bp=DjaGraphics.getBresenhamParams(this);
108       DjaGraphics.setColor(_g,fg);
109       DjaGraphics.drawRect(_g,x,y,w-1,h-1,bp);
110     }
111 
112     if(image_!=null)
113       _g.drawImage(image_,x,y,w,h,HELPER);
114 
115     super.paintObject(_g);
116   }
117 
118   public void paintInteractive(Graphics _g)
119   {
120     if(isSelected())
121     {
122       int x=getX();
123       int y=getY();
124       int w=getWidth();
125       int h=getHeight();
126 
127       _g.setColor(getForeground());
128       _g.drawRect(x-1,y-1,w+1,h+1);
129     }
130   }
131 }
132 
133