FileDocCategorySizeDatePackage
SpotlightDemo.javaAPI DocExample4042Mon Jan 09 11:02:00 GMT 2006None

SpotlightDemo

public class SpotlightDemo extends JFrame

Fields Summary
private SpotlightPanel
glassPane
private JComponent[]
books
Constructors Summary
public SpotlightDemo()

		super("Spotlight Demo");

		glassPane = new SpotlightPanel(true);
		this.setGlassPane(glassPane);

        Container c = new GradientPanel();
        setContentPane(c);
		c.setLayout(new BorderLayout());

        JPanel headerPanel = new JPanel(new BorderLayout());
        HeaderPanel header = new HeaderPanel();
        headerPanel.add(BorderLayout.NORTH, header);
        headerPanel.add(BorderLayout.SOUTH, new JSeparator(JSeparator.HORIZONTAL));
        c.add(BorderLayout.NORTH, headerPanel);

        JPanel booksPanel = new GradientPanel();
        booksPanel.setOpaque(false);
        booksPanel.setLayout(new GridLayout(2, 3));
        booksPanel.setBorder(new EmptyBorder(6, 0, 0, 0));
        createBooks(booksPanel);
        c.add(BorderLayout.CENTER, booksPanel);

        JPanel searchPanel = new JPanel();
        searchPanel.setOpaque(false);
        JLabel label = new JLabel("Search for books:");
        searchPanel.add(label);
        JTextField searchField = new JTextField(12);
        searchField.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent evt)
            {
                String text = ((JTextField) evt.getSource()).getText();
                if ("sci-fi".equals(text))
                    createSciFiSpots();
                else if ("books".equals(text))
                    createSpotsForAll();
                else if ("pratchett".equals(text))
                    createPratchettSpots();
                else if ("adams".equals(text))
                    createAdamsSpots();
            }
        });
        searchPanel.add(searchField);
        c.add(BorderLayout.SOUTH, searchPanel);

        pack();
        setResizable(false);
		setLocationRelativeTo(null);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
    
Methods Summary
private voidaddSpotForBook(int i)

        Point p = new Point(books[i].getLocation());
        SwingUtilities.convertPointToScreen(p, books[i].getParent());
        SwingUtilities.convertPointFromScreen(p, glassPane);
        glassPane.addSpotlight(p.x - 4, p.y - 4, 96, 152);
    
private voidcreateAdamsSpots()

        for (int i = 3; i < 6; i++)
        {
            addSpotForBook(i);
        }
    
private voidcreateBooks(javax.swing.JPanel container)

        books = new JComponent[6];
        for (int i = 0; i < books.length; i++)
        {
            JPanel buttonPanel = new JPanel();
            buttonPanel.setOpaque(false);
            buttonPanel.add(books[i] = UIHelper.createLabel("", "cover" + (i + 1) + "_small_button"));
            container.add(buttonPanel);
        }
    
private voidcreatePratchettSpots()

        addSpotForBook(2);
    
private voidcreateSciFiSpots()

        addSpotForBook(0);
        for (int i = 3; i < 6; i++)
        {
            addSpotForBook(i);
        }
    
private voidcreateSpotsForAll()

        for (int i = 0; i < 6; i++)
        {
            addSpotForBook(i);
        }
    
public static voidmain(java.lang.String[] args)

        SpotlightDemo demo = new SpotlightDemo();
        demo.setVisible(true);