List of usage examples for org.jfree.chart.plot XYPlot getRangeGridlinePaint
public Paint getRangeGridlinePaint()
From source file:org.cds06.speleograph.graph.GraphEditor.java
/** * Creates a modal dialog by specifying the attached {@link GraphPanel}. * <p>Please look at {@link javax.swing.JDialog#JDialog()} to see defaults params applied to this Dialog.</p> *///from w w w .j a v a 2 s. co m public GraphEditor(GraphPanel panel) { super((Frame) SwingUtilities.windowForComponent(panel), true); Validate.notNull(panel); this.graphPanel = panel; KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); mainPanel.registerKeyboardAction(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setVisible(false); } }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW); setContentPane(mainPanel); mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); this.setTitle(I18nSupport.translate("menus.graph.graphEditor")); { // This section use FormLayout which is an external layout for Java, consult the doc before edit the // following lines ! final FormLayout layout = new FormLayout( "right:max(40dlu;p), 4dlu, p:grow, 4dlu, p, 4dlu, p:grow, 4dlu, p", //NON-NLS "p,4dlu,p,4dlu,p,4dlu,p,4dlu,p" //NON-NLS ); PanelBuilder builder = new PanelBuilder(layout); final JLabel colorLabel = new JLabel(); final JTextField titleForGraph = new JTextField( graphPanel.getChart().getTitle() != null ? graphPanel.getChart().getTitle().getText() : ""); final JLabel colorXYPlotLabel = new JLabel(); final JLabel colorGridLabel = new JLabel(); final JCheckBox showLegendCheckBox = new JCheckBox("Afficher la lgende", graphPanel.getChart().getLegend().isVisible()); { builder.addLabel("Titre :", "1,1"); builder.add(titleForGraph, "3,1,7,1"); } { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.backgroundColor"), "1,3"); colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorLabel.setText(" "); colorLabel.setBackground((Color) graphPanel.getChart().getBackgroundPaint()); colorLabel.setOpaque(true); colorLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorLabel.getBackground()); if (c != null) { colorLabel.setBackground(c); } } }); builder.add(colorLabel, "3,3,5,1"); builder.add(edit, "9,3"); } final XYPlot xyPlot = graphPanel.getChart().getXYPlot(); { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.graphColor"), "1,5"); colorXYPlotLabel.setText(" "); colorXYPlotLabel.setOpaque(true); colorXYPlotLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorXYPlotLabel.setBackground((Color) xyPlot.getBackgroundPaint()); colorXYPlotLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorXYPlotLabel.getBackground()); if (c != null) { colorXYPlotLabel.setBackground(c); } } }); builder.add(colorXYPlotLabel, "3,5,5,1"); builder.add(edit, "9,5"); } { builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.gridColor"), "1,7"); colorGridLabel.setOpaque(true); colorGridLabel.setText(" "); colorGridLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); colorGridLabel.setBackground((Color) xyPlot.getRangeGridlinePaint()); colorGridLabel.setEnabled(false); final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit")); edit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Color c = JColorChooser.showDialog(GraphEditor.this, I18nSupport.translate("menus.graph.graphEditor.selectColor"), colorGridLabel.getBackground()); if (c != null) { colorGridLabel.setBackground(c); } } }); builder.add(colorGridLabel, "3,7,5,1"); builder.add(edit, "9,7"); } { builder.add(showLegendCheckBox, "1,9,9,1"); } mainPanel.add(builder.build(), BorderLayout.CENTER); ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder(); buttonBarBuilder.addGlue(); buttonBarBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("cancel")); } @Override public void actionPerformed(ActionEvent e) { GraphEditor.this.setVisible(false); } }); buttonBarBuilder.addButton(new AbstractAction() { { putValue(NAME, I18nSupport.translate("ok")); } @Override public void actionPerformed(ActionEvent e) { if (titleForGraph.getText().isEmpty()) graphPanel.getChart().setTitle((String) null); else graphPanel.getChart().setTitle(titleForGraph.getText()); { Color c = colorGridLabel.getBackground(); xyPlot.setRangeGridlinePaint(c); xyPlot.setRangeMinorGridlinePaint(c); xyPlot.setDomainGridlinePaint(c); xyPlot.setDomainMinorGridlinePaint(c); } graphPanel.getChart().setBackgroundPaint(colorLabel.getBackground()); xyPlot.setBackgroundPaint(colorXYPlotLabel.getBackground()); graphPanel.getChart().getLegend().setVisible(showLegendCheckBox.isSelected()); GraphEditor.this.setVisible(false); } }); mainPanel.add(buttonBarBuilder.build(), BorderLayout.SOUTH); } pack(); Dimension d = this.getPreferredSize(); this.setSize(new Dimension(d.width + 20, d.height)); setResizable(false); }