Revision 15144 import/ext3D/trunk/JDialogSkin/src/com/iver/core/mdiManager/FrameWindowSupport.java

View differences:

FrameWindowSupport.java
45 45
import java.awt.Container;
46 46
import java.awt.Image;
47 47
import java.awt.Panel;
48
import java.awt.Point;
49
import java.awt.Rectangle;
48 50
import java.awt.Window;
49 51
import java.util.Hashtable;
50 52
import java.util.Iterator;
......
147 149
    
148 150
    public JDialog createFrame(IWindow p)
149 151
    {
150
        WindowInfo vi = vis.getWindowInfo(p);
152
        WindowInfo windowInfo = vis.getWindowInfo(p);
151 153
        JDialog frame = new JDialog(mainFrame, false);
152
        /*if (icon!=null) {
153
        	frame.setIconImage(icon);
154
        }*/
155 154
        frame.getContentPane().add((JPanel) p);
156
        frame.setSize(getWidth(p, vi), getHeight(p, vi));
157
        frame.setTitle(vi.getTitle());
158
        frame.setVisible(vi.isVisible());
159
        frame.setResizable(vi.isResizable());
160
        frame.setLocation(vi.getX(), vi.getY());
155
        frame.setTitle(windowInfo.getTitle());
156
        frame.setBounds(calculateBounds(p, windowInfo));
157
        frame.setVisible(windowInfo.isVisible());
158
        frame.setResizable(windowInfo.isResizable());
161 159
        frame.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
160
        updateWindowInfo(frame, windowInfo);
162 161
        return frame;
163 162
    }
164 163

  
165
    public JInternalFrame createJInternalFrame(IWindow p)
164
   /* public JInternalFrame createJInternalFrame(IWindow p)
166 165
    {
167 166
        WindowInfo vi = vis.getWindowInfo(p);
168 167
        JInternalFrame nuevo = new JInternalFrame();
......
183 182

  
184 183
        nuevo.setDefaultCloseOperation(JInternalFrame.DISPOSE_ON_CLOSE);
185 184
        return nuevo;
186
    }
185
    }*/
187 186
    
188 187
    public IWindow getWindow(Component dlg){
189 188
    	return (IWindow) frameView.get(dlg);
......
283 282
            return wi.getWidth();
284 283
        }
285 284
    }
286
    
285

  
287 286
    /**
288 287
     * DOCUMENT ME!
289 288
     *
......
300 299
            return wi.getHeight();
301 300
        }
302 301
    }
302

  
303
    private Rectangle calculateBounds(IWindow win, WindowInfo wi) {
304
    	Rectangle bounds = new Rectangle();
305
        if (wi.getWidth() == -1) {
306
            JPanel p = (JPanel) win;
307

  
308
            bounds.width = p.getSize().width;
309
        } else {
310
            bounds.width = wi.getWidth();
311
        }
312
        
313
        if (wi.getHeight() == -1) {
314
            JPanel p = (JPanel) win;
315

  
316
            bounds.height = p.getSize().height;
317
        } else {
318
            bounds.height = wi.getHeight();
319
        }
320
    	
321
    	Rectangle frame = mainFrame.getBounds();
322
        if (wi.getX() == -1) {
323
            bounds.x = frame.x + (int)(Math.random()*(frame.width-bounds.width));
324
            if (bounds.x<0)
325
            	bounds.x = 0;
326
        } else {
327
        	bounds.x = wi.getX();
328
        }
329
        if (wi.getY() == -1) {
330
        	// 135: because we don't want it to be placed at the upmost part of the window
331
        	bounds.y = frame.y + 135 + (int)(Math.random()*(frame.height-bounds.height-135));
332
        	if (bounds.y<0)
333
        		bounds.y = 135;
334
        } else {
335
            bounds.y = wi.getY();
336
        }
337
        return bounds;
338
    }
303 339
    
340
    private void updateWindowInfo(Container container, WindowInfo windowInfo) {
341
		windowInfo.setWidth(container.getWidth());
342
		windowInfo.setHeight(container.getHeight());
343
		windowInfo.setX(container.getX());
344
		windowInfo.setY(container.getY());
345
		windowInfo.setClosed(!container.isShowing());
346
		if (container instanceof JFrame) {
347
			JFrame frame = (JFrame) container;
348
			if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) {
349
				windowInfo.setMaximized(true);
350
			}
351
			else {
352
				windowInfo.setMaximized(false);
353
				windowInfo.setNormalBounds(frame.getBounds());
354
			}
355
		}
356
    }
357
   
358
    /**
359
     * Updates the windowInfo object, so that it correctly reflects the
360
     * current frame properties.
361
     * 
362
     * @param win
363
     * @param windowInfo The WindowInfo object to update
364
     */
304 365
    public void updateWindowInfo(IWindow win, WindowInfo windowInfo) {
305 366
    	Object o = viewFrame.get(win);
306 367
    	if (windowInfo!=null && o!=null) {
307 368
    		if (o instanceof Container) {
308
    			Container component = (Container) o;
309
        		windowInfo.setWidth(component.getWidth());
310
				windowInfo.setHeight(component.getHeight());
311
				windowInfo.setX(component.getX());
312
				windowInfo.setY(component.getY());
313
				windowInfo.setClosed(!component.isShowing());
314
				if (component instanceof JFrame) {
315
					JFrame frame = (JFrame) component;
316
					if ((frame.getExtendedState() & JFrame.MAXIMIZED_BOTH) == JFrame.MAXIMIZED_BOTH) {
317
						windowInfo.setMaximized(true);
318
					}
319
					else {
320
						windowInfo.setMaximized(false);
321
						windowInfo.setNormalBounds(frame.getBounds());
322
					}
323
				}
369
    			updateWindowInfo((Container) o, windowInfo);
324 370
    		}
325 371
    	}
326 372
    }

Also available in: Unified diff