| 1 | // Jomic - a viewer for comic book archives. |
| 2 | // Copyright (C) 2004-2011 Thomas Aglassinger |
| 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, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // This program is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | package net.sf.jomic.ui; |
| 17 | |
| 18 | import java.awt.Color; |
| 19 | import java.awt.Dimension; |
| 20 | import java.awt.Frame; |
| 21 | import java.awt.GridBagConstraints; |
| 22 | import java.awt.GridBagLayout; |
| 23 | import java.awt.image.RenderedImage; |
| 24 | import java.io.IOException; |
| 25 | |
| 26 | import javax.swing.BorderFactory; |
| 27 | import javax.swing.ImageIcon; |
| 28 | import javax.swing.JLabel; |
| 29 | import javax.swing.JPanel; |
| 30 | import javax.swing.JScrollPane; |
| 31 | |
| 32 | import junit.extensions.abbot.ComponentTestFixture; |
| 33 | import net.sf.jomic.tools.ColorBox; |
| 34 | import net.sf.jomic.tools.ImageTools; |
| 35 | import net.sf.jomic.tools.TestTools; |
| 36 | |
| 37 | /** |
| 38 | * TestCase for ColorBox. |
| 39 | * |
| 40 | * @author Thomas Aglassinger |
| 41 | */ |
| 42 | public class ColorBoxTest extends ComponentTestFixture |
| 43 | { |
| 44 | public void testColorBox() |
| 45 | throws IOException { |
| 46 | TestTools testTools = TestTools.instance(); |
| 47 | ImageTools imageTools = ImageTools.instance(); |
| 48 | |
| 49 | RenderedImage image = testTools.getTestImage(); |
| 50 | ImageIcon icon = imageTools.getAsImageIcon(image); |
| 51 | GridBagConstraints c = new GridBagConstraints(); |
| 52 | JPanel pane = new JPanel(new GridBagLayout()); |
| 53 | |
| 54 | c.gridx = 0; |
| 55 | c.gridy = 0; |
| 56 | c.gridwidth = GridBagConstraints.REMAINDER; |
| 57 | c.weightx = 1.0; |
| 58 | c.weighty = 1.0; |
| 59 | c.fill = GridBagConstraints.BOTH; |
| 60 | pane.add(createColorBox(Color.RED), c); |
| 61 | c.gridy += 1; |
| 62 | c.gridwidth = 1; |
| 63 | c.weighty = 0.0; |
| 64 | pane.add(createColorBox(Color.GREEN), c); |
| 65 | c.gridx += 1; |
| 66 | c.weightx = 0.0; |
| 67 | c.fill = GridBagConstraints.NONE; |
| 68 | |
| 69 | JLabel iconLabel = new JLabel(icon); |
| 70 | |
| 71 | pane.add(iconLabel, c); |
| 72 | c.gridx += 1; |
| 73 | c.weightx = 1.0; |
| 74 | c.fill = GridBagConstraints.BOTH; |
| 75 | pane.add(createColorBox(Color.BLUE), c); |
| 76 | c.gridx = 0; |
| 77 | c.gridy += 1; |
| 78 | c.weighty = 1.0; |
| 79 | c.gridwidth = GridBagConstraints.REMAINDER; |
| 80 | pane.add(createColorBox(Color.CYAN), c); |
| 81 | pane.setBorder(BorderFactory.createEmptyBorder()); |
| 82 | |
| 83 | Frame frame = showFrame(new JScrollPane(pane)); |
| 84 | int width = frame.getWidth(); |
| 85 | int height = frame.getHeight(); |
| 86 | int tooBigWidth = 3 * width / 2; |
| 87 | int tooBigHeight = 3 * height / 2; |
| 88 | int tooSmallWidth = 2 * width / 3; |
| 89 | int tooSmallHeight = 2 * height / 3; |
| 90 | |
| 91 | testTools.waitSomeTime(); |
| 92 | frame.setSize(tooBigWidth, tooBigHeight); |
| 93 | testTools.waitSomeTime(); |
| 94 | frame.setSize(tooSmallWidth, tooSmallHeight); |
| 95 | testTools.waitSomeTime(); |
| 96 | } |
| 97 | |
| 98 | private ColorBox createColorBox(Color color) { |
| 99 | assert color != null; |
| 100 | ColorBox result = new ColorBox(color); |
| 101 | |
| 102 | result.setPreferredSize(new Dimension(0, 0)); |
| 103 | return result; |
| 104 | } |
| 105 | |
| 106 | } |