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-2006 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: * DeviceAnywhereCustomizerPanel.java
044: *
045: * Created on April 27, 2007, 4:34 PM
046: */
047:
048: package org.netbeans.modules.deployment.deviceanywhere;
049:
050: import java.awt.BasicStroke;
051: import java.awt.Color;
052: import java.awt.Cursor;
053: import java.awt.Dimension;
054: import java.awt.Font;
055: import java.awt.FontMetrics;
056: import java.awt.Graphics;
057: import java.awt.Graphics2D;
058: import java.awt.RenderingHints;
059: import java.awt.Stroke;
060: import java.awt.Toolkit;
061: import java.net.MalformedURLException;
062: import java.net.URL;
063: import java.util.Map;
064: import java.util.ResourceBundle;
065: import javax.swing.JButton;
066: import org.openide.ErrorManager;
067: import org.openide.awt.HtmlBrowser.URLDisplayer;
068: import org.openide.util.NbBundle;
069:
070: /**
071: *
072: * @author suchys
073: */
074: public class DeviceAnywhereGlobalCustomizerPanel extends
075: javax.swing.JPanel {
076:
077: private boolean underline1 = false;
078: private boolean underline2 = false;
079: static final Stroke LINK_IN_FOCUS_STROKE = new BasicStroke(1,
080: BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0,
081: new float[] { 0, 2 }, 0);
082: static final Color LINK_IN_FOCUS_COLOR = getColor("LINK_IN_FOCUS"); //NOI18N
083:
084: /**
085: * Creates new form DeviceAnywhereCustomizerPanel
086: */
087: DeviceAnywhereGlobalCustomizerPanel() {
088: initComponents();
089: }
090:
091: /** This method is called from within the constructor to
092: * initialize the form.
093: * WARNING: Do NOT modify this code. The content of this method is
094: * always regenerated by the Form Editor.
095: */
096: // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
097: private void initComponents() {
098:
099: jLabel3 = new javax.swing.JLabel();
100: jLabel4 = new javax.swing.JLabel();
101: jTextFieldUser = new javax.swing.JTextField();
102: jPasswordField = new javax.swing.JPasswordField();
103: jTextArea1 = new javax.swing.JTextArea();
104: jButton1 = new JButton() {
105: @Override
106: protected void paintComponent(Graphics g) {
107: Graphics2D g2 = prepareGraphics(g);
108: super .paintComponent(g2);
109:
110: Dimension size = getSize();
111: if (hasFocus()) {
112: g2.setStroke(LINK_IN_FOCUS_STROKE);
113: g2.setColor(LINK_IN_FOCUS_COLOR);
114: g2.drawRect(0, 0, size.width - 1, size.height - 1);
115: }
116: }
117:
118: @Override
119: public void paint(Graphics g) {
120: super .paint(g);
121: if (underline1) {
122: Font f = getFont();
123: FontMetrics fm = getFontMetrics(f);
124: int y1 = fm.getHeight();
125: int x2 = fm.stringWidth(getText());
126: if (getText().length() > 0)
127: g.drawLine(0, y1, x2, y1);
128: }
129: }
130: };
131: jButton2 = new JButton() {
132: @Override
133: protected void paintComponent(Graphics g) {
134: Graphics2D g2 = prepareGraphics(g);
135: super .paintComponent(g2);
136:
137: Dimension size = getSize();
138: if (hasFocus()) {
139: g2.setStroke(LINK_IN_FOCUS_STROKE);
140: g2.setColor(LINK_IN_FOCUS_COLOR);
141: g2.drawRect(0, 0, size.width - 1, size.height - 1);
142: }
143: }
144:
145: @Override
146: public void paint(Graphics g) {
147: super .paint(g);
148: if (underline2) {
149: Font f = getFont();
150: FontMetrics fm = getFontMetrics(f);
151: int y1 = fm.getHeight();
152: int x2 = fm.stringWidth(getText());
153: if (getText().length() > 0)
154: g.drawLine(0, y1, x2, y1);
155: }
156: }
157: };
158:
159: jLabel3.setLabelFor(jTextFieldUser);
160: org.openide.awt.Mnemonics.setLocalizedText(jLabel3,
161: org.openide.util.NbBundle.getMessage(
162: DeviceAnywhereGlobalCustomizerPanel.class,
163: "LBL_UserName")); // NOI18N
164:
165: jLabel4.setLabelFor(jPasswordField);
166: org.openide.awt.Mnemonics.setLocalizedText(jLabel4,
167: org.openide.util.NbBundle.getMessage(
168: DeviceAnywhereGlobalCustomizerPanel.class,
169: "LBL_Password")); // NOI18N
170:
171: jTextFieldUser
172: .setName(DeviceAnywhereDeploymentPlugin.PROP_USERID);
173:
174: jPasswordField
175: .setName(DeviceAnywhereDeploymentPlugin.PROP_PASSWORD);
176:
177: jTextArea1.setBackground(javax.swing.UIManager.getDefaults()
178: .getColor("Panel.background"));
179: jTextArea1.setEditable(false);
180: jTextArea1.setLineWrap(true);
181: jTextArea1.setText(org.openide.util.NbBundle.getMessage(
182: DeviceAnywhereGlobalCustomizerPanel.class,
183: "MSG_PassWarning")); // NOI18N
184: jTextArea1.setWrapStyleWord(true);
185:
186: org.openide.awt.Mnemonics.setLocalizedText(jButton1,
187: org.openide.util.NbBundle.getMessage(
188: DeviceAnywhereGlobalCustomizerPanel.class,
189: "DA_url_text")); // NOI18N
190: jButton1.setBorder(javax.swing.BorderFactory.createEmptyBorder(
191: 1, 1, 1, 1));
192: jButton1.setBorderPainted(false);
193: jButton1.setContentAreaFilled(false);
194: jButton1.setFocusPainted(false);
195: jButton1
196: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
197: jButton1.setMargin(new java.awt.Insets(0, 0, 0, 0));
198: jButton1.setCursor(Cursor
199: .getPredefinedCursor(Cursor.HAND_CURSOR));
200: jButton1.setForeground(new Color(0x0E1B55));
201: jButton1.addActionListener(new java.awt.event.ActionListener() {
202: public void actionPerformed(java.awt.event.ActionEvent evt) {
203: jButton1ActionPerformed(evt);
204: }
205: });
206: jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
207: public void mouseEntered(java.awt.event.MouseEvent evt) {
208: jButton1MouseEntered(evt);
209: }
210:
211: public void mouseExited(java.awt.event.MouseEvent evt) {
212: jButton1MouseExited(evt);
213: }
214: });
215:
216: org.openide.awt.Mnemonics.setLocalizedText(jButton2,
217: org.openide.util.NbBundle.getMessage(
218: DeviceAnywhereGlobalCustomizerPanel.class,
219: "DA_about_text")); // NOI18N
220: jButton2.setBorder(javax.swing.BorderFactory.createEmptyBorder(
221: 1, 1, 1, 1));
222: jButton2.setBorderPainted(false);
223: jButton2.setContentAreaFilled(false);
224: jButton2.setFocusPainted(false);
225: jButton2
226: .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
227: jButton2.setMargin(new java.awt.Insets(0, 0, 0, 0));
228: jButton2.setCursor(Cursor
229: .getPredefinedCursor(Cursor.HAND_CURSOR));
230: jButton2.setForeground(new Color(0x0E1B55));
231: jButton2.addActionListener(new java.awt.event.ActionListener() {
232: public void actionPerformed(java.awt.event.ActionEvent evt) {
233: jButton2ActionPerformed(evt);
234: }
235: });
236: jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
237: public void mouseEntered(java.awt.event.MouseEvent evt) {
238: jButton2MouseEntered(evt);
239: }
240:
241: public void mouseExited(java.awt.event.MouseEvent evt) {
242: jButton2MouseExited(evt);
243: }
244: });
245:
246: org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(
247: this );
248: this .setLayout(layout);
249: layout
250: .setHorizontalGroup(layout
251: .createParallelGroup(
252: org.jdesktop.layout.GroupLayout.LEADING)
253: .add(
254: layout.createSequentialGroup().add(
255: jButton1).addContainerGap())
256: .add(
257: layout.createSequentialGroup().add(
258: jButton2).addContainerGap())
259: .add(
260: org.jdesktop.layout.GroupLayout.TRAILING,
261: layout
262: .createSequentialGroup()
263: .add(
264: layout
265: .createParallelGroup(
266: org.jdesktop.layout.GroupLayout.TRAILING)
267: .add(
268: org.jdesktop.layout.GroupLayout.LEADING,
269: jTextArea1,
270: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
271: 517,
272: Short.MAX_VALUE)
273: .add(
274: layout
275: .createSequentialGroup()
276: .add(
277: layout
278: .createParallelGroup(
279: org.jdesktop.layout.GroupLayout.LEADING)
280: .add(
281: jLabel3)
282: .add(
283: layout
284: .createSequentialGroup()
285: .add(
286: jLabel4,
287: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
288: 93,
289: Short.MAX_VALUE)
290: .addPreferredGap(
291: org.jdesktop.layout.LayoutStyle.RELATED)))
292: .add(
293: 1,
294: 1,
295: 1)
296: .add(
297: layout
298: .createParallelGroup(
299: org.jdesktop.layout.GroupLayout.LEADING,
300: false)
301: .add(
302: jTextFieldUser)
303: .add(
304: jPasswordField,
305: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
306: 423,
307: Short.MAX_VALUE))))
308: .add(0, 0, 0)));
309: layout
310: .setVerticalGroup(layout
311: .createParallelGroup(
312: org.jdesktop.layout.GroupLayout.LEADING)
313: .add(
314: layout
315: .createSequentialGroup()
316: .add(
317: layout
318: .createParallelGroup(
319: org.jdesktop.layout.GroupLayout.BASELINE)
320: .add(jLabel3)
321: .add(
322: jTextFieldUser,
323: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
324: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
325: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
326: .addPreferredGap(
327: org.jdesktop.layout.LayoutStyle.RELATED)
328: .add(
329: layout
330: .createParallelGroup(
331: org.jdesktop.layout.GroupLayout.BASELINE)
332: .add(jLabel4)
333: .add(
334: jPasswordField,
335: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
336: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
337: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
338: .addPreferredGap(
339: org.jdesktop.layout.LayoutStyle.RELATED)
340: .add(jButton1)
341: .addPreferredGap(
342: org.jdesktop.layout.LayoutStyle.RELATED)
343: .add(jButton2)
344: .addPreferredGap(
345: org.jdesktop.layout.LayoutStyle.RELATED)
346: .add(
347: jTextArea1,
348: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE,
349: org.jdesktop.layout.GroupLayout.DEFAULT_SIZE,
350: org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
351: .add(0, 0, 0)));
352:
353: jLabel3.getAccessibleContext().setAccessibleName(
354: org.openide.util.NbBundle.getMessage(
355: DeviceAnywhereGlobalCustomizerPanel.class,
356: "ACSN_UserName")); // NOI18N
357: jLabel3.getAccessibleContext().setAccessibleDescription(
358: org.openide.util.NbBundle.getMessage(
359: DeviceAnywhereGlobalCustomizerPanel.class,
360: "ACSD_UserName")); // NOI18N
361: jLabel4.getAccessibleContext().setAccessibleName(
362: org.openide.util.NbBundle.getMessage(
363: DeviceAnywhereGlobalCustomizerPanel.class,
364: "ACSN_Password")); // NOI18N
365: jLabel4.getAccessibleContext().setAccessibleDescription(
366: org.openide.util.NbBundle.getMessage(
367: DeviceAnywhereGlobalCustomizerPanel.class,
368: "ACSD_Password")); // NOI18N
369: jTextArea1.getAccessibleContext().setAccessibleName(
370: org.openide.util.NbBundle.getMessage(
371: DeviceAnywhereGlobalCustomizerPanel.class,
372: "ACSN_PassWarning")); // NOI18N
373: jTextArea1.getAccessibleContext().setAccessibleDescription(
374: org.openide.util.NbBundle.getMessage(
375: DeviceAnywhereGlobalCustomizerPanel.class,
376: "ACSD_PassWarning")); // NOI18N
377: jButton1.getAccessibleContext().setAccessibleName(
378: org.openide.util.NbBundle.getMessage(
379: DeviceAnywhereGlobalCustomizerPanel.class,
380: "ACSN_Link")); // NOI18N
381: jButton1.getAccessibleContext().setAccessibleDescription(
382: org.openide.util.NbBundle.getMessage(
383: DeviceAnywhereGlobalCustomizerPanel.class,
384: "ACSD_Link")); // NOI18N
385: }// </editor-fold>//GEN-END:initComponents
386:
387: private void jButton1MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseEntered
388: underline1 = true;
389: setForeground(getColor("RSS_LINK")); //NOI18N
390: repaint();
391: }//GEN-LAST:event_jButton1MouseEntered
392:
393: private void jButton1MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton1MouseExited
394: underline1 = false;
395: setForeground(getColor("HEADER_TEXT")); //NOI18N
396: repaint();
397: }//GEN-LAST:event_jButton1MouseExited
398:
399: private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
400: try {
401: URLDisplayer.getDefault().showURL(
402: new URL(org.openide.util.NbBundle.getMessage(
403: DeviceAnywhereGlobalCustomizerPanel.class,
404: "DA_url"))); //NOI18N
405: } catch (MalformedURLException ex) {
406: //ignore
407: }
408: }//GEN-LAST:event_jButton1ActionPerformed
409:
410: private void jButton2MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseEntered
411: underline2 = true;
412: setForeground(getColor("RSS_LINK")); //NOI18N
413: repaint();
414: }//GEN-LAST:event_jButton2MouseEntered
415:
416: private void jButton2MouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton2MouseExited
417: underline2 = false;
418: setForeground(getColor("HEADER_TEXT")); //NOI18N
419: repaint();
420: }//GEN-LAST:event_jButton2MouseExited
421:
422: private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
423: try {
424: URLDisplayer.getDefault().showURL(
425: new URL(org.openide.util.NbBundle.getMessage(
426: DeviceAnywhereGlobalCustomizerPanel.class,
427: "DA_about"))); //NOI18N
428: } catch (MalformedURLException ex) {
429: //ignore
430: }
431: }//GEN-LAST:event_jButton2ActionPerformed
432:
433: // Variables declaration - do not modify//GEN-BEGIN:variables
434: private javax.swing.JButton jButton1;
435: private javax.swing.JButton jButton2;
436: javax.swing.JLabel jLabel3;
437: javax.swing.JLabel jLabel4;
438: javax.swing.JPasswordField jPasswordField;
439: javax.swing.JTextArea jTextArea1;
440: javax.swing.JTextField jTextFieldUser;
441:
442: // End of variables declaration//GEN-END:variables
443:
444: private static Color getColor(String resId) {
445: ResourceBundle bundle = NbBundle
446: .getBundle("org.netbeans.modules.deployment.deviceanywhere.Bundle"); // NOI18N
447: try {
448: Integer rgb = Integer.decode(bundle.getString(resId));
449: return new Color(rgb.intValue());
450: } catch (NumberFormatException nfE) {
451: ErrorManager.getDefault().notify(
452: ErrorManager.INFORMATIONAL, nfE);
453: return Color.BLACK;
454: }
455: }
456:
457: private static Graphics2D prepareGraphics(Graphics g) {
458: Graphics2D g2 = (Graphics2D) g;
459: Map rhints = (Map) (Toolkit.getDefaultToolkit()
460: .getDesktopProperty("awt.font.desktophints")); //NOI18N
461: if (rhints == null && Boolean.getBoolean("swing.aatext")) { //NOI18N
462: g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
463: RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
464: } else if (rhints != null) {
465: g2.addRenderingHints(rhints);
466: }
467: return g2;
468: }
469: }
|