[Imagetools-commit] SF.net SVN: imagetools:[7] trunk/imagetools/src/net/codebuilders/desktop/ image
Status: Beta
Brought to you by:
cmarcum
|
From: <cm...@us...> - 2009-04-08 00:33:06
|
Revision: 7
http://imagetools.svn.sourceforge.net/imagetools/?rev=7&view=rev
Author: cmarcum
Date: 2009-04-08 00:33:05 +0000 (Wed, 08 Apr 2009)
Log Message:
-----------
Added KeyPressed methods for draw buttons to unselect button and cancel mouse listeners to stop drawing on image. Set button focusable to capture KeyEvent.
Modified Paths:
--------------
trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.form
trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.java
Modified: trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.form
===================================================================
--- trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.form 2009-04-08 00:27:08 UTC (rev 6)
+++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.form 2009-04-08 00:33:05 UTC (rev 7)
@@ -382,11 +382,13 @@
<ComponentRef name="drawButtonGroup"/>
</Property>
<Property name="text" type="java.lang.String" resourceKey="lineButton.text"/>
- <Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="name" type="java.lang.String" value="lineButton" noResource="true"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
+ <Events>
+ <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="lineButtonKeyPressed"/>
+ </Events>
</Component>
<Component class="javax.swing.JToggleButton" name="rectangleButton">
<Properties>
@@ -397,11 +399,13 @@
<ComponentRef name="drawButtonGroup"/>
</Property>
<Property name="text" type="java.lang.String" resourceKey="rectangleButton.text"/>
- <Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="name" type="java.lang.String" value="rectangleButton" noResource="true"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
+ <Events>
+ <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="rectangleButtonKeyPressed"/>
+ </Events>
</Component>
<Component class="javax.swing.JToggleButton" name="textButton">
<Properties>
@@ -412,11 +416,13 @@
<ComponentRef name="drawButtonGroup"/>
</Property>
<Property name="text" type="java.lang.String" resourceKey="textButton.text"/>
- <Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="name" type="java.lang.String" value="textButton" noResource="true"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
+ <Events>
+ <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="textButtonKeyPressed"/>
+ </Events>
</Component>
</SubComponents>
</Container>
Modified: trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.java
===================================================================
--- trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.java 2009-04-08 00:27:08 UTC (rev 6)
+++ trunk/imagetools/src/net/codebuilders/desktop/imagetools/ImageToolsView.java 2009-04-08 00:33:05 UTC (rev 7)
@@ -24,6 +24,7 @@
*/
package net.codebuilders.desktop.imagetools;
+import java.awt.event.KeyListener;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
@@ -31,6 +32,7 @@
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
+import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
@@ -53,7 +55,7 @@
/**
* The application's main frame.
*/
-public class ImageToolsView extends FrameView {
+public class ImageToolsView extends FrameView implements KeyListener {
public ImageToolsView(SingleFrameApplication app) {
super(app);
@@ -186,9 +188,9 @@
}
});
+
-
-
+
} // end constructor
@Action
@@ -464,36 +466,81 @@
lineButton.setAction(actionMap.get("drawLine")); // NOI18N
drawButtonGroup.add(lineButton);
lineButton.setText(resourceMap.getString("lineButton.text")); // NOI18N
- lineButton.setFocusable(false);
lineButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
lineButton.setName("lineButton"); // NOI18N
lineButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
+ lineButton.addKeyListener(this);
toolBar.add(lineButton);
rectangleButton.setAction(actionMap.get("drawRectangle")); // NOI18N
drawButtonGroup.add(rectangleButton);
rectangleButton.setText(resourceMap.getString("rectangleButton.text")); // NOI18N
- rectangleButton.setFocusable(false);
rectangleButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
rectangleButton.setName("rectangleButton"); // NOI18N
rectangleButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
+ rectangleButton.addKeyListener(this);
toolBar.add(rectangleButton);
textButton.setAction(actionMap.get("drawText")); // NOI18N
drawButtonGroup.add(textButton);
textButton.setText(resourceMap.getString("textButton.text")); // NOI18N
- textButton.setFocusable(false);
textButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
textButton.setName("textButton"); // NOI18N
textButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
+ textButton.addKeyListener(this);
toolBar.add(textButton);
setComponent(mainPanel);
setMenuBar(menuBar);
setStatusBar(statusPanel);
setToolBar(toolBar);
+ }
+
+ // Code for dispatching events from components to event handlers.
+
+ public void keyPressed(java.awt.event.KeyEvent evt) {
+ if (evt.getSource() == lineButton) {
+ ImageToolsView.this.lineButtonKeyPressed(evt);
+ }
+ else if (evt.getSource() == rectangleButton) {
+ ImageToolsView.this.rectangleButtonKeyPressed(evt);
+ }
+ else if (evt.getSource() == textButton) {
+ ImageToolsView.this.textButtonKeyPressed(evt);
+ }
+ }
+
+ public void keyReleased(java.awt.event.KeyEvent evt) {
+ }
+
+ public void keyTyped(java.awt.event.KeyEvent evt) {
}// </editor-fold>//GEN-END:initComponents
+ private void lineButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_lineButtonKeyPressed
+ // if ESC key, unselect button
+ if(evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ drawButtonGroup.clearSelection();
+ imageArea.tearDownMouseListeners();
+ }
+
+ }//GEN-LAST:event_lineButtonKeyPressed
+
+ private void rectangleButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_rectangleButtonKeyPressed
+ // if ESC key, unselect button
+ if(evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ drawButtonGroup.clearSelection();
+ imageArea.tearDownMouseListeners();
+ }
+ }//GEN-LAST:event_rectangleButtonKeyPressed
+
+ private void textButtonKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_textButtonKeyPressed
+ // if ESC key, unselect button
+ if(evt.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ drawButtonGroup.clearSelection();
+ imageArea.tearDownMouseListeners();
+ }
+ }//GEN-LAST:event_textButtonKeyPressed
+
@Action(enabledProperty = "captureEnabled", selectedProperty = "captureSelected")
public void captureScreen() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|