Search in sources :

Example 6 with ColorButton

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

the class AbstractChartEditor method getAxisColorBtn.

protected ColorButton getAxisColorBtn() {
    if (axisColorBtn == null) {
        final Color color = chart.get(AXIS_COLOR, Color.class, Color.DARK_GRAY);
        axisColorBtn = new ColorButton(color);
        axisColorBtn.setVisible(hasAxes);
        axisColorBtn.addPropertyChangeListener("color", new PropertyChangeListener() {

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

Example 7 with ColorButton

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

the class ArrowAnnotationPanel method initComponents.

private void initComponents() {
    setBorder(LookAndFeelUtil.createPanelBorder());
    final JLabel nameLabel = new JLabel("Annotation Name:");
    final JLabel label1 = new JLabel("Line Color:");
    final JLabel label2 = new JLabel("Line Opacity:");
    final JLabel label3 = new JLabel("Line Width:");
    nameField = new JTextField(32);
    if (annotation.getName() != null) {
        nameField.setText(annotation.getName());
    }
    nameField.addMouseListener(new TextFieldMouseListener(nameField, preview));
    final ColorButton lineColorButton = new ColorButton((Color) preview.getLineColor());
    lineColorButton.setToolTipText("Select line color...");
    final JSlider lineOpacitySlider = new JSlider(0, 100);
    final JCheckBox lineColorCheck = new JCheckBox();
    lineColorCheck.setSelected(annotation.getLineColor() != null);
    lineColorCheck.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            if (lineColorCheck.isSelected()) {
                lineColorButton.setEnabled(true);
                lineOpacitySlider.setEnabled(true);
                preview.setLineColor(mixColor(lineColorButton.getColor(), lineOpacitySlider.getValue()));
            } else {
                lineColorButton.setEnabled(false);
                lineOpacitySlider.setEnabled(false);
                preview.setLineColor(null);
            }
            previewPanel.repaint();
        }
    });
    lineColorButton.setEnabled(lineColorCheck.isSelected());
    lineColorButton.addPropertyChangeListener("color", new PropertyChangeListener() {

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

        @Override
        public void stateChanged(ChangeEvent evt) {
            preview.setLineColor(mixColor(preview.getLineColor(), lineOpacitySlider.getValue()));
            previewPanel.repaint();
        }
    });
    final JComboBox<String> lineWidthCombo = new JComboBox<>();
    lineWidthCombo.setModel(new DefaultComboBoxModel<String>(new String[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15" }));
    lineWidthCombo.setSelectedIndex(1);
    for (int i = 0; i < lineWidthCombo.getModel().getSize(); i++) {
        if (((int) annotation.getLineWidth()) == Integer.parseInt((String) lineWidthCombo.getModel().getElementAt(i))) {
            lineWidthCombo.setSelectedIndex(i);
            break;
        }
    }
    lineWidthCombo.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            preview.setLineWidth(Integer.parseInt((String) (lineWidthCombo.getModel().getSelectedItem())));
            previewPanel.repaint();
        }
    });
    final JPanel sourcePanel = getArrowPanel(ArrowEnd.SOURCE);
    final JPanel targetPanel = getArrowPanel(ArrowEnd.TARGET);
    final GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setAutoCreateContainerGaps(true);
    layout.setAutoCreateGaps(!LookAndFeelUtil.isAquaLAF());
    layout.setHorizontalGroup(layout.createParallelGroup(CENTER, true).addGroup(layout.createSequentialGroup().addGap(10, 20, Short.MAX_VALUE).addGroup(layout.createParallelGroup(TRAILING, true).addComponent(label1).addComponent(label2).addComponent(label3)).addPreferredGap(ComponentPlacement.RELATED).addGroup(layout.createParallelGroup(Alignment.LEADING, true).addGroup(layout.createSequentialGroup().addComponent(lineColorCheck, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(lineColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addComponent(lineOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(lineWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGap(10, 20, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addComponent(sourcePanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE).addPreferredGap(ComponentPlacement.RELATED).addComponent(targetPanel, DEFAULT_SIZE, DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(CENTER, false).addComponent(label1).addComponent(lineColorCheck).addComponent(lineColorButton, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(LEADING, false).addComponent(label2).addComponent(lineOpacitySlider, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addGroup(layout.createParallelGroup(CENTER, false).addComponent(label3).addComponent(lineWidthCombo, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)).addPreferredGap(ComponentPlacement.UNRELATED).addGroup(layout.createParallelGroup(LEADING, true).addComponent(sourcePanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE).addComponent(targetPanel, PREFERRED_SIZE, DEFAULT_SIZE, PREFERRED_SIZE)));
    iModifySAPreview();
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) JComboBox(javax.swing.JComboBox) ActionEvent(java.awt.event.ActionEvent) JLabel(javax.swing.JLabel) JTextField(javax.swing.JTextField) Paint(java.awt.Paint) JCheckBox(javax.swing.JCheckBox) ColorButton(org.cytoscape.util.swing.ColorButton) ActionListener(java.awt.event.ActionListener) 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)

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