4,10 → 4,10 |
* Coded by: Group 5, software practice summer 2003 |
* University of Bielefeld, Germany |
* |
* @version $Revision: 1.24 $ |
* @version $Revision: 1.25 $ |
* |
* Last modification: $Date: 2003/07/23 15:02:00 $ |
* $Id: RegionEditorPlugin.java,v 1.24 2003/07/23 15:02:00 mdonner Exp $ |
* Last modification: $Date: 2003/07/23 18:32:04 $ |
* $Id: RegionEditorPlugin.java,v 1.25 2003/07/23 18:32:04 cstollen Exp $ |
*/ |
|
package src.plugins.regionEditorPlugin; |
42,7 → 42,7 |
|
import javax.swing.JButton; |
//import javax.swing.JFileChooser; |
//import javax.swing.JLabel; |
import javax.swing.JLabel; |
import javax.swing.JPanel; |
import javax.swing.JTextField; |
import javax.swing.tree.TreePath; |
60,7 → 60,7 |
* |
* @author Yulia Klassen, Viktoriya Zudova |
* |
* @version $Revision: 1.24 $ Last modification: $Date: 2003/07/23 15:02:00 $ |
* @version $Revision: 1.25 $ Last modification: $Date: 2003/07/23 18:32:04 $ |
*/ |
public class RegionEditorPlugin |
extends JPanel |
71,6 → 71,9 |
|
/* The current image. */ |
private Image image; |
|
/* Label where the name of image is. */ |
private JLabel imageNameLabel = new JLabel(" Image Name "); |
|
/* A text field to enter the name of an image. */ |
private JTextField imageNameField = new JTextField(); |
78,6 → 81,9 |
/* A button "Confirm" to change the image name in the node. */ |
private JButton confirmButton = new JButton("Confirm"); |
|
/* Label where the name of region is. */ |
private JLabel regionNameLabel = new JLabel(" Region Name "); |
|
/* A text field to enter the name of region. */ |
private JTextField regionNameField = new JTextField(); |
|
93,10 → 99,10 |
/* Stores a reference to the event listener. */ |
private OurEventListener ourEventListener; |
|
/* the image's name from the attributes of the selected node */ |
/* The image's name from the attributes of the selected node. */ |
private String imageName; |
|
/* the location of the image */ |
/* The location of the image. */ |
private String imageUrl; |
|
/* The current file. */ |
149,6 → 155,7 |
// Left panel: text field to enter name of image. |
JPanel leftPanel = new JPanel(); |
leftPanel.setLayout(new BorderLayout()); |
leftPanel.add(imageNameLabel, BorderLayout.WEST); |
leftPanel.add(imageNameField); |
leftPanel.add(confirmButton, BorderLayout.EAST); |
|
156,6 → 163,7 |
JPanel rightPanel = new JPanel(); |
rightPanel.setPreferredSize(new Dimension(240, 24)); |
rightPanel.setLayout(new BorderLayout()); |
rightPanel.add(regionNameLabel, BorderLayout.WEST); |
rightPanel.add(regionNameField); |
rightPanel.add(regionConfirmButton, BorderLayout.EAST); |
|
229,7 → 237,7 |
imageNameField.setText(imageName); |
loadImage(imageUrl); |
|
// load existing regions |
// Load existing regions. |
initRegions(node); |
|
gui.setPluginPanel(this); |
241,9 → 249,9 |
/** |
* Tries to find the Url to the belonging Imagelabel among all children of 'parent' |
* |
* @param label: The label of the Image |
* @param label: The label of the Image. |
* |
* @param parent: The node among its children we search |
* @param parent: The node among its children we search. |
* |
* @return The belonging Url. If it can not be found null is returned |
* |
282,9 → 290,12 |
} |
return null; // Url not found. |
} |
|
|
|
/** |
* Reads the existent regions from document. |
* |
* @param node: The node that the has been chosen. |
*/ |
private void initRegions(Node node) |
{ |
regions.clear(); |
304,7 → 315,7 |
for(int j = 0; j < rectChildren.getLength(); j++) { |
Node subnode = rectChildren.item(j); |
|
// get coordinates |
// Get coordinates. |
if(subnode.getNodeName().equals("COORDS")) { |
NamedNodeMap attrs = subnode.getAttributes(); |
|
315,7 → 326,7 |
h = Integer.parseInt(attrs.getNamedItem("h").getNodeValue()); |
} |
catch(NumberFormatException ex) { |
// ignore any errors in coordinates |
// Ignore any errors in coordinates. |
} |
} |
else if(subnode.getNodeName().equals("#text")) { |
385,50 → 396,63 |
public void setOurEventListener(OurEventListener newListener) { |
ourEventListener = newListener; |
} |
|
/** |
* Forces the plugin to report its status. |
*/ |
public void forceStatusReport() { |
changedNode = oldNode.cloneNode(false); |
Document tempDoc = oldNode.getOwnerDocument(); |
changedNode.getAttributes().getNamedItem("image").setNodeValue(imageName); |
java.util.Iterator i = regions.iterator(); |
while(i.hasNext()) { |
Region region = (Region)i.next(); |
i.remove(); |
System.out.println(region.getRect()); |
Text name = tempDoc.createTextNode(region.getName()); |
org.w3c.dom.Element geom = tempDoc.createElement("RECTANGLE"); |
org.w3c.dom.Element coords = tempDoc.createElement("COORDS"); |
coords.setAttribute("x", Integer.toString(region.getRect().x)); |
coords.setAttribute("y", Integer.toString(region.getRect().y)); |
coords.setAttribute("w", Integer.toString(region.getRect().width)); |
coords.setAttribute("h", Integer.toString(region.getRect().height)); |
/* Node nameNode = (Node)name; |
Node coordsNode = (Node)coords; |
Node geomNode = (Node)geom; |
System.out.println("nameNode = " + nameNode); |
System.out.println("coordsNode = " + coordsNode); |
System.out.println("geomNode = " + geomNode);*/ |
geom.appendChild(name); |
geom.appendChild(coords); |
changedNode.appendChild((Node)geom); |
} |
firePluginChangedElement(oldNode, changedNode); |
} |
|
/** |
* ... |
* |
* @param oldNode: ... |
* @param changedNode: .. |
*/ |
private void firePluginChangedElement(Node oldNode, Node changedNode) { |
OurEvent e = new OurEvent(new Object[] {oldNode, changedNode, pluginName}); |
ourEventListener.firedOurEvent(e); |
} |
|
/** |
* ... |
* |
* @param region: ... |
*/ |
private void sendRegionChanged(Region region) |
{ |
} |
|
public void forceStatusReport() { |
changedNode = oldNode.cloneNode(false); |
Document tempDoc = oldNode.getOwnerDocument(); |
changedNode.getAttributes().getNamedItem("image").setNodeValue(imageName); |
java.util.Iterator i = regions.iterator(); |
while(i.hasNext()) { |
Region region = (Region)i.next(); |
i.remove(); |
System.out.println(region.getRect()); |
Text name = tempDoc.createTextNode(region.getName()); |
org.w3c.dom.Element geom = tempDoc.createElement("RECTANGLE"); |
org.w3c.dom.Element coords = tempDoc.createElement("COORDS"); |
coords.setAttribute("x", Integer.toString(region.getRect().x)); |
coords.setAttribute("y", Integer.toString(region.getRect().y)); |
coords.setAttribute("w", Integer.toString(region.getRect().width)); |
coords.setAttribute("h", Integer.toString(region.getRect().height)); |
/*Node nameNode = (Node)name; |
Node coordsNode = (Node)coords; |
Node geomNode = (Node)geom; |
System.out.println("nameNode = " + nameNode); |
System.out.println("coordsNode = " + coordsNode); |
System.out.println("geomNode = " + geomNode);*/ |
geom.appendChild(name); |
geom.appendChild(coords); |
changedNode.appendChild((Node)geom); |
} |
firePluginChangedElement(oldNode, changedNode); |
} |
|
private void firePluginChangedElement(Node oldNode, Node changedNode) { |
OurEvent e = new OurEvent(new Object[] {oldNode, changedNode, pluginName}); |
ourEventListener.firedOurEvent(e); |
} |
|
private void sendRegionChanged(Region region) |
{ |
} |
|
/** |
* Loads image. |
* |
* @param fileName the file name that must be shown |
* @param fileName: The file name that must be shown: |
*/ |
private void loadImage(String fileName) |
{ |
473,7 → 497,7 |
/** |
* Reaction of all buttons. |
* |
* @param e some event |
* @param e: Some event. |
*/ |
public void actionPerformed(ActionEvent e) |
{ |
496,11 → 520,9 |
|
|
/** |
* Invoked when a mouse button is pressed on a component. |
* Invoked when a mouse is pressed on a component. |
* |
* @see |
* |
* @param e mouse event |
* @param e: Mouse event. |
*/ |
public void mouseDragged(MouseEvent e) |
{ |
557,9 → 579,9 |
} |
|
/** |
* Invoked when the mouse button has been moved on a component (with no buttons no down). |
* Invoked when the mouse has been moved on a component (with no buttons no down). |
* |
* @param e mouse event |
* @param e: Mouse event. |
*/ |
public void mouseMoved(MouseEvent e) |
{ |
587,7 → 609,8 |
/** |
* Shows the current position of mouse. |
* |
* @param e mouse event |
* @param mouseX: Position of mouse. |
* @param mouseY: Position of mouse. |
*/ |
public void showMouse(int mouseX, int mouseY) |
{ |
621,9 → 644,9 |
} |
|
/** |
* Invoked when a mouse button has been pressed on a Component. |
* Invoked when a mouse has been pressed on a Component. |
* |
* @param e mouse event |
* @param e: Mouse event. |
*/ |
public void mousePressed(MouseEvent e) |
{ |
656,7 → 679,7 |
} |
|
/** |
* Invoked when a mouse button has been released on a component. |
* Invoked when a mouse has been released on a component. |
* |
* @param e: A mouse event indicating that a mouse button has been |
* pressed on a component. |
697,9 → 720,9 |
} |
|
/** |
* ... |
* Adds new region. |
* |
* @param region add the given region |
* @param region: Add the given region. |
*/ |
public void addRegion(Region region) |
{ |
708,9 → 731,9 |
} |
|
/** |
* ... |
* Delets a region. |
* |
* @param region delete the given region |
* @param region: Delete the given region. |
*/ |
public void deleteRegion(Region region) |
{ |
720,10 → 743,10 |
} |
|
/** |
* ... |
* Selects a region. |
* |
* @param x point of region that the user will select |
* @param y point of region that the user will select |
* @param x: Point of region that the user will select. |
* @param y: Point of region that the user will select. |
*/ |
private void selectRegion(int x, int y) |
{ |
743,13 → 766,14 |
} |
|
/** |
* ... |
* Finds region that must be moved or resized. |
* |
* @param x ... |
* @param y ... |
* @param nordWest ... |
* @param x: Position of mouse. |
* @param y: Position of mouse. |
* @param nordWest: If true then top left of corner will be serched, |
* else bottom right of corner will be serched. |
* |
* @return |
* @return currentRegion or null if nothing was found. |
*/ |
private Region findRegion(int x, int y, boolean nordWest) |
{ |
784,10 → 808,10 |
} |
|
/** |
* ... |
* Shows popup menu. |
* |
* @param x ... |
* @param y ... |
* @param x: Position of menu. |
* @param y: Position of menu. |
*/ |
private void showPopup(int x, int y) |
{ |
802,7 → 826,7 |
/** |
* Sets the currently selected region in the image panel. |
* |
* @param region The region selected. |
* @param region: The region selected. |
*/ |
private void setSelectedRegion(Region region) { |
selectedRegion = region; |