Commit 8fb893a0 authored by angermue's avatar angermue
Browse files

Provides text annotation in teacher mode.

git-svn-id: https://www2.in.tum.de/repos/ttt/trunk@37 0463f305-d864-43cb-8a47-61cf597d4139
parent 223acc84
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universitt Mnchen
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universitt Mnchen
//
// This file is part of TeleTeachingTool.
//
......@@ -44,6 +44,8 @@ import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
import com.sun.media.codec.video.cinepak.CineStore;
import ttt.messages.Annotation;
public class PaintControls extends GradientPanel {
......@@ -51,6 +53,7 @@ public class PaintControls extends GradientPanel {
private JCheckBox activateButton;
private JRadioButton[] colorButtons;
private AbstractButton textButton;
private AbstractButton highlightButton;
private AbstractButton freeButton;
private AbstractButton rectangleButton;
......@@ -84,6 +87,9 @@ public class PaintControls extends GradientPanel {
static final String DELETE_ALL = "delete all";
private void jbInit() throws Exception {
URL urlText = this.getClass().getResource("/ttt/resources/text24.png");
URL urlActiveText = this.getClass().getResource("/ttt/resources/text_active24.png");
URL urlRolloverText = this.getClass().getResource("/ttt/resources/text_rollover24.png");
URL urlRect = this.getClass().getResource("resources/Rectangle24_new.gif");
URL urlActiveRect = this.getClass().getResource("resources/Rectangle_active24_new.gif");
URL urlRolloverRect = this.getClass().getResource("resources/Rectangle_rollover24_new.gif");
......@@ -171,6 +177,14 @@ public class PaintControls extends GradientPanel {
colorGroup.add(colorButtons[i]);
// paint modes
textButton = new JToggleButton();
textButton.setToolTipText("Text");
textButton.setBorder(BorderFactory.createEmptyBorder());
textButton.setIcon(new ImageIcon(urlText));
textButton.setSelectedIcon(new ImageIcon(urlActiveText));
textButton.setRolloverIcon(new ImageIcon(urlRolloverText));
textButton.setFocusable(false);
highlightButton = new JToggleButton();
highlightButton.setToolTipText("Highlight");
highlightButton.setBorder(BorderFactory.createEmptyBorder());
......@@ -219,6 +233,7 @@ public class PaintControls extends GradientPanel {
deleteAllButton.setFocusable(false);
ButtonGroup modeButtons = new ButtonGroup();
modeButtons.add(textButton);
modeButtons.add(lineButton);
modeButtons.add(rectangleButton);
modeButtons.add(freeButton);
......@@ -252,6 +267,7 @@ public class PaintControls extends GradientPanel {
add(colorButtons[3]);
add(colorButtons[4]);
add(Box.createRigidArea(new Dimension(20, 0)));
add(textButton);
add(freeButton);
add(highlightButton);
add(lineButton);
......@@ -279,32 +295,44 @@ public class PaintControls extends GradientPanel {
}
// set paint mode
if (event.getSource() == highlightButton) {
if (event.getSource() == textButton) {
paintListener.setPaintMode(Constants.AnnotationText);
highlightButton.setSelected(false);
freeButton.setSelected(false);
lineButton.setSelected(false);
rectangleButton.setSelected(false);
deleteButton.setSelected(false);
} else if (event.getSource() == highlightButton) {
paintListener.setPaintMode(Constants.AnnotationHighlight);
textButton.setSelected(false);
freeButton.setSelected(false);
lineButton.setSelected(false);
rectangleButton.setSelected(false);
deleteButton.setSelected(false);
} else if (event.getSource() == freeButton) {
paintListener.setPaintMode(Constants.AnnotationFreehand);
textButton.setSelected(false);
highlightButton.setSelected(false);
lineButton.setSelected(false);
rectangleButton.setSelected(false);
deleteButton.setSelected(false);
} else if (event.getSource() == rectangleButton) {
paintListener.setPaintMode(Constants.AnnotationRectangle);
textButton.setSelected(false);
highlightButton.setSelected(false);
freeButton.setSelected(false);
lineButton.setSelected(false);
deleteButton.setSelected(false);
} else if (event.getSource() == lineButton) {
paintListener.setPaintMode(Constants.AnnotationLine);
textButton.setSelected(false);
highlightButton.setSelected(false);
freeButton.setSelected(false);
rectangleButton.setSelected(false);
deleteButton.setSelected(false);
} else if (event.getSource() == deleteButton) {
paintListener.setPaintMode(Constants.AnnotationDelete);
textButton.setSelected(false);
highlightButton.setSelected(false);
freeButton.setSelected(false);
lineButton.setSelected(false);
......@@ -335,6 +363,7 @@ public class PaintControls extends GradientPanel {
activateButton.addActionListener(actionListener);
textButton.addActionListener(actionListener);
highlightButton.addActionListener(actionListener);
freeButton.addActionListener(actionListener);
rectangleButton.addActionListener(actionListener);
......@@ -386,6 +415,9 @@ public class PaintControls extends GradientPanel {
public void selectPaintModeButton(int paintMode) {
switch (paintMode) {
case Constants.AnnotationText:
textButton.setSelected(true);
break;
case Constants.AnnotationFreehand:
freeButton.setSelected(true);
break;
......
// TeleTeachingTool - Presentation Recording With Automated Indexing
//
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universitt Mnchen
// Copyright (C) 2003-2008 Peter Ziewer - Technische Universitt Mnchen
//
// This file is part of TeleTeachingTool.
//
......@@ -44,6 +44,7 @@ import ttt.messages.FreehandAnnotation;
import ttt.messages.HighlightAnnotation;
import ttt.messages.LineAnnotation;
import ttt.messages.RectangleAnnotation;
import ttt.messages.TextAnnotation;
import ttt.messages.WhiteboardMessage;
public class PaintListener extends RFBKeyAndMouseListener {
......@@ -62,7 +63,10 @@ public class PaintListener extends RFBKeyAndMouseListener {
// temporary annotation
private Annotation annotation;
// true when text is edited
private boolean textMode = false;
// enable/disable painting
private boolean activated;
......@@ -123,6 +127,8 @@ public class PaintListener extends RFBKeyAndMouseListener {
private int paintMode = Constants.AnnotationFreehand;
public void setPaintMode(int paintMode) {
// end text input if not yet finished
if(textMode) finishPainting();
if (paintMode == Constants.AnnotationDeleteAll)
// delete all is no permanent mode
writeMessage(new DeleteAllAnnotation(0));
......@@ -133,6 +139,8 @@ public class PaintListener extends RFBKeyAndMouseListener {
public int togglePaintMode() {
// switch to next next mode
if (paintMode == Constants.AnnotationText)
paintMode = Constants.AnnotationFreehand;
if (paintMode == Constants.AnnotationFreehand)
paintMode = Constants.AnnotationHighlight;
else if (paintMode == Constants.AnnotationHighlight)
......@@ -142,7 +150,7 @@ public class PaintListener extends RFBKeyAndMouseListener {
else if (paintMode == Constants.AnnotationRectangle)
paintMode = Constants.AnnotationDelete;
else if (paintMode == Constants.AnnotationDelete)
paintMode = Constants.AnnotationFreehand;
paintMode = Constants.AnnotationText;
// update GUI
if (paintControls != null)
......@@ -240,25 +248,37 @@ public class PaintListener extends RFBKeyAndMouseListener {
return;
// create and write temporary annotation
if (activated && !alt_tab) {
if (textMode) {
finishPainting();
} else if (activated && !alt_tab) {
set(event.getX(), event.getY());
writeMessage(annotation);
} else
super.mousePressed(event);
}
public void mouseReleased(MouseEvent event) {
if (!areCoordinatesValid(event))
return;
// write final annotation
if (activated && !alt_tab)
if (!textMode && activated && !alt_tab)
finishPainting();
else
super.mouseReleased(event);
}
private void finishPainting() {
if(textMode) {
textMode = false;
// if text annotation is still empty, discard it
if (((TextAnnotation)annotation).isEmpty()) {
annotation = null;
} else {
((TextAnnotation)annotation).trim();
}
}
if (annotation != null) {
// NOTE: reset last coordinates not needed - same as last dragged event
annotation.temporary = false;
......@@ -322,6 +342,11 @@ public class PaintListener extends RFBKeyAndMouseListener {
// initiates new temporary annotation
private void set(int x, int y) {
switch (paintMode) {
case Constants.AnnotationText:
annotation = new TextAnnotation(0, color, x, y, 0, "");
annotation.temporary = true;
textMode = true;
break;
case Constants.AnnotationHighlight:
annotation = new HighlightAnnotation(0, color + 3, x, y, x, y);
annotation.temporary = true;
......@@ -381,61 +406,87 @@ public class PaintListener extends RFBKeyAndMouseListener {
}
}
@Override
public void keyTyped(KeyEvent evt) {
if (textMode) {
if(evt.getKeyChar() != KeyEvent.CHAR_UNDEFINED &&
(evt.getKeyChar() > 31 || evt.getKeyChar() == KeyEvent.VK_ENTER)) {
// add non special characters to text annotation
((TextAnnotation)annotation).addChar(evt.getKeyChar());
graphicsContext.refresh();
evt.consume();
}
if (evt.getKeyChar() == KeyEvent.VK_BACK_SPACE) {
// delete last character when backspace pressed
((TextAnnotation)annotation).deleteLastChar();
graphicsContext.refresh();
evt.consume();
}
}
super.keyTyped(evt);
}
@Override
public void keyPressed(KeyEvent evt) {
// TODO: add option panel to set keys
switch (evt.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_LEFT:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
// Automatically delete annotations
writeMessage(new DeleteAllAnnotation(0));
break;
case KeyEvent.VK_F9:
// switch paint color (rotate)
if (!activated) {
setActivated(true);
paintControls.updateActivatedState(activated);
}
toggleColor();
// consume key
return;
case KeyEvent.VK_F10:
// switch paint mode (rotate)
if (!activated) {
setActivated(true);
paintControls.updateActivatedState(activated);
}
togglePaintMode();
// consume key
return;
case KeyEvent.VK_F12:
// activate / deactivte painting
setActivated(!activated);
paintControls.updateActivatedState(activated);
// consume key
return;
}
// TODO: add option panel to set keys
if (!textMode) {
switch (evt.getKeyCode()) {
case KeyEvent.VK_PAGE_UP:
case KeyEvent.VK_PAGE_DOWN:
case KeyEvent.VK_RIGHT:
case KeyEvent.VK_LEFT:
case KeyEvent.VK_UP:
case KeyEvent.VK_DOWN:
// Automatically delete annotations
writeMessage(new DeleteAllAnnotation(0));
break;
case KeyEvent.VK_F9:
// switch paint color (rotate)
if (!activated) {
setActivated(true);
paintControls.updateActivatedState(activated);
}
toggleColor();
// consume key
return;
case KeyEvent.VK_F10:
// switch paint mode (rotate)
if (!activated) {
setActivated(true);
paintControls.updateActivatedState(activated);
}
togglePaintMode();
// consume key
return;
case KeyEvent.VK_F12:
// activate / deactivte painting
setActivated(!activated);
paintControls.updateActivatedState(activated);
// consume key
return;
}
}
super.keyPressed(evt);
}
@Override
public void keyReleased(KeyEvent evt) {
// filter paint control keys of ttt
// TODO: option to set keys
switch (evt.getKeyCode()) {
case KeyEvent.VK_F9:
case KeyEvent.VK_F10:
case KeyEvent.VK_F12:
// consume key
return;
}
super.keyPressed(evt);
if (!textMode) {
switch (evt.getKeyCode()) {
case KeyEvent.VK_F9:
case KeyEvent.VK_F10:
case KeyEvent.VK_F12:
// consume key
return;
}
}
super.keyReleased(evt);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment