/* * This file is part of the Echo Web Application Framework (hereinafter "Echo"). * Copyright (C) 2002 NextApp, Inc. * * Echo is free software; you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * Echo is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with Echo; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ import java.util.Enumeration; import nextapp.echo.Button; import nextapp.echo.Color; import nextapp.echo.ContainerPane; import nextapp.echo.ContentPane; import nextapp.echo.EchoInstance; import nextapp.echo.EchoConstants; import nextapp.echo.Filler; import nextapp.echo.Label; import nextapp.echo.SelectField; import nextapp.echo.Window; import nextapp.echo.event.ActionListener; import nextapp.echo.event.ActionEvent; import nextapp.echoservlet.EchoServer; public class WindowServlet extends EchoServer { public EchoInstance newInstance() { return new WindowDemo(); } } // This class extends the LayoutDemo. It enhances it by // providing a user selectable border size between 0 and 8 // pixels instead of simply toggling among 0, 1, 2, 4, and // 8 pixels like the overriden version of changeBorderSize() // did. It overrides only the changeBorderSize() method. // The LayoutDemo object calls the changeBorderSize() // method when the user clicks the "Change Border Size" // button. class WindowDemo extends LayoutDemo { // This class needs to keep track of the state of the // popup window and the select field inside of it. private SelectField select; private Window popup = null; // This method will be called by LayoutDemo when the // user clicks the "Change Border Size" button. public void changeBorderSize() { // If the popup window is open, close it. if (popup != null && popup.isVisible()) { popup.dispose(); } // Create a new 300x150 popup window with the title // "Change Border Size" popup = new Window("Change Border Size"); popup.setWidth(300); popup.setHeight(150); // Set the default close operation to // DISPOSE_ON_CLOSE. This will cause the popup // window to disappear and be destroyed if the // user clicks it's close button. If you do not // set this attribute, the window will be reopened. popup.setDefaultCloseOperation( Window.DISPOSE_ON_CLOSE); // The popup window will have two panes, one which // contains a select field and the other which // contains an Ok button. // Create the main pane. ContentPane mainPane = new ContentPane(); mainPane.add(new Label( "Select a border size for the grid:")); mainPane.add(Filler.createVerticalStrut(10)); // Setup the select field. The select field can // take an array of options in the form of Objects // as a parameter to its constructor. It will // display each object visually by calling its // toString() method. // In this case, we create an array of strings from // "0" to "8". Object[] items = new Object[9]; for (int index = 0; index <= 8; ++index) { items[index] = Integer.toString(index); } // Create the SelectField select = new SelectField(items); // Set the selected index of the SelectField to the // current border size of the grid. // The demoGrid variable is a protected instance // variable of LayoutDemo, which this class extends. select.setSelectedIndex(demoGrid.getBorderSize()); mainPane.add(select); // Create the button pane. ContentPane buttonPane = new ContentPane(); buttonPane.setHeight(30); buttonPane.setForeground(Color.WHITE); buttonPane.setBackground(BUTTON_PANE_BLUE); buttonPane.setScrollBarPolicy( ContentPane.SCROLL_BAR_NEVER); Button ok = new Button("Ok"); buttonPane.add(ok); // Add an anonymous inner class as an action // listener for the OK button. ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // When clicked, the selected value of the // select field is determined and the // border of the demo grid is set // accordingly. demoGrid.setBorderSize(Integer.parseInt( select.getSelectedItem() .toString())); // Close the popup window. popup.dispose(); popup = null; } }); // Create a container pane and add the main pane // and the button pane to it. ContainerPane container = new ContainerPane(); container.setOrientation( ContainerPane.ORIENTATION_VERTICAL); container.add(mainPane); container.add(buttonPane); // Set the container to be the contents of the popup // window. popup.setContent(container); // Add the window to the EchoInstance using the // addWindow() method. This will cause it to be // opened on the user's browser. addWindow(popup); } }