From 6c47e1f44bb131b744f6adeca52c1aba67fdd216 Mon Sep 17 00:00:00 2001 From: lingutln Date: Wed, 28 Dec 2011 22:51:04 +0000 Subject: [PATCH] Popup Label functionality. Done by Nikhil. svn path=/; revision=243 --- Annotation/.classpath | 22 +-- .../apps/ist/dialogs/PopUpLabelDialog.java | 159 ++++++++++++++++++ .../dcu/apps/ist/views/SegmentationView.java | 32 +++- 3 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java diff --git a/Annotation/.classpath b/Annotation/.classpath index 61c9bd1..22412b6 100644 --- a/Annotation/.classpath +++ b/Annotation/.classpath @@ -1,11 +1,11 @@ - - - - - - - - - - - + + + + + + + + + + + diff --git a/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java b/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java new file mode 100644 index 0000000..d3d62f2 --- /dev/null +++ b/Annotation/src/ie/dcu/apps/ist/dialogs/PopUpLabelDialog.java @@ -0,0 +1,159 @@ +package ie.dcu.apps.ist.dialogs; + +import ie.dcu.swt.SwtUtils; +import ie.dcu.swt.layout.LayoutFactory; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Dialog; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +public class PopUpLabelDialog extends Dialog { + + public class Result { + public final String html; + public final String image; + + Result() { + html = htmlText.getText().trim(); + image = imageText.getText().trim(); + } + }; + + // Result + private Result result; + + // Top level components + private Shell shell; + private Composite content; + private Composite widgets; + private Composite buttons; + + // Widgets + private Text htmlText; + private Text imageText; + // Dialog buttons + private Button cancelButton; + private Button assignButton; + + // Default title + private static final String TITLE = "Label the segmented Pieces"; + + public PopUpLabelDialog(Shell shell) { + super(shell); + setText(TITLE); + } + + public PopUpLabelDialog(Shell shell, int style) { + super(shell, style); + setText(TITLE); + } + + public Result open() { + Shell parent = getParent(); + shell = new Shell(parent, SWT.DIALOG_TRIM | + SWT.APPLICATION_MODAL | SWT.SHEET); + shell.setText(getText()); + shell.setLayout(new FillLayout()); + + createUI(); + + shell.pack(); + + SwtUtils.center(parent, shell); + + shell.open(); + Display display = parent.getDisplay(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) display.sleep(); + } + + return result; + } + + private void createUI() { + // Overall layout + content = new Composite(shell, 0); + content.setLayout(LayoutFactory.createGridLayout(0, 0, 2, false)); + widgets = new Composite(content, 0); + widgets.setLayout(LayoutFactory.createGridLayout(10, 5, 3, false)); + widgets.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + hline(content); + buttons = new Composite(content, 0); + buttons.setLayout(LayoutFactory.createGridLayout(10, 5, 3, false)); + buttons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + + // Form content + label(widgets, "HTML file name:"); + htmlText = text(widgets, "imagemap.html"); + spacer(widgets); + hline(widgets); + + // Button bar + expander(buttons); + cancelButton = new Button(buttons, SWT.PUSH); + cancelButton.setLayoutData(layout4()); + cancelButton.setText("Cancel"); + assignButton = new Button(buttons, SWT.PUSH); + assignButton.setLayoutData(layout4()); + assignButton.setText("Export"); + + // Set the default button + shell.setDefaultButton(assignButton); + + // Add listeners + } + + private Label hline(Composite parent) { + Label label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); + GridData data = new GridData(SWT.FILL, SWT.CENTER, false, false); + data.horizontalSpan = 3; + data.heightHint = 10; + label.setLayoutData(data); + return label; + } + + private Label spacer(Composite parent) { + Label label = new Label(parent, SWT.NONE); + label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + return label; + } + + private Label expander(Composite parent) { + Label label = new Label(parent, SWT.NONE); + label.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); + return label; + } + + private Label label(Composite parent, String text) { + Label label = new Label(parent, SWT.NONE); + label.setText(text); + label.setLayoutData(layout1()); + return label; + } + + private Text text(Composite parent, String value) { + Text text = new Text(parent, SWT.BORDER | SWT.SINGLE); + text.setText(value); + text.setLayoutData(layout2()); + return text; + } + + private GridData layout1() { + return new GridData(SWT.LEFT, SWT.CENTER, false, false); + } + + private GridData layout2() { + return new GridData(SWT.FILL, SWT.CENTER, true, false); + } + + private GridData layout4() { + return new GridData(SWT.RIGHT, SWT.BOTTOM, false, false); + } +} diff --git a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java index cc762de..208c127 100644 --- a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java +++ b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java @@ -3,6 +3,7 @@ package ie.dcu.apps.ist.views; import ie.dcu.apps.ist.PainterRegistry; import ie.dcu.apps.ist.event.*; +import ie.dcu.apps.ist.export.imagemap.Exporter; import ie.dcu.apps.ist.widgets.*; import ie.dcu.segment.*; import ie.dcu.segment.annotate.*; @@ -10,11 +11,13 @@ import ie.dcu.segment.options.SegmenterOptionDialog; import ie.dcu.segment.painters.SegmentationPainter; import ie.dcu.swt.*; import ie.dcu.swt.event.*; +import ie.dcu.apps.ist.dialogs.PopUpLabelDialog; import java.lang.reflect.InvocationTargetException; import java.net.*; import java.util.Properties; import java.util.logging.*; +import java.awt.image.BufferedImage; import java.io.*; import org.json.*; @@ -1052,16 +1055,33 @@ public class SegmentationView extends Composite { private final MouseListener popupListener = new MouseListener() { - public void mouseUp(MouseEvent e) { - System.out.println("Mouse up"); - Menu menu = new Menu(getShell(), SWT.POP_UP); - getShell().setMenu(menu); + public void mouseUp(MouseEvent event) { + PopUpLabelDialog dialog = new PopUpLabelDialog(getShell()); + PopUpLabelDialog.Result result = dialog.open(); + if (result != null) { + + // Grab image and mask + SegmentationContext ctx = view.getContext(); + SegmentationMask mask = ctx.getMask(); + BufferedImage image = ImageConverter.convert(ctx.getImageData()); + + // Setup exporter + Exporter exporter = new Exporter(image, mask); + exporter.setHtmlFile(result.html); + exporter.setImageFile(result.image); + String label = SegmentationView.comboLabel.getText(); + if(label.indexOf('{') != -1) + { + label = label.substring(0,label.indexOf('{')-1); + } + exporter.setTitle(label); + } } public void mouseDown(MouseEvent e) { - System.out.println("In Mouse down"); + } public void mouseDoubleClick(MouseEvent e) { - System.out.println("In Mouse Double click"); + } }; -- 2.34.1