List of usage examples for javax.swing JColorChooser showDialog
public static Color showDialog(Component component, String title, Color initialColor) throws HeadlessException
From source file:com.midas.classify.gui.DecisionTreeViewer.java
public DecisionTreeViewer(DelegateTree<TreeNode, TreeEdge> tr, String[] cls) { setLayout(new BorderLayout()); // ---------------------------------------------- // // INICIALIZACION DE COMPONENTES DE VISUALIZACION // // ---------------------------------------------- // tree = tr;/*w ww . ja v a 2s .c o m*/ classNames = cls; classColors = new TreeMap(); nodeColor = Color.BLUE; for (int i = 0; i < cls.length; ++i) { classColors.put(cls[i], Color.RED); } leafNodes = new TreeSet(); for (TreeNode n : tr.getVertices()) { if (tr.isLeaf(n)) { for (String s : cls) { if (n.toString().startsWith(s)) { leafNodes.add(s); break; } } } } TreeLayout<TreeNode, TreeEdge> layout = new TreeLayout(tr); vv = new VisualizationViewer(layout); vv.setBackground(Color.white); vv.getRenderContext().setEdgeFontTransformer(new EdgeFontTransformer()); vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line<TreeNode, TreeEdge>()); PickedState<TreeNode> picked_state = vv.getPickedVertexState(); vv.getRenderContext().setVertexFillPaintTransformer(new VertexFillColorTransformer<TreeNode>(picked_state)); vv.getRenderContext().setVertexDrawPaintTransformer(new VertexDrawColorTransformer<TreeNode>(picked_state)); vv.getRenderContext().setVertexFontTransformer(new VertexFontTransformer()); vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller()); vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller()); GraphZoomScrollPane scrollPane = new GraphZoomScrollPane(vv); gm = new DefaultModalGraphMouse(); vv.setGraphMouse(gm); final ScalingControl scaler = new CrossoverScalingControl(); // ---------------------------------------- // // INICIALIZACION DE COMPONENTES DE CONTROL // // ---------------------------------------- // fontChooser = new JFontChooser(); JPanel pControl = new JPanel(new GridLayout(7, 1, 4, 2)); JPanel pZoom = new JPanel(new GridLayout(1, 2, 2, 2)); pZoom.setBorder(new TitledBorder("Zoom")); bZoomIn = new JButton("+"); bZoomIn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1.1f, vv.getCenter()); } }); bZoomOut = new JButton("-"); bZoomOut.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { scaler.scale(vv, 1 / 1.1f, vv.getCenter()); } }); pZoom.add(bZoomIn); pZoom.add(bZoomOut); JPanel pFont = new JPanel(new GridLayout(1, 2, 2, 2)); pFont.setBorder(new TitledBorder("Fonts")); bNodeFont = new JButton("Node Font"); bNodeFont.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fontChooser.showDialog(null); if (r == JFontChooser.OK_OPTION) { nodeFont = fontChooser.getSelectedFont(); vv.repaint(); } } }); bEdgeFont = new JButton("Edge Font"); bEdgeFont.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int r = fontChooser.showDialog(null); if (r == JFontChooser.OK_OPTION) { edgeFont = fontChooser.getSelectedFont(); vv.repaint(); } } }); pFont.add(bNodeFont); pFont.add(bEdgeFont); bNodeColor = new JButton("Node Color"); bNodeColor.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { nodeColor = JColorChooser.showDialog(null, "Select color for intern nodes", Color.RED); vv.repaint(); } }); JPanel pMode = new JPanel(); pMode.setBorder(new TitledBorder("Mode")); cbMode = new JComboBox(); cbMode.addItem(ModalGraphMouse.Mode.TRANSFORMING); cbMode.addItem(ModalGraphMouse.Mode.PICKING); cbMode.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { gm.setMode((ModalGraphMouse.Mode) e.getItem()); } }); pMode.add(cbMode); JPanel pColors = new JPanel(new GridLayout(1, 2, 2, 2)); pColors.setBorder(new TitledBorder("Node Colors")); cbClasses = new JComboBox(classNames); cbClasses.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(null, "Select class color for " + cbClasses.getSelectedItem(), Color.RED); classColors.put(cbClasses.getSelectedItem().toString(), c); vv.repaint(); } }); pColors.add(cbClasses); pColors.add(bNodeColor); JPanel pLabelPosition = new JPanel(); pLabelPosition.setBorder(new TitledBorder("Label Position")); cbLabelPosition = new JComboBox(); cbLabelPosition.addItem(Renderer.VertexLabel.Position.N); cbLabelPosition.addItem(Renderer.VertexLabel.Position.NE); cbLabelPosition.addItem(Renderer.VertexLabel.Position.E); cbLabelPosition.addItem(Renderer.VertexLabel.Position.SE); cbLabelPosition.addItem(Renderer.VertexLabel.Position.S); cbLabelPosition.addItem(Renderer.VertexLabel.Position.SW); cbLabelPosition.addItem(Renderer.VertexLabel.Position.W); cbLabelPosition.addItem(Renderer.VertexLabel.Position.NW); cbLabelPosition.addItem(Renderer.VertexLabel.Position.N); cbLabelPosition.addItem(Renderer.VertexLabel.Position.CNTR); cbLabelPosition.addItem(Renderer.VertexLabel.Position.AUTO); cbLabelPosition.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { Renderer.VertexLabel.Position position = (Renderer.VertexLabel.Position) e.getItem(); vv.getRenderer().getVertexLabelRenderer().setPosition(position); vv.repaint(); } }); cbLabelPosition.setSelectedItem(Renderer.VertexLabel.Position.SE); pLabelPosition.add(cbLabelPosition); chkShowEdgeNames = new JCheckBox("Show Edge Name"); chkShowEdgeNames.addActionListener(new ActionListener() { ToStringLabeller strLabeller = new ToStringLabeller(); ConstantTransformer none = new ConstantTransformer(null); @Override public void actionPerformed(ActionEvent e) { AbstractButton src = (AbstractButton) e.getSource(); if (src.isSelected()) { vv.getRenderContext().setEdgeLabelTransformer(strLabeller); } else { vv.getRenderContext().setEdgeLabelTransformer(none); } vv.repaint(); } }); chkShowEdgeNames.setSelected(true); chkShowNodeNames = new JCheckBox("Show Node Name"); chkShowNodeNames.addActionListener(new ActionListener() { ToStringLabeller strLabeller = new ToStringLabeller(); ConstantTransformer none = new ConstantTransformer(null); @Override public void actionPerformed(ActionEvent e) { AbstractButton src = (AbstractButton) e.getSource(); if (src.isSelected()) { vv.getRenderContext().setVertexLabelTransformer(strLabeller); } else { vv.getRenderContext().setVertexLabelTransformer(none); } vv.repaint(); } }); chkShowNodeNames.setSelected(true); pControl.add(pZoom); pControl.add(pFont); pControl.add(pMode); pControl.add(pLabelPosition); pControl.add(pColors); pControl.add(chkShowNodeNames); pControl.add(chkShowEdgeNames); // Agregar componentes al panel add(scrollPane); JPanel p = new JPanel(new FlowLayout()); p.add(pControl); add(p, BorderLayout.EAST); }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultTitleEditor.java
/** * Allow the user the opportunity to select a Paint object. For now, we just * use the standard color chooser - all colors are Paint objects, but not * all Paint objects are colors (later we can implement a more general Paint * chooser)./*w ww . j a v a2s . c om*/ */ public void attemptPaintSelection() { Paint p = this.titlePaint.getPaint(); Color defaultColor = (p instanceof Color ? (Color) p : Color.blue); Color c = JColorChooser.showDialog(this, localizationResources.getString("Title_Color"), defaultColor); if (c != null) { this.titlePaint.setPaint(c); } }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultNumberAxisEditor.java
/** * Handle a grid paint selection./*from ww w. ja va 2 s. c om*/ */ private void attemptGridPaintSelection() { Color c; c = JColorChooser.showDialog(this, localizationResources.getString("Grid_Color"), Color.blue); if (c != null) { this.gridPaintSample.setPaint(c); } }
From source file:org.cds06.speleograph.graph.SeriesMenu.java
private JPopupMenu createPopupMenuForSeries(final Series series) { if (series == null) return new JPopupMenu(); final JPopupMenu menu = new JPopupMenu(series.getName()); menu.removeAll();/* www .ja v a2s. c om*/ menu.add(new AbstractAction() { { putValue(NAME, "Renommer la srie"); } @Override public void actionPerformed(ActionEvent e) { menu.setVisible(false); String newName = ""; while (newName == null || newName.equals("")) { newName = (String) JOptionPane.showInputDialog(application, "Entrez un nouveau nom pour la srie", null, JOptionPane.QUESTION_MESSAGE, null, null, series.getName()); } series.setName(newName); } }); if (series.hasOwnAxis()) { menu.add(new AbstractAction() { { putValue(NAME, "Supprimer l'axe spcifique"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes vous sr de vouloir supprimer cet axe ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION) { series.setAxis(null); } } }); } else { menu.add(new JMenuItem(new AbstractAction() { { putValue(NAME, "Crer un axe spcifique pour la srie"); } @Override public void actionPerformed(ActionEvent e) { String name = JOptionPane.showInputDialog(application, "Quel titre pour cet axe ?", series.getAxis().getLabel()); if (name == null || "".equals(name)) return; // User has canceled series.setAxis(new NumberAxis(name)); } })); } menu.add(new SetTypeMenu(series)); if (series.isWater()) { menu.addSeparator(); menu.add(new SumOnPeriodAction(series)); menu.add(new CreateCumulAction(series)); } if (series.isWaterCumul()) { menu.addSeparator(); menu.add(new SamplingAction(series)); } if (series.isPressure()) { menu.addSeparator(); menu.add(new CorrelateAction(series)); menu.add(new WaterHeightAction(series)); } menu.addSeparator(); menu.add(new AbstractAction() { { String name; if (series.canUndo()) name = "Annuler " + series.getItemsName(); else name = series.getLastUndoName(); putValue(NAME, name); if (series.canUndo()) setEnabled(true); else { setEnabled(false); } } @Override public void actionPerformed(ActionEvent e) { series.undo(); } }); menu.add(new AbstractAction() { { String name; if (series.canRedo()) { name = "Refaire " + series.getNextRedoName(); setEnabled(true); } else { name = series.getNextRedoName(); setEnabled(false); } putValue(NAME, name); } @Override public void actionPerformed(ActionEvent e) { series.redo(); } }); menu.add(new AbstractAction() { { putValue(NAME, I18nSupport.translate("menus.serie.resetSerie")); if (series.canUndo()) setEnabled(true); else setEnabled(false); } @Override public void actionPerformed(ActionEvent e) { series.reset(); } }); menu.add(new LimitDateRangeAction(series)); menu.add(new HourSettingAction(series)); menu.addSeparator(); { JMenuItem deleteItem = new JMenuItem("Supprimer la srie"); deleteItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir supprimer cette srie ?\n" + "Cette action est dfinitive.", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { series.delete(); } } }); menu.add(deleteItem); } menu.addSeparator(); { final JMenuItem up = new JMenuItem("Remonter dans la liste"), down = new JMenuItem("Descendre dans la liste"); ActionListener listener = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (e.getSource().equals(up)) { series.upSeriesInList(); } else { series.downSeriesInList(); } } }; up.addActionListener(listener); down.addActionListener(listener); if (series.isFirst()) { menu.add(down); } else if (series.isLast()) { menu.add(up); } else { menu.add(up); menu.add(down); } } menu.addSeparator(); { menu.add(new SeriesInfoAction(series)); } { JMenuItem colorItem = new JMenuItem("Couleur de la srie"); colorItem.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { series.setColor(JColorChooser.showDialog(application, I18nSupport.translate("actions.selectColorForSeries"), series.getColor())); } }); menu.add(colorItem); } { JMenu plotRenderer = new JMenu("Affichage de la srie"); final ButtonGroup modes = new ButtonGroup(); java.util.List<DrawStyle> availableStyles; if (series.isMinMax()) { availableStyles = DrawStyles.getDrawableStylesForHighLow(); } else { availableStyles = DrawStyles.getDrawableStyles(); } for (final DrawStyle s : availableStyles) { final JRadioButtonMenuItem item = new JRadioButtonMenuItem(DrawStyles.getHumanCheckboxText(s)); item.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (item.isSelected()) series.setStyle(s); } }); modes.add(item); if (s.equals(series.getStyle())) { modes.setSelected(item.getModel(), true); } plotRenderer.add(item); } menu.add(plotRenderer); } menu.addSeparator(); menu.add(new AbstractAction() { { putValue(Action.NAME, "Fermer le fichier"); } @Override public void actionPerformed(ActionEvent e) { if (JOptionPane.showConfirmDialog(application, "tes-vous sur de vouloir fermer toutes les sries du fichier ?", "Confirmation", JOptionPane.OK_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.OK_OPTION) { final File f = series.getOrigin(); for (final Series s : Series.getInstances().toArray(new Series[Series.getInstances().size()])) { if (s.getOrigin().equals(f)) s.delete(); } } } }); return menu; }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultAxisEditor.java
/** * Allows the user the opportunity to change the outline paint. *//*from w w w.ja va2 s . co m*/ private void attemptModifyLabelPaint() { Color c; c = JColorChooser.showDialog(this, localizationResources.getString("Label_Color"), Color.blue); if (c != null) { this.labelPaintSample.setPaint(c); } }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultPlotEditor.java
/** * Allow the user to change the background paint. *//*from ww w . ja va 2 s . com*/ private void attemptBackgroundPaintSelection() { Color c; c = JColorChooser.showDialog(this, localizationResources.getString("Background_Color"), Color.blue); if (c != null) { this.backgroundPaintSample.setPaint(c); } }
From source file:ch.zhaw.simulation.diagram.charteditor.DefaultPlotEditor.java
/** * Allow the user to change the outline paint. We use JColorChooser, so the * user can only choose colors (a subset of all possible paints). *///from w w w.j a va 2s.c om private void attemptOutlinePaintSelection() { Color c; c = JColorChooser.showDialog(this, localizationResources.getString("Outline_Color"), Color.blue); if (c != null) { this.outlinePaintSample.setPaint(c); } }
From source file:com.alvermont.terraj.planet.ui.MainFrame.java
/** * Bring up a colour selector for the specified colour and set the * corresponding colour parameter if the user picks a new one * * @param source The button that was pressed to produce this action * @param label The string to be displayed by the colour dialog * @param index The index of the colour parameter to be set * @return The new colour that was chosen or <code>null</code> if the * user cancelled.//from w ww . j a va 2 s.co m */ protected Color pickColour(JButton source, String label, int index) { final Color newColour = JColorChooser.showDialog(this, label, source.getBackground()); if (newColour != null) { /// then a new colour was chosen source.setBackground(newColour); final int[][] colours = params.getProjectionParameters().getColors(); colours[index][0] = newColour.getRed(); colours[index][1] = newColour.getGreen(); colours[index][2] = newColour.getBlue(); } return newColour; }
From source file:com.sciaps.view.PlotConfigPanel.java
private void btnSetBgColor_ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSetBgColor_ActionPerformed Color backgroundColor = JColorChooser.showDialog(Constants.MAIN_FRAME, "Choose chart background color", Color.white);/*from w w w . jav a 2 s .co m*/ plot_.setBackgroundPaint(backgroundColor); }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
protected void displayColorPicker(JFreeChart chart, String label, int series, ColorButton button) { Color color = (Color) chart.getPlot().getLegendItems().get(series).getLinePaint(); Color newColor = JColorChooser.showDialog(this, "Pick a color for " + label, color); if (newColor != null) { palette.release(color);/*from ww w . j a v a2s . co m*/ setColor(enabled.get(series), newColor); gp.saveLayout(); } }