001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.visualweb.propertyeditors.css;
042:
043: import org.netbeans.modules.visualweb.propertyeditors.css.model.BorderData;
044: import org.netbeans.modules.visualweb.propertyeditors.css.model.CssStyleData;
045: import java.awt.*;
046: import java.awt.Dimension;
047: import java.beans.PropertyChangeEvent;
048: import java.beans.PropertyChangeListener;
049: import java.util.*;
050: import java.awt.event.*;
051: import javax.swing.*;
052: import javax.swing.border.LineBorder;
053: import javax.swing.table.*;
054:
055: import java.awt.Component;
056: import java.awt.event.*;
057: import java.awt.AWTEvent;
058: import java.lang.Boolean;
059: import javax.swing.table.*;
060: import javax.swing.event.*;
061: import java.util.EventObject;
062: import javax.swing.tree.*;
063: import java.io.Serializable;
064: import javax.swing.*;
065: import org.openide.util.NbBundle;
066:
067: /**
068: * Margin Data Table that holds the margin style info
069: * @author Winston Prakash
070: */
071: public class MarginDataTable extends JTable {
072: CssStyleData cssStyleData;
073: /**
074: * Holds value of property value.
075: */
076: private String value;
077:
078: MarginWidthField allMarginField;
079: PaddingWidthField allPaddingField;
080: MarginWidthField topMarginField;
081: PaddingWidthField topPaddingField;
082: MarginWidthField bottomMarginField;
083: PaddingWidthField leftPaddingField;
084: MarginWidthField rightMarginField;
085: PaddingWidthField rightPaddingField;
086: PaddingWidthField bottomPaddingField;
087: MarginWidthField leftMarginField;
088:
089: private MarginPropertyChangeListener marginPropertyChangeListener = new MarginPropertyChangeListener();
090: private PaddingPropertyChangeListener paddingPropertyChangeListener = new PaddingPropertyChangeListener();
091:
092: public MarginDataTable(CssStyleData cssStyleData) {
093: super (6, 3);
094: this .cssStyleData = cssStyleData;
095: setDefaultRenderer(JComponent.class,
096: new JComponentCellRenderer());
097: setDefaultEditor(JComponent.class, new JComponentCellEditor());
098: FontMetrics fontMetrics = getFontMetrics(getFont());
099: setRowHeight((fontMetrics.getHeight() + 10) > 25 ? (fontMetrics
100: .getHeight() + 10) : 25);
101: setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
102: setIntercellSpacing(new Dimension(5, 5));
103: //setShowGrid(false);
104: setTableHeader(null);
105: setBackground(new JPanel().getBackground());
106: initCells();
107: getColumnModel().getColumn(0).setPreferredWidth(30);
108: getColumnModel().getColumn(1).setPreferredWidth(150);
109: getColumnModel().getColumn(2).setPreferredWidth(150);
110: getAccessibleContext().setAccessibleName(
111: NbBundle.getMessage(MarginDataTable.class,
112: "MARGIN_STYLE_TABLE_ACCESS_NAME"));
113: getAccessibleContext().setAccessibleDescription(
114: NbBundle.getMessage(MarginDataTable.class,
115: "MARGIN_STYLE_TABLE_ACCESS_DESC"));
116: }
117:
118: public void initCells() {
119: JPanel colHeader1 = new JPanel();
120: //colHeader1.add(new JLabel(org.openide.util.NbBundle.getMessage(MarginDataTable.class, "MARGIN_SIDE")));
121: setValueAt(colHeader1, 0, 0);
122: JPanel colHeader2 = new JPanel();
123: colHeader2.add(new JLabel(org.openide.util.NbBundle.getMessage(
124: MarginDataTable.class, "MARGIN_ALL")));
125: setValueAt(colHeader2, 0, 1);
126: JPanel colHeader3 = new JPanel();
127: colHeader3.add(new JLabel(org.openide.util.NbBundle.getMessage(
128: MarginDataTable.class, "PADDING")));
129: setValueAt(colHeader3, 0, 2);
130:
131: JPanel rowHeader1 = new JPanel();
132: rowHeader1.add(new JLabel(org.openide.util.NbBundle.getMessage(
133: MarginDataTable.class, "MARGIN_PADDING_ALL")));
134: setValueAt(rowHeader1, 1, 0);
135: JPanel rowHeader2 = new JPanel();
136: rowHeader2.add(new JLabel(org.openide.util.NbBundle.getMessage(
137: MarginDataTable.class, "MARGIN_PADDING_TOP")));
138: setValueAt(rowHeader2, 2, 0);
139: JPanel rowHeader3 = new JPanel();
140: rowHeader3.add(new JLabel(org.openide.util.NbBundle.getMessage(
141: MarginDataTable.class, "MARGIN_PADDING_BOTTOM")));
142: setValueAt(rowHeader3, 3, 0);
143: JPanel rowHeader4 = new JPanel();
144: rowHeader4.add(new JLabel(org.openide.util.NbBundle.getMessage(
145: MarginDataTable.class, "MARGIN_PADDING_LEFT")));
146: setValueAt(rowHeader4, 4, 0);
147: JPanel rowHeader5 = new JPanel();
148: rowHeader5.add(new JLabel(org.openide.util.NbBundle.getMessage(
149: MarginDataTable.class, "MARGIN_PADDING_RIGHT")));
150: setValueAt(rowHeader5, 5, 0);
151:
152: // All Side Margin
153: allMarginField = new MarginWidthField();
154: allMarginField.setAccessibleName(NbBundle.getMessage(
155: MarginDataTable.class,
156: "ALL_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
157: .getMessage(MarginDataTable.class,
158: "ALL_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
159: allMarginField.setAccessibleDescription(NbBundle.getMessage(
160: MarginDataTable.class,
161: "ALL_SIDE_MARGIN_WIDTH_ACCESS_DESC"), NbBundle
162: .getMessage(MarginDataTable.class,
163: "ALL_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
164: allMarginField
165: .addCssPropertyChangeListener(marginPropertyChangeListener);
166: setValueAt(allMarginField, 1, 1);
167:
168: // All Side Margin
169: allPaddingField = new PaddingWidthField();
170: allPaddingField.setAccessibleName(NbBundle.getMessage(
171: MarginDataTable.class,
172: "ALL_SIDE_PADDING_WIDTH_ACCESS_NAME"), NbBundle
173: .getMessage(MarginDataTable.class,
174: "ALL_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
175: allPaddingField.setAccessibleDescription(NbBundle.getMessage(
176: MarginDataTable.class,
177: "ALL_SIDE_PADDING_WIDTH_ACCESS_DESC"), NbBundle
178: .getMessage(MarginDataTable.class,
179: "ALL_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
180: allPaddingField
181: .addCssPropertyChangeListener(paddingPropertyChangeListener);
182: setValueAt(allPaddingField, 1, 2);
183:
184: // Top Side Margin
185: topMarginField = new MarginWidthField();
186: topMarginField.setAccessibleName(NbBundle.getMessage(
187: MarginDataTable.class,
188: "TOP_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
189: .getMessage(MarginDataTable.class,
190: "TOP_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
191: topMarginField.setAccessibleDescription(NbBundle.getMessage(
192: MarginDataTable.class,
193: "TOP_SIDE_MARGIN_WIDTH_ACCESS_DESC"), NbBundle
194: .getMessage(MarginDataTable.class,
195: "TOP_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
196: topMarginField.setMarginString(cssStyleData
197: .getProperty(CssStyleData.MARGIN_TOP));
198: topMarginField
199: .addCssPropertyChangeListener(marginPropertyChangeListener);
200: setValueAt(topMarginField, 2, 1);
201:
202: // Top Side Margin
203: topPaddingField = new PaddingWidthField();
204: topPaddingField.setAccessibleName(NbBundle.getMessage(
205: MarginDataTable.class,
206: "TOP_SIDE_PADDING_WIDTH_ACCESS_NAME"), NbBundle
207: .getMessage(MarginDataTable.class,
208: "TOP_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
209: topPaddingField.setAccessibleDescription(NbBundle.getMessage(
210: MarginDataTable.class,
211: "TOP_SIDE_PADDING_WIDTH_ACCESS_DESC"), NbBundle
212: .getMessage(MarginDataTable.class,
213: "TOP_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
214: topPaddingField.setPaddingString(cssStyleData
215: .getProperty(CssStyleData.PADDING_TOP));
216: topPaddingField
217: .addCssPropertyChangeListener(paddingPropertyChangeListener);
218: setValueAt(topPaddingField, 2, 2);
219:
220: // Bottom Side Margin
221: bottomMarginField = new MarginWidthField();
222: bottomMarginField.setAccessibleName(NbBundle.getMessage(
223: MarginDataTable.class,
224: "BOTTOM_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
225: .getMessage(MarginDataTable.class,
226: "BOTTOM_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
227: bottomMarginField.setAccessibleDescription(NbBundle.getMessage(
228: MarginDataTable.class,
229: "BOTTOM_SIDE_MARGIN_WIDTH_ACCESS_DESC"), NbBundle
230: .getMessage(MarginDataTable.class,
231: "BOTTOM_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
232: bottomMarginField.setMarginString(cssStyleData
233: .getProperty(CssStyleData.MARGIN_BOTTOM));
234: bottomMarginField
235: .addCssPropertyChangeListener(marginPropertyChangeListener);
236: setValueAt(bottomMarginField, 3, 1);
237:
238: // Bottom Side Margin
239: bottomPaddingField = new PaddingWidthField();
240: bottomPaddingField.setAccessibleName(NbBundle.getMessage(
241: MarginDataTable.class,
242: "BOTTOM_SIDE_PADDING_WIDTH_ACCESS_NAME"), NbBundle
243: .getMessage(MarginDataTable.class,
244: "BOTTOM_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
245: bottomPaddingField.setAccessibleDescription(NbBundle
246: .getMessage(MarginDataTable.class,
247: "BOTTOM_SIDE_PADDING_WIDTH_ACCESS_DESC"),
248: NbBundle.getMessage(MarginDataTable.class,
249: "BOTTOM_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
250: bottomPaddingField.setPaddingString(cssStyleData
251: .getProperty(CssStyleData.PADDING_BOTTOM));
252: bottomPaddingField
253: .addCssPropertyChangeListener(paddingPropertyChangeListener);
254: setValueAt(bottomPaddingField, 3, 2);
255:
256: // Left Side Margin
257: leftMarginField = new MarginWidthField();
258: leftMarginField.setAccessibleName(NbBundle.getMessage(
259: MarginDataTable.class,
260: "LEFT_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
261: .getMessage(MarginDataTable.class,
262: "LEFT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
263: leftMarginField.setAccessibleDescription(NbBundle.getMessage(
264: MarginDataTable.class,
265: "LEFT_SIDE_MARGIN_WIDTH_ACCESS_DESC"), NbBundle
266: .getMessage(MarginDataTable.class,
267: "LEFT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
268: leftMarginField.setMarginString(cssStyleData
269: .getProperty(CssStyleData.MARGIN_LEFT));
270: leftMarginField
271: .addCssPropertyChangeListener(marginPropertyChangeListener);
272: setValueAt(leftMarginField, 4, 1);
273:
274: // Left Side Margin
275: leftPaddingField = new PaddingWidthField();
276: leftPaddingField.setAccessibleName(NbBundle.getMessage(
277: MarginDataTable.class,
278: "LEFT_SIDE_PADDING_WIDTH_ACCESS_NAME"), NbBundle
279: .getMessage(MarginDataTable.class,
280: "LEFT_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
281: leftPaddingField.setAccessibleDescription(NbBundle.getMessage(
282: MarginDataTable.class,
283: "LEFT_SIDE_PADDING_WIDTH_ACCESS_DESC"), NbBundle
284: .getMessage(MarginDataTable.class,
285: "LEFT_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
286: leftPaddingField.setPaddingString(cssStyleData
287: .getProperty(CssStyleData.PADDING_LEFT));
288: leftPaddingField
289: .addCssPropertyChangeListener(paddingPropertyChangeListener);
290: setValueAt(leftPaddingField, 4, 2);
291:
292: // Left Side Margin
293: rightMarginField = new MarginWidthField();
294: rightMarginField.setAccessibleName(NbBundle.getMessage(
295: MarginDataTable.class,
296: "RIGHT_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
297: .getMessage(MarginDataTable.class,
298: "RIGHT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
299: rightMarginField.setAccessibleDescription(NbBundle.getMessage(
300: MarginDataTable.class,
301: "RIGHT_SIDE_MARGIN_WIDTH_ACCESS_DESC"), NbBundle
302: .getMessage(MarginDataTable.class,
303: "RIGHT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
304: rightMarginField.setMarginString(cssStyleData
305: .getProperty(CssStyleData.MARGIN_RIGHT));
306: rightMarginField
307: .addCssPropertyChangeListener(marginPropertyChangeListener);
308: setValueAt(rightMarginField, 5, 1);
309:
310: // Left Side Margin
311: rightPaddingField = new PaddingWidthField();
312: rightPaddingField.setAccessibleName(NbBundle.getMessage(
313: MarginDataTable.class,
314: "RIGHT_SIDE_PADDING_WIDTH_ACCESS_NAME"), NbBundle
315: .getMessage(MarginDataTable.class,
316: "RIGHT_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
317: rightPaddingField.setAccessibleDescription(NbBundle.getMessage(
318: MarginDataTable.class,
319: "RIGHT_SIDE_PADDING_WIDTH_ACCESS_DESC"), NbBundle
320: .getMessage(MarginDataTable.class,
321: "RIGHT_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
322: rightPaddingField.setPaddingString(cssStyleData
323: .getProperty(CssStyleData.PADDING_RIGHT));
324: rightPaddingField
325: .addCssPropertyChangeListener(paddingPropertyChangeListener);
326: setValueAt(rightPaddingField, 5, 2);
327: }
328:
329: private void checkMarginAll() {
330: allMarginField
331: .removeCssPropertyChangeListener(marginPropertyChangeListener);
332: String topMargin = cssStyleData
333: .getProperty(CssStyleData.MARGIN_TOP);
334: String bottomMargin = cssStyleData
335: .getProperty(CssStyleData.MARGIN_BOTTOM);
336: String leftMargin = cssStyleData
337: .getProperty(CssStyleData.MARGIN_LEFT);
338: String rightMargin = cssStyleData
339: .getProperty(CssStyleData.MARGIN_RIGHT);
340:
341: if ((topMargin != null) && (bottomMargin != null)
342: && (leftMargin != null) && (rightMargin != null)
343: && (topMargin.equals(bottomMargin))
344: && (topMargin.equals(leftMargin))
345: && (topMargin.equals(rightMargin))) {
346: allMarginField.setMarginString(topMargin);
347: } else {
348: allMarginField.setMarginString(null);
349: }
350: allMarginField
351: .addCssPropertyChangeListener(marginPropertyChangeListener);
352: }
353:
354: private void checkPaddingAll() {
355: allPaddingField
356: .removeCssPropertyChangeListener(paddingPropertyChangeListener);
357: String topPadding = cssStyleData
358: .getProperty(CssStyleData.PADDING_TOP);
359: String bottomPadding = cssStyleData
360: .getProperty(CssStyleData.PADDING_BOTTOM);
361: String leftPadding = cssStyleData
362: .getProperty(CssStyleData.PADDING_LEFT);
363: String rightPadding = cssStyleData
364: .getProperty(CssStyleData.PADDING_RIGHT);
365:
366: if ((topPadding != null) && (bottomPadding != null)
367: && (leftPadding != null) && (rightPadding != null)
368: && (topPadding.equals(bottomPadding))
369: && (topPadding.equals(leftPadding))
370: && (topPadding.equals(rightPadding))) {
371: allPaddingField.setPaddingString(topPadding);
372: } else {
373: allPaddingField.setPaddingString(null);
374: }
375:
376: allPaddingField
377: .addCssPropertyChangeListener(paddingPropertyChangeListener);
378: }
379:
380: private class MarginPropertyChangeListener implements
381: PropertyChangeListener {
382: public void propertyChange(PropertyChangeEvent evt) {
383: if (evt.getSource() == allMarginField) {
384:
385: topMarginField
386: .removeCssPropertyChangeListener(marginPropertyChangeListener);
387: bottomMarginField
388: .removeCssPropertyChangeListener(marginPropertyChangeListener);
389: leftMarginField
390: .removeCssPropertyChangeListener(marginPropertyChangeListener);
391: rightMarginField
392: .removeCssPropertyChangeListener(marginPropertyChangeListener);
393:
394: cssStyleData.modifyProperty(CssStyleData.MARGIN_TOP,
395: evt.getNewValue().toString());
396: topMarginField.setMarginString(evt.getNewValue()
397: .toString());
398:
399: cssStyleData.modifyProperty(CssStyleData.MARGIN_BOTTOM,
400: evt.getNewValue().toString());
401: bottomMarginField.setMarginString(evt.getNewValue()
402: .toString());
403:
404: cssStyleData.modifyProperty(CssStyleData.MARGIN_LEFT,
405: evt.getNewValue().toString());
406: leftMarginField.setMarginString(evt.getNewValue()
407: .toString());
408:
409: cssStyleData.modifyProperty(CssStyleData.MARGIN_RIGHT,
410: evt.getNewValue().toString());
411: rightMarginField.setMarginString(evt.getNewValue()
412: .toString());
413:
414: topMarginField
415: .addCssPropertyChangeListener(marginPropertyChangeListener);
416: bottomMarginField
417: .addCssPropertyChangeListener(marginPropertyChangeListener);
418: leftMarginField
419: .addCssPropertyChangeListener(marginPropertyChangeListener);
420: rightMarginField
421: .addCssPropertyChangeListener(marginPropertyChangeListener);
422: } else if (evt.getSource() == topMarginField) {
423: cssStyleData.modifyProperty(CssStyleData.MARGIN_TOP,
424: evt.getNewValue().toString());
425: checkMarginAll();
426: } else if (evt.getSource() == bottomMarginField) {
427: cssStyleData.modifyProperty(CssStyleData.MARGIN_BOTTOM,
428: evt.getNewValue().toString());
429: checkMarginAll();
430: }
431: if (evt.getSource() == leftMarginField) {
432: cssStyleData.modifyProperty(CssStyleData.MARGIN_LEFT,
433: evt.getNewValue().toString());
434: checkMarginAll();
435: }
436: if (evt.getSource() == rightMarginField) {
437: cssStyleData.modifyProperty(CssStyleData.MARGIN_RIGHT,
438: evt.getNewValue().toString());
439: checkMarginAll();
440: }
441: }
442: }
443:
444: private class PaddingPropertyChangeListener implements
445: PropertyChangeListener {
446: public void propertyChange(PropertyChangeEvent evt) {
447: if (evt.getSource() == allPaddingField) {
448: topPaddingField
449: .removeCssPropertyChangeListener(paddingPropertyChangeListener);
450: bottomPaddingField
451: .removeCssPropertyChangeListener(paddingPropertyChangeListener);
452: leftPaddingField
453: .removeCssPropertyChangeListener(paddingPropertyChangeListener);
454: rightPaddingField
455: .removeCssPropertyChangeListener(paddingPropertyChangeListener);
456:
457: cssStyleData.modifyProperty(CssStyleData.PADDING_TOP,
458: evt.getNewValue().toString());
459: topPaddingField.setPaddingString(evt.getNewValue()
460: .toString());
461:
462: cssStyleData.modifyProperty(
463: CssStyleData.PADDING_BOTTOM, evt.getNewValue()
464: .toString());
465: bottomPaddingField.setPaddingString(evt.getNewValue()
466: .toString());
467:
468: cssStyleData.modifyProperty(CssStyleData.PADDING_LEFT,
469: evt.getNewValue().toString());
470: leftPaddingField.setPaddingString(evt.getNewValue()
471: .toString());
472:
473: cssStyleData.modifyProperty(CssStyleData.PADDING_RIGHT,
474: evt.getNewValue().toString());
475: rightPaddingField.setPaddingString(evt.getNewValue()
476: .toString());
477:
478: topPaddingField
479: .addCssPropertyChangeListener(paddingPropertyChangeListener);
480: bottomPaddingField
481: .addCssPropertyChangeListener(paddingPropertyChangeListener);
482: leftPaddingField
483: .addCssPropertyChangeListener(paddingPropertyChangeListener);
484: rightPaddingField
485: .addCssPropertyChangeListener(paddingPropertyChangeListener);
486: } else if (evt.getSource() == topPaddingField) {
487: cssStyleData.modifyProperty(CssStyleData.PADDING_TOP,
488: evt.getNewValue().toString());
489: checkPaddingAll();
490: } else if (evt.getSource() == bottomPaddingField) {
491: cssStyleData.modifyProperty(
492: CssStyleData.PADDING_BOTTOM, evt.getNewValue()
493: .toString());
494: checkPaddingAll();
495: } else if (evt.getSource() == leftPaddingField) {
496: cssStyleData.modifyProperty(CssStyleData.PADDING_LEFT,
497: evt.getNewValue().toString());
498: checkPaddingAll();
499: } else if (evt.getSource() == rightPaddingField) {
500: cssStyleData.modifyProperty(CssStyleData.PADDING_RIGHT,
501: evt.getNewValue().toString());
502: checkPaddingAll();
503: }
504: }
505: }
506:
507: class PropertyChangeListenerImpl implements PropertyChangeListener {
508: public void propertyChange(PropertyChangeEvent evt) {
509: }
510: }
511:
512: public TableCellRenderer getCellRenderer(int row, int column) {
513: TableColumn tableColumn = getColumnModel().getColumn(column);
514: TableCellRenderer renderer = tableColumn.getCellRenderer();
515: if (renderer == null) {
516: Class c = getColumnClass(column);
517: if (c.equals(Object.class)) {
518: Object o = getValueAt(row, column);
519: if (o != null)
520: c = getValueAt(row, column).getClass();
521: }
522: renderer = getDefaultRenderer(c);
523: }
524: return renderer;
525: }
526:
527: public TableCellEditor getCellEditor(int row, int column) {
528: TableColumn tableColumn = getColumnModel().getColumn(column);
529: TableCellEditor editor = tableColumn.getCellEditor();
530: if (editor == null) {
531: Class c = getColumnClass(column);
532: if (c.equals(Object.class)) {
533: Object o = getValueAt(row, column);
534: if (o != null)
535: c = getValueAt(row, column).getClass();
536: }
537: editor = getDefaultEditor(c);
538: }
539: return editor;
540: }
541:
542: class JComponentCellRenderer implements TableCellRenderer {
543: public Component getTableCellRendererComponent(JTable table,
544: Object value, boolean isSelected, boolean hasFocus,
545: int row, int column) {
546: JComponent comp = (JComponent) value;
547: comp.setMinimumSize(new Dimension(100, 25));
548: return comp;
549: }
550: }
551:
552: class JComponentCellEditor implements TableCellEditor,
553: TreeCellEditor, Serializable {
554:
555: protected EventListenerList listenerList = new EventListenerList();
556: transient protected ChangeEvent changeEvent = null;
557:
558: protected JComponent editorComponent = null;
559: protected JComponent container = null; // Can be tree or table
560:
561: public Component getComponent() {
562: return editorComponent;
563: }
564:
565: public Object getCellEditorValue() {
566: return editorComponent;
567: }
568:
569: public boolean isCellEditable(EventObject anEvent) {
570: return true;
571: }
572:
573: public boolean shouldSelectCell(EventObject anEvent) {
574: if (editorComponent != null
575: && anEvent instanceof MouseEvent
576: && ((MouseEvent) anEvent).getID() == MouseEvent.MOUSE_PRESSED) {
577: Component dispatchComponent = SwingUtilities
578: .getDeepestComponentAt(editorComponent, 3, 3);
579: MouseEvent e = (MouseEvent) anEvent;
580: MouseEvent e2 = new MouseEvent(dispatchComponent,
581: MouseEvent.MOUSE_RELEASED,
582: e.getWhen() + 100000, e.getModifiers(), 3, 3, e
583: .getClickCount(), e.isPopupTrigger());
584: dispatchComponent.dispatchEvent(e2);
585: e2 = new MouseEvent(dispatchComponent,
586: MouseEvent.MOUSE_CLICKED, e.getWhen() + 100001,
587: e.getModifiers(), 3, 3, 1, e.isPopupTrigger());
588: dispatchComponent.dispatchEvent(e2);
589: }
590: return false;
591: }
592:
593: public boolean stopCellEditing() {
594: fireEditingStopped();
595: return true;
596: }
597:
598: public void cancelCellEditing() {
599: fireEditingCanceled();
600: }
601:
602: public void addCellEditorListener(CellEditorListener l) {
603: listenerList.add(CellEditorListener.class, l);
604: }
605:
606: public void removeCellEditorListener(CellEditorListener l) {
607: listenerList.remove(CellEditorListener.class, l);
608: }
609:
610: protected void fireEditingStopped() {
611: Object[] listeners = listenerList.getListenerList();
612: // Process the listeners last to first, notifying
613: // those that are interested in this event
614: for (int i = listeners.length - 2; i >= 0; i -= 2) {
615: if (listeners[i] == CellEditorListener.class) {
616: // Lazily create the event:
617: if (changeEvent == null)
618: changeEvent = new ChangeEvent(this );
619: ((CellEditorListener) listeners[i + 1])
620: .editingStopped(changeEvent);
621: }
622: }
623: }
624:
625: protected void fireEditingCanceled() {
626: // Guaranteed to return a non-null array
627: Object[] listeners = listenerList.getListenerList();
628: // Process the listeners last to first, notifying
629: // those that are interested in this event
630: for (int i = listeners.length - 2; i >= 0; i -= 2) {
631: if (listeners[i] == CellEditorListener.class) {
632: // Lazily create the event:
633: if (changeEvent == null)
634: changeEvent = new ChangeEvent(this );
635: ((CellEditorListener) listeners[i + 1])
636: .editingCanceled(changeEvent);
637: }
638: }
639: }
640:
641: // implements javax.swing.tree.TreeCellEditor
642: public Component getTreeCellEditorComponent(JTree tree,
643: Object value, boolean isSelected, boolean expanded,
644: boolean leaf, int row) {
645: String stringValue = tree.convertValueToText(value,
646: isSelected, expanded, leaf, row, false);
647:
648: editorComponent = (JComponent) value;
649: container = tree;
650: return editorComponent;
651: }
652:
653: // implements javax.swing.table.TableCellEditor
654: public Component getTableCellEditorComponent(JTable table,
655: Object value, boolean isSelected, int row, int column) {
656:
657: editorComponent = (JComponent) value;
658: container = table;
659: return editorComponent;
660: }
661:
662: } // End of class JComponentCellEditor
663:
664: }
|