|
|||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| MDIFrameServiceProvider.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* EJTools, the Enterprise Java Tools
|
|
| 3 |
*
|
|
| 4 |
* Distributable under LGPL license.
|
|
| 5 |
* See terms of license at www.gnu.org.
|
|
| 6 |
*/
|
|
| 7 |
package org.ejtools.adwt.service;
|
|
| 8 |
|
|
| 9 |
import java.awt.BorderLayout;
|
|
| 10 |
import java.awt.Dimension;
|
|
| 11 |
import java.awt.Toolkit;
|
|
| 12 |
import java.beans.PropertyVetoException;
|
|
| 13 |
import java.beans.beancontext.BeanContextServices;
|
|
| 14 |
import java.util.Iterator;
|
|
| 15 |
import java.util.Vector;
|
|
| 16 |
|
|
| 17 |
import javax.swing.ButtonGroup;
|
|
| 18 |
import javax.swing.JInternalFrame;
|
|
| 19 |
import javax.swing.WindowConstants;
|
|
| 20 |
|
|
| 21 |
import org.apache.log4j.Logger;
|
|
| 22 |
import org.ejtools.adwt.action.Command;
|
|
| 23 |
import org.ejtools.adwt.action.window.CascadeAction;
|
|
| 24 |
import org.ejtools.adwt.action.window.CloseAction;
|
|
| 25 |
import org.ejtools.adwt.action.window.CloseAllAction;
|
|
| 26 |
import org.ejtools.adwt.action.window.TileAction;
|
|
| 27 |
|
|
| 28 |
/**
|
|
| 29 |
* Description of the Class
|
|
| 30 |
*
|
|
| 31 |
* @author Laurent Etiemble
|
|
| 32 |
* @version $Revision: 1.5 $
|
|
| 33 |
* @todo Javadoc to complete
|
|
| 34 |
*/
|
|
| 35 |
public class MDIFrameServiceProvider extends FrameServiceProvider implements MDIFrameService |
|
| 36 |
{
|
|
| 37 |
/** Description of the Field */
|
|
| 38 |
protected MDIDesktopPane desktop = new MDIDesktopPane(); |
|
| 39 |
/** Description of the Field */
|
|
| 40 |
protected Vector frames = new Vector(); |
|
| 41 |
/** Description of the Field */
|
|
| 42 |
protected ButtonGroup group = new ButtonGroup(); |
|
| 43 |
/** Description of the Field */
|
|
| 44 |
private static Logger logger = Logger.getLogger(MDIFrameServiceProvider.class); |
|
| 45 |
|
|
| 46 |
|
|
| 47 |
/** Constructor for the FrameServiceProvider object */
|
|
| 48 | 0 |
public MDIFrameServiceProvider()
|
| 49 |
{
|
|
| 50 | 0 |
super();
|
| 51 |
} |
|
| 52 |
|
|
| 53 |
|
|
| 54 |
/**
|
|
| 55 |
* Description of the Method
|
|
| 56 |
*
|
|
| 57 |
* @param frame Description of Parameter
|
|
| 58 |
*/
|
|
| 59 | 0 |
public void activate(BeanContextInternalFrame frame) |
| 60 |
{
|
|
| 61 | 0 |
try
|
| 62 |
{
|
|
| 63 | 0 |
JInternalFrame internalFrame = (JInternalFrame) frame.getComponent(); |
| 64 | 0 |
internalFrame.setSelected(true);
|
| 65 | 0 |
this.desktop.getDesktopManager().activateFrame(internalFrame);
|
| 66 |
} |
|
| 67 |
catch (PropertyVetoException e)
|
|
| 68 |
{
|
|
| 69 |
} |
|
| 70 |
} |
|
| 71 |
|
|
| 72 |
|
|
| 73 |
/**
|
|
| 74 |
* Gets the activated attribute of the FrameServiceProvider object
|
|
| 75 |
*
|
|
| 76 |
* @return The activated value
|
|
| 77 |
*/
|
|
| 78 | 0 |
public BeanContextInternalFrame getActivated()
|
| 79 |
{
|
|
| 80 | 0 |
Iterator it = frames.iterator(); |
| 81 | 0 |
while (it.hasNext())
|
| 82 |
{
|
|
| 83 | 0 |
BeanContextInternalFrame frame = (BeanContextInternalFrame) it.next(); |
| 84 | 0 |
if (this.isActivated(frame)) |
| 85 |
{
|
|
| 86 | 0 |
return frame;
|
| 87 |
} |
|
| 88 |
} |
|
| 89 | 0 |
return null; |
| 90 |
} |
|
| 91 |
|
|
| 92 |
|
|
| 93 |
/**
|
|
| 94 |
* Gets the activated attribute of the FrameServiceProvider object
|
|
| 95 |
*
|
|
| 96 |
* @param frame Description of Parameter
|
|
| 97 |
* @return The activated value
|
|
| 98 |
*/
|
|
| 99 | 0 |
public boolean isActivated(BeanContextInternalFrame frame) |
| 100 |
{
|
|
| 101 | 0 |
JInternalFrame selected = this.desktop.getSelectedFrame();
|
| 102 | 0 |
JInternalFrame internalFrame = (JInternalFrame) frame.getComponent(); |
| 103 | 0 |
return selected.equals(internalFrame);
|
| 104 |
} |
|
| 105 |
|
|
| 106 |
|
|
| 107 |
/**
|
|
| 108 |
* Description of the Method
|
|
| 109 |
*
|
|
| 110 |
* @param frame Description of Parameter
|
|
| 111 |
*/
|
|
| 112 | 0 |
public void register(BeanContextInternalFrame frame) |
| 113 |
{
|
|
| 114 | 0 |
JInternalFrame internalFrame = (JInternalFrame) frame.getComponent(); |
| 115 | 0 |
this.frames.add(frame);
|
| 116 | 0 |
this.desktop.add(internalFrame);
|
| 117 | 0 |
this.group.add(frame.getAction().getMenuItem());
|
| 118 |
} |
|
| 119 |
|
|
| 120 |
|
|
| 121 |
/**
|
|
| 122 |
* Description of the Method
|
|
| 123 |
*
|
|
| 124 |
* @param frame Description of Parameter
|
|
| 125 |
*/
|
|
| 126 | 0 |
public void unregister(BeanContextInternalFrame frame) |
| 127 |
{
|
|
| 128 | 0 |
JInternalFrame internalFrame = (JInternalFrame) frame.getComponent(); |
| 129 | 0 |
this.group.remove(frame.getAction().getMenuItem());
|
| 130 | 0 |
this.desktop.remove(internalFrame);
|
| 131 | 0 |
this.frames.remove(frame);
|
| 132 |
} |
|
| 133 |
|
|
| 134 |
|
|
| 135 |
/**
|
|
| 136 |
* @return The serviceClass value
|
|
| 137 |
*/
|
|
| 138 | 0 |
protected Class[] getServiceClass()
|
| 139 |
{
|
|
| 140 | 0 |
return new Class[]{FrameService.class, MDIFrameService.class}; |
| 141 |
} |
|
| 142 |
|
|
| 143 |
|
|
| 144 |
/** Description of the Method */
|
|
| 145 | 0 |
protected void initializeBeanContextResources() |
| 146 |
{
|
|
| 147 | 0 |
super.initializeBeanContextResources();
|
| 148 |
|
|
| 149 | 0 |
BeanContextServices context = (BeanContextServices) this.getBeanContext();
|
| 150 |
|
|
| 151 | 0 |
this.frame.setSize(new Dimension(700, 500)); |
| 152 |
|
|
| 153 | 0 |
this.scrollPane.getViewport().add(desktop);
|
| 154 | 0 |
this.frame.getContentPane().add(BorderLayout.CENTER, scrollPane);
|
| 155 |
|
|
| 156 | 0 |
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); |
| 157 | 0 |
this.frame.setLocation(screen.width / 2 - frame.getSize().width / 2, screen.height / 2 - frame.getSize().height / 2);
|
| 158 | 0 |
this.frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
| 159 |
|
|
| 160 | 0 |
this.add(new CascadeAction( |
| 161 |
new Command()
|
|
| 162 |
{
|
|
| 163 | 0 |
public void execute() |
| 164 |
{
|
|
| 165 | 0 |
MDIFrameServiceProvider.this.desktop.cascadeFrames();
|
| 166 |
} |
|
| 167 |
} |
|
| 168 |
)); |
|
| 169 |
|
|
| 170 | 0 |
this.add(new TileAction( |
| 171 |
new Command()
|
|
| 172 |
{
|
|
| 173 | 0 |
public void execute() |
| 174 |
{
|
|
| 175 | 0 |
MDIFrameServiceProvider.this.desktop.tileFrames();
|
| 176 |
} |
|
| 177 |
} |
|
| 178 |
)); |
|
| 179 |
|
|
| 180 | 0 |
this.add(new CloseAction( |
| 181 |
new Command()
|
|
| 182 |
{
|
|
| 183 | 0 |
public void execute() |
| 184 |
{
|
|
| 185 | 0 |
BeanContextInternalFrame frame = MDIFrameServiceProvider.this.getActivated();
|
| 186 | 0 |
if (frame != null) |
| 187 |
{
|
|
| 188 | 0 |
frame.close(); |
| 189 |
} |
|
| 190 |
} |
|
| 191 |
} |
|
| 192 |
)); |
|
| 193 |
|
|
| 194 | 0 |
this.add(new CloseAllAction( |
| 195 |
new Command()
|
|
| 196 |
{
|
|
| 197 | 0 |
public void execute() |
| 198 |
{
|
|
| 199 | 0 |
while (!MDIFrameServiceProvider.this.frames.isEmpty()) |
| 200 |
{
|
|
| 201 | 0 |
BeanContextInternalFrame frame = (BeanContextInternalFrame) MDIFrameServiceProvider.this.frames.lastElement();
|
| 202 | 0 |
frame.close(); |
| 203 |
} |
|
| 204 |
} |
|
| 205 |
} |
|
| 206 |
)); |
|
| 207 |
|
|
| 208 | 0 |
this.useServices(context);
|
| 209 | 0 |
this.frame.setVisible(true); |
| 210 |
|
|
| 211 | 0 |
logger.debug("MDIFrameService added");
|
| 212 |
} |
|
| 213 |
|
|
| 214 |
|
|
| 215 |
/** */
|
|
| 216 | 0 |
protected void releaseBeanContextResources() |
| 217 |
{
|
|
| 218 | 0 |
super.releaseBeanContextResources();
|
| 219 |
|
|
| 220 | 0 |
logger.debug("MDIFrameService removed");
|
| 221 |
} |
|
| 222 |
} |
|
| 223 |
|
|
||||||||||