Search in sources :

Example 1 with BoundedTextAnnotationImpl

use of org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl in project cytoscape-impl by cytoscape.

the class BoundedTextAnnotationFactory method createAnnotation.

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

Example 2 with BoundedTextAnnotationImpl

use of org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl 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 3 with BoundedTextAnnotationImpl

use of org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl in project cytoscape-impl by cytoscape.

the class TextAnnotationPanel method initComponents.

private void initComponents() {
    setBorder(LookAndFeelUtil.createPanelBorder());
    final JLabel nameLabel = new JLabel("Annotation Name:");
    final JLabel label1 = new JLabel("Text:");
    final JLabel label2 = new JLabel("Font Family:");
    final JLabel label3 = new JLabel("Style:");
    final JLabel label4 = new JLabel("Size:");
    nameField = new JTextField(32);
    if (!(annotation instanceof BoundedTextAnnotationImpl)) {
        if (annotation.getName() != null) {
            nameField.setText(annotation.getName());
        }
        nameField.addMouseListener(new TextFieldMouseListener(nameField, preview));
    }
    annotationText = new JTextField(annotation.getText());
    textColorButton = new ColorButton(getTextColor());
    fontTypeList = new JList<>();
    fontStyleList = new JList<>();
    fontSizeList = new JList<>();
    final JScrollPane scrollPane1 = new JScrollPane(fontTypeList);
    final JScrollPane scrollPane2 = new JScrollPane(fontStyleList);
    final JScrollPane scrollPane3 = new JScrollPane(fontSizeList);
    final String[] familyStrings = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
    fontTypeList.setModel(new AbstractListModel<String>() {

        @Override
        public int getSize() {
            return familyStrings.length;
        }

        @Override
        public String getElementAt(int i) {
            return familyStrings[i];
        }
    });
    for (int i = 0; i < fontTypeList.getModel().getSize(); i++) {
        if (annotation.getFont().getFamily().equals((String) fontTypeList.getModel().getElementAt(i))) {
            fontTypeList.setSelectedValue(familyStrings[i], true);
            break;
        }
    }
    // Font style
    final String[] typeStrings = { "Plain", "Bold", "Italic", "Bold and Italic" };
    fontStyleList.setModel(new AbstractListModel<String>() {

        @Override
        public int getSize() {
            return typeStrings.length;
        }

        @Override
        public String getElementAt(int i) {
            return typeStrings[i];
        }
    });
    if (annotation.getFont().getStyle() == Font.PLAIN)
        fontStyleList.setSelectedValue(typeStrings[0], true);
    else if (annotation.getFont().getStyle() == Font.BOLD)
        fontStyleList.setSelectedValue(typeStrings[1], true);
    else if (annotation.getFont().getStyle() == Font.ITALIC)
        fontStyleList.setSelectedValue(typeStrings[2], true);
    else
        fontStyleList.setSelectedValue(typeStrings[3], true);
    // Font size
    final String[] sizeStrings = { "10", "12", "14", "16", "18", "20", "22", "24", "26", "28", "30", "32", "34", "36" };
    fontSizeList.setModel(new AbstractListModel<String>() {

        @Override
        public int getSize() {
            return sizeStrings.length;
        }

        @Override
        public String getElementAt(int i) {
            return sizeStrings[i];
        }
    });
    int fontSize = annotation.getFont().getSize();
    if (fontSize % 2 != 0)
        fontSize++;
    int i = 0;
    for (i = 0; i < fontSizeList.getModel().getSize(); i++) {
        if (fontSize == Integer.parseInt((String) fontSizeList.getModel().getElementAt(i))) {
            fontSizeList.setSelectedValue(sizeStrings[i], true);
            break;
        }
    }
    if (i == fontSizeList.getModel().getSize())
        fontSizeList.setSelectedValue(sizeStrings[2], true);
    iModifyTAPreview();
    fontStyleList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            fontStyleListValueChanged(evt);
        }
    });
    fontTypeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            fontTypeListValueChanged(evt);
        }
    });
    fontSizeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            fontSizeListValueChanged(evt);
        }
    });
    textColorButton.setToolTipText("Select text color...");
    textColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            preview.setTextColor((Color) evt.getNewValue());
            previewPanel.repaint();
        }
    });
    annotationText.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            annotationTextActionPerformed(evt);
        }
    });
    final GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    GroupLayout.Group hGroup = layout.createParallelGroup(LEADING, true);
    if (!(annotation instanceof BoundedTextAnnotationImpl)) {
        hGroup.addGroup(layout.createSequentialGroup().addComponent(nameLabel).addComponent(nameField));
    }
    hGroup.addGroup(layout.createSequentialGroup().addComponent(label1, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addPreferredGap(ComponentPlacement.RELATED).addComponent(annotationText, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(textColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(LEADING, true).addComponent(label2).addComponent(scrollPane1)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(LEADING, true).addComponent(label3).addComponent(scrollPane2)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(LEADING, true).addComponent(label4).addComponent(scrollPane3))).addGroup(layout.createSequentialGroup().addComponent(scrollPane2, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(scrollPane3, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE));
    layout.setHorizontalGroup(hGroup);
    GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
    if (!(annotation instanceof BoundedTextAnnotationImpl)) {
        vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(nameLabel).addComponent(nameField));
    }
    vGroup.addGroup(layout.createParallelGroup(CENTER, false).addComponent(label1).addComponent(annotationText, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(textColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(LEADING, true).addGroup(layout.createSequentialGroup().addComponent(label2, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(scrollPane1, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addComponent(label3, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(scrollPane2, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addComponent(label4, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(scrollPane3, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(vGroup);
}
Also used : JScrollPane(javax.swing.JScrollPane) PropertyChangeEvent(java.beans.PropertyChangeEvent) BoundedTextAnnotationImpl(org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) ListSelectionListener(javax.swing.event.ListSelectionListener) ColorButton(org.cytoscape.util.swing.ColorButton) ActionListener(java.awt.event.ActionListener) GroupLayout(javax.swing.GroupLayout)

Aggregations

BoundedTextAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl)3 ActionEvent (java.awt.event.ActionEvent)2 GroupLayout (javax.swing.GroupLayout)2 Color (java.awt.Color)1 ActionListener (java.awt.event.ActionListener)1 PropertyChangeEvent (java.beans.PropertyChangeEvent)1 PropertyChangeListener (java.beans.PropertyChangeListener)1 AbstractAction (javax.swing.AbstractAction)1 JButton (javax.swing.JButton)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JScrollPane (javax.swing.JScrollPane)1 JTextField (javax.swing.JTextField)1 ListSelectionEvent (javax.swing.event.ListSelectionEvent)1 ListSelectionListener (javax.swing.event.ListSelectionListener)1 DGraphView (org.cytoscape.ding.impl.DGraphView)1 ColorButton (org.cytoscape.util.swing.ColorButton)1 BoundedTextAnnotation (org.cytoscape.view.presentation.annotations.BoundedTextAnnotation)1 ShapeAnnotation (org.cytoscape.view.presentation.annotations.ShapeAnnotation)1 TextAnnotation (org.cytoscape.view.presentation.annotations.TextAnnotation)1