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:
042: /*
043: * BorderStyleEditor.java
044: *
045: * Created on October 13, 2004, 12:23 PM
046: */
047:
048: package org.netbeans.modules.css.visual.ui;
049:
050: import org.netbeans.modules.css.visual.model.CssProperties;
051: import org.netbeans.modules.css.editor.model.CssRuleContent;
052: import java.awt.BorderLayout;
053: import java.awt.FontMetrics;
054: import org.netbeans.modules.css.editor.model.CssRuleContent;
055: import java.awt.Dimension;
056: import java.beans.PropertyChangeEvent;
057: import java.beans.PropertyChangeListener;
058: import java.awt.event.*;
059: import javax.swing.table.*;
060: import javax.swing.event.*;
061: import javax.swing.tree.*;
062: import javax.swing.*;
063: import org.openide.util.NbBundle;
064:
065: /**
066: * Margin Style editor.
067: * @author Winston Prakash
068: * @version 1.0
069: */
070: public class MarginStyleEditor extends StyleEditor {
071:
072: MarginDataTable marginDataTable = new MarginDataTable();
073:
074: /** Creates new form FontStyleEditor */
075: public MarginStyleEditor() {
076: setName("marginStyleEditor"); //NOI18N
077: setDisplayName(NbBundle.getMessage(MarginStyleEditor.class,
078: "MARGIN_EDITOR_DISPNAME"));
079: initComponents();
080: marginPanel.add(marginDataTable, BorderLayout.CENTER);
081: }
082:
083: /**
084: * Set the CSS Properties Values from the CssStyleData data structure
085: * to the GUI components.
086: */
087: protected void setCssPropertyValues(CssRuleContent cssStyleData) {
088: removeCssPropertyChangeListener();
089: marginDataTable.setCssPropertyValues(cssStyleData);
090: setCssPropertyChangeListener(cssStyleData);
091: marginDataTable.validate();
092: marginDataTable.repaint();
093: }
094:
095: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
096: private void initComponents() {
097:
098: marginPanel = new javax.swing.JPanel();
099:
100: setLayout(new java.awt.BorderLayout(0, 5));
101:
102: marginPanel.setLayout(new java.awt.BorderLayout());
103: add(marginPanel, java.awt.BorderLayout.NORTH);
104: }// </editor-fold>//GEN-END:initComponents
105:
106: /**
107: * Margin Data Table that holds the margin style info
108: * @author Winston Prakash
109: */
110: public class MarginDataTable extends JPanel {
111:
112: /**
113: * Holds value of property value.
114: */
115: private String value;
116: MarginWidthField allMarginField;
117: PaddingWidthField allPaddingField;
118: MarginWidthField topMarginField;
119: PaddingWidthField topPaddingField;
120: MarginWidthField bottomMarginField;
121: PaddingWidthField leftPaddingField;
122: MarginWidthField rightMarginField;
123: PaddingWidthField rightPaddingField;
124: PaddingWidthField bottomPaddingField;
125: MarginWidthField leftMarginField;
126:
127: public MarginDataTable() {
128: setLayout(new FlexibleGridLayout(6, 3, 5, 5));
129: FontMetrics fontMetrics = getFontMetrics(getFont());
130: int aheight = (fontMetrics.getHeight() + 10) > 25 ? (fontMetrics
131: .getHeight() + 10)
132: : 25;
133: setBackground(new JPanel().getBackground());
134: initCells(aheight);
135: getAccessibleContext().setAccessibleName(
136: NbBundle.getMessage(MarginDataTable.class,
137: "MARGIN_STYLE_TABLE_ACCESS_NAME"));
138: getAccessibleContext().setAccessibleDescription(
139: NbBundle.getMessage(MarginDataTable.class,
140: "MARGIN_STYLE_TABLE_ACCESS_DESC"));
141: }
142:
143: protected void setCssPropertyValues(CssRuleContent cssStyleData) {
144:
145: // Set the value for the Margin
146: String topMargin = cssStyleData
147: .getProperty(CssProperties.MARGIN_TOP);
148: String bottomMargin = cssStyleData
149: .getProperty(CssProperties.MARGIN_BOTTOM);
150: String leftMargin = cssStyleData
151: .getProperty(CssProperties.MARGIN_LEFT);
152: String rightMargin = cssStyleData
153: .getProperty(CssProperties.MARGIN_RIGHT);
154:
155: if ((topMargin != null) && (bottomMargin != null)
156: && (leftMargin != null) && (rightMargin != null)
157: && (topMargin.equals(bottomMargin))
158: && (topMargin.equals(leftMargin))
159: && (topMargin.equals(rightMargin))) {
160: allMarginField.setMarginString(topMargin);
161: } else {
162: allMarginField.setMarginString(null);
163: topMarginField.setMarginString(topMargin);
164: bottomMarginField.setMarginString(bottomMargin);
165: leftMarginField.setMarginString(leftMargin);
166: rightMarginField.setMarginString(rightMargin);
167: }
168:
169: // Set the value for the Padding
170: String topPadding = cssStyleData
171: .getProperty(CssProperties.PADDING_TOP);
172: String bottomPadding = cssStyleData
173: .getProperty(CssProperties.PADDING_BOTTOM);
174: String leftPadding = cssStyleData
175: .getProperty(CssProperties.PADDING_LEFT);
176: String rightPadding = cssStyleData
177: .getProperty(CssProperties.PADDING_RIGHT);
178:
179: if ((topPadding != null) && (bottomPadding != null)
180: && (leftPadding != null) && (rightPadding != null)
181: && (topPadding.equals(bottomPadding))
182: && (topPadding.equals(leftPadding))
183: && (topPadding.equals(rightPadding))) {
184: allPaddingField.setPaddingString(topPadding);
185: } else {
186: allPaddingField.setPaddingString(null);
187: topPaddingField.setPaddingString(topPadding);
188: bottomPaddingField.setPaddingString(bottomPadding);
189: leftPaddingField.setPaddingString(leftPadding);
190: rightPaddingField.setPaddingString(rightPadding);
191: }
192: }
193:
194: public void initCells(int aheight) {
195: JPanel colHeader1 = new JPanel();
196:
197: JPanel colHeader2 = new JPanel();
198: colHeader2.add(new JLabel(org.openide.util.NbBundle
199: .getMessage(MarginDataTable.class, "MARGIN_ALL")));
200:
201: JPanel colHeader3 = new JPanel();
202: colHeader3.add(new JLabel(org.openide.util.NbBundle
203: .getMessage(MarginDataTable.class, "PADDING")));
204:
205: JPanel rowHeader1 = new JPanel();
206: rowHeader1.add(new JLabel(org.openide.util.NbBundle
207: .getMessage(MarginDataTable.class,
208: "MARGIN_PADDING_ALL")));
209:
210: JPanel rowHeader2 = new JPanel();
211: rowHeader2.add(new JLabel(org.openide.util.NbBundle
212: .getMessage(MarginDataTable.class,
213: "MARGIN_PADDING_TOP")));
214:
215: JPanel rowHeader3 = new JPanel();
216: rowHeader3.add(new JLabel(org.openide.util.NbBundle
217: .getMessage(MarginDataTable.class,
218: "MARGIN_PADDING_BOTTOM")));
219:
220: JPanel rowHeader4 = new JPanel();
221: rowHeader4.add(new JLabel(org.openide.util.NbBundle
222: .getMessage(MarginDataTable.class,
223: "MARGIN_PADDING_LEFT")));
224:
225: JPanel rowHeader5 = new JPanel();
226: rowHeader5.add(new JLabel(org.openide.util.NbBundle
227: .getMessage(MarginDataTable.class,
228: "MARGIN_PADDING_RIGHT")));
229:
230: // All Side Margin
231: allMarginField = new MarginWidthField();
232: allMarginField.setAccessibleName(NbBundle.getMessage(
233: MarginDataTable.class,
234: "ALL_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
235: .getMessage(MarginDataTable.class,
236: "ALL_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
237: allMarginField.setAccessibleDescription(NbBundle
238: .getMessage(MarginDataTable.class,
239: "ALL_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
240: NbBundle.getMessage(MarginDataTable.class,
241: "ALL_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
242: allMarginField.addPropertyChangeListener("margin-width",
243: new PropertyChangeListenerImpl() {
244:
245: //NOI18N
246: public void propertyChange(
247: PropertyChangeEvent evt) {
248: //cssPropertyChangeSupport().firePropertyChange(CssProperties.MARGIN, null, evt.getNewValue().toString());
249: topMarginField.setMarginString(evt
250: .getNewValue().toString());
251: bottomMarginField.setMarginString(evt
252: .getNewValue().toString());
253: leftMarginField.setMarginString(evt
254: .getNewValue().toString());
255: rightMarginField.setMarginString(evt
256: .getNewValue().toString());
257: }
258: });
259:
260: // All Side Margin
261: allPaddingField = new PaddingWidthField();
262: allPaddingField.setAccessibleName(NbBundle.getMessage(
263: MarginDataTable.class,
264: "ALL_SIDE_PADDING_WIDTH_ACCESS_NAME"), NbBundle
265: .getMessage(MarginDataTable.class,
266: "ALL_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
267: allPaddingField.setAccessibleDescription(NbBundle
268: .getMessage(MarginDataTable.class,
269: "ALL_SIDE_PADDING_WIDTH_ACCESS_DESC"),
270: NbBundle.getMessage(MarginDataTable.class,
271: "ALL_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
272: allPaddingField.addPropertyChangeListener("margin-width",
273: new PropertyChangeListenerImpl() {
274:
275: //NOI18N
276: public void propertyChange(
277: PropertyChangeEvent evt) {
278: //cssPropertyChangeSupport().firePropertyChange(CssProperties.PADDING, null, evt.getNewValue().toString());
279: topPaddingField.setPaddingString(evt
280: .getNewValue().toString());
281: bottomPaddingField.setPaddingString(evt
282: .getNewValue().toString());
283: leftPaddingField.setPaddingString(evt
284: .getNewValue().toString());
285: rightPaddingField.setPaddingString(evt
286: .getNewValue().toString());
287: }
288: });
289:
290: // Top Side Margin
291: topMarginField = new MarginWidthField();
292: topMarginField.setAccessibleName(NbBundle.getMessage(
293: MarginDataTable.class,
294: "TOP_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
295: .getMessage(MarginDataTable.class,
296: "TOP_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
297: topMarginField.setAccessibleDescription(NbBundle
298: .getMessage(MarginDataTable.class,
299: "TOP_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
300: NbBundle.getMessage(MarginDataTable.class,
301: "TOP_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
302: topMarginField.addPropertyChangeListener("margin-width",
303: new PropertyChangeListenerImpl() {
304:
305: //NOI18N
306: public void propertyChange(
307: PropertyChangeEvent evt) {
308: cssPropertyChangeSupport()
309: .firePropertyChange(
310: CssProperties.MARGIN_TOP,
311: null,
312: evt.getNewValue()
313: .toString());
314: }
315: });
316:
317: // Top Side Margin
318: topPaddingField = new PaddingWidthField();
319: topPaddingField.setAccessibleName(NbBundle.getMessage(
320: MarginDataTable.class,
321: "TOP_SIDE_PADDING_WIDTH_ACCESS_NAME"), NbBundle
322: .getMessage(MarginDataTable.class,
323: "TOP_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
324: topPaddingField.setAccessibleDescription(NbBundle
325: .getMessage(MarginDataTable.class,
326: "TOP_SIDE_PADDING_WIDTH_ACCESS_DESC"),
327: NbBundle.getMessage(MarginDataTable.class,
328: "TOP_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
329: topPaddingField.addPropertyChangeListener("margin-width",
330: new PropertyChangeListenerImpl() {
331:
332: //NOI18N
333: public void propertyChange(
334: PropertyChangeEvent evt) {
335: cssPropertyChangeSupport()
336: .firePropertyChange(
337: CssProperties.PADDING_TOP,
338: null,
339: evt.getNewValue()
340: .toString());
341: }
342: });
343:
344: // Bottom Side Margin
345: bottomMarginField = new MarginWidthField();
346: bottomMarginField
347: .setAccessibleName(
348: NbBundle
349: .getMessage(MarginDataTable.class,
350: "BOTTOM_SIDE_MARGIN_WIDTH_ACCESS_NAME"),
351: NbBundle
352: .getMessage(MarginDataTable.class,
353: "BOTTOM_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
354: bottomMarginField
355: .setAccessibleDescription(
356: NbBundle
357: .getMessage(MarginDataTable.class,
358: "BOTTOM_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
359: NbBundle
360: .getMessage(MarginDataTable.class,
361: "BOTTOM_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
362: bottomMarginField.addPropertyChangeListener("margin-width",
363: new PropertyChangeListenerImpl() {
364:
365: //NOI18N
366: public void propertyChange(
367: PropertyChangeEvent evt) {
368: cssPropertyChangeSupport()
369: .firePropertyChange(
370: CssProperties.MARGIN_BOTTOM,
371: null,
372: evt.getNewValue()
373: .toString());
374: }
375: });
376:
377: // Bottom Side Margin
378: bottomPaddingField = new PaddingWidthField();
379: bottomPaddingField
380: .setAccessibleName(
381: NbBundle
382: .getMessage(MarginDataTable.class,
383: "BOTTOM_SIDE_PADDING_WIDTH_ACCESS_NAME"),
384: NbBundle
385: .getMessage(MarginDataTable.class,
386: "BOTTOM_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
387: bottomPaddingField
388: .setAccessibleDescription(
389: NbBundle
390: .getMessage(MarginDataTable.class,
391: "BOTTOM_SIDE_PADDING_WIDTH_ACCESS_DESC"),
392: NbBundle
393: .getMessage(MarginDataTable.class,
394: "BOTTOM_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
395: bottomPaddingField.addPropertyChangeListener(
396: "margin-width", new PropertyChangeListenerImpl() {
397:
398: //NOI18N
399: public void propertyChange(
400: PropertyChangeEvent evt) {
401: cssPropertyChangeSupport()
402: .firePropertyChange(
403: CssProperties.PADDING_BOTTOM,
404: null,
405: evt.getNewValue()
406: .toString());
407: }
408: });
409:
410: // Left Side Margin
411: leftMarginField = new MarginWidthField();
412: leftMarginField.setAccessibleName(NbBundle.getMessage(
413: MarginDataTable.class,
414: "LEFT_SIDE_MARGIN_WIDTH_ACCESS_NAME"), NbBundle
415: .getMessage(MarginDataTable.class,
416: "LEFT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
417: leftMarginField.setAccessibleDescription(NbBundle
418: .getMessage(MarginDataTable.class,
419: "LEFT_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
420: NbBundle.getMessage(MarginDataTable.class,
421: "LEFT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
422: leftMarginField.addPropertyChangeListener("margin-width",
423: new PropertyChangeListenerImpl() {
424:
425: //NOI18N
426: public void propertyChange(
427: PropertyChangeEvent evt) {
428: cssPropertyChangeSupport()
429: .firePropertyChange(
430: CssProperties.MARGIN_LEFT,
431: null,
432: evt.getNewValue()
433: .toString());
434: }
435: });
436:
437: // Left Side Margin
438: leftPaddingField = new PaddingWidthField();
439: leftPaddingField
440: .setAccessibleName(
441: NbBundle
442: .getMessage(MarginDataTable.class,
443: "LEFT_SIDE_PADDING_WIDTH_ACCESS_NAME"),
444: NbBundle
445: .getMessage(MarginDataTable.class,
446: "LEFT_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
447: leftPaddingField
448: .setAccessibleDescription(
449: NbBundle
450: .getMessage(MarginDataTable.class,
451: "LEFT_SIDE_PADDING_WIDTH_ACCESS_DESC"),
452: NbBundle
453: .getMessage(MarginDataTable.class,
454: "LEFT_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
455: leftPaddingField.addPropertyChangeListener("margin-width",
456: new PropertyChangeListenerImpl() {
457:
458: //NOI18N
459: public void propertyChange(
460: PropertyChangeEvent evt) {
461: cssPropertyChangeSupport()
462: .firePropertyChange(
463: CssProperties.PADDING_LEFT,
464: null,
465: evt.getNewValue()
466: .toString());
467: }
468: });
469:
470: // Left Side Margin
471: rightMarginField = new MarginWidthField();
472: rightMarginField
473: .setAccessibleName(
474: NbBundle
475: .getMessage(MarginDataTable.class,
476: "RIGHT_SIDE_MARGIN_WIDTH_ACCESS_NAME"),
477: NbBundle
478: .getMessage(MarginDataTable.class,
479: "RIGHT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_NAME"));
480: rightMarginField
481: .setAccessibleDescription(
482: NbBundle
483: .getMessage(MarginDataTable.class,
484: "RIGHT_SIDE_MARGIN_WIDTH_ACCESS_DESC"),
485: NbBundle
486: .getMessage(MarginDataTable.class,
487: "RIGHT_SIDE_MARGIN_WIDTH_UNIT_ACCESS_DESC"));
488: rightMarginField.addPropertyChangeListener("margin-width",
489: new PropertyChangeListenerImpl() {
490:
491: //NOI18N
492: public void propertyChange(
493: PropertyChangeEvent evt) {
494: cssPropertyChangeSupport()
495: .firePropertyChange(
496: CssProperties.MARGIN_RIGHT,
497: null,
498: evt.getNewValue()
499: .toString());
500: }
501: });
502:
503: // Left Side Margin
504: rightPaddingField = new PaddingWidthField();
505: rightPaddingField
506: .setAccessibleName(
507: NbBundle
508: .getMessage(MarginDataTable.class,
509: "RIGHT_SIDE_PADDING_WIDTH_ACCESS_NAME"),
510: NbBundle
511: .getMessage(MarginDataTable.class,
512: "RIGHT_SIDE_PADDING_WIDTH_UNIT_ACCESS_NAME"));
513: rightPaddingField
514: .setAccessibleDescription(
515: NbBundle
516: .getMessage(MarginDataTable.class,
517: "RIGHT_SIDE_PADDING_WIDTH_ACCESS_DESC"),
518: NbBundle
519: .getMessage(MarginDataTable.class,
520: "RIGHT_SIDE_PADDING_WIDTH_UNIT_ACCESS_DESC"));
521: rightPaddingField.addPropertyChangeListener("margin-width",
522: new PropertyChangeListenerImpl() {
523:
524: //NOI18N
525: public void propertyChange(
526: PropertyChangeEvent evt) {
527: cssPropertyChangeSupport()
528: .firePropertyChange(
529: CssProperties.PADDING_RIGHT,
530: null,
531: evt.getNewValue()
532: .toString());
533: }
534: });
535:
536: add(colHeader1);
537: add(colHeader2);
538: add(colHeader3);
539: add(rowHeader1);
540: add(allMarginField);
541: add(allPaddingField);
542: add(rowHeader2);
543: add(topMarginField);
544: add(topPaddingField);
545: add(rowHeader3);
546: add(bottomMarginField);
547: add(bottomPaddingField);
548: add(rowHeader4);
549: add(leftMarginField);
550: add(leftPaddingField);
551: add(rowHeader5);
552: add(rightMarginField);
553: add(rightPaddingField);
554: int cnt = getComponentCount();
555: int[] widths = { 30, 100, 100 };
556: for (int i = 0; i < cnt; i++) {
557: int awidth = widths[i % 3];
558: getComponent(i).setPreferredSize(
559: new Dimension(awidth, aheight));
560: getComponent(i).setMinimumSize(
561: new Dimension(awidth, aheight));
562: getComponent(i).setMaximumSize(
563: new Dimension(awidth, aheight));
564: }
565: }
566:
567: class PropertyChangeListenerImpl implements
568: PropertyChangeListener {
569:
570: public void propertyChange(PropertyChangeEvent evt) {
571: }
572: }
573: }
574:
575: // Variables declaration - do not modify//GEN-BEGIN:variables
576: private javax.swing.JPanel marginPanel;
577: // End of variables declaration//GEN-END:variables
578: }
|