Merge remote-tracking branch 'origin/master' into micropeak-logging
[fw/altos] / micropeak / MicroFrame.java
1 /*
2  * Copyright © 2011 Keith Packard <keithp@keithp.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16  */
17
18 package org.altusmetrum.micropeak;
19
20 import java.awt.*;
21 import java.awt.event.*;
22 import javax.swing.*;
23 import java.util.*;
24
25 class MicroFrameListener extends WindowAdapter {
26         public void windowClosing (WindowEvent e) {
27                 MicroPreferences.unregister_ui_listener((MicroFrame) e.getWindow());
28         }
29 }
30
31 public class MicroFrame extends JFrame implements MicroUIListener {
32
33         public void ui_changed(String look_and_feel) {
34                 SwingUtilities.updateComponentTreeUI(this);
35                 this.pack();
36         }
37
38         static final String[] icon_names = {
39                 "/micropeak-16.png",
40                 "/micropeak-32.png",
41                 "/micropeak-48.png",
42                 "/micropeak-64.png",
43                 "/micropeak-128.png",
44                 "/micropeak-256.png"
45         };
46
47         public void set_icon() {
48                 ArrayList<Image> icons = new ArrayList<Image>();
49                 
50                 for (int i = 0; i < icon_names.length; i++) {
51                         java.net.URL imgURL = MicroPeak.class.getResource(icon_names[i]);
52                         if (imgURL != null)
53                                 icons.add(new ImageIcon(imgURL).getImage());
54                 }
55
56                 setIconImages(icons);
57         }
58                         
59         public MicroFrame() {
60                 super();
61                 MicroPreferences.set_component(this);
62                 MicroPreferences.register_ui_listener(this);
63                 addWindowListener(new MicroFrameListener());
64                 set_icon();
65         }
66
67         public MicroFrame(String name) {
68                 super(name);
69                 MicroPreferences.set_component(this);
70                 MicroPreferences.register_ui_listener(this);
71                 addWindowListener(new MicroFrameListener());
72                 set_icon();
73         }
74 }