Source Code Cross Referenced for Attribute.java in  » IDE-Netbeans » print » org » netbeans » modules » print » impl » ui » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » IDE Netbeans » print » org.netbeans.modules.print.impl.ui 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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:        package org.netbeans.modules.print.impl.ui;
042:
043:        import java.awt.Color;
044:        import java.awt.Font;
045:        import java.awt.GridBagConstraints;
046:        import java.awt.GridBagLayout;
047:        import java.awt.Insets;
048:
049:        import java.awt.event.ActionEvent;
050:        import java.awt.event.ActionListener;
051:        import java.awt.event.FocusEvent;
052:        import java.awt.event.FocusListener;
053:        import java.awt.event.ItemEvent;
054:        import java.awt.event.ItemListener;
055:
056:        import javax.swing.ButtonGroup;
057:        import javax.swing.JButton;
058:        import javax.swing.JCheckBox;
059:        import javax.swing.JComponent;
060:        import javax.swing.JLabel;
061:        import javax.swing.JPanel;
062:        import javax.swing.JRadioButton;
063:        import javax.swing.JSpinner;
064:        import javax.swing.JTextField;
065:        import javax.swing.SpinnerNumberModel;
066:
067:        import org.openide.DialogDescriptor;
068:        import org.openide.util.HelpCtx;
069:
070:        import org.netbeans.modules.print.impl.util.Percent;
071:        import org.netbeans.modules.print.impl.util.Macro;
072:        import org.netbeans.modules.print.impl.util.Option;
073:        import static org.netbeans.modules.print.impl.util.UI.*;
074:
075:        /**
076:         * @author Vladimir Yaroslavskiy
077:         * @version 2006.02.14
078:         */
079:        final class Attribute extends Dialog implements  FocusListener,
080:                Macro.Listener, Percent.Listener {
081:            Attribute(Preview preview) {
082:                myPreview = preview;
083:
084:                myBorderColorValue = Option.getDefault().getBorderColor();
085:                myTextColorValue = Option.getDefault().getTextColor();
086:                myTextFontValue = Option.getDefault().getTextFont();
087:                myBackgroundColorValue = Option.getDefault()
088:                        .getBackgroundColor();
089:
090:                myHeaderColorValue = Option.getDefault().getHeaderColor();
091:                myHeaderFontValue = Option.getDefault().getHeaderFont();
092:                myFooterColorValue = Option.getDefault().getFooterColor();
093:                myFooterFontValue = Option.getDefault().getFooterFont();
094:            }
095:
096:            @Override
097:            protected DialogDescriptor createDescriptor() {
098:                myDescriptor = new DialogDescriptor(
099:                        getResizable(createPanel()),
100:                        i18n("LBL_Print_Options"), // NOI18N
101:                        true, getButtons(), DialogDescriptor.OK_OPTION,
102:                        DialogDescriptor.DEFAULT_ALIGN, null,
103:                        new ActionListener() {
104:                            public void actionPerformed(ActionEvent event) {
105:                                if (DialogDescriptor.OK_OPTION == event
106:                                        .getSource()) {
107:                                    if (updatePreview()) {
108:                                        myDescriptor
109:                                                .setClosingOptions(new Object[] {
110:                                                        DialogDescriptor.OK_OPTION,
111:                                                        DialogDescriptor.CANCEL_OPTION });
112:                                    } else {
113:                                        myDescriptor
114:                                                .setClosingOptions(new Object[] { DialogDescriptor.CANCEL_OPTION });
115:                                    }
116:                                }
117:                            }
118:                        });
119:                myDescriptor.setHelpCtx(new HelpCtx(Attribute.class));
120:
121:                return myDescriptor;
122:            }
123:
124:            public void invalidValue(String value) {
125:                //out("INVALID value: " + value);
126:                printError(i18n("ERR_Zoom_Value_Is_Invalid")); // NOI18N
127:            }
128:
129:            private Object[] getButtons() {
130:                return new Object[] {
131:                        DialogDescriptor.OK_OPTION,
132:                        createButton(new ButtonAction(i18n("LBL_Apply"),
133:                                i18n("TLT_Apply")) { // NOI18N
134:                            public void actionPerformed(ActionEvent event) {
135:                                updatePreview();
136:                            }
137:                        }), DialogDescriptor.CANCEL_OPTION };
138:            }
139:
140:            private boolean updatePreview() {
141:                int zoomWidth = getInt(myZoomWidth.getText());
142:                int zoomHeight = getInt(myZoomHeight.getText());
143:
144:                if (!checkValue(zoomWidth, zoomHeight)) {
145:                    return false;
146:                }
147:                Option.getDefault().setBorder(myBorder.isSelected());
148:                Option.getDefault().setBorderColor(myBorderColorValue);
149:
150:                Option.getDefault().setHeader(myHeader.isSelected());
151:                Option.getDefault().setHeaderLeft(myHeaderLeft.getText());
152:                Option.getDefault().setHeaderCenter(myHeaderCenter.getText());
153:                Option.getDefault().setHeaderRight(myHeaderRight.getText());
154:                Option.getDefault().setHeaderColor(myHeaderColorValue);
155:                Option.getDefault().setHeaderFont(myHeaderFontValue);
156:
157:                Option.getDefault().setFooter(myFooter.isSelected());
158:                Option.getDefault().setFooterLeft(myFooterLeft.getText());
159:                Option.getDefault().setFooterCenter(myFooterCenter.getText());
160:                Option.getDefault().setFooterRight(myFooterRight.getText());
161:                Option.getDefault().setFooterColor(myFooterColorValue);
162:                Option.getDefault().setFooterFont(myFooterFontValue);
163:
164:                Option.getDefault().setWrapLines(myWrapLines.isSelected());
165:                Option.getDefault().setLineNumbers(myLineNumbers.isSelected());
166:                Option.getDefault().setUseFont(myUseFont.isSelected());
167:                Option.getDefault().setUseColor(myUseColor.isSelected());
168:                Option.getDefault().setTextColor(myTextColorValue);
169:                Option.getDefault().setTextFont(myTextFontValue);
170:                Option.getDefault().setBackgroundColor(myBackgroundColorValue);
171:                Option.getDefault().setLineSpacing(
172:                        getDouble(myLineSpacing.getValue()));
173:                Option.getDefault().setAsEditor(myAsEditor.isSelected());
174:
175:                double zoom = 0.0;
176:
177:                if (myZoomFactor.isEnabled()) {
178:                    zoom = myZoomFactor.getValue();
179:                } else if (myZoomWidth.isEnabled()) {
180:                    zoom = Percent.createZoomWidth(zoomWidth);
181:                } else if (myZoomHeight.isEnabled()) {
182:                    zoom = Percent.createZoomHeight(zoomHeight);
183:                } else if (myFitToPage.isSelected()) {
184:                    zoom = 0.0;
185:                }
186:                Option.getDefault().setZoom(zoom);
187:                myPreview.updated();
188:                //out("SET zoom: " + zoom);
189:
190:                return true;
191:            }
192:
193:            private boolean checkValue(int zoomWidth, int zoomHeight) {
194:                if (myHeaderFontValue.getSize() > MAX_HEADER_SIZE) {
195:                    printError(i18n("ERR_Header_Size_Is_Too_Big")); // NOI18N
196:                    return false;
197:                }
198:                if (myFooterFontValue.getSize() > MAX_FOOTER_SIZE) {
199:                    printError(i18n("ERR_Footer_Size_Is_Too_Big")); // NOI18N
200:                    return false;
201:                }
202:                if (zoomWidth <= 0 || zoomHeight <= 0) {
203:                    printError(i18n("ERR_Page_Number_Is_Invalid")); // NOI18N
204:                    return false;
205:                }
206:                if (zoomWidth > MAX_PAGE_NUBER || zoomHeight > MAX_PAGE_NUBER) {
207:                    printError(i18n("ERR_Page_Number_Is_Too_Big")); // NOI18N
208:                    return false;
209:                }
210:                return true;
211:            }
212:
213:            private JPanel createPanel() {
214:                JPanel panel = new JPanel(new GridBagLayout());
215:                GridBagConstraints c = new GridBagConstraints();
216:                c.anchor = GridBagConstraints.NORTHWEST;
217:                c.fill = GridBagConstraints.HORIZONTAL;
218:                c.weightx = 1.0;
219:                c.gridx = 0;
220:
221:                // border
222:                panel.add(createSeparator(i18n("LBL_Border")), c); // NOI18N
223:                panel.add(getBorderPanel(), c);
224:
225:                // header & footer
226:                panel.add(createSeparator(i18n("LBL_Header_Footer")), c); // NOI18N
227:                panel.add(getTitlePanel(), c);
228:
229:                // text
230:                panel.add(createSeparator(i18n("LBL_Text")), c); // NOI18N
231:                panel.add(getTextPanel(), c);
232:
233:                // zoom
234:                panel.add(createSeparator(i18n("LBL_Zoom")), c); // NOI18N
235:                panel.add(getZoomPanel(), c);
236:
237:                updateControl();
238:
239:                return panel;
240:            }
241:
242:            private JPanel getBorderPanel() {
243:                JPanel panel = new JPanel(new GridBagLayout());
244:                GridBagConstraints c = new GridBagConstraints();
245:                c.anchor = GridBagConstraints.WEST;
246:
247:                // border
248:                myBorder = createCheckBox(new ButtonAction(
249:                        i18n("LBL_Print_Border")) { // NOI18N
250:                    public void actionPerformed(ActionEvent event) {
251:                        myBorderColor.setEnabled(myBorder.isSelected());
252:                    }
253:                });
254:                panel.add(myBorder, c);
255:
256:                // border.color
257:                c.weightx = 1.0;
258:                c.insets = new Insets(0, SMALL_INSET, TINY_INSET, 0);
259:                myBorderColor = createButton(new ButtonAction(icon(
260:                        Option.class, "color"), // NOI18N
261:                        i18n("TLT_Border_Color")) { // NOI18N
262:                    public void actionPerformed(ActionEvent event) {
263:                        borderColor();
264:                    }
265:                });
266:                panel.add(myBorderColor, c);
267:
268:                return panel;
269:            }
270:
271:            private JPanel getTitlePanel() {
272:                JPanel panel = new JPanel(new GridBagLayout());
273:                GridBagConstraints c = new GridBagConstraints();
274:
275:                setLabelPanel(panel, c);
276:                setHeaderPanel(panel, c);
277:                setFooterPanel(panel, c);
278:                setMacroPanel(panel, c);
279:                //  panel.setBorder(new javax.swing.border.LineBorder(java.awt.Color.red));
280:
281:                return panel;
282:            }
283:
284:            private void setLabelPanel(JPanel panel, GridBagConstraints c) {
285:                // []
286:                c.gridy++;
287:                c.anchor = GridBagConstraints.CENTER;
288:                c.insets = new Insets(0, SMALL_INSET, TINY_INSET, 0);
289:                panel.add(new JLabel(), c);
290:
291:                // left
292:                panel.add(createLabel(i18n("LBL_Left")), c); // NOI18N
293:
294:                // center
295:                panel.add(createLabel(i18n("LBL_Center")), c); // NOI18N
296:
297:                // right
298:                panel.add(createLabel(i18n("LBL_Right")), c); // NOI18N
299:            }
300:
301:            private void setHeaderPanel(JPanel panel, GridBagConstraints c) {
302:                // header
303:                c.gridy++;
304:                c.insets = new Insets(0, 0, 0, 0);
305:                c.anchor = GridBagConstraints.WEST;
306:                myHeader = createCheckBox(new ButtonAction(
307:                        i18n("LBL_Print_Header")) { // NOI18N
308:                    public void actionPerformed(ActionEvent event) {
309:                        boolean enabled = myHeader.isSelected();
310:                        myHeaderLeft.setEnabled(enabled);
311:                        myHeaderCenter.setEnabled(enabled);
312:                        myHeaderRight.setEnabled(enabled);
313:                        myHeaderColor.setEnabled(enabled);
314:                        myHeaderFont.setEnabled(enabled);
315:                    }
316:                });
317:                panel.add(myHeader, c);
318:
319:                // header left
320:                c.weightx = 1.0;
321:                c.fill = GridBagConstraints.HORIZONTAL;
322:                c.insets = new Insets(TINY_INSET, SMALL_INSET, TINY_INSET, 0);
323:                myHeaderLeft = new JTextField();
324:                setWidthFocused(myHeaderLeft, FIELD_WIDTH);
325:                panel.add(myHeaderLeft, c);
326:
327:                // header center
328:                myHeaderCenter = new JTextField();
329:                setWidthFocused(myHeaderCenter, FIELD_WIDTH);
330:                panel.add(myHeaderCenter, c);
331:
332:                // header right
333:                myHeaderRight = new JTextField();
334:                setWidthFocused(myHeaderRight, FIELD_WIDTH);
335:                panel.add(myHeaderRight, c);
336:
337:                // header.color
338:                c.weightx = 0.0;
339:                c.fill = GridBagConstraints.NONE;
340:                myHeaderColor = createButton(new ButtonAction(icon(
341:                        Option.class, "color"), // NOI18N
342:                        i18n("TLT_Header_Color")) { // NOI18N
343:                    public void actionPerformed(ActionEvent event) {
344:                        headerColor();
345:                    }
346:                });
347:                panel.add(myHeaderColor, c);
348:
349:                // header font
350:                myHeaderFont = createButton(new ButtonAction(icon(Option.class,
351:                        "font"), i18n("TLT_Header_Font")) { // NOI18N
352:                    public void actionPerformed(ActionEvent event) {
353:                        headerFont();
354:                    }
355:                });
356:                panel.add(myHeaderFont, c);
357:            }
358:
359:            private void setFooterPanel(JPanel panel, GridBagConstraints c) {
360:                // footer
361:                c.gridy++;
362:                c.insets = new Insets(0, 0, 0, 0);
363:                c.anchor = GridBagConstraints.WEST;
364:                myFooter = createCheckBox(new ButtonAction(
365:                        i18n("LBL_Print_Footer")) { // NOI18N
366:                    public void actionPerformed(ActionEvent event) {
367:                        boolean enabled = myFooter.isSelected();
368:                        myFooterLeft.setEnabled(enabled);
369:                        myFooterCenter.setEnabled(enabled);
370:                        myFooterRight.setEnabled(enabled);
371:                        myFooterColor.setEnabled(enabled);
372:                        myFooterFont.setEnabled(enabled);
373:                    }
374:                });
375:                panel.add(myFooter, c);
376:
377:                c.weightx = 1.0;
378:                c.insets = new Insets(0, SMALL_INSET, TINY_INSET, 0);
379:                c.fill = GridBagConstraints.HORIZONTAL;
380:                myFooterLeft = new JTextField();
381:                setWidthFocused(myFooterLeft, FIELD_WIDTH);
382:                panel.add(myFooterLeft, c);
383:
384:                // footer center
385:                myFooterCenter = new JTextField();
386:                setWidthFocused(myFooterCenter, FIELD_WIDTH);
387:                panel.add(myFooterCenter, c);
388:
389:                // footer right
390:                myFooterRight = new JTextField();
391:                setWidthFocused(myFooterRight, FIELD_WIDTH);
392:                panel.add(myFooterRight, c);
393:
394:                // footer color
395:                c.weightx = 0.0;
396:                c.fill = GridBagConstraints.NONE;
397:                myFooterColor = createButton(new ButtonAction(icon(
398:                        Option.class, "color"), // NOI18N
399:                        i18n("TLT_Footer_Color")) { // NOI18N
400:                    public void actionPerformed(ActionEvent event) {
401:                        footerColor();
402:                    }
403:                });
404:                panel.add(myFooterColor, c);
405:
406:                // footer font
407:                myFooterFont = createButton(new ButtonAction(icon(Option.class,
408:                        "font"), i18n("TLT_Footer_Font")) { // NOI18N
409:                    public void actionPerformed(ActionEvent event) {
410:                        footerFont();
411:                    }
412:                });
413:                panel.add(myFooterFont, c);
414:            }
415:
416:            private void setMacroPanel(JPanel panel, GridBagConstraints c) {
417:                JPanel p = new JPanel(new GridBagLayout());
418:
419:                // []
420:                c.gridy++;
421:                c.insets = new Insets(0, 0, 0, 0);
422:                c.anchor = GridBagConstraints.CENTER;
423:                panel.add(createLabel(i18n("LBL_Insert_Macros")), c); // NOI18N
424:
425:                // buttons
426:                for (Macro macro : Macro.values()) {
427:                    JButton button = macro.getButton(this );
428:                    button.setEnabled(false);
429:                    p.add(button, c);
430:                }
431:
432:                // macros
433:                c.weightx = 1.0;
434:                c.insets = new Insets(SMALL_INSET, SMALL_INSET, TINY_INSET, 0);
435:                c.gridwidth = 1 + 1 + 1;
436:                panel.add(p, c);
437:            }
438:
439:            public void pressed(Macro macro) {
440:                mySelectedField = getSelectedTextField();
441:                //out(field);
442:
443:                if (mySelectedField != null) {
444:                    //out("Set macro: " + macro);
445:                    //out("   select: " + mySelectedField.getSelectionStart() + " " + mySelectedField.getSelectionEnd());
446:                    String text = mySelectedField.getText();
447:                    String head = text.substring(0, mySelectedField
448:                            .getSelectionStart());
449:                    String tail = text.substring(mySelectedField
450:                            .getSelectionEnd(), text.length());
451:
452:                    mySelectedField.setText(head + macro.getName() + tail);
453:                }
454:            }
455:
456:            private JTextField getSelectedTextField() {
457:                if (myHeaderLeft.hasFocus()) {
458:                    return myHeaderLeft;
459:                }
460:                if (myHeaderCenter.hasFocus()) {
461:                    return myHeaderCenter;
462:                }
463:                if (myHeaderRight.hasFocus()) {
464:                    return myHeaderRight;
465:                }
466:                if (myFooterLeft.hasFocus()) {
467:                    return myFooterLeft;
468:                }
469:                if (myFooterCenter.hasFocus()) {
470:                    return myFooterCenter;
471:                }
472:                if (myFooterRight.hasFocus()) {
473:                    return myFooterRight;
474:                }
475:                return null;
476:            }
477:
478:            private JPanel getTextPanel() {
479:                JPanel panel = new JPanel(new GridBagLayout());
480:                GridBagConstraints c = new GridBagConstraints();
481:                c.anchor = GridBagConstraints.WEST;
482:
483:                createTopTextPanel(panel, c);
484:                createBottomTextPanel(panel, c);
485:
486:                return panel;
487:            }
488:
489:            private void createTopTextPanel(JPanel panel, GridBagConstraints c) {
490:                // line numbers
491:                c.gridy++;
492:                myLineNumbers = createCheckBox(new ButtonAction(
493:                        i18n("LBL_Line_Numbers")) { // NOI18N
494:                    public void actionPerformed(ActionEvent event) {
495:                    }
496:                });
497:                panel.add(myLineNumbers, c);
498:
499:                // use color
500:                myUseColor = createCheckBox(new ButtonAction(
501:                        i18n("LBL_Use_Color"), i18n("TLT_Use_Color")) { // NOI18N
502:                    public void actionPerformed(ActionEvent event) {
503:                    }
504:                });
505:                panel.add(myUseColor, c);
506:
507:                // font and color label
508:                myTextFontColorLabel = createLabel(i18n("LBL_Text_Font_and_Color")); // NOI18N
509:                panel.add(myTextFontColorLabel, c);
510:
511:                // text color
512:                c.insets = new Insets(0, SMALL_INSET, TINY_INSET, 0);
513:                myTextColor = createButton(new ButtonAction(icon(Option.class,
514:                        "color"), i18n("TLT_Text_Color")) { // NOI18N
515:                    public void actionPerformed(ActionEvent event) {
516:                        textColor();
517:                    }
518:                });
519:                panel.add(myTextColor, c);
520:
521:                // text font
522:                myTextFont = createButton(new ButtonAction(icon(Option.class,
523:                        "font"), i18n("TLT_Text_Font")) { // NOI18N
524:                    public void actionPerformed(ActionEvent event) {
525:                        textFont();
526:                    }
527:                });
528:                panel.add(myTextFont, c);
529:            }
530:
531:            private void createBottomTextPanel(JPanel panel,
532:                    GridBagConstraints c) {
533:                // wrap lines
534:                c.gridy++;
535:                c.insets = new Insets(0, 0, 0, 0);
536:                myWrapLines = createCheckBox(new ButtonAction(
537:                        i18n("LBL_Wrap_Lines")) { // NOI18N
538:                    public void actionPerformed(ActionEvent event) {
539:                    }
540:                });
541:                panel.add(myWrapLines, c);
542:
543:                // use font
544:                myUseFont = createCheckBox(new ButtonAction(
545:                        i18n("LBL_Use_Font"), i18n("TLT_Use_Font")) { // NOI18N
546:                    public void actionPerformed(ActionEvent event) {
547:                    }
548:                });
549:                panel.add(myUseFont, c);
550:
551:                // background label
552:                c.anchor = GridBagConstraints.EAST;
553:                c.insets = new Insets(TINY_INSET, SMALL_INSET, TINY_INSET, 0);
554:                myBackgroundColorLabel = createLabel(i18n("LBL_Background_Color")); // NOI18N
555:                panel.add(myBackgroundColorLabel, c);
556:
557:                // background color
558:                c.anchor = GridBagConstraints.WEST;
559:                c.insets = new Insets(0, SMALL_INSET, TINY_INSET, 0);
560:                myBackgroundColor = createButton(new ButtonAction(icon(
561:                        Option.class, "color"), // NOI18N
562:                        i18n("TLT_Background_Color")) { // NOI18N
563:                    public void actionPerformed(ActionEvent event) {
564:                        backgroundColor();
565:                    }
566:                });
567:                panel.add(myBackgroundColor, c);
568:
569:                // []
570:                c.gridy++;
571:                c.weightx = 1.0;
572:                c.insets = new Insets(0, 0, 0, 0);
573:                myAsEditor = createCheckBox(new ButtonAction(
574:                        i18n("LBL_As_Editor"), i18n("TLT_As_Editor")) { // NOI18N
575:                    public void actionPerformed(ActionEvent event) {
576:                    }
577:                });
578:                myAsEditor.addItemListener(new ItemListener() {
579:                    public void itemStateChanged(ItemEvent event) {
580:                        updateText();
581:                    }
582:                });
583:                panel.add(myAsEditor, c);
584:
585:                // []
586:                panel.add(new JLabel(), c);
587:
588:                // line spacing
589:                c.weightx = 0.0;
590:                c.anchor = GridBagConstraints.EAST;
591:                c.insets = new Insets(TINY_INSET, SMALL_INSET, TINY_INSET, 0);
592:                myLineSpacingLabel = createLabel(i18n("LBL_Line_Spacing")); // NOI18N
593:                panel.add(myLineSpacingLabel, c);
594:
595:                c.anchor = GridBagConstraints.WEST;
596:                c.insets = new Insets(0, SMALL_INSET, TINY_INSET, 0);
597:                double value = Option.getDefault().getLineSpacing();
598:
599:                if (value < 0) {
600:                    value = 1.0;
601:                }
602:                myLineSpacing = new JSpinner(new SpinnerNumberModel(value,
603:                        SPACING_MIN, SPACING_MAX, SPACING_STP));
604:                int height = myLineSpacing.getPreferredSize().height;
605:                setHeight(myLineSpacing, round(height * SPACING_FTR));
606:
607:                myLineSpacingLabel.setLabelFor(myLineSpacing);
608:                panel.add(myLineSpacing, c);
609:            }
610:
611:            private JPanel getZoomPanel() {
612:                JPanel panel = new JPanel(new GridBagLayout());
613:                GridBagConstraints c = new GridBagConstraints();
614:                ButtonGroup group = new ButtonGroup();
615:                double zoom = Option.getDefault().getZoom();
616:                c.anchor = GridBagConstraints.WEST;
617:                //out("GET ZOOM: " + zoom);
618:
619:                // (o) Fit width to
620:                c.gridy++;
621:                c.insets = new Insets(SMALL_INSET, 0, 0, 0);
622:                JRadioButton buttonWidth = createRadioButton(
623:                        i18n("LBL_Fit_Width_to"), i18n("TLT_Fit_Width_to")); // NOI18N
624:                buttonWidth.addItemListener(createItemListener(true, false,
625:                        false));
626:                panel.add(buttonWidth, c);
627:                group.add(buttonWidth);
628:
629:                // [width]
630:                c.insets = new Insets(SMALL_INSET, SMALL_INSET, TINY_INSET, 0);
631:                myZoomWidth = new JTextField(getString(Percent.getZoomWidth(
632:                        zoom, 1)));
633:                setWidth(myZoomWidth, TEXT_WIDTH);
634:                panel.add(myZoomWidth, c);
635:
636:                // page(s)
637:                c.weightx = 1.0;
638:                panel.add(createLabel(i18n("LBL_Pages")), c); // NOI18N
639:
640:                // (o) Zoom to
641:                c.weightx = 0.0;
642:                c.insets = new Insets(SMALL_INSET, 0, 0, 0);
643:                JRadioButton buttonFactor = createRadioButton(
644:                        i18n("LBL_Zoom_to"), i18n("TLT_Zoom_to")); // NOI18N
645:                buttonFactor.addItemListener(createItemListener(false, false,
646:                        true));
647:                panel.add(buttonFactor, c);
648:                group.add(buttonFactor);
649:
650:                // [zoom]
651:                c.insets = new Insets(SMALL_INSET, SMALL_INSET, TINY_INSET, 0);
652:                //out("ZOOM:"  + Percent.getZoomFactor(zoom, 1.0));
653:                myZoomFactor = new Percent(this , Percent.getZoomFactor(zoom,
654:                        1.0), PERCENTS, 0, null, i18n("TLT_Print_Zoom") // NOI18N
655:                );
656:                panel.add(myZoomFactor, c);
657:
658:                // (o) Fit height to
659:                c.gridy++;
660:                c.weightx = 0.0;
661:                c.insets = new Insets(SMALL_INSET, 0, 0, 0);
662:                JRadioButton buttonHeight = createRadioButton(
663:                        i18n("LBL_Fit_Height_to"), i18n("TLT_Fit_Height_to")); // NOI18N
664:                buttonHeight.addItemListener(createItemListener(false, true,
665:                        false));
666:                panel.add(buttonHeight, c);
667:                group.add(buttonHeight);
668:
669:                // [height]
670:                c.insets = new Insets(SMALL_INSET, SMALL_INSET, TINY_INSET, 0);
671:                myZoomHeight = new JTextField(getString(Percent.getZoomHeight(
672:                        zoom, 1)));
673:                setWidth(myZoomHeight, TEXT_WIDTH);
674:                panel.add(myZoomHeight, c);
675:
676:                // page(s)
677:                panel.add(createLabel(i18n("LBL_Pages")), c); // NOI18N
678:
679:                // (o) Fit to page
680:                c.weightx = 0.0;
681:                c.insets = new Insets(SMALL_INSET, 0, 0, 0);
682:                myFitToPage = createRadioButton(i18n("LBL_Fit_to_Page"),
683:                        i18n("TLT_Fit_to_Page")); // NOI18N
684:                myFitToPage.addItemListener(createItemListener(false, false,
685:                        false));
686:                panel.add(myFitToPage, c);
687:                group.add(myFitToPage);
688:
689:                buttonFactor.setSelected(Percent.isZoomFactor(zoom));
690:                buttonWidth.setSelected(Percent.isZoomWidth(zoom));
691:                buttonHeight.setSelected(Percent.isZoomHeight(zoom));
692:                myFitToPage.setSelected(Percent.isZoomPage(zoom));
693:                //  panel.setBorder(new javax.swing.border.LineBorder(java.awt.Color.green));
694:
695:                return panel;
696:            }
697:
698:            private ItemListener createItemListener(final boolean width,
699:                    final boolean height, final boolean factor) {
700:                return new ItemListener() {
701:                    public void itemStateChanged(ItemEvent event) {
702:                        if (myZoomWidth != null) {
703:                            myZoomWidth.setEnabled(width);
704:                        }
705:                        if (myZoomHeight != null) {
706:                            myZoomHeight.setEnabled(height);
707:                        }
708:                        if (myZoomFactor != null) {
709:                            myZoomFactor.setEnabled(factor);
710:                        }
711:                    }
712:                };
713:            }
714:
715:            private void updateText() {
716:                boolean enabled = !myAsEditor.isSelected();
717:
718:                myLineNumbers.setEnabled(enabled);
719:                myWrapLines.setEnabled(enabled);
720:                myUseColor.setEnabled(enabled);
721:                myUseFont.setEnabled(enabled);
722:                myTextFont.setEnabled(enabled);
723:                myTextColor.setEnabled(enabled);
724:                myTextFontColorLabel.setEnabled(enabled);
725:                myBackgroundColor.setEnabled(enabled);
726:                myBackgroundColorLabel.setEnabled(enabled);
727:                myLineSpacing.setEnabled(enabled);
728:                myLineSpacingLabel.setEnabled(enabled);
729:            }
730:
731:            private String getString(int value) {
732:                if (value < 0) {
733:                    return Integer.toString(-value);
734:                }
735:                return Integer.toString(value);
736:            }
737:
738:            private void setWidthFocused(JComponent component, int width) {
739:                setWidth(component, width);
740:                component.addFocusListener(this );
741:            }
742:
743:            public void focusGained(FocusEvent event) {
744:                //out("FOCUS GAINED");
745:                setMacroEnabled(true);
746:            }
747:
748:            public void focusLost(FocusEvent event) {
749:                //out("FOCUS LOST");
750:                setMacroEnabled(false);
751:            }
752:
753:            private void setMacroEnabled(boolean enabled) {
754:                for (Macro macro : Macro.values()) {
755:                    macro.getButton().setEnabled(enabled);
756:                }
757:            }
758:
759:            private void headerFont() {
760:                Font font = font(myHeaderFontValue);
761:
762:                if (font != null) {
763:                    myHeaderFontValue = font;
764:                }
765:            }
766:
767:            private void footerFont() {
768:                Font font = font(myFooterFontValue);
769:
770:                if (font != null) {
771:                    myFooterFontValue = font;
772:                }
773:            }
774:
775:            private void textFont() {
776:                Font font = font(myTextFontValue);
777:
778:                if (font != null) {
779:                    myTextFontValue = font;
780:                }
781:            }
782:
783:            private Font font(Font font) {
784:                return (Font) new Editor(Font.class, i18n("LBL_Choose_Font"), // NOI18N
785:                        font).getValue();
786:            }
787:
788:            private void borderColor() {
789:                Color color = color(myBorderColorValue);
790:
791:                if (color != null) {
792:                    myBorderColorValue = color;
793:                }
794:            }
795:
796:            private void headerColor() {
797:                Color color = color(myHeaderColorValue);
798:
799:                if (color != null) {
800:                    myHeaderColorValue = color;
801:                }
802:            }
803:
804:            private void footerColor() {
805:                Color color = color(myFooterColorValue);
806:
807:                if (color != null) {
808:                    myFooterColorValue = color;
809:                }
810:            }
811:
812:            private void textColor() {
813:                Color color = color(myTextColorValue);
814:
815:                if (color != null) {
816:                    myTextColorValue = color;
817:                }
818:            }
819:
820:            private void backgroundColor() {
821:                Color color = color(myBackgroundColorValue);
822:
823:                if (color != null) {
824:                    myBackgroundColorValue = color;
825:                }
826:            }
827:
828:            private Color color(Color color) {
829:                return (Color) new Editor(Color.class,
830:                        i18n("LBL_Choose_Color"), // NOI18N
831:                        color).getValue();
832:            }
833:
834:            private void updateControl() {
835:                myBorder.setSelected(Option.getDefault().hasBorder());
836:                myBorderColor.setEnabled(Option.getDefault().hasBorder());
837:
838:                myHeader.setSelected(Option.getDefault().hasHeader());
839:                myHeaderLeft.setText(Option.getDefault().getHeaderLeft());
840:                myHeaderLeft.setEnabled(Option.getDefault().hasHeader());
841:                myHeaderCenter.setText(Option.getDefault().getHeaderCenter());
842:                myHeaderCenter.setEnabled(Option.getDefault().hasHeader());
843:                myHeaderRight.setText(Option.getDefault().getHeaderRight());
844:                myHeaderRight.setEnabled(Option.getDefault().hasHeader());
845:                myHeaderColor.setEnabled(Option.getDefault().hasHeader());
846:                myHeaderFont.setEnabled(Option.getDefault().hasHeader());
847:
848:                myFooter.setSelected(Option.getDefault().hasFooter());
849:                myFooterLeft.setText(Option.getDefault().getFooterLeft());
850:                myFooterLeft.setEnabled(Option.getDefault().hasFooter());
851:                myFooterCenter.setText(Option.getDefault().getFooterCenter());
852:                myFooterCenter.setEnabled(Option.getDefault().hasFooter());
853:                myFooterRight.setText(Option.getDefault().getFooterRight());
854:                myFooterRight.setEnabled(Option.getDefault().hasFooter());
855:                myFooterColor.setEnabled(Option.getDefault().hasFooter());
856:                myFooterFont.setEnabled(Option.getDefault().hasFooter());
857:
858:                myLineNumbers.setSelected(Option.getDefault().isLineNumbers());
859:                myWrapLines.setSelected(Option.getDefault().isWrapLines());
860:                myUseFont.setSelected(Option.getDefault().isUseFont());
861:                myUseColor.setSelected(Option.getDefault().isUseColor());
862:                myAsEditor.setSelected(Option.getDefault().isAsEditor());
863:
864:                updateText();
865:            }
866:
867:            @Override
868:            protected void opened() {
869:                myHeaderLeft.requestFocus();
870:            }
871:
872:            public double getCustomValue(int index) {
873:                return 0.0;
874:            }
875:
876:            public void valueChanged(double value, int index) {
877:            }
878:
879:            private double getDouble(Object value) {
880:                if (!(value instanceof  Double)) {
881:                    return -1.0;
882:                }
883:                return ((Double) value).doubleValue();
884:            }
885:
886:            private JCheckBox myHeader;
887:            private JTextField myHeaderLeft;
888:            private JTextField myHeaderCenter;
889:            private JTextField myHeaderRight;
890:            private JButton myHeaderFont;
891:            private JButton myHeaderColor;
892:            private Color myHeaderColorValue;
893:            private Font myHeaderFontValue;
894:
895:            private JCheckBox myFooter;
896:            private JTextField myFooterLeft;
897:            private JTextField myFooterCenter;
898:            private JTextField myFooterRight;
899:            private JButton myFooterFont;
900:            private JButton myFooterColor;
901:            private Color myFooterColorValue;
902:            private Font myFooterFontValue;
903:
904:            private JCheckBox myBorder;
905:            private JButton myBorderColor;
906:            private Color myBorderColorValue;
907:
908:            private JCheckBox myLineNumbers;
909:            private JCheckBox myWrapLines;
910:            private JCheckBox myUseFont;
911:            private JCheckBox myUseColor;
912:
913:            private JButton myTextFont;
914:            private JButton myTextColor;
915:            private JButton myBackgroundColor;
916:            private JSpinner myLineSpacing;
917:            private Font myTextFontValue;
918:            private Color myTextColorValue;
919:            private Color myBackgroundColorValue;
920:            private JCheckBox myAsEditor;
921:            private JLabel myTextFontColorLabel;
922:            private JLabel myBackgroundColorLabel;
923:            private JLabel myLineSpacingLabel;
924:
925:            private Percent myZoomFactor;
926:            private JTextField myZoomWidth;
927:            private JTextField myZoomHeight;
928:            private JTextField mySelectedField;
929:            private JRadioButton myFitToPage;
930:
931:            private Preview myPreview;
932:            private DialogDescriptor myDescriptor;
933:
934:            private static final int TEXT_WIDTH = 30;
935:            private static final int FIELD_WIDTH = 90;
936:            private static final int MAX_PAGE_NUBER = 32;
937:            private static final int MAX_HEADER_SIZE = 100;
938:            private static final int MAX_FOOTER_SIZE = 100;
939:            private static final double SPACING_MIN = 0.1;
940:            private static final double SPACING_MAX = 10.0;
941:            private static final double SPACING_STP = 0.1;
942:            private static final double SPACING_FTR = 1.15;
943:            private static final int[] PERCENTS = new int[] { 25, 50, 75, 100,
944:                    125, 150, 200, 300, 500 };
945:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.