Source Code Cross Referenced for StylesView.java in  » Report » iReport-2.0.5 » it » businesslogic » ireport » gui » style » 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 » Report » iReport 2.0.5 » it.businesslogic.ireport.gui.style 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * Copyright (C) 2005 - 2008 JasperSoft Corporation.  All rights reserved. 
0003:         * http://www.jaspersoft.com.
0004:         *
0005:         * Unless you have purchased a commercial license agreement from JasperSoft,
0006:         * the following license terms apply:
0007:         *
0008:         * This program is free software; you can redistribute it and/or modify
0009:         * it under the terms of the GNU General Public License version 2 as published by
0010:         * the Free Software Foundation.
0011:         *
0012:         * This program is distributed WITHOUT ANY WARRANTY; and without the
0013:         * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
0014:         * See the GNU General Public License for more details.
0015:         *
0016:         * You should have received a copy of the GNU General Public License
0017:         * along with this program; if not, see http://www.gnu.org/licenses/gpl.txt
0018:         * or write to:
0019:         *
0020:         * Free Software Foundation, Inc.,
0021:         * 59 Temple Place - Suite 330,
0022:         * Boston, MA  USA  02111-1307
0023:         *
0024:         *
0025:         *
0026:         *
0027:         * StylesView.java
0028:         * 
0029:         * Created on March 20, 2006, 5:15 PM
0030:         *
0031:         */
0032:
0033:        package it.businesslogic.ireport.gui.style;
0034:
0035:        import it.businesslogic.ireport.JasperTemplate;
0036:        import it.businesslogic.ireport.Report;
0037:        import it.businesslogic.ireport.Style;
0038:        import it.businesslogic.ireport.Template;
0039:        import it.businesslogic.ireport.TemplateStyle;
0040:        import it.businesslogic.ireport.UndefinedStyle;
0041:        import it.businesslogic.ireport.gui.JReportFrame;
0042:        import it.businesslogic.ireport.gui.MainFrame;
0043:        import it.businesslogic.ireport.gui.dnd.JListTransfertHandler;
0044:        import it.businesslogic.ireport.gui.docking.GenericDragTargetListener;
0045:        import it.businesslogic.ireport.gui.event.ReportFrameActivatedEvent;
0046:        import it.businesslogic.ireport.gui.event.ReportFrameActivatedListener;
0047:        import it.businesslogic.ireport.gui.event.StyleChangedEvent;
0048:        import it.businesslogic.ireport.gui.event.StyleChangedListener;
0049:        import it.businesslogic.ireport.gui.event.TemplateChangedEvent;
0050:        import it.businesslogic.ireport.gui.sheet.Tag;
0051:        import it.businesslogic.ireport.util.I18n;
0052:        import it.businesslogic.ireport.util.LanguageChangedEvent;
0053:        import it.businesslogic.ireport.util.LanguageChangedListener;
0054:        import it.businesslogic.ireport.util.Misc;
0055:        import java.awt.BorderLayout;
0056:        import java.awt.dnd.DnDConstants;
0057:        import java.awt.dnd.DropTarget;
0058:        import java.io.File;
0059:        import java.util.ArrayList;
0060:        import java.util.Vector;
0061:        import javax.swing.JOptionPane;
0062:        import javax.swing.JSeparator;
0063:        import javax.swing.JTree;
0064:        import javax.swing.tree.DefaultMutableTreeNode;
0065:        import javax.swing.tree.DefaultTreeModel;
0066:        import javax.swing.tree.MutableTreeNode;
0067:        import javax.swing.tree.TreePath;
0068:
0069:        /**
0070:         *
0071:         * @author  gtoffoli
0072:         */
0073:        public class StylesView extends javax.swing.JPanel implements 
0074:                LanguageChangedListener, ReportFrameActivatedListener,
0075:                StyleChangedListener {
0076:            private JReportFrame activeReportFrame = null;
0077:            private DefaultTreeModel libraryTreeModel = null;
0078:            private DefaultTreeModel reportTreeModel = null;
0079:
0080:            private ArrayList<JasperTemplate> openedTemplates = new ArrayList<JasperTemplate>();
0081:
0082:            /** Creates new form StylesView */
0083:            public StylesView() {
0084:                initComponents();
0085:                applyI18n();
0086:
0087:                reportTreeModel = new DefaultTreeModel(
0088:                        new DefaultMutableTreeNode("report"));
0089:                jListStyles.setDropTarget(new DropTarget(this ,
0090:                        DnDConstants.ACTION_MOVE,
0091:                        new GenericDragTargetListener(), true));
0092:                jListStyles.setTransferHandler(new JListTransfertHandler());
0093:                jListStyles.setRootVisible(false);
0094:                jListStyles.setModel(reportTreeModel);
0095:
0096:                libraryTreeModel = new DefaultTreeModel(
0097:                        new DefaultMutableTreeNode("library"));
0098:                jListStylesLibrary
0099:                        .setTransferHandler(new JListTransfertHandler());
0100:                jListStylesLibrary.setRootVisible(false);
0101:                jListStylesLibrary.setModel(libraryTreeModel);
0102:
0103:                jComboBoxStyleType.addItem(new Tag("reportStyles",
0104:                        it.businesslogic.ireport.util.I18n.getString(
0105:                                "stylesView.reportStyles", "Report styles")));
0106:                jComboBoxStyleType.addItem(new Tag("libraryStyles",
0107:                        it.businesslogic.ireport.util.I18n.getString(
0108:                                "stylesView.stylesLibrary", "Styles library")));
0109:
0110:                languageChanged(null);
0111:
0112:                MainFrame.getMainInstance().addReportFrameActivatedListener(
0113:                        this );
0114:
0115:                updateStyles();
0116:
0117:                jComboBoxStyleType.setSelectedIndex(0);
0118:            }
0119:
0120:            public void loadLibraryStyles() {
0121:                Vector v = MainFrame.getMainInstance().getStyleLibrarySet();
0122:                for (int i = 0; i < v.size(); ++i) {
0123:                    DefaultMutableTreeNode node = new DefaultMutableTreeNode(v
0124:                            .elementAt(i));
0125:                    ((DefaultMutableTreeNode) libraryTreeModel.getRoot())
0126:                            .add(node);
0127:                }
0128:                jListStylesLibrary.clearSelection();
0129:                jListStylesLibrary.updateUI();
0130:            }
0131:
0132:            public void refreshReportStyles() {
0133:                ((DefaultMutableTreeNode) reportTreeModel.getRoot())
0134:                        .removeAllChildren();
0135:
0136:                if (getActiveReportFrame() != null) {
0137:                    Vector v = getActiveReportFrame().getReport().getStyles();
0138:                    for (int i = 0; i < v.size(); ++i) {
0139:                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(
0140:                                v.elementAt(i));
0141:                        ((DefaultMutableTreeNode) reportTreeModel.getRoot())
0142:                                .add(node);
0143:                    }
0144:                    v = getActiveReportFrame().getReport().getTemplates();
0145:                    for (int i = 0; i < v.size(); ++i) {
0146:                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(
0147:                                v.elementAt(i));
0148:                        ((DefaultMutableTreeNode) reportTreeModel.getRoot())
0149:                                .add(node);
0150:                    }
0151:                }
0152:                jListStyles.clearSelection();
0153:                jListStyles.updateUI();
0154:
0155:                if (isListingReportStyles()) {
0156:                    jListStylesValueChanged(null);
0157:                }
0158:            }
0159:
0160:            /** This method is called from within the constructor to
0161:             * initialize the form.
0162:             * WARNING: Do NOT modify this code. The content of this method is
0163:             * always regenerated by the Form Editor.
0164:             */
0165:            // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
0166:            private void initComponents() {
0167:                java.awt.GridBagConstraints gridBagConstraints;
0168:
0169:                jPopupMenu1 = new javax.swing.JPopupMenu();
0170:                jMenuItemNewStyle = new javax.swing.JMenuItem();
0171:                jMenuItemNewStyleTemplate = new javax.swing.JMenuItem();
0172:                jMenuItemEditStyle = new javax.swing.JMenuItem();
0173:                jMenuItemEditTemplate = new javax.swing.JMenuItem();
0174:                jMenuItemRemove = new javax.swing.JMenuItem();
0175:                jMenuItemCloseTemplate = new javax.swing.JMenuItem();
0176:                jMenuItemAddTemplateToJT = new javax.swing.JMenuItem();
0177:                jMenuItemAddStyleToJT = new javax.swing.JMenuItem();
0178:                jMenuItemNewTemplateItem = new javax.swing.JMenuItem();
0179:                jMenuItemOpenStyleTemplate = new javax.swing.JMenuItem();
0180:                jScrollPaneLibraryList = new javax.swing.JScrollPane();
0181:                jListStylesLibrary = new it.businesslogic.ireport.gui.style.JBGTree();
0182:                jMenuItemEditJTemplate = new javax.swing.JMenuItem();
0183:                jScrollPaneReportList = new javax.swing.JScrollPane();
0184:                jListStyles = new it.businesslogic.ireport.gui.style.JBGTree();
0185:                jPanel1 = new javax.swing.JPanel();
0186:                jComboBoxStyleType = new javax.swing.JComboBox();
0187:                jToolBar1 = new javax.swing.JToolBar();
0188:                jButtonAddStyle = new javax.swing.JButton();
0189:                jButtonEditStyle = new javax.swing.JButton();
0190:                jButtonDeleteStyle = new javax.swing.JButton();
0191:
0192:                jPopupMenu1
0193:                        .addPopupMenuListener(new javax.swing.event.PopupMenuListener() {
0194:                            public void popupMenuCanceled(
0195:                                    javax.swing.event.PopupMenuEvent evt) {
0196:                            }
0197:
0198:                            public void popupMenuWillBecomeInvisible(
0199:                                    javax.swing.event.PopupMenuEvent evt) {
0200:                            }
0201:
0202:                            public void popupMenuWillBecomeVisible(
0203:                                    javax.swing.event.PopupMenuEvent evt) {
0204:                                jPopupMenu1PopupMenuWillBecomeVisible(evt);
0205:                            }
0206:                        });
0207:
0208:                jMenuItemNewStyle.setText("New style");
0209:                jMenuItemNewStyle.setActionCommand("New Style");
0210:                jMenuItemNewStyle
0211:                        .addActionListener(new java.awt.event.ActionListener() {
0212:                            public void actionPerformed(
0213:                                    java.awt.event.ActionEvent evt) {
0214:                                jMenuItemNewStyleActionPerformed(evt);
0215:                            }
0216:                        });
0217:
0218:                jMenuItemNewStyleTemplate.setText("New Jasper Template");
0219:                jMenuItemNewStyleTemplate
0220:                        .setActionCommand("New Style Template");
0221:                jMenuItemNewStyleTemplate
0222:                        .addActionListener(new java.awt.event.ActionListener() {
0223:                            public void actionPerformed(
0224:                                    java.awt.event.ActionEvent evt) {
0225:                                jMenuItemNewStyleTemplateActionPerformed(evt);
0226:                            }
0227:                        });
0228:
0229:                jMenuItemEditStyle.setText("Edit Style");
0230:                jMenuItemEditStyle.setActionCommand("New Style Template");
0231:                jMenuItemEditStyle
0232:                        .addActionListener(new java.awt.event.ActionListener() {
0233:                            public void actionPerformed(
0234:                                    java.awt.event.ActionEvent evt) {
0235:                                jMenuItemEditStyleActionPerformed(evt);
0236:                            }
0237:                        });
0238:
0239:                jMenuItemEditTemplate.setText("Edit Template Reference");
0240:                jMenuItemEditTemplate
0241:                        .addActionListener(new java.awt.event.ActionListener() {
0242:                            public void actionPerformed(
0243:                                    java.awt.event.ActionEvent evt) {
0244:                                jMenuItemEditTemplateActionPerformed(evt);
0245:                            }
0246:                        });
0247:
0248:                jMenuItemRemove.setText("Delete");
0249:                jMenuItemRemove.setActionCommand("New Style Template");
0250:                jMenuItemRemove
0251:                        .addActionListener(new java.awt.event.ActionListener() {
0252:                            public void actionPerformed(
0253:                                    java.awt.event.ActionEvent evt) {
0254:                                jMenuItemRemoveActionPerformed(evt);
0255:                            }
0256:                        });
0257:
0258:                jMenuItemCloseTemplate.setText("Close Jasper Template");
0259:                jMenuItemCloseTemplate.setActionCommand("New Style Template");
0260:                jMenuItemCloseTemplate
0261:                        .addActionListener(new java.awt.event.ActionListener() {
0262:                            public void actionPerformed(
0263:                                    java.awt.event.ActionEvent evt) {
0264:                                jMenuItemCloseTemplateActionPerformed(evt);
0265:                            }
0266:                        });
0267:
0268:                jMenuItemAddTemplateToJT
0269:                        .setText("Add Template to Jasper Template");
0270:                jMenuItemAddTemplateToJT
0271:                        .addActionListener(new java.awt.event.ActionListener() {
0272:                            public void actionPerformed(
0273:                                    java.awt.event.ActionEvent evt) {
0274:                                jMenuItemAddTemplateToJTActionPerformed(evt);
0275:                            }
0276:                        });
0277:
0278:                jMenuItemAddStyleToJT.setText("Add Style to Jasper Template");
0279:                jMenuItemAddStyleToJT.setActionCommand("New Style");
0280:                jMenuItemAddStyleToJT
0281:                        .addActionListener(new java.awt.event.ActionListener() {
0282:                            public void actionPerformed(
0283:                                    java.awt.event.ActionEvent evt) {
0284:                                jMenuItemAddStyleToJTActionPerformed(evt);
0285:                            }
0286:                        });
0287:
0288:                jMenuItemNewTemplateItem.setText("New Template Item");
0289:                jMenuItemNewTemplateItem
0290:                        .addActionListener(new java.awt.event.ActionListener() {
0291:                            public void actionPerformed(
0292:                                    java.awt.event.ActionEvent evt) {
0293:                                jMenuItemNewTemplateItemActionPerformed(evt);
0294:                            }
0295:                        });
0296:
0297:                jMenuItemOpenStyleTemplate.setText("Open Jasper Template");
0298:                jMenuItemOpenStyleTemplate
0299:                        .addActionListener(new java.awt.event.ActionListener() {
0300:                            public void actionPerformed(
0301:                                    java.awt.event.ActionEvent evt) {
0302:                                jMenuItemOpenStyleTemplateActionPerformed(evt);
0303:                            }
0304:                        });
0305:
0306:                jListStylesLibrary.setComponentPopupMenu(jPopupMenu1);
0307:                jListStylesLibrary.setDragEnabled(true);
0308:                jListStylesLibrary.setOpaque(false);
0309:                jListStylesLibrary
0310:                        .addMouseListener(new java.awt.event.MouseAdapter() {
0311:                            public void mouseClicked(
0312:                                    java.awt.event.MouseEvent evt) {
0313:                                jListStylesLibraryMouseClicked(evt);
0314:                            }
0315:                        });
0316:                jListStylesLibrary
0317:                        .addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
0318:                            public void valueChanged(
0319:                                    javax.swing.event.TreeSelectionEvent evt) {
0320:                                jListStylesLibraryValueChanged(evt);
0321:                            }
0322:                        });
0323:                jScrollPaneLibraryList.setViewportView(jListStylesLibrary);
0324:
0325:                jMenuItemEditJTemplate.setText("Edit Template Reference");
0326:                jMenuItemEditJTemplate
0327:                        .addActionListener(new java.awt.event.ActionListener() {
0328:                            public void actionPerformed(
0329:                                    java.awt.event.ActionEvent evt) {
0330:                                jMenuItemEditJTemplateActionPerformed(evt);
0331:                            }
0332:                        });
0333:
0334:                setLayout(new java.awt.BorderLayout());
0335:
0336:                jScrollPaneReportList.setBackground(new java.awt.Color(255,
0337:                        255, 255));
0338:
0339:                jListStyles.setComponentPopupMenu(jPopupMenu1);
0340:                jListStyles.setDragEnabled(true);
0341:                jListStyles.setOpaque(false);
0342:                jListStyles.addMouseListener(new java.awt.event.MouseAdapter() {
0343:                    public void mouseClicked(java.awt.event.MouseEvent evt) {
0344:                        jListStylesMouseClicked(evt);
0345:                    }
0346:                });
0347:                jListStyles
0348:                        .addTreeSelectionListener(new javax.swing.event.TreeSelectionListener() {
0349:                            public void valueChanged(
0350:                                    javax.swing.event.TreeSelectionEvent evt) {
0351:                                jListStylesValueChanged(evt);
0352:                            }
0353:                        });
0354:                jScrollPaneReportList.setViewportView(jListStyles);
0355:
0356:                add(jScrollPaneReportList, java.awt.BorderLayout.CENTER);
0357:
0358:                jPanel1.setLayout(new java.awt.GridBagLayout());
0359:
0360:                jComboBoxStyleType
0361:                        .addActionListener(new java.awt.event.ActionListener() {
0362:                            public void actionPerformed(
0363:                                    java.awt.event.ActionEvent evt) {
0364:                                jComboBoxStyleTypeActionPerformed(evt);
0365:                            }
0366:                        });
0367:                gridBagConstraints = new java.awt.GridBagConstraints();
0368:                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
0369:                gridBagConstraints.weightx = 1.0;
0370:                gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 4);
0371:                jPanel1.add(jComboBoxStyleType, gridBagConstraints);
0372:
0373:                jToolBar1.setFloatable(false);
0374:
0375:                jButtonAddStyle
0376:                        .setIcon(new javax.swing.ImageIcon(
0377:                                getClass()
0378:                                        .getResource(
0379:                                                "/it/businesslogic/ireport/icons/styles/style_add.png"))); // NOI18N
0380:                jButtonAddStyle.setToolTipText("Style add");
0381:                jButtonAddStyle.setBorder(javax.swing.BorderFactory
0382:                        .createEmptyBorder(1, 1, 1, 1));
0383:                jButtonAddStyle.setFocusPainted(false);
0384:                jButtonAddStyle.setMargin(new java.awt.Insets(0, 0, 0, 0));
0385:                jButtonAddStyle
0386:                        .addActionListener(new java.awt.event.ActionListener() {
0387:                            public void actionPerformed(
0388:                                    java.awt.event.ActionEvent evt) {
0389:                                jButtonAddStyleActionPerformed(evt);
0390:                            }
0391:                        });
0392:                jToolBar1.add(jButtonAddStyle);
0393:
0394:                jButtonEditStyle
0395:                        .setIcon(new javax.swing.ImageIcon(
0396:                                getClass()
0397:                                        .getResource(
0398:                                                "/it/businesslogic/ireport/icons/styles/style_edit.png"))); // NOI18N
0399:                jButtonEditStyle.setToolTipText("Style add");
0400:                jButtonEditStyle.setBorder(javax.swing.BorderFactory
0401:                        .createEmptyBorder(1, 1, 1, 1));
0402:                jButtonEditStyle.setFocusPainted(false);
0403:                jButtonEditStyle.setMargin(new java.awt.Insets(0, 0, 0, 0));
0404:                jButtonEditStyle
0405:                        .addActionListener(new java.awt.event.ActionListener() {
0406:                            public void actionPerformed(
0407:                                    java.awt.event.ActionEvent evt) {
0408:                                jButtonEditStyleActionPerformed(evt);
0409:                            }
0410:                        });
0411:                jToolBar1.add(jButtonEditStyle);
0412:
0413:                jButtonDeleteStyle
0414:                        .setIcon(new javax.swing.ImageIcon(
0415:                                getClass()
0416:                                        .getResource(
0417:                                                "/it/businesslogic/ireport/icons/styles/style_delete.png"))); // NOI18N
0418:                jButtonDeleteStyle.setToolTipText("Style add");
0419:                jButtonDeleteStyle.setBorder(javax.swing.BorderFactory
0420:                        .createEmptyBorder(1, 1, 1, 1));
0421:                jButtonDeleteStyle.setFocusPainted(false);
0422:                jButtonDeleteStyle.setMargin(new java.awt.Insets(0, 0, 0, 0));
0423:                jButtonDeleteStyle
0424:                        .addActionListener(new java.awt.event.ActionListener() {
0425:                            public void actionPerformed(
0426:                                    java.awt.event.ActionEvent evt) {
0427:                                jButtonDeleteStyleActionPerformed(evt);
0428:                            }
0429:                        });
0430:                jToolBar1.add(jButtonDeleteStyle);
0431:
0432:                gridBagConstraints = new java.awt.GridBagConstraints();
0433:                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
0434:                gridBagConstraints.weighty = 1.0;
0435:                jPanel1.add(jToolBar1, gridBagConstraints);
0436:
0437:                add(jPanel1, java.awt.BorderLayout.NORTH);
0438:            }// </editor-fold>//GEN-END:initComponents
0439:
0440:            private void jMenuItemEditJTemplateActionPerformed(
0441:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemEditJTemplateActionPerformed
0442:
0443:                Object selectedObject = getActiveList().getSelectedItem();
0444:                if (selectedObject == null
0445:                        || !(selectedObject instanceof  JasperTemplate))
0446:                    return;
0447:
0448:                JasperTemplate template = (JasperTemplate) selectedObject;
0449:                if (template.getParent() != null)
0450:                    return;
0451:
0452:                TemplateDataDialog td = new TemplateDataDialog(MainFrame
0453:                        .getMainInstance(), true);
0454:                String exp = template.getExpression();
0455:                td.setTemplate(exp);
0456:                td.setVisible(true);
0457:
0458:                if (td.getDialogResult() == JOptionPane.OK_OPTION) {
0459:                    template.setExpression(td.getTemplate());
0460:                    try {
0461:
0462:                        template.getParent().saveTemplateFile();
0463:                    } catch (Exception ex) {
0464:                        ex.printStackTrace();
0465:                    }
0466:                    getActiveList().updateUI();
0467:                }
0468:            }//GEN-LAST:event_jMenuItemEditJTemplateActionPerformed
0469:
0470:            private void jMenuItemAddTemplateToJTActionPerformed(
0471:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAddTemplateToJTActionPerformed
0472:
0473:                Object selectedObject = getActiveList().getSelectedItem();
0474:                if (selectedObject != null
0475:                        && selectedObject instanceof  JasperTemplate) {
0476:                    JasperTemplate jt = (JasperTemplate) selectedObject;
0477:                    if (jt.getParent() != null)
0478:                        return;
0479:                    if (jt.canWrite()) {
0480:                        TemplateDataDialog tdd = new TemplateDataDialog(
0481:                                MainFrame.getMainInstance(), true);
0482:                        tdd.setVisible(true);
0483:
0484:                        if (tdd.getDialogResult() == JOptionPane.OK_OPTION) {
0485:                            String templateStr = tdd.getTemplate();
0486:                            JasperTemplate newTemplate = new JasperTemplate(
0487:                                    templateStr);
0488:                            newTemplate.setParent(jt);
0489:                            jt.getTemplates().add(newTemplate);
0490:
0491:                            try {
0492:
0493:                                jt.saveTemplateFile();
0494:                            } catch (Exception ex) {
0495:                                ex.printStackTrace();
0496:                            }
0497:
0498:                            DefaultMutableTreeNode node = Misc
0499:                                    .findNodeWithUserObject(
0500:                                            selectedObject,
0501:                                            (DefaultMutableTreeNode) getActiveList()
0502:                                                    .getModel().getRoot());
0503:                            DefaultMutableTreeNode child = new DefaultMutableTreeNode(
0504:                                    newTemplate);
0505:                            node.add(child);
0506:
0507:                            getActiveList().expandPath(
0508:                                    new TreePath(node.getPath()));
0509:                            getActiveList().updateUI();
0510:                        }
0511:                    }
0512:                }
0513:
0514:            }//GEN-LAST:event_jMenuItemAddTemplateToJTActionPerformed
0515:
0516:            private void jMenuItemAddStyleToJTActionPerformed(
0517:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemAddStyleToJTActionPerformed
0518:                Object selectedObject = getActiveList().getSelectedItem();
0519:                if (selectedObject != null
0520:                        && selectedObject instanceof  JasperTemplate) {
0521:                    JasperTemplate jt = (JasperTemplate) selectedObject;
0522:                    if (jt.getParent() != null)
0523:                        return;
0524:                    if (jt.canWrite()) {
0525:                        StyleDialog sd = new StyleDialog(MainFrame
0526:                                .getMainInstance(), true);
0527:                        sd.setLibraryStyle(true);
0528:                        sd.setJasperTemplate(jt);
0529:                        sd.setVisible(true);
0530:
0531:                        if (sd.getDialogResult() == JOptionPane.OK_OPTION) {
0532:                            TemplateStyle templateStyle = new TemplateStyle(sd
0533:                                    .getStyle());
0534:
0535:                            templateStyle.setJasperTemplate(jt);
0536:                            jt.getStyles().add(templateStyle);
0537:
0538:                            try {
0539:
0540:                                jt.saveTemplateFile();
0541:                            } catch (Exception ex) {
0542:                                ex.printStackTrace();
0543:                            }
0544:
0545:                            DefaultMutableTreeNode node = Misc
0546:                                    .findNodeWithUserObject(
0547:                                            selectedObject,
0548:                                            (DefaultMutableTreeNode) getActiveList()
0549:                                                    .getModel().getRoot());
0550:                            DefaultMutableTreeNode child = new DefaultMutableTreeNode(
0551:                                    templateStyle);
0552:                            node.add(child);
0553:
0554:                            getActiveList().expandPath(
0555:                                    new TreePath(node.getPath()));
0556:                            getActiveList().updateUI();
0557:                        }
0558:                    }
0559:                }
0560:            }//GEN-LAST:event_jMenuItemAddStyleToJTActionPerformed
0561:
0562:            private void jMenuItemCloseTemplateActionPerformed(
0563:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemCloseTemplateActionPerformed
0564:                Object selectedObject = getActiveList().getSelectedItem();
0565:                if (selectedObject != null
0566:                        && selectedObject instanceof  JasperTemplate) {
0567:                    JasperTemplate jt = (JasperTemplate) selectedObject;
0568:                    if (jt.getParent() != null) {
0569:                        jt = jt.getParent();
0570:                    }
0571:                    DefaultMutableTreeNode node = Misc.findNodeWithUserObject(
0572:                            jt, (DefaultMutableTreeNode) getActiveList()
0573:                                    .getModel().getRoot());
0574:                    ((DefaultTreeModel) getActiveList().getModel())
0575:                            .removeNodeFromParent(node);
0576:                    getActiveList().updateUI();
0577:                }
0578:            }//GEN-LAST:event_jMenuItemCloseTemplateActionPerformed
0579:
0580:            private void jListStylesValueChanged(
0581:                    javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jListStylesValueChanged
0582:                Object selectedObject = jListStyles.getSelectedItem();
0583:                if (selectedObject == null
0584:                        || selectedObject instanceof  TemplateStyle
0585:                        || selectedObject instanceof  Template
0586:                        || selectedObject instanceof  JasperTemplate) {
0587:                    jButtonEditStyle.setEnabled(false);
0588:                    jButtonDeleteStyle.setEnabled(false);
0589:                } else if (selectedObject instanceof  Style) {
0590:                    jButtonEditStyle.setEnabled(true);
0591:                    jButtonDeleteStyle.setEnabled(true);
0592:                } else {
0593:                    jButtonEditStyle.setEnabled(false);
0594:                    jButtonDeleteStyle.setEnabled(false);
0595:                }
0596:
0597:                jButtonAddStyle.setEnabled(!isListingReportStyles()
0598:                        || getActiveReportFrame() != null);
0599:
0600:            }//GEN-LAST:event_jListStylesValueChanged
0601:
0602:            private void jListStylesLibraryValueChanged(
0603:                    javax.swing.event.TreeSelectionEvent evt) {//GEN-FIRST:event_jListStylesLibraryValueChanged
0604:                Object selectedObject = jListStylesLibrary.getSelectedItem();
0605:                if (selectedObject == null
0606:                        || selectedObject instanceof  TemplateStyle
0607:                        || selectedObject instanceof  Template
0608:                        || selectedObject instanceof  JasperTemplate) {
0609:                    jButtonEditStyle.setEnabled(false);
0610:                    jButtonDeleteStyle.setEnabled(false);
0611:                } else if (selectedObject instanceof  Style) {
0612:                    jButtonEditStyle.setEnabled(true);
0613:                    jButtonDeleteStyle.setEnabled(true);
0614:                } else {
0615:                    jButtonEditStyle.setEnabled(false);
0616:                    jButtonDeleteStyle.setEnabled(false);
0617:                }
0618:
0619:                jButtonAddStyle.setEnabled(true);
0620:            }//GEN-LAST:event_jListStylesLibraryValueChanged
0621:
0622:            private void jListStylesLibraryMouseClicked(
0623:                    java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListStylesLibraryMouseClicked
0624:
0625:                if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1) {
0626:                    Object selectedObject = jListStylesLibrary
0627:                            .getSelectedItem();
0628:                    if (selectedObject != null
0629:                            && selectedObject instanceof  Style) {
0630:                        jButtonEditStyleActionPerformed(null);
0631:                    } else if (selectedObject != null
0632:                            && selectedObject instanceof  Template) {
0633:                        jMenuItemEditTemplateActionPerformed(null);
0634:                    }
0635:                }
0636:            }//GEN-LAST:event_jListStylesLibraryMouseClicked
0637:
0638:            private void jMenuItemNewStyleTemplateActionPerformed(
0639:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemNewStyleTemplateActionPerformed
0640:
0641:                try {
0642:                    String fileName = "";
0643:                    javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(
0644:                            MainFrame.getMainInstance().getCurrentDirectory());
0645:
0646:                    jfc.setDialogTitle("New JasperTemplate");
0647:                    jfc.setDialogTitle(it.businesslogic.ireport.util.I18n
0648:                            .getString("style.title.newJasperTemplate",
0649:                                    "New JasperTemplate"));//I18N
0650:
0651:                    jfc.setAcceptAllFileFilterUsed(true);
0652:                    jfc.setFileSelectionMode(jfc.FILES_ONLY);
0653:                    jfc
0654:                            .addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {
0655:                                public boolean accept(java.io.File file) {
0656:                                    String filename = file.getName();
0657:                                    return (filename.toLowerCase().endsWith(
0658:                                            ".jrtx") || file.isDirectory());
0659:                                }
0660:
0661:                                public String getDescription() {
0662:                                    return "*.jrtx";
0663:                                }
0664:                            });
0665:
0666:                    jfc.setDialogType(javax.swing.JFileChooser.SAVE_DIALOG);
0667:                    if (jfc.showOpenDialog(this ) == javax.swing.JOptionPane.OK_OPTION) {
0668:                        java.io.File file = jfc.getSelectedFile();
0669:
0670:                        if (!file.getName().toLowerCase().endsWith(".jrtx")) {
0671:                            file = new File(file + ".jrtx");
0672:                        }
0673:
0674:                        JasperTemplate jt = new JasperTemplate();
0675:                        jt.setFilename(file + "");
0676:                        System.out.println("Saved to " + jt.getFilename());
0677:                        jt.saveTemplateFile();
0678:
0679:                        openedTemplates.add(jt);
0680:
0681:                        ((DefaultMutableTreeNode) libraryTreeModel.getRoot())
0682:                                .add(createTemplateNode(jt));
0683:
0684:                        getActiveList().updateUI();
0685:                    }
0686:                } catch (Exception ex) {
0687:                    ex.printStackTrace();
0688:                }
0689:
0690:            }//GEN-LAST:event_jMenuItemNewStyleTemplateActionPerformed
0691:
0692:            private DefaultMutableTreeNode createTemplateNode(JasperTemplate jt) {
0693:                DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(jt);
0694:                jt.reloadTemplate();
0695:
0696:                for (JasperTemplate template : jt.getTemplates()) {
0697:                    DefaultMutableTreeNode templateNode = new DefaultMutableTreeNode(
0698:                            template);
0699:                    dmtn.add(templateNode);
0700:                }
0701:
0702:                for (TemplateStyle style : jt.getStyles()) {
0703:                    DefaultMutableTreeNode styleNode = new DefaultMutableTreeNode(
0704:                            style);
0705:                    dmtn.add(styleNode);
0706:                }
0707:
0708:                return dmtn;
0709:            }
0710:
0711:            private void jMenuItemNewStyleActionPerformed(
0712:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemNewStyleActionPerformed
0713:                jButtonAddStyleActionPerformed(evt);
0714:            }//GEN-LAST:event_jMenuItemNewStyleActionPerformed
0715:
0716:            private void jMenuItemEditStyleActionPerformed(
0717:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemEditStyleActionPerformed
0718:
0719:                jButtonEditStyleActionPerformed(evt);
0720:
0721:            }//GEN-LAST:event_jMenuItemEditStyleActionPerformed
0722:
0723:            private void jMenuItemRemoveActionPerformed(
0724:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemRemoveActionPerformed
0725:
0726:                if (isListingReportStyles()) {
0727:                    if (getActiveReportFrame() == null)
0728:                        return;
0729:
0730:                    Object selectedObject = getActiveList().getSelectedItem();
0731:                    if (selectedObject == null)
0732:                        return;
0733:                    if (selectedObject instanceof  Template) {
0734:                        Template template = (Template) selectedObject;
0735:                        getActiveReportFrame().getReport().removeTemplate(
0736:                                template);
0737:                        //getActiveReportFrame().getReport().incrementReportChanges();
0738:
0739:                        // Remove from the list...
0740:                        DefaultMutableTreeNode node = Misc
0741:                                .findNodeWithUserObject(
0742:                                        selectedObject,
0743:                                        (DefaultMutableTreeNode) getActiveList()
0744:                                                .getModel().getRoot());
0745:                        ((DefaultTreeModel) getActiveList().getModel())
0746:                                .removeNodeFromParent(node);
0747:                        getActiveList().updateUI();
0748:                    } else if (selectedObject instanceof  Style) {
0749:                        jButtonDeleteStyleActionPerformed(null);
0750:                    }
0751:                } else {
0752:                    Object selectedObject = getActiveList().getSelectedItem();
0753:                    if (selectedObject == null)
0754:                        return;
0755:                    if (selectedObject instanceof  JasperTemplate) {
0756:                        JasperTemplate jt = (JasperTemplate) selectedObject;
0757:                        if (jt.getParent() != null) {
0758:                            JasperTemplate parent = jt.getParent();
0759:                            parent.getTemplates().remove(jt);
0760:                            try {
0761:                                parent.saveTemplateFile();
0762:                            } catch (Exception ex) {
0763:                                ex.printStackTrace();
0764:                            }
0765:                        }
0766:                        DefaultMutableTreeNode node = Misc
0767:                                .findNodeWithUserObject(
0768:                                        selectedObject,
0769:                                        (DefaultMutableTreeNode) getActiveList()
0770:                                                .getModel().getRoot());
0771:                        ((DefaultTreeModel) getActiveList().getModel())
0772:                                .removeNodeFromParent(node);
0773:                        getActiveList().updateUI();
0774:                    } else if (selectedObject instanceof  TemplateStyle) {
0775:                        TemplateStyle ts = (TemplateStyle) selectedObject;
0776:                        if (ts.getJasperTemplate() != null) {
0777:                            JasperTemplate parent = ts.getJasperTemplate();
0778:                            parent.getStyles().remove(ts);
0779:                            try {
0780:                                parent.saveTemplateFile();
0781:                            } catch (Exception ex) {
0782:                                ex.printStackTrace();
0783:                            }
0784:                        }
0785:                        DefaultMutableTreeNode node = Misc
0786:                                .findNodeWithUserObject(
0787:                                        selectedObject,
0788:                                        (DefaultMutableTreeNode) getActiveList()
0789:                                                .getModel().getRoot());
0790:                        ((DefaultTreeModel) getActiveList().getModel())
0791:                                .removeNodeFromParent(node);
0792:                        getActiveList().updateUI();
0793:                    } else {
0794:                        jButtonDeleteStyleActionPerformed(null);
0795:                    }
0796:                }
0797:
0798:            }//GEN-LAST:event_jMenuItemRemoveActionPerformed
0799:
0800:            private void jMenuItemEditTemplateActionPerformed(
0801:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemEditTemplateActionPerformed
0802:
0803:                if (getActiveReportFrame() == null)
0804:                    return;
0805:
0806:                Object selectedObject = getActiveList().getSelectedItem();
0807:                if (selectedObject == null
0808:                        || !(selectedObject instanceof  Template))
0809:                    return;
0810:
0811:                Template template = (Template) selectedObject;
0812:
0813:                JRTemplateDialog td = new JRTemplateDialog(MainFrame
0814:                        .getMainInstance(), true);
0815:                td.setTemplate(template);
0816:                td.setVisible(true);
0817:
0818:                if (td.getDialogResult() == JOptionPane.OK_OPTION) {
0819:                    boolean modified = false;
0820:                    modified = modified
0821:                            || (!template.getExpression().equals(
0822:                                    td.getTemplate().getExpression()));
0823:                    template.setExpression(td.getTemplate().getExpression());
0824:
0825:                    modified = modified
0826:                            || (!template.getExpressionClass().equals(
0827:                                    td.getTemplate().getExpressionClass()));
0828:                    template.setExpressionClass(td.getTemplate()
0829:                            .getExpressionClass());
0830:
0831:                    if (modified) {
0832:                        getActiveReportFrame().getReport()
0833:                                .incrementReportChanges();
0834:                    }
0835:
0836:                    getActiveList().updateUI();
0837:                }
0838:
0839:            }//GEN-LAST:event_jMenuItemEditTemplateActionPerformed
0840:
0841:            private void jMenuItemNewTemplateItemActionPerformed(
0842:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemNewTemplateItemActionPerformed
0843:
0844:                if (getActiveReportFrame() == null)
0845:                    return;
0846:
0847:                JRTemplateDialog td = new JRTemplateDialog(MainFrame
0848:                        .getMainInstance(), true);
0849:
0850:                td.setVisible(true);
0851:
0852:                if (td.getDialogResult() == JOptionPane.OK_OPTION) {
0853:                    Template template = td.getTemplate();
0854:                    // Now we have an old and a new object.
0855:                    // 1. Adjust table...
0856:                    try {
0857:                        DefaultMutableTreeNode node = new DefaultMutableTreeNode(
0858:                                template);
0859:                        ((DefaultMutableTreeNode) jListStyles.getModel()
0860:                                .getRoot()).add(node);
0861:                        jListStyles.updateUI();
0862:                    } catch (Exception ex) {
0863:                        return;
0864:                    }
0865:
0866:                    getActiveReportFrame().getReport().addTemplate(template);
0867:                    getActiveReportFrame().getReport().incrementReportChanges();
0868:                }
0869:            }//GEN-LAST:event_jMenuItemNewTemplateItemActionPerformed
0870:
0871:            private void jMenuItemOpenStyleTemplateActionPerformed(
0872:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItemOpenStyleTemplateActionPerformed
0873:                try {
0874:                    String fileName = "";
0875:                    javax.swing.JFileChooser jfc = new javax.swing.JFileChooser(
0876:                            MainFrame.getMainInstance().getCurrentDirectory());
0877:
0878:                    jfc.setDialogTitle("Open JasperTemplate");
0879:                    jfc.setDialogTitle(it.businesslogic.ireport.util.I18n
0880:                            .getString("style.title.openJasperTemplate",
0881:                                    "Open JasperTemplate"));//I18N
0882:
0883:                    jfc.setAcceptAllFileFilterUsed(true);
0884:                    jfc.setFileSelectionMode(jfc.FILES_ONLY);
0885:                    jfc
0886:                            .addChoosableFileFilter(new javax.swing.filechooser.FileFilter() {
0887:                                public boolean accept(java.io.File file) {
0888:                                    String filename = file.getName();
0889:                                    return (filename.toLowerCase().endsWith(
0890:                                            ".jrtx") || file.isDirectory());
0891:                                }
0892:
0893:                                public String getDescription() {
0894:                                    return "*.jrtx";
0895:                                }
0896:                            });
0897:
0898:                    jfc.setMultiSelectionEnabled(true);
0899:                    jfc.setDialogType(javax.swing.JFileChooser.OPEN_DIALOG);
0900:                    if (jfc.showOpenDialog(this ) == javax.swing.JOptionPane.OK_OPTION) {
0901:                        java.io.File[] files = jfc.getSelectedFiles();
0902:
0903:                        for (int i = 0; i < files.length; ++i) {
0904:                            JasperTemplate jt = new JasperTemplate();
0905:                            jt.setFilename(files[i] + "");
0906:                            openedTemplates.add(jt);
0907:                            ((DefaultMutableTreeNode) libraryTreeModel
0908:                                    .getRoot()).add(createTemplateNode(jt));
0909:                        }
0910:                        getActiveList().updateUI();
0911:                    }
0912:                } catch (Exception ex) {
0913:                    ex.printStackTrace();
0914:                }
0915:            }//GEN-LAST:event_jMenuItemOpenStyleTemplateActionPerformed
0916:
0917:            private void jPopupMenu1PopupMenuWillBecomeVisible(
0918:                    javax.swing.event.PopupMenuEvent evt) {//GEN-FIRST:event_jPopupMenu1PopupMenuWillBecomeVisible
0919:
0920:                Object selectedObject = getActiveList().getSelectedItem();
0921:
0922:                jPopupMenu1.removeAll();
0923:
0924:                if (this .isListingReportStyles()) {
0925:
0926:                    jPopupMenu1.add(jMenuItemNewStyle);
0927:                    jMenuItemNewStyle
0928:                            .setEnabled(getActiveReportFrame() != null);
0929:                    jPopupMenu1.add(jMenuItemNewTemplateItem);
0930:                    jMenuItemNewTemplateItem
0931:                            .setEnabled(getActiveReportFrame() != null);
0932:
0933:                    if (selectedObject != null) {
0934:                        if (selectedObject instanceof  Style) {
0935:                            jMenuItemEditStyle.setEnabled(true);
0936:                            jPopupMenu1.add(jMenuItemEditStyle);
0937:                        } else if (selectedObject instanceof  Template) {
0938:                            jPopupMenu1.add(jMenuItemEditTemplate);
0939:                        }
0940:
0941:                        jMenuItemRemove.setEnabled(true);
0942:                        jPopupMenu1.add(jMenuItemRemove);
0943:                    }
0944:                } else {
0945:                    jMenuItemNewStyle.setEnabled(true);
0946:                    jPopupMenu1.add(jMenuItemNewStyle);
0947:                    jPopupMenu1.add(jMenuItemNewStyleTemplate);
0948:                    jPopupMenu1.add(jMenuItemOpenStyleTemplate);
0949:
0950:                    if (selectedObject != null) {
0951:                        if (selectedObject instanceof  TemplateStyle) {
0952:                            TemplateStyle ts = (TemplateStyle) selectedObject;
0953:                            jPopupMenu1.add(new JSeparator());
0954:                            jPopupMenu1.add(jMenuItemEditStyle);
0955:                            jMenuItemEditStyle.setEnabled(ts
0956:                                    .getJasperTemplate().canWrite());
0957:                            jPopupMenu1.add(jMenuItemRemove);
0958:                            jMenuItemRemove.setEnabled(ts.getJasperTemplate()
0959:                                    .canWrite());
0960:                        } else if (selectedObject instanceof  Style) {
0961:                            jPopupMenu1.add(jMenuItemEditStyle);
0962:                            jPopupMenu1.add(jMenuItemRemove);
0963:                        } else if (selectedObject instanceof  JasperTemplate) {
0964:                            JasperTemplate jt = (JasperTemplate) selectedObject;
0965:                            jPopupMenu1.add(jMenuItemCloseTemplate);
0966:
0967:                            if (jt.getParent() == null) {
0968:                                jPopupMenu1.add(new JSeparator());
0969:                                jPopupMenu1.add(jMenuItemAddStyleToJT);
0970:                                jPopupMenu1.add(jMenuItemAddTemplateToJT);
0971:                            } else {
0972:                                jPopupMenu1.add(new JSeparator());
0973:                                jPopupMenu1.add(jMenuItemEditJTemplate);
0974:                                jMenuItemEditJTemplate.setEnabled(jt
0975:                                        .getParent().canWrite());
0976:                                jPopupMenu1.add(jMenuItemRemove);
0977:                                jMenuItemRemove.setEnabled(jt.getParent()
0978:                                        .canWrite());
0979:                            }
0980:
0981:                            // jPopupMenu1.add(jMenuItemEditStyleTemplate);
0982:
0983:                        }
0984:                    }
0985:                }
0986:
0987:            }//GEN-LAST:event_jPopupMenu1PopupMenuWillBecomeVisible
0988:
0989:            private void jComboBoxStyleTypeActionPerformed(
0990:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxStyleTypeActionPerformed
0991:
0992:                updateStyles();
0993:
0994:            }//GEN-LAST:event_jComboBoxStyleTypeActionPerformed
0995:
0996:            private void jListStylesMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jListStylesMouseClicked
0997:
0998:                if (evt.getClickCount() == 2 && evt.getButton() == evt.BUTTON1) {
0999:                    Object selectedObject = jListStyles.getSelectedItem();
1000:                    if (selectedObject != null
1001:                            && selectedObject instanceof  Style) {
1002:                        jButtonEditStyleActionPerformed(null);
1003:                    } else if (selectedObject != null
1004:                            && selectedObject instanceof  Template) {
1005:                        jMenuItemEditTemplateActionPerformed(null);
1006:                    }
1007:                }
1008:
1009:            }//GEN-LAST:event_jListStylesMouseClicked
1010:
1011:            private void jButtonDeleteStyleActionPerformed(
1012:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDeleteStyleActionPerformed
1013:
1014:                Object selectedObject = getActiveList().getSelectedItem();
1015:                if (selectedObject == null)
1016:                    return;
1017:                if (selectedObject instanceof  TemplateStyle)
1018:                    return;
1019:                if (selectedObject instanceof  Template)
1020:                    return;
1021:
1022:                if (selectedObject instanceof  Style) {
1023:
1024:                    Style irc = null;
1025:                    try {
1026:                        irc = (Style) selectedObject;
1027:
1028:                    } catch (Exception ex) {
1029:                        return;
1030:                    }
1031:
1032:                    if (javax.swing.JOptionPane.showConfirmDialog(this , I18n
1033:                            .getString("messages.stylesDialog.removingStyle",
1034:                                    "Do you want really remove this style?"),
1035:                            "", javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
1036:                            javax.swing.JOptionPane.QUESTION_MESSAGE) == javax.swing.JOptionPane.YES_OPTION) {
1037:                        if (!isListingReportStyles()) {
1038:                            MainFrame.getMainInstance().getStyleLibrarySet()
1039:                                    .remove(irc);
1040:                            MainFrame.getMainInstance().saveStyleLibrary();
1041:                            DefaultTreeModel dtm = (DefaultTreeModel) getActiveList()
1042:                                    .getModel();
1043:                            dtm
1044:                                    .removeNodeFromParent((MutableTreeNode) getActiveList()
1045:                                            .getSelectionPath()
1046:                                            .getLastPathComponent());
1047:                        } else {
1048:                            Report report = MainFrame.getMainInstance()
1049:                                    .getActiveReportFrame().getReport();
1050:                            report.removeStyle(irc);
1051:                        }
1052:                    }
1053:                }
1054:            }//GEN-LAST:event_jButtonDeleteStyleActionPerformed
1055:
1056:            private void jButtonEditStyleActionPerformed(
1057:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonEditStyleActionPerformed
1058:
1059:                Object selectedObject = getActiveList().getSelectedItem();
1060:                if (selectedObject == null)
1061:                    return;
1062:                if (!(selectedObject instanceof  Style))
1063:                    return;
1064:
1065:                StyleDialog cd = new StyleDialog(MainFrame.getMainInstance(),
1066:                        true);
1067:
1068:                // Take the selected style from the table...
1069:                DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) getActiveList()
1070:                        .getSelectionPath().getLastPathComponent();
1071:
1072:                Style irc = (Style) selectedObject; //jListStyles.getSelectedValue();
1073:                cd.setStyle(irc);
1074:
1075:                cd.setLibraryStyle(!isListingReportStyles());
1076:
1077:                if (irc instanceof  TemplateStyle) {
1078:                    TemplateStyle ts = (TemplateStyle) irc;
1079:                    if (ts.getJasperTemplate().getParent() != null
1080:                            || !ts.getJasperTemplate().canWrite()) {
1081:                        cd.setReadOnly(true);
1082:                    }
1083:                }
1084:
1085:                if (irc instanceof  UndefinedStyle) {
1086:                    cd.setLibraryStyle(true);
1087:                    cd.setReadOnly(true);
1088:                }
1089:
1090:                cd.setVisible(true);
1091:
1092:                if (cd.getDialogResult() == JOptionPane.OK_OPTION) {
1093:                    Style sub = cd.getStyle();
1094:                    // Now we have an old and a new object.
1095:                    // 1. Adjust table...
1096:                    try {
1097:                        // getListModel().setElementAt(sub, index);
1098:                        selectedNode.setUserObject(sub);
1099:                        getActiveList().updateUI();
1100:                    } catch (Exception ex) {
1101:                        return;
1102:                    }
1103:
1104:                    if (selectedObject instanceof  TemplateStyle) {
1105:                        try {
1106:                            ((it.businesslogic.ireport.TemplateStyle) selectedObject)
1107:                                    .getJasperTemplate().saveTemplateFile();
1108:                        } catch (Exception ex) {
1109:                            ex.printStackTrace();
1110:                        }
1111:                    } else if (!isListingReportStyles()) {
1112:                        MainFrame.getMainInstance().saveStyleLibrary();
1113:                    }
1114:                    getActiveList().updateUI();
1115:                }
1116:
1117:            }//GEN-LAST:event_jButtonEditStyleActionPerformed
1118:
1119:            private void jButtonAddStyleActionPerformed(
1120:                    java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonAddStyleActionPerformed
1121:
1122:                StyleDialog cd = new StyleDialog(MainFrame.getMainInstance(),
1123:                        true);
1124:
1125:                if (!isListingReportStyles()) {
1126:                    cd.setLibraryStyle(true);
1127:                } else {
1128:                    if (getActiveReportFrame() == null)
1129:                        return;
1130:                }
1131:
1132:                cd.setVisible(true);
1133:
1134:                if (cd.getDialogResult() == JOptionPane.OK_OPTION
1135:                        && cd.isLibraryStyle()) {
1136:                    // If we are editing/adding a library style, no events are fire, so we have
1137:                    // to handle the new style by our self...
1138:                    // The new style should be already present in library.
1139:                    //getListModel().addElement( cd.getStyle() );
1140:                    DefaultMutableTreeNode dmtn = new DefaultMutableTreeNode(cd
1141:                            .getStyle());
1142:                    ((DefaultMutableTreeNode) getActiveList().getModel()
1143:                            .getRoot()).add(dmtn);
1144:                    getActiveList().updateUI();
1145:                    MainFrame.getMainInstance().saveStyleLibrary();
1146:                }
1147:
1148:            }//GEN-LAST:event_jButtonAddStyleActionPerformed
1149:
1150:            public void languageChanged(LanguageChangedEvent evt) {
1151:
1152:                jButtonAddStyle.setToolTipText(I18n.getString(
1153:                        "gui.style.newStyle", "New Style"));
1154:                jButtonEditStyle.setToolTipText(I18n.getString(
1155:                        "gui.style.editStyle", "Edit Style"));
1156:                jButtonDeleteStyle.setToolTipText(I18n.getString(
1157:                        "gui.style.deleteStyle", "Delete Style"));
1158:
1159:                jMenuItemNewStyle.setText(I18n.getString("gui.style.newStyle",
1160:                        "New Style"));
1161:                jMenuItemEditStyle.setText(I18n.getString(
1162:                        "gui.style.editStyle", "Edit Style"));
1163:                jMenuItemRemove.setText(I18n.getString("gui.style.remove",
1164:                        "Remove"));
1165:
1166:                jMenuItemNewTemplateItem.setText(I18n.getString(
1167:                        "gui.style.newTemaplateItem", "New Template Item"));
1168:                jMenuItemEditTemplate.setText(I18n.getString(
1169:                        "gui.style.editTemaplateItem", "Edit Template Item"));
1170:
1171:                for (int i = 0; i < jComboBoxStyleType.getItemCount(); ++i) {
1172:                    Tag t = (Tag) jComboBoxStyleType.getItemAt(i);
1173:                    if (t.getName().equals("reportStyles"))
1174:                        t.setName(I18n
1175:                                .getString("gui.style.types.reportStyles",
1176:                                        "Report Styles"));
1177:                    else if (t.getName().equals("libraryStyles"))
1178:                        t.setName(I18n.getString(
1179:                                "gui.style.types.libraryStyles",
1180:                                "Styles Library"));
1181:
1182:                }
1183:
1184:            }
1185:
1186:            public void reportFrameActivated(ReportFrameActivatedEvent evt) {
1187:                setActiveReportFrame(evt.getReportFrame());
1188:            }
1189:
1190:            public JReportFrame getActiveReportFrame() {
1191:                return activeReportFrame;
1192:            }
1193:
1194:            public void setActiveReportFrame(JReportFrame newActiveReportFrame) {
1195:
1196:                if (newActiveReportFrame != this .activeReportFrame) {
1197:                    if (this .activeReportFrame != null) {
1198:                        this .activeReportFrame.getReport()
1199:                                .removeStyleChangedListener(this );
1200:                    }
1201:                } else {
1202:                    return;
1203:                }
1204:
1205:                this .activeReportFrame = newActiveReportFrame;
1206:
1207:                if (this .activeReportFrame != null) {
1208:                    this .activeReportFrame.getReport().addStyleChangedListener(
1209:                            this );
1210:                }
1211:
1212:                refreshReportStyles();
1213:
1214:            }
1215:
1216:            public void updateStyles() {
1217:                //((DefaultMutableTreeNode)jListStyles.getModel().getRoot()).removeAllChildren();
1218:
1219:                jListStyles.setShowLibrary(!isListingReportStyles());
1220:
1221:                if (((Tag) jComboBoxStyleType.getSelectedItem()).getValue()
1222:                        .equals("libraryStyles")) {
1223:                    remove(jScrollPaneReportList);
1224:                    add(jScrollPaneLibraryList, BorderLayout.CENTER);
1225:
1226:                    jListStylesLibraryValueChanged(null);
1227:
1228:                    //jListStyles.setModel(libraryTreeModel);
1229:                    // load library styles....
1230:
1231:                    /*
1232:                    for (JasperTemplate jt : openedTemplates)
1233:                    {
1234:                       DefaultMutableTreeNode node = new DefaultMutableTreeNode( jt );
1235:                        ((DefaultMutableTreeNode)jListStyles.getModel().getRoot()).add(node); 
1236:                    }
1237:                     */
1238:                } else if (((Tag) jComboBoxStyleType.getSelectedItem())
1239:                        .getValue().equals("reportStyles")) {
1240:                    remove(jScrollPaneLibraryList);
1241:                    add(jScrollPaneReportList, BorderLayout.CENTER);
1242:
1243:                    jListStylesValueChanged(null);
1244:                }
1245:
1246:                updateUI();
1247:            }
1248:
1249:            /*
1250:            protected DefaultListModel getListModel() {
1251:                return listModel;
1252:            }
1253:
1254:            protected void setListModel(DefaultListModel listModel) {
1255:                this.listModel = listModel;
1256:            }
1257:             */
1258:
1259:            public void styleChanged(StyleChangedEvent evt) {
1260:
1261:                if (evt.getSource() == this )
1262:                    return;
1263:                refreshReportStyles();
1264:            }
1265:
1266:            public void templateChanged(TemplateChangedEvent evt) {
1267:
1268:                if (evt.getSource() == this )
1269:                    return;
1270:                refreshReportStyles();
1271:            }
1272:
1273:            /**
1274:             * Return true if the currently displayed list refers to the report styles
1275:             * False = displaying library styles (currently not modifiables...)
1276:             */
1277:            public boolean isListingReportStyles() {
1278:                Tag t = (Tag) jComboBoxStyleType.getSelectedItem();
1279:
1280:                if (t != null && t.getValue().equals("reportStyles")) {
1281:                    return true;
1282:                }
1283:
1284:                return false;
1285:            }
1286:
1287:            // Variables declaration - do not modify//GEN-BEGIN:variables
1288:            private javax.swing.JButton jButtonAddStyle;
1289:            private javax.swing.JButton jButtonDeleteStyle;
1290:            private javax.swing.JButton jButtonEditStyle;
1291:            private javax.swing.JComboBox jComboBoxStyleType;
1292:            private it.businesslogic.ireport.gui.style.JBGTree jListStyles;
1293:            private it.businesslogic.ireport.gui.style.JBGTree jListStylesLibrary;
1294:            private javax.swing.JMenuItem jMenuItemAddStyleToJT;
1295:            private javax.swing.JMenuItem jMenuItemAddTemplateToJT;
1296:            private javax.swing.JMenuItem jMenuItemCloseTemplate;
1297:            private javax.swing.JMenuItem jMenuItemEditJTemplate;
1298:            private javax.swing.JMenuItem jMenuItemEditStyle;
1299:            private javax.swing.JMenuItem jMenuItemEditTemplate;
1300:            private javax.swing.JMenuItem jMenuItemNewStyle;
1301:            private javax.swing.JMenuItem jMenuItemNewStyleTemplate;
1302:            private javax.swing.JMenuItem jMenuItemNewTemplateItem;
1303:            private javax.swing.JMenuItem jMenuItemOpenStyleTemplate;
1304:            private javax.swing.JMenuItem jMenuItemRemove;
1305:            private javax.swing.JPanel jPanel1;
1306:            private javax.swing.JPopupMenu jPopupMenu1;
1307:            private javax.swing.JScrollPane jScrollPaneLibraryList;
1308:            private javax.swing.JScrollPane jScrollPaneReportList;
1309:            private javax.swing.JScrollPane jScrollPaneReportList1;
1310:            private javax.swing.JToolBar jToolBar1;
1311:
1312:            // End of variables declaration//GEN-END:variables
1313:
1314:            public void applyI18n() {
1315:                // Start autogenerated code ----------------------
1316:                // End autogenerated code ----------------------
1317:            }
1318:
1319:            public JBGTree getActiveList() {
1320:                return (isListingReportStyles()) ? jListStyles
1321:                        : jListStylesLibrary;
1322:            }
1323:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.