From: <de...@us...> - 2008-08-11 21:54:16
|
Revision: 3770 http://fudaa.svn.sourceforge.net/fudaa/?rev=3770&view=rev Author: deniger Date: 2008-08-11 21:54:12 +0000 (Mon, 11 Aug 2008) Log Message: ----------- Modified Paths: -------------- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/EbliWidgetActionAlign.java Added Paths: ----------- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/CommandMove.java Copied: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/CommandMove.java (from rev 3762, branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/EbliWidgetActionUndoRedo.java) =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/CommandMove.java (rev 0) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/CommandMove.java 2008-08-11 21:54:12 UTC (rev 3770) @@ -0,0 +1,67 @@ +package org.fudaa.ebli.visuallibrary.actions; + +import java.awt.Point; +import java.util.Arrays; +import java.util.List; + +import org.fudaa.ctulu.CtuluCommand; +import org.fudaa.ebli.visuallibrary.EbliScene; +import org.netbeans.api.visual.widget.Widget; + +/** + * classe qui permet de faire du undo redo de positions de une ou plusieurs widgets + * + * @author genesis + * + */ +public class CommandMove implements CtuluCommand { + + List<Widget> widgets_; + List<Point> oldPos_; + List<Point> newPos_; + + public CommandMove(List<Widget> _widgets, List<Point> _oldPos, List<Point> _newPos) { + super(); + this.newPos_ = _newPos; + this.oldPos_ = _oldPos; + this.widgets_ = _widgets; + if (_newPos.size() != _oldPos.size()) + throw new IllegalArgumentException("list must ahava the same size"); + if (_widgets.size() != _oldPos.size()) + throw new IllegalArgumentException("list must ahava the same size"); + } + + public CommandMove(Widget _widget, Point _oldPos, Point _newPos) { + super(); + this.newPos_ = Arrays.asList(_newPos); + this.oldPos_ = Arrays.asList(_oldPos); + this.widgets_ = Arrays.asList(_widget); + } + + public void redo() { + final int nb = widgets_.size(); + if (nb == 0) + return; + for (int i = 0; i < nb; i++) { + widgets_.get(i).setPreferredLocation(newPos_.get(i)); + + } + refreshScene(); + } + + private void refreshScene() { + EbliScene.refreshScene(widgets_.get(0).getScene()); + } + + public void undo() { + final int nb = widgets_.size(); + if (nb == 0) + return; + for (int i = 0; i < nb; i++) { + widgets_.get(i).setPreferredLocation(oldPos_.get(i)); + + } + refreshScene(); + } + +} Property changes on: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/CommandMove.java ___________________________________________________________________ Added: svn:mergeinfo + Modified: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/EbliWidgetActionAlign.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/EbliWidgetActionAlign.java 2008-08-11 21:32:37 UTC (rev 3769) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/actions/EbliWidgetActionAlign.java 2008-08-11 21:54:12 UTC (rev 3770) @@ -4,22 +4,23 @@ import java.awt.Point; import java.awt.Rectangle; import java.awt.event.ActionEvent; -import java.beans.PropertyChangeListener; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; -import javax.swing.AbstractAction; +import javax.swing.Icon; -import org.fudaa.ctulu.CtuluCommand; +import org.fudaa.ctulu.CtuluCommandContainer; import org.fudaa.ctulu.CtuluCommandManager; +import org.fudaa.ebli.commun.EbliActionSimple; +import org.fudaa.ebli.ressource.EbliResource; import org.fudaa.ebli.visuallibrary.EbliNode; -import org.fudaa.ebli.visuallibrary.EbliNodeDefault; import org.fudaa.ebli.visuallibrary.EbliScene; -import org.fudaa.ebli.visuallibrary.graphe.EbliWidgetCreatorGraphe; import org.netbeans.api.visual.widget.Widget; +import sun.security.action.GetLongAction; + /** * Action qui permet de realiser l alignement des composants. * @@ -36,154 +37,304 @@ *@author Adrien Hadoux * */ -public class EbliWidgetActionAlign extends AbstractAction { +public abstract class EbliWidgetActionAlign extends EbliActionSimple { - /** - * - */ - private static final long serialVersionUID = 1L; - EbliScene scene_; - public final static int ALIGNLEFT = 0; - public final static int ALIGNRIGHT = 1; - public final static int ALIGNCENTERHORIZONTAL = 2; - public final static int ALIGNCENTERVERTICAL = 3; - public final static int ALIGNTOP = 4; - public final static int ALIGNBOTTOM = 5; + public static class Bottom extends EbliWidgetActionAlign { - int typeAlignement_; - - - CtuluCommandManager cmd_=new CtuluCommandManager() ; + public Bottom(EbliScene _scene) { + super(EbliResource.EBLI.getString("en bas"), EbliResource.EBLI.getToolIcon("aobottom"), "BOTTOM", _scene); + } + @Override + protected List<Point> getNewPositionFor(List<Widget> _widgetToMove) { + // TODO A terminer pour aligner en haut les widget + return null; + } - public EbliWidgetActionAlign(EbliScene _scene, int _typeAlignement) { - super(); - // TODO Auto-generated constructor stub - scene_ = _scene; - typeAlignement_ = _typeAlignement; - // -- renseignements des infos complementaires --// - putValue(NAME, "Alignement " + traduct(_typeAlignement)); + } - } + public static class Center extends EbliWidgetActionAlign { - public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub - alignComponents(); - - - } - + public Center(EbliScene _scene) { + super(EbliResource.EBLI.getString("Centrer verticalement"), EbliResource.EBLI.getToolIcon("aocenterv"), + "CENTERV", _scene); + } - /** - * methode qui recalcule la nouvelle position par rapport a la scene et a l - * alignement choisiT. - */ - - private Point calculeNewLocation(Point _previousLocation, - Rectangle _dimensionWidget, Dimension _dimensionScene) { + @Override + protected List<Point> getNewPositionFor(List<Widget> _widgetToMove) { + // TODO A terminer pour centrer horizontalement les widgets + return null; + } - switch (typeAlignement_) { - case ALIGNLEFT: - return new Point(0, _previousLocation.y); - case ALIGNRIGHT: - return new Point(_dimensionScene.width - _dimensionWidget.width, - _previousLocation.y); - case ALIGNCENTERHORIZONTAL: - return new Point(_dimensionScene.width / 2 - _dimensionWidget.width - / 2, _previousLocation.y); - case ALIGNCENTERVERTICAL: - return new Point(_previousLocation.x, _dimensionScene.height / 2 - - _dimensionWidget.height / 2); - case ALIGNTOP: - return new Point(_previousLocation.x, 0); - case ALIGNBOTTOM: - return new Point(_previousLocation.x, _dimensionScene.height - - _dimensionWidget.height); + } - default: - return _previousLocation; - } + @SuppressWarnings("serial") + public static class Left extends EbliWidgetActionAlign { - } + public Left(EbliScene _scene) { + super(EbliResource.EBLI.getString("Alignement \xE0 gauche"), EbliResource.EBLI.getToolIcon("aoleft"), "LEFT", _scene); + } - private String traduct(int _align) { - switch (typeAlignement_) { - case ALIGNLEFT: - return "\xE0 gauche"; - case ALIGNRIGHT: - return "\xE0 droite"; - case ALIGNCENTERHORIZONTAL: - return "centr\xE9 horizontal"; - case ALIGNCENTERVERTICAL: - return "centr\xE9 vertical"; - case ALIGNTOP: - return "en haut"; - case ALIGNBOTTOM: - return "en bas"; + @Override + protected List<Point> getNewPositionFor(List<Widget> _widgetToMove) { + // on recupere le premier + // minx est le x min dans le repere de la scene + // on est oblige de passer par la car on la location ne suffit pas pour + // determiner + // la position d'un widget: ily a aussi les bounds + int minx = _widgetToMove.get(0).convertLocalToScene(_widgetToMove.get(0).getBounds()).x; + for (Widget widget : _widgetToMove) { + minx = Math.min(minx, widget.convertLocalToScene(widget.getBounds()).x); + } + List<Point> newPoints = new ArrayList<Point>(_widgetToMove.size()); + for (Widget widget : _widgetToMove) { + Point p = widget.getPreferredLocation(); + // celui la ne change pas + int oldY = p.y; + p.x = minx; + widget.getParentWidget().convertSceneToLocal(p); + //maintenant le p.x contient la position de bounds dans le repere qu'il faut. + //la location + bounds.x vaut la postion final du dessin donc + //la location final vaut=le point du dessin - bounds.x + p.x = p.x - widget.getBounds().x; + p.y = oldY; + newPoints.add(p); + } + return newPoints; + } - default: - return ""; - } - } + } - /** - * action alignement qui realise l alignements de tous les composants - */ - public void alignComponents() { + public static class Middle extends EbliWidgetActionAlign { - + public Middle(EbliScene _scene) { + super(EbliResource.EBLI.getString("Centrer horizontalement"), EbliResource.EBLI.getToolIcon("aocenterh"), + "CENTERH", _scene); + } - // -- recuperation de la liste des widgets selectionnees --// + @Override + protected List<Point> getNewPositionFor(List<Widget> _widgetToMove) { + // TODO A terminer pour centrer horizontalement les widgets + return null; + } - Set<EbliNode> listeNode = (Set<EbliNode>) scene_.getSelectedObjects();// scene_ - // . - // getNodes - // ( - // ) - // ; + } - // -- parcours des nodes - for (Iterator<EbliNode> it = listeNode.iterator(); it.hasNext();) { + @SuppressWarnings("serial") + public static class Right extends EbliWidgetActionAlign { - EbliNode currentNode = it.next(); - if (currentNode != null && currentNode.isMovable()) { + public Right(EbliScene _scene) { + super(EbliResource.EBLI.getString("Alignement \xE0 droite"), EbliResource.EBLI.getToolIcon("aoright"), "RIGHT", + _scene); + } - // -- deplacement que si la widget est selectionnee --// - if (currentNode.getCreator().getWidget().getState() - .isSelected()) { + @Override + protected List<Point> getNewPositionFor(List<Widget> _widgetToMove) { + // TODO A terminer pour aligner a droite les widget + return null; + } - // -- enregistrement de la previous position --// - Point previousLocation=currentNode.getPreferedLocation(); + } - // -- calcul de la nouvelle position du node en fonction de - // l alignement choisi --// - Point newLocation = calculeNewLocation(currentNode - .getCreator().getWidget().getLocation(), - currentNode.getCreator().getWidget().getBounds(), - scene_.getView().getSize()); + public static class Top extends EbliWidgetActionAlign { - // -- tentative de modification de la position du node --// - currentNode.setPreferedLocation(newLocation); + public Top(EbliScene _scene) { + super(EbliResource.EBLI.getString("en haut"), EbliResource.EBLI.getToolIcon("aotop"), "TOP", _scene); + } - currentNode.getCreator().getWidget().revalidate(); - currentNode.getCreator().getWidget().repaint(); - - //-- enregistrement de la commande undo redo --// - - //--creation d une commande undo redo --// - EbliWidgetActionUndoRedo cmd=new EbliWidgetActionUndoRedo(newLocation,previousLocation,currentNode.getCreator().getWidget()); - - //-- ajout de la commande undo redo --// - if (cmd_ != null) - cmd_.addCmd(cmd); + @Override + protected List<Point> getNewPositionFor(List<Widget> _widgetToMove) { + // TODO A terminer pour aligner en haut les widget + return null; + } - } - } + } - } - // -- rafraichissement de la scene --// - scene_.refresh(); + /** + * + */ + private static final long serialVersionUID = 1L; + EbliScene scene_; - } + // public final static int ALIGNLEFT = 0; + // + // public final static int ALIGNRIGHT = 1; + // + // public final static int ALIGNCENTERHORIZONTAL = 2; + // + // public final static int ALIGNCENTERVERTICAL = 3; + // + // public final static int ALIGNTOP = 4; + // + // public final static int ALIGNBOTTOM = 5; + // + // int typeAlignement_; + CtuluCommandContainer cmd_; + + public EbliWidgetActionAlign(String name, Icon ic, String id, EbliScene _scene) { + super(name, ic, id); + // TODO Auto-generated constructor stub + scene_ = _scene; + cmd_ = _scene.getCmdMng(); + // typeAlignement_ = _typeAlignement; + // -- renseignements des infos complementaires --// + // putValue(NAME, "Alignement " + traduct(_typeAlignement)); + + } + + public void actionPerformed(ActionEvent e) { + // -- recuperation de la liste des widgets selectionnees --// + Set<EbliNode> listeNode = (Set<EbliNode>) scene_.getSelectedObjects();// scene_ + // pas de selection: on return + if (listeNode == null || listeNode.isEmpty()) + return; + List<Widget> widgetToMove = new ArrayList<Widget>(listeNode.size()); + // liste des anciens points + List<Point> oldSize = new ArrayList<Point>(listeNode.size()); + // -- parcours des nodes + for (Iterator<EbliNode> it = listeNode.iterator(); it.hasNext();) { + + EbliNode currentNode = it.next(); + if (currentNode.isMovable()) { + Widget widget = scene_.findWidget(currentNode); + widgetToMove.add(widget); + oldSize.add(widget.getPreferredLocation()); + } + } + if (widgetToMove.isEmpty()) + return; + // on calcule les nouvelles positions + List<Point> newPos = getNewPositionFor(widgetToMove); + // on met a jour les positions + if (newPos != null) { + for (int i = 0; i < newPos.size(); i++) { + widgetToMove.get(i).setPreferredLocation(newPos.get(i)); + } + } + // on enregistre la commande + if (cmd_ != null) { + cmd_.addCmd(new CommandMove(widgetToMove, oldSize, newPos)); + } + scene_.refresh(); + + } + + /** + * methode qui recalcule la nouvelle position par rapport a la scene et a l + * alignement choisiT. + */ + + // private Point calculeNewLocation(Point _previousLocation, Rectangle + // _dimensionWidget, Dimension _dimensionScene) { + // + // switch (typeAlignement_) { + // case ALIGNLEFT: + // return new Point(0, _previousLocation.y); + // case ALIGNRIGHT: + // return new Point(_dimensionScene.width - _dimensionWidget.width, + // _previousLocation.y); + // case ALIGNCENTERHORIZONTAL: + // return new Point(_dimensionScene.width / 2 - _dimensionWidget.width / 2, + // _previousLocation.y); + // case ALIGNCENTERVERTICAL: + // return new Point(_previousLocation.x, _dimensionScene.height / 2 - + // _dimensionWidget.height / 2); + // case ALIGNTOP: + // return new Point(_previousLocation.x, 0); + // case ALIGNBOTTOM: + // return new Point(_previousLocation.x, _dimensionScene.height - + // _dimensionWidget.height); + // + // default: + // return _previousLocation; + // } + // + // } + /** + * @param _widgetToMove + * non vide et non null + * @return les nouvelles positions correspondantes aux points pass\xE9s en + * parametres + */ + protected abstract List<Point> getNewPositionFor(List<Widget> _widgetToMove); + + // private String traduct(int _align) { + // switch (typeAlignement_) { + // case ALIGNLEFT: + // return "\xE0 gauche"; + // case ALIGNRIGHT: + // return "\xE0 droite"; + // case ALIGNCENTERHORIZONTAL: + // return "centr\xE9 horizontal"; + // case ALIGNCENTERVERTICAL: + // return "centr\xE9 vertical"; + // case ALIGNTOP: + // return "en haut"; + // case ALIGNBOTTOM: + // return "en bas"; + // + // default: + // return ""; + // } + // } + + /** + * action alignement qui realise l alignements de tous les composants + */ + // public void alignComponents() { + // + // // -- recuperation de la liste des widgets selectionnees --// + // + // Set<EbliNode> listeNode = (Set<EbliNode>) scene_.getSelectedObjects();// + // scene_ + // // . + // // getNodes + // // ( + // // ) + // // ; + // + // // -- parcours des nodes + // for (Iterator<EbliNode> it = listeNode.iterator(); it.hasNext();) { + // + // EbliNode currentNode = it.next(); + // if (currentNode != null && currentNode.isMovable()) { + // + // // -- deplacement que si la widget est selectionnee --// + // if (currentNode.getCreator().getWidget().getState().isSelected()) { + // + // // -- enregistrement de la previous position --// + // Point previousLocation = currentNode.getPreferedLocation(); + // + // // -- calcul de la nouvelle position du node en fonction de + // // l alignement choisi --// + // Point newLocation = + // calculeNewLocation(currentNode.getCreator().getWidget().getLocation(), + // currentNode + // .getCreator().getWidget().getBounds(), scene_.getView().getSize()); + // + // // -- tentative de modification de la position du node --// + // currentNode.setPreferedLocation(newLocation); + // + // currentNode.getCreator().getWidget().revalidate(); + // currentNode.getCreator().getWidget().repaint(); + // + // // -- enregistrement de la commande undo redo --// + // + // // --creation d une commande undo redo --// + // CommandMove cmd = new CommandMove(currentNode.getCreator().getWidget(), + // previousLocation, newLocation); + // + // // -- ajout de la commande undo redo --// + // if (cmd_ != null) + // cmd_.addCmd(cmd); + // + // } + // } + // + // } + // // -- rafraichissement de la scene --// + // scene_.refresh(); + // + // } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |