Source code: com/memoire/bu/BuFrameImage.java
1 /**
2 * @modification $Date: 2002/12/06 18:38:03 $
3 * @statut unstable
4 * @file BuFrameImage.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.bu;
13
14 import com.memoire.bu.*;
15 import com.memoire.dnd.*;
16 import com.memoire.fu.*;
17 import com.memoire.re.*;
18
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import java.beans.*;
23 import java.net.*;
24 import java.io.*;
25
26 import javax.swing.*;
27 import javax.swing.border.*;
28 import javax.swing.text.*;
29 import javax.swing.event.*;
30
31 /**
32 * A small image displayer.
33 */
34
35 public class BuFrameImage
36 extends BuInternalFrame
37 implements BuPrintable
38 {
39 private BuCommonImplementation app_;
40 private JComponent content_;
41 private BuPicture pane_;
42 private BuScrollPane sp_;
43
44 public BuFrameImage()
45 { this(null,null,null); }
46
47 public BuFrameImage(BuCommonImplementation _app, String _file, Image _img)
48 {
49 super("",true,true,true,true);
50 app_=_app;
51
52 setName("ifIMAGEUR");
53 if(app_!=null) app_.installContextHelp(getRootPane(),"bu/p-imageur.html");
54
55 content_=(JComponent)getContentPane();
56 content_.setBorder(new EmptyBorder(0,0,0,0));
57
58 pane_=new BuPicture();
59 pane_.setOpaque(true);
60 pane_.setBackground(Color.white);
61 pane_.setBorder(new EmptyBorder(5,5,5,5));
62 pane_.setMode(BuPicture.LEFT);
63
64 sp_=new BuScrollPane(pane_);
65 sp_.setBorder(new EmptyBorder(0,0,0,0));
66 content_.add(sp_,BuBorderLayout.CENTER);
67
68 if(_file!=null) setTitle(new File(_file).getName());
69 else setTitle(BuResource.BU.getString("Image"));
70
71 setFrameIcon(BuResource.BU.getFrameIcon("image"));
72
73 setImage(_img);
74 }
75
76 public Image getImage()
77 {
78 return pane_.getImage();
79 }
80
81 public void setImage(Image _img)
82 {
83 pane_.setImage(_img);
84 Dimension ps=getPreferredSize();
85 if(ps.width >370) ps.width =296;
86 if(ps.height>370) ps.height=296;
87 if(ps.width <148) ps.width =148;
88 if(ps.height< 74) ps.height= 74;
89 setSize(ps);
90 }
91
92 public void setBounds(int _x,int _y,int _w,int _h)
93 {
94 super.setBounds(_x,_y,_w,_h);
95
96 if(pane_!=null)
97 {
98 pane_.computePreferredSize();
99 Dimension ps=pane_.getPreferredSize();
100 sp_.getViewport().setViewPosition(new Point(0,0));
101 sp_.getViewport().setViewSize (ps);
102 }
103 }
104
105 /*
106 public void setSelected(boolean _state) throws PropertyVetoException
107 {
108 super.setSelected(_state);
109 if(isSelected()) pane_.requestFocus();
110 }
111 */
112
113 // BuInternalFrame
114
115 public String[] getEnabledActions()
116 {
117 String[] r=new String[]
118 {
119 "IMPRIMER","PREVISUALISER",
120 //"COPIER"
121 };
122 return r;
123 }
124
125 // BuPrintable
126
127 public void print(PrintJob _job, Graphics _g)
128 {
129 BuPrinter.INFO_DOC =new BuInformationsDocument();
130 BuPrinter.INFO_DOC.name=getTitle();
131 BuPrinter.INFO_DOC.logo=BuResource.BU.getIcon("image",24);
132
133 BuPrinter.printImage(_job,_g,getImage());
134 }
135
136 // Test
137
138 public static void main(String[] _args)
139 {
140 JFrame f=new JFrame("test BuFrameImage");
141 BuFrameImage b=new BuFrameImage();
142 BuFrameImage c=new BuFrameImage();
143
144 BuDesktop d=new BuDesktop();
145 d.add(b);
146 d.add(c);
147
148 f.getContentPane().add("Center",d);
149 f.setSize(300,400);
150 f.show();
151 f.setLocation(200,100);
152
153 b.setImage(BuResource.BU.getImage("background_desktop_1.gif"));
154 c.setImage(BuResource.BU.getImage("ouvrir_24.gif"));
155 b.setLocation(70,30);
156 }
157 }