1 30 package com.genimen.djeneric.tools.modeler.diagrammer; 31 32 import java.awt.BorderLayout ; 33 import java.awt.Color ; 34 import java.awt.Dimension ; 35 import java.awt.FlowLayout ; 36 import java.awt.Frame ; 37 import java.awt.Toolkit ; 38 import java.awt.event.ActionEvent ; 39 import java.awt.event.MouseEvent ; 40 import java.awt.event.WindowEvent ; 41 42 import javax.swing.JButton ; 43 import javax.swing.JColorChooser ; 44 import javax.swing.JComponent ; 45 import javax.swing.JDialog ; 46 import javax.swing.JLabel ; 47 import javax.swing.JPanel ; 48 import javax.swing.event.ChangeEvent ; 49 import javax.swing.event.ChangeListener ; 50 51 import com.genimen.djeneric.language.Messages; 52 import com.genimen.djeneric.ui.DjVerticalFlowLayout; 53 import com.genimen.djeneric.ui.Util; 54 import com.genimen.djeneric.util.DjLogger; 55 56 public class ColorChooserDialog extends JDialog 57 { 58 private static final long serialVersionUID = 1L; 59 static Color _storedExtentBackground = new Color (58, 110, 165); 60 static Color _storedPropertyForeground = Color.lightGray; 61 static Color _storedExtentNameForeground = Color.white; 62 63 JPanel panel1 = new JPanel (); 64 BorderLayout borderLayout1 = new BorderLayout (); 65 JColorChooser _colorChooser = new JColorChooser (Color.white); 66 JPanel jPanel1 = new JPanel (); 67 BorderLayout borderLayout2 = new BorderLayout (); 68 JPanel jPanel2 = new JPanel (); 69 JButton _butOk = new JButton (); 70 JButton _butCancel = new JButton (); 71 JPanel jPanel4 = new JPanel (); 72 FlowLayout flowLayout1 = new FlowLayout (); 73 JPanel _tableBackGround = new JPanel (); 74 JLabel _tableColor = new JLabel (); 75 JLabel _columnColor = new JLabel (); 76 DjVerticalFlowLayout verticalFlowLayout1 = new DjVerticalFlowLayout(); 77 78 JComponent _selected = _tableBackGround; 79 JPanel jPanel3 = new JPanel (); 80 JButton _butStore = new JButton (); 81 JButton _butRecall = new JButton (); 82 boolean _canceled = true; 83 84 public ColorChooserDialog(Frame frame) 85 { 86 super(frame, Messages.getString("ColorChooserDialog.ChooseColor"), true); 87 try 88 { 89 jbInit(); 90 91 pack(); 92 93 Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); 94 Dimension frameSize = getSize(); 95 setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2); 96 97 } 98 catch (Exception ex) 99 { 100 DjLogger.log(ex); 101 } 102 } 103 104 void jbInit() throws Exception 105 { 106 panel1.setLayout(borderLayout1); 107 jPanel1.setLayout(borderLayout2); 108 _butOk.setText(Messages.getString("global.Ok")); 109 _butOk.addActionListener(new java.awt.event.ActionListener () 110 { 111 public void actionPerformed(ActionEvent e) 112 { 113 _butOk_actionPerformed(e); 114 } 115 }); 116 _butCancel.setText(Messages.getString("global.Cancel")); 117 _butCancel.addActionListener(new java.awt.event.ActionListener () 118 { 119 public void actionPerformed(ActionEvent e) 120 { 121 _butCancel_actionPerformed(e); 122 } 123 }); 124 125 JPanel dummy = new JPanel (); 127 dummy.setPreferredSize(new Dimension (1, 1)); 128 _colorChooser.setPreviewPanel(dummy); 129 130 jPanel4.setLayout(flowLayout1); 131 _tableColor.setText(Messages.getString("ColorChooserDialog.ExtentName")); 132 _tableColor.addMouseListener(new java.awt.event.MouseAdapter () 133 { 134 public void mouseClicked(MouseEvent e) 135 { 136 _tableColor_mouseClicked(e); 137 } 138 }); 139 _columnColor.setText(Messages.getString("ColorChooserDialog.PropertyName")); 140 _columnColor.addMouseListener(new java.awt.event.MouseAdapter () 141 { 142 public void mouseClicked(MouseEvent e) 143 { 144 _columnColor_mouseClicked(e); 145 } 146 }); 147 _tableBackGround.setLayout(verticalFlowLayout1); 148 verticalFlowLayout1.setAlignment(FlowLayout.CENTER); 149 verticalFlowLayout1.setHorizontalFill(false); 150 _tableBackGround.setBackground(new Color (125, 125, 255)); 151 _tableBackGround.setPreferredSize(new Dimension (150, 60)); 152 _tableBackGround.addMouseListener(new java.awt.event.MouseAdapter () 153 { 154 public void mouseClicked(MouseEvent e) 155 { 156 _tableBackGround_mouseClicked(e); 157 } 158 }); 159 _butStore.setText(Messages.getString("ColorChooserDialog.Store")); 160 _butStore.addActionListener(new java.awt.event.ActionListener () 161 { 162 public void actionPerformed(ActionEvent e) 163 { 164 _butStore_actionPerformed(e); 165 } 166 }); 167 _butRecall.setText(Messages.getString("ColorChooserDialog.Recall")); 168 _butRecall.addActionListener(new java.awt.event.ActionListener () 169 { 170 public void actionPerformed(ActionEvent e) 171 { 172 _butRecall_actionPerformed(e); 173 } 174 }); 175 this.addWindowListener(new java.awt.event.WindowAdapter () 176 { 177 public void windowOpened(WindowEvent e) 178 { 179 this_windowOpened(e); 180 } 181 }); 182 183 getContentPane().add(panel1); 184 panel1.add(jPanel4, BorderLayout.SOUTH); 187 188 jPanel4.add(_tableBackGround, null); 189 _tableBackGround.add(_tableColor, null); 190 191 panel1.add(_colorChooser, BorderLayout.CENTER); 192 193 this.getContentPane().add(jPanel1, BorderLayout.SOUTH); 194 jPanel1.add(jPanel2, BorderLayout.EAST); 195 jPanel2.add(_butCancel, null); 196 jPanel2.add(_butOk, null); 197 jPanel1.add(jPanel3, BorderLayout.WEST); 198 jPanel3.add(_butStore, null); 199 _tableBackGround.add(_columnColor, null); 200 jPanel3.add(_butRecall, null); 201 202 _colorChooser.getSelectionModel().addChangeListener(new ChangeListener () 203 { 204 public void stateChanged(ChangeEvent e) 205 { 206 updateColorChooser(); 207 } 208 }); 209 Util.sizeButtons(jPanel1); 210 } 211 212 public Color setExtentColor() 213 { 214 return _tableBackGround.getBackground(); 215 } 216 217 public Color getPropertyColor() 218 { 219 return _columnColor.getForeground(); 220 } 221 222 public Color getNameColor() 223 { 224 return _tableColor.getForeground(); 225 } 226 227 public Color getExtentColor() 228 { 229 return _tableBackGround.getBackground(); 230 } 231 232 public void setExtentColor(Color c) 233 { 234 _tableBackGround.setBackground(c); 235 _tableColor.setBackground(c); 236 _columnColor.setBackground(c); 237 } 238 239 public void setNameColor(Color c) 240 { 241 _tableColor.setForeground(c); 242 } 243 244 public void setPropertyColor(Color c) 245 { 246 _columnColor.setForeground(c); 247 } 248 249 void _tableBackGround_mouseClicked(MouseEvent e) 250 { 251 _selected = _tableBackGround; 252 _colorChooser.setColor(_tableBackGround.getBackground()); 253 } 254 255 void _tableColor_mouseClicked(MouseEvent e) 256 { 257 _selected = _tableColor; 258 _colorChooser.setColor(_selected.getForeground()); 259 } 260 261 void _columnColor_mouseClicked(MouseEvent e) 262 { 263 _selected = _columnColor; 264 _colorChooser.setColor(_selected.getForeground()); 265 } 266 267 public void updateColorChooser() 268 { 269 if (_selected == _tableBackGround) 270 { 271 _tableBackGround.setBackground(_colorChooser.getColor()); 272 _tableColor.setBackground(_colorChooser.getColor()); 273 _columnColor.setBackground(_colorChooser.getColor()); 274 } 275 else _selected.setForeground(_colorChooser.getColor()); 276 } 277 278 void _butStore_actionPerformed(ActionEvent e) 279 { 280 _storedExtentBackground = getExtentColor(); 281 _storedPropertyForeground = getPropertyColor(); 282 _storedExtentNameForeground = getNameColor(); 283 } 284 285 void _butRecall_actionPerformed(ActionEvent e) 286 { 287 setExtentColor(_storedExtentBackground); 288 setPropertyColor(_storedPropertyForeground); 289 setNameColor(_storedExtentNameForeground); 290 291 _selected = _tableBackGround; 292 _colorChooser.setColor(getExtentColor()); 293 } 294 295 void _butOk_actionPerformed(ActionEvent e) 296 { 297 _canceled = false; 298 setVisible(false); 299 } 300 301 void _butCancel_actionPerformed(ActionEvent e) 302 { 303 setVisible(false); 304 } 305 306 public boolean isCancelled() 307 { 308 return _canceled; 309 } 310 311 void this_windowOpened(WindowEvent e) 312 { 313 _colorChooser.setColor(getExtentColor()); 314 } 315 316 } | Popular Tags |