Search in sources :

Example 1 with TextAnnotation

use of org.cytoscape.view.presentation.annotations.TextAnnotation in project cytoscape-impl by cytoscape.

the class BoundedTextAnnotationDialog method initComponents.

private void initComponents() {
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setModalityType(DEFAULT_MODALITY_TYPE);
    setResizable(false);
    setTitle(create ? "Create Bounded Text Annotation" : "Modify Bounded Text Annotation");
    // Create the preview panel
    preview = new BoundedTextAnnotationImpl(view, getOwner());
    preview.setUsedForPreviews(true);
    preview.setText(mAnnotation.getText());
    preview.setFont(mAnnotation.getFont());
    preview.fitShapeToText();
    PreviewPanel previewPanel = new PreviewPanel(preview);
    shapeAnnotationPanel = new ShapeAnnotationPanel((ShapeAnnotation) mAnnotation, previewPanel);
    textAnnotationPanel = new TextAnnotationPanel((TextAnnotation) mAnnotation, previewPanel);
    applyButton = new JButton(new AbstractAction("OK") {

        @Override
        public void actionPerformed(ActionEvent e) {
            applyButtonActionPerformed(e);
        }
    });
    cancelButton = new JButton(new AbstractAction("Cancel") {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });
    final JPanel buttonPanel = LookAndFeelUtil.createOkCancelPanel(applyButton, cancelButton);
    final JPanel contents = new JPanel();
    final GroupLayout layout = new GroupLayout(contents);
    contents.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(true);
    layout.setHorizontalGroup(layout.createParallelGroup(LEADING, true).addComponent(shapeAnnotationPanel).addComponent(textAnnotationPanel).addComponent(previewPanel, DEFAULT_SIZE, PREVIEW_WIDTH, Short.MAX_VALUE).addComponent(buttonPanel));
    layout.setVerticalGroup(layout.createSequentialGroup().addComponent(shapeAnnotationPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(textAnnotationPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(previewPanel, DEFAULT_SIZE, PREVIEW_HEIGHT, Short.MAX_VALUE).addComponent(buttonPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    LookAndFeelUtil.setDefaultOkCancelKeyStrokes(getRootPane(), applyButton.getAction(), cancelButton.getAction());
    getRootPane().setDefaultButton(applyButton);
    getContentPane().add(contents);
    pack();
}
Also used : JPanel(javax.swing.JPanel) BoundedTextAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl) ActionEvent(java.awt.event.ActionEvent) ShapeAnnotation(org.cytoscape.view.presentation.annotations.ShapeAnnotation) JButton(javax.swing.JButton) GroupLayout(javax.swing.GroupLayout) TextAnnotation(org.cytoscape.view.presentation.annotations.TextAnnotation) AbstractAction(javax.swing.AbstractAction)

Example 2 with TextAnnotation

use of org.cytoscape.view.presentation.annotations.TextAnnotation in project cytoscape-impl by cytoscape.

the class GroupAnnotationImpl method setSize.

/*
	@Override
	public void setSelected(boolean selected) {
		// for (DingAnnotation child: annotations) {
		// 	child.setSelected(selected);
		// }
		super.setSelected(selected);
	}
*/
/*
	 * 1) update our bounds
	 * 2) move each child
	 * 3) reset the size of each child
	 */
public void setSize(Dimension d) {
    // Get our width
    double width = getWidth();
    double height = getHeight();
    double dx = d.getWidth() / width;
    double dy = d.getHeight() / height;
    double x = getX();
    double y = getY();
    /*
		System.out.println("Changing size of group from: "+width+"x"+height+" to "+d.getWidth()+"x"+d.getHeight());
		System.out.println("dx = "+dx+", dy = "+dy);
		System.out.println("x = "+x+", y = "+y);
		*/
    ViewUtil.invokeOnEDTAndWait(() -> {
        // Now and move each of our children
        for (DingAnnotation child : annotations) {
            JComponent childComponent = child.getComponent();
            double childX = childComponent.getX();
            double childY = childComponent.getY();
            double childWidth = childComponent.getWidth();
            double childHeight = childComponent.getHeight();
            double newX = (childX - x) * dx + x;
            double newY = (childY - y) * dy + y;
            double newWidth = childWidth * dx;
            double newHeight = childHeight * dy;
            childComponent.setLocation((int) Math.round(newX), (int) Math.round(newY));
            child.getCanvas().modifyComponentLocation((int) Math.round(newX), (int) Math.round(newY), childComponent);
            if (child instanceof TextAnnotationImpl) {
                TextAnnotation textChild = (TextAnnotation) child;
                double fontSize = textChild.getFontSize();
                textChild.setFontSize(fontSize * dx);
            }
            if (child instanceof BoundedTextAnnotationImpl) {
                BoundedTextAnnotationImpl textChild = (BoundedTextAnnotationImpl) child;
                double fontSize = textChild.getFontSize();
                textChild.setFontSize(fontSize * dx, false);
            }
            if (child instanceof ShapeAnnotationImpl) {
                ShapeAnnotationImpl shapeChild = (ShapeAnnotationImpl) child;
                double borderWidth = shapeChild.getBorderWidth();
                double zoom = shapeChild.getZoom();
                newWidth = newWidth - borderWidth * 2 * zoom;
                newHeight = newHeight - borderWidth * 2 * zoom;
                shapeChild.setSize(newWidth, newHeight);
            }
            child.update();
        }
        super.setSize((int) d.getWidth(), (int) d.getHeight());
    });
}
Also used : JComponent(javax.swing.JComponent) TextAnnotation(org.cytoscape.view.presentation.annotations.TextAnnotation)

Example 3 with TextAnnotation

use of org.cytoscape.view.presentation.annotations.TextAnnotation in project cytoscape-impl by cytoscape.

the class TextAnnotationFactory method createAnnotation.

@Override
public TextAnnotation createAnnotation(Class<? extends TextAnnotation> type, CyNetworkView view, Map<String, String> argMap) {
    if (!(view instanceof DGraphView))
        return null;
    DGraphView dView = (DGraphView) view;
    if (type.equals(TextAnnotation.class)) {
        final TextAnnotationImpl a = new TextAnnotationImpl(dView, argMap, getActiveWindow());
        a.update();
        return (TextAnnotation) a;
    }
    return null;
}
Also used : TextAnnotation(org.cytoscape.view.presentation.annotations.TextAnnotation) TextAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.TextAnnotationImpl) DGraphView(org.cytoscape.ding.impl.DGraphView)

Aggregations

TextAnnotation (org.cytoscape.view.presentation.annotations.TextAnnotation)3 ActionEvent (java.awt.event.ActionEvent)1 AbstractAction (javax.swing.AbstractAction)1 GroupLayout (javax.swing.GroupLayout)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JPanel (javax.swing.JPanel)1 DGraphView (org.cytoscape.ding.impl.DGraphView)1 BoundedTextAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl)1 TextAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.TextAnnotationImpl)1 ShapeAnnotation (org.cytoscape.view.presentation.annotations.ShapeAnnotation)1