Author: tchemit Date: 2008-04-27 08:23:03 +0000 (Sun, 27 Apr 2008) New Revision: 620 Modified: trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java Log: ajout du positionnement de ui par rapport a parent (?\195?\160 finir pour le center) Modified: trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java =================================================================== --- trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java 2008-04-27 08:22:28 UTC (rev 619) +++ trunk/lutinui/src/main/java/org/codelutin/ui/ShowUIAction.java 2008-04-27 08:23:03 UTC (rev 620) @@ -14,6 +14,9 @@ */ package org.codelutin.ui; +import java.awt.Dimension; +import java.awt.Point; + /** @author chemit */ public abstract class ShowUIAction<M extends DialogUIModel, U extends DialogUI<H>, H extends DialogUIHandler<M, U>, HH extends org.codelutin.ui.DialogUIHandler<?, ?>> extends AbstractUIAction<HH> { @@ -23,6 +26,10 @@ protected transient UIFactory factory; + protected String position; + + protected boolean undecorated = true; + protected abstract U initUI(java.awt.event.ActionEvent e); public <UU extends DialogUI<HH>> ShowUIAction(UU ui, DialogUIDef<M, U, H> uiDef, UIFactory factory, boolean showText) { @@ -42,22 +49,69 @@ return uiDef; } + public UIFactory getFactory() { + return factory; + } + public void setUiDef(DialogUIDef<M, U, H> uiDef) { this.uiDef = uiDef; } - public UIFactory getFactory() { - return factory; + public void setPosition(String position) { + this.position = position; } + public void setUndecorated(boolean undecorated) { + this.undecorated = undecorated; + } + public void actionPerformed(java.awt.event.ActionEvent e) { checkInit(); U ui = initUI(e); ui.setTitle(uiDef.getUiTitle()); log.info(ui.getTitle()); + //TODO ui.setUndecorated(undecorated); + setPosition(this.ui, ui, position); + ui.setVisible(true); } + protected void setPosition(javax.swing.JDialog parentUI, javax.swing.JDialog ui, String position) { + if (position == null || parentUI == null) { + return; + } + Point parentLocation = parentUI.getLocationOnScreen(); + Dimension parentSize = parentUI.getSize(); + + if (position.equals("bottom-left")) { + int top = (int) (parentLocation.getY() + parentSize.getHeight()); + int left = (int) (parentLocation.getX()); + Point newLocation = new Point(left, top); + newLocation.setLocation(left, top); + ui.setLocation(newLocation); + return; + } + if (position.equals("top-left")) { + int top = (int) (parentLocation.getY()); + int left = (int) (parentLocation.getX()); + Point newLocation = new Point(left, top); + newLocation.setLocation(left, top); + ui.setLocation(newLocation); + return; + } + if (position.equals("top-right")) { + int top = (int) (parentLocation.getY()); + int left = (int) (parentLocation.getX() + parentSize.getWidth()); + Point newLocation = new Point(left, top); + newLocation.setLocation(left, top); + ui.setLocation(newLocation); + return; + } + if (position.equals(("center"))) { + //TODO + } + } + @Override protected void checkInit() throws IllegalStateException { super.checkInit();
participants (1)
-
tchemit@users.labs.libre-entreprise.org