1 19 20 25 26 package org.netbeans.modules.css.visual.ui; 27 28 import java.awt.BorderLayout ; 29 import java.awt.FontMetrics ; 30 import org.netbeans.modules.css.visual.model.BorderModel; 31 import org.netbeans.modules.css.visual.model.CssProperties; 32 import org.netbeans.modules.css.visual.model.CssStyleData; 33 import java.awt.Dimension ; 34 import java.beans.PropertyChangeEvent ; 35 import java.beans.PropertyChangeListener ; 36 import java.awt.Component ; 37 import java.awt.event.*; 38 import javax.swing.table.*; 39 import javax.swing.event.*; 40 import java.util.EventObject ; 41 import javax.swing.tree.*; 42 import java.io.Serializable ; 43 import javax.swing.*; 44 import org.openide.util.NbBundle; 45 46 51 public class BorderStyleEditor extends StyleEditor { 52 BorderDataTable borderDataTable = new BorderDataTable(); 53 54 public BorderStyleEditor() { 55 setName("borderStyleEditor"); setDisplayName(NbBundle.getMessage(BorderStyleEditor.class, "BORDER_EDITOR_DISPNAME")); 57 initComponents(); 58 borderPanel.add(borderDataTable, BorderLayout.CENTER); 59 } 60 61 65 protected void setCssPropertyValues(CssStyleData cssStyleData){ 66 removeCssPropertyChangeListener(); 67 borderDataTable.setCssPropertyValues(cssStyleData); 68 setCssPropertyChangeListener(cssStyleData); 69 } 70 71 private void initComponents() { 73 borderPanel = new javax.swing.JPanel (); 74 75 setLayout(new java.awt.BorderLayout (0, 5)); 76 77 borderPanel.setLayout(new java.awt.BorderLayout ()); 78 79 borderPanel.setBorder(new javax.swing.border.CompoundBorder (new javax.swing.border.EmptyBorder (new java.awt.Insets (5, 5, 5, 5)), new javax.swing.border.EtchedBorder ())); 80 add(borderPanel, java.awt.BorderLayout.NORTH); 81 82 } 83 85 class BorderDataTable extends JTable{ 86 CssStyleData cssStyleData ; 87 90 private String value; 91 92 BorderModel borderModel = new BorderModel(); 93 94 JComboBox allStyleCombo; 95 BorderWidthField allWidthField; 96 ColorSelectionField allColorField; 97 98 JComboBox topStyleCombo; 99 BorderWidthField topWidthField; 100 ColorSelectionField topColorField; 101 102 JComboBox bottomStyleCombo; 103 BorderWidthField bottomWidthField; 104 ColorSelectionField bottomColorField; 105 106 JComboBox leftStyleCombo; 107 BorderWidthField leftWidthField; 108 ColorSelectionField leftColorField; 109 110 JComboBox rightStyleCombo; 111 BorderWidthField rightWidthField; 112 ColorSelectionField rightColorField; 113 114 public BorderDataTable(){ 115 super(6,4); 116 setDefaultRenderer( JComponent.class, new JComponentCellRenderer() ); 117 setDefaultEditor( JComponent.class, new JComponentCellEditor() ); 118 FontMetrics fontMetrics = getFontMetrics(getFont()); 119 setRowHeight((fontMetrics.getHeight() + 10) > 25 ? (fontMetrics.getHeight() + 10) : 25); 120 setAutoResizeMode(JTable.AUTO_RESIZE_OFF); 121 setIntercellSpacing(new Dimension (5,5)); 122 setTableHeader(null); 123 setBackground(new JPanel().getBackground()); 124 initCells(); 125 getColumnModel().getColumn(0).setPreferredWidth(50); 126 getColumnModel().getColumn(1).setPreferredWidth(75); 127 getColumnModel().getColumn(2).setPreferredWidth(125); 128 getColumnModel().getColumn(3).setPreferredWidth(125); 129 getAccessibleContext().setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "BORDER_STYLE_TABLE_ACCESS_NAME")); 130 getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "BORDER_STYLE_TABLE_ACCESS_DESC")); 131 } 132 133 protected void setCssPropertyValues(CssStyleData cssStyleData){ 134 removeCssPropertyChangeListener(); 135 136 137 String topStyle = cssStyleData.getProperty(CssProperties.BORDER_TOP_STYLE); 139 String bottomStyle = cssStyleData.getProperty(CssProperties.BORDER_BOTTOM_STYLE); 140 String leftStyle = cssStyleData.getProperty(CssProperties.BORDER_LEFT_STYLE); 141 String rightStyle = cssStyleData.getProperty(CssProperties.BORDER_RIGHT_STYLE); 142 143 144 if ((topStyle != null) && (bottomStyle != null) && (leftStyle != null) && (rightStyle != null) && 145 (topStyle.equals(bottomStyle)) && (topStyle.equals(leftStyle)) && 146 (topStyle.equals(rightStyle))){ 147 allStyleCombo.setSelectedItem(topStyle); 148 }else{ 149 allStyleCombo.setSelectedIndex(0); 150 if(topStyle != null){ 151 topStyleCombo.setSelectedItem(topStyle); 152 }else{ 153 topStyleCombo.setSelectedIndex(0); 154 } 155 if(bottomStyle != null){ 156 bottomStyleCombo.setSelectedItem(bottomStyle); 157 }else{ 158 bottomStyleCombo.setSelectedIndex(0); 159 } 160 if(leftStyle != null){ 161 leftStyleCombo.setSelectedItem(leftStyle); 162 }else{ 163 leftStyleCombo.setSelectedIndex(0); 164 } 165 if(rightStyle != null){ 166 rightStyleCombo.setSelectedItem(rightStyle); 167 }else{ 168 rightStyleCombo.setSelectedIndex(0); 169 } 170 } 171 172 String topWidth = cssStyleData.getProperty(CssProperties.BORDER_TOP_WIDTH); 174 String bottomWidth = cssStyleData.getProperty(CssProperties.BORDER_BOTTOM_WIDTH); 175 String leftWidth = cssStyleData.getProperty(CssProperties.BORDER_LEFT_WIDTH); 176 String rightWidth = cssStyleData.getProperty(CssProperties.BORDER_RIGHT_WIDTH); 177 178 if ((topWidth != null) && (bottomWidth != null) && (leftWidth != null) && (rightWidth != null) && 179 (topWidth.equals(bottomWidth)) && (topWidth.equals(leftWidth)) && 180 (topWidth.equals(rightWidth))){ 181 allWidthField.setWidthString(topWidth); 182 }else{ 183 allWidthField.setWidthString(null); 184 topWidthField.setWidthString(topWidth); 185 bottomWidthField.setWidthString(bottomWidth); 186 leftWidthField.setWidthString(leftWidth); 187 rightWidthField.setWidthString(rightWidth); 188 } 189 190 String topColor = cssStyleData.getProperty(CssProperties.BORDER_TOP_COLOR); 192 String bottomColor = cssStyleData.getProperty(CssProperties.BORDER_BOTTOM_COLOR); 193 String leftColor = cssStyleData.getProperty(CssProperties.BORDER_LEFT_COLOR); 194 String rightColor = cssStyleData.getProperty(CssProperties.BORDER_RIGHT_COLOR); 195 196 if ((topColor != null) && (bottomColor != null) && (leftColor != null) && (rightColor != null) && 197 (topColor.equals(bottomColor)) && (topColor.equals(leftColor)) && 198 (topColor.equals(rightColor))){ 199 allColorField.setColorString(topColor); 200 }else{ 201 allColorField.setColorString(null); 202 topColorField.setColorString(topColor); 203 bottomColorField.setColorString(bottomColor); 204 leftColorField.setColorString(leftColor); 205 rightColorField.setColorString(rightColor); 206 } 207 208 borderDataTable.validate(); 209 borderDataTable.repaint(); 210 setCssPropertyChangeListener(cssStyleData); 211 } 212 213 public void initCells(){ 214 JPanel colHeader1 = new JPanel(); 215 setValueAt(colHeader1, 0, 0 ); 217 JPanel colHeader2 = new JPanel(); 218 colHeader2.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_STYLE"))); 219 setValueAt(colHeader2, 0, 1 ); 220 JPanel colHeader3 = new JPanel(); 221 colHeader3.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_WIDTH"))); 222 setValueAt(colHeader3, 0, 2 ); 223 JPanel colHeader6 = new JPanel(); 224 colHeader6.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_COLOR"))); 225 setValueAt(colHeader6, 0, 3); 226 227 JPanel rowHeader1 = new JPanel(); 228 rowHeader1.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_ALL"))); 229 setValueAt(rowHeader1, 1, 0 ); 230 JPanel rowHeader2 = new JPanel(); 231 rowHeader2.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_TOP"))); 232 setValueAt(rowHeader2, 2, 0 ); 233 JPanel rowHeader3 = new JPanel(); 234 rowHeader3.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_BOTTOM"))); 235 setValueAt(rowHeader3, 3, 0 ); 236 JPanel rowHeader4 = new JPanel(); 237 rowHeader4.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_LEFT"))); 238 setValueAt(rowHeader4, 4, 0 ); 239 JPanel rowHeader5 = new JPanel(); 240 rowHeader5.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_RIGHT"))); 241 setValueAt(rowHeader5, 5, 0 ); 242 243 allStyleCombo = new JComboBox(); 245 allStyleCombo.getAccessibleContext().setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "ALL_SIDE_BORDER_STYLE_ACCESS_NAME")); 246 allStyleCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "ALL_SIDE_BORDER_STYLE_ACCESS_DESC")); 247 allStyleCombo.setModel(borderModel.getStyleList()); 248 allStyleCombo.addItemListener(new ItemListener() { 249 public void itemStateChanged(ItemEvent evt) { 250 topStyleCombo.setSelectedIndex(allStyleCombo.getSelectedIndex()); 252 bottomStyleCombo.setSelectedIndex(allStyleCombo.getSelectedIndex()); 253 leftStyleCombo.setSelectedIndex(allStyleCombo.getSelectedIndex()); 254 rightStyleCombo.setSelectedIndex(allStyleCombo.getSelectedIndex()); 255 } 256 }); 257 setValueAt(allStyleCombo, 1, 1); 258 259 allWidthField = new BorderWidthField(); 261 allWidthField.setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "ALL_SIDE_BORDER_WIDTH_ACCESS_NAME"), 262 NbBundle.getMessage(BorderDataTable.class, "ALL_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME")); 263 allWidthField.setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "ALL_SIDE_BORDER_WIDTH_ACCESS_DESC"), 264 NbBundle.getMessage(BorderDataTable.class, "ALL_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC")); 265 allWidthField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 266 public void propertyChange(PropertyChangeEvent evt) { 267 topWidthField.setWidthString(evt.getNewValue().toString()); 269 bottomWidthField.setWidthString(evt.getNewValue().toString()); 270 leftWidthField.setWidthString(evt.getNewValue().toString()); 271 rightWidthField.setWidthString(evt.getNewValue().toString()); 272 } 273 }); 274 setValueAt(allWidthField, 1, 2); 275 276 allColorField = new ColorSelectionField(); 278 allColorField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 279 public void propertyChange(PropertyChangeEvent evt) { 280 topColorField.setColorString(allColorField.getColorString()); 282 bottomColorField.setColorString(allColorField.getColorString()); 283 leftColorField.setColorString(allColorField.getColorString()); 284 rightColorField.setColorString(allColorField.getColorString()); 285 } 286 }); 287 setValueAt(allColorField, 1, 3); 288 289 topStyleCombo = new JComboBox(); 291 topStyleCombo.getAccessibleContext().setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "TOP_SIDE_BORDER_STYLE_ACCESS_NAME")); 292 topStyleCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "TOP_SIDE_BORDER_STYLE_ACCESS_DESC")); 293 topStyleCombo.setModel(borderModel.getStyleList()); 294 topStyleCombo.addItemListener(new ItemListener() { 295 public void itemStateChanged(ItemEvent evt) { 296 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_TOP_STYLE, null, topStyleCombo.getSelectedItem().toString()); 297 } 298 }); 299 setValueAt(topStyleCombo, 2, 1); 300 301 topWidthField = new BorderWidthField(); 303 topWidthField.setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "TOP_SIDE_BORDER_WIDTH_ACCESS_NAME"), 304 NbBundle.getMessage(BorderDataTable.class, "TOP_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME")); 305 topWidthField.setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "TOP_SIDE_BORDER_WIDTH_ACCESS_DESC"), 306 NbBundle.getMessage(BorderDataTable.class, "TOP_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC")); 307 topWidthField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 308 public void propertyChange(PropertyChangeEvent evt) { 309 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_TOP_WIDTH, null, evt.getNewValue().toString()); 310 } 311 }); 312 setValueAt(topWidthField, 2, 2); 313 314 topColorField = new ColorSelectionField(); 316 topColorField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 317 public void propertyChange(PropertyChangeEvent evt) { 318 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_TOP_COLOR, null, topColorField.getColorString()); 319 } 320 }); 321 setValueAt(topColorField, 2, 3); 322 323 324 bottomStyleCombo = new JComboBox(); 326 bottomStyleCombo.getAccessibleContext().setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "BOTTOM_SIDE_BORDER_STYLE_ACCESS_NAME")); 327 bottomStyleCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "BOTTOM_SIDE_BORDER_STYLE_ACCESS_DESC")); 328 bottomStyleCombo.setModel(borderModel.getStyleList()); 329 bottomStyleCombo.addItemListener(new ItemListener() { 330 public void itemStateChanged(ItemEvent evt) { 331 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_BOTTOM_STYLE, null, bottomStyleCombo.getSelectedItem().toString()); 332 } 333 }); 334 setValueAt(bottomStyleCombo, 3, 1); 335 336 bottomWidthField = new BorderWidthField(); 338 bottomWidthField.setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "BOTTOM_SIDE_BORDER_WIDTH_ACCESS_NAME"), 339 NbBundle.getMessage(BorderDataTable.class, "BOTTOM_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME")); 340 bottomWidthField.setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "BOTTOM_SIDE_BORDER_WIDTH_ACCESS_DESC"), 341 NbBundle.getMessage(BorderDataTable.class, "BOTTOM_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC")); 342 bottomWidthField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 343 public void propertyChange(PropertyChangeEvent evt) { 344 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_BOTTOM_WIDTH, null, evt.getNewValue().toString()); 345 } 346 }); 347 setValueAt(bottomWidthField, 3, 2); 348 349 bottomColorField = new ColorSelectionField(); 351 bottomColorField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 352 public void propertyChange(PropertyChangeEvent evt) { 353 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_BOTTOM_COLOR, null, bottomColorField.getColorString()); 354 } 355 }); 356 setValueAt(bottomColorField, 3, 3); 357 358 359 360 361 leftStyleCombo = new JComboBox( new String [] {}); 363 leftStyleCombo.getAccessibleContext().setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "LEFT_SIDE_BORDER_STYLE_ACCESS_NAME")); 364 leftStyleCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "LEFT_SIDE_BORDER_STYLE_ACCESS_DESC")); 365 leftStyleCombo.setModel(borderModel.getStyleList()); 366 leftStyleCombo.addItemListener(new ItemListener() { 367 public void itemStateChanged(ItemEvent evt) { 368 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_LEFT_STYLE, null, leftStyleCombo.getSelectedItem().toString()); 369 } 370 }); 371 setValueAt(leftStyleCombo, 4, 1); 372 373 leftWidthField = new BorderWidthField(); 375 leftWidthField.setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "LEFT_SIDE_BORDER_WIDTH_ACCESS_NAME"), 376 NbBundle.getMessage(BorderDataTable.class, "LEFT_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME")); 377 leftWidthField.setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "LEFT_SIDE_BORDER_WIDTH_ACCESS_DESC"), 378 NbBundle.getMessage(BorderDataTable.class, "LEFT_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC")); 379 381 leftWidthField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 382 public void propertyChange(PropertyChangeEvent evt) { 383 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_LEFT_WIDTH, null, evt.getNewValue().toString()); 384 } 385 }); 386 setValueAt(leftWidthField, 4, 2); 387 388 leftColorField = new ColorSelectionField(); 390 leftColorField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 391 public void propertyChange(PropertyChangeEvent evt) { 392 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_LEFT_COLOR, null, leftColorField.getColorString()); 393 } 394 }); 395 setValueAt(leftColorField, 4, 3); 396 397 398 rightStyleCombo = new JComboBox(); 400 rightStyleCombo.getAccessibleContext().setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "RIGHT_SIDE_BORDER_STYLE_ACCESS_NAME")); 401 rightStyleCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "RIGHT_SIDE_BORDER_STYLE_ACCESS_DESC")); 402 rightStyleCombo.setModel(borderModel.getStyleList()); 403 rightStyleCombo.addItemListener(new ItemListener() { 404 public void itemStateChanged(ItemEvent evt) { 405 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_RIGHT_STYLE, null, rightStyleCombo.getSelectedItem().toString()); 406 } 407 }); 408 setValueAt(rightStyleCombo, 5, 1); 409 410 411 rightWidthField = new BorderWidthField(); 413 rightWidthField.setAccessibleName(NbBundle.getMessage(BorderDataTable.class, "RIGHT_SIDE_BORDER_WIDTH_ACCESS_NAME"), 414 NbBundle.getMessage(BorderDataTable.class, "RIGHT_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME")); 415 rightWidthField.setAccessibleDescription(NbBundle.getMessage(BorderDataTable.class, "RIGHT_SIDE_BORDER_WIDTH_ACCESS_DESC"), 416 NbBundle.getMessage(BorderDataTable.class, "RIGHT_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC")); 417 rightWidthField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 418 public void propertyChange(PropertyChangeEvent evt) { 419 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_RIGHT_WIDTH, null, evt.getNewValue().toString()); 420 } 421 }); 422 setValueAt(rightWidthField, 5, 2); 423 424 rightColorField = new ColorSelectionField(); 426 rightColorField.addPropertyChangeListener(new PropertyChangeListenerImpl() { 427 public void propertyChange(PropertyChangeEvent evt) { 428 cssPropertyChangeSupport.firePropertyChange(CssProperties.BORDER_RIGHT_COLOR, null, rightColorField.getColorString()); 429 } 430 }); 431 setValueAt(rightColorField, 5, 3); 432 } 433 434 private void setAllSideBorder(){ 435 436 } 437 438 class PropertyChangeListenerImpl implements PropertyChangeListener { 439 public void propertyChange(PropertyChangeEvent evt) { 440 } 441 } 442 443 public TableCellRenderer getCellRenderer(int row, int column) { 444 TableColumn tableColumn = getColumnModel().getColumn(column); 445 TableCellRenderer renderer = tableColumn.getCellRenderer(); 446 if (renderer == null) { 447 Class c = getColumnClass(column); 448 if( c.equals(Object .class) ) { 449 Object o = getValueAt(row,column); 450 if( o != null ) 451 c = getValueAt(row,column).getClass(); 452 } 453 renderer = getDefaultRenderer(c); 454 } 455 return renderer; 456 } 457 458 public TableCellEditor getCellEditor(int row, int column) { 459 TableColumn tableColumn = getColumnModel().getColumn(column); 460 TableCellEditor editor = tableColumn.getCellEditor(); 461 if (editor == null) { 462 Class c = getColumnClass(column); 463 if( c.equals(Object .class) ) { 464 Object o = getValueAt(row,column); 465 if( o != null ) 466 c = getValueAt(row,column).getClass(); 467 } 468 editor = getDefaultEditor(c); 469 } 470 return editor; 471 } 472 473 private class JComponentCellRenderer implements TableCellRenderer { 474 public Component getTableCellRendererComponent(JTable table, Object value, 475 boolean isSelected, boolean hasFocus, int row, int column) { 476 JComponent comp = (JComponent)value; 477 comp.setMinimumSize(new Dimension (100,25)); 478 return comp; 479 } 480 } 481 482 private class JComponentCellEditor implements TableCellEditor, TreeCellEditor,Serializable { 483 484 protected EventListenerList listenerList = new EventListenerList(); 485 transient protected ChangeEvent changeEvent = null; 486 487 protected JComponent editorComponent = null; 488 protected JComponent container = null; 490 491 public Component getComponent() { 492 return editorComponent; 493 } 494 495 496 public Object getCellEditorValue() { 497 return editorComponent; 498 } 499 500 public boolean isCellEditable(EventObject anEvent) { 501 return true; 502 } 503 504 public boolean shouldSelectCell(EventObject anEvent) { 505 if( editorComponent != null && anEvent instanceof MouseEvent 506 && ((MouseEvent)anEvent).getID() == MouseEvent.MOUSE_PRESSED ) { 507 Component dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, 3, 3 ); 508 MouseEvent e = (MouseEvent)anEvent; 509 MouseEvent e2 = new MouseEvent( dispatchComponent, MouseEvent.MOUSE_RELEASED, 510 e.getWhen() + 100000, e.getModifiers(), 3, 3, e.getClickCount(), 511 e.isPopupTrigger() ); 512 dispatchComponent.dispatchEvent(e2); 513 e2 = new MouseEvent( dispatchComponent, MouseEvent.MOUSE_CLICKED, 514 e.getWhen() + 100001, e.getModifiers(), 3, 3, 1, 515 e.isPopupTrigger() ); 516 dispatchComponent.dispatchEvent(e2); 517 } 518 return false; 519 } 520 521 public boolean stopCellEditing() { 522 fireEditingStopped(); 523 return true; 524 } 525 526 public void cancelCellEditing() { 527 fireEditingCanceled(); 528 } 529 530 public void addCellEditorListener(CellEditorListener l) { 531 listenerList.add(CellEditorListener.class, l); 532 } 533 534 public void removeCellEditorListener(CellEditorListener l) { 535 listenerList.remove(CellEditorListener.class, l); 536 } 537 538 protected void fireEditingStopped() { 539 Object [] listeners = listenerList.getListenerList(); 540 for (int i = listeners.length-2; i>=0; i-=2) { 543 if (listeners[i]==CellEditorListener.class) { 544 if (changeEvent == null) 546 changeEvent = new ChangeEvent (this); 547 ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent); 548 } 549 } 550 } 551 552 protected void fireEditingCanceled() { 553 Object [] listeners = listenerList.getListenerList(); 555 for (int i = listeners.length-2; i>=0; i-=2) { 558 if (listeners[i]==CellEditorListener.class) { 559 if (changeEvent == null) 561 changeEvent = new ChangeEvent (this); 562 ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent); 563 } 564 } 565 } 566 567 public Component getTreeCellEditorComponent(JTree tree, Object value, 569 boolean isSelected, boolean expanded, boolean leaf, int row) { 570 String stringValue = tree.convertValueToText(value, isSelected, 571 expanded, leaf, row, false); 572 573 editorComponent = (JComponent)value; 574 container = tree; 575 return editorComponent; 576 } 577 578 public Component getTableCellEditorComponent(JTable table, Object value, 580 boolean isSelected, int row, int column) { 581 582 editorComponent = (JComponent)value; 583 container = table; 584 return editorComponent; 585 } 586 587 } 588 } 589 590 private javax.swing.JPanel borderPanel; 592 594 } 595 | Popular Tags |