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.BorderModel;
045: import org.netbeans.modules.visualweb.propertyeditors.css.model.CssStyleData;
046: import java.awt.*;
047: import java.awt.Dimension;
048: import java.beans.PropertyChangeEvent;
049: import java.beans.PropertyChangeListener;
050: import java.util.*;
051: import java.awt.event.*;
052: import javax.swing.*;
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: * Border Data Table that holds the border style info
069: * @author Winston Prakash
070: */
071: public class BorderDataTable extends JTable {
072: CssStyleData cssStyleData;
073: /**
074: * Holds value of property value.
075: */
076: private String value;
077:
078: JComboBox allStyleCombo;
079: BorderWidthField allWidthField;
080: ColorSelectionField allColorField;
081:
082: JComboBox topStyleCombo;
083: BorderWidthField topWidthField;
084: ColorSelectionField topColorField;
085:
086: JComboBox bottomStyleCombo;
087: BorderWidthField bottomWidthField;
088: ColorSelectionField bottomColorField;
089:
090: JComboBox leftStyleCombo;
091: BorderWidthField leftWidthField;
092: ColorSelectionField leftColorField;
093:
094: JComboBox rightStyleCombo;
095: BorderWidthField rightWidthField;
096: ColorSelectionField rightColorField;
097:
098: private StyleItemListener styleItemListener = new StyleItemListener();
099: private WidthPropertyChangeListener widthPropertyChangeListener = new WidthPropertyChangeListener();
100: private ColorPropertyChangeListener colorPropertyChangeListener = new ColorPropertyChangeListener();
101:
102: public BorderDataTable(CssStyleData cssStyleData) {
103: super (6, 4);
104: this .cssStyleData = cssStyleData;
105: setDefaultRenderer(JComponent.class,
106: new JComponentCellRenderer());
107: setDefaultEditor(JComponent.class, new JComponentCellEditor());
108: FontMetrics fontMetrics = getFontMetrics(getFont());
109: setRowHeight((fontMetrics.getHeight() + 10) > 25 ? (fontMetrics
110: .getHeight() + 10) : 25);
111: setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
112: setIntercellSpacing(new Dimension(5, 5));
113: setTableHeader(null);
114: setBackground(new JPanel().getBackground());
115: initCells();
116: getColumnModel().getColumn(0).setPreferredWidth(50);
117: getColumnModel().getColumn(1).setPreferredWidth(75);
118: getColumnModel().getColumn(2).setPreferredWidth(125);
119: getColumnModel().getColumn(3).setPreferredWidth(125);
120: getAccessibleContext().setAccessibleName(
121: NbBundle.getMessage(BorderDataTable.class,
122: "BORDER_STYLE_TABLE_ACCESS_NAME"));
123: getAccessibleContext().setAccessibleDescription(
124: NbBundle.getMessage(BorderDataTable.class,
125: "BORDER_STYLE_TABLE_ACCESS_DESC"));
126: }
127:
128: public void initCells() {
129: JPanel colHeader1 = new JPanel();
130: //colHeader1.add(new JLabel(NbBundle.getMessage(BorderDataTable.class, "BORDER_SIDE")));
131: setValueAt(colHeader1, 0, 0);
132: JPanel colHeader2 = new JPanel();
133: colHeader2.add(new JLabel(NbBundle.getMessage(
134: BorderDataTable.class, "BORDER_STYLE")));
135: setValueAt(colHeader2, 0, 1);
136: JPanel colHeader3 = new JPanel();
137: colHeader3.add(new JLabel(NbBundle.getMessage(
138: BorderDataTable.class, "BORDER_WIDTH")));
139: setValueAt(colHeader3, 0, 2);
140: JPanel colHeader6 = new JPanel();
141: colHeader6.add(new JLabel(NbBundle.getMessage(
142: BorderDataTable.class, "BORDER_COLOR")));
143: setValueAt(colHeader6, 0, 3);
144:
145: JPanel rowHeader1 = new JPanel();
146: rowHeader1.add(new JLabel(NbBundle.getMessage(
147: BorderDataTable.class, "BORDER_ALL")));
148: setValueAt(rowHeader1, 1, 0);
149: JPanel rowHeader2 = new JPanel();
150: rowHeader2.add(new JLabel(NbBundle.getMessage(
151: BorderDataTable.class, "BORDER_TOP")));
152: setValueAt(rowHeader2, 2, 0);
153: JPanel rowHeader3 = new JPanel();
154: rowHeader3.add(new JLabel(NbBundle.getMessage(
155: BorderDataTable.class, "BORDER_BOTTOM")));
156: setValueAt(rowHeader3, 3, 0);
157: JPanel rowHeader4 = new JPanel();
158: rowHeader4.add(new JLabel(NbBundle.getMessage(
159: BorderDataTable.class, "BORDER_LEFT")));
160: setValueAt(rowHeader4, 4, 0);
161: JPanel rowHeader5 = new JPanel();
162: rowHeader5.add(new JLabel(NbBundle.getMessage(
163: BorderDataTable.class, "BORDER_RIGHT")));
164: setValueAt(rowHeader5, 5, 0);
165:
166: BorderModel borderModel = new BorderModel();
167:
168: // All Side Style
169: allStyleCombo = new JComboBox();
170: allStyleCombo.getAccessibleContext().setAccessibleName(
171: NbBundle.getMessage(BorderDataTable.class,
172: "ALL_SIDE_BORDER_STYLE_ACCESS_NAME"));
173: allStyleCombo.getAccessibleContext().setAccessibleDescription(
174: NbBundle.getMessage(BorderDataTable.class,
175: "ALL_SIDE_BORDER_STYLE_ACCESS_DESC"));
176: allStyleCombo.setModel(borderModel.getStyleList());
177: allStyleCombo.addItemListener(styleItemListener);
178: setValueAt(allStyleCombo, 1, 1);
179:
180: // All Side Width
181: allWidthField = new BorderWidthField();
182: allWidthField.setAccessibleName(NbBundle.getMessage(
183: BorderDataTable.class,
184: "ALL_SIDE_BORDER_WIDTH_ACCESS_NAME"), NbBundle
185: .getMessage(BorderDataTable.class,
186: "ALL_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME"));
187: allWidthField.setAccessibleDescription(NbBundle.getMessage(
188: BorderDataTable.class,
189: "ALL_SIDE_BORDER_WIDTH_ACCESS_DESC"), NbBundle
190: .getMessage(BorderDataTable.class,
191: "ALL_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC"));
192: allWidthField
193: .addCssPropertyChangeListener(widthPropertyChangeListener);
194: setValueAt(allWidthField, 1, 2);
195:
196: // All Side Width
197: allColorField = new ColorSelectionField();
198: allColorField
199: .addCssPropertyChangeListener(colorPropertyChangeListener);
200: setValueAt(allColorField, 1, 3);
201:
202: // Set the value for the top side border
203:
204: // Top Side Style
205: topStyleCombo = new JComboBox();
206: topStyleCombo.getAccessibleContext().setAccessibleName(
207: NbBundle.getMessage(BorderDataTable.class,
208: "TOP_SIDE_BORDER_STYLE_ACCESS_NAME"));
209: topStyleCombo.getAccessibleContext().setAccessibleDescription(
210: NbBundle.getMessage(BorderDataTable.class,
211: "TOP_SIDE_BORDER_STYLE_ACCESS_DESC"));
212: topStyleCombo.setModel(borderModel.getStyleList());
213: if (cssStyleData.getProperty(CssStyleData.BORDER_TOP_STYLE) != null) {
214: topStyleCombo.setSelectedItem(cssStyleData
215: .getProperty(CssStyleData.BORDER_TOP_STYLE));
216: }
217: topStyleCombo.addItemListener(styleItemListener);
218: setValueAt(topStyleCombo, 2, 1);
219:
220: // Top Side Width
221: topWidthField = new BorderWidthField();
222: topWidthField.setAccessibleName(NbBundle.getMessage(
223: BorderDataTable.class,
224: "TOP_SIDE_BORDER_WIDTH_ACCESS_NAME"), NbBundle
225: .getMessage(BorderDataTable.class,
226: "TOP_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME"));
227: topWidthField.setAccessibleDescription(NbBundle.getMessage(
228: BorderDataTable.class,
229: "TOP_SIDE_BORDER_WIDTH_ACCESS_DESC"), NbBundle
230: .getMessage(BorderDataTable.class,
231: "TOP_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC"));
232: topWidthField.setWidthString(cssStyleData
233: .getProperty(CssStyleData.BORDER_TOP_WIDTH));
234: topWidthField
235: .addCssPropertyChangeListener(widthPropertyChangeListener);
236: setValueAt(topWidthField, 2, 2);
237:
238: // Top Side Color
239: topColorField = new ColorSelectionField();
240: topColorField.setColorString(cssStyleData
241: .getProperty(CssStyleData.BORDER_TOP_COLOR));
242: topColorField
243: .addCssPropertyChangeListener(colorPropertyChangeListener);
244: setValueAt(topColorField, 2, 3);
245:
246: // Set the Bottom Side data
247:
248: // Bottom Side Style
249: bottomStyleCombo = new JComboBox();
250: bottomStyleCombo.getAccessibleContext().setAccessibleName(
251: NbBundle.getMessage(BorderDataTable.class,
252: "BOTTOM_SIDE_BORDER_STYLE_ACCESS_NAME"));
253: bottomStyleCombo
254: .getAccessibleContext()
255: .setAccessibleDescription(
256: NbBundle.getMessage(BorderDataTable.class,
257: "BOTTOM_SIDE_BORDER_STYLE_ACCESS_DESC"));
258: bottomStyleCombo.setModel(borderModel.getStyleList());
259: if (cssStyleData.getProperty(CssStyleData.BORDER_BOTTOM_STYLE) != null) {
260: bottomStyleCombo.setSelectedItem(cssStyleData
261: .getProperty(CssStyleData.BORDER_BOTTOM_STYLE));
262: }
263: bottomStyleCombo.addItemListener(styleItemListener);
264: setValueAt(bottomStyleCombo, 3, 1);
265:
266: // Bottom Side Width
267: bottomWidthField = new BorderWidthField();
268: bottomWidthField.setAccessibleName(NbBundle.getMessage(
269: BorderDataTable.class,
270: "BOTTOM_SIDE_BORDER_WIDTH_ACCESS_NAME"), NbBundle
271: .getMessage(BorderDataTable.class,
272: "BOTTOM_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME"));
273: bottomWidthField.setAccessibleDescription(NbBundle.getMessage(
274: BorderDataTable.class,
275: "BOTTOM_SIDE_BORDER_WIDTH_ACCESS_DESC"), NbBundle
276: .getMessage(BorderDataTable.class,
277: "BOTTOM_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC"));
278: bottomWidthField.setWidthString(cssStyleData
279: .getProperty(CssStyleData.BORDER_BOTTOM_WIDTH));
280: bottomWidthField
281: .addCssPropertyChangeListener(widthPropertyChangeListener);
282: setValueAt(bottomWidthField, 3, 2);
283:
284: // Bottom Side Width
285: bottomColorField = new ColorSelectionField();
286: bottomColorField.setColorString(cssStyleData
287: .getProperty(CssStyleData.BORDER_BOTTOM_COLOR));
288: bottomColorField
289: .addCssPropertyChangeListener(colorPropertyChangeListener);
290: setValueAt(bottomColorField, 3, 3);
291:
292: // Set the Left Side data
293:
294: // Left Side Style
295: leftStyleCombo = new JComboBox(new String[] {});
296: leftStyleCombo.getAccessibleContext().setAccessibleName(
297: NbBundle.getMessage(BorderDataTable.class,
298: "LEFT_SIDE_BORDER_STYLE_ACCESS_NAME"));
299: leftStyleCombo.getAccessibleContext().setAccessibleDescription(
300: NbBundle.getMessage(BorderDataTable.class,
301: "LEFT_SIDE_BORDER_STYLE_ACCESS_DESC"));
302: leftStyleCombo.setModel(borderModel.getStyleList());
303: if (cssStyleData.getProperty(CssStyleData.BORDER_LEFT_STYLE) != null) {
304: leftStyleCombo.setSelectedItem(cssStyleData
305: .getProperty(CssStyleData.BORDER_LEFT_STYLE));
306: }
307: leftStyleCombo.addItemListener(styleItemListener);
308: setValueAt(leftStyleCombo, 4, 1);
309:
310: // Left Side Width
311: leftWidthField = new BorderWidthField();
312: leftWidthField.setAccessibleName(NbBundle.getMessage(
313: BorderDataTable.class,
314: "LEFT_SIDE_BORDER_WIDTH_ACCESS_NAME"), NbBundle
315: .getMessage(BorderDataTable.class,
316: "LEFT_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME"));
317: leftWidthField.setAccessibleDescription(NbBundle.getMessage(
318: BorderDataTable.class,
319: "LEFT_SIDE_BORDER_WIDTH_ACCESS_DESC"), NbBundle
320: .getMessage(BorderDataTable.class,
321: "LEFT_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC"));
322: leftWidthField.setWidthString(cssStyleData
323: .getProperty(CssStyleData.BORDER_LEFT_WIDTH));
324: leftWidthField
325: .addCssPropertyChangeListener(widthPropertyChangeListener);
326: setValueAt(leftWidthField, 4, 2);
327:
328: // Left Side Width
329: leftColorField = new ColorSelectionField();
330: leftColorField.setColorString(cssStyleData
331: .getProperty(CssStyleData.BORDER_LEFT_COLOR));
332: leftColorField
333: .addCssPropertyChangeListener(colorPropertyChangeListener);
334: setValueAt(leftColorField, 4, 3);
335:
336: // Set the Right Side data
337:
338: // Right Side Style
339: rightStyleCombo = new JComboBox();
340: rightStyleCombo.getAccessibleContext().setAccessibleName(
341: NbBundle.getMessage(BorderDataTable.class,
342: "RIGHT_SIDE_BORDER_STYLE_ACCESS_NAME"));
343: rightStyleCombo.getAccessibleContext()
344: .setAccessibleDescription(
345: NbBundle.getMessage(BorderDataTable.class,
346: "RIGHT_SIDE_BORDER_STYLE_ACCESS_DESC"));
347: rightStyleCombo.setModel(borderModel.getStyleList());
348: if (cssStyleData.getProperty(CssStyleData.BORDER_RIGHT_STYLE) != null) {
349: rightStyleCombo.setSelectedItem(cssStyleData
350: .getProperty(CssStyleData.BORDER_RIGHT_STYLE));
351: }
352: rightStyleCombo.addItemListener(styleItemListener);
353: setValueAt(rightStyleCombo, 5, 1);
354:
355: // Right Side Width
356: rightWidthField = new BorderWidthField();
357: rightWidthField.setAccessibleName(NbBundle.getMessage(
358: BorderDataTable.class,
359: "RIGHT_SIDE_BORDER_WIDTH_ACCESS_NAME"), NbBundle
360: .getMessage(BorderDataTable.class,
361: "RIGHT_SIDE_BORDER_WIDTH_UNIT_ACCESS_NAME"));
362: rightWidthField.setAccessibleDescription(NbBundle.getMessage(
363: BorderDataTable.class,
364: "RIGHT_SIDE_BORDER_WIDTH_ACCESS_DESC"), NbBundle
365: .getMessage(BorderDataTable.class,
366: "RIGHT_SIDE_BORDER_WIDTH_UNIT_ACCESS_DESC"));
367: rightWidthField.setWidthString(cssStyleData
368: .getProperty(CssStyleData.BORDER_RIGHT_WIDTH));
369: rightWidthField
370: .addCssPropertyChangeListener(widthPropertyChangeListener);
371: setValueAt(rightWidthField, 5, 2);
372:
373: // Right Side Color
374: rightColorField = new ColorSelectionField();
375: rightColorField.setColorString(cssStyleData
376: .getProperty(CssStyleData.BORDER_RIGHT_COLOR));
377: rightColorField
378: .addCssPropertyChangeListener(colorPropertyChangeListener);
379: setValueAt(rightColorField, 5, 3);
380:
381: checkBorderStyleAll();
382: checkBorderWidthAll();
383: checkBorderColorAll();
384: }
385:
386: private void checkBorderStyleAll() {
387: allStyleCombo.removeItemListener(styleItemListener);
388:
389: String topStyle = cssStyleData
390: .getProperty(CssStyleData.BORDER_TOP_STYLE);
391: String bottomStyle = cssStyleData
392: .getProperty(CssStyleData.BORDER_BOTTOM_STYLE);
393: String leftStyle = cssStyleData
394: .getProperty(CssStyleData.BORDER_LEFT_STYLE);
395: String rightStyle = cssStyleData
396: .getProperty(CssStyleData.BORDER_RIGHT_STYLE);
397:
398: if ((topStyle != null) && (bottomStyle != null)
399: && (leftStyle != null) && (rightStyle != null)
400: && (topStyle.equals(bottomStyle))
401: && (topStyle.equals(leftStyle))
402: && (topStyle.equals(rightStyle))) {
403: allStyleCombo.setSelectedItem(topStyle);
404: } else {
405: allStyleCombo.setSelectedIndex(0);
406: }
407: allStyleCombo.addItemListener(styleItemListener);
408: }
409:
410: private void checkBorderWidthAll() {
411: allWidthField
412: .removeCssPropertyChangeListener(widthPropertyChangeListener);
413:
414: String topWidth = cssStyleData
415: .getProperty(CssStyleData.BORDER_TOP_WIDTH);
416: String bottomWidth = cssStyleData
417: .getProperty(CssStyleData.BORDER_BOTTOM_WIDTH);
418: String leftWidth = cssStyleData
419: .getProperty(CssStyleData.BORDER_LEFT_WIDTH);
420: String rightWidth = cssStyleData
421: .getProperty(CssStyleData.BORDER_RIGHT_WIDTH);
422:
423: if ((topWidth != null) && (bottomWidth != null)
424: && (leftWidth != null) && (rightWidth != null)
425: && (topWidth.equals(bottomWidth))
426: && (topWidth.equals(leftWidth))
427: && (topWidth.equals(rightWidth))) {
428: allWidthField.setWidthString(topWidth);
429: } else {
430: allWidthField.setWidthString(null);
431: }
432: allWidthField
433: .addCssPropertyChangeListener(widthPropertyChangeListener);
434: }
435:
436: private void checkBorderColorAll() {
437: allColorField
438: .removeCssPropertyChangeListener(colorPropertyChangeListener);
439: String topColor = cssStyleData
440: .getProperty(CssStyleData.BORDER_TOP_COLOR);
441: String bottomColor = cssStyleData
442: .getProperty(CssStyleData.BORDER_BOTTOM_COLOR);
443: String leftColor = cssStyleData
444: .getProperty(CssStyleData.BORDER_LEFT_COLOR);
445: String rightColor = cssStyleData
446: .getProperty(CssStyleData.BORDER_RIGHT_COLOR);
447:
448: if ((topColor != null) && (bottomColor != null)
449: && (leftColor != null) && (rightColor != null)
450: && (topColor.equals(bottomColor))
451: && (topColor.equals(leftColor))
452: && (topColor.equals(rightColor))) {
453: allColorField.setColorString(topColor);
454: } else {
455: allColorField.setColorString(null);
456: }
457: allColorField
458: .addCssPropertyChangeListener(colorPropertyChangeListener);
459: }
460:
461: private class StyleItemListener implements ItemListener {
462: public void itemStateChanged(ItemEvent evt) {
463: if (evt.getSource() == allStyleCombo) {
464: topStyleCombo.removeItemListener(styleItemListener);
465: bottomStyleCombo.removeItemListener(styleItemListener);
466: leftStyleCombo.removeItemListener(styleItemListener);
467: rightStyleCombo.removeItemListener(styleItemListener);
468:
469: cssStyleData.modifyProperty(
470: CssStyleData.BORDER_TOP_STYLE, allStyleCombo
471: .getSelectedItem().toString());
472: topStyleCombo.setSelectedIndex(allStyleCombo
473: .getSelectedIndex());
474:
475: cssStyleData.modifyProperty(
476: CssStyleData.BORDER_BOTTOM_STYLE, allStyleCombo
477: .getSelectedItem().toString());
478: bottomStyleCombo.setSelectedIndex(allStyleCombo
479: .getSelectedIndex());
480:
481: cssStyleData.modifyProperty(
482: CssStyleData.BORDER_LEFT_STYLE, allStyleCombo
483: .getSelectedItem().toString());
484: leftStyleCombo.setSelectedIndex(allStyleCombo
485: .getSelectedIndex());
486:
487: cssStyleData.modifyProperty(
488: CssStyleData.BORDER_RIGHT_STYLE, allStyleCombo
489: .getSelectedItem().toString());
490: rightStyleCombo.setSelectedIndex(allStyleCombo
491: .getSelectedIndex());
492:
493: topStyleCombo.addItemListener(styleItemListener);
494: bottomStyleCombo.addItemListener(styleItemListener);
495: leftStyleCombo.addItemListener(styleItemListener);
496: rightStyleCombo.addItemListener(styleItemListener);
497: } else if (evt.getSource() == topStyleCombo) {
498: cssStyleData.modifyProperty(
499: CssStyleData.BORDER_TOP_STYLE, topStyleCombo
500: .getSelectedItem().toString());
501: checkBorderStyleAll();
502: } else if (evt.getSource() == bottomStyleCombo) {
503: cssStyleData.modifyProperty(
504: CssStyleData.BORDER_BOTTOM_STYLE,
505: bottomStyleCombo.getSelectedItem().toString());
506: checkBorderStyleAll();
507:
508: } else if (evt.getSource() == leftStyleCombo) {
509: cssStyleData.modifyProperty(
510: CssStyleData.BORDER_LEFT_STYLE, leftStyleCombo
511: .getSelectedItem().toString());
512: checkBorderStyleAll();
513:
514: } else if (evt.getSource() == rightStyleCombo) {
515: cssStyleData.modifyProperty(
516: CssStyleData.BORDER_RIGHT_STYLE,
517: rightStyleCombo.getSelectedItem().toString());
518: checkBorderStyleAll();
519:
520: }
521:
522: }
523: }
524:
525: private class WidthPropertyChangeListener implements
526: PropertyChangeListener {
527: public void propertyChange(PropertyChangeEvent evt) {
528: if (evt.getSource() == allWidthField) {
529: topWidthField
530: .removeCssPropertyChangeListener(widthPropertyChangeListener);
531: bottomWidthField
532: .removeCssPropertyChangeListener(widthPropertyChangeListener);
533: leftWidthField
534: .removeCssPropertyChangeListener(widthPropertyChangeListener);
535: rightWidthField
536: .removeCssPropertyChangeListener(widthPropertyChangeListener);
537:
538: cssStyleData.modifyProperty(
539: CssStyleData.BORDER_TOP_WIDTH, evt
540: .getNewValue().toString());
541: topWidthField.setWidthString(evt.getNewValue()
542: .toString());
543:
544: cssStyleData.modifyProperty(
545: CssStyleData.BORDER_BOTTOM_WIDTH, evt
546: .getNewValue().toString());
547: bottomWidthField.setWidthString(evt.getNewValue()
548: .toString());
549:
550: cssStyleData.modifyProperty(
551: CssStyleData.BORDER_LEFT_WIDTH, evt
552: .getNewValue().toString());
553: leftWidthField.setWidthString(evt.getNewValue()
554: .toString());
555:
556: cssStyleData.modifyProperty(
557: CssStyleData.BORDER_RIGHT_WIDTH, evt
558: .getNewValue().toString());
559: rightWidthField.setWidthString(evt.getNewValue()
560: .toString());
561:
562: topWidthField
563: .addCssPropertyChangeListener(widthPropertyChangeListener);
564: bottomWidthField
565: .addCssPropertyChangeListener(widthPropertyChangeListener);
566: leftWidthField
567: .addCssPropertyChangeListener(widthPropertyChangeListener);
568: rightWidthField
569: .addCssPropertyChangeListener(widthPropertyChangeListener);
570: } else if (evt.getSource() == topWidthField) {
571: cssStyleData.modifyProperty(
572: CssStyleData.BORDER_TOP_WIDTH, evt
573: .getNewValue().toString());
574: checkBorderWidthAll();
575: } else if (evt.getSource() == bottomWidthField) {
576: cssStyleData.modifyProperty(
577: CssStyleData.BORDER_BOTTOM_WIDTH, evt
578: .getNewValue().toString());
579: checkBorderWidthAll();
580: } else if (evt.getSource() == leftWidthField) {
581: cssStyleData.modifyProperty(
582: CssStyleData.BORDER_LEFT_WIDTH, evt
583: .getNewValue().toString());
584: checkBorderWidthAll();
585: } else if (evt.getSource() == rightWidthField) {
586: cssStyleData.modifyProperty(
587: CssStyleData.BORDER_RIGHT_WIDTH, evt
588: .getNewValue().toString());
589: checkBorderWidthAll();
590: }
591: }
592: }
593:
594: private class ColorPropertyChangeListener implements
595: PropertyChangeListener {
596: public void propertyChange(PropertyChangeEvent evt) {
597: if (evt.getSource() == allColorField) {
598: topColorField
599: .removeCssPropertyChangeListener(colorPropertyChangeListener);
600: bottomColorField
601: .removeCssPropertyChangeListener(colorPropertyChangeListener);
602: leftColorField
603: .removeCssPropertyChangeListener(colorPropertyChangeListener);
604: rightColorField
605: .removeCssPropertyChangeListener(colorPropertyChangeListener);
606:
607: topColorField.setColorString(allColorField
608: .getColorString());
609: cssStyleData.modifyProperty(
610: CssStyleData.BORDER_TOP_COLOR, allColorField
611: .getColorString());
612:
613: bottomColorField.setColorString(allColorField
614: .getColorString());
615: cssStyleData.modifyProperty(
616: CssStyleData.BORDER_BOTTOM_COLOR, allColorField
617: .getColorString());
618:
619: leftColorField.setColorString(allColorField
620: .getColorString());
621: cssStyleData.modifyProperty(
622: CssStyleData.BORDER_LEFT_COLOR, allColorField
623: .getColorString());
624:
625: rightColorField.setColorString(allColorField
626: .getColorString());
627: cssStyleData.modifyProperty(
628: CssStyleData.BORDER_RIGHT_COLOR, allColorField
629: .getColorString());
630:
631: topColorField
632: .addCssPropertyChangeListener(colorPropertyChangeListener);
633: bottomColorField
634: .addCssPropertyChangeListener(colorPropertyChangeListener);
635: leftColorField
636: .addCssPropertyChangeListener(colorPropertyChangeListener);
637: rightColorField
638: .addCssPropertyChangeListener(colorPropertyChangeListener);
639: }
640: if (evt.getSource() == topColorField) {
641: cssStyleData.modifyProperty(
642: CssStyleData.BORDER_TOP_COLOR, topColorField
643: .getColorString());
644: checkBorderColorAll();
645: }
646: if (evt.getSource() == bottomColorField) {
647: cssStyleData.modifyProperty(
648: CssStyleData.BORDER_BOTTOM_COLOR,
649: bottomColorField.getColorString());
650: checkBorderColorAll();
651: }
652: if (evt.getSource() == leftColorField) {
653: cssStyleData.modifyProperty(
654: CssStyleData.BORDER_LEFT_COLOR, leftColorField
655: .getColorString());
656: checkBorderColorAll();
657: }
658: if (evt.getSource() == rightColorField) {
659: cssStyleData.modifyProperty(
660: CssStyleData.BORDER_RIGHT_COLOR,
661: rightColorField.getColorString());
662: checkBorderColorAll();
663: }
664: }
665: }
666:
667: class PropertyChangeListenerImpl implements PropertyChangeListener {
668: public void propertyChange(PropertyChangeEvent evt) {
669: }
670: }
671:
672: public TableCellRenderer getCellRenderer(int row, int column) {
673: TableColumn tableColumn = getColumnModel().getColumn(column);
674: TableCellRenderer renderer = tableColumn.getCellRenderer();
675: if (renderer == null) {
676: Class c = getColumnClass(column);
677: if (c.equals(Object.class)) {
678: Object o = getValueAt(row, column);
679: if (o != null)
680: c = getValueAt(row, column).getClass();
681: }
682: renderer = getDefaultRenderer(c);
683: }
684: return renderer;
685: }
686:
687: public TableCellEditor getCellEditor(int row, int column) {
688: TableColumn tableColumn = getColumnModel().getColumn(column);
689: TableCellEditor editor = tableColumn.getCellEditor();
690: if (editor == null) {
691: Class c = getColumnClass(column);
692: if (c.equals(Object.class)) {
693: Object o = getValueAt(row, column);
694: if (o != null)
695: c = getValueAt(row, column).getClass();
696: }
697: editor = getDefaultEditor(c);
698: }
699: return editor;
700: }
701:
702: class JComponentCellRenderer implements TableCellRenderer {
703: public Component getTableCellRendererComponent(JTable table,
704: Object value, boolean isSelected, boolean hasFocus,
705: int row, int column) {
706: JComponent comp = (JComponent) value;
707: comp.setMinimumSize(new Dimension(100, 25));
708: return comp;
709: }
710: }
711:
712: class JComponentCellEditor implements TableCellEditor,
713: TreeCellEditor, Serializable {
714:
715: protected EventListenerList listenerList = new EventListenerList();
716: transient protected ChangeEvent changeEvent = null;
717:
718: protected JComponent editorComponent = null;
719: protected JComponent container = null; // Can be tree or table
720:
721: public Component getComponent() {
722: return editorComponent;
723: }
724:
725: public Object getCellEditorValue() {
726: return editorComponent;
727: }
728:
729: public boolean isCellEditable(EventObject anEvent) {
730: return true;
731: }
732:
733: public boolean shouldSelectCell(EventObject anEvent) {
734: if (editorComponent != null
735: && anEvent instanceof MouseEvent
736: && ((MouseEvent) anEvent).getID() == MouseEvent.MOUSE_PRESSED) {
737: Component dispatchComponent = SwingUtilities
738: .getDeepestComponentAt(editorComponent, 3, 3);
739: MouseEvent e = (MouseEvent) anEvent;
740: MouseEvent e2 = new MouseEvent(dispatchComponent,
741: MouseEvent.MOUSE_RELEASED,
742: e.getWhen() + 100000, e.getModifiers(), 3, 3, e
743: .getClickCount(), e.isPopupTrigger());
744: dispatchComponent.dispatchEvent(e2);
745: e2 = new MouseEvent(dispatchComponent,
746: MouseEvent.MOUSE_CLICKED, e.getWhen() + 100001,
747: e.getModifiers(), 3, 3, 1, e.isPopupTrigger());
748: dispatchComponent.dispatchEvent(e2);
749: }
750: return false;
751: }
752:
753: public boolean stopCellEditing() {
754: fireEditingStopped();
755: return true;
756: }
757:
758: public void cancelCellEditing() {
759: fireEditingCanceled();
760: }
761:
762: public void addCellEditorListener(CellEditorListener l) {
763: listenerList.add(CellEditorListener.class, l);
764: }
765:
766: public void removeCellEditorListener(CellEditorListener l) {
767: listenerList.remove(CellEditorListener.class, l);
768: }
769:
770: protected void fireEditingStopped() {
771: Object[] listeners = listenerList.getListenerList();
772: // Process the listeners last to first, notifying
773: // those that are interested in this event
774: for (int i = listeners.length - 2; i >= 0; i -= 2) {
775: if (listeners[i] == CellEditorListener.class) {
776: // Lazily create the event:
777: if (changeEvent == null)
778: changeEvent = new ChangeEvent(this );
779: ((CellEditorListener) listeners[i + 1])
780: .editingStopped(changeEvent);
781: }
782: }
783: }
784:
785: protected void fireEditingCanceled() {
786: // Guaranteed to return a non-null array
787: Object[] listeners = listenerList.getListenerList();
788: // Process the listeners last to first, notifying
789: // those that are interested in this event
790: for (int i = listeners.length - 2; i >= 0; i -= 2) {
791: if (listeners[i] == CellEditorListener.class) {
792: // Lazily create the event:
793: if (changeEvent == null)
794: changeEvent = new ChangeEvent(this );
795: ((CellEditorListener) listeners[i + 1])
796: .editingCanceled(changeEvent);
797: }
798: }
799: }
800:
801: // implements javax.swing.tree.TreeCellEditor
802: public Component getTreeCellEditorComponent(JTree tree,
803: Object value, boolean isSelected, boolean expanded,
804: boolean leaf, int row) {
805: String stringValue = tree.convertValueToText(value,
806: isSelected, expanded, leaf, row, false);
807:
808: editorComponent = (JComponent) value;
809: container = tree;
810: return editorComponent;
811: }
812:
813: // implements javax.swing.table.TableCellEditor
814: public Component getTableCellEditorComponent(JTable table,
815: Object value, boolean isSelected, int row, int column) {
816:
817: editorComponent = (JComponent) value;
818: container = table;
819: return editorComponent;
820: }
821:
822: } // End of class JComponentCellEditor
823:
824: }
|