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: * TemplateEntry.java
044: *
045: * Created on June 19, 2007, 10:18 AM
046: */
047:
048: package org.netbeans.modules.uml.codegen.ui.customizer;
049:
050: import java.awt.BorderLayout;
051: import java.awt.Dimension;
052: import java.awt.Font;
053: import java.awt.Rectangle;
054: import javax.swing.JTextArea;
055: import org.netbeans.modules.uml.codegen.dataaccess.xmlbeans.DomainObject;
056: import org.openide.util.NbBundle;
057:
058: /**
059: *
060: * @author treyspiva
061: */
062: public class TemplateEntry extends javax.swing.JPanel {
063: private DomainObject domainObject = null;
064: private DescriptionTextArea templateDescription = new DescriptionTextArea();
065:
066: public TemplateEntry(String familyName, DomainObject domain,
067: boolean isChecked) {
068: initComponents();
069: setLabelFont();
070:
071: descContainer.add(templateDescription, BorderLayout.CENTER);
072: domainObject = domain;
073: setTemplateName(domainObject.getName());
074: setTemplateDescription(domainObject.getDescription());
075: setModelElement(domainObject.getModelElement());
076: setStereroType(domainObject.getStereotype());
077:
078: templateNameCheckBox.setSelected(isChecked);
079: templateNameCheckBox
080: .putClientProperty("familyName", familyName); // NOI18N
081: }
082:
083: private void setLabelFont() {
084: String type = getFont().getFamily();
085: int size = getFont().getSize() - 1;
086:
087: templateDescription.setFont(new Font(type, Font.ITALIC, size));
088: elementTypeLabel.setFont(new Font(type, Font.ITALIC, size));
089: elementTypeValue.setFont(new Font(type, Font.ITALIC, size)); // NOI18N
090: stereotypeLabel.setFont(new Font(type, Font.ITALIC, size)); // NOI18N
091: stereotypeValue.setFont(new Font(type, Font.ITALIC, size)); // NOI18N
092: }
093:
094: public void setTemplateName(String name) {
095: templateNameCheckBox.setText(name);
096: }
097:
098: public void setTemplateDescription(String desc) {
099: templateDescription.setText(desc);
100: Dimension preferredSize = templateDescription
101: .getPreferredSize();
102: templateDescription.setSize(preferredSize);
103: }
104:
105: public void setStereroType(String value) {
106: if ((value == null) || (value.length() == 0))
107: value = org.openide.util.NbBundle.getMessage(
108: TemplateEntry.class, "LBL_NA"); // NOI18N
109:
110: stereotypeValue.setText(value);
111: }
112:
113: public void setModelElement(String value) {
114: elementTypeValue.setText(value);
115: }
116:
117: public javax.swing.JCheckBox getTemplateNameField() {
118: return templateNameCheckBox;
119: }
120:
121: /** This method is called from within the constructor to
122: * initialize the form.
123: * WARNING: Do NOT modify this code. The content of this method is
124: * always regenerated by the Form Editor.
125: */
126: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
127: private void initComponents() {
128:
129: templateNameCheckBox = new javax.swing.JCheckBox();
130: elementTypeLabel = new javax.swing.JLabel();
131: elementTypeValue = new javax.swing.JLabel();
132: stereotypeLabel = new javax.swing.JLabel();
133: stereotypeValue = new javax.swing.JLabel();
134: descContainer = new javax.swing.JPanel();
135:
136: setOpaque(false);
137:
138: templateNameCheckBox.setText("<domainName>");
139: templateNameCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
140: templateNameCheckBox.setOpaque(false);
141:
142: elementTypeLabel.setText(org.openide.util.NbBundle.getMessage(
143: TemplateEntry.class, "LBL_ElementType")); // NOI18N
144:
145: elementTypeValue.setText("<elementType>");
146:
147: stereotypeLabel.setText(org.openide.util.NbBundle.getMessage(
148: TemplateEntry.class, "LBL_Stereotype")); // NOI18N
149:
150: stereotypeValue.setText(org.openide.util.NbBundle.getMessage(
151: TemplateEntry.class, "LBL_NA")); // NOI18N
152:
153: descContainer.setBackground(new java.awt.Color(255, 255, 0));
154: descContainer.setOpaque(false);
155: descContainer.setLayout(new java.awt.BorderLayout());
156:
157: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
158: this );
159: this .setLayout(layout);
160: layout
161: .setHorizontalGroup(layout
162: .createParallelGroup(
163: org.jdesktop.layout.GroupLayout.LEADING)
164: .add(
165: layout
166: .createSequentialGroup()
167: .add(
168: layout
169: .createParallelGroup(
170: org.jdesktop.layout.GroupLayout.LEADING)
171: .add(
172: layout
173: .createSequentialGroup()
174: .addContainerGap()
175: .add(
176: templateNameCheckBox,
177: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
178: 373,
179: Short.MAX_VALUE))
180: .add(
181: layout
182: .createSequentialGroup()
183: .add(
184: 39,
185: 39,
186: 39)
187: .add(
188: layout
189: .createParallelGroup(
190: org.jdesktop.layout.GroupLayout.LEADING)
191: .add(
192: descContainer,
193: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
194: 342,
195: Short.MAX_VALUE)
196: .add(
197: layout
198: .createSequentialGroup()
199: .addPreferredGap(
200: org.jdesktop.layout.LayoutStyle.RELATED)
201: .add(
202: elementTypeLabel)
203: .addPreferredGap(
204: org.jdesktop.layout.LayoutStyle.RELATED)
205: .add(
206: elementTypeValue,
207: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
208: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
209: Short.MAX_VALUE)
210: .add(
211: 18,
212: 18,
213: 18)
214: .add(
215: stereotypeLabel,
216: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
217: 53,
218: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
219: .addPreferredGap(
220: org.jdesktop.layout.LayoutStyle.RELATED)
221: .add(
222: stereotypeValue,
223: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
224: 112,
225: Short.MAX_VALUE)))))
226: .addContainerGap()));
227: layout
228: .setVerticalGroup(layout
229: .createParallelGroup(
230: org.jdesktop.layout.GroupLayout.LEADING)
231: .add(
232: layout
233: .createSequentialGroup()
234: .add(templateNameCheckBox)
235: .addPreferredGap(
236: org.jdesktop.layout.LayoutStyle.RELATED)
237: .add(
238: descContainer,
239: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
240: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
241: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
242: .add(4, 4, 4)
243: .add(
244: layout
245: .createParallelGroup(
246: org.jdesktop.layout.GroupLayout.BASELINE)
247: .add(
248: elementTypeLabel)
249: .add(
250: elementTypeValue)
251: .add(
252: stereotypeLabel,
253: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
254: 12,
255: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
256: .add(
257: stereotypeValue))
258: .addContainerGap(
259: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
260: Short.MAX_VALUE)));
261: }// </editor-fold>//GEN-END:initComponents
262:
263: // Variables declaration - do not modify//GEN-BEGIN:variables
264: private javax.swing.JPanel descContainer;
265: private javax.swing.JLabel elementTypeLabel;
266: private javax.swing.JLabel elementTypeValue;
267: private javax.swing.JLabel stereotypeLabel;
268: private javax.swing.JLabel stereotypeValue;
269: private javax.swing.JCheckBox templateNameCheckBox;
270:
271: // End of variables declaration//GEN-END:variables
272:
273: /**
274: * This JTextArea is used to make sure that all rows are visible. If I use
275: * the JTextArea in the group layout, then the text area will never grow to
276: * fit all of the rows of text. If I use something like a Gridbag layout
277: * then the text area is too big by default. So, I have created a text area
278: * that makes sure the bounds of the text area will fit all of the rows of
279: * text when word wrapping is turned on.
280: */
281: public class DescriptionTextArea extends JTextArea {
282:
283: public DescriptionTextArea() {
284: setOpaque(false);
285: setLineWrap(true);
286: setWrapStyleWord(true);
287: }
288:
289: @Override
290: public void setBounds(int x, int y, int w, int h) {
291: super .setBounds(x, y, w, h);
292:
293: int rows = getRows();
294: int height = getRowHeight();
295:
296: if (h == rows * height) {
297: setBounds(x, y, w, rows * height);
298: }
299: }
300:
301: @Override
302: public void setBounds(Rectangle bounds) {
303: super .setBounds(bounds);
304:
305: int rows = getRows();
306: int height = getRowHeight();
307:
308: if (bounds.height == rows * height) {
309: setBounds(bounds.x, bounds.y, bounds.width, rows
310: * height);
311: }
312: }
313:
314: }
315:
316: }
|