|
From: <nr...@us...> - 2011-07-04 21:09:18
|
Revision: 15645
http://dcm4che.svn.sourceforge.net/dcm4che/?rev=15645&view=rev
Author: nroduit
Date: 2011-07-04 21:09:08 +0000 (Mon, 04 Jul 2011)
Log Message:
-----------
improve download progression display, minor issues
Modified Paths:
--------------
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/CircularProgressBar.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/AnimatedLabel.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/TagW.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/Thumbnail.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/util/FileUtil.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/DefaultView2d.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/PerpendicularLineGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/PolygonGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/model/AbstractLayerModel.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/messages.properties
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-codec/src/main/java/org/weasis/dicom/codec/DicomInstance.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-codec/src/main/java/org/weasis/dicom/codec/DicomMediaIO.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-explorer/src/main/java/org/weasis/dicom/explorer/DicomExplorer.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-explorer/src/main/java/org/weasis/dicom/explorer/messages.properties
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-explorer/src/main/java/org/weasis/dicom/explorer/wado/DownloadManager.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-explorer/src/main/java/org/weasis/dicom/explorer/wado/LoadRemoteDicomManifest.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-explorer/src/main/java/org/weasis/dicom/explorer/wado/LoadSeries.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-viewer2d/src/main/java/org/weasis/dicom/viewer2d/InfoLayer.java
weasis/weasis_framework/trunk/weasis-dicom/weasis-dicom-viewer2d/src/main/java/org/weasis/dicom/viewer2d/View2d.java
weasis/weasis_framework/trunk/weasis-launcher/conf/config.properties
weasis/weasis_framework/trunk/weasis-launcher/src/main/java/org/weasis/launcher/messages_ja.properties
Added Paths:
-----------
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/SeriesProgressMonitor.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/resources/icon/22x22/process-working.png
Removed Paths:
-------------
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicOld.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/FreeHandGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/FreeHandLineGraphic.java
weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/MedianLineGraphic.java
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/CircularProgressBar.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/CircularProgressBar.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/CircularProgressBar.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -15,16 +15,21 @@
import java.awt.Graphics2D;
import java.awt.RenderingHints;
+import javax.swing.ImageIcon;
import javax.swing.JProgressBar;
+import org.weasis.core.api.gui.util.AnimatedIconStatic;
+import org.weasis.core.api.gui.util.ImageSectionIcon;
import org.weasis.core.api.util.FontTools;
public class CircularProgressBar extends JProgressBar {
private final static Color BACK_COLOR = new Color(82, 152, 219);
- private String message;
+ public static final ImageIcon ICON = new ImageIcon(
+ CircularProgressBar.class.getResource("/icon/22x22/process-working.png")); //$NON-NLS-1$
+ private volatile Animate animateThread;
+
public CircularProgressBar() {
- super();
init();
}
@@ -35,15 +40,26 @@
private void init() {
this.setOpaque(false);
+ this.setSize(30, 30);
}
@Override
public void paint(Graphics g) {
if (g instanceof Graphics2D) {
- draw((Graphics2D) g);
+ if (isIndeterminate()) {
+ drawInderminate((Graphics2D) g);
+ } else {
+ draw((Graphics2D) g);
+ }
}
}
+ private void drawInderminate(Graphics2D g) {
+ if (animateThread != null) {
+ animateThread.paintIcon(this, g);
+ }
+ }
+
private void draw(Graphics2D g2) {
int h = this.getHeight();
int w = this.getWidth();
@@ -74,16 +90,68 @@
}
@Override
- public void setIndeterminate(boolean indeterminate) {
- if (indeterminate) {
+ public synchronized void setIndeterminate(boolean newValue) {
+ if (newValue != this.isIndeterminate()) {
+ if (animateThread != null) {
+ stopIndeterminate();
+ }
+ if (newValue) {
+ if (animateThread == null) {
+ animateThread = new Animate(50);
+ animateThread.start();
+ }
+ }
+ super.setIndeterminate(newValue);
+ }
+ }
+ public synchronized void stopIndeterminate() {
+ Thread moribund = animateThread;
+ animateThread = null;
+ if (moribund != null) {
+ moribund.interrupt();
}
- super.setIndeterminate(indeterminate);
}
- public void setMessage(String message) {
- this.message = message;
+ @Override
+ protected void finalize() throws Throwable {
+ if (animateThread != null) {
+ animateThread.interrupt();
+ }
+ }
+ protected class Animate extends Thread {
+ private final AnimatedIconStatic indeterminateIcon;
+ private final long refresh;
+
+ public Animate(long refresh) {
+ super.setDaemon(true);
+ this.refresh = refresh;
+ indeterminateIcon = new ImageSectionIcon(ICON, 22, 22, 0, 32);
+ }
+
+ public void paintIcon(CircularProgressBar circularProgressBar, Graphics2D g) {
+ int h = circularProgressBar.getHeight();
+ int w = circularProgressBar.getWidth();
+ int x = (w - indeterminateIcon.getIconWidth()) / 2;
+ int y = (h - indeterminateIcon.getIconHeight()) / 2;
+ g.setPaint(Color.WHITE);
+ g.fillRect(x, y, indeterminateIcon.getIconWidth(), indeterminateIcon.getIconHeight());
+ indeterminateIcon.paintIcon(circularProgressBar, g, x, y);
+ }
+
+ @Override
+ public void run() {
+ while (!this.isInterrupted()) {
+ indeterminateIcon.animate();
+ CircularProgressBar.this.repaint();
+ try {
+ Thread.sleep(this.refresh);
+ } catch (InterruptedException e) {
+ this.interrupt();
+ }
+ }
+ }
}
}
Added: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/SeriesProgressMonitor.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/SeriesProgressMonitor.java (rev 0)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/SeriesProgressMonitor.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -0,0 +1,113 @@
+package org.weasis.core.api.gui.task;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InterruptedIOException;
+
+import org.weasis.core.api.gui.util.GuiExecutor;
+import org.weasis.core.api.media.data.Series;
+import org.weasis.core.api.media.data.SeriesImporter;
+import org.weasis.core.api.media.data.TagW;
+import org.weasis.core.api.media.data.Thumbnail;
+
+public class SeriesProgressMonitor extends FilterInputStream {
+ private final Series series;
+ private int nread = 0;
+ private int size = 0;
+ private double initialSize;
+
+ public SeriesProgressMonitor(final Series series, InputStream in) {
+ super(in);
+ if (series == null)
+ throw new IllegalArgumentException("Series cannot be null!");
+ this.series = series;
+ this.initialSize = series.getFileSize();
+ try {
+ size = in.available();
+ } catch (IOException ioe) {
+ size = 0;
+ }
+ }
+
+ private boolean isLoadingSeriesCanceled() {
+ SeriesImporter loader = series.getSeriesLoader();
+ return (loader == null || loader.isStopped());
+ }
+
+ private void updateSeriesProgression() {
+ series.setFileSize(initialSize + nread);
+ GuiExecutor.instance().execute(new Runnable() {
+
+ @Override
+ public void run() {
+ Thumbnail thumb = (Thumbnail) series.getTagValue(TagW.Thumbnail);
+ if (thumb != null) {
+ thumb.repaint();
+ }
+ }
+ });
+ }
+
+ @Override
+ public int read() throws IOException {
+ int c = in.read();
+ if (c >= 0) {
+ nread++;
+ updateSeriesProgression();
+ }
+ if (isLoadingSeriesCanceled()) {
+ InterruptedIOException exc = new InterruptedIOException("progress");
+ exc.bytesTransferred = nread;
+ throw exc;
+ }
+ return c;
+ }
+
+ @Override
+ public int read(byte b[]) throws IOException {
+ int nr = in.read(b);
+ if (nr > 0) {
+ nread += nr;
+ updateSeriesProgression();
+ }
+ if (isLoadingSeriesCanceled()) {
+ InterruptedIOException exc = new InterruptedIOException("progress");
+ exc.bytesTransferred = nread;
+ throw exc;
+ }
+ return nr;
+ }
+
+ @Override
+ public int read(byte b[], int off, int len) throws IOException {
+ int nr = in.read(b, off, len);
+ if (nr > 0) {
+ nread += nr;
+ updateSeriesProgression();
+ }
+ if (isLoadingSeriesCanceled()) {
+ InterruptedIOException exc = new InterruptedIOException("progress");
+ exc.bytesTransferred = nread;
+ throw exc;
+ }
+ return nr;
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ long nr = in.skip(n);
+ if (nr > 0) {
+ nread += nr;
+ updateSeriesProgression();
+ }
+ return nr;
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ in.reset();
+ nread = size - in.available();
+ updateSeriesProgression();
+ }
+}
Property changes on: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/task/SeriesProgressMonitor.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/AnimatedLabel.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/AnimatedLabel.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/gui/util/AnimatedLabel.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -10,24 +10,21 @@
******************************************************************************/
package org.weasis.core.api.gui.util;
+import java.awt.Graphics;
+
import javax.swing.JLabel;
-import org.weasis.core.api.Messages;
-
public class AnimatedLabel extends JLabel {
private static final long serialVersionUID = 1L;
- private AnimatedIconStatic ani;
- private Animate an;
+ private volatile AnimatedIconStatic ani;
+ private volatile Animate an;
public AnimatedLabel(AnimatedIconStatic icon, long refresh) {
init(icon, refresh);
}
- protected AnimatedLabel() {
- }
-
protected void init(AnimatedIconStatic icon, long refresh) {
this.ani = icon;
super.setIcon(icon);
@@ -50,6 +47,12 @@
}
@Override
+ protected void paintComponent(Graphics g) {
+ ani.paintIcon(this, g, 0, 0);
+ super.paintComponent(g);
+ }
+
+ @Override
protected void finalize() throws Throwable {
this.an.interrupt();
}
@@ -60,7 +63,7 @@
public Animate(long refresh) {
super.setDaemon(true);
- super.setName("AnimatorThread_" + this.refresh + "_" + AnimatedLabel.this.ani.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ super.setName(AnimatedLabel.this.ani.getName()); //$NON-NLS-1$ //$NON-NLS-2$
this.refresh = refresh;
}
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/TagW.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/TagW.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/TagW.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -69,9 +69,11 @@
public static final TagW ImageBitsPerPixel = new TagW(Messages.getString("TagElement.img_bpp"), TagType.Integer); //$NON-NLS-1$
public static final TagW ImageCache = new TagW("Image Cache", TagType.Boolean); //$NON-NLS-1$
- // Do not internationalize WadoTransferSyntaxUID and WadoCompressionRate because they are defined in wado_query.xsd
+ // Do not internationalize WadoTransferSyntaxUID, WadoCompressionRate and DirectDownloadFile because they are
+ // defined in wado_query.xsd
public static final TagW WadoCompressionRate = new TagW("Wado Compression Rate", TagType.Integer); //$NON-NLS-1$
public final static TagW WadoTransferSyntaxUID = new TagW("Wado Transfer Syntax UID", TagType.String); //$NON-NLS-1$
+ public final static TagW DirectDownloadFile = new TagW("Direct Download File", TagType.String); //$NON-NLS-1$
public final static TagW WadoParameters = new TagW("Wado Parameter", TagType.Object); //$NON-NLS-1$
public final static TagW WadoInstanceReferenceList = new TagW("List of DICOM instance References", TagType.List); //$NON-NLS-1$
@@ -289,9 +291,8 @@
@Override
public boolean equals(Object obj) {
- if (obj instanceof TagW) {
+ if (obj instanceof TagW)
return ((TagW) obj).id == id;
- }
return false;
}
@@ -301,9 +302,8 @@
}
public static String getFormattedText(Object value, TagType type, String format) {
- if (value == null) {
+ if (value == null)
return ""; //$NON-NLS-1$
- }
String str;
@@ -425,9 +425,8 @@
private static String getPattern(int startIndex, String format) {
int beginIndex = format.indexOf('$', startIndex);
int endIndex = format.indexOf('$', startIndex + 2);
- if (beginIndex == -1 || endIndex == -1) {
+ if (beginIndex == -1 || endIndex == -1)
return null;
- }
return format.substring(beginIndex + 1, endIndex);
}
@@ -484,9 +483,8 @@
}
public static String formatDate(Date date) {
- if (date != null) {
+ if (date != null)
return formatDate.format(date);
- }
return ""; //$NON-NLS-1$
}
@@ -498,18 +496,16 @@
@Override
public boolean isDataFlavorSupported(DataFlavor flavor) {
for (int i = 0; i < flavors.length; i++) {
- if (flavor.equals(flavors[i])) {
+ if (flavor.equals(flavors[i]))
return true;
- }
}
return false;
}
@Override
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
- if (flavor.equals(flavors[0])) {
+ if (flavor.equals(flavors[0]))
return this;
- }
throw new UnsupportedFlavorException(flavor);
}
}
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/Thumbnail.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/Thumbnail.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/media/data/Thumbnail.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -68,7 +68,6 @@
import javax.swing.border.LineBorder;
import org.weasis.core.api.Messages;
-import org.weasis.core.api.gui.task.CircularProgressBar;
import org.weasis.core.api.gui.util.AbstractProperties;
import org.weasis.core.api.gui.util.GhostGlassPane;
import org.weasis.core.api.image.util.ImageFiler;
@@ -554,9 +553,10 @@
@Override
public void mouseReleased(MouseEvent e) {
- if (progressBar instanceof JProgressBar) {
- CircularProgressBar cricleBar = (CircularProgressBar) progressBar;
- Rectangle rect = cricleBar.getBounds();
+ if (progressBar != null) {
+ // To avoid concurrency issue
+ JProgressBar bar = progressBar;
+ Rectangle rect = bar.getBounds();
rect.x = thumbnailSize - rect.width - 2;
rect.y = thumbnailSize - rect.height - 2;
if (rect.contains(e.getPoint())) {
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/util/FileUtil.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/util/FileUtil.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/java/org/weasis/core/api/util/FileUtil.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -17,6 +17,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.net.URL;
import java.nio.ByteBuffer;
@@ -32,7 +33,6 @@
import javax.xml.stream.XMLStreamWriter;
import org.weasis.core.api.Messages;
-import org.weasis.core.api.media.data.Series;
public class FileUtil {
private static final double BASE = 1024, KB = BASE, MB = KB * BASE, GB = MB * BASE;
@@ -60,9 +60,8 @@
}
public final static void deleteDirectoryContents(final File dir) {
- if ((dir == null) || !dir.isDirectory()) {
+ if ((dir == null) || !dir.isDirectory())
return;
- }
final File[] files = dir.listFiles();
if (files != null) {
for (final File f : files) {
@@ -102,9 +101,8 @@
public static boolean isWriteable(File file) {
if (file.exists()) {
// Check the existing file.
- if (!file.canWrite()) {
+ if (!file.canWrite())
return false;
- }
} else {
// Check the file that doesn't exist yet.
// Create a new file. The file is writeable if
@@ -134,13 +132,11 @@
}
public static String nameWithoutExtension(String fn) {
- if (fn == null) {
+ if (fn == null)
return null;
- }
int i = fn.lastIndexOf('.');
- if (i > 0) {
+ if (i > 0)
return fn.substring(0, i);
- }
return fn;
}
@@ -163,9 +159,8 @@
}
public static boolean writeFile(InputStream inputStream, OutputStream out) {
- if (inputStream == null && out == null) {
+ if (inputStream == null && out == null)
return false;
- }
try {
byte[] buf = new byte[4096];
int offset;
@@ -173,55 +168,32 @@
out.write(buf, 0, offset);
}
return true;
+ } catch (InterruptedIOException e) {
+ return false;
} catch (IOException e) {
e.printStackTrace();
return false;
- } finally {
- FileUtil.safeClose(inputStream);
- FileUtil.safeClose(out);
}
- }
- public static boolean writeFile(InputStream inputStream, OutputStream out, Series series) {
- if (inputStream == null && out == null) {
- return false;
- }
- try {
- double size = series.getFileSize();
- byte[] buf = new byte[4096];
- int offset;
- while ((offset = inputStream.read(buf)) > 0) {
- out.write(buf, 0, offset);
- size += offset;
- series.setFileSize(size);
- }
- return true;
- } catch (IOException e) {
- e.printStackTrace();
- return false;
- } finally {
+ finally {
FileUtil.safeClose(inputStream);
FileUtil.safeClose(out);
}
}
public static String formatSize(double size) {
- if (size >= GB) {
+ if (size >= GB)
return df.format(size / GB) + Messages.getString("FileUtil.gb"); //$NON-NLS-1$
- }
- if (size >= MB) {
+ if (size >= MB)
return df.format(size / MB) + Messages.getString("FileUtil.mb"); //$NON-NLS-1$
- }
- if (size >= KB) {
+ if (size >= KB)
return df.format(size / KB) + Messages.getString("FileUtil.kb"); //$NON-NLS-1$
- }
return (int) size + Messages.getString("FileUtil.bytes"); //$NON-NLS-1$ //$NON-NLS-2$
}
public static boolean nioWriteFile(FileInputStream inputStream, FileOutputStream out) {
- if (inputStream == null && out == null) {
+ if (inputStream == null && out == null)
return false;
- }
try {
FileChannel fci = inputStream.getChannel();
FileChannel fco = out.getChannel();
@@ -237,9 +209,8 @@
}
public static boolean nioWriteFile(InputStream in, OutputStream out, final int bufferSize) {
- if (in == null && out == null) {
+ if (in == null && out == null)
return false;
- }
try {
ReadableByteChannel readChannel = Channels.newChannel(in);
WritableByteChannel writeChannel = Channels.newChannel(out);
Added: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/resources/icon/22x22/process-working.png
===================================================================
(Binary files differ)
Property changes on: weasis/weasis_framework/trunk/weasis-core/weasis-core-api/src/main/resources/icon/22x22/process-working.png
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/DefaultView2d.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/DefaultView2d.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/editor/image/DefaultView2d.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -59,6 +59,8 @@
import javax.swing.border.Border;
import javax.swing.border.EtchedBorder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.weasis.core.api.gui.Image2DViewer;
import org.weasis.core.api.gui.model.ViewModel;
import org.weasis.core.api.gui.util.ActionState;
@@ -103,6 +105,8 @@
public abstract class DefaultView2d<E extends ImageElement> extends GraphicsPane implements PropertyChangeListener,
FocusListener, Image2DViewer, ImageLayerChangeListener, KeyListener {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(DefaultView2d.class);
private static final ImageTransferHandler EXPORT_TO_CLIPBOARD = new ImageTransferHandler();
protected final FocusHandler focusHandler = new FocusHandler();
@@ -949,7 +953,7 @@
event.getWhen(), event.getModifiers(), mp.x, mp.y,
event.getXOnScreen(), event.getYOnScreen(), event.getClickCount(),
event.isPopupTrigger(), event.getButton());
- event.setImageCoordinates(p);
+ event.setImageCoordinates((Point2D) p.clone());
SwingUtilities.convertPointToScreen(mp, DefaultView2d.this);
robot.mouseMove(mp.x, mp.y);
} catch (AWTException e1) {
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphic.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -31,6 +31,8 @@
import java.util.List;
import java.util.ListIterator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.weasis.core.api.gui.Image2DViewer;
import org.weasis.core.api.gui.util.DecFormater;
import org.weasis.core.api.gui.util.GeomUtil;
@@ -47,6 +49,8 @@
public abstract class AbstractDragGraphic implements Graphic, Cloneable {
+ protected static final Logger logger = LoggerFactory.getLogger(AbstractDragGraphic.class);
+
public final static int UNDEFINED = -1;
protected PropertyChangeSupport pcs;
@@ -164,8 +168,7 @@
public Point2D getHandlePoint(int index) {
if (index < 0 || index >= handlePointList.size())
return null;
- Point2D handlePoint = handlePointList.get(index);
- return handlePoint != null ? (Point2D) handlePointList.get(index).clone() : null;
+ return handlePointList.get(index);
}
@Override
@@ -844,7 +847,7 @@
int lastPointIndex = handlePointList.size() - 1;
while (lastPointIndex > 0) {
- Point2D checkPoint = handlePointList.get(lastPointIndex);
+ Point2D checkPoint = getHandlePoint(lastPointIndex);
ListIterator<Point2D> listIt = handlePointList.listIterator(lastPointIndex--);
while (listIt.hasPrevious()) {
if (checkPoint != null && checkPoint.equals(listIt.previous()))
@@ -1017,7 +1020,7 @@
}
}
} else {
- Point2D point = handlePointList.get(handlePointIndex);
+ Point2D point = getHandlePoint(handlePointIndex);
if (point != null) {
point.setLocation(mouseEvent.getImageCoordinates());
// point.setLocation(point.getX() + deltaX, point.getY() + deltaY);
Deleted: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicOld.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicOld.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/AbstractDragGraphicOld.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -1,793 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Nicolas Roduit.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Roduit - initial API and implementation
- ******************************************************************************/
-package org.weasis.core.ui.graphic;
-
-import java.awt.BasicStroke;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.Graphics2D;
-import java.awt.Paint;
-import java.awt.Point;
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.Stroke;
-import java.awt.event.MouseEvent;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Area;
-import java.awt.geom.Point2D;
-import java.awt.geom.Rectangle2D;
-import java.beans.PropertyChangeListener;
-import java.beans.PropertyChangeSupport;
-import java.util.ArrayList;
-
-import javax.media.jai.PlanarImage;
-import javax.media.jai.iterator.RectIter;
-import javax.media.jai.iterator.RectIterFactory;
-
-import org.weasis.core.api.gui.Image2DViewer;
-import org.weasis.core.api.media.data.ImageElement;
-import org.weasis.core.ui.editor.image.DefaultView2d;
-import org.weasis.core.ui.graphic.model.GraphicsPane;
-import org.weasis.core.ui.util.MouseEventDouble;
-
-/**
- * The Class AbstractDragGraphic.
- *
- * @author Nicolas Roduit
- */
-public abstract class AbstractDragGraphicOld implements Graphic, Cloneable {
-
- protected float lineThickness;
- protected Paint paint;
- protected boolean filled;
- // private transient AbstractLayer layer;
- protected transient PropertyChangeSupport pcs;
- protected transient boolean selected;
- protected transient boolean showLabel;
- protected transient boolean createPoints = true;
- protected transient Stroke stroke;
- // protected transient AffineTransform affineTransform;
- // protected transient Shape transformedShape;
- protected transient Shape shape;
- private transient String[] labels;
-
- protected transient Double labelHeight = null;
-
- protected transient GraphicLabel graphicLabel = null;
-
- /**
- * The Class DefaultDragSequence.
- *
- * @author Nicolas Roduit
- */
- protected class DefaultDragSequence implements DragSequence {
-
- @Override
- public void startDrag(MouseEventDouble mouseevent) {
- update(mouseevent);
- }
-
- @Override
- public void drag(MouseEventDouble mouseevent) {
- int deltaX = mouseevent.getX() - getLastX();
- int deltaY = mouseevent.getY() - getLastY();
-
- if (deltaX != 0 || deltaY != 0) {
- boundingPointIndex = resizeOnDrawing(getType(), deltaX, deltaY, mouseevent);
- updateShapeOnDrawing(mouseevent); // moved here from resizeOnDrawing calls in subclass by BTJA
- update(mouseevent);
- }
- }
-
- @Override
- public boolean completeDrag(MouseEventDouble mouseevent) {
- if (createPoints) {
- // closed = true;
- updateShape(); // should not be necessary till it's called in updateshape on drawing
- createPoints = false;
- }
-
- // FIXME - why do we need to update ??? seems that update is useless ...
- int deltaX = mouseevent.getX() - getLastX();
- int deltaY = mouseevent.getY() - getLastY();
- if (deltaX != 0 || deltaY != 0) {
- System.out.println();
- }
-
- update(mouseevent);
- return true;
- }
-
- protected int getType() {
- return boundingPointIndex;
- }
-
- protected int getLastX() {
- return lastX;
- }
-
- protected int getLastY() {
- return lastY;
- }
-
- protected void update(int x, int y) {
- lastX = x;
- lastY = y;
- }
-
- protected void update(MouseEvent mouseevent) {
- lastX = mouseevent.getX();
- lastY = mouseevent.getY();
- }
-
- protected int lastX;
- protected int lastY;
- protected int boundingPointIndex;
-
- protected DefaultDragSequence() {
- this(false, -1);
- }
-
- protected DefaultDragSequence(boolean flag, int i) {
- // createPoints = flag; // should not be decided here if drag Graphic is finished
- // handle point type
- boundingPointIndex = i;
- }
-
- }
-
- public AbstractDragGraphicOld() {
- this.showLabel = true;
- }
-
- protected Graphics2D getGraphics2D(MouseEvent mouseevent) {
- if (mouseevent != null && mouseevent.getSource() instanceof GraphicsPane)
- return (Graphics2D) ((GraphicsPane) mouseevent.getSource()).getGraphics();
- return null;
- }
-
- protected AffineTransform getAffineTransform(MouseEvent mouseevent) {
- if (mouseevent != null && mouseevent.getSource() instanceof Image2DViewer)
- return ((Image2DViewer) mouseevent.getSource()).getAffineTransform();
- return null;
- }
-
- protected ImageElement getImageElement(MouseEvent mouseevent) {
- if (mouseevent != null && mouseevent.getSource() instanceof Image2DViewer)
- return ((Image2DViewer) mouseevent.getSource()).getImage();
- return null;
- }
-
- // seems never to be used
- // protected ImageLayer getImageLayer(MouseEvent mouseevent) {
- // if (mouseevent != null && mouseevent.getSource() instanceof Image2DViewer) {
- // return ((Image2DViewer) mouseevent.getSource()).getImageLayer();
- // }
- // return null;
- // }
- @Override
- public void toFront() {
- firePropertyChange("toFront", null, this);
- }
-
- @Override
- public void toBack() {
- firePropertyChange("toBack", null, this);
-
- }
-
- @Override
- public void setSelected(boolean flag) {
- if (selected != flag) {
- selected = flag;
- // firePropertyChange("selected", !flag, flag);
- firePropertyChange("bounds", null, shape); //$NON-NLS-1$
- }
- }
-
- @Override
- public String toString() {
- return getUIName();
- }
-
- @Override
- public boolean isSelected() {
- return selected;
- }
-
- public void setShape(Shape shape, MouseEvent mouseevent) {
- if (shape != null) {
- Shape oldShape = this.shape;
- this.shape = shape;
- // Fire event to repaint the old shape and the new shape of the graphic
- firePropertyChange("bounds", oldShape, shape); //$NON-NLS-1$
- }
- }
-
- protected void buildLabelBound(DefaultView2d view2d) {
- if (showLabel && labels != null && view2d != null) {
-
- Rectangle2D longestBound = null;
- for (String l : labels) {
- Font defaultFont = view2d.getEventManager().getViewSetting().getFont();
- Rectangle2D bound =
- defaultFont.getStringBounds(l, ((Graphics2D) view2d.getGraphics()).getFontRenderContext());
- // Find out the longest labels
- if (longestBound == null || bound.getWidth() > longestBound.getWidth()) {
- longestBound = bound;
- }
- }
- if (longestBound == null) {
- graphicLabel = null;
- labelHeight = null;
- } else {
- labelHeight = longestBound.getHeight();
- Rectangle rect = shape.getBounds();
- if (graphicLabel == null) {
- graphicLabel = new GraphicLabel();
-
- }
- // Rectangle oldBound = graphicLabel.getBound();
- // graphicLabel.setLabelBound(rect.x + rect.width, rect.y + rect.height * 0.5,
- // longestBound.getWidth() + 6, labelHeight * labels.length + 6);
- // firePropertyChange("graphicLabel", oldBound, graphicLabel); //$NON-NLS-1$
- }
- }
- }
-
- @Override
- public GraphicLabel getGraphicLabel() {
- return graphicLabel;
- }
-
- @Override
- public Shape getShape() {
- return shape;
- }
-
- public int getHandleSize() {
- // if (layer.getSettingsData() == null) {
- return 6;
- // }
- // else {
- // return layer.getSettingsData().getDis_handleDisplaySize();
- // }
-
- }
-
- public void setPaint(Paint paint1) {
- paint = paint1;
- // firePropertyChange("paint", paint2, paint1);
- firePropertyChange("bounds", null, shape); //$NON-NLS-1$
- }
-
- public Paint getPaint() {
- return paint;
- }
-
- public void setFilled(boolean flag) {
- if (filled != flag) {
- filled = flag;
- firePropertyChange("bounds", null, shape); //$NON-NLS-1$
- // firePropertyChange("selected", !flag, flag);
- }
- }
-
- public boolean isFilled() {
- return filled;
- }
-
- protected void updateShape() {
- firePropertyChange("bounds", null, shape); //$NON-NLS-1$
- // firePropertyChange("shape", null, shape);
- }
-
- // public void repaint() {
- // AbstractLayer layer1 = getLayer();
- // if (layer1 != null) {
- // layer1.repaint(getAllShapeRepaintBounds());
- // }
- // }
-
- protected void updateStroke() {
- stroke = new BasicStroke(lineThickness, BasicStroke.CAP_BUTT, BasicStroke.CAP_ROUND);
- }
-
- public float getLineThickness() {
- return lineThickness;
- }
-
- public Point getLabelPosition(Shape shape) {
- if (labelHeight != null) {
- Rectangle rect = shape.getBounds();
- return new Point(rect.x + 3 + rect.width, (int) (rect.y + 6 + rect.height / 2 - labelHeight * labels.length
- * 0.5));
- }
- return null;
- }
-
- @Override
- public void paint(Graphics2D g2d, AffineTransform transform) {
- Shape shape = getShape();
- if (shape != null) {
- g2d.setPaint(getPaint());
- g2d.setStroke(stroke);
- Shape transformedShape = transform == null ? shape : transform.createTransformedShape(shape);
- if (isFilled()) {
- // draw filled shape
- g2d.fill(transformedShape);
- }
- // draw outline shape
- g2d.draw(transformedShape);
- if (selected && !createPoints) {
- paintHandles(g2d, transform);
- }
- paintLabel(g2d, transform);
- }
- }
-
- @Override
- public void paintLabel(Graphics2D g2d, AffineTransform transform) {
- if (showLabel && labels != null) {
- if (graphicLabel != null && labelHeight != null) {
- // Rectangle2D labelBound = graphicLabel.getLabelBounds();
- Rectangle2D labelBound = graphicLabel.getBounds(transform);
- Point2D.Double p = new Point2D.Double(labelBound.getX(), labelBound.getY());
- transform.transform(p, p);
- // p.x += graphicLabel.getOffsetX();
- // p.y += graphicLabel.getOffsetY();
- for (int i = 0; i < labels.length; i++) {
- paintFontOutline(g2d, labels[i], (float) (p.x + 3), (float) (p.y + labelHeight * (i + 1)));
- }
- // Test, show bound to repaint
- // g2d.drawRect((int) p.x, (int) p.y, (int) labelBound.getWidth(), (int) labelBound.getHeight());
- }
- }
- }
-
- public void paintFontOutline(Graphics2D g2, String str, float x, float y) {
- g2.setPaint(Color.BLACK);
- g2.drawString(str, x - 1f, y - 1f);
- g2.drawString(str, x - 1f, y);
- g2.drawString(str, x - 1f, y + 1f);
- g2.drawString(str, x, y - 1f);
- g2.drawString(str, x, y + 1f);
- g2.drawString(str, x + 1f, y - 1f);
- g2.drawString(str, x + 1f, y);
- g2.drawString(str, x + 1f, y + 1f);
- g2.setPaint(Color.WHITE);
- g2.drawString(str, x, y);
- }
-
- protected Stroke getStroke() {
- return stroke;
- }
-
- /*
- * (non-Javadoc) draw the handles, when the graphic is selected
- *
- * @see org.weasis.core.ui.graphic.Graphic#paintHandles(java.awt.Graphics2D, java.awt.geom.AffineTransform)
- */
- public void paintHandles(Graphics2D graphics2d, AffineTransform transform) {
- Rectangle rect = getBounds();
- graphics2d.setPaint(Color.black);
- int numPoints = 8;
- int i = getHandleSize();
- int j = i / 2;
- float x = rect.x;
- float y = rect.y;
- float w = x + rect.width;
- float h = y + rect.height;
- float mw = x + rect.width / 2.0f;
- float mh = y + rect.height / 2.0f;
-
- float[] dstPts = new float[] { x, y, mw, y, w, y, x, mh, w, mh, x, h, mw, h, w, h };
- if (transform != null) {
- transform.transform(dstPts, 0, dstPts, 0, numPoints);
- }
- int k = 0;
- for (int l = numPoints * 2; k < l; k++) {
- graphics2d.fill(new Rectangle2D.Float(dstPts[k] - j, dstPts[++k] - j, i, i));
- }
-
- k = 0;
- graphics2d.setPaint(Color.white);
- graphics2d.setStroke(new BasicStroke(1.0f));
- for (int l = numPoints * 2; k < l; k++) {
- graphics2d.draw(new Rectangle2D.Float(dstPts[k] - j, dstPts[++k] - j, i, i));
- }
- }
-
- public void setLineThickness(float f) {
- lineThickness = f;
- updateStroke();
- updateShape();
- }
-
- @Override
- public boolean intersects(Rectangle rectangle) {
- return getArea().intersects(rectangle);
- }
-
- @Override
- public boolean intersects(Rectangle rectangle, AffineTransform transform) {
- return getArea(transform).intersects(rectangle);
- }
-
- /*
- * return the rectangle that corresponds to the bounding box of the graphic (when is selected it is the bounding box
- * of handles)
- */
- @Override
- public Rectangle getRepaintBounds() {
- return getRepaintBounds(shape);
- }
-
- public Rectangle getRepaintBounds(Shape shape) {
- if (shape == null)
- return null;
- Rectangle rectangle = shape.getBounds();
- growHandles(rectangle);
- return rectangle;
- }
-
- public void growHandles(Rectangle rectangle) {
- int i = getHandleSize();
- int thick = (int) Math.ceil(lineThickness);
- if (thick > i) {
- i = thick;
- }
- // Add 2 pixels tolerance to ensure that the graphic is correctly repainted
- i += 4;
- rectangle.width += i;
- rectangle.height += i;
- i /= 2;
- rectangle.x -= i;
- rectangle.y -= i;
- }
-
- public Rectangle getTransformedBounds(AffineTransform affineTransform) {
- return getTransformedBounds(shape, affineTransform);
- }
-
- @Override
- public Rectangle getTransformedBounds(Shape shape, AffineTransform affineTransform) {
- // Get the bounds of the transformed shape + the handles.
- if (affineTransform == null)
- return getRepaintBounds(shape);
- Rectangle rectangle = affineTransform.createTransformedShape(shape).getBounds();
- growHandles(rectangle);
- return rectangle;
- }
-
- @Override
- public Rectangle getTransformedBounds(GraphicLabel label, AffineTransform transform) {
- return (label != null) ? label.getTransformedBounds(transform).getBounds() : null;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.weasis.core.ui.graphic.Graphic#getBounds()
- */
- @Override
- public Rectangle getBounds() {
- return getBounds(null);
- }
-
- @Override
- public Rectangle getBounds(AffineTransform affineTransform) {
- Shape shape1 = getShape();
- if (shape1 == null)
- return null;
- // bound is not accurate with complex shape (it is true for rectangle or ellipse with rotation)
- Rectangle bound = shape1.getBounds();
- if (bound.width < 1) {
- bound.width = 1;
- }
- if (bound.height < 1) {
- bound.height = 1;
- }
- return bound;
- }
-
- public DragSequence createDragSequence(DragSequence dragsequence, MouseEvent mouseevent) {
- int i = 1;
-
- if (mouseevent != null && (dragsequence != null || (i = getResizeCorner(mouseevent)) == -1))
- return createMoveDrag(dragsequence, mouseevent);
- else
- // let drag the handle i to resize the graphic
- return createResizeDrag(mouseevent, i);
- }
-
- // Start a drag sequence to move the graphic
- protected DragSequence createMoveDrag(DragSequence dragsequence, MouseEvent mouseevent) {
- return new DefaultDragSequence();
- }
-
- protected DragSequence createResizeDrag(MouseEvent mouseevent, int i) {
- // let drag the handle i to resize the graphic
- return new DefaultDragSequence((mouseevent == null), i);
- }
-
- @Override
- public Area getArea() {
- return new Area(getShape());
- }
-
- public Area getArea(MouseEvent mouseevent) {
- return getArea();
- }
-
- @Override
- public Area getArea(AffineTransform transform) {
- return getArea();
- }
-
- public int getResizeCorner(MouseEvent mouseevent) {
- // return the selected handle point position
- /*
- * 1 2 3 8 4 7 6 5
- */
- final Point pos = mouseevent.getPoint();
- Rectangle rect = getBounds();
- int k = getHandleSize() + 2;
- AffineTransform affineTransform = getAffineTransform(mouseevent);
- if (affineTransform != null) {
- // Enable to get a better selection of the handle with a low or high magnification zoom
- double scale = affineTransform.getScaleX();
- k = (int) Math.ceil(k / scale + 1);
- }
-
- int l = k / 2;
- int i = pos.x - rect.x + l;
- int j = pos.y - rect.y + l;
- int i1 = -1;
- if (i >= 0) {
- if (i < k) {
- i1 = 1;
- } else if (i >= rect.width / 2 && i < rect.width / 2 + k) {
- i1 = 2;
- } else if (i >= rect.width && i < rect.width + k) {
- i1 = 3;
- }
- }
- if (i1 != -1 && j >= 0) {
- if (j >= rect.height / 2 && j < rect.height / 2 + k) {
- if (i1 == 2)
- return -1;
- i1 = i1 == 1 ? 0 : 4;
- } else if (j >= rect.height && j < rect.height + k) {
- i1 = i1 == 1 ? 7 : i1 == 2 ? 6 : 5;
- } else if (j >= k) {
- i1 = -1;
- }
- } else {
- i1 = -1;
- }
- return i1;
- }
-
- @Override
- public Object clone() throws CloneNotSupportedException {
- AbstractDragGraphicOld abstractGraphic = null;
- try {
- abstractGraphic = (AbstractDragGraphicOld) super.clone();
- } catch (CloneNotSupportedException clonenotsupportedexception) {
- return null; // never happen
- }
- abstractGraphic.pcs = null;
- abstractGraphic.selected = false;
- abstractGraphic.filled = filled;
-
- return abstractGraphic;
- }
-
- // protected abstract int resizeOnDrawing(int i, int j, int k, MouseEvent mouseevent);
- protected abstract int resizeOnDrawing(int boundingPointIndex, int deltaX, int deltaY, MouseEvent mouseEvent);
-
- public abstract Graphic clone(int xPos, int yPos);
-
- protected abstract void updateShapeOnDrawing(MouseEvent mouseevent);
-
- public void move(int i, int j, int k, MouseEvent mouseevent) {
- // WeasisWin.getInstance().getImageCanvas().moveOrigin(j, k);
- }
-
- public Point needToMoveCanvas(int x, int y) {
- // WeasisWin imageFrame = WeasisWin.getInstance();
- // if (imageFrame.getProjectSettingsData().isDis_autoMove()) {
- // return null;
- // // return imageFrame.getImageCanvas().stepToMoveCanvas(getRepaintBounds(), x, y);
- // }
- // else {
- return null;
- // }
- }
-
- // moved
- // protected int adjustBoundsForResize(Rectangle rectangle, int i, int j, int k) {
- // switch (i) {
- // // handle points
- // /*
- // * 1=NW 2=N 3=NE 0=W 4=E 7=SW 6=S 5=SE
- // */
- // case 0:
- // rectangle.x += j;
- // rectangle.width -= j;
- // break;
- // case 1:
- // rectangle.x += j;
- // rectangle.y += k;
- // rectangle.width -= j;
- // rectangle.height -= k;
- // break;
- // case 2:
- // rectangle.y += k;
- // rectangle.height -= k;
- // break;
- // case 3:
- // rectangle.width += j;
- // rectangle.y += k;
- // rectangle.height -= k;
- // break;
- // case 4:
- // rectangle.width += j;
- // break;
- // case 5:
- // rectangle.width += j;
- // rectangle.height += k;
- // break;
- // case 6:
- // rectangle.height += k;
- // break;
- // case 7:
- // rectangle.x += j;
- // rectangle.height += k;
- // rectangle.width -= j;
- // break;
- // }
- // int l = 0;
- // if (rectangle.width < 0) {
- // rectangle.x += rectangle.width;
- // rectangle.width = -rectangle.width;
- // l |= 1;
- // }
- // if (rectangle.height < 0) {
- // rectangle.y += rectangle.height;
- // rectangle.height = -rectangle.height;
- // l |= 2;
- // }
- // return l;
- // }
-
- protected void firePropertyChange(String s, Object obj, Object obj1) {
- if (pcs != null) {
- pcs.firePropertyChange(s, obj, obj1);
- }
- }
-
- protected void firePropertyChange(String s, int i, int j) {
- if (pcs != null) {
- pcs.firePropertyChange(s, i, j);
- }
- }
-
- protected void firePropertyChange(String s, boolean flag, boolean flag1) {
- if (pcs != null) {
- pcs.firePropertyChange(s, flag, flag1);
- }
- }
-
- protected void fireMoveAction() {
- if (pcs != null) {
- pcs.firePropertyChange("move", null, this); //$NON-NLS-1$
- }
- }
-
- @Override
- public void fireRemoveAction() {
- if (pcs != null) {
- pcs.firePropertyChange("remove", null, this); //$NON-NLS-1$
- }
- }
-
- public void fireRemoveAndRepaintAction() {
- if (pcs != null) {
- pcs.firePropertyChange("remove.repaint", null, this); //$NON-NLS-1$
- }
- }
-
- @Override
- public void addPropertyChangeListener(PropertyChangeListener propertychangelistener) {
- if (pcs == null) {
- pcs = new PropertyChangeSupport(this);
- }
- // Do not add if already exists
- for (PropertyChangeListener listener : pcs.getPropertyChangeListeners()) {
- if (listener == propertychangelistener)
- return;
- }
- pcs.addPropertyChangeListener(propertychangelistener);
- }
-
- @Override
- public void removePropertyChangeListener(PropertyChangeListener propertychangelistener) {
- if (pcs != null) {
- pcs.removePropertyChangeListener(propertychangelistener);
- }
- }
-
- public boolean isCreatePoints() {
- return createPoints;
- }
-
- @Override
- public String[] getLabel() {
- return labels;
- }
-
- @Override
- public void setLabel(String[] label, DefaultView2d view2d) {
- this.labels = label;
- buildLabelBound(view2d);
- }
-
- protected ArrayList<Integer> getValueFromArea(PlanarImage imageData) {
- if (imageData == null || shape == null)
- return null;
- Area area = new Area(shape);
- Rectangle bound = area.getBounds();
- bound = imageData.getBounds().intersection(bound);
- if (bound.width == 0 || bound.height == 0)
- return null;
- RectIter it;
- try {
- it = RectIterFactory.create(imageData, bound);
- } catch (Exception ex) {
- it = null;
- }
- ArrayList<Integer> list = null;
-
- if (it != null) {
- int band = imageData.getSampleModel().getNumBands();
- list = new ArrayList<Integer>();
- int[] c = { 0, 0, 0 };
- it.startBands();
- it.startLines();
- int y = bound.y;
- while (!it.finishedLines()) {
- it.startPixels();
- int x = bound.x;
- while (!it.finishedPixels()) {
- if (shape.contains(x, y)) {
- it.getPixel(c);
- for (int i = 0; i < band; i++) {
- list.add(c[i]);
- }
- }
- it.nextPixel();
- x++;
- }
- it.nextLine();
- y++;
- }
- }
- return list;
- }
-
- @Override
- public Rectangle getRepaintBounds(AffineTransform transform) {
- // TODO Auto-generated method stub
- return null;
- }
-}
Modified: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/CobbAngleToolGraphic.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -23,7 +23,6 @@
import javax.swing.ImageIcon;
import org.weasis.core.api.gui.util.GeomUtil;
-import org.weasis.core.ui.Messages;
import org.weasis.core.ui.util.MouseEventDouble;
/**
@@ -52,7 +51,7 @@
@Override
public String getUIName() {
- return Messages.getString("MeasureToolBar.cobb.angle"); //$NON-NLS-1$
+ return "Cobb's Angle";
}
@Override
@@ -66,9 +65,9 @@
// Let MN be the bisector of the two line segments AB & CD, if parallel MN is the median line
Line2D lineMN;
- if (lineParallel)
+ if (lineParallel) {
lineMN = GeomUtil.getMedianLine(A, B, C, D);
- else {
+ } else {
AffineTransform rotate =
AffineTransform.getRotateInstance(-Math.toRadians(angleDeg) / 2, P.getX(), P.getY());
@@ -80,9 +79,9 @@
if (handlePointIndex == 4 && O != null) {
O = GeomUtil.getPerpendicularPointToLine(lineMN, O);
} else {
- if (lineParallel)
+ if (lineParallel) {
O = GeomUtil.getMidPoint(lineMN.getP1(), lineMN.getP1());
- else {
+ } else {
// Point2D H1 = GeomUtil.getColinearPointWithRatio(ABPline[0], ABPline[1], 3 / 4);
// Point2D H2 = GeomUtil.getColinearPointWithRatio(CDPline[0], CDPline[1], 3 / 4);
@@ -95,13 +94,15 @@
O = GeomUtil.getMidPoint(O1, O2);
}
}
- } else
+ } else {
O = null;
+ }
- if (handlePointList.size() < 5)
+ if (handlePointList.size() < 5) {
handlePointList.add(O);
- else
+ } else {
handlePointList.set(4, O);
+ }
}
return handlePointIndex;
@@ -114,11 +115,13 @@
Shape newShape = null;
Path2D path = new Path2D.Double(Path2D.WIND_NON_ZERO, 6);
- if (ABvalid)
+ if (ABvalid) {
path.append(new Line2D.Double(A, B), false);
+ }
- if (CDvalid)
+ if (CDvalid) {
path.append(new Line2D.Double(C, D), false);
+ }
if (ABvalid && CDvalid && O != null) {
AdvancedShape aShape = (AdvancedShape) (newShape = new AdvancedShape(10));
@@ -140,11 +143,13 @@
final Point2D I = new Point2D.Double(Ax + r1 * (Bx - Ax), Ay + r1 * (By - Ay));
final Point2D J = new Point2D.Double(Cx + r2 * (Dx - Cx), Cy + r2 * (Dy - Cy));
- if (r1 < 0 || r1 > 1) // I is outside of AB line segment
+ if (r1 < 0 || r1 > 1) {
aShape.addShape(new Line2D.Double(r1 > 1 ? B : A, I), getDashStroke(1.0f), true);
+ }
- if (r2 < 0 || r2 > 1)// J is outside of AB line segment
+ if (r2 < 0 || r2 > 1) {
aShape.addShape(new Line2D.Double(r1 > 1 ? D : C, J), getDashStroke(1.0f), true);
+ }
aShape.addShape(new Line2D.Double(O, I));
aShape.addShape(new Line2D.Double(O, J));
@@ -191,8 +196,9 @@
aShape.addInvShape(arcAngle, O, radius / rMax, false);
}
- } else if (path.getCurrentPoint() != null)
+ } else if (path.getCurrentPoint() != null) {
newShape = path;
+ }
setShape(newShape, mouseEvent);
updateLabel(mouseEvent, getDefaultView2d(mouseEvent));
Deleted: weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/FreeHandGraphic.java
===================================================================
--- weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/FreeHandGraphic.java 2011-07-02 07:51:20 UTC (rev 15644)
+++ weasis/weasis_framework/trunk/weasis-core/weasis-core-ui/src/main/java/org/weasis/core/ui/graphic/FreeHandGraphic.java 2011-07-04 21:09:08 UTC (rev 15645)
@@ -1,343 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010 Nicolas Roduit.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Nicolas Roduit - initial API and implementation
- ******************************************************************************/
-package org.weasis.core.ui.graphic;
-
-import java.awt.Color;
-import java.awt.Graphics2D;
-import java.awt.Point;
-import java.awt.event.MouseEvent;
-import java.awt.geom.AffineTransform;
-import java.awt.geom.Area;
-import java.awt.geom.GeneralPath;
-import java.util.List;
-
-...
[truncated message content] |