[Ejtools-cvs] CVS: libraries/adwt/src/main/net/sourceforge/ejtools/awt/services AboutService.java,NO
Brought to you by:
letiemble
Update of /cvsroot/ejtools/libraries/adwt/src/main/net/sourceforge/ejtools/awt/services In directory usw-pr-cvs1:/tmp/cvs-serv9837 Added Files: AboutService.java AboutServiceProvider.java ActionToolBar.java BeanContextInternalFrame.java FrameService.java FrameServiceProvider.java HistoryService.java HistoryServiceProvider.java MDIDesktopPane.java MDIFrameService.java MenuBarService.java MenuBarServiceProvider.java PreferencesService.java SDIFrameService.java StatusBarService.java StatusBarServiceProvider.java ToolBarService.java ToolBarServiceProvider.java Log Message: Initial Import --- NEW FILE: AboutService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.Container; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface AboutService { /** * Description of the Method * * @return The value of panel attribute */ public Container getPanel(); } --- NEW FILE: AboutServiceProvider.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Container; import java.awt.GridLayout; import java.beans.beancontext.BeanContextServiceProvider; import java.beans.beancontext.BeanContextServices; import java.beans.beancontext.BeanContextServicesSupport; import java.util.Iterator; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import net.sourceforge.ejtools.awt.action.Command; import net.sourceforge.ejtools.awt.action.help.AboutAction; import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 2 novembre 2001 * @todo Javadoc to complete * @todo I18N to complete */ public class AboutServiceProvider extends BeanContextServicesSupport implements BeanContextServiceProvider, AboutService { /** Description of the Field */ private JPanel panel = null; /** Description of the Field */ private AboutService service = null; /** Description of the Field */ private static Category cat = Category.getInstance(AboutServiceProvider.class.getName()); /** Constructor for the AboutServiceProvider object */ public AboutServiceProvider() { service = this; } /** * Constructor for the AboutServiceProvider object * * @param service Description of Parameter */ public AboutServiceProvider(AboutService service) { this.service = service; } /** * Gets the currentServiceSelectors attribute of the * ApplicationServiceProvider object * * @param bcs Description of Parameter * @param serviceClass Description of Parameter * @return The currentServiceSelectors value */ public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) { return new Vector().iterator(); } /** * Gets the panel attribute of the AboutServiceProvider object * * @return The panel value */ public Container getPanel() { if (panel == null) { createPanel(); } return panel; } /** * Gets the service attribute of the ApplicationServiceProvider object * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param serviceClass Description of Parameter * @param serviceSelector Description of Parameter * @return The service value */ public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) { return service; } /** * Description of the Method * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param service Description of Parameter */ public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } /** Description of the Method */ protected void initializeBeanContextResources() { ((BeanContextServices) getBeanContext()).addService(AboutService.class, this); // Add the service getBeanContext().add(service); // Add the About button getBeanContext().add(new AboutAction( new Command() { public void execute() { show(); } } )); cat.debug("AboutService added"); } /** Description of the Method */ protected void releaseBeanContextResources() { ((BeanContextServices) getBeanContext()).revokeService(AboutService.class, this, true); remove(service); cat.debug("AboutService removed"); } /** Description of the Method */ protected void show() { BeanContextServices context = (BeanContextServices) getBeanContext(); if (context.hasService(FrameService.class)) { cat.debug("Using service FrameService..."); try { FrameService fservice = (FrameService) context.getService(this, this, FrameService.class, this, this); JFrame frame = (JFrame) fservice.getContainer(); // I18N Todo JOptionPane.showMessageDialog(frame, service.getPanel(), "About Service", JOptionPane.PLAIN_MESSAGE); context.releaseService(this, this, FrameService.class); } catch (Exception e) { cat.error("Error during utilisation ofgetBeanContext() service FrameService (" + e.getMessage() + ")"); } } } /** Description of the Method */ private void createPanel() { panel = new JPanel(new BorderLayout()); String display = null; JLabel label = null; // North part panel.add("North", new JLabel("Insert your logo here")); // Center part panel.add("Center", new JLabel("This is the default AboutService")); // South part JPanel info = new JPanel(new GridLayout(2, 1)); JLabel java = new JLabel("Java version:" + System.getProperty("java.version"), JLabel.CENTER); java.setForeground(Color.black); info.add(java); JLabel vm = new JLabel("VM:" + System.getProperty("java.vm.name") + ", " + System.getProperty("java.vm.version"), JLabel.CENTER); vm.setForeground(Color.black); info.add(vm); panel.add("South", info); } } --- NEW FILE: ActionToolBar.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.util.Hashtable; import javax.swing.Action; import javax.swing.JButton; import javax.swing.JToolBar; /** * Description of the Class * * @author letiembl * @created 2 novembre 2001 * @todo Javadoc to complete */ public class ActionToolBar extends JToolBar { /** Description of the Field */ protected Hashtable buttons = new Hashtable(); /** * Description of the Method * * @param action Description of Parameter * @return Description of the Returned Value */ public JButton add(Action action) { JButton button = super.add(action); this.buttons.put(action, button); return button; } /** * Description of the Method * * @param action Description of Parameter */ public void remove(Action action) { JButton button = (JButton) this.buttons.get(action); this.remove(button); } } --- NEW FILE: BeanContextInternalFrame.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.Component; import java.beans.PropertyVetoException; import java.beans.beancontext.BeanContextServices; import java.beans.beancontext.BeanContextServicesSupport; import javax.swing.Action; import javax.swing.ButtonGroup; import javax.swing.JInternalFrame; import javax.swing.event.InternalFrameAdapter; import javax.swing.event.InternalFrameEvent; import net.sourceforge.ejtools.awt.action.Command; import net.sourceforge.ejtools.awt.action.CommandAction; import net.sourceforge.ejtools.awt.action.window.InternalFrameAction; import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public class BeanContextInternalFrame extends BeanContextServicesSupport { /** Description of the Field */ protected static ButtonGroup group = new ButtonGroup(); private static Category cat = Category.getInstance(BeanContextInternalFrame.class.getName()); /** Description of the Field */ protected JInternalFrame frame; /** Description of the Field */ protected CommandAction action; /** Description of the Field */ protected MDIFrameService service; /** Description of the Field */ protected ViewerManager viewer; /** Constructor for the BeanContextInternalFrame object */ public BeanContextInternalFrame() { } /** * Sets the title attribute of the BeanContextInternalFrame object * * @param title The new title value */ public void setTitle(String title) { frame.setTitle(title); action.putValue(Action.NAME, title); } /** * Gets the component attribute of the BeanContextInternalFrame object * * @return The component value */ public Component getComponent() { return this.frame; } /** * Gets the action attribute of the BeanContextInternalFrame object * * @return The action value */ public CommandAction getAction() { return this.action; } /** Description of the Method */ public void close() { frame.doDefaultCloseAction(); } /** Description of the Method */ protected void initializeBeanContextResources() { cat.info("In initializeBeanContextResources"); BeanContextServices context = (BeanContextServices) getBeanContext(); register(context); frame = new JInternalFrame("", true, true, true, true); viewer = new ViewerManager(); frame.addInternalFrameListener(viewer); frame.setSize(400, 300); if (service != null) { service.register(this); } action = new InternalFrameAction( new Command() { public void execute() { activate(); } }); context.add(action); this.createFrame(); group.add(action.getMenuItem()); frame.setSize(400, 300); frame.validate(); frame.setVisible(true); try { frame.setMaximum(true); } catch (PropertyVetoException e) { } activate(); } /** Description of the Method */ protected void activate() { try { if (service != null) { service.activate(BeanContextInternalFrame.this); } if (action != null) { action.getMenuItem().setSelected(true); } } catch (Exception e) { } } /** * Description of the Method * * @param context Description of Parameter */ protected void register(BeanContextServices context) { if (context.hasService(MDIFrameService.class)) { cat.debug("Using service MDIFrameService..."); try { service = (MDIFrameService) context.getService(this, this, MDIFrameService.class, this.frame, this); cat.debug("Service MDIFrameService registered"); } catch (Exception e) { cat.error("Error during utilisation of service MDIFrameService (" + e.getMessage() + ")"); e.printStackTrace(); } } } /** * Description of the Method * * @param context Description of Parameter */ protected void unregister(BeanContextServices context) { if (context.hasService(MDIFrameService.class)) { cat.debug("Using service MDIFrameService..."); try { context.releaseService(this, this, MDIFrameService.class); } catch (Exception e) { cat.error("Error during utilisation of service MDIFrameService (" + e.getMessage() + ")"); e.printStackTrace(); } } } /** Description of the Method */ protected void releaseBeanContextResources() { cat.info("In releaseBeanContextResources"); BeanContextServices context = (BeanContextServices) getBeanContext(); if (service != null) { service.unregister(this); } group.remove(action.getMenuItem()); context.remove(action); unregister(context); } /** Description of the Method */ protected void createFrame() { } /** * Description of the Method * * @exception Exception Description of Exception */ protected void destroyFrame() throws Exception { } /** * Description of the Class * * @author laurent * @created 12 janvier 2002 */ class ViewerManager extends InternalFrameAdapter { /** * Description of the Method * * @param e Description of Parameter */ public void internalFrameActivated(InternalFrameEvent e) { activate(); } /** * Description of the Method * * @param e Description of Parameter */ public void internalFrameClosed(InternalFrameEvent e) { try { destroyFrame(); setBeanContext(null); } catch (Exception ex) { ex.printStackTrace(); } } } } --- NEW FILE: FrameService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.beans.beancontext.BeanContextContainerProxy; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface FrameService extends BeanContextContainerProxy, MenuBarService.Listener { /** Description of the Field */ public final static String MDI_FRAME = "MDI"; /** Description of the Field */ public final static String SDI_FRAME = "SDI"; /** * Setter for the title attribute * * @param title The new value */ public void setTitle(String title); } --- NEW FILE: FrameServiceProvider.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.Container; import java.awt.Dimension; import java.awt.Toolkit; import java.beans.PropertyVetoException; import java.beans.beancontext.BeanContextServiceProvider; import java.beans.beancontext.BeanContextServices; import java.beans.beancontext.BeanContextServicesSupport; import java.util.Iterator; import java.util.Vector; import javax.swing.JFrame; import javax.swing.JInternalFrame; import javax.swing.JMenuBar; import javax.swing.JPanel; import javax.swing.JScrollPane; import net.sourceforge.ejtools.awt.action.Command; import net.sourceforge.ejtools.awt.action.CommandAction; import net.sourceforge.ejtools.awt.action.window.CascadeAction; import net.sourceforge.ejtools.awt.action.window.CloseAction; import net.sourceforge.ejtools.awt.action.window.CloseAllAction; import net.sourceforge.ejtools.awt.action.window.TileAction; import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 2 novembre 2001 * @todo Javadoc to complete */ public class FrameServiceProvider extends BeanContextServicesSupport implements BeanContextServiceProvider, MDIFrameService, SDIFrameService { private static Category cat = Category.getInstance(FrameServiceProvider.class.getName()); private FrameService service = null; private String type = null; private JFrame frame = new JFrame(); private MDIDesktopPane desktop = new MDIDesktopPane(); private Container content = new JPanel(); private JScrollPane scrollPane = new JScrollPane(); private Vector frames = new Vector(); /** * Constructor for the FrameServiceProvider object * * @param type Description of Parameter */ public FrameServiceProvider(String type) { service = this; this.type = type; } /** * Sets the content attribute of the FrameServiceProvider object * * @param c The new content value */ public void setContent(Container c) { this.content = c; } /** * Setter for the title attribute * * @param title The new value */ public void setTitle(String title) { this.frame.setTitle(title); } /** * Gets the container attribute of the FrameServiceProvider object * * @return The container value */ public Container getContainer() { return this.frame; } /** * Gets the service attribute of the ApplicationServiceProvider object * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param serviceClass Description of Parameter * @param serviceSelector Description of Parameter * @return The service value */ public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) { if (serviceClass.equals(FrameService.class)) { return (FrameService) service; } if ((serviceClass.equals(MDIFrameService.class)) && (FrameService.MDI_FRAME.equals(this.type))) { return (MDIFrameService) service; } if ((serviceClass.equals(SDIFrameService.class)) && (FrameService.SDI_FRAME.equals(this.type))) { return (SDIFrameService) service; } cat.warn("The requested service doesn't match the current service"); return null; } /** * Gets the currentServiceSelectors attribute of the * ApplicationServiceProvider object * * @param bcs Description of Parameter * @param serviceClass Description of Parameter * @return The currentServiceSelectors value */ public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) { return new Vector().iterator(); } /** * Gets the activated attribute of the FrameServiceProvider object * * @param frame Description of Parameter * @return The activated value */ public boolean isActivated(BeanContextInternalFrame frame) { JInternalFrame f = desktop.getSelectedFrame(); return f.equals((JInternalFrame) frame.getComponent()); } /** * Gets the activated attribute of the FrameServiceProvider object * * @return The activated value */ public BeanContextInternalFrame getActivated() { Iterator enum = frames.iterator(); while (enum.hasNext()) { Object obj = enum.next(); if (obj instanceof BeanContextInternalFrame) { if (isActivated((BeanContextInternalFrame) obj)) { return ((BeanContextInternalFrame) obj); } } } return null; } /** * Description of the Method * * @param menuBar Description of Parameter */ public void update(JMenuBar menuBar) { this.frame.setJMenuBar(menuBar); this.frame.setVisible(true); } /** * Description of the Method * * @param frame Description of Parameter */ public void register(BeanContextInternalFrame frame) { desktop.add(((JInternalFrame) frame.getComponent())); frames.add(frame); } /** * Description of the Method * * @param frame Description of Parameter */ public void unregister(BeanContextInternalFrame frame) { frames.remove(frame); desktop.remove(((JInternalFrame) frame.getComponent())); } /** * Description of the Method * * @param frame Description of Parameter */ public void activate(BeanContextInternalFrame frame) { desktop.getDesktopManager().activateFrame(((JInternalFrame) frame.getComponent())); try { ((JInternalFrame) frame.getComponent()).setSelected(true); } catch (PropertyVetoException e) { } } /** * Description of the Method * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param service Description of Parameter */ public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } /** * Description of the Method * * @param context Description of Parameter */ protected void register(BeanContextServices context) { // Set up MenuBar if (context.hasService(MenuBarService.class)) { cat.debug("Using service MenuBarService..."); try { MenuBarService service = (MenuBarService) context.getService(this, this, MenuBarService.class, this.frame, this); service.addMenuBarListener(this); } catch (Exception e) { cat.error("Error during utilisation of service MenuBarService (" + e.getMessage() + ")"); e.printStackTrace(); } } // Set up ToolBar if (context.hasService(ToolBarService.class)) { cat.debug("Using service ToolBarService..."); try { ToolBarService service = (ToolBarService) context.getService(this, this, ToolBarService.class, this.frame, this); frame.getContentPane().add("North", service.getContainer()); } catch (Exception e) { cat.error("Error during utilisation of service ToolBarService (" + e.getMessage() + ")"); e.printStackTrace(); } } // Set up StatusBar if (context.hasService(StatusBarService.class)) { cat.debug("Using service StatusBarService..."); try { StatusBarService service = (StatusBarService) context.getService(this, this, StatusBarService.class, this.frame, this); frame.getContentPane().add("South", service.getContainer()); } catch (Exception e) { cat.error("Error during utilisation of service StatusBarService (" + e.getMessage() + ")"); e.printStackTrace(); } } } /** * Description of the Method * * @param context Description of Parameter */ protected void unregister(BeanContextServices context) { } /** Description of the Method */ protected void initializeBeanContextResources() { BeanContextServices context = (BeanContextServices) getBeanContext(); context.addService(FrameService.class, this); context.addService(MDIFrameService.class, this); context.addService(SDIFrameService.class, this); frame.setSize(new Dimension(700, 500)); if (FrameService.MDI_FRAME.equals(this.type)) { scrollPane.getViewport().add(desktop); } else { scrollPane.getViewport().add(content); } frame.getContentPane().add("Center", scrollPane); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation(screen.width / 2 - frame.getSize().width / 2, screen.height / 2 - frame.getSize().height / 2); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); if (FrameService.MDI_FRAME.equals(this.type)) { context.add(new CascadeAction( new Command() { public void execute() { desktop.cascadeFrames(); } } )); context.add(new TileAction( new Command() { public void execute() { desktop.tileFrames(); } } )); context.add(new CloseAction( new Command() { public void execute() { BeanContextInternalFrame frame = getActivated(); if (frame != null) { frame.close(); } } } )); context.add(new CloseAllAction( new Command() { public void execute() { BeanContextInternalFrame frame; while ((frame = getActivated()) != null) { frame.close(); } } } )); } register(context); frame.setVisible(true); cat.debug("FrameService added"); } /** Description of the Method */ protected void releaseBeanContextResources() { BeanContextServices context = (BeanContextServices) getBeanContext(); frame.setVisible(false); unregister(context); context.revokeService(SDIFrameService.class, this, true); context.revokeService(MDIFrameService.class, this, true); context.revokeService(FrameService.class, this, true); cat.debug("FrameService removed"); } } --- NEW FILE: HistoryService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.net.URL; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface HistoryService { /** * Description of the Method * * @param url Description of Parameter * @param context Description of Parameter */ public void push(URL url, Object context); /** * Description of the Class * * @author letiembl * @created 7 novembre 2001 */ public interface Holder { /** * Description of the Method * * @param url Description of Parameter * @param context Description of Parameter */ public void loadResource(URL url, Object context); } } --- NEW FILE: HistoryServiceProvider.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.beans.beancontext.BeanContextServiceProvider; import java.beans.beancontext.BeanContextServices; import java.beans.beancontext.BeanContextServicesSupport; import java.net.URL; import java.util.Iterator; import java.util.Vector; import net.sourceforge.ejtools.awt.action.Command; import net.sourceforge.ejtools.awt.action.CommandAction; import net.sourceforge.ejtools.awt.action.file.FileHistoryAction; import net.sourceforge.ejtools.awt.action.file.FileHistoryActionTop; import net.sourceforge.ejtools.util.LimitedStack; import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 2 novembre 2001 * @todo Javadoc to complete */ public class HistoryServiceProvider extends BeanContextServicesSupport implements BeanContextServiceProvider, HistoryService { private final static int MAX_WIDTH = 30; private static Category cat = Category.getInstance(HistoryServiceProvider.class.getName()); private HistoryService service = null; private LimitedStack stack = null; private Vector menus = null; private HistoryService.Holder holder = null; private int maxHistory; /** * Constructor for the HistoryServiceProvider object * * @param maxHistory Description of Parameter * @param holder Description of Parameter */ public HistoryServiceProvider(HistoryService.Holder holder, int maxHistory) { this.service = this; this.holder = holder; this.maxHistory = maxHistory; this.stack = new LimitedStack(maxHistory); this.menus = new Vector(maxHistory); } /** * Gets the service attribute of the HistoryServiceProvider object * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param serviceClass Description of Parameter * @param serviceSelector Description of Parameter * @return The service value */ public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) { return service; } /** * Gets the currentServiceSelectors attribute of the HistoryServiceProvider * object * * @param bcs Description of Parameter * @param serviceClass Description of Parameter * @return The currentServiceSelectors value */ public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) { return new Vector().iterator(); } /** * Description of the Method * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param service Description of Parameter */ public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } /** * Description of the Method * * @param url Description of Parameter * @param context Description of Parameter */ public void push(URL url, Object context) { this.stack.push(new HistoryContext(url, context)); for (int i = 0; i < stack.size(); i++) { HistoryContext hc = (HistoryContext) this.stack.elementAt(i); URL theUrl = hc.getURL(); String s = theUrl.toString(); if (s.length() > MAX_WIDTH) { s = "" + (i + 1) + ": " + theUrl.getProtocol() + "..." + s.substring(s.length() - 25); } else { s = "" + (i + 1) + ": " + theUrl.toString(); } CommandAction action = (CommandAction) menus.elementAt(i); action.putValue(CommandAction.NAME, s); action.setEnabled(true); } } /** Description of the Method */ protected void initializeBeanContextResources() { BeanContextServices context = (BeanContextServices) getBeanContext(); context.addService(HistoryService.class, this); CommandAction action; for (int i = 0; i < this.maxHistory; i++) { if (i == 0) { action = new FileHistoryActionTop( new FileHistoryCommand(i) ); } else { action = new FileHistoryAction( new FileHistoryCommand(i) ); } action.setEnabled(false); menus.add(action); context.add(action); } cat.debug("HistoryService added"); } /** Description of the Method */ protected void releaseBeanContextResources() { BeanContextServices context = (BeanContextServices) getBeanContext(); context.revokeService(HistoryService.class, this, true); cat.debug("HistoryService removed"); } /** * Description of the Class * * @author letiembl * @created 7 novembre 2001 */ private class HistoryContext { private URL url; private Object context; /** * Constructor for the HistoryContext object * * @param url Description of Parameter * @param context Description of Parameter */ public HistoryContext(URL url, Object context) { this.url = url; this.context = context; } /** * Gets the uRL attribute of the HistoryContext object * * @return The uRL value */ public URL getURL() { return this.url; } /** * Gets the context attribute of the HistoryContext object * * @return The context value */ public Object getContext() { return this.context; } /** * Description of the Method * * @param o Description of Parameter * @return Description of the Returned Value */ public boolean equals(Object o) { cat.debug("Object to test " + ((HistoryContext) o).getURL().toString()); cat.debug("The URL " + this.url.toString()); return ((HistoryContext) o).getURL().equals(this.url); } } /** * Description of the Class * * @author letiembl * @created 7 novembre 2001 */ private class FileHistoryCommand implements Command { private int position; /** * Constructor for the FileHistoryCommand object * * @param position Description of Parameter */ public FileHistoryCommand(int position) { this.position = position; } /** Description of the Method */ public void execute() { HistoryContext hc = (HistoryContext) HistoryServiceProvider.this.stack.elementAt(position); cat.info("Loading " + hc.getURL()); HistoryServiceProvider.this.holder.loadResource(hc.getURL(), hc.getContext()); } } } --- NEW FILE: MDIDesktopPane.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.Component; import java.awt.Dimension; import java.awt.Insets; import java.awt.Point; import java.beans.PropertyVetoException; import javax.swing.DefaultDesktopManager; import javax.swing.JComponent; import javax.swing.JDesktopPane; import javax.swing.JInternalFrame; import javax.swing.JScrollPane; import javax.swing.JViewport; import javax.swing.filechooser.FileFilter; import org.apache.log4j.Category; /** * An extension of WDesktopPane that supports often used MDI functionality. * This class also handles setting scroll bars for when windows move too far to * the left or bottom, providing the MDIDesktopPane is in a ScrollPane. * * @author laurent * @created 29 décembre 2001 * @todo Javadoc to complete */ public class MDIDesktopPane extends JDesktopPane { private static Category cat = Category.getInstance(MDIDesktopPane.class.getName()); private static int FRAME_OFFSET = 30; private MDIDesktopManager manager; /** Constructor for the MDIDesktopPane object */ public MDIDesktopPane() { manager = new MDIDesktopManager(this); setDesktopManager(manager); setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); } /** * Sets the Bounds attribute of the MDIDesktopPane object * * @param x The new Bounds value * @param y The new Bounds value * @param w The new Bounds value * @param h The new Bounds value */ public void setBounds(int x, int y, int w, int h) { super.setBounds(x, y, w, h); checkDesktopSize(); } /** * Sets all component size properties ( maximum, minimum, preferred) to the * given dimension. * * @param d The new AllSize value */ public void setAllSize(Dimension d) { setMinimumSize(d); setMaximumSize(d); setPreferredSize(d); } /** * Sets all component size properties ( maximum, minimum, preferred) to the * given width and height. * * @param width The new AllSize value * @param height The new AllSize value */ public void setAllSize(int width, int height) { setAllSize(new Dimension(width, height)); } /** * Description of the Method * * @param frame Description of Parameter * @return Description of the Returned Value */ public Component add(JInternalFrame frame) { JInternalFrame[] array = getAllFrames(); Point p; int w; int h; Component retval = super.add(frame); checkDesktopSize(); if (array.length > 0) { p = array[0].getLocation(); p.x = p.x + FRAME_OFFSET; p.y = p.y + FRAME_OFFSET; } else { p = new Point(0, 0); } frame.setLocation(p.x, p.y); if (frame.isResizable()) { w = getWidth() - (getWidth() / 3); h = getHeight() - (getHeight() / 3); if (w < frame.getMinimumSize().getWidth()) { w = (int) frame.getMinimumSize().getWidth(); } if (h < frame.getMinimumSize().getHeight()) { h = (int) frame.getMinimumSize().getHeight(); } frame.setSize(w, h); } moveToFront(frame); frame.setVisible(true); try { frame.setSelected(true); } catch (PropertyVetoException e) { frame.toBack(); } return retval; } /** * Description of the Method * * @param c Description of Parameter */ public void remove(Component c) { super.remove(c); checkDesktopSize(); } /** Cascade all internal frames */ public void cascadeFrames() { int x = 0; int y = 0; JInternalFrame allFrames[] = getAllFrames(); manager.setNormalSize(); int frameHeight = (getBounds().height - 5) - allFrames.length * FRAME_OFFSET; int frameWidth = (getBounds().width - 5) - allFrames.length * FRAME_OFFSET; for (int i = allFrames.length - 1; i >= 0; i--) { allFrames[i].setSize(frameWidth, frameHeight); allFrames[i].setLocation(x, y); x = x + FRAME_OFFSET; y = y + FRAME_OFFSET; } } /** Tile all internal frames */ public void tileFrames() { java.awt.Component allFrames[] = getAllFrames(); manager.setNormalSize(); int frameHeight = getBounds().height / allFrames.length; int y = 0; for (int i = 0; i < allFrames.length; i++) { allFrames[i].setSize(getBounds().width, frameHeight); allFrames[i].setLocation(0, y); y = y + frameHeight; } } /** Description of the Method */ private void checkDesktopSize() { if (getParent() != null && isVisible()) { manager.resizeDesktop(); } } /** * Private class used to replace the standard DesktopManager for * JDesktopPane. Used to provide scrollbar functionality. * * @author laurent * @created 29 décembre 2001 */ class MDIDesktopManager extends DefaultDesktopManager { private MDIDesktopPane desktop; /** * Constructor for the MDIDesktopManager object * * @param desktop Description of Parameter */ public MDIDesktopManager(MDIDesktopPane desktop) { this.desktop = desktop; } /** * Sets the NormalSize attribute of the MDIDesktopManager object */ public void setNormalSize() { JScrollPane scrollPane = getScrollPane(); int x = 0; int y = 0; Insets scrollInsets = getScrollPaneInsets(); if (scrollPane != null) { Dimension d = scrollPane.getVisibleRect().getSize(); if (scrollPane.getBorder() != null) { d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right, d.getHeight() - scrollInsets.top - scrollInsets.bottom); } d.setSize(d.getWidth() - 20, d.getHeight() - 20); desktop.setAllSize(x, y); scrollPane.invalidate(); scrollPane.validate(); } } /** * Description of the Method * * @param f Description of Parameter */ public void endResizingFrame(JComponent f) { super.endResizingFrame(f); resizeDesktop(); } /** * Description of the Method * * @param f Description of Parameter */ public void endDraggingFrame(JComponent f) { super.endDraggingFrame(f); resizeDesktop(); } /** Description of the Method */ protected void resizeDesktop() { int x = 0; int y = 0; JScrollPane scrollPane = getScrollPane(); Insets scrollInsets = getScrollPaneInsets(); if (scrollPane != null) { JInternalFrame allFrames[] = desktop.getAllFrames(); for (int i = 0; i < allFrames.length; i++) { if (allFrames[i].getX() + allFrames[i].getWidth() > x) { x = allFrames[i].getX() + allFrames[i].getWidth(); } if (allFrames[i].getY() + allFrames[i].getHeight() > y) { y = allFrames[i].getY() + allFrames[i].getHeight(); } } Dimension d = scrollPane.getVisibleRect().getSize(); if (scrollPane.getBorder() != null) { d.setSize(d.getWidth() - scrollInsets.left - scrollInsets.right, d.getHeight() - scrollInsets.top - scrollInsets.bottom); } if (x <= d.getWidth()) { x = ((int) d.getWidth()) - 20; } if (y <= d.getHeight()) { y = ((int) d.getHeight()) - 20; } desktop.setAllSize(x, y); scrollPane.invalidate(); scrollPane.validate(); } } /** * Gets the ScrollPaneInsets attribute of the MDIDesktopManager object * * @return The ScrollPaneInsets value */ private Insets getScrollPaneInsets() { JScrollPane scrollPane = getScrollPane(); if (scrollPane == null) { return new Insets(0, 0, 0, 0); } else { return getScrollPane().getBorder().getBorderInsets(scrollPane); } } /** * Gets the ScrollPane attribute of the MDIDesktopManager object * * @return The ScrollPane value */ private JScrollPane getScrollPane() { if (desktop.getParent() instanceof JViewport) { JViewport viewPort = (JViewport) desktop.getParent(); if (viewPort.getParent() instanceof JScrollPane) { return (JScrollPane) viewPort.getParent(); } } return null; } } } --- NEW FILE: MDIFrameService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import javax.swing.filechooser.FileFilter; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface MDIFrameService extends FrameService { /** * Description of the Method * * @param frame Description of Parameter */ public void register(BeanContextInternalFrame frame); /** * Description of the Method * * @param frame Description of Parameter */ public void unregister(BeanContextInternalFrame frame); /** * Description of the Method * * @param frame Description of Parameter */ public void activate(BeanContextInternalFrame frame); } --- NEW FILE: MenuBarService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import javax.swing.JMenuBar; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface MenuBarService extends ToolBarService { /** Description of the Field */ public final static int NO_LAYOUT = 0; /** Description of the Field */ public final static int SEPARATOR_BEFORE = 1; /** Description of the Field */ public final static int SEPARATOR_AFTER = 2; /** * Adds a feature to the MenuBarListener attribute of the MenuBarService * object * * @param mbsl The feature to be added to the MenuBarListener attribute */ public void addMenuBarListener(MenuBarService.Listener mbsl); /** * Description of the Method * * @param mbsl Description of Parameter */ public void removeMenuBarListener(MenuBarService.Listener mbsl); /** * Description of the Class * * @author letiembl * @created 5 novembre 2001 */ public interface Listener { /** * Description of the Method * * @param menuBar Description of Parameter */ public void update(JMenuBar menuBar); } } --- NEW FILE: MenuBarServiceProvider.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.Container; import java.awt.Point; import java.awt.event.MouseEvent; import java.beans.beancontext.BeanContextServiceProvider; import java.beans.beancontext.BeanContextServices; import java.beans.beancontext.BeanContextServicesSupport; import java.util.Iterator; import java.util.ResourceBundle; import java.util.Vector; import javax.swing.Action; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import net.sourceforge.ejtools.awt.action.Command; import net.sourceforge.ejtools.awt.action.CommandAction; import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 2 novembre 2001 * @todo Javadoc to complete */ public class MenuBarServiceProvider extends BeanContextServicesSupport implements BeanContextServiceProvider, MenuBarService { private static Category cat = Category.getInstance(MenuBarServiceProvider.class.getName()); /** Description of the Field */ protected Vector requestors = new Vector(); /** Description of the Field */ protected MenuBarService service = null; /** Description of the Field */ protected Vector listeners = new Vector(); /** Description of the Field */ protected JMenuBar menuBar = new JMenuBar(); /** Constructor for the MenuBarServiceProvider object */ public MenuBarServiceProvider() { this.service = this; } /** * Gets the container attribute of the MenuBarServiceProvider object * * @return The container value */ public Container getContainer() { return this.menuBar; } /** * Gets the service attribute of the ApplicationServiceProvider object * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param serviceClass Description of Parameter * @param serviceSelector Description of Parameter * @return The service value */ public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) { // Check if the requestor has already a service if (!requestors.contains(requestor)) { requestors.add(requestor); } return service; } /** * Gets the currentServiceSelectors attribute of the * ApplicationServiceProvider object * * @param bcs Description of Parameter * @param serviceClass Description of Parameter * @return The currentServiceSelectors value */ public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) { return new Vector().iterator(); } /** * Adds a feature to the MenuBarListener attribute of the * MenuBarServiceProvider object * * @param mbsl The feature to be added to the MenuBarListener attribute */ public void addMenuBarListener(MenuBarService.Listener mbsl) { this.listeners.add(mbsl); } /** * Description of the Method * * @param mbsl Description of Parameter */ public void removeMenuBarListener(MenuBarService.Listener mbsl) { this.listeners.remove(mbsl); } /** * Description of the Method * * @param action Description of Parameter */ public void register(CommandAction action) { String menuName = action.getMenu(); ResourceBundle res = action.getResourceBundle(); JMenu parent = findMenu(menuName); if (parent == null) { parent = addMenu(res, menuName); } addMenuItem(action, parent); } /** * Description of the Method * * @param action Description of Parameter */ public void unregister(CommandAction action) { String menuName = action.getMenu(); JMenu parent = findMenu(menuName); if (parent == null) { return; } removeMenuItem(action, parent); } /** * Description of the Method * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param service Description of Parameter */ public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } /** Description of the Method */ protected void update() { for (int i = 0; i < this.listeners.size(); i++) { MenuBarService.Listener o = (MenuBarService.Listener) this.listeners.elementAt(i); o.update(this.menuBar); } } /** * Adds a feature to the Menu attribute of the MenuBarServiceProvider object * * @param menuName The feature to be added to the Menu attribute * @param res The feature to be added to the Menu attribute * @return Description of the Returned Value */ protected JMenu addMenu(ResourceBundle res, String menuName) { JMenu menu = new JMenu(res.getString(menuName)); menu.setName(menuName); try { menu.setMnemonic(Integer.parseInt(res.getString(menuName + ".mnemonic"))); } catch (Exception e) { } this.menuBar.add(menu); this.update(); return menu; } /** * Adds a feature to the MenuItem attribute of the MenuBarServiceProvider * object * * @param action The feature to be added to the MenuItem attribute * @param menu The feature to be added to the MenuItem attribute */ protected void addMenuItem(CommandAction action, JMenu menu) { JMenuItem item = action.getMenuItem(); if (action.getMenuLayout() == MenuBarService.SEPARATOR_BEFORE) { if (menu.getItemCount() > 0) { menu.addSeparator(); } } (menu.add(item)).setIcon(null); if (action.getMenuLayout() == MenuBarService.SEPARATOR_AFTER) { menu.addSeparator(); } } /** * Description of the Method * * @param action Description of Parameter * @param menu Description of Parameter */ protected void removeMenuItem(CommandAction action, JMenu menu) { JMenuItem item = action.getMenuItem(); menu.remove(item); } /** * Description of the Method * * @param menuName Description of Parameter * @return Description of the Returned Value */ protected JMenu findMenu(String menuName) { for (int i = 0; i < menuBar.getMenuCount(); i++) { JMenu menu = menuBar.getMenu(i); if (menu.getName().equals(menuName)) { return menu; } } return null; } /** Description of the Method */ protected void initializeBeanContextResources() { ((BeanContextServices) getBeanContext()).addService(MenuBarService.class, this); cat.debug("MenuBarService added"); } /** Description of the Method */ protected void releaseBeanContextResources() { ((BeanContextServices) getBeanContext()).revokeService(MenuBarService.class, this, true); cat.debug("MenuBarService removed"); } /** * Description of the Class * * @author letiembl * @created 6 novembre 2001 */ private final class JMenuItemWithFixedTooltip extends JMenuItem { /** * Constructor for the MenuItemWithFixedTooltip object * * @param action Description of Parameter */ public JMenuItemWithFixedTooltip(Action action) { super(action); } /** * Gets the toolTipLocation attribute of the MenuItemWithFixedTooltip * object * * @param e Description of Parameter * @return The toolTipLocation value */ public Point getToolTipLocation(MouseEvent e) { /* * Graphics g = getGraphics(); * FontMetrics metrics = g.getFontMetrics(g.getFont()); * String prefix = itemnameHistory.size() <= 9 ? "8: " : "88: "; * int prefixWidth = metrics.stringWidth(prefix); * int x = JButton.TRAILING + JButton.LEADING - 1 + prefixWidth; */ return new Point(0, 0); } } } --- NEW FILE: PreferencesService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface PreferencesService { /** Description of the Method */ public void show(); /** Description of the Method */ public void load(); /** Description of the Method */ public void save(); } --- NEW FILE: SDIFrameService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.Container; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface SDIFrameService extends FrameService { /** * Sets the content attribute of the SDIFrameService object * * @param c The new content value */ public void setContent(Container c); } --- NEW FILE: StatusBarService.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.beans.beancontext.BeanContextContainerProxy; import javax.swing.Icon; import javax.swing.SwingConstants; /** * Description of the Class * * @author letiembl * @created 25 octobre 2001 * @todo Javadoc to complete */ public interface StatusBarService extends BeanContextContainerProxy { /** Description of the Field */ public final int LEFT = SwingConstants.LEFT; /** Description of the Field */ public final int CENTER = SwingConstants.CENTER; /** Description of the Field */ public final int RIGHT = SwingConstants.RIGHT; /** * Adds a feature to the Zone attribute of the StatusBarService object * * @param name The feature to be added to the Zone attribute */ public void addZone(String name); /** * Adds a feature to the Zone attribute of the StatusBarService object * * @param name The feature to be added to the Zone attribute * @param alignement The feature to be added to the Zone attribute */ public void addZone(String name, int alignement); /** * Description of the Method * * @param name Description of Parameter */ public void removeZone(String name); /** * Sets the content attribute of the StatusBarService object * * @param name The new content value * @param text The new content value */ public void setContent(String name, String text); /** * Sets the content attribute of the StatusBarService object * * @param name The new content value * @param icon The new content value */ public void setContent(String name, Icon icon); /** * Sets the content attribute of the StatusBarService object * * @param name The new content value * @param text The new content value * @param icon The new content value */ public void setContent(String name, String text, Icon icon); } --- NEW FILE: StatusBarServiceProvider.java --- /* * EJTools, the Enterprise Java Tools * * Distributable under LGPL license. * See terms of license at www.gnu.org. */ package net.sourceforge.ejtools.awt.services; import java.awt.Container; import java.beans.beancontext.BeanContextServiceProvider; import java.beans.beancontext.BeanContextServices; import java.beans.beancontext.BeanContextServicesSupport; import java.util.Iterator; import java.util.Vector; import javax.swing.Icon; import javax.swing.JPanel; import org.apache.log4j.Category; /** * Description of the Class * * @author letiembl * @created 2 novembre 2001 * @todo Javadoc to complete */ public class StatusBarServiceProvider extends BeanContextServicesSupport implements BeanContextServiceProvider, StatusBarService { private static Category cat = Category.getInstance(StatusBarServiceProvider.class.getName()); private StatusBarService service = null; private JPanel panel = new JPanel(); /** Constructor for the StatusBarServiceProvider object */ public StatusBarServiceProvider() { service = this; } /** * Sets the content attribute of the StatusBarServiceProvider object * * @param name The new content value * @param text The new content value */ public void setContent(String name, String text) { } /** * Sets the content attribute of the StatusBarServiceProvider object * * @param name The new content value * @param icon The new content value */ public void setContent(String name, Icon icon) { } /** * Sets the content attribute of the StatusBarServiceProvider object * * @param name The new content value * @param text The new content value * @param icon The new content value */ public void setContent(String name, String text, Icon icon) { } /** * Gets the container attribute of the StatusBarServiceProvider object * * @return The container value */ public Container getContainer() { return this.panel; } /** * Gets the service attribute of the ApplicationServiceProvider object * * @param bcs Description of Parameter * @param requestor Description of Parameter * @param serviceClass Description of Parameter * @param serviceSelector Description of Parameter * @return The service value */ public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) { return service; } /** * Gets the currentServiceSelectors attribute of the * ApplicationServiceProvider object * * @param bcs Description of Parameter * @param serviceClass Description of Parameter * @return The currentServiceSelectors value */ public Iterator getCurrentServiceSelectors... [truncated message content] |