Search in sources :

Example 1 with ColorButton

use of org.cytoscape.util.swing.ColorButton in project cytoscape-impl by cytoscape.

the class ArrowAnnotationPanel method getArrowPanel.

private JPanel getArrowPanel(final ArrowEnd end) {
    final JLabel label1 = new JLabel("Shape:");
    final JLabel label2 = new JLabel("Color:");
    final JLabel label3 = new JLabel("Opacity:");
    final JLabel label4 = new JLabel("Size:");
    final JLabel label5 = new JLabel("Anchor:");
    final JComboBox<String> arrowTypeCombo = new JComboBox<>();
    final List<String> arrows = annotation.getSupportedArrows();
    arrowTypeCombo.setModel(new DefaultComboBoxModel<String>(arrows.toArray(new String[arrows.size()])));
    arrowTypeCombo.setSelectedItem(annotation.getArrowType(end));
    arrowTypeCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            preview.setArrowType(end, (String) arrowTypeCombo.getSelectedItem());
            previewPanel.repaint();
        }
    });
    final ColorButton arrowColorButton = new ColorButton((Color) preview.getArrowColor(end));
    arrowColorButton.setToolTipText("Select arrow color...");
    final JSlider arrowOpacitySlider = new JSlider(0, 100);
    final JCheckBox arrowColorCheck = new JCheckBox();
    arrowColorCheck.setSelected(annotation.getArrowColor(end) != null);
    arrowColorCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            if (arrowColorCheck.isSelected()) {
                arrowColorButton.setEnabled(true);
                arrowOpacitySlider.setEnabled(true);
                preview.setArrowColor(end, mixColor(arrowColorButton.getColor(), arrowOpacitySlider.getValue()));
            } else {
                arrowColorButton.setEnabled(false);
                arrowOpacitySlider.setEnabled(false);
                preview.setArrowColor(end, null);
            }
        }
    });
    arrowColorButton.setEnabled(arrowColorCheck.isSelected());
    arrowColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            preview.setArrowColor(end, mixColor((Color) evt.getNewValue(), arrowOpacitySlider.getValue()));
            previewPanel.repaint();
        }
    });
    arrowOpacitySlider.setMajorTickSpacing(100);
    arrowOpacitySlider.setMinorTickSpacing(25);
    arrowOpacitySlider.setPaintTicks(true);
    arrowOpacitySlider.setPaintLabels(true);
    arrowOpacitySlider.setValue(100);
    arrowOpacitySlider.setEnabled(arrowColorCheck.isSelected());
    arrowOpacitySlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            preview.setArrowColor(end, mixColor(preview.getArrowColor(end), arrowOpacitySlider.getValue()));
            previewPanel.repaint();
        }
    });
    final JComboBox<String> arrowSizeCombo = new JComboBox<>();
    arrowSizeCombo.setModel(new DefaultComboBoxModel<String>(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20" }));
    arrowSizeCombo.setSelectedIndex(1);
    for (int i = 0; i < arrowSizeCombo.getModel().getSize(); i++) {
        if (((int) annotation.getArrowSize(end)) == Integer.parseInt((String) arrowSizeCombo.getModel().getElementAt(i))) {
            arrowSizeCombo.setSelectedIndex(i);
            break;
        }
    }
    arrowSizeCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            preview.setArrowSize(end, Integer.parseInt(arrowSizeCombo.getModel().getSelectedItem().toString()));
            previewPanel.repaint();
        }
    });
    final JComboBox<String> anchorTypeCombo = new JComboBox<>();
    anchorTypeCombo.setModel(new DefaultComboBoxModel<String>(new String[] { "Edge", "Center" }));
    if (annotation.getAnchorType(end) == AnchorType.CENTER)
        anchorTypeCombo.setSelectedIndex(1);
    else
        anchorTypeCombo.setSelectedIndex(0);
    anchorTypeCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            if (anchorTypeCombo.getModel().getSelectedItem().equals("Center"))
                preview.setAnchorType(end, AnchorType.CENTER);
            else
                preview.setAnchorType(end, AnchorType.ANCHOR);
            previewPanel.repaint();
        }
    });
    final JPanel arrowPanel = new JPanel();
    arrowPanel.setBorder(LookAndFeelUtil.createTitledBorder(end == ArrowEnd.TARGET ? "Target Arrow" : "Source Arrow"));
    if (LookAndFeelUtil.isAquaLAF())
        arrowPanel.setOpaque(false);
    final GroupLayout layout = new GroupLayout(arrowPanel);
    arrowPanel.setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(TRAILING, true).addComponent(label1).addComponent(label2).addComponent(label3).addComponent(label4).addComponent(label5)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.LEADING, true).addComponent(arrowTypeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addGroup(layout.createSequentialGroup().addComponent(arrowColorCheck, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(arrowColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(arrowOpacitySlider, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(arrowSizeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(anchorTypeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(CENTER, false).addComponent(label1).addComponent(arrowTypeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label2).addComponent(arrowColorCheck, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(arrowColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label3).addComponent(arrowOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label4).addComponent(arrowSizeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label5).addComponent(anchorTypeCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)));
    return arrowPanel;
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) JComboBox(javax.swing.JComboBox) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) Paint(java.awt.Paint) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ColorButton(org.cytoscape.util.swing.ColorButton) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) GroupLayout(javax.swing.GroupLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 2 with ColorButton

use of org.cytoscape.util.swing.ColorButton in project cytoscape-impl by cytoscape.

the class ImageAnnotationPanel method initComponents.

private void initComponents() {
    setBorder(LookAndFeelUtil.createPanelBorder());
    final JLabel nameLabel = new JLabel("Annotation Name:");
    final JLabel label1 = new JLabel("Border Color:");
    final JLabel label2 = new JLabel("Border Opacity:");
    final JLabel label3 = new JLabel("Border Width:");
    final JLabel label4 = new JLabel("Opacity:");
    final JLabel label5 = new JLabel("Brightness:");
    final JLabel label6 = new JLabel("Contrast:");
    nameField = new JTextField(32);
    if (annotation.getName() != null) {
        nameField.setText(annotation.getName());
    }
    nameField.addMouseListener(new TextFieldMouseListener(nameField, preview));
    borderColorCheck = new JCheckBox();
    borderColorCheck.setSelected(annotation.getBorderColor() != null);
    borderColorCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            borderColorCheckActionPerformed(evt);
        }
    });
    borderColorButton = new ColorButton((Color) preview.getBorderColor());
    borderColorButton.setToolTipText("Select border color...");
    borderColorButton.setEnabled(borderColorCheck.isSelected());
    borderColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            preview.setBorderColor((Color) evt.getNewValue());
            previewPanel.repaint();
        }
    });
    borderOpacitySlider = new JSlider(0, 100);
    borderOpacitySlider.setMajorTickSpacing(100);
    borderOpacitySlider.setMinorTickSpacing(25);
    borderOpacitySlider.setPaintTicks(true);
    borderOpacitySlider.setPaintLabels(true);
    if (annotation.getBorderOpacity() != 100.0 || borderColorCheck.isSelected()) {
        borderOpacitySlider.setEnabled(true);
        borderOpacitySlider.setValue((int) annotation.getBorderOpacity());
    } else {
        borderOpacitySlider.setValue(100);
        borderOpacitySlider.setEnabled(false);
    }
    borderOpacitySlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateBorderOpacity(borderOpacitySlider.getValue());
        }
    });
    borderWidthCombo = new JComboBox<>();
    borderWidthCombo.setModel(new DefaultComboBoxModel<String>(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" }));
    borderWidthCombo.setSelectedIndex(1);
    for (int i = 0; i < borderWidthCombo.getModel().getSize(); i++) {
        if (((int) annotation.getBorderWidth()) == Integer.parseInt((String) borderWidthCombo.getModel().getElementAt(i))) {
            borderWidthCombo.setSelectedIndex(i);
            break;
        }
    }
    borderWidthCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            modifySAPreview();
        }
    });
    opacitySlider = new JSlider(0, 100);
    opacitySlider.setMajorTickSpacing(100);
    opacitySlider.setMinorTickSpacing(25);
    opacitySlider.setPaintTicks(true);
    opacitySlider.setPaintLabels(true);
    opacitySlider.setEnabled(true);
    if (annotation.getImageOpacity() != 100.0 || borderColorCheck.isSelected())
        opacitySlider.setValue((int) (annotation.getImageOpacity() * 100));
    else
        opacitySlider.setValue(100);
    opacitySlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateOpacity(opacitySlider.getValue());
        }
    });
    brightnessSlider = new JSlider(-100, 100);
    brightnessSlider.setMajorTickSpacing(100);
    brightnessSlider.setMinorTickSpacing(25);
    brightnessSlider.setPaintTicks(true);
    brightnessSlider.setPaintLabels(true);
    brightnessSlider.setValue(0);
    brightnessSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateBrightness(brightnessSlider.getValue());
        }
    });
    contrastSlider = new JSlider(-100, 100);
    contrastSlider.setMajorTickSpacing(100);
    contrastSlider.setMinorTickSpacing(25);
    contrastSlider.setPaintTicks(true);
    contrastSlider.setPaintLabels(true);
    contrastSlider.setValue(0);
    contrastSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateContrast(contrastSlider.getValue());
        }
    });
    final GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createSequentialGroup().addGap(0, 20, Short.MAX_VALUE).addGroup(layout.createParallelGroup(TRAILING, true).addComponent(label1).addComponent(label2).addComponent(label3).addComponent(label4).addComponent(label5).addComponent(label6)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.LEADING, true).addGroup(layout.createSequentialGroup().addComponent(borderColorCheck).addComponent(borderColorButton)).addComponent(borderOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(borderWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(opacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(brightnessSlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(contrastSlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGap(0, 20, Short.MAX_VALUE));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(CENTER, false).addComponent(label1).addComponent(borderColorCheck).addComponent(borderColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label2).addComponent(borderOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label3).addComponent(borderWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGap(20).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label4).addComponent(opacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label5).addComponent(brightnessSlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label6).addComponent(contrastSlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)));
    iModifySAPreview();
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) ColorButton(org.cytoscape.util.swing.ColorButton) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) GroupLayout(javax.swing.GroupLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 3 with ColorButton

use of org.cytoscape.util.swing.ColorButton in project cytoscape-impl by cytoscape.

the class ShapeAnnotationPanel method initComponents.

private void initComponents() {
    setBorder(LookAndFeelUtil.createPanelBorder());
    final JLabel nameLabel = new JLabel("Annotation Name:");
    final JLabel label1 = new JLabel("Shape:");
    final JLabel label2 = new JLabel("Fill Color:");
    final JLabel label3 = new JLabel("Fill Opacity:");
    final JLabel label4 = new JLabel("Border Color:");
    final JLabel label5 = new JLabel("Border Opacity:");
    final JLabel label6 = new JLabel("Border Width:");
    nameField = new JTextField(32);
    if (annotation.getName() != null) {
        nameField.setText(annotation.getName());
    }
    nameField.addMouseListener(new TextFieldMouseListener(nameField, preview));
    shapeList = new JList<>();
    shapeList.setModel(new AbstractListModel<String>() {

        List<String> typeList = annotation.getSupportedShapes();

        @Override
        public int getSize() {
            return typeList.size();
        }

        @Override
        public String getElementAt(int i) {
            return typeList.get(i);
        }
    });
    shapeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    shapeList.setSelectedValue(annotation.getShapeType(), true);
    shapeList.addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent evt) {
            shapeListValueChanged(evt);
        }
    });
    final JScrollPane scrollPane = new JScrollPane(shapeList);
    fillColorCheck = new JCheckBox();
    fillColorCheck.setSelected(annotation.getFillColor() != null);
    fillColorCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            fillColorCheckActionPerformed(evt);
        }
    });
    fillColorButton = new ColorButton((Color) preview.getFillColor());
    fillColorButton.setToolTipText("Select fill color...");
    fillColorButton.setEnabled(fillColorCheck.isSelected());
    fillColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            preview.setFillColor((Color) evt.getNewValue());
            previewPanel.repaint();
        }
    });
    fillOpacitySlider = new JSlider(0, 100);
    fillOpacitySlider.setMajorTickSpacing(100);
    fillOpacitySlider.setMinorTickSpacing(25);
    fillOpacitySlider.setPaintTicks(true);
    fillOpacitySlider.setPaintLabels(true);
    if (annotation.getFillOpacity() != 100.0) {
        fillOpacitySlider.setEnabled(true);
        fillOpacitySlider.setValue((int) annotation.getFillOpacity());
    } else {
        fillOpacitySlider.setValue(100);
        fillOpacitySlider.setEnabled(false);
    }
    fillOpacitySlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateFillOpacity(fillOpacitySlider.getValue());
        }
    });
    borderColorCheck = new JCheckBox();
    borderColorCheck.setSelected(annotation.getBorderColor() != null);
    borderColorCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            borderColorCheckActionPerformed(evt);
        }
    });
    borderColorButton = new ColorButton((Color) preview.getBorderColor());
    borderColorButton.setToolTipText("Select border color...");
    borderColorButton.setEnabled(borderColorCheck.isSelected());
    borderColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            preview.setBorderColor((Color) evt.getNewValue());
            previewPanel.repaint();
        }
    });
    borderOpacitySlider = new JSlider(0, 100);
    borderOpacitySlider.setMajorTickSpacing(100);
    borderOpacitySlider.setMinorTickSpacing(25);
    borderOpacitySlider.setPaintTicks(true);
    borderOpacitySlider.setPaintLabels(true);
    if (annotation.getBorderOpacity() != 100.0 || borderColorCheck.isSelected()) {
        borderOpacitySlider.setEnabled(true);
        borderOpacitySlider.setValue((int) annotation.getBorderOpacity());
    } else {
        borderOpacitySlider.setValue(100);
        borderOpacitySlider.setEnabled(false);
    }
    borderOpacitySlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent evt) {
            updateBorderOpacity(borderOpacitySlider.getValue());
        }
    });
    borderWidthCombo = new JComboBox<>();
    borderWidthCombo.setModel(new DefaultComboBoxModel<String>(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13" }));
    borderWidthCombo.setSelectedIndex(1);
    for (int i = 0; i < borderWidthCombo.getModel().getSize(); i++) {
        if (((int) annotation.getBorderWidth()) == Integer.parseInt(borderWidthCombo.getModel().getElementAt(i))) {
            borderWidthCombo.setSelectedIndex(i);
            break;
        }
    }
    borderWidthCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            borderWidthActionPerformed(evt);
        }
    });
    final GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createParallelGroup(LEADING, true).addGroup(layout.createSequentialGroup().addComponent(nameLabel).addComponent(nameField)).addComponent(label1).addGroup(layout.createSequentialGroup().addComponent(scrollPane, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(TRAILING, true).addComponent(label2).addComponent(label3).addComponent(label4).addComponent(label5).addComponent(label6)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.LEADING, true).addGroup(layout.createSequentialGroup().addComponent(fillColorCheck).addComponent(fillColorButton)).addComponent(fillOpacitySlider, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addGroup(layout.createSequentialGroup().addComponent(borderColorCheck).addComponent(borderColorButton)).addComponent(borderOpacitySlider, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addComponent(borderWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE))));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(Alignment.BASELINE).addComponent(nameLabel).addComponent(nameField)).addComponent(label1).addGroup(layout.createParallelGroup(LEADING, true).addComponent(scrollPane).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(CENTER, false).addComponent(label2).addComponent(fillColorCheck).addComponent(fillColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label3).addComponent(fillOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGap(20).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label4).addComponent(borderColorCheck).addComponent(borderColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label5).addComponent(borderOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label6).addComponent(borderWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)))));
    iModifySAPreview();
}
Also used : PropertyChangeListener(java.beans.PropertyChangeListener) ActionEvent(java.awt.event.ActionEvent) ListSelectionEvent(javax.swing.event.ListSelectionEvent) JTextField(javax.swing.JTextField) ColorButton(org.cytoscape.util.swing.ColorButton) GroupLayout(javax.swing.GroupLayout) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener) JScrollPane(javax.swing.JScrollPane) PropertyChangeEvent(java.beans.PropertyChangeEvent) Color(java.awt.Color) JLabel(javax.swing.JLabel) ListSelectionListener(javax.swing.event.ListSelectionListener) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent)

