Example usage for javax.swing JColorChooser showDialog

List of usage examples for javax.swing JColorChooser showDialog

Introduction

In this page you can find the example usage for javax.swing JColorChooser showDialog.

Prototype

public static Color showDialog(Component component, String title, Color initialColor) throws HeadlessException 

Source Link

Document

Shows a modal color-chooser dialog and blocks until the dialog is hidden.

Usage

From source file:org.apache.jmeter.visualizers.StatGraphVisualizer.java

@Override
public void actionPerformed(ActionEvent event) {
    boolean forceReloadData = false;
    final Object eventSource = event.getSource();
    if (eventSource == displayButton) {
        actionMakeGraph();//from  w w w . ja  va2 s . c o m
    } else if (eventSource == saveGraph) {
        saveGraphToFile = true;
        try {
            ActionRouter.getInstance().getAction(ActionNames.SAVE_GRAPHICS, SaveGraphics.class.getName())
                    .doAction(new ActionEvent(this, event.getID(), ActionNames.SAVE_GRAPHICS));
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    } else if (eventSource == saveTable) {
        JFileChooser chooser = FileDialoger.promptToSaveFile("statistics.csv"); //$NON-NLS-1$
        if (chooser == null) {
            return;
        }
        FileWriter writer = null;
        try {
            writer = new FileWriter(chooser.getSelectedFile()); // TODO Charset ?
            CSVSaveService.saveCSVStats(getAllTableData(model, FORMATS), writer,
                    saveHeaders.isSelected() ? getLabels(COLUMNS) : null);
        } catch (IOException e) {
            JMeterUtils.reportErrorToUser(e.getMessage(), "Error saving data");
        } finally {
            JOrphanUtils.closeQuietly(writer);
        }
    } else if (eventSource == chooseForeColor) {
        Color color = JColorChooser.showDialog(null, JMeterUtils.getResString("aggregate_graph_choose_color"), //$NON-NLS-1$
                colorBarGraph);
        if (color != null) {
            colorForeGraph = color;
        }
    } else if (eventSource == syncWithName) {
        graphTitle.setText(namePanel.getName());
    } else if (eventSource == dynamicGraphSize) {
        // if use dynamic graph size is checked, we disable the dimension fields
        if (dynamicGraphSize.isSelected()) {
            graphWidth.setEnabled(false);
            graphHeight.setEnabled(false);
        } else {
            graphWidth.setEnabled(true);
            graphHeight.setEnabled(true);
        }
    } else if (eventSource == columnSelection) {
        if (columnSelection.isSelected()) {
            columnMatchLabel.setEnabled(true);
            applyFilterBtn.setEnabled(true);
            caseChkBox.setEnabled(true);
            regexpChkBox.setEnabled(true);
        } else {
            columnMatchLabel.setEnabled(false);
            applyFilterBtn.setEnabled(false);
            caseChkBox.setEnabled(false);
            regexpChkBox.setEnabled(false);
            // Force reload data
            forceReloadData = true;
        }
    }
    // Not 'else if' because forceReloadData 
    if (eventSource == applyFilterBtn || forceReloadData) {
        if (columnSelection.isSelected() && columnMatchLabel.getText() != null
                && columnMatchLabel.getText().length() > 0) {
            pattern = createPattern(columnMatchLabel.getText());
        } else if (forceReloadData) {
            pattern = null;
            matcher = null;
        }
        if (getFile() != null && getFile().length() > 0) {
            clearData();
            FilePanel filePanel = (FilePanel) getFilePanel();
            filePanel.actionPerformed(event);
        }
    } else if (eventSource instanceof JButton) {
        // Changing color for column
        JButton btn = ((JButton) eventSource);
        if (btn.getName() != null) {
            try {
                BarGraph bar = eltList.get(Integer.parseInt(btn.getName()));
                Color color = JColorChooser.showDialog(null, bar.getLabel(), bar.getBackColor());
                if (color != null) {
                    bar.setBackColor(color);
                    btn.setBackground(bar.getBackColor());
                }
            } catch (NumberFormatException nfe) {
            } // nothing to do
        }
    }
}

From source file:org.languagetool.gui.ConfigurationDialog.java

JPanel getUnderlineColorPanel(List<Rule> rules) {
    JPanel panel = new JPanel();

    panel.setLayout(new GridBagLayout());
    GridBagConstraints cons = new GridBagConstraints();
    cons.gridx = 0;//from w w w  .  j ava2  s.  c  o m
    cons.gridy = 0;
    cons.weightx = 0.0f;
    cons.fill = GridBagConstraints.NONE;
    cons.anchor = GridBagConstraints.NORTHWEST;

    List<String> categories = new ArrayList<String>();
    for (Rule rule : rules) {
        String category = rule.getCategory().getName();
        boolean contain = false;
        for (String c : categories) {
            if (c.equals(category)) {
                contain = true;
                break;
            }
        }
        if (!contain) {
            categories.add(category);
        }
    }
    List<JLabel> categorieLabel = new ArrayList<JLabel>();
    List<JLabel> underlineLabel = new ArrayList<JLabel>();
    List<JButton> changeButton = new ArrayList<JButton>();
    List<JButton> defaultButton = new ArrayList<JButton>();
    for (int nCat = 0; nCat < categories.size(); nCat++) {
        categorieLabel.add(new JLabel(categories.get(nCat) + " "));
        underlineLabel.add(new JLabel(" \u2588\u2588\u2588 ")); // \u2587 is smaller
        underlineLabel.get(nCat).setForeground(config.getUnderlineColor(categories.get(nCat)));
        underlineLabel.get(nCat).setBackground(config.getUnderlineColor(categories.get(nCat)));
        JLabel uLabel = underlineLabel.get(nCat);
        String cLabel = categories.get(nCat);
        panel.add(categorieLabel.get(nCat), cons);
        cons.gridx++;
        panel.add(underlineLabel.get(nCat), cons);

        changeButton.add(new JButton(messages.getString("guiUColorChange")));
        changeButton.get(nCat).addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Color oldColor = uLabel.getForeground();
                Color newColor = JColorChooser.showDialog(null, messages.getString("guiUColorDialogHeader"),
                        oldColor);
                if (newColor != null && newColor != oldColor) {
                    uLabel.setForeground(newColor);
                    config.setUnderlineColor(cLabel, newColor);
                }
            }
        });
        cons.gridx++;
        panel.add(changeButton.get(nCat), cons);

        defaultButton.add(new JButton(messages.getString("guiUColorDefault")));
        defaultButton.get(nCat).addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                config.setDefaultUnderlineColor(cLabel);
                uLabel.setForeground(config.getUnderlineColor(cLabel));
            }
        });
        cons.gridx++;
        panel.add(defaultButton.get(nCat), cons);
        cons.gridx = 0;
        cons.gridy++;
    }
    return panel;
}

