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: * NewJPanel.java
043: *
044: * Created on August 13, 2007, 6:13 PM
045: */
046:
047: package org.netbeans.modules.visualweb.palette.codeclips;
048:
049: import java.awt.Dialog;
050: import java.awt.Dimension;
051: import java.awt.Toolkit;
052: import javax.swing.border.EtchedBorder;
053: import org.openide.DialogDescriptor;
054: import org.openide.DialogDisplayer;
055: import org.openide.util.NbBundle;
056:
057: /**
058: *
059: * @author joelle
060: */
061: public class CodeClipViewerPanel extends javax.swing.JPanel {
062:
063: private static final int DIALOG_HEIGHT = 250;
064:
065: /** Creates new form NewJPanel */
066: public CodeClipViewerPanel(String title, String tooltip,
067: String content) {
068: initComponents();
069:
070: setBorder(new EtchedBorder(EtchedBorder.LOWERED));
071: setClipName(title);
072: setContentText(content);
073: setToolTip(tooltip);
074:
075: titleField.getAccessibleContext().setAccessibleName(
076: NbBundle.getMessage(CodeClipViewerPanel.class,
077: "Acc_CodeSnippetViewer_Title"));
078: titleField.getAccessibleContext().setAccessibleName(
079: NbBundle.getMessage(CodeClipViewerPanel.class,
080: "Acc_CodeSnippetViewer_TitleDesc"));
081:
082: clipContentTextArea.getAccessibleContext().setAccessibleName(
083: NbBundle.getMessage(CodeClipViewerPanel.class,
084: "Acc_EditorPane_Name")); // NOI18N
085: clipContentTextArea.getAccessibleContext()
086: .setAccessibleDescription(
087: NbBundle.getMessage(CodeClipViewerPanel.class,
088: "Acc_EditorPane_Desc")); // NOI18N
089:
090: tooltipField.getAccessibleContext().setAccessibleName(
091: NbBundle.getMessage(CodeClipViewerPanel.class,
092: "Acc_CodeSnippetViewer_Tooltip"));
093: tooltipField.getAccessibleContext().setAccessibleDescription(
094: NbBundle.getMessage(CodeClipViewerPanel.class,
095: "Acc_CodeSnippetViewer_Tooltip_Desc"));
096:
097: }
098:
099: /** This method is called from within the constructor to
100: * initialize the form.
101: * WARNING: Do NOT modify this code. The content of this method is
102: * always regenerated by the Form Editor.
103: */
104: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
105: private void initComponents() {
106:
107: titleField = new javax.swing.JTextField();
108: jScrollPane1 = new javax.swing.JScrollPane();
109: clipContentTextArea = new javax.swing.JTextArea();
110: titleLabel = new javax.swing.JLabel();
111: tooltipLabel = new javax.swing.JLabel();
112: tooltipField = new javax.swing.JTextField();
113:
114: titleField.setText(org.openide.util.NbBundle.getMessage(
115: CodeClipViewerPanel.class,
116: "CodeClipViewerPanel.titleField.text")); // NOI18N
117:
118: clipContentTextArea.setColumns(20);
119: clipContentTextArea.setRows(5);
120: jScrollPane1.setViewportView(clipContentTextArea);
121:
122: titleLabel.setText(org.openide.util.NbBundle.getMessage(
123: CodeClipViewerPanel.class,
124: "CodeClipViewerPanel.titleLabel.text")); // NOI18N
125:
126: tooltipLabel.setText(org.openide.util.NbBundle.getMessage(
127: CodeClipViewerPanel.class,
128: "CodeClipViewerPanel.tooltipLabel.text")); // NOI18N
129:
130: tooltipField.setText(org.openide.util.NbBundle.getMessage(
131: CodeClipViewerPanel.class,
132: "CodeClipViewerPanel.tooltipField.text")); // NOI18N
133:
134: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
135: this );
136: this .setLayout(layout);
137: layout
138: .setHorizontalGroup(layout
139: .createParallelGroup(
140: org.jdesktop.layout.GroupLayout.LEADING)
141: .add(
142: layout
143: .createSequentialGroup()
144: .add(
145: layout
146: .createParallelGroup(
147: org.jdesktop.layout.GroupLayout.TRAILING)
148: .add(
149: org.jdesktop.layout.GroupLayout.LEADING,
150: layout
151: .createSequentialGroup()
152: .addContainerGap()
153: .add(
154: jScrollPane1,
155: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
156: 280,
157: Short.MAX_VALUE))
158: .add(
159: org.jdesktop.layout.GroupLayout.LEADING,
160: layout
161: .createSequentialGroup()
162: .add(
163: 18,
164: 18,
165: 18)
166: .add(
167: layout
168: .createParallelGroup(
169: org.jdesktop.layout.GroupLayout.LEADING,
170: false)
171: .add(
172: layout
173: .createSequentialGroup()
174: .add(
175: tooltipLabel)
176: .addPreferredGap(
177: org.jdesktop.layout.LayoutStyle.RELATED,
178: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
179: Short.MAX_VALUE)
180: .add(
181: tooltipField,
182: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
183: 216,
184: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
185: .add(
186: layout
187: .createSequentialGroup()
188: .add(
189: titleLabel)
190: .add(
191: 27,
192: 27,
193: 27)
194: .add(
195: titleField,
196: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
197: 216,
198: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
199: .addPreferredGap(
200: org.jdesktop.layout.LayoutStyle.RELATED)))
201: .addContainerGap(
202: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
203: Short.MAX_VALUE)));
204: layout
205: .setVerticalGroup(layout
206: .createParallelGroup(
207: org.jdesktop.layout.GroupLayout.LEADING)
208: .add(
209: layout
210: .createSequentialGroup()
211: .addContainerGap()
212: .add(
213: layout
214: .createParallelGroup(
215: org.jdesktop.layout.GroupLayout.BASELINE)
216: .add(titleLabel)
217: .add(
218: titleField,
219: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
220: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
221: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
222: .addPreferredGap(
223: org.jdesktop.layout.LayoutStyle.UNRELATED)
224: .add(
225: layout
226: .createParallelGroup(
227: org.jdesktop.layout.GroupLayout.BASELINE)
228: .add(
229: tooltipLabel)
230: .add(
231: tooltipField,
232: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
233: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
234: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
235: .add(14, 14, 14)
236: .add(
237: jScrollPane1,
238: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
239: 202,
240: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
241: .addContainerGap(
242: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
243: Short.MAX_VALUE)));
244: }// </editor-fold>//GEN-END:initComponents
245:
246: // Variables declaration - do not modify//GEN-BEGIN:variables
247: private javax.swing.JTextArea clipContentTextArea;
248: private javax.swing.JScrollPane jScrollPane1;
249: private javax.swing.JTextField titleField;
250: private javax.swing.JLabel titleLabel;
251: private javax.swing.JTextField tooltipField;
252: private javax.swing.JLabel tooltipLabel;
253:
254: // End of variables declaration//GEN-END:variables
255:
256: public String getContentText() {
257: return clipContentTextArea.getText();
258: }
259:
260: public void setContentText(String clipContent) {
261: clipContentTextArea.setText(clipContent);
262: }
263:
264: public String getClipName() {
265: return titleField.getText();
266: }
267:
268: public void setClipName(String clipName) {
269: titleField.setText(clipName);
270: }
271:
272: public String getToolTip() {
273: return tooltipField.getText();
274: }
275:
276: public void setToolTip(String tooltip) {
277: tooltipField.setText(tooltip);
278: }
279:
280: private DialogDescriptor dd;
281: private Dialog dialog;
282:
283: public void setupDialog() {
284: dd = new DialogDescriptor(this , getClipName());
285: int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
286: dialog = DialogDisplayer.getDefault().createDialog(dd);
287: dialog.setPreferredSize(new Dimension(screenWidth * 2 / 3,
288: DIALOG_HEIGHT));
289: dialog.getAccessibleContext().setAccessibleName(
290: NbBundle.getMessage(CodeClipViewerPanel.class,
291: "Acc_Dialog_Name")); // NOI18N
292: dialog.getAccessibleContext().setAccessibleDescription(
293: NbBundle.getMessage(CodeClipViewerPanel.class,
294: "Acc_Dialog_Desc")); // NOI18N
295: dialog.setVisible(true);
296: }
297:
298: public boolean isCancelled() {
299: if (dd.getValue().equals(DialogDescriptor.CANCEL_OPTION)) {
300: return true;
301: }
302: return false;
303: }
304:
305: @Override
306: public void setVisible(boolean aFlag) {
307: super.setVisible(aFlag);
308: if (aFlag) {
309: setupDialog();
310: } else {
311: dialog.dispose();
312: }
313: }
314:
315: }
|