Example 4 with ColorButton

use of org.cytoscape.util.swing.ColorButton in project cytoscape-impl by cytoscape.

the class AbstractChartEditor method getBorderColorBtn.

protected ColorButton getBorderColorBtn() {
    if (borderColorBtn == null) {
        final Color color = chart.get(BORDER_COLOR, Color.class, Color.DARK_GRAY);
        borderColorBtn = new ColorButton(color);
        borderColorBtn.addPropertyChangeListener("color", new PropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent e) {
                final Color newColor = (Color) e.getNewValue();
                chart.set(BORDER_COLOR, newColor);
            }
        });
    }
    return borderColorBtn;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) ColorButton(org.cytoscape.util.swing.ColorButton) PropertyChangeListener(java.beans.PropertyChangeListener) Color(java.awt.Color)

Example 5 with ColorButton

use of org.cytoscape.util.swing.ColorButton 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

PropertyChangeEvent (java.beans.PropertyChangeEvent)7 PropertyChangeListener (java.beans.PropertyChangeListener)7 ColorButton (org.cytoscape.util.swing.ColorButton)7 Color (java.awt.Color)5 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 GroupLayout (javax.swing.GroupLayout)5 JLabel (javax.swing.JLabel)5 JCheckBox (javax.swing.JCheckBox)4 JSlider (javax.swing.JSlider)4 JTextField (javax.swing.JTextField)4 ChangeEvent (javax.swing.event.ChangeEvent)4 ChangeListener (javax.swing.event.ChangeListener)4 Paint (java.awt.Paint)2 JComboBox (javax.swing.JComboBox)2 JPanel (javax.swing.JPanel)2 JScrollPane (javax.swing.JScrollPane)2 ListSelectionEvent (javax.swing.event.ListSelectionEvent)2 ListSelectionListener (javax.swing.event.ListSelectionListener)2 BoundedTextAnnotationImpl (org.cytoscape.ding.impl.cyannotator.annotations.BoundedTextAnnotationImpl)1