r2955 - in isis-fish/branches/3.3.1/src: main/java/fr/ifremer/isisfish/ui/widget test/java/fr/ifremer/isisfish/ui/widget
Author: chatellier Date: 2010-01-28 10:17:53 +0000 (Thu, 28 Jan 2010) New Revision: 2955 Added: isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/FormInterval.java isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/IntervalPanelTest.java Removed: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/FormInterval.java Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/Interval.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalGraphic.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalLabel.java isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalPanel.java Log: Update interval panel code, move main() to unit test Deleted: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/FormInterval.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/FormInterval.java 2010-01-28 09:48:10 UTC (rev 2954) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/FormInterval.java 2010-01-28 10:17:53 UTC (rev 2955) @@ -1,48 +0,0 @@ -/* *##% - * Copyright (C) 2002 - 2009 Code Lutin - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%*/ - -package fr.ifremer.isisfish.ui.widget; - -import java.awt.Frame; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; - -/** - * FormInterval. - */ -public class FormInterval extends Frame { - - /** serialVersionUID. */ - private static final long serialVersionUID = 4911081593147906648L; - - class QuitListener extends WindowAdapter { - public void windowClosing(WindowEvent e) { - e.getWindow().dispose(); - } - } - - public FormInterval(Interval i) { - IntervalPanel ip = new IntervalPanel(); - this.add(ip); - // ip.setEnabled(false); - ip.setModel(i); - - this.addWindowListener(new QuitListener()); - pack(); - } -} Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/Interval.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/Interval.java 2010-01-28 09:48:10 UTC (rev 2954) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/Interval.java 2010-01-28 10:17:53 UTC (rev 2955) @@ -1,5 +1,5 @@ /* ##%% - * Copyright (C) 2002 - 2009 Code Lutin + * Copyright (C) 2002 - 2010 Ifremer, Code Lutin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -69,7 +69,9 @@ } /** - * Retourne le nombre minimal que peut prendre comme valeur cette interval + * Retourne le nombre minimal que peut prendre comme valeur cette interval. + * + * @return interval minimal value */ public int getMin() { return min; @@ -84,7 +86,9 @@ } /** - * Retourne le nombre maximal que peut prendre comme valeur cette interval + * Retourne le nombre maximal que peut prendre comme valeur cette interval. + * + * @return interval maximal value */ public int getMax() { return max; @@ -202,9 +206,10 @@ } /** - * retourne une chaine XML qui represente l'objet. + * Retourne une chaine XML qui represente l'objet. * * @deprecated since 20090414 (unused) + * @return interval representation as xml */ public String toXML() { return "<Interval min=\"" + getMin() + "\" max=\"" + getMax() @@ -213,27 +218,9 @@ } /** - * Retourne une representation string de la valeur donne. - * - * @deprecated since 20090414 (unused) - */ - public String getString(int entier) { - return String.valueOf(entier); - } - - /** - * Retourne une representation entiere de la valeur String donne - * - * @deprecated since 20090414 (unused) - */ - public int getString(String ch) { - return Integer.parseInt(ch); - } - - /** * @return une iteration */ - public Iterator iterator() { + public Iterator<Integer> iterator() { return new IntervalIterator(getMin(), getMax(), getFirst(), getLast()); } @@ -262,8 +249,8 @@ return result; } - public static class IntervalIterator implements Iterator { - private int min; + public static class IntervalIterator implements Iterator<Integer> { + //private int min; private int max; @@ -274,7 +261,7 @@ private int current; public IntervalIterator(int min, int max, int first, int last) { - this.min = min; + //this.min = min; this.max = max; this.first = first; this.last = last; @@ -291,7 +278,7 @@ return (current++) % (max + 1); } - public Object next() { + public Integer next() { return new Integer(nextInt()); } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalGraphic.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalGraphic.java 2010-01-28 09:48:10 UTC (rev 2954) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalGraphic.java 2010-01-28 10:17:53 UTC (rev 2955) @@ -1,5 +1,5 @@ /* ##%% - * Copyright (C) 2002 - 2009 Code Lutin + * Copyright (C) 2002 - 2010 Ifremer, Code Lutin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -45,7 +45,7 @@ /** serialVersionUID. */ private static final long serialVersionUID = -6795996897731533693L; - + /* some constants. */ private static final int HANDLE_WITH = 5; private static final Cursor DEFAULT_CURSOR = new Cursor(Cursor.DEFAULT_CURSOR); @@ -54,117 +54,118 @@ private static final Cursor MOVE_CURSOR = new Cursor(Cursor.MOVE_CURSOR); /* Colors. */ - private Color backColor = Color.blue; - private Color foreColor = Color.yellow; - private Color lineColor = Color.yellow.darker(); + private Color backColor = Color.BLUE; + private Color foreColor = Color.YELLOW; + private Color lineColor = Color.YELLOW.darker(); protected Interval model; /** - * rapport entre le model et la vu + * Rapport entre le model et la vue. */ protected float coef; /** - * decalage de la position de la souris lors d'un drag par rapport - * a la position de l'element 1 + * Decalage de la position de la souris lors d'un drag par rapport + * à la position de l'element 1. */ protected float delta; //tous pour changer la selection avec la souris private boolean inDrag = false; private int cursorType = 1; - private Cursor mouseCursor; + //private Cursor mouseCursor; - //si vrai le composant est editable private boolean enable = true; class MouseClick extends MouseAdapter { - public void mouseEntered( MouseEvent e) { + /*public void mouseEntered( MouseEvent e) { mouseCursor = getCursor(); - } - public void mousePressed( MouseEvent e) { + }*/ + public void mousePressed(MouseEvent e) { int mouseX = e.getX(); - if(model.getFirst() <= model.getLast()) { - inDrag = (model.getFirst()*coef - HANDLE_WITH < mouseX) && - (mouseX < (model.getLast()+1)*coef + HANDLE_WITH); + if (model.getFirst() <= model.getLast()) { + inDrag = (model.getFirst() * coef - HANDLE_WITH < mouseX) + && (mouseX < (model.getLast() + 1) * coef + HANDLE_WITH); + } else if (model.getFirst() > model.getLast()) { + inDrag = ((0 <= mouseX) && (mouseX < (model.getLast() + 1) + * coef + HANDLE_WITH)) + || ((model.getFirst() * coef - HANDLE_WITH < mouseX) && (mouseX <= getSize().width)); } - else if(model.getFirst() > model.getLast()) { - inDrag = - ((0 <= mouseX) && - (mouseX < (model.getLast()+1)*coef + HANDLE_WITH)) - || - ((model.getFirst()*coef - HANDLE_WITH < mouseX) && - (mouseX <= getSize().width)); + if (inDrag) { + delta = mouseX - (model.getFirst() * coef); } - if(inDrag) { - delta = mouseX - (model.getFirst()*coef); - } } - public void mouseReleased( MouseEvent e) { + public void mouseReleased(MouseEvent e) { inDrag = false; } } class MouseMove extends MouseMotionAdapter { - public void mouseMoved( MouseEvent e ) { + public void mouseMoved(MouseEvent e) { if (!inDrag && enable) { int x = e.getX(); //on determine sur quel section on est - if((model.getFirst()*coef - HANDLE_WITH < x ) && - (x < model.getFirst()*coef + HANDLE_WITH)) { - cursorType = 0; - setCursor(W_RESIZE_CURSOR); - }else if(((model.getLast()+1)*coef - HANDLE_WITH <x ) && - (x < (model.getLast()+1)*coef + HANDLE_WITH)) { - cursorType = 2; - setCursor(E_RESIZE_CURSOR); - delta = x - (model.getLast()*coef); + if ((model.getFirst() * coef - HANDLE_WITH < x) + && (x < model.getFirst() * coef + HANDLE_WITH)) { + cursorType = 0; + setCursor(W_RESIZE_CURSOR); + } else if (((model.getLast() + 1) * coef - HANDLE_WITH < x) + && (x < (model.getLast() + 1) * coef + HANDLE_WITH)) { + cursorType = 2; + setCursor(E_RESIZE_CURSOR); + delta = x - (model.getLast() * coef); + } else { + boolean bool = ((model.getFirst() <= model.getLast()) + && (model.getFirst() * coef + HANDLE_WITH < x) && (x < (model + .getLast() + 1) + * coef - HANDLE_WITH)) + || ((model.getFirst() > model.getLast()) && (((0 <= x) && (x < (model + .getLast() + 1) + * coef - HANDLE_WITH)) || ((model + .getFirst() + * coef + HANDLE_WITH < x) && (x <= getSize().width)))); + + if (bool) { + cursorType = 1; + setCursor(MOVE_CURSOR); } else { - boolean bool = - ((model.getFirst() <= model.getLast()) && - (model.getFirst()*coef + HANDLE_WITH < x) && - (x < (model.getLast()+1)*coef - HANDLE_WITH)) - || - ((model.getFirst() > model.getLast()) && - (((0 <= x) && - (x < (model.getLast()+1)*coef - HANDLE_WITH)) - || - ((model.getFirst()*coef + HANDLE_WITH < x) && - (x <= getSize().width)))); - - if (bool) { - cursorType = 1; - setCursor(MOVE_CURSOR); - } - else { - cursorType = 4; - setCursor(DEFAULT_CURSOR); - } + cursorType = 4; + setCursor(DEFAULT_CURSOR); } + } } } - public void mouseDragged( MouseEvent e ){ - if (inDrag && enable){ - int x=e.getX(); - switch (cursorType){ - case 0: //on tire par le debut - if (x < 0) x = 0; - if (x > getSize().width) x = getSize().width; + public void mouseDragged(MouseEvent e) { + if (inDrag && enable) { + int x = e.getX(); + switch (cursorType) { + case 0: //on tire par le debut + if (x < 0) { + x = 0; + } + if (x > getSize().width) { + x = getSize().width; + } model.setFirst(Math.round(x / coef)); break; - case 1: //on deplace - int decal = Math.round((x-delta)/coef) - model.getFirst(); + case 1: //on deplace + int decal = Math.round((x - delta) / coef) + - model.getFirst(); model.move(decal); break; - case 2: //on tire par la fin - if (x < 0) x = 0; - if (x > getSize().width) x = getSize().width; - model.setLast(Math.round((x-coef) / coef)); + case 2: //on tire par la fin + if (x < 0) { + x = 0; + } + if (x > getSize().width) { + x = getSize().width; + } + model.setLast(Math.round((x - coef) / coef)); break; } } @@ -172,17 +173,19 @@ } /** - * Constructeur - */ - public IntervalGraphic(Interval m){ + * Constructor with interval value. + * + * @param m interval + */ + public IntervalGraphic(Interval m) { super(); setModel(m); addMouseListener(new MouseClick()); addMouseMotionListener(new MouseMove()); } - public void setModel(Interval m){ - if(this.model != null) { + public void setModel(Interval m) { + if (this.model != null) { this.model.deleteObserver(this); } this.model = m; @@ -190,15 +193,15 @@ update(this.model, null); } - public void setEnabled(boolean enable){ + public void setEnabled(boolean enable) { this.enable = enable; } /** - * Dessine sur le graphique l'interval courant - */ - protected void redraw( Graphics g ) { - coef = (float)getSize().width / (float)(model.getMax()+1); + * Dessine sur le graphique l'interval courant. + */ + protected void redraw(Graphics g) { + coef = (float) getSize().width / (float) (model.getMax() + 1); int width = getSize().width; int height = getSize().height; @@ -208,46 +211,43 @@ //peindre le fond tmpg.setColor(backColor); - tmpg.fillRect(0 , 0, width, height); + tmpg.fillRect(0, 0, width, height); //peindre la section tmpg.setColor(foreColor); - for (Interval.IntervalIterator i=(Interval.IntervalIterator)model.iterator();i.hasNext();){ + for (Interval.IntervalIterator i = (Interval.IntervalIterator) model + .iterator(); i.hasNext();) { int val = i.nextInt(); tmpg.setColor(foreColor); - tmpg.fillRect(Math.round(val*coef) , 0, - Math.round(coef) , height); + tmpg.fillRect(Math.round(val * coef), 0, Math.round(coef), height); tmpg.setColor(lineColor); - tmpg.drawRect(Math.round(val*coef) , 0, - Math.round(coef) , height); + tmpg.drawRect(Math.round(val * coef), 0, Math.round(coef), height); } g.drawImage(ImageBuffer, 0, 0, getSize().width, getSize().height, - new ImageObserver(){ - public boolean imageUpdate( Image img, int infoflags, - int x, int y, - int width, int height ){ - return true; - } - }); + new ImageObserver() { + public boolean imageUpdate(Image img, int infoflags, int x, + int y, int width, int height) { + return true; + } + }); } - /** - */ - public void paint( Graphics g ){ + @Override + public void paint(Graphics g) { redraw(g); } - /** - */ - public void update( Graphics g ){ + @Override + public void update(Graphics g) { redraw(g); } /** - * Call by observable object - */ - public void update(Observable o, Object arg){ + * Called by observable object. + */ + @Override + public void update(Observable o, Object arg) { repaint(); } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalLabel.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalLabel.java 2010-01-28 09:48:10 UTC (rev 2954) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalLabel.java 2010-01-28 10:17:53 UTC (rev 2955) @@ -1,5 +1,5 @@ /* ##%% - * Copyright (C) 2002 - 2009 Code Lutin + * Copyright (C) 2002 - 2010 Ifremer, Code Lutin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,7 +33,7 @@ * Mise a jour: $Date: 2009-03-09 15:40:20 +0100 (lun. 09 mars 2009) $ * par : $Author: sletellier $ */ -class IntervalLabel extends JLabel implements Observer { +public class IntervalLabel extends JLabel implements Observer { /** serialVersionUID. */ private static final long serialVersionUID = -6269941008930677478L; @@ -59,6 +59,7 @@ this.renderArray = renderArray; } + @Override public void update(Observable o, Object arg) { setText(toString(model.getFirst()) + " - " + toString(model.getLast())); } Modified: isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalPanel.java =================================================================== --- isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalPanel.java 2010-01-28 09:48:10 UTC (rev 2954) +++ isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/IntervalPanel.java 2010-01-28 10:17:53 UTC (rev 2955) @@ -1,5 +1,5 @@ -/* ##%% - * Copyright (C) 2002, 2003 Code Lutin +/* *##% + * Copyright (C) 2002 - 2010 Ifremer, Code Lutin * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - *##%%**/ + *##%*/ package fr.ifremer.isisfish.ui.widget; @@ -39,15 +39,10 @@ /** serialVersionUID. */ private static final long serialVersionUID = 4245022583233407638L; + private final static int DEFAULT_WIDTH = 110; private final static int DEFAULT_HEIGHT = 50; - public static void main(String args[]) { - Interval i = new Interval(0, 11); - FormInterval f = new FormInterval(i); - f.setVisible(true); - } - private Interval model = null; private IntervalGraphic graph; private IntervalLabel label; Copied: isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/FormInterval.java (from rev 2946, isis-fish/branches/3.3.1/src/main/java/fr/ifremer/isisfish/ui/widget/FormInterval.java) =================================================================== --- isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/FormInterval.java (rev 0) +++ isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/FormInterval.java 2010-01-28 10:17:53 UTC (rev 2955) @@ -0,0 +1,51 @@ +/* *##% + * Copyright (C) 2002 - 2009 Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package fr.ifremer.isisfish.ui.widget; + +import java.awt.Frame; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +import fr.ifremer.isisfish.ui.widget.Interval; +import fr.ifremer.isisfish.ui.widget.IntervalPanel; + +/** + * FormInterval. + */ +public class FormInterval extends Frame { + + /** serialVersionUID. */ + private static final long serialVersionUID = 4911081593147906648L; + + class QuitListener extends WindowAdapter { + public void windowClosing(WindowEvent e) { + e.getWindow().dispose(); + } + } + + public FormInterval(Interval i) { + IntervalPanel ip = new IntervalPanel(); + this.add(ip); + // ip.setEnabled(false); + ip.setModel(i); + + this.addWindowListener(new QuitListener()); + pack(); + } +} Added: isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/IntervalPanelTest.java =================================================================== --- isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/IntervalPanelTest.java (rev 0) +++ isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/IntervalPanelTest.java 2010-01-28 10:17:53 UTC (rev 2955) @@ -0,0 +1,68 @@ +/* *##% + * Copyright (C) 2002 - 2010 Ifremer, Code Lutin + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *##%*/ + +package fr.ifremer.isisfish.ui.widget; + +import javax.swing.SwingUtilities; + +import org.junit.Test; + +/** + * Test class for {@link IntervalPanel}. + * + * @author chatellier + * @version $Revision$ + * + * Last update : $Date$ + * By : $Author$ + */ +public class IntervalPanelTest { + + /** + * Test to display a frame with interval panel. + * + * @throws InterruptedException + */ + @Test + public void testIntervalPanelDisplay() throws InterruptedException { + Interval i = new Interval(0, 11); + final FormInterval f = new FormInterval(i); + SwingUtilities.invokeLater(new Runnable() { + @Override + public void run() { + f.setVisible(true); + } + }); + + Thread t = new Thread(new Runnable() { + public void run() { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + // do nothing + } + f.dispose(); + } + }); + t.start(); + + // it would really be nice to wait the thread, otherwise the test + // means nothing!!! + t.join(); + } +} Property changes on: isis-fish/branches/3.3.1/src/test/java/fr/ifremer/isisfish/ui/widget/IntervalPanelTest.java ___________________________________________________________________ Added: svn:keywords + "Author Date Id Revision HeadURL"
participants (1)
-
chatellier@users.labs.libre-entreprise.org