From source file:org.tros.logo.swing.LogoMenuBar.java

/**
 * Set up the tools menu./*from  ww w . j  a va2 s  .c  o  m*/
 *
 * @return
 */
private JMenu setupToolsMenu() {
    JMenu toolsMenu = new JMenu(Localization.getLocalizedString("ToolsMenu"));

    toolsPenColorChooser = new JMenuItem(Localization.getLocalizedString("ToolsPenColorChooser"));
    toolsCanvasColorChooser = new JMenuItem(Localization.getLocalizedString("ToolsCanvasColorChooser"));

    toolsPenColorChooser.setMnemonic('P');
    toolsCanvasColorChooser.setMnemonic('C');

    toolsPenColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            Color selected = JColorChooser.showDialog(parent, Localization.getLocalizedString("ColorChooser"),
                    null);
            if (selected != null) {
                int red = selected.getRed();
                int green = selected.getGreen();
                int blue = selected.getBlue();
                String hex = String.format("#%02x%02x%02x", red, green, blue);
                controller.insertCommand("pencolor" + " " + hex);
            }
        }
    });
    toolsCanvasColorChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent ae) {
            Color selected = JColorChooser.showDialog(parent, Localization.getLocalizedString("ColorChooser"),
                    null);
            if (selected != null) {
                int red = selected.getRed();
                int green = selected.getGreen();
                int blue = selected.getBlue();
                String hex = String.format("#%02x%02x%02x", red, green, blue);
                controller.insertCommand("canvascolor" + " " + hex);
            }
        }
    });

    toolsMenu.add(toolsPenColorChooser);
    toolsMenu.add(toolsCanvasColorChooser);

    toolsMenu.setMnemonic('T');

    return (toolsMenu);
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButtonColorDiferenteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonColorDiferenteActionPerformed
    // TODO add your handling code here:
    Color c = JColorChooser.showDialog(this, "Elegir un color especfico para el Relleno", Color.BLACK);
    jButtonColorDiferente.setBackground(c);
    VentanaInterna vi;//from  w ww.  j  av a2  s . com
    UserShape shape;

    if (escritorio.getSelectedFrame() instanceof VentanaInterna) {
        vi = (VentanaInterna) escritorio.getSelectedFrame();
        vi.getLienzo().setColorTrazo(c);
    }

}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButtonDegradado1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDegradado1ActionPerformed
    // TODO add your handling code here:
    Color c = JColorChooser.showDialog(this, "Elegir un color especfico para el degradado 1", Color.BLACK);
    jButtonDegradado1.setBackground(c);//from w w  w  .  java2s.c  o  m
    //        VentanaInterna vi;
    //        UserShape shape;
    //        
    //        if(escritorio.getSelectedFrame()instanceof VentanaInterna){
    //            vi=(VentanaInterna)escritorio.getSelectedFrame();
    //            vi.getLienzo().setColorTrazo(c);
    //        }
}

From source file:paintbasico2d.VentanaPrincipal.java

private void jButtonDegradado2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDegradado2ActionPerformed
    // TODO add your handling code here:
    Color c = JColorChooser.showDialog(this, "Elegir un color especfico para el degradado 2", Color.BLACK);
    jButtonDegradado2.setBackground(c);/*from ww  w .j a  v a 2 s.co m*/
    //        VentanaInterna vi;
    //        UserShape shape;
    //        
    //        if(escritorio.getSelectedFrame()instanceof VentanaInterna){
    //            vi=(VentanaInterna)escritorio.getSelectedFrame();
    //            vi.getLienzo().setColorTrazo(c);
    //        }
}

From source file:plugin.notes.gui.NotesView.java

private void colorButtonActionPerformed() {
    //GEN-FIRST:event_colorButtonActionPerformed
    AttributeSet as = editor.getCharacterAttributes();
    SimpleAttributeSet sas = new SimpleAttributeSet(as);
    Color newColor = JColorChooser.showDialog(GMGenSystem.inst, "Choose Text Color",
            editor.getStyledDocument().getForeground(as));

    if (newColor != null) {
        StyleConstants.setForeground(sas, newColor);
        editor.setCharacterAttributes(sas, true);
    }//from   ww  w. j a  va2 s.co m

    editor.repaint();
}

From source file:repast.simphony.visualization.gui.styleBuilder.EditedStyleDialog.java

private void fontColorButtonActionPerformed(ActionEvent e) {
    float labelColor[] = userStyleData.getLabelColor();
    Color labelPaint = new Color(labelColor[0], labelColor[1], labelColor[2]);

    Color color = JColorChooser.showDialog(EditedStyleDialog.this, "Choose a Font Color", labelPaint);
    if (color != null) {
        userStyleData.setLabelColor(color.getRGBColorComponents(null));
        fontColorButton.setIcon(new SquareIcon(14, 14, color));
        preview.setEditorFontColor(color);
    }/*w ww.j  a  v  a  2s. c  o  m*/
}

From source file:repast.simphony.visualization.gui.styleBuilder.EditedStyleDialog.java

private void iconColorbuttonActionPerformed(ActionEvent e) {
    float iconColor[] = userStyleData.getColor();
    Color iconPaint = new Color(iconColor[0], iconColor[1], iconColor[2]);

    Color color = JColorChooser.showDialog(EditedStyleDialog.this, "Choose an Icon Color", iconPaint);
    if (color != null) {
        float col[] = color.getRGBColorComponents(null);
        userStyleData.setColor(col);/*from w w  w  . jav a2  s .  c  o m*/
        userStyleData.setRedMethod(null);
        userStyleData.setGreenMethod(null);
        userStyleData.setBlueMethod(null);
        variableIconRedColorValueModel.addElement(col[0]);
        variableIconGreenColorValueModel.addElement(col[1]);
        variableIconBlueColorValueModel.addElement(col[2]);
        variableIconRedColorValueModel.setSelectedItem(col[0]);
        variableIconGreenColorValueModel.setSelectedItem(col[1]);
        variableIconBlueColorValueModel.setSelectedItem(col[2]);

        iconColorbutton.setIcon(new SquareIcon(14, 14, color));
        preview.setFillColor(color);
    }
}