1 package com.calipso.reportgenerator.userinterface; 2 3 import javax.swing.*; 4 import java.awt.*; 5 import java.awt.event.ActionListener ; 6 import java.awt.event.ActionEvent ; 7 import java.awt.event.KeyListener ; 8 import java.awt.event.KeyEvent ; 9 10 13 14 public class ChartCustomizer extends JDialog implements ActionListener , KeyListener { 15 16 private JPanel colorPanel; 17 private JPanel checkBoxPanel; 18 private JPanel btsPanel; 19 private JButton btAccept; 20 private JButton btCancel; 21 private JCheckBox checkBoxLegend; 22 private JCheckBox checkBoxToolTips; 23 private JCheckBox checkBoxMultipleAxis; 24 private JButton btColor; 25 private Color color; 26 private boolean legend; 27 private boolean tooltips; 28 private boolean multipleAxis; 29 private Point locationPoint; 30 31 32 38 public ChartCustomizer(Frame owner, boolean modal) throws HeadlessException { 39 super(owner, modal); 40 setColor(Color.white); 41 initialize(); 42 setLegend(checkBoxLegend.isSelected()); 43 setTooltips(checkBoxToolTips.isSelected()); 44 setMultipleAxis(checkBoxMultipleAxis.isSelected()); 45 46 setLocation(getDefaultLocation()); 47 } 48 49 54 private Point getDefaultLocation() { 55 Point ownerLocation = getOwner().getLocation(); 56 Dimension ownerSize = getOwner().getSize(); 57 Dimension size = getSize(); 58 59 int x = ownerLocation.x + ownerSize.width / 2 - size.width / 2; 60 int y = ownerLocation.y + ownerSize.height / 2 - size.height / 2; 61 return new Point(x, y); 62 } 63 64 67 private void initialize(){ 68 colorPanel = new JPanel(new BorderLayout()); 69 btColor = new JButton("Color..."); 70 btColor.addActionListener(this); 71 btColor.addKeyListener(this); 72 colorPanel.add(btColor); 73 74 checkBoxPanel = new JPanel(new GridLayout(3, 2)); 75 checkBoxLegend = new JCheckBox(); 76 checkBoxToolTips = new JCheckBox(); 77 checkBoxMultipleAxis = new JCheckBox(); 78 79 checkBoxPanel.add(new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("235"))); 80 checkBoxPanel.add(checkBoxLegend); 81 checkBoxPanel.add(new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("236"))); 82 checkBoxPanel.add(checkBoxToolTips); 83 checkBoxPanel.add(new JLabel(com.calipso.reportgenerator.common.LanguageTraslator.traslate("391"))); 84 checkBoxPanel.add(checkBoxMultipleAxis); 85 86 checkBoxLegend.setSelected(true); 87 checkBoxToolTips.setSelected(true); 88 checkBoxMultipleAxis.setSelected(false); 89 90 btAccept = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("112")); 91 btAccept.addActionListener(this); 92 btAccept.addKeyListener(this); 93 btCancel = new JButton(com.calipso.reportgenerator.common.LanguageTraslator.traslate("113")); 94 btCancel.addActionListener(this); 95 btCancel.addKeyListener(this); 96 btsPanel = new JPanel(new FlowLayout()); 97 btsPanel.add(btAccept); 98 btsPanel.add(btCancel); 99 100 this.getContentPane().add(colorPanel, BorderLayout.NORTH); 101 this.getContentPane().add(checkBoxPanel, BorderLayout.CENTER); 102 this.getContentPane().add(btsPanel, BorderLayout.SOUTH); 103 104 this.pack(); 105 } 106 107 112 public void actionPerformed(ActionEvent ae) { 113 if(ae.getSource() == btAccept){ 114 setLegend(checkBoxLegend.isSelected()); 115 setTooltips(checkBoxToolTips.isSelected()); 116 setMultipleAxis(checkBoxMultipleAxis.isSelected()); 117 this.dispose(); 118 }else if(ae.getSource() == btColor){ 119 setColor(JColorChooser.showDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("237"), Color.white)); 120 }else if(ae.getSource() == btCancel){ 121 this.dispose(); 122 } 123 } 124 125 129 public Color getColor() { 130 return color; 131 } 132 133 137 public void setColor(Color color) { 138 this.color = color; 139 } 140 141 146 public boolean isLegend() { 147 return legend; 148 } 149 150 155 public void setLegend(boolean legend) { 156 this.legend = legend; 157 } 158 159 164 public boolean isTooltips() { 165 return tooltips; 166 } 167 172 public void setTooltips(boolean tooltips) { 173 this.tooltips = tooltips; 174 } 175 176 public void setMultipleAxis(boolean checkBoxMultipleAxis) { 177 this.multipleAxis = checkBoxMultipleAxis; 178 } 179 180 184 public void keyTyped(KeyEvent e) { 185 } 186 187 192 public void keyPressed(KeyEvent e) { 193 if(e.getSource() == btAccept){ 194 setLegend(checkBoxLegend.isSelected()); 195 setTooltips(checkBoxToolTips.isSelected()); 196 setMultipleAxis(checkBoxMultipleAxis.isSelected()); 197 this.dispose(); 198 }else if(e.getSource() == btCancel){ 199 this.dispose(); 200 }else if(e.getSource() == btColor){ 201 setColor(JColorChooser.showDialog(this, com.calipso.reportgenerator.common.LanguageTraslator.traslate("237"), Color.white)); 202 } 203 } 204 205 209 public void keyReleased(KeyEvent e) { 210 } 211 212 public boolean isMultipleAxis() { 213 return multipleAxis; 214 } 215 } 216 | Popular Tags |