From: <de...@us...> - 2008-08-06 21:58:27
|
Revision: 3721 http://fudaa.svn.sourceforge.net/fudaa/?rev=3721&view=rev Author: deniger Date: 2008-08-06 21:58:30 +0000 (Wed, 06 Aug 2008) Log Message: ----------- maj test sur les widgets Modified Paths: -------------- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliScene.java branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidget.java branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidgetRectangle.java Added Paths: ----------- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/OverlayLayoutGap.java Modified: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliScene.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliScene.java 2008-08-06 21:57:43 UTC (rev 3720) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliScene.java 2008-08-06 21:58:30 UTC (rev 3721) @@ -55,25 +55,24 @@ public void setVisu_(LayerWidget visu_) { this.visu_ = visu_; } + @Override protected void notifyNodeAdded(EbliNode node, Widget widget) { -// node.widgetCreated((EbliWidget)widget); + // node.widgetCreated((EbliWidget)widget); } - - @Override protected void attachEdgeSourceAnchor(EbliEdge edge, EbliNode oldSourceNode, EbliNode sourceNode) { // TODO Auto-generated method stub - + } @Override protected void attachEdgeTargetAnchor(EbliEdge edge, EbliNode oldTargetNode, EbliNode targetNode) { // TODO Auto-generated method stub - + } @Override @@ -83,18 +82,19 @@ } @Override - protected Widget attachNodeWidget(EbliNode node ) { - - //-- creation de la widget ici --// - EbliWidget res= node.getCreator().create(this); - - //-- remplissage des proprietes + protected Widget attachNodeWidget(EbliNode node) { + + // -- creation de la widget ici --// + EbliWidget res = node.getCreator().create(this); + + // -- remplissage des proprietes res.setPreferredLocation(node.getLocation()); - res.setPreferredSize(node.getPreferedDimension()); - - //-- ajout dans la vue layer --// + if (node.getPreferedDimension() != null) + res.setPreferredSize(node.getPreferedDimension()); + + // -- ajout dans la vue layer --// visu_.addChild(res); - + return res; } Modified: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidget.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidget.java 2008-08-06 21:57:43 UTC (rev 3720) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidget.java 2008-08-06 21:58:30 UTC (rev 3721) @@ -19,139 +19,152 @@ import org.netbeans.api.visual.widget.Scene; import org.netbeans.api.visual.widget.Widget; - /** * Widget version EBLI + * * @author Adrien Hadoux - * + * */ class EbliWidget extends Widget { + private static final Border RESIZE_BORDER = BorderFactory + .createResizeBorder(8, Color.blue.brighter().brighter(), true); + private static final Border DEFAULT_BORDER = BorderFactory + .createEmptyBorder(8); - private static final Border RESIZE_BORDER = BorderFactory.createResizeBorder(8,Color.blue.brighter().brighter(),true); - private static final Border DEFAULT_BORDER =BorderFactory.createEmptyBorder(8); - - private EbliScene scene_; - - public EbliScene getScene_() { - return scene_; - } + private EbliScene scene_; - public void setScene_(EbliScene scene_) { - this.scene_ = scene_; - } - + public EbliScene getScene_() { + return scene_; + } + + public void setScene_(EbliScene scene_) { + this.scene_ = scene_; + } + /** * @param scene - * @param Point : indiaue la location preferentiel. peut etre nul + * @param Point + * : indiaue la location preferentiel. peut etre nul */ public EbliWidget(EbliScene scene) { super(scene); setScene_(scene); - getActions().addAction( ActionFactory.createResizeAction()); + getActions().addAction(ActionFactory.createResizeAction()); getActions().addAction(ActionFactory.createMoveAction()); getActions().addAction(scene.createWidgetHoverAction()); - //getActions().addAction( scene.createSelectAction()); + // getActions().addAction( scene.createSelectAction()); - setBorder(getScene().getLookFeel().getMiniBorder(ObjectState.createNormal())); + setBorder(DEFAULT_BORDER); // positionnement de la widget si precise -// if(preferredLocation!=null) -// setPreferredLocation(preferredLocation); + // if(preferredLocation!=null) + // setPreferredLocation(preferredLocation); - //menu clic droit basique (fermeture, duplication) + // menu clic droit basique (fermeture, duplication) setMenu(); } @Override - public void notifyStateChanged(ObjectState previousState, ObjectState newState) { + public void notifyStateChanged(ObjectState previousState, + ObjectState newState) { LookFeel lookFeel = getScene().getLookFeel(); // setBorder(lookFeel.getMiniBorder(newState)); - - setBorder( newState.isSelected() ? ( - newState.isHovered() ? RESIZE_BORDER : lookFeel.getMiniBorder(newState)) : ( - newState.isHovered() ? RESIZE_BORDER : lookFeel.getMiniBorder(newState))); + if (!newState.isHovered() || !newState.isSelected()) { + setBorder(DEFAULT_BORDER); + return; + } + setBorder(newState.isSelected() ? (newState.isHovered() ? RESIZE_BORDER + : lookFeel.getMiniBorder(newState)) + : (newState.isHovered() ? RESIZE_BORDER : lookFeel + .getMiniBorder(newState))); } - /** - * Methode generique qui fait apparaitre un menuItem propre au composant et offre les op\xE9rations de base - * on ouvre le menu via le clic droit ou le raccourcis shift+F10 + * Methode generique qui fait apparaitre un menuItem propre au composant et + * offre les op\xE9rations de base on ouvre le menu via le clic droit ou le + * raccourcis shift+F10 */ public void setMenu() { - getActions ().addAction (ActionFactory.createPopupMenuAction (new PopupMenuProvider() { - public JPopupMenu getPopupMenu (Widget widget, Point localLocation) { - JPopupMenu popup = new JPopupMenu (); + getActions().addAction( + ActionFactory.createPopupMenuAction(new PopupMenuProvider() { + public JPopupMenu getPopupMenu(Widget widget, + Point localLocation) { + JPopupMenu popup = new JPopupMenu(); - //-- creation du menu commun a tous les widgets - constructPopupMenuBase(popup); - - - return popup; - } - })); + // -- creation du menu commun a tous les widgets + constructPopupMenuBase(popup); + + return popup; + } + })); } - /** * Methode de construction des menus de base + * * @param _popup */ - public void constructPopupMenuBase(JPopupMenu _popup){ - JMenuItem menuItem1=_popup.add ("Dupliquer l'objet"); + public void constructPopupMenuBase(JPopupMenu _popup) { + JMenuItem menuItem1 = _popup.add("Dupliquer l'objet"); menuItem1.setIcon(CtuluResource.CTULU.getIcon("crystal22_cascade")); - menuItem1.addActionListener(new ActionListener(){ + menuItem1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - //position a cote de l element initial - Point nouvellePosition=new Point((int)(EbliWidget.this.getLocation().x+EbliWidget.this.getClientArea().width/2),(int)(EbliWidget.this.getLocation().y+EbliWidget.this.getClientArea().height/2)); + // position a cote de l element initial + Point nouvellePosition = new Point( + (int) (EbliWidget.this.getLocation().x + EbliWidget.this + .getClientArea().width / 2), + (int) (EbliWidget.this.getLocation().y + EbliWidget.this + .getClientArea().height / 2)); EbliWidget duplique; try { - //clonage de l'objet - duplique=(EbliWidget)EbliWidget.this.clone(); - duplique.setPreferredSize(EbliWidget.this.getScene().getPreferredSize()); + // clonage de l'objet + duplique = (EbliWidget) EbliWidget.this.clone(); + duplique.setPreferredSize(EbliWidget.this.getScene() + .getPreferredSize()); duplique.setPreferredLocation(nouvellePosition); - - //-- ajout dans la scene --// - if(EbliWidget.this.getScene()!=null){ + + // -- ajout dans la scene --// + if (EbliWidget.this.getScene() != null) { EbliWidget.this.getScene().addChild(duplique); } - + } catch (CloneNotSupportedException e1) { - // TODO que fqire si ca pete? une peite fenetre d'erreur, widget pas duplicable? ou alors surcharger la methode dans les filles? + // TODO que fqire si ca pete? une peite fenetre d'erreur, + // widget pas duplicable? ou alors surcharger la methode + // dans les filles? e1.printStackTrace(); } } }); - JMenuItem menuItem2=_popup.add ("Fermer l'objet"); + JMenuItem menuItem2 = _popup.add("Fermer l'objet"); menuItem2.setIcon(CtuluResource.CTULU.getIcon("crystal_non")); - menuItem2.addActionListener(new ActionListener(){ + menuItem2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { EbliWidget.this.setVisible(false); - EbliNode n=(EbliNode)EbliWidget.this.getScene_().findObject(EbliWidget.this); + EbliNode n = (EbliNode) EbliWidget.this.getScene_().findObject( + EbliWidget.this); EbliWidget.this.getScene_().removeNode(n); - + // NE PAS DECOCHER CES ELEMENTS - //fermeture des widgets children - //EbliWidget.this.removeChildren(); - //fermeture du widget donne - //EbliWidget.this.removeFromParent(); - + // fermeture des widgets children + // EbliWidget.this.removeChildren(); + // fermeture du widget donne + // EbliWidget.this.removeFromParent(); } }); } - - } \ No newline at end of file Modified: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidgetRectangle.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidgetRectangle.java 2008-08-06 21:57:43 UTC (rev 3720) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/EbliWidgetRectangle.java 2008-08-06 21:58:30 UTC (rev 3721) @@ -1,7 +1,8 @@ package org.fudaa.ebli.visuallibrary; - +import java.awt.Color; import java.awt.Graphics2D; +import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; @@ -17,84 +18,100 @@ import org.netbeans.api.visual.widget.LabelWidget; import org.netbeans.api.visual.widget.Scene; import org.netbeans.api.visual.widget.Widget; +import org.netbeans.api.visual.widget.LabelWidget.VerticalAlignment; import org.netbeans.modules.visual.layout.FlowLayout; +import org.netbeans.modules.visual.layout.OverlayLayout; - - /** - * Legende - * Widget qui permet de construire des rectangles avec du texte + * Legende Widget qui permet de construire des rectangles avec du texte + * * @author Adrien Hadoux - * + * */ -public class EbliWidgetRectangle extends EbliWidget implements TextFieldInplaceEditor{ +public class EbliWidgetRectangle extends EbliWidget implements + TextFieldInplaceEditor { - + LabelWidget intern; + Insets inGaps_; + int largeurBorder = 15; + int espaceInterieur = 5; - LabelWidget intern; + /** + * @param _scene + */ + public EbliWidgetRectangle(EbliScene _scene, String label) { + super(_scene); + inGaps_ = new Insets(largeurBorder + espaceInterieur, largeurBorder + + espaceInterieur, largeurBorder + espaceInterieur, + largeurBorder + espaceInterieur); + // Ce layout permet de placer le texte + setLayout(new OverlayLayoutGap(inGaps_)); + intern = new LabelWidget(_scene); + intern.setVerticalAlignment(VerticalAlignment.CENTER); + intern.setLabel(label); - /** - * @param _scene - */ - public EbliWidgetRectangle(EbliScene _scene, String label) { - super(_scene); - setLayout(new FlowLayout(true, SerialAlignment.CENTER, 23)); - intern = new LabelWidget(_scene); - intern.setLabel(label); - - addChild(intern); - - //-- ajouter l option de remplacer le text dans le label --// - - //-- creation de l action --// - WidgetAction editorAction = ActionFactory.createInplaceEditorAction (this); - - //-- ajout de l action au label correspondant --// - intern.getActions ().addAction (editorAction); - - intern.getActions ().addAction( ActionFactory.createResizeAction()); - - - //setEnabled(false); - } - - public void majLabel(String label){ - //intern.setForeground(); - intern.setLabel(label); - } - + addChild(intern); - protected void paintWidget() { - Graphics2D g = getGraphics(); - Rectangle rec = getClientArea(); - g.translate(rec.x, rec.y); - //la ligne - - TraceLigne l = new TraceLigne(); - l.setEpaisseur(5); - //l.dessineTrait(g, 0, 0, rec.width, rec.height / 2); - l.dessineRectangle(g, 0, 0, rec.width, rec.height); - g.translate(-rec.x, -rec.y); - } + // -- ajouter l option de remplacer le text dans le label --// + // -- creation de l action --// + WidgetAction editorAction = ActionFactory + .createInplaceEditorAction(this); + // -- ajout de l action au label correspondant --// + intern.getActions().addAction(editorAction); + intern.getActions().addAction(ActionFactory.createResizeAction()); + // setEnabled(false); + } + + public void majLabel(String label) { + // intern.setForeground(); + intern.setLabel(label); + revalidate(); + } + + @Override + protected Rectangle calculateClientArea() { + Rectangle res = intern.getPreferredBounds(); + // TODO Auto-generated method stub + return new Rectangle(0, 0, 2 * (largeurBorder + espaceInterieur) + + res.width, 2 * (largeurBorder + espaceInterieur) + res.height); + } + + protected void paintWidget() { + Graphics2D g = getGraphics(); + + Rectangle rec = getClientArea(); + g.translate(rec.x, rec.y); + // la ligne + + TraceLigne l = new TraceLigne(); + + l.setEpaisseur(largeurBorder); + // l.dessineTrait(g, 0, 0, rec.width, rec.height / 2); + l.dessineRectangle(g, l.getEpaisseur() / 2, l.getEpaisseur() / 2, + rec.width - l.getEpaisseur(), rec.height - l.getEpaisseur()); + g.translate(-rec.x, -rec.y); + g.setColor(Color.RED); + g.draw(getBounds()); + g.draw(getClientArea()); + } + public String getText(Widget widget) { - return ((LabelWidget) widget).getLabel (); + return ((LabelWidget) widget).getLabel(); } public boolean isEnabled(Widget widget) { // TODO Auto-generated method stub - return true; + return true; } public void setText(Widget widget, String text) { - ((LabelWidget) widget).setLabel (text); - + ((LabelWidget) widget).setLabel(text); + revalidate(); + } - - - } \ No newline at end of file Added: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/OverlayLayoutGap.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/OverlayLayoutGap.java (rev 0) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/OverlayLayoutGap.java 2008-08-06 21:58:30 UTC (rev 3721) @@ -0,0 +1,62 @@ +package org.fudaa.ebli.visuallibrary; + +import java.awt.Dimension; +import java.awt.Insets; +import java.awt.Point; +import java.awt.Rectangle; + +import org.netbeans.api.visual.layout.Layout; +import org.netbeans.api.visual.widget.Widget; + +public class OverlayLayoutGap implements Layout { + + Insets inGaps_; + + public OverlayLayoutGap(Insets _inGaps) { + super(); + inGaps_ = _inGaps; + } + + public void layout(Widget widget) { + Dimension total = new Dimension(); + for (Widget child : widget.getChildren()) { + if (!child.isVisible()) + continue; + Dimension size = child.getPreferredBounds().getSize(); + if (size.width > total.width) + total.width = size.width; + if (size.height > total.height) + total.height = size.height; + } + total.width -= inGaps_.left + inGaps_.right; + total.height -= inGaps_.top + inGaps_.bottom; + for (Widget child : widget.getChildren()) { + Point location = child.getPreferredBounds().getLocation(); + child.resolveBounds(new Point(-location.x+inGaps_.left, -location.y+inGaps_.top), + new Rectangle(location, total)); + } + } + + public boolean requiresJustification(Widget widget) { + return true; + } + + public void justify(Widget widget) { + Rectangle clientArea = widget.getClientArea(); + clientArea.x+=inGaps_.left; + clientArea.y+=inGaps_.top; + clientArea.width -= inGaps_.left + inGaps_.right; + clientArea.height -= inGaps_.top + inGaps_.bottom; + for (Widget child : widget.getChildren()) { + if (child.isVisible()) { + Point location = child.getPreferredBounds().getLocation(); + child.resolveBounds(new Point(clientArea.x - location.x, + clientArea.y - location.y), new Rectangle(location, + clientArea.getSize())); + } else { + child.resolveBounds(clientArea.getLocation(), new Rectangle()); + } + } + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |