KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > css > visual > ui > MarginStyleEditor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /*
21  * BorderStyleEditor.java
22  *
23  * Created on October 13, 2004, 12:23 PM
24  */

25
26 package org.netbeans.modules.css.visual.ui;
27
28 import org.netbeans.modules.css.visual.model.CssProperties;
29 import org.netbeans.modules.css.visual.model.CssStyleData;
30 import java.awt.BorderLayout JavaDoc;
31 import java.awt.FontMetrics JavaDoc;
32 import org.netbeans.modules.css.visual.model.CssStyleData;
33 import java.awt.Dimension JavaDoc;
34 import java.beans.PropertyChangeEvent JavaDoc;
35 import java.beans.PropertyChangeListener JavaDoc;
36 import java.awt.Component JavaDoc;
37 import java.awt.event.*;
38 import javax.swing.table.*;
39 import javax.swing.event.*;
40 import java.util.EventObject JavaDoc;
41 import javax.swing.tree.*;
42 import java.io.Serializable JavaDoc;
43 import javax.swing.*;
44 import org.openide.util.NbBundle;
45
46 /**
47  * Margin Style editor.
48  * @author Winston Prakash
49  * @version 1.0
50  */

51 public class MarginStyleEditor extends StyleEditor {
52     MarginDataTable marginDataTable = new MarginDataTable();
53
54     /** Creates new form FontStyleEditor */
55     public MarginStyleEditor() {
56         setName("marginStyleEditor"); //NOI18N
57
setDisplayName(NbBundle.getMessage(MarginStyleEditor.class, "MARGIN_EDITOR_DISPNAME"));
58         initComponents();
59         marginPanel.add(marginDataTable, BorderLayout.CENTER);
60     }
61
62     /**
63      * Set the CSS Properties Values from the CssStyleData data structure
64      * to the GUI components.
65      */

66     protected void setCssPropertyValues(CssStyleData cssStyleData){
67         removeCssPropertyChangeListener();
68         marginDataTable.setCssPropertyValues(cssStyleData);
69         setCssPropertyChangeListener(cssStyleData);
70         marginDataTable.validate();
71         marginDataTable.repaint();
72     }
73
74     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
75
private void initComponents() {
76         marginPanel = new javax.swing.JPanel JavaDoc();
77
78         setLayout(new java.awt.BorderLayout JavaDoc(0, 5));
79
80         marginPanel.setLayout(new java.awt.BorderLayout JavaDoc());
81
82         marginPanel.setBorder(new javax.swing.border.CompoundBorder JavaDoc(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(5, 5, 5, 5)), new javax.swing.border.EtchedBorder JavaDoc()));
83         add(marginPanel, java.awt.BorderLayout.NORTH);
84
85     }
86     // </editor-fold>//GEN-END:initComponents
87
/**
88      * Margin Data Table that holds the margin style info
89      * @author Winston Prakash
90      */

91     public class MarginDataTable extends JTable{
92         /**
93          * Holds value of property value.
94          */

95         private String JavaDoc value;
96
97         MarginWidthField allMarginField;
98         PaddingWidthField allPaddingField;
99         MarginWidthField topMarginField;
100         PaddingWidthField topPaddingField;
101         MarginWidthField bottomMarginField;
102         PaddingWidthField leftPaddingField;
103         MarginWidthField rightMarginField;
104         PaddingWidthField rightPaddingField;
105         PaddingWidthField bottomPaddingField;
106         MarginWidthField leftMarginField;
107
108         public MarginDataTable(){
109             super(6,3);
110             setDefaultRenderer( JComponent.class, new JComponentCellRenderer() );
111             setDefaultEditor( JComponent.class, new JComponentCellEditor() );
112             FontMetrics JavaDoc fontMetrics = getFontMetrics(getFont());
113             setRowHeight((fontMetrics.getHeight() + 10) > 25 ? (fontMetrics.getHeight() + 10) : 25);
114             setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
115             setIntercellSpacing(new Dimension JavaDoc(5,5));
116             //setShowGrid(false);
117
setTableHeader(null);
118             setBackground(new JPanel().getBackground());
119             initCells();
120             getColumnModel().getColumn(0).setPreferredWidth(30);
121             getColumnModel().getColumn(1).setPreferredWidth(150);
122             getColumnModel().getColumn(2).setPreferredWidth(150);
123             getAccessibleContext().setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "MARGIN_STYLE_TABLE_ACCESS_NAME"));
124             getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "MARGIN_STYLE_TABLE_ACCESS_DESC"));
125         }
126         
127         protected void setCssPropertyValues(CssStyleData cssStyleData){
128             
129             // Set the value for the Margin
130
String JavaDoc topMargin = cssStyleData.getProperty(CssProperties.MARGIN_TOP);
131             String JavaDoc bottomMargin = cssStyleData.getProperty(CssProperties.MARGIN_BOTTOM);
132             String JavaDoc leftMargin = cssStyleData.getProperty(CssProperties.MARGIN_LEFT);
133             String JavaDoc rightMargin = cssStyleData.getProperty(CssProperties.MARGIN_RIGHT);
134             
135             if ((topMargin != null) && (bottomMargin != null) && (leftMargin != null) && (rightMargin != null) &&
136                     (topMargin.equals(bottomMargin)) && (topMargin.equals(leftMargin)) &&
137                     (topMargin.equals(rightMargin))){
138                 allMarginField.setMarginString(topMargin);
139             }else{
140                 allMarginField.setMarginString(null);
141                 topMarginField.setMarginString(topMargin);
142                 bottomMarginField.setMarginString(bottomMargin);
143                 leftMarginField.setMarginString(leftMargin);
144                 rightMarginField.setMarginString(rightMargin);
145             }
146             
147             // Set the value for the Padding
148
String JavaDoc topPadding = cssStyleData.getProperty(CssProperties.PADDING_TOP);
149             String JavaDoc bottomPadding = cssStyleData.getProperty(CssProperties.PADDING_BOTTOM);
150             String JavaDoc leftPadding = cssStyleData.getProperty(CssProperties.PADDING_LEFT);
151             String JavaDoc rightPadding = cssStyleData.getProperty(CssProperties.PADDING_RIGHT);
152             
153             if ((topPadding != null) && (bottomPadding != null) && (leftPadding != null) && (rightPadding != null) &&
154                     (topPadding.equals(bottomPadding)) && (topPadding.equals(leftPadding)) &&
155                     (topPadding.equals(rightPadding))){
156                 allPaddingField.setPaddingString(topPadding);
157             }else{
158                 allPaddingField.setPaddingString(null);
159                 topPaddingField.setPaddingString(topPadding);
160                 bottomPaddingField.setPaddingString(bottomPadding);
161                 leftPaddingField.setPaddingString(leftPadding);
162                 rightPaddingField.setPaddingString(rightPadding);
163             }
164  
165         }
166         
167         public void initCells(){
168             JPanel colHeader1 = new JPanel();
169             //colHeader1.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_SIDE")));
170
setValueAt(colHeader1, 0, 0 );
171             JPanel colHeader2 = new JPanel();
172             colHeader2.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_ALL")));
173             setValueAt(colHeader2, 0, 1 );
174             JPanel colHeader3 = new JPanel();
175             colHeader3.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "PADDING")));
176             setValueAt(colHeader3, 0, 2 );
177             
178             JPanel rowHeader1 = new JPanel();
179             rowHeader1.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_PADDING_ALL")));
180             setValueAt(rowHeader1, 1, 0 );
181             JPanel rowHeader2 = new JPanel();
182             rowHeader2.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_PADDING_TOP")));
183             setValueAt(rowHeader2, 2, 0 );
184             JPanel rowHeader3 = new JPanel();
185             rowHeader3.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_PADDING_BOTTOM")));
186             setValueAt(rowHeader3, 3, 0 );
187             JPanel rowHeader4 = new JPanel();
188             rowHeader4.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_PADDING_LEFT")));
189             setValueAt(rowHeader4, 4, 0 );
190             JPanel rowHeader5 = new JPanel();
191             rowHeader5.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_PADDING_RIGHT")));
192             setValueAt(rowHeader5, 5, 0 );
193             
194             // All Side Margin
195
allMarginField = new MarginWidthField();
196             allMarginField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_MARGIN_WIDTH_ACCESS_NAME"),
197                     NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
198             allMarginField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
199                     NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
200             allMarginField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
201                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
202                     //cssPropertyChangeSupport.firePropertyChange(CssProperties.MARGIN, null, evt.getNewValue().toString());
203
topMarginField.setMarginString(evt.getNewValue().toString());
204                     bottomMarginField.setMarginString(evt.getNewValue().toString());
205                     leftMarginField.setMarginString(evt.getNewValue().toString());
206                     rightMarginField.setMarginString(evt.getNewValue().toString());
207                 }
208             });
209             setValueAt(allMarginField, 1, 1);
210             
211             
212             
213             // All Side Margin
214
allPaddingField = new PaddingWidthField();
215             allPaddingField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_PADDING_WIDTH_ACCESS_NAME"),
216                     NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
217             allPaddingField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_PADDING_WIDTH_ACCESS_DESC"),
218                     NbBundle.getMessage(MarginDataTable.class, "ALL_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
219             allPaddingField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
220                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
221                     //cssPropertyChangeSupport.firePropertyChange(CssProperties.PADDING, null, evt.getNewValue().toString());
222
topPaddingField.setPaddingString(evt.getNewValue().toString());
223                     bottomPaddingField.setPaddingString(evt.getNewValue().toString());
224                     leftPaddingField.setPaddingString(evt.getNewValue().toString());
225                     rightPaddingField.setPaddingString(evt.getNewValue().toString());
226                 }
227             });
228             setValueAt(allPaddingField, 1, 2);
229             
230             
231             // Top Side Margin
232
topMarginField = new MarginWidthField();
233             topMarginField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_MARGIN_WIDTH_ACCESS_NAME"),
234                     NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
235             topMarginField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
236                     NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
237             topMarginField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
238                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
239                     cssPropertyChangeSupport.firePropertyChange(CssProperties.MARGIN_TOP, null, evt.getNewValue().toString());
240                 }
241             });
242             setValueAt(topMarginField, 2, 1);
243             
244             // Top Side Margin
245
topPaddingField = new PaddingWidthField();
246             topPaddingField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_PADDING_WIDTH_ACCESS_NAME"),
247                     NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
248             topPaddingField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_PADDING_WIDTH_ACCESS_DESC"),
249                     NbBundle.getMessage(MarginDataTable.class, "TOP_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
250             topPaddingField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
251                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
252                     cssPropertyChangeSupport.firePropertyChange(CssProperties.PADDING_TOP, null, evt.getNewValue().toString());
253                 }
254             });
255             setValueAt(topPaddingField, 2, 2);
256             
257             // Bottom Side Margin
258
bottomMarginField = new MarginWidthField();
259             bottomMarginField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_MARGIN_WIDTH_ACCESS_NAME"),
260                     NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
261             bottomMarginField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
262                     NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
263             bottomMarginField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
264                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
265                     cssPropertyChangeSupport.firePropertyChange(CssProperties.MARGIN_BOTTOM, null, evt.getNewValue().toString());
266                 }
267             });
268             setValueAt(bottomMarginField, 3, 1);
269             
270             // Bottom Side Margin
271
bottomPaddingField = new PaddingWidthField();
272             bottomPaddingField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_PADDING_WIDTH_ACCESS_NAME"),
273                     NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
274             bottomPaddingField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_PADDING_WIDTH_ACCESS_DESC"),
275                     NbBundle.getMessage(MarginDataTable.class, "BOTTOM_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
276             bottomPaddingField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
277                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
278                     cssPropertyChangeSupport.firePropertyChange(CssProperties.PADDING_BOTTOM, null, evt.getNewValue().toString());
279                 }
280             });
281             setValueAt(bottomPaddingField, 3, 2);
282             
283             // Left Side Margin
284
leftMarginField = new MarginWidthField();
285             leftMarginField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_MARGIN_WIDTH_ACCESS_NAME"),
286                     NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
287             leftMarginField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
288                     NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
289             leftMarginField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
290                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
291                     cssPropertyChangeSupport.firePropertyChange(CssProperties.MARGIN_LEFT, null, evt.getNewValue().toString());
292                 }
293             });
294             setValueAt(leftMarginField, 4, 1);
295             
296             // Left Side Margin
297
leftPaddingField = new PaddingWidthField();
298             leftPaddingField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_PADDING_WIDTH_ACCESS_NAME"),
299                     NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
300             leftPaddingField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_PADDING_WIDTH_ACCESS_DESC"),
301                     NbBundle.getMessage(MarginDataTable.class, "LEFT_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
302             leftPaddingField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
303                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
304                     cssPropertyChangeSupport.firePropertyChange(CssProperties.PADDING_LEFT, null, evt.getNewValue().toString());
305                 }
306             });
307             setValueAt(leftPaddingField, 4, 2);
308             
309             // Left Side Margin
310
rightMarginField = new MarginWidthField();
311             rightMarginField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_MARGIN_WIDTH_ACCESS_NAME"),
312                     NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
313             rightMarginField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
314                     NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
315             rightMarginField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
316                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
317                     cssPropertyChangeSupport.firePropertyChange(CssProperties.MARGIN_RIGHT, null, evt.getNewValue().toString());
318                 }
319             });
320             setValueAt(rightMarginField, 5, 1);
321             
322             // Left Side Margin
323
rightPaddingField = new PaddingWidthField();
324             rightPaddingField.setAccessibleName(NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_PADDING_WIDTH_ACCESS_NAME"),
325                     NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
326             rightPaddingField.setAccessibleDescription(NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_PADDING_WIDTH_ACCESS_DESC"),
327                     NbBundle.getMessage(MarginDataTable.class, "RIGHT_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
328             rightPaddingField.addPropertyChangeListener(new PropertyChangeListenerImpl() {
329                 public void propertyChange(PropertyChangeEvent JavaDoc evt) {
330                     cssPropertyChangeSupport.firePropertyChange(CssProperties.PADDING_RIGHT, null, evt.getNewValue().toString());
331                 }
332             });
333             setValueAt(rightPaddingField, 5, 2);
334         }
335         
336         class PropertyChangeListenerImpl implements PropertyChangeListener JavaDoc{
337             public void propertyChange(PropertyChangeEvent JavaDoc evt) {
338             }
339         }
340         
341         public TableCellRenderer getCellRenderer(int row, int column) {
342             TableColumn tableColumn = getColumnModel().getColumn(column);
343             TableCellRenderer renderer = tableColumn.getCellRenderer();
344             if (renderer == null) {
345                 Class JavaDoc c = getColumnClass(column);
346                 if( c.equals(Object JavaDoc.class) ) {
347                     Object JavaDoc o = getValueAt(row,column);
348                     if( o != null )
349                         c = getValueAt(row,column).getClass();
350                 }
351                 renderer = getDefaultRenderer(c);
352             }
353             return renderer;
354         }
355         
356         public TableCellEditor getCellEditor(int row, int column) {
357             TableColumn tableColumn = getColumnModel().getColumn(column);
358             TableCellEditor editor = tableColumn.getCellEditor();
359             if (editor == null) {
360                 Class JavaDoc c = getColumnClass(column);
361                 if( c.equals(Object JavaDoc.class) ) {
362                     Object JavaDoc o = getValueAt(row,column);
363                     if( o != null )
364                         c = getValueAt(row,column).getClass();
365                 }
366                 editor = getDefaultEditor(c);
367             }
368             return editor;
369         }
370         
371         private class JComponentCellRenderer implements TableCellRenderer {
372             public Component JavaDoc getTableCellRendererComponent(JTable table, Object JavaDoc value,
373                     boolean isSelected, boolean hasFocus, int row, int column) {
374                 JComponent comp = (JComponent)value;
375                 comp.setMinimumSize(new Dimension JavaDoc(100,25));
376                 return comp;
377             }
378         }
379         
380         private class JComponentCellEditor implements TableCellEditor, TreeCellEditor,
381                 Serializable JavaDoc {
382             
383             protected EventListenerList listenerList = new EventListenerList();
384             transient protected ChangeEvent JavaDoc changeEvent = null;
385             
386             protected JComponent editorComponent = null;
387             protected JComponent container = null; // Can be tree or table
388

389             
390             public Component JavaDoc getComponent() {
391                 return editorComponent;
392             }
393             
394             
395             public Object JavaDoc getCellEditorValue() {
396                 return editorComponent;
397             }
398             
399             public boolean isCellEditable(EventObject JavaDoc anEvent) {
400                 return true;
401             }
402             
403             public boolean shouldSelectCell(EventObject JavaDoc anEvent) {
404                 if( editorComponent != null && anEvent instanceof MouseEvent
405                         && ((MouseEvent)anEvent).getID() == MouseEvent.MOUSE_PRESSED ) {
406                     Component JavaDoc dispatchComponent = SwingUtilities.getDeepestComponentAt(editorComponent, 3, 3 );
407                     MouseEvent e = (MouseEvent)anEvent;
408                     MouseEvent e2 = new MouseEvent( dispatchComponent, MouseEvent.MOUSE_RELEASED,
409                             e.getWhen() + 100000, e.getModifiers(), 3, 3, e.getClickCount(),
410                             e.isPopupTrigger() );
411                     dispatchComponent.dispatchEvent(e2);
412                     e2 = new MouseEvent( dispatchComponent, MouseEvent.MOUSE_CLICKED,
413                             e.getWhen() + 100001, e.getModifiers(), 3, 3, 1,
414                             e.isPopupTrigger() );
415                     dispatchComponent.dispatchEvent(e2);
416                 }
417                 return false;
418             }
419             
420             public boolean stopCellEditing() {
421                 fireEditingStopped();
422                 return true;
423             }
424             
425             public void cancelCellEditing() {
426                 fireEditingCanceled();
427             }
428             
429             public void addCellEditorListener(CellEditorListener l) {
430                 listenerList.add(CellEditorListener.class, l);
431             }
432             
433             public void removeCellEditorListener(CellEditorListener l) {
434                 listenerList.remove(CellEditorListener.class, l);
435             }
436             
437             protected void fireEditingStopped() {
438                 Object JavaDoc[] listeners = listenerList.getListenerList();
439                 // Process the listeners last to first, notifying
440
// those that are interested in this event
441
for (int i = listeners.length-2; i>=0; i-=2) {
442                     if (listeners[i]==CellEditorListener.class) {
443                         // Lazily create the event:
444
if (changeEvent == null)
445                             changeEvent = new ChangeEvent JavaDoc(this);
446                         ((CellEditorListener)listeners[i+1]).editingStopped(changeEvent);
447                     }
448                 }
449             }
450             
451             protected void fireEditingCanceled() {
452                 // Guaranteed to return a non-null array
453
Object JavaDoc[] listeners = listenerList.getListenerList();
454                 // Process the listeners last to first, notifying
455
// those that are interested in this event
456
for (int i = listeners.length-2; i>=0; i-=2) {
457                     if (listeners[i]==CellEditorListener.class) {
458                         // Lazily create the event:
459
if (changeEvent == null)
460                             changeEvent = new ChangeEvent JavaDoc(this);
461                         ((CellEditorListener)listeners[i+1]).editingCanceled(changeEvent);
462                     }
463                 }
464             }
465             
466             // implements javax.swing.tree.TreeCellEditor
467
public Component JavaDoc getTreeCellEditorComponent(JTree tree, Object JavaDoc value,
468                     boolean isSelected, boolean expanded, boolean leaf, int row) {
469                 String JavaDoc stringValue = tree.convertValueToText(value, isSelected,
470                         expanded, leaf, row, false);
471                 
472                 editorComponent = (JComponent)value;
473                 container = tree;
474                 return editorComponent;
475             }
476             
477             // implements javax.swing.table.TableCellEditor
478
public Component JavaDoc getTableCellEditorComponent(JTable table, Object JavaDoc value,
479                     boolean isSelected, int row, int column) {
480                 
481                 editorComponent = (JComponent)value;
482                 container = table;
483                 return editorComponent;
484             }
485         } // End of class JComponentCellEditor
486
}
487     
488     // Variables declaration - do not modify//GEN-BEGIN:variables
489
private javax.swing.JPanel JavaDoc marginPanel;
490     // End of variables declaration//GEN-END:variables
491

492 }
493
Popular Tags