From: <de...@us...> - 2008-09-03 16:55:51
|
Revision: 3874 http://fudaa.svn.sourceforge.net/fudaa/?rev=3874&view=rev Author: deniger Date: 2008-09-03 16:55:56 +0000 (Wed, 03 Sep 2008) Log Message: ----------- Added Paths: ----------- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/calque/EbliWidgetCalqueLegende.java Added: branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/calque/EbliWidgetCalqueLegende.java =================================================================== --- branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/calque/EbliWidgetCalqueLegende.java (rev 0) +++ branches/Prepro-0.92-SNAPSHOT/ebli/src/org/fudaa/ebli/visuallibrary/calque/EbliWidgetCalqueLegende.java 2008-09-03 16:55:56 UTC (rev 3874) @@ -0,0 +1,207 @@ +package org.fudaa.ebli.visuallibrary.calque; + +import java.awt.Dimension; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Rectangle; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.EnumSet; +import java.util.Iterator; +import java.util.List; + +import javax.swing.JComponent; + +import org.fudaa.ebli.calque.BCalqueLegendePanel; +import org.fudaa.ebli.palette.PaletteSelecteurCouleurPlage; +import org.fudaa.ebli.visuallibrary.EbliScene; +import org.fudaa.ebli.visuallibrary.EbliWidget; +import org.netbeans.api.visual.action.ActionFactory; +import org.netbeans.api.visual.action.InplaceEditorProvider; +import org.netbeans.api.visual.action.WidgetAction; +import org.netbeans.api.visual.action.InplaceEditorProvider.ExpansionDirection; +import org.netbeans.api.visual.widget.LabelWidget; +import org.netbeans.api.visual.widget.Widget; + +import com.memoire.fu.FuLog; + +/** + * Creation de la classe widget specifique au calque. Permet de gerer le resize via le changement de font + */ +public class EbliWidgetCalqueLegende extends EbliWidget implements InplaceEditorProvider<JComponent>, + PropertyChangeListener { + + BCalqueLegendePanel legendePanel_; + // BArbreCalqueModel modelTree_; + boolean maj = true; + Font oldFont_; + + public EbliWidgetCalqueLegende(EbliScene _scene, boolean _controller/* , BArbreCalqueModel model */, + BCalqueLegendePanel _legendePanel) { + super(_scene, _controller); + oldFont_ = getFormeFont(); + // -- la legende est un listener des modifs de son calque --// + _legendePanel.getCalque().addPropertyChangeListener("paletteCouleur", this); + _legendePanel.getCalque().addPropertyChangeListener("paletteTitle", this); + + // modelTree_.addTreeModelListener(this); + + legendePanel_ = _legendePanel; + setEnabled(true); + + // -- creation de l action edition des labels --// + WidgetAction editorAction = ActionFactory.createInplaceEditorAction(this); + // -- ajout de l action au label correspondant --// + this.getActions().addAction(editorAction); + + } + + /** + * Methode qui cree l editeur du calque. + */ + public JComponent createEditorComponent( + org.netbeans.api.visual.action.InplaceEditorProvider.EditorController _controller, Widget _widget) { + if (PaletteSelecteurCouleurPlage.isTargetValid(legendePanel_.getCalque())) { + PaletteSelecteurCouleurPlage palette = new PaletteSelecteurCouleurPlage(); + palette.setPalettePanelTarget(legendePanel_.getCalque()); + palette.setSize(this.getBounds().width, this.getBounds().height); + palette.setMaximumSize(new Dimension(this.getBounds().width, this.getBounds().height)); + palette.setPreferredSize(new Dimension(this.getBounds().width, this.getBounds().height)); + return palette; + } + + return null; + } + + public EnumSet<org.netbeans.api.visual.action.InplaceEditorProvider.ExpansionDirection> getExpansionDirections( + org.netbeans.api.visual.action.InplaceEditorProvider.EditorController _controller, Widget _widget, + JComponent _editor) { + return null; + } + + public Rectangle getInitialEditorComponentBounds( + org.netbeans.api.visual.action.InplaceEditorProvider.EditorController _controller, Widget _widget, + JComponent _editor, Rectangle _viewBounds) { + return null; + } + + public void notifyClosing(org.netbeans.api.visual.action.InplaceEditorProvider.EditorController _controller, + Widget _widget, JComponent _editor, boolean _commit) { + // + // + // reconstructWidget(this, legendePanel_, getEbliScene(), modelTree_); + // this.getEbliScene().refresh(); + } + + public void notifyOpened(org.netbeans.api.visual.action.InplaceEditorProvider.EditorController _controller, + Widget _widget, JComponent _editor) {} + + protected void notifyRemoved() { + legendePanel_.getCalque().removePropertyChangeListener("paletteCouleur", this); + legendePanel_.getCalque().removePropertyChangeListener("paletteTitle", this); + } + + protected void paintWidget() { + + // -- mise a jour de la fonte que si il y a eu une modification --// + if (oldFont_ != getFormeFont() || maj) { + maj = false; + // -- calcul des max height et width pour resize les composants --// + Rectangle newBounds = resizeMaxLegende(); + + // -- mise a jour de la widget avec la nouvelle font + List<Widget> listePlage = getChildren(); + for (Iterator<Widget> it = listePlage.iterator(); it.hasNext();) { + Widget widget = it.next(); + // -- test si il s agit d un widget plage --// + if (widget instanceof EbliWidgetPlageTitle) { + EbliWidgetPlageTitle new_widget = (EbliWidgetPlageTitle) widget; + new_widget.getIntern().setFont(getFormeFont()); + new_widget.getIntern().majText(); + FuLog.warning("MA plage: " + new_widget.plage_.getLegende()); + + // -- mise du nouveau bounds max --// + Rectangle boundsIntern = new_widget.getIntern().getBounds(); + boundsIntern.width = newBounds.width; + boundsIntern.height = (int) (newBounds.height); + + new_widget.getIntern().setPreferredBounds(boundsIntern); + + // resize pour le logo: forme carr\xE9 + Rectangle boundsLogo = new_widget.getLogo_().getBounds(); + boundsLogo.height = (int) (newBounds.height); + boundsLogo.width = (int) (newBounds.height); + new_widget.getLogo_().setPreferredBounds(boundsLogo); + new_widget.getLogo_().repaint(); + + } else if (widget instanceof LabelWidget) { + LabelWidget new_widget = (LabelWidget) widget; + + new_widget.setFont(getFormeFont()); + Rectangle boundsTitre = new_widget.getBounds(); + boundsTitre.width = newBounds.width; + boundsTitre.height = (int) (newBounds.height); + new_widget.setPreferredBounds(boundsTitre); + } + + } + // Resize de la widget + + Rectangle newBoundConteneurs = getParentWidget().getBounds(); + newBoundConteneurs.height = (int) ((listePlage.size() + 1) * (newBounds.height * 1.5));// ( + newBoundConteneurs.width = (int) (newBounds.width * 1.5); + getParentWidget().setPreferredBounds(newBoundConteneurs); + getEbliScene().refresh(); + oldFont_ = getFormeFont(); + + } + + } + + /** + * Si la palette est modifiee on change la widget + */ + public void propertyChange(PropertyChangeEvent _evt) { + rebuildWidget(); + + } + + private void rebuildWidget() { + this.removeChildren(); + + CalqueLegendeWidgetAdapter.reconstructWidget(this, legendePanel_, getEbliScene()); + this.getEbliScene().refresh(); + } + + protected Rectangle resizeMaxLegende() { + this.getGraphics().setFont(getFormeFont()); + int maxHeight = 0; + int maxWidth = 0; + // -- mise a jour de la widget avec la nouvelle font + List<Widget> listePlage = getChildren(); + for (Iterator<Widget> it = listePlage.iterator(); it.hasNext();) { + Widget widget = it.next(); + // -- test si il s agit d un widget plage --// + if (widget instanceof EbliWidgetPlageTitle) { + EbliWidgetPlageTitle new_widget = (EbliWidgetPlageTitle) widget; + + // -- recuperation des tailles des font pour les textes saisies + + FontMetrics ftm = this.getGraphics().getFontMetrics(); + + int newWidth = ftm.stringWidth(new_widget.getIntern().getLabel()); + int newHeight = ftm.getHeight(); + if (maxWidth < newWidth) maxWidth = newWidth; + maxHeight = newHeight; + + } + + } + Rectangle newBounds = new Rectangle(); + newBounds.height /* + */= maxHeight; + newBounds.width /* + */= maxWidth; + + return newBounds; + } + +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |