Author: kono
Date: 2009-05-28 13:47:56 -0700 (Thu, 28 May 2009)
New Revision: 16834
Added:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/CyLabelPositionPropertyEditor.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPlacerControl.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPlacerGraphic.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPositionCellRenderer.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPositionChooser.java
Modified:
core3/ding-presentation-impl/trunk/pom.xml
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPosition.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/PresentationFactoryImpl.java
Log:
Two D properties are moved to general property package. Now it includes 3D
properties,too.
Modified: core3/ding-presentation-impl/trunk/pom.xml
===================================================================
--- core3/ding-presentation-impl/trunk/pom.xml 2009-05-28 20:47:05 UTC (rev
16833)
+++ core3/ding-presentation-impl/trunk/pom.xml 2009-05-28 20:47:56 UTC (rev
16834)
@@ -155,6 +155,39 @@
<artifactId>spacial</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
+ <dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>spring-osgi-core</artifactId>
+ <version>1.2.0</version>
+ <type>bundle</type>
+ </dependency>
+
+ <!-- Wrapped libraries -->
+ <dependency>
+ <groupId>org.cytoscape.wrappers</groupId>
+ <artifactId>com.l2fprod.common.sheet</artifactId>
+ <version>7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape.wrappers</groupId>
+ <artifactId>org.swinglabs.swingx</artifactId>
+ <version>0.9.7</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape.wrappers</groupId>
+ <artifactId>org.swinglabs.swing-layout</artifactId>
+ <version>1.0.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape.wrappers</groupId>
+ <artifactId>com.l2fprod.common.shared</artifactId>
+ <version>7.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.cytoscape.wrappers</groupId>
+ <artifactId>com.l2fprod.common.fontchooser</artifactId>
+ <version>7.3</version>
+ </dependency>
</dependencies>
</project>
Copied:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/CyLabelPositionPropertyEditor.java
(from rev 16720,
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/CyLabelPositionPropertyEditor.java)
===================================================================
---
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/CyLabelPositionPropertyEditor.java
2009-04-30 20:50:04 UTC (rev 16720)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/CyLabelPositionPropertyEditor.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -0,0 +1,118 @@
+/*
+ Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.ding;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import javax.swing.JButton;
+import javax.swing.JPanel;
+
+
+import com.l2fprod.common.swing.ComponentFactory;
+import com.l2fprod.common.swing.PercentLayout;
+
+
+/**
+ *
+ */
+public class CyLabelPositionPropertyEditor extends
com.l2fprod.common.beans.editor.AbstractPropertyEditor {
+ private LabelPositionCellRenderer label;
+ private JButton button;
+ private LabelPosition position;
+
+ private Component parentComponent;
+
+ /**
+ * Creates a new CyLabelPositionLabelEditor object.
+ */
+ public CyLabelPositionPropertyEditor() {
+ editor = new JPanel(new PercentLayout(PercentLayout.HORIZONTAL,
0));
+ ((JPanel) editor).add("*", label = new
LabelPositionCellRenderer());
+ label.setOpaque(false);
+ ((JPanel) editor).add(button =
ComponentFactory.Helper.getFactory().createMiniButton());
+ button.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ editLabelPosition(parentComponent);
+ }
+ });
+ ((JPanel) editor).add(button =
ComponentFactory.Helper.getFactory().createMiniButton());
+ button.setText("X");
+ button.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ LabelPosition old = position;
+ label.setValue(null);
+ position = null;
+ firePropertyChange(old, null);
+ }
+ });
+ ((JPanel) editor).setOpaque(false);
+ }
+
+ public void setParentComponent(Component parent) {
+ this.parentComponent = parent;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Object getValue() {
+ return position;
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param value DOCUMENT ME!
+ */
+ public void setValue(Object value) {
+ position = (LabelPosition) value;
+ label.setValue(value);
+ }
+
+ protected void editLabelPosition(Component parentComponent) {
+ final LabelPosition newVal =
LabelPositionChooser.showDialog(parentComponent, position);
+
+ if (newVal != null) {
+ final LabelPosition old = position;
+
+ setValue(newVal);
+ firePropertyChange(old, newVal);
+ }
+ }
+}
Copied:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPlacerControl.java
(from rev 16720,
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPlacerControl.java)
===================================================================
---
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPlacerControl.java
2009-04-30 20:50:04 UTC (rev 16720)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPlacerControl.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -0,0 +1,227 @@
+/*
+ File: LabelPlacerControl.java
+
+ Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.cytoscape.ding;
+
+import java.awt.GridLayout;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JComboBox;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JTextField;
+
+
+
+/**
+ * A group of widgets that specifies the placement of
+ * node labels.
+ */
+class LabelPlacerControl extends JPanel
+ implements ActionListener, PropertyChangeListener {
+ private final static long serialVersionUID = 1202339876754050L;
+ private LabelPosition lp;
+ private JComboBox justifyCombo;
+ private JTextField xoffsetBox;
+ private JTextField yoffsetBox;
+ private JComboBox nodeAnchors;
+ private JComboBox labelAnchors;
+ private boolean ignoreEvents;
+
+ LabelPlacerControl(LabelPosition pos) {
+ super();
+
+ if (pos == null)
+ lp = new LabelPosition(Label.NONE, Label.NONE,
+ Label.JUSTIFY_CENTER, 0.0, 0.0);
+ else
+ lp = pos;
+
+ ignoreEvents = false;
+
+ setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
+
+ JPanel anchorNames = new JPanel();
+ anchorNames.setLayout(new GridLayout(2, 2));
+
+ String[] points = LabelPosition.getAnchorNames();
+
+ JLabel nodeAnchorLabel = new JLabel("Node Anchor Points ");
+ nodeAnchors = new JComboBox(points);
+ nodeAnchors.addActionListener(this);
+ anchorNames.add(nodeAnchorLabel);
+ anchorNames.add(nodeAnchors);
+
+ JLabel labelAnchorLabel = new JLabel("Label Anchor Points");
+ labelAnchors = new JComboBox(points);
+ labelAnchors.addActionListener(this);
+ anchorNames.add(labelAnchorLabel);
+ anchorNames.add(labelAnchors);
+
+ add(anchorNames);
+
+ JPanel justifyPanel = new JPanel();
+ justifyPanel.setLayout(new GridLayout(1, 2));
+
+ JLabel justifyLabel = new JLabel("Label Justification");
+ String[] justifyTypes = LabelPosition.getJustifyNames();
+ justifyCombo = new JComboBox(justifyTypes);
+ justifyCombo.addActionListener(this);
+ justifyPanel.add(justifyLabel);
+ justifyPanel.add(justifyCombo);
+
+ add(justifyPanel);
+
+ JPanel offsetPanel = new JPanel();
+ offsetPanel.setLayout(new GridLayout(2, 2));
+
+ JLabel xoffsetLabel = new JLabel("X Offset Value (can be negative)");
+ xoffsetBox = new JTextField("0", 8);
+ xoffsetBox.addActionListener(this);
+ offsetPanel.add(xoffsetLabel);
+ offsetPanel.add(xoffsetBox);
+
+ JLabel yoffsetLabel = new JLabel("Y Offset Value (can be negative)");
+ yoffsetBox = new JTextField("0", 8);
+ yoffsetBox.addActionListener(this);
+ offsetPanel.add(yoffsetLabel);
+ offsetPanel.add(yoffsetBox);
+
+ add(offsetPanel);
+
+ applyPosition();
+ }
+
+ private void applyPosition() {
+ ignoreEvents = true; // so that we don't pay attention to events
generated from these calls
+
+ int nodeAnchor = lp.getTargetAnchor();
+ int labelAnchor = lp.getLabelAnchor();
+
+ if (nodeAnchor == Label.NONE)
+ nodeAnchors.setSelectedIndex(-1);
+ else
+ nodeAnchors.setSelectedItem(LabelPosition.convert(nodeAnchor));
+
+ if (labelAnchor == Label.NONE)
+ labelAnchors.setSelectedIndex(-1);
+ else
+ labelAnchors.setSelectedItem(LabelPosition.convert(labelAnchor));
+
+ justifyCombo.setSelectedItem(LabelPosition.convert(lp.getJustify()));
+ xoffsetBox.setText(Integer.valueOf((int) lp.getOffsetX()).toString());
+ yoffsetBox.setText(Integer.valueOf((int) lp.getOffsetY()).toString());
+ ignoreEvents = false;
+ repaint();
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void actionPerformed(ActionEvent e) {
+ // ignore events that are generated by setting values to match
+ // the graphic
+ if (ignoreEvents)
+ return;
+
+ Object source = e.getSource();
+ boolean changed = false;
+
+ if (source == nodeAnchors) {
+ lp.setTargetAnchor(
+ LabelPosition.convert((String) nodeAnchors.getSelectedItem()));
+ changed = true;
+ }
+
+ if (source == labelAnchors) {
+ lp.setLabelAnchor(
+ LabelPosition.convert((String)
labelAnchors.getSelectedItem()));
+ changed = true;
+ }
+
+ if (source == justifyCombo) {
+ lp.setJustify(
+ LabelPosition.convert((String)
justifyCombo.getSelectedItem()));
+ changed = true;
+ }
+
+ // handle both at the same time since people might forget to press
enter
+ if ((getOffset(xoffsetBox) != lp.getOffsetX()) ||
+ (getOffset(yoffsetBox) != lp.getOffsetY())) {
+ lp.setOffsetX(getOffset(xoffsetBox));
+ lp.setOffsetY(getOffset(yoffsetBox));
+ changed = true;
+ }
+
+ if (!changed)
+ return; // nothing we care about has changed
+
+ firePropertyChange("LABEL_POSITION_CHANGED", null, lp);
+ }
+
+ private double getOffset(JTextField jtf) {
+ try {
+ double d = Double.parseDouble(jtf.getText());
+
+ return d;
+ } catch (Exception ex) {
+ System.err.println("not a number!");
+ jtf.setText("0");
+
+ return 0.0;
+ }
+ }
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param e DOCUMENT ME!
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+ String type = e.getPropertyName();
+
+ if (type.equals("LABEL_POSITION_CHANGED")) {
+ lp = (LabelPosition) e.getNewValue();
+ applyPosition();
+ }
+ }
+}
Copied:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPlacerGraphic.java
(from rev 16720,
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPlacerGraphic.java)
===================================================================
---
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPlacerGraphic.java
2009-04-30 20:50:04 UTC (rev 16720)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPlacerGraphic.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -0,0 +1,486 @@
+package org.cytoscape.ding;
+
+/*
+File: LabelPlacerGraphic.java
+
+Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+
+The Cytoscape Consortium is:
+- Institute for Systems Biology
+- University of California San Diego
+- Memorial Sloan-Kettering Cancer Center
+- Institut Pasteur
+- Agilent Technologies
+
+This library is free software; you can redistribute it and/or modify it
+under the terms of the GNU Lesser General Public License as published
+by the Free Software Foundation; either version 2.1 of the License, or
+any later version.
+
+This library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+documentation provided hereunder is on an "as is" basis, and the
+Institute for Systems Biology and the Whitehead Institute
+have no obligations to provide maintenance, support,
+updates, enhancements or modifications. In no event shall the
+Institute for Systems Biology and the Whitehead Institute
+be liable to any party for direct, indirect, special,
+incidental or consequential damages, including lost profits, arising
+out of the use of this software and its documentation, even if the
+Institute for Systems Biology and the Whitehead Institute
+have been advised of the possibility of such damage. See
+the GNU Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public License
+along with this library; if not, write to the Free Software Foundation,
+Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Dimension;
+import java.awt.FontMetrics;
+import java.awt.Graphics;
+import java.awt.Graphics2D;
+import java.awt.Point;
+import java.awt.RenderingHints;
+import java.awt.Stroke;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseMotionAdapter;
+import java.awt.geom.Point2D;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.JPanel;
+
+
+
+/**
+* A drag and drop graphic that allows users to set the placement
+* of node labels.
+*/
+public class LabelPlacerGraphic extends JPanel implements
PropertyChangeListener {
+
+ private LabelPosition lp;
+
+ // dimensions of panel
+ private int default_xy = 500;
+ private int xy;
+ private int center;
+ private float offsetRatio;
+
+ // dimensions for node box
+ private int nxy;
+
+ // locations of node points
+ private int[] npoints;
+
+ // dimensions for label box
+ private int lx;
+ private int ly;
+
+ // locations for label points
+ private int[] lxpoints;
+ private int[] lypoints;
+
+ // diameter of a point
+ private int dot;
+
+ // x/y positions for label box, initially offset
+ private int xPos;
+ private int yPos;
+
+ // indices of the closest points
+ private int bestLabelX = 1;
+ private int bestLabelY = 1;
+ private int bestNodeX = 1;
+ private int bestNodeY = 1;
+
+ // mouse drag state
+ private boolean beenDragged = false;
+ private boolean canOffsetDrag = false;
+
+ // click offset
+ private int xClickOffset = 0;
+ private int yClickOffset = 0;
+
+ // the x and y offsets for the label rendering
+ private int xOffset;
+ private int yOffset;
+
+ // default text justify rule
+ private int justify;
+
+ // used to label box and node
+ private Color transparentRed = new Color(1.0f, 0.0f, 0.0f, 0.1f);
+ private Color transparentBlue = new Color(0.0f, 0.0f, 1.0f, 0.1f);
+ private Color transparentMagenta = new Color(0.0f, 0.0f, 1.0f, 0.05f);
+
+ // used to determine the render level of detail
+ private boolean renderDetail;
+
+ // strings for the graphic
+ private String label = "LABEL";
+ private String node = "NODE";
+ private String click = "CLICK 'N DRAG";
+
+ // font metrics for strings
+ private int labelLen = 0;
+ private int nodeLen = 0;
+ private int clickLen = 0;
+ private int ascent = 0;
+ private int detailStrokeWidth = 3;
+ private int lowStrokeWidth = 1;
+ private Stroke detailStroke = new BasicStroke(detailStrokeWidth);
+ private Stroke lowStroke = new BasicStroke(lowStrokeWidth);
+
+ private double gravityDistance = 10;
+
+ /**
+ * A gui for placing a label relative to a node. Draws the graphic
+ * in full detail at a size of 500 pixels.
+ * @param pos initial label position
+ */
+ public LabelPlacerGraphic(LabelPosition pos) {
+ this(pos, 500, true);
+ }
+
+ /**
+ * A gui for placing a label relative to a node.
+ * @param pos initial label position
+ * @param size number of pixels square the that graphic should be
+ * @param fullDetail whether or not to render at full detail or not
+ */
+ public LabelPlacerGraphic(LabelPosition pos, int size, boolean
fullDetail) {
+ super();
+
+ if (pos == null)
+ lp = new LabelPosition(Label.NONE, Label.NONE,
Label.JUSTIFY_CENTER, 0.0, 0.0);
+ else
+ lp = pos;
+
+ renderDetail = fullDetail;
+
+ initSize(size);
+
+ setPreferredSize(new Dimension(xy, xy));
+ setBackground(Color.white);
+
+
+ addMouseListener(new MouseClickHandler());
+ addMouseMotionListener(new MouseDragHandler());
+
+ applyPosition();
+
+ repaint();
+ }
+
+ private void initSize(int size) {
+ // dimensions of panel
+ xy = size;
+ center = xy / 2;
+
+ offsetRatio = (float) xy / (float) default_xy;
+
+ // dimensions for node box
+ nxy = (int) (0.3 * xy);
+
+ // locations of node points
+ int[] tnpoints = { center - (nxy / 2), center, center + (nxy /
2) };
+ npoints = tnpoints;
+
+ // dimensions for label box
+ lx = (int) (0.4 * xy);
+ ly = (int) (0.1 * xy);
+
+ // locations for label points
+ int[] tlxpoints = { 0, lx / 2, lx };
+ int[] tlypoints = { 0, ly / 2, ly };
+ lxpoints = tlxpoints;
+ lypoints = tlypoints;
+
+ // diameter of a point
+ dot = (int) (0.02 * xy);
+
+ // x/y positions for label box, initially offset
+ xPos = dot;
+ yPos = dot;
+ }
+
+ /**
+ * The method that handles the rendering of placement gui.
+ */
+ public void paint(Graphics gin) {
+ Graphics2D g = (Graphics2D) gin;
+
+ g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
+
+ // calculate the font
+ if (labelLen <= 0) {
+ FontMetrics fm = g.getFontMetrics();
+ labelLen = fm.stringWidth(label);
+ nodeLen = fm.stringWidth(node);
+ clickLen = fm.stringWidth(click);
+ ascent = fm.getMaxAscent();
+ }
+
+ // clear the screen
+ g.setColor(Color.white);
+ g.fillRect(0, 0, xy, xy);
+
+ // draw the node box
+ int x = center - (nxy / 2);
+ int y = center - (nxy / 2);
+
+ g.setColor(transparentBlue);
+ g.fillOval(x, y, nxy, nxy);
+
+ if (renderDetail)
+ g.setStroke(detailStroke);
+ else
+ g.setStroke(lowStroke);
+
+ g.setColor(Color.blue);
+ g.drawLine(x, y, x + nxy, y);
+ g.drawLine(x + nxy, y, x + nxy, y + nxy);
+ g.drawLine(x + nxy, y + nxy, x, y + nxy);
+ g.drawLine(x, y + nxy, x, y);
+
+ if (renderDetail) {
+ g.drawString(node, center - (nxy / 12), center - (nxy /
6));
+
+ // draw the node box points
+ g.setColor(Color.black);
+ int gd = (int)((gravityDistance * 2)+(dot/2));
+
+ for (int i = 0; i < npoints.length; i++)
+ for (int j = 0; j < npoints.length; j++) {
+ g.setColor(transparentMagenta);
+ g.fillOval(npoints[i] - (gd / 2),
npoints[j] - (gd / 2), gd, gd);
+ if ((i == bestNodeX) && (j ==
bestNodeY) && !beenDragged)
+ g.setColor(Color.yellow);
+ else
+ g.setColor(Color.black);
+ g.fillOval(npoints[i] - (dot / 2),
npoints[j] - (dot / 2), dot, dot);
+ }
+ }
+
+ // draw the label box
+ g.setColor(transparentRed);
+ g.fillRect(xOffset + xPos, yOffset + yPos, lx, ly);
+
+ g.setColor(Color.red);
+ g.drawLine(xOffset + xPos, yOffset + yPos, xOffset + xPos + lx,
yOffset + yPos);
+ g.drawLine(xOffset + xPos + lx, yOffset + yPos, xOffset + xPos
+ lx, yOffset + yPos + ly);
+ g.drawLine(xOffset + xPos + lx, yOffset + yPos + ly, xOffset +
xPos, yOffset + yPos + ly);
+ g.drawLine(xOffset + xPos, yOffset + yPos + ly, xOffset + xPos,
yOffset + yPos);
+
+ // draw the string in the justified location
+ if (renderDetail) {
+ int vspace = (ly - ascent - ascent) / 3;
+
+ if (justify == Label.JUSTIFY_LEFT) {
+ g.drawString(label, xOffset + xPos +
detailStrokeWidth,
+ yOffset + yPos + vspace + ascent);
+ g.drawString(click, xOffset + xPos +
detailStrokeWidth,
+ yOffset + yPos + (2 * (vspace +
ascent)));
+ } else if (justify == Label.JUSTIFY_RIGHT) {
+ g.drawString(label, xOffset + xPos + (lx -
labelLen),
+ yOffset + yPos + vspace + ascent);
+ ;
+ g.drawString(click, xOffset + xPos + (lx -
clickLen),
+ yOffset + yPos + (2 * (vspace +
ascent)));
+ } else { // center
+ g.drawString(label, (xOffset + xPos + ((lx -
labelLen) / 2)) - detailStrokeWidth,
+ yOffset + yPos + vspace + ascent);
+ g.drawString(click, (xOffset + xPos + ((lx -
clickLen) / 2)) - detailStrokeWidth,
+ yOffset + yPos + (2 * (vspace +
ascent)));
+ }
+ } else {
+ g.setColor(Color.gray);
+
+ if (justify == Label.JUSTIFY_LEFT)
+ g.drawLine(xOffset + xPos + lowStrokeWidth,
yOffset + yPos + (ly / 2),
+ xOffset + xPos + (lx / 3), yOffset +
yPos + (ly / 2));
+ else if (justify == Label.JUSTIFY_RIGHT)
+ g.drawLine(xOffset + xPos + ((2 * lx) / 3),
yOffset + yPos + (ly / 2),
+ xOffset + xPos + lx, yOffset + yPos
+ (ly / 2));
+ else
+ g.drawLine(xOffset + xPos + (lx / 3), yOffset +
yPos + (ly / 2),
+ (xOffset + xPos + ((2 * lx) / 3)) -
lowStrokeWidth,
+ yOffset + yPos + (ly / 2));
+ }
+
+ if (renderDetail) {
+ // draw the label box points
+ g.setColor(Color.black);
+
+ for (int i = 0; i < lxpoints.length; i++)
+ for (int j = 0; j < lypoints.length; j++) {
+ if ((i == bestLabelX) && (j ==
bestLabelY) && !beenDragged)
+ g.setColor(Color.yellow);
+
+ g.fillOval((xPos + xOffset +
lxpoints[i]) - (dot / 2),
+ (yPos + yOffset +
lypoints[j]) - (dot / 2),
+ dot, dot);
+
+ if ((i == bestLabelX) && (j ==
bestLabelY))
+ g.setColor(Color.black);
+ }
+ }
+ }
+
+ private class MouseClickHandler extends MouseAdapter {
+ /**
+ * Only allows dragging if we're in the label box.
+ * Also sets the offset from where the click is and where
+ * the box is, so the box doesn't appear to jump around
+ * too much.
+ */
+ public void mousePressed(MouseEvent e) {
+ int x = e.getX();
+ int y = e.getY();
+
+ // click+drag within box
+ if ((x >= (xPos + xOffset)) && (x <= (xPos + xOffset +
lx)) &&
+ (y >= (yPos + yOffset)) && (y <= (yPos + yOffset +
ly))) {
+ canOffsetDrag = true;
+ xClickOffset = x - xPos;
+ yClickOffset = y - yPos;
+ }
+ }
+
+ /**
+ * Finds the closest points once the dragging is finished.
+ */
+ public void mouseReleased(MouseEvent e) {
+ if (beenDragged) {
+
+ int x = e.getX();
+ int y = e.getY();
+
+ // top right
+ xPos = x - xClickOffset + xOffset;
+ yPos = y - yClickOffset + yOffset;
+
+ double best = Double.POSITIVE_INFINITY;
+ double offX = 0;
+ double offY = 0;
+
+ // loop over each point in the node box
+ for (int i = 0; i < npoints.length; i++) {
+ for (int j = 0; j < npoints.length;
j++) {
+ Point nodePoint = new
Point(npoints[i] - (dot / 2), npoints[j] - (dot / 2));
+
+ // loop over each point in the
label box
+ for (int a = 0; a <
lxpoints.length; a++) {
+ for (int b = 0; b <
lypoints.length; b++) {
+ Point
labelPoint = new Point((xPos + lxpoints[a]) - (dot / 2),
+
(yPos + lypoints[b]) - (dot / 2));
+
+ double dist =
labelPoint.distance((Point2D) nodePoint);
+
+ if (dist <
best) {
+ best =
dist;
+
bestLabelX = a;
+
bestLabelY = b;
+
bestNodeX = i;
+
bestNodeY = j;
+ offX =
labelPoint.getX() - nodePoint.getX();
+ offY =
labelPoint.getY() - nodePoint.getY();
+ }
+ }
+ }
+ }
+ }
+
+ xPos = npoints[bestNodeX] -
lxpoints[bestLabelX];
+ yPos = npoints[bestNodeY] -
lypoints[bestLabelY];
+
+ if ( Math.sqrt(offX*offX + offY*offY) >
(gravityDistance+(dot/2)) ) {
+ xOffset = (int)offX;
+ yOffset = (int)offY;
+ } else {
+ xOffset = 0;
+ yOffset = 0;
+ }
+
+ lp.setOffsetX(xOffset);
+ lp.setOffsetY(yOffset);
+ lp.setLabelAnchor(bestLabelX + (3 *
bestLabelY));
+ lp.setTargetAnchor(bestNodeX + (3 * bestNodeY));
+ firePropertyChange("LABEL_POSITION_CHANGED",
null, lp);
+
+ repaint();
+ beenDragged = false;
+ canOffsetDrag = false;
+ }
+ }
+ }
+
+ private class MouseDragHandler extends MouseMotionAdapter {
+ /**
+ * Handles redrawing for dragging.
+ */
+ public void mouseDragged(MouseEvent e) {
+ // dragging within normal box
+ if (canOffsetDrag) {
+ xPos = e.getX() - xClickOffset;
+ yPos = e.getY() - yClickOffset;
+
+ beenDragged = true;
+ repaint();
+ }
+ }
+ }
+
+ /**
+ * Finds the points on the Label box and Node box that are closest.
+ */
+ private void findClosestPoint() {
+
+ }
+
+ /**
+ * Applies the new LabelPosition to the graphic.
+ */
+ private void applyPosition() {
+ xOffset = (int) (lp.getOffsetX() * offsetRatio);
+ yOffset = (int) (lp.getOffsetY() * offsetRatio);
+ justify = lp.getJustify();
+
+ int nodeAnchor = lp.getTargetAnchor();
+
+ if (nodeAnchor != Label.NONE) {
+ bestNodeX = nodeAnchor % 3;
+ bestNodeY = (int) nodeAnchor / 3;
+ }
+
+ int labelAnchor = lp.getLabelAnchor();
+
+ if (labelAnchor != Label.NONE) {
+ bestLabelX = labelAnchor % 3;
+ bestLabelY = (int) labelAnchor / 3;
+ }
+
+ if ((nodeAnchor != Label.NONE) || (labelAnchor != Label.NONE)) {
+ xPos = npoints[bestNodeX] - lxpoints[bestLabelX];
+ yPos = npoints[bestNodeY] - lypoints[bestLabelY];
+ }
+ }
+
+ /**
+ * Handles all property changes that the panel listens for.
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+ String type = e.getPropertyName();
+
+ if (type.equals("LABEL_POSITION_CHANGED")) {
+ lp = (LabelPosition) e.getNewValue();
+ applyPosition();
+ repaint();
+ }
+ }
+}
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPosition.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPosition.java
2009-05-28 20:47:05 UTC (rev 16833)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPosition.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -42,7 +42,9 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import javax.swing.Icon;
+
/**
*
*/
@@ -531,6 +533,11 @@
return "x";
}
}
+
+ //TODO: where should this go?
+ public Icon toIcon() {
+ return null;
+ }
/**
*
Copied:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPositionCellRenderer.java
(from rev 16720,
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPositionCellRenderer.java)
===================================================================
---
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPositionCellRenderer.java
2009-04-30 20:50:04 UTC (rev 16720)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPositionCellRenderer.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -0,0 +1,86 @@
+/*
+ Copyright (c) 2006, 2007, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.ding;
+
+import java.awt.Component;
+
+import javax.swing.JLabel;
+import javax.swing.JTable;
+import javax.swing.SwingConstants;
+
+
+import com.l2fprod.common.swing.renderer.DefaultCellRenderer;
+
+
+/**
+ * DING-dependent cell renderer for Label Position.
+ */
+public class LabelPositionCellRenderer extends DefaultCellRenderer {
+ private final static long serialVersionUID = 120233986947092L;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param table DOCUMENT ME!
+ * @param value DOCUMENT ME!
+ * @param isSelected DOCUMENT ME!
+ * @param hasFocus DOCUMENT ME!
+ * @param row DOCUMENT ME!
+ * @param column DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected,
+ boolean hasFocus, int
row, int column) {
+ final JLabel label = new JLabel();
+
+ if (isSelected) {
+ label.setBackground(table.getSelectionBackground());
+ label.setForeground(table.getSelectionForeground());
+ } else {
+ label.setBackground(table.getBackground());
+ label.setForeground(table.getForeground());
+ }
+
+ if ((value != null) && value instanceof LabelPosition) {
+ final LabelPosition lp = (LabelPosition) value;
+ label.setIcon(lp.toIcon());
+ label.setVerticalAlignment(SwingConstants.CENTER);
+ label.setHorizontalAlignment(SwingConstants.CENTER);
+ }
+
+ return label;
+ }
+}
Copied:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPositionChooser.java
(from rev 16720,
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPositionChooser.java)
===================================================================
---
core3/vizmap-gui/trunk/src/main/java/org/cytoscape/ding/vizmap/LabelPositionChooser.java
2009-04-30 20:50:04 UTC (rev 16720)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/LabelPositionChooser.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -0,0 +1,161 @@
+/*
+ File: PopupLabelPositionChooser.java
+
+ Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+
+ The Cytoscape Consortium is:
+ - Institute for Systems Biology
+ - University of California San Diego
+ - Memorial Sloan-Kettering Cancer Center
+ - Institut Pasteur
+ - Agilent Technologies
+
+ This library is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published
+ by the Free Software Foundation; either version 2.1 of the License, or
+ any later version.
+
+ This library is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. The software and
+ documentation provided hereunder is on an "as is" basis, and the
+ Institute for Systems Biology and the Whitehead Institute
+ have no obligations to provide maintenance, support,
+ updates, enhancements or modifications. In no event shall the
+ Institute for Systems Biology and the Whitehead Institute
+ be liable to any party for direct, indirect, special,
+ incidental or consequential damages, including lost profits, arising
+ out of the use of this software and its documentation, even if the
+ Institute for Systems Biology and the Whitehead Institute
+ have been advised of the possibility of such damage. See
+ the GNU Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this library; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.cytoscape.ding;
+
+import java.awt.Component;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JPanel;
+
+import org.cytoscape.model.GraphObject;
+/**
+ *
+ */
+public class LabelPositionChooser extends JDialog implements
PropertyChangeListener {
+ private final static long serialVersionUID = 1202339876929138L;
+
+ protected LabelPosition lp;
+ protected LabelPosition newlp;
+
+ /**
+ * DOCUMENT ME!
+ *
+ * @param f DOCUMENT ME!
+ * @param pos DOCUMENT ME!
+ *
+ * @return DOCUMENT ME!
+ */
+ public static LabelPosition showDialog(Component parentComponent,
LabelPosition pos) {
+ final LabelPositionChooser placer = new
LabelPositionChooser(parentComponent, true, pos);
+ return placer.getLabelPosition();
+ }
+
+ private LabelPositionChooser(Component parent, boolean modal,
LabelPosition pos) {
+ super();
+ this.setModal(modal);
+ this.setLocationRelativeTo(parent);
+ init(pos);
+ }
+
+ private void init(LabelPosition pos) {
+ if (pos == null)
+ lp = new LabelPosition(Label.NONE, Label.NONE,
Label.JUSTIFY_CENTER, 0.0, 0.0);
+ else
+ lp = pos;
+
+ newlp = new LabelPosition(lp);
+
+ setTitle("Select Label Placement");
+
+ JPanel placer = new JPanel();
+ placer.setLayout(new BoxLayout(placer, BoxLayout.Y_AXIS));
+ placer.setOpaque(true); //content panes must be opaque
+
+ //Set up and connect the gui components.
+ LabelPlacerGraphic graphic = new LabelPlacerGraphic(new
LabelPosition(lp));
+ LabelPlacerControl control = new LabelPlacerControl(new
LabelPosition(lp));
+
+ control.addPropertyChangeListener(graphic);
+ control.addPropertyChangeListener(this);
+
+ graphic.addPropertyChangeListener(control);
+ graphic.addPropertyChangeListener(this);
+
+ placer.add(graphic);
+ placer.add(control);
+
+ JPanel buttonPanel = new JPanel();
+ final JButton ok = new JButton("OK");
+ ok.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ lp = newlp;
+ dispose();
+ }
+ });
+ ok.addActionListener(control);
+
+ final JButton cancel = new JButton("Cancel");
+ cancel.addActionListener(new ActionListener() {
+ public void actionPerformed(ActionEvent e) {
+ dispose();
+ }
+ });
+
+ buttonPanel.add(ok);
+ buttonPanel.add(cancel);
+ placer.add(buttonPanel);
+ add(placer);
+
+ pack();
+ setVisible(true);
+ }
+
+ private LabelPosition getLabelPosition() {
+ return lp;
+ }
+
+ /**
+ * Handles all property changes that the panel listens for.
+ */
+ public void propertyChange(PropertyChangeEvent e) {
+ String type = e.getPropertyName();
+
+ if (type.equals("LABEL_POSITION_CHANGED")) {
+ newlp = (LabelPosition) e.getNewValue();
+
+ // horrible, horrible hack
+
+ //FIXME: where is BypassHack?
+ //GraphObject go = BypassHack.getCurrentObject();
+
+// if (go != null) {
+// //TODO: make this work with new model.
+// String val =
ObjectToString.getStringValue(newlp);
+// // TODO check if attr has been created or not
and create if necessary
+//
go.attrs().set(NODE_LABEL_POSITION.getBypassAttrName(), val);
+//
+// //Cytoscape.redrawGraph(vmm.getNetworkView());
+// }
+ }
+ }
+}
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
2009-05-28 20:47:05 UTC (rev 16833)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DEdgeView.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -46,7 +46,7 @@
import org.cytoscape.ding.Label;
import org.cytoscape.ding.ArrowShape;
-import org.cytoscape.view.presentation.twod.TwoDVisualLexicon;
+import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
import org.cytoscape.view.model.View;
import org.cytoscape.view.model.VisualProperty;
import org.cytoscape.view.model.ViewChangeListener;
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
2009-05-28 20:47:05 UTC (rev 16833)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DGraphView.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -98,7 +98,7 @@
import org.cytoscape.view.model.EdgeViewTaskFactory;
import org.cytoscape.view.model.NodeViewTaskFactory;
import org.cytoscape.view.presentation.NetworkRenderer;
-import org.cytoscape.view.presentation.twod.TwoDVisualLexicon;
+import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
import org.cytoscape.work.UndoSupport;
import org.cytoscape.work.TunableInterceptor;
import org.cytoscape.work.TaskManager;
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
2009-05-28 20:47:05 UTC (rev 16833)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DNodeView.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -36,23 +36,15 @@
package org.cytoscape.ding.impl;
-import org.cytoscape.graph.render.immed.GraphGraphics;
-import org.cytoscape.graph.render.stateful.CustomGraphic;
-import org.cytoscape.model.CyNode;
-import org.cytoscape.model.CyEdge;
-import org.cytoscape.ding.EdgeView;
-import org.cytoscape.ding.GraphView;
-import org.cytoscape.ding.GraphViewChangeListener;
-import org.cytoscape.ding.Label;
-import org.cytoscape.ding.NodeView;
-import org.cytoscape.ding.NodeShape;
-
-import org.cytoscape.view.model.View;
-import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.model.ViewChangeListener;
-import org.cytoscape.view.presentation.twod.*;
-
-import java.awt.*;
+import java.awt.AlphaComposite;
+import java.awt.BasicStroke;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.Graphics2D;
+import java.awt.Paint;
+import java.awt.Shape;
+import java.awt.Stroke;
+import java.awt.TexturePaint;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
@@ -62,7 +54,22 @@
import java.util.LinkedHashSet;
import java.util.List;
+import org.cytoscape.ding.EdgeView;
+import org.cytoscape.ding.GraphView;
+import org.cytoscape.ding.GraphViewChangeListener;
+import org.cytoscape.ding.Label;
+import org.cytoscape.ding.NodeShape;
+import org.cytoscape.ding.NodeView;
+import org.cytoscape.graph.render.immed.GraphGraphics;
+import org.cytoscape.graph.render.stateful.CustomGraphic;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.view.model.View;
+import org.cytoscape.view.model.ViewChangeListener;
+import org.cytoscape.view.model.VisualProperty;
+import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
+
/**
* DOCUMENT ME!
*
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
2009-05-28 20:47:05 UTC (rev 16833)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/DVisualLexicon.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -47,41 +47,41 @@
import org.cytoscape.ding.ArrowShape;
import org.cytoscape.ding.NodeShape;
import org.cytoscape.view.model.VisualProperty;
-import org.cytoscape.view.presentation.twod.BooleanTwoDVisualProperty;
-import org.cytoscape.view.presentation.twod.ColorTwoDVisualProperty;
-import org.cytoscape.view.presentation.twod.DoubleTwoDVisualProperty;
-import org.cytoscape.view.presentation.twod.StringTwoDVisualProperty;
-import org.cytoscape.view.presentation.twod.TwoDVisualLexicon;
+import org.cytoscape.view.presentation.property.BooleanVisualProperty;
+import org.cytoscape.view.presentation.property.ColorVisualProperty;
+import org.cytoscape.view.presentation.property.DoubleVisualProperty;
+import org.cytoscape.view.presentation.property.StringVisualProperty;
+import org.cytoscape.view.presentation.property.TwoDVisualLexicon;
public class DVisualLexicon extends TwoDVisualLexicon {
- public static final VisualProperty<Boolean> NETWORK_NODE_SELECTION =
new BooleanTwoDVisualProperty(
+ public static final VisualProperty<Boolean> NETWORK_NODE_SELECTION =
new BooleanVisualProperty(
NETWORK, Boolean.TRUE, "NETWORK_NODE_SELECTION",
"Network Node Selection");
- public static final VisualProperty<Boolean> NETWORK_EDGE_SELECTION =
new BooleanTwoDVisualProperty(
+ public static final VisualProperty<Boolean> NETWORK_EDGE_SELECTION =
new BooleanVisualProperty(
NETWORK, Boolean.TRUE, "NETWORK_EDGE_SELECTION",
"Network Edge Selection");
public static final VisualProperty<NodeShape> NODE_SHAPE = new
NodeShapeTwoDVisualProperty(
NODE, NodeShape.ELLIPSE, "NODE_SHAPE", "Node Shape");
- public static final VisualProperty<? extends Paint> NODE_SELECTED_PAINT
= new ColorTwoDVisualProperty(
+ public static final VisualProperty<? extends Paint> NODE_SELECTED_PAINT
= new ColorVisualProperty(
NODE, Color.YELLOW, "NODE_SELECTED_PAINT", "Node
Selected Paint");
- public static final VisualProperty<? extends Paint> NODE_BORDER_PAINT =
new ColorTwoDVisualProperty(
+ public static final VisualProperty<? extends Paint> NODE_BORDER_PAINT =
new ColorVisualProperty(
NODE, Color.BLACK, "NODE_BORDER_PAINT", "Node Border
Paint");
- public static final VisualProperty<Double> NODE_BORDER_WIDTH = new
DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> NODE_BORDER_WIDTH = new
DoubleVisualProperty(
NODE, 2.0, "NODE_BORDER_WIDTH", "Node Border Width");
public static final VisualProperty<? extends Stroke> NODE_BORDER_STROKE
= new StrokeTwoDVisualProperty(
NODE, new BasicStroke(), "NODE_BORDER_STROKE", "Node
Border Stroke");
- public static final VisualProperty<Double> NODE_WIDTH = new
DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> NODE_WIDTH = new
DoubleVisualProperty(
NODE, 40.0, "NODE_WIDTH", "Node Width");
- public static final VisualProperty<Double> NODE_HEIGHT = new
DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> NODE_HEIGHT = new
DoubleVisualProperty(
NODE, 40.0, "NODE_HEIGHT", "Node Height");
- public static final VisualProperty<String> NODE_TOOLTIP = new
StringTwoDVisualProperty(
+ public static final VisualProperty<String> NODE_TOOLTIP = new
StringVisualProperty(
NODE, "", "NODE_TOOLTIP", "Node Tooltip");
public static final VisualProperty<Font> NODE_LABEL_FONT_FACE = new
FontTwoDVisualProperty(
NODE, new Font("SansSerif", Font.PLAIN, 10),
@@ -96,10 +96,10 @@
NODE, Anchor.CENTER, "NODE_LABEL_NODE_ANCHOR",
"Node Label Node Anchor");
- public static final VisualProperty<Double> NODE_LABEL_ANCHOR_X_OFFSET =
new DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> NODE_LABEL_ANCHOR_X_OFFSET =
new DoubleVisualProperty(
NODE, 0.0, "NODE_LABEL_ANCHOR_X_OFFSET",
"Node Label Anchor X Offset");
- public static final VisualProperty<Double> NODE_LABEL_ANCHOR_Y_OFFSET =
new DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> NODE_LABEL_ANCHOR_Y_OFFSET =
new DoubleVisualProperty(
NODE, 0.0, "NODE_LABEL_ANCHOR_Y_OFFSET",
"Node Label Anchor Y Offset");
@@ -108,24 +108,24 @@
public static final VisualProperty<Integer> NODE_TRANSPARENCY = new
IntegerTwoDVisualProperty(
NODE, 255, "NODE_TRANSPARENCY", "Node Transparency");
- public static final VisualProperty<? extends Paint> EDGE_SELECTED_PAINT
= new ColorTwoDVisualProperty(
+ public static final VisualProperty<? extends Paint> EDGE_SELECTED_PAINT
= new ColorVisualProperty(
EDGE, Color.RED, "EDGE_SELECTED_PAINT", "Edge Selected
Paint");
public static final VisualProperty<? extends Stroke> EDGE_STROKE = new
StrokeTwoDVisualProperty(
EDGE, new BasicStroke(), "EDGE_STROKE", "Edge Stroke");
- public static final VisualProperty<Double> EDGE_WIDTH = new
DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> EDGE_WIDTH = new
DoubleVisualProperty(
EDGE, 2.0, "EDGE_WIDTH", "Edge Width");
- public static final VisualProperty<? extends Paint>
EDGE_SOURCE_ARROW_SELECTED_PAINT = new ColorTwoDVisualProperty(
+ public static final VisualProperty<? extends Paint>
EDGE_SOURCE_ARROW_SELECTED_PAINT = new ColorVisualProperty(
EDGE, Color.YELLOW, "EDGE_SOURCE_ARROW_SELECTED_PAINT",
"Edge Source Arrow Selected Paint");
- public static final VisualProperty<? extends Paint>
EDGE_TARGET_ARROW_SELECTED_PAINT = new ColorTwoDVisualProperty(
+ public static final VisualProperty<? extends Paint>
EDGE_TARGET_ARROW_SELECTED_PAINT = new ColorVisualProperty(
EDGE, Color.YELLOW, "EDGE_TARGET_ARROW_SELECTED_PAINT",
"Edge Target Arrow Selected Paint");
- public static final VisualProperty<? extends Paint>
EDGE_SOURCE_ARROW_UNSELECTED_PAINT = new ColorTwoDVisualProperty(
+ public static final VisualProperty<? extends Paint>
EDGE_SOURCE_ARROW_UNSELECTED_PAINT = new ColorVisualProperty(
EDGE, Color.BLACK, "EDGE_SOURCE_ARROW_UNSELECTED_PAINT",
"Edge Source Arrow Unselected Paint");
- public static final VisualProperty<? extends Paint>
EDGE_TARGET_ARROW_UNSELECTED_PAINT = new ColorTwoDVisualProperty(
+ public static final VisualProperty<? extends Paint>
EDGE_TARGET_ARROW_UNSELECTED_PAINT = new ColorVisualProperty(
EDGE, Color.BLACK, "EDGE_TARGET_ARROW_UNSELECTED_PAINT",
"Edge Target Arrow Unselected Paint");
@@ -136,7 +136,7 @@
EDGE, ArrowShape.NONE, "EDGE_TARGET_ARROW_SHAPE",
"Edge Target Arrow Shape");
- public static final VisualProperty<String> EDGE_TOOLTIP = new
StringTwoDVisualProperty(
+ public static final VisualProperty<String> EDGE_TOOLTIP = new
StringVisualProperty(
EDGE, "", "EDGE_TOOLTIP", "Edge Tooltip");
public static final VisualProperty<Anchor> EDGE_LABEL_TEXT_ANCHOR = new
AnchorTwoDVisualProperty(
@@ -146,10 +146,10 @@
EDGE, Anchor.CENTER, "EDGE_LABEL_EDGE_ANCHOR",
"Edge Label Edge Anchor");
- public static final VisualProperty<Double> EDGE_LABEL_ANCHOR_X_OFFSET =
new DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> EDGE_LABEL_ANCHOR_X_OFFSET =
new DoubleVisualProperty(
EDGE, 0.0, "EDGE_LABEL_ANCHOR_X_OFFSET",
"Edge Label Anchor X Offset");
- public static final VisualProperty<Double> EDGE_LABEL_ANCHOR_Y_OFFSET =
new DoubleTwoDVisualProperty(
+ public static final VisualProperty<Double> EDGE_LABEL_ANCHOR_Y_OFFSET =
new DoubleVisualProperty(
EDGE, 0.0, "EDGE_LABEL_ANCHOR_Y_OFFSET",
"Edge Label Anchor Y Offset");
@@ -200,5 +200,4 @@
visualPropertySet.add(EDGE_LABEL_FONT_SIZE);
visualPropertySet.add(EDGE_LABEL_JUSTIFY);
}
-
}
Modified:
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/PresentationFactoryImpl.java
===================================================================
---
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/PresentationFactoryImpl.java
2009-05-28 20:47:05 UTC (rev 16833)
+++
core3/ding-presentation-impl/trunk/src/main/java/org/cytoscape/ding/impl/PresentationFactoryImpl.java
2009-05-28 20:47:56 UTC (rev 16834)
@@ -5,6 +5,7 @@
import java.util.HashMap;
import java.util.Map;
+import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
@@ -22,6 +23,7 @@
import org.cytoscape.view.model.NodeViewTaskFactory;
import org.cytoscape.view.model.EdgeViewTaskFactory;
import org.cytoscape.view.presentation.NavigationPresentation;
+import org.cytoscape.view.presentation.NetworkRenderer;
import org.cytoscape.view.presentation.PresentationFactory;
import org.cytoscape.work.UndoSupport;
import org.cytoscape.work.TaskManager;
@@ -35,7 +37,7 @@
private UndoSupport undo;
private RootVisualLexicon rootLexicon;
private VisualLexicon dingLexicon;
- private Map<CyNetworkView, GraphView> viewMap;
+ private Map<CyNetworkView, DGraphView> viewMap;
private Map<NodeViewTaskFactory,Map> nodeViewTFs;
private Map<EdgeViewTaskFactory,Map> edgeViewTFs;
@@ -57,30 +59,36 @@
this.ti = ti;
this.tm = tm;
- viewMap = new HashMap<CyNetworkView, GraphView>();
+ viewMap = new HashMap<CyNetworkView, DGraphView>();
nodeViewTFs = new HashMap<NodeViewTaskFactory,Map>();
edgeViewTFs = new HashMap<EdgeViewTaskFactory,Map>();
}
+ /**
+ *
+ */
public void addPresentation(Object frame, CyNetworkView view) {
-
- System.out.println("########################### add
Presentation: " + view.getSUID());
-
+
if ( view == null )
throw new NullPointerException("CyNetworkView is null");
- if ( frame instanceof JInternalFrame ) {
- JInternalFrame inFrame = (JInternalFrame)frame;
- JDesktopPane desktopPane = inFrame.getDesktopPane();
-
- DGraphView dgv = new
DGraphView(view,dataTableFactory,rootNetworkFactory,undo,spacialFactory,rootLexicon,
dingLexicon,nodeViewTFs,edgeViewTFs,ti,tm);
+ if ( frame instanceof JComponent ) {
+
+ DGraphView dgv = new
DGraphView(view,dataTableFactory,rootNetworkFactory,undo,spacialFactory,
+ rootLexicon,
dingLexicon,nodeViewTFs,edgeViewTFs,ti,tm);
viewMap.put(view, dgv);
-
- // TODO - not sure this layered pane bit is optimal
- inFrame.setContentPane(
dgv.getContainer(inFrame.getLayeredPane()) );
- dgv.addTransferComponent(desktopPane);
-
view.addViewChangeListener(dgv);
-
+
+ if(frame instanceof JInternalFrame) {
+ JInternalFrame inFrame = (JInternalFrame)frame;
+ JDesktopPane desktopPane =
inFrame.getDesktopPane();
+
+ // TODO - not sure this layered pane bit is
optimal
+ inFrame.setContentPane(
dgv.getContainer(inFrame.getLayeredPane()) );
+ dgv.addTransferComponent(desktopPane);
+ } else {
+ JComponent component = (JComponent) frame;
+ component.add(dgv.getComponent());
+ }
} else {
throw new IllegalArgumentException("frame object is not
of type JInternalFrame, which is invalid for this implementation of
PresentationFactory");
}
@@ -103,12 +111,12 @@
public void handleEvent(NetworkViewChangedEvent nvce) {
- GraphView gv = viewMap.get(nvce.getNetworkView());
+ DGraphView gv = viewMap.get(nvce.getNetworkView());
if ( gv != null )
gv.updateView();
}
- public GraphView getGraphView(CyNetworkView cnv) {
+ public DGraphView getGraphView(CyNetworkView cnv) {
return viewMap.get(cnv);
}
@@ -144,4 +152,8 @@
edgeViewTFs.remove(evtf);
}
+ public NetworkRenderer getPresentation(CyNetworkView view) {
+ return this.viewMap.get(view);
+ }
+
}
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"cytoscape-cvs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cytoscape-cvs?hl=en
-~----------~----~----~----~------~----~------~--~---