001    /*
002     * 
003     * $Revision: 1.7 $ $Date: 2009/04/03 08:41:02 $
004     *
005     * This file is part of ***  M y C o R e  ***
006     * See http://www.mycore.de/ for details.
007     *
008     * This program is free software; you can use it, redistribute it
009     * and / or modify it under the terms of the GNU General Public License
010     * (GPL) as published by the Free Software Foundation; either version 2
011     * of the License or (at your option) any later version.
012     *
013     * This program is distributed in the hope that it will be useful, but
014     * WITHOUT ANY WARRANTY; without even the implied warranty of
015     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016     * GNU General Public License for more details.
017     *
018     * You should have received a copy of the GNU General Public License
019     * along with this program, in a file called gpl.txt or license.txt.
020     * If not, write to the Free Software Foundation Inc.,
021     * 59 Temple Place - Suite 330, Boston, MA  02111-1307 USA
022     */
023    package org.mycore.frontend.metsmods;
024    
025    import java.awt.Color;
026    import java.awt.Toolkit;
027    import java.awt.event.ActionEvent;
028    import java.awt.event.ActionListener;
029    import java.awt.event.FocusEvent;
030    import java.awt.event.FocusListener;
031    import java.awt.event.MouseAdapter;
032    import java.awt.event.MouseEvent;
033    import java.io.File;
034    import java.net.URL;
035    import java.util.ResourceBundle;
036    
037    import javax.swing.ImageIcon;
038    import javax.swing.JButton;
039    import javax.swing.JCheckBox;
040    import javax.swing.JLabel;
041    import javax.swing.JPanel;
042    import javax.swing.JTextField;
043    import javax.swing.event.DocumentEvent;
044    import javax.swing.event.DocumentListener;
045    
046     
047    /**
048     * This class is part of the MetsMods module. It is a representation of a item containing
049     * filename, order, button up, button down and a check box which shows you whether the file
050     * is included in mets (the last point isn't implemented yet). There you can also find a
051     * text box that is made for holding the "orderlabel" text of a picture in a mets file. 
052     * 
053     * @author Stefan Freitag (sasf)
054     * 
055     * @version $Revision: 1.7 $ $Date: 2009/04/03 08:41:02 $
056     */
057    
058    public class MCRMetsModsPictureItem extends JPanel{
059    
060            private static final long serialVersionUID = -3003017208325790629L;
061            MCRMetsModsPicture mmp;
062            JLabel filename = new JLabel();
063            JLabel order = new JLabel();
064            JButton button_up = new JButton();
065            JButton button_down = new JButton();
066            JCheckBox checkmets = new JCheckBox();
067            JTextField orderlabel = new JTextField();
068            Color colorroom, colorhighlight;
069            MCRMetsModsPictureContainer mmpc;
070                    
071            public MCRMetsModsPictureItem(MCRMetsModsPicture mmp)
072            {
073                    this.mmp = mmp;
074                    init(200);
075            }
076            
077            public MCRMetsModsPictureItem(MCRMetsModsPicture mmp, int l)
078            {
079                    this.mmp = mmp;
080                    init(l);
081            }
082    
083            public void changeHighlight(Color c)
084            {
085                    this.colorhighlight = c;
086            }
087            
088            public int getOrderValue()
089            {
090                    return mmp.getOrder();
091            }
092            
093            public String getPictureName()
094            {
095                    return mmp.getPicture();
096            }
097            
098            public String getOrderLabelValue()
099            {
100                    if(orderlabel.getText()!=null)
101                            return orderlabel.getText();
102                    
103                    return mmp.getOrderlabel();
104            }
105            
106            public MCRMetsModsPicture getMetsModsPicture()
107            {
108                    return mmp;
109            }
110            
111            public void setContainer(MCRMetsModsPictureContainer mmpc)
112            {
113                    this.mmpc = mmpc;
114            }
115            
116            /**
117             * Once up in the list
118             */
119            public void setUp()
120            {
121                    mmpc.changeItem(this, true);            
122            }
123            
124            /**
125             * Once down in the list
126             */
127            public void setDown()
128            {
129                    mmpc.changeItem(this, false);           
130            }
131            
132            public void changeOL()
133            {
134                    mmpc.changeOrderLabel(this, orderlabel.getText());
135            }
136            
137            public void renew()
138            {
139                    order.setText(String.valueOf(mmp.getOrder()));
140            }
141            
142            private void init(int l)
143            {
144                    this.setLayout(null);
145                    checkmets.setEnabled(false);
146                    int max_width = l+310;
147                    
148                    this.setBounds(0, 0, max_width, 20);
149                                    
150                    colorhighlight = Color.LIGHT_GRAY;
151                    
152                    URL url1 = this.getClass().getResource("/pmud-up.png");
153                    URL url2 = this.getClass().getResource("/pmud-down.png");
154                    
155                    button_up = new JButton(new ImageIcon(url1));
156                    button_down = new JButton(new ImageIcon(url2));
157                                    
158                    filename.setText(mmp.getPicture());
159                    order.setText(String.valueOf(mmp.getOrder()));
160                    
161                    filename.setBounds(0,0,l,20);
162                    order.setBounds(l,0,40,20);
163                    button_up.setBounds(l+40,0,20,20);
164                    button_down.setBounds(l+65,0,20,20);
165                    checkmets.setBounds(l+90,0,20,20);
166                    orderlabel.setBounds(l+120,0,180,20);
167                    orderlabel.setText(mmp.getOrderlabel());
168                    
169                    checkmets.addMouseListener(new MouseAdapter()
170                    {
171                            public void mouseEntered(MouseEvent me)
172                            {
173                                    colorroom = getBackground();
174                                    setBackground(colorhighlight);
175                            }
176                            
177                            public void mouseExited(MouseEvent me)
178                            {
179                                    setBackground(colorroom);       
180                            }
181                    });
182                    
183                    button_up.addMouseListener(new MouseAdapter()
184                    {
185                            public void mouseEntered(MouseEvent me)
186                            {
187                                    colorroom = getBackground();
188                                    setBackground(colorhighlight);
189                            }
190                            
191                            public void mouseExited(MouseEvent me)
192                            {
193                                    setBackground(colorroom);       
194                            }
195                    });
196                    
197                    button_down.addMouseListener(new MouseAdapter()
198                    {
199                            public void mouseEntered(MouseEvent me)
200                            {
201                                    colorroom = getBackground();
202                                    setBackground(colorhighlight);
203                            }
204                            
205                            public void mouseExited(MouseEvent me)
206                            {
207                                    setBackground(colorroom);       
208                            }
209                    });
210                    
211                    button_up.addActionListener(new ActionListener(){
212                            public void actionPerformed(ActionEvent e)
213                            {
214                                    setDown();
215                            }
216                    });
217                    
218                    button_down.addActionListener(new ActionListener(){
219                            public void actionPerformed(ActionEvent e)
220                            {
221                                    setUp();
222                            }
223                    });
224                    
225                    /*orderlabel.getDocument().addDocumentListener(new DocumentListener(){
226    
227    
228                            public void changedUpdate(DocumentEvent arg0) {
229                                    
230                                    new javax.swing.JOptionPane().showMessageDialog(new javax.swing.JFrame(), "change");
231                            }
232    
233    
234                            public void insertUpdate(DocumentEvent arg0) {
235    
236                                    new javax.swing.JOptionPane().showMessageDialog(new javax.swing.JFrame(), "insert");
237                            }
238    
239    
240                            public void removeUpdate(DocumentEvent arg0) {
241    
242                                    new javax.swing.JOptionPane().showMessageDialog(new javax.swing.JFrame(), "remove");
243                            }
244                            
245                    });*/
246                    
247                    orderlabel.addFocusListener(new FocusListener(){
248    
249                            public void focusGained(FocusEvent arg0) {
250                                    // TODO Auto-generated method stub
251                                    
252                            }
253    
254                            public void focusLost(FocusEvent arg0) {
255                                    // TODO Auto-generated method stub
256                                    changeOL();
257                            }
258                            
259                            
260                    });
261                    
262                    
263                    orderlabel.addActionListener(new ActionListener(){
264                            public void actionPerformed(ActionEvent arg0) {
265                                    //new javax.swing.JOptionPane().showMessageDialog(new javax.swing.JFrame(), "now");
266                                    changeOL();
267                            }
268                            
269                    });
270                    
271                    this.add(filename);
272                    this.add(order);
273                    this.add(button_up);
274                    this.add(button_down);
275                    this.add(checkmets);
276                    this.add(orderlabel);
277            }
278    }