Example usage for java.awt Component RIGHT_ALIGNMENT

List of usage examples for java.awt Component RIGHT_ALIGNMENT

Introduction

In this page you can find the example usage for java.awt Component RIGHT_ALIGNMENT.

Prototype

float RIGHT_ALIGNMENT

To view the source code for java.awt Component RIGHT_ALIGNMENT.

Click Source Link

Document

Ease-of-use constant for getAlignmentX .

Usage

From source file:op.care.med.inventory.PnlInventory.java

private CollapsiblePane createCP4(final MedInventory inventory) {
    /***//from   www . j  a v a 2s.  c  o  m
     *                          _        ____ ____  _  _    _____                      _                 __
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |  / /_ _|_ ____   _____ _ __ | |_ ___  _ __ _   \ \
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_| | | || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | | |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _| | | || | | \ V /  __/ | | | || (_) | |  | |_| | |
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_| | ||___|_| |_|\_/ \___|_| |_|\__\___/|_|   \__, | |
     *                                                     \_\                                       |___/_/
     */
    final String key = inventory.getID() + ".xinventory";
    synchronized (cpMap) {
        if (!cpMap.containsKey(key)) {
            cpMap.put(key, new CollapsiblePane());
            try {
                cpMap.get(key).setCollapsed(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }

        }

        cpMap.get(key).setName("inventory");

        //            final CollapsiblePane cpInventory = cpMap.get(key);

        BigDecimal sumInventory = BigDecimal.ZERO;
        try {
            EntityManager em = OPDE.createEM();
            sumInventory = MedInventoryTools.getSum(em, inventory);
            em.close();
        } catch (Exception e) {
            OPDE.fatal(e);
        }

        String title = "<html><table border=\"0\">" + "<tr>" +

                "<td width=\"520\" align=\"left\"><font size=+1>" + inventory.getText() + "</font></td>"
                + "<td width=\"200\" align=\"right\"><font size=+1>"
                + NumberFormat.getNumberInstance().format(sumInventory) + " "
                + DosageFormTools.getPackageText(MedInventoryTools.getForm(inventory)) + "</font></td>" +

                "</tr>" + "</table>" +

                "</html>";

        DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    cpMap.get(key).setCollapsed(!cpMap.get(key).isCollapsed());
                } catch (PropertyVetoException pve) {
                    // BAH!
                }
            }
        });
        cpMap.get(key).setTitleLabelComponent(cptitle.getMain());
        cpMap.get(key).setSlidingDirection(SwingConstants.SOUTH);
        cptitle.getButton().setIcon(inventory.isClosed() ? SYSConst.icon22stopSign : null);

        if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, "nursingrecords.inventory")) {
            /***
             *       ____ _                ___                      _
             *      / ___| | ___  ___  ___|_ _|_ ____   _____ _ __ | |_ ___  _ __ _   _
             *     | |   | |/ _ \/ __|/ _ \| || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | |
             *     | |___| | (_) \__ \  __/| || | | \ V /  __/ | | | || (_) | |  | |_| |
             *      \____|_|\___/|___/\___|___|_| |_|\_/ \___|_| |_|\__\___/|_|   \__, |
             *                                                                    |___/
             */
            final JButton btnCloseInventory = new JButton(SYSConst.icon22playerStop);
            btnCloseInventory.setPressedIcon(SYSConst.icon22playerStopPressed);
            btnCloseInventory.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnCloseInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnCloseInventory.setContentAreaFilled(false);
            btnCloseInventory.setBorder(null);
            btnCloseInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btncloseinventory.tooltip"));
            btnCloseInventory.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    new DlgYesNo(
                            SYSTools.xx("nursingrecords.inventory.question.close1") + "<br/><b>"
                                    + inventory.getText() + "</b>" + "<br/>"
                                    + SYSTools.xx("nursingrecords.inventory.question.close2"),
                            SYSConst.icon48playerStop, new Closure() {
                                @Override
                                public void execute(Object answer) {
                                    if (answer.equals(JOptionPane.YES_OPTION)) {
                                        EntityManager em = OPDE.createEM();
                                        try {
                                            em.getTransaction().begin();

                                            MedInventory myInventory = em.merge(inventory);
                                            em.lock(myInventory, LockModeType.OPTIMISTIC);
                                            em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC);

                                            // close all stocks
                                            for (MedStock stock : MedStockTools.getAll(myInventory)) {
                                                if (!stock.isClosed()) {
                                                    MedStock mystock = em.merge(stock);
                                                    em.lock(mystock, LockModeType.OPTIMISTIC);
                                                    mystock.setNextStock(null);
                                                    MedStockTools.close(em, mystock, SYSTools.xx(
                                                            "nursingrecords.inventory.stock.msg.inventory_closed"),
                                                            MedStockTransactionTools.STATE_EDIT_INVENTORY_CLOSED);
                                                }
                                            }
                                            // close inventory
                                            myInventory.setTo(new Date());

                                            em.getTransaction().commit();

                                            createCP4(myInventory);
                                            buildPanel();
                                        } catch (OptimisticLockException ole) {
                                            OPDE.warn(ole);
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                                OPDE.getMainframe().emptyFrame();
                                                OPDE.getMainframe().afterLogin();
                                            }
                                            OPDE.getDisplayManager()
                                                    .addSubMessage(DisplayManager.getLockMessage());
                                        } catch (Exception e) {
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            OPDE.fatal(e);
                                        } finally {
                                            em.close();
                                        }
                                    }
                                }
                            });
                }
            });
            btnCloseInventory.setEnabled(!inventory.isClosed());
            cptitle.getRight().add(btnCloseInventory);
        }
        if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, "nursingrecords.inventory")) {
            /***
             *      ____       _ ___                      _
             *     |  _ \  ___| |_ _|_ ____   _____ _ __ | |_ ___  _ __ _   _
             *     | | | |/ _ \ || || '_ \ \ / / _ \ '_ \| __/ _ \| '__| | | |
             *     | |_| |  __/ || || | | \ V /  __/ | | | || (_) | |  | |_| |
             *     |____/ \___|_|___|_| |_|\_/ \___|_| |_|\__\___/|_|   \__, |
             *                                                          |___/
             */
            final JButton btnDelInventory = new JButton(SYSConst.icon22delete);
            btnDelInventory.setPressedIcon(SYSConst.icon22deletePressed);
            btnDelInventory.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnDelInventory.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnDelInventory.setContentAreaFilled(false);
            btnDelInventory.setBorder(null);
            btnDelInventory.setToolTipText(SYSTools.xx("nursingrecords.inventory.btndelinventory.tooltip"));
            btnDelInventory.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    new DlgYesNo(
                            SYSTools.xx("nursingrecords.inventory.question.delete1") + "<br/><b>"
                                    + inventory.getText() + "</b>" + "<br/>"
                                    + SYSTools.xx("nursingrecords.inventory.question.delete2"),
                            SYSConst.icon48delete, new Closure() {
                                @Override
                                public void execute(Object answer) {
                                    if (answer.equals(JOptionPane.YES_OPTION)) {
                                        EntityManager em = OPDE.createEM();
                                        try {
                                            em.getTransaction().begin();

                                            MedInventory myInventory = em.merge(inventory);
                                            em.lock(myInventory, LockModeType.OPTIMISTIC);
                                            em.lock(myInventory.getResident(), LockModeType.OPTIMISTIC);

                                            em.remove(myInventory);

                                            em.getTransaction().commit();

                                            //                                        lstInventories.remove(inventory);
                                            buildPanel();
                                        } catch (OptimisticLockException ole) {
                                            OPDE.warn(ole);
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                                OPDE.getMainframe().emptyFrame();
                                                OPDE.getMainframe().afterLogin();
                                            }
                                            OPDE.getDisplayManager()
                                                    .addSubMessage(DisplayManager.getLockMessage());
                                        } catch (Exception e) {
                                            if (em.getTransaction().isActive()) {
                                                em.getTransaction().rollback();
                                            }
                                            OPDE.fatal(e);
                                        } finally {
                                            em.close();
                                        }
                                    }
                                }
                            });
                }
            });
            cptitle.getRight().add(btnDelInventory);
        }

        final JToggleButton tbClosedStock = GUITools.getNiceToggleButton(null);
        tbClosedStock.setToolTipText(SYSTools.xx("nursingrecords.inventory.showclosedstocks"));
        if (!inventory.isClosed()) {
            tbClosedStock.addItemListener(new ItemListener() {
                @Override
                public void itemStateChanged(ItemEvent e) {
                    cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected()));
                }
            });
        }
        tbClosedStock.setSelected(inventory.isClosed());
        tbClosedStock.setEnabled(!inventory.isClosed());

        mapKey2ClosedToggleButton.put(key, tbClosedStock);

        cptitle.getRight().add(tbClosedStock);

        CollapsiblePaneAdapter adapter = new CollapsiblePaneAdapter() {
            @Override
            public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
                cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected()));
            }
        };
        synchronized (cpListener) {
            if (cpListener.containsKey(key)) {
                cpMap.get(key).removeCollapsiblePaneListener(cpListener.get(key));
            }
            cpListener.put(key, adapter);
            cpMap.get(key).addCollapsiblePaneListener(adapter);
        }

        if (!cpMap.get(key).isCollapsed()) {
            cpMap.get(key).setContentPane(createContentPanel4(inventory, tbClosedStock.isSelected()));
        }

        cpMap.get(key).setHorizontalAlignment(SwingConstants.LEADING);
        cpMap.get(key).setOpaque(false);
        cpMap.get(key).setBackground(getColor(SYSConst.medium2, lstInventories.indexOf(inventory) % 2 != 0));

        return cpMap.get(key);
    }
}

From source file:op.care.supervisor.PnlHandover.java

private CollapsiblePane createCP4Day(final LocalDate day) {
    final String key = DateFormat.getDateInstance().format(day.toDate());
    synchronized (cpMap) {
        if (!cpMap.containsKey(key)) {
            cpMap.put(key, new CollapsiblePane());
            try {
                cpMap.get(key).setCollapsed(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace();/* w w w. java2 s.  c  o m*/
            }
        }
    }
    final CollapsiblePane cpDay = cpMap.get(key);
    if (hollidays == null) {
        hollidays = SYSCalendar.getHolidays(day.getYear(), day.getYear());
    }
    String titleDay = "<html><font size=+1>" + dayFormat.format(day.toDate())
            + SYSTools.catchNull(hollidays.get(day), " (", ")") + "</font></html>";
    final DefaultCPTitle titleCPDay = new DefaultCPTitle(titleDay, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                cpDay.setCollapsed(!cpDay.isCollapsed());
            } catch (PropertyVetoException pve) {
                // BAH!
            }
        }
    });

    final JButton btnAcknowledge = new JButton(SYSConst.icon163ledGreenOn);
    btnAcknowledge.setAlignmentX(Component.RIGHT_ALIGNMENT);
    btnAcknowledge.setToolTipText(SYSTools.xx("nursingrecords.handover.tooltips.btnAcknowledge"));
    btnAcknowledge.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            EntityManager em = OPDE.createEM();
            try {
                em.getTransaction().begin();

                synchronized (cacheHO) {
                    ArrayList<Handovers> listHO = new ArrayList<Handovers>(cacheHO.get(key));
                    for (final Handovers ho : listHO) {
                        if (!Handover2UserTools.containsUser(em, ho, OPDE.getLogin().getUser())) {
                            Handovers myHO = em.merge(ho);
                            Handover2User connObj = em
                                    .merge(new Handover2User(myHO, em.merge(OPDE.getLogin().getUser())));
                            myHO.getUsersAcknowledged().add(connObj);
                        }
                    }
                }

                synchronized (cacheNR) {
                    ArrayList<NReport> listNR = new ArrayList<NReport>(cacheNR.get(key));
                    for (final NReport nreport : listNR) {
                        if (!NR2UserTools.containsUser(em, nreport, OPDE.getLogin().getUser())) {
                            NReport myNR = em.merge(nreport);
                            NR2User connObj = em.merge(new NR2User(myNR, em.merge(OPDE.getLogin().getUser())));
                            myNR.getUsersAcknowledged().add(connObj);
                        }
                    }
                }

                em.getTransaction().commit();
                createCP4Day(day);
                buildPanel();
            } catch (OptimisticLockException ole) {
                OPDE.warn(ole);
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                    OPDE.getMainframe().emptyFrame();
                    OPDE.getMainframe().afterLogin();
                }
                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
            } catch (Exception e) {
                if (em.getTransaction().isActive()) {
                    em.getTransaction().rollback();
                }
                OPDE.fatal(e);
            } finally {
                em.close();
            }

        }

    });
    titleCPDay.getRight().add(btnAcknowledge);

    cpDay.setTitleLabelComponent(titleCPDay.getMain());
    cpDay.setSlidingDirection(SwingConstants.SOUTH);

    if (hollidays.containsKey(day)) {
        cpDay.setBackground(SYSConst.red1[SYSConst.medium1]);
    } else if (day.getDayOfWeek() == DateTimeConstants.SATURDAY
            || day.getDayOfWeek() == DateTimeConstants.SUNDAY) {
        cpDay.setBackground(SYSConst.red1[SYSConst.light3]);
    } else {
        cpDay.setBackground(SYSConst.orange1[SYSConst.light3]);
    }
    cpDay.setOpaque(true);

    cpDay.setHorizontalAlignment(SwingConstants.LEADING);
    cpDay.setStyle(CollapsiblePane.PLAIN_STYLE);
    cpDay.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            createContentPanel4Day(day, cpDay);
            btnAcknowledge.setEnabled(true);
        }

        @Override
        public void paneCollapsed(CollapsiblePaneEvent collapsiblePaneEvent) {
            btnAcknowledge.setEnabled(false);
        }
    });

    btnAcknowledge.setEnabled(!cpDay.isCollapsed());
    if (!cpDay.isCollapsed()) {
        createContentPanel4Day(day, cpDay);
    }

    return cpDay;
}

From source file:greenfoot.gui.export.ExportPublishPane.java

/**
 * Creates the scenario information display including information such as title, description, url.
 * For an update (isUpdate = true), the displayed options are slightly different.
 *///w  w w.  j ava  2s .c o  m
private void createScenarioDisplay() {
    leftPanel = new Box(BoxLayout.Y_AXIS);
    JLabel text;
    MiksGridLayout titleAndDescLayout = new MiksGridLayout(6, 2, 8, 8);
    titleAndDescLayout.setVerticallyExpandingRow(3);

    titleAndDescPanel = new JPanel(titleAndDescLayout);
    titleAndDescPanel.setBackground(background);

    if (imagePanel == null) {
        imagePanel = new ImageEditPanel(IMAGE_WIDTH, IMAGE_HEIGHT);
        imagePanel.setBackground(background);
    }

    Box textPanel = new Box(BoxLayout.Y_AXIS);
    {
        text = new JLabel(Config.getString("export.publish.image1"));
        text.setAlignmentX(Component.RIGHT_ALIGNMENT);
        text.setFont(font);
        textPanel.add(text);
        text = new JLabel(Config.getString("export.publish.image2"));
        text.setAlignmentX(Component.RIGHT_ALIGNMENT);
        text.setFont(font);
        textPanel.add(text);
    }
    titleAndDescPanel.add(textPanel);
    titleAndDescPanel.add(imagePanel);

    if (isUpdate) {
        text = new JLabel(Config.getString("export.snapshot.label"), SwingConstants.TRAILING);
        text.setFont(font);
        titleAndDescPanel.add(text);

        keepScenarioScreenshot = new JCheckBox();
        keepScenarioScreenshot.setSelected(true);
        // "keep screenshot" defaults to true, therefore the image panel should be disabled
        imagePanel.enableImageEditPanel(false);
        keepScenarioScreenshot.setName(Config.getString("export.publish.keepScenario"));
        keepScenarioScreenshot.setOpaque(false);
        keepScenarioScreenshot.addChangeListener(this);
        titleAndDescPanel.add(keepScenarioScreenshot);
    }

    text = new JLabel(Config.getString("export.publish.title"), SwingConstants.TRAILING);
    text.setFont(font);
    titleAndDescPanel.add(text);

    String title = project.getName();
    if (getTitle() != null) {
        title = getTitle();
    }
    titleField = new JTextField(title);
    titleField.setInputVerifier(new InputVerifier() {
        @Override
        public boolean verify(JComponent input) {
            String text = titleField.getText();
            return text.length() > 0;
        }
    });
    titleField.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            checkForExistingScenario();
        }
    });
    titleAndDescPanel.add(titleField);

    // If there is an update a "changes" description area is shown.
    // If not there a short description and long description area are shown.
    if (isUpdate) {
        JLabel updateLabel = new JLabel(Config.getString("export.publish.update"), SwingConstants.TRAILING);
        updateLabel.setVerticalAlignment(SwingConstants.TOP);
        updateLabel.setFont(font);

        updateArea = new JTextArea();
        updateArea.setRows(6);
        updateArea.setLineWrap(true);
        updateArea.setWrapStyleWord(true);
        JScrollPane updatePane = new JScrollPane(updateArea);

        titleAndDescPanel.add(updateLabel);
        titleAndDescPanel.add(updatePane);
        titleAndDescLayout.setVerticallyExpandingRow(4);
    } else {
        text = new JLabel(Config.getString("export.publish.shortDescription"), SwingConstants.TRAILING);
        text.setFont(font);
        shortDescriptionField = new JTextField();
        titleAndDescPanel.add(text);
        titleAndDescPanel.add(shortDescriptionField);
        text = new JLabel(Config.getString("export.publish.longDescription"), SwingConstants.TRAILING);
        text.setVerticalAlignment(SwingConstants.TOP);
        text.setFont(font);

        descriptionArea = new JTextArea();
        descriptionArea.setRows(6);
        descriptionArea.setLineWrap(true);
        descriptionArea.setWrapStyleWord(true);
        JScrollPane description = new JScrollPane(descriptionArea);
        titleAndDescPanel.add(text);
        titleAndDescPanel.add(description);
    }

    text = new JLabel(Config.getString("export.publish.url"), SwingConstants.TRAILING);
    text.setFont(font);
    titleAndDescPanel.add(text);

    urlField = new JTextField();
    titleAndDescPanel.add(urlField);

    leftPanel.add(titleAndDescPanel, BorderLayout.SOUTH);

    JComponent sourceAndLockPanel = new JPanel(new FlowLayout(FlowLayout.CENTER, 8, 0));
    {
        sourceAndLockPanel.setBackground(background);
        includeSource = new JCheckBox(Config.getString("export.publish.includeSource"));
        includeSource.setOpaque(false);
        includeSource.setSelected(false);
        includeSource.setFont(font);
        sourceAndLockPanel.add(includeSource);
        lockScenario.setFont(font);
        sourceAndLockPanel.add(lockScenario);
        sourceAndLockPanel.setMaximumSize(sourceAndLockPanel.getPreferredSize());
    }

    leftPanel.add(sourceAndLockPanel, BorderLayout.SOUTH);
}

From source file:op.care.values.PnlValues.java

private JPanel createContentPanel4Year(final ResValueTypes vtype, final int year) {
    final String keyYears = vtype.getID() + ".xtypes." + Integer.toString(year) + ".year";

    java.util.List<ResValue> myValues;
    synchronized (mapType2Values) {
        if (!mapType2Values.containsKey(keyYears)) {
            mapType2Values.put(keyYears, ResValueTools.getResValues(resident, vtype, year));
        }//from   w  ww .  j a v a  2  s  . c  om
        if (mapType2Values.get(keyYears).isEmpty()) {
            JLabel lbl = new JLabel(SYSTools.xx("misc.msg.novalue"));
            JPanel pnl = new JPanel();
            pnl.add(lbl);
            return pnl;
        }
        myValues = mapType2Values.get(keyYears);
    }

    JPanel pnlYear = new JPanel(new VerticalLayout());

    pnlYear.setOpaque(false);

    for (final ResValue resValue : myValues) {
        String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"200\" align=\"left\">"
                + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT).format(resValue.getPit())
                + " [" + resValue.getID() + "]</td>" + "<td width=\"340\" align=\"left\">"
                + ResValueTools.getValueAsHTML(resValue) + "</td>" + "<td width=\"200\" align=\"left\">"
                + resValue.getUser().getFullname() + "</td>" + "</tr>" + "</table>" + "</html>";

        final DefaultCPTitle pnlTitle = new DefaultCPTitle(title, null);

        pnlTitle.getMain().setBackground(GUITools.blend(vtype.getColor(), Color.WHITE, 0.1f));
        pnlTitle.getMain().setOpaque(true);

        if (resValue.isObsolete()) {
            pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22eraser));
        }
        if (resValue.isReplacement()) {
            pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22edited));
        }
        if (!resValue.getText().trim().isEmpty()) {
            pnlTitle.getAdditionalIconPanel().add(new JLabel(SYSConst.icon22info));
        }
        if (pnlTitle.getAdditionalIconPanel().getComponentCount() > 0) {
            pnlTitle.getButton().addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    GUITools.showPopup(
                            GUITools.getHTMLPopup(pnlTitle.getButton(), ResValueTools.getInfoAsHTML(resValue)),
                            SwingConstants.NORTH);
                }
            });
        }

        if (!resValue.getAttachedFilesConnections().isEmpty()) {
            /***
             *      _     _         _____ _ _
             *     | |__ | |_ _ __ |  ___(_) | ___  ___
             *     | '_ \| __| '_ \| |_  | | |/ _ \/ __|
             *     | |_) | |_| | | |  _| | | |  __/\__ \
             *     |_.__/ \__|_| |_|_|   |_|_|\___||___/
             *
             */
            final JButton btnFiles = new JButton(
                    Integer.toString(resValue.getAttachedFilesConnections().size()), SYSConst.icon22greenStar);
            btnFiles.setToolTipText(SYSTools.xx("misc.btnfiles.tooltip"));
            btnFiles.setForeground(Color.BLUE);
            btnFiles.setHorizontalTextPosition(SwingUtilities.CENTER);
            btnFiles.setFont(SYSConst.ARIAL18BOLD);
            btnFiles.setPressedIcon(SYSConst.icon22Pressed);
            btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnFiles.setAlignmentY(Component.TOP_ALIGNMENT);
            btnFiles.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnFiles.setContentAreaFilled(false);
            btnFiles.setBorder(null);

            btnFiles.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    new DlgFiles(resValue, new Closure() {
                        @Override
                        public void execute(Object o) {
                            EntityManager em = OPDE.createEM();
                            final ResValue myValue = em.find(ResValue.class, resValue.getID());
                            em.close();

                            synchronized (mapType2Values) {
                                mapType2Values.get(keyYears).remove(resValue);
                                mapType2Values.get(keyYears).add(myValue);
                                Collections.sort(mapType2Values.get(keyYears));
                            }

                            createCP4Year(vtype, year);
                            buildPanel();
                        }
                    });
                }
            });
            btnFiles.setEnabled(OPDE.isFTPworking());
            pnlTitle.getRight().add(btnFiles);
        }

        if (!resValue.getAttachedProcessConnections().isEmpty()) {
            /***
             *      _     _         ____
             *     | |__ | |_ _ __ |  _ \ _ __ ___   ___ ___  ___ ___
             *     | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __|
             *     | |_) | |_| | | |  __/| | | (_) | (_|  __/\__ \__ \
             *     |_.__/ \__|_| |_|_|   |_|  \___/ \___\___||___/___/
             *
             */
            final JButton btnProcess = new JButton(
                    Integer.toString(resValue.getAttachedProcessConnections().size()), SYSConst.icon22redStar);
            btnProcess.setToolTipText(SYSTools.xx("misc.btnprocess.tooltip"));
            btnProcess.setForeground(Color.YELLOW);
            btnProcess.setHorizontalTextPosition(SwingUtilities.CENTER);
            btnProcess.setFont(SYSConst.ARIAL18BOLD);
            btnProcess.setPressedIcon(SYSConst.icon22Pressed);
            btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnProcess.setAlignmentY(Component.TOP_ALIGNMENT);
            btnProcess.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnProcess.setContentAreaFilled(false);
            btnProcess.setBorder(null);
            btnProcess.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    new DlgProcessAssign(resValue, new Closure() {
                        @Override
                        public void execute(Object o) {
                            if (o == null) {
                                return;
                            }
                            Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o;

                            ArrayList<QProcess> assigned = result.getFirst();
                            ArrayList<QProcess> unassigned = result.getSecond();

                            EntityManager em = OPDE.createEM();

                            try {
                                em.getTransaction().begin();

                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                ResValue myValue = em.merge(resValue);
                                em.lock(myValue, LockModeType.OPTIMISTIC_FORCE_INCREMENT);

                                ArrayList<SYSVAL2PROCESS> attached = new ArrayList<SYSVAL2PROCESS>(
                                        resValue.getAttachedProcessConnections());
                                for (SYSVAL2PROCESS linkObject : attached) {
                                    if (unassigned.contains(linkObject.getQProcess())) {
                                        linkObject.getQProcess().getAttachedNReportConnections()
                                                .remove(linkObject);
                                        linkObject.getResValue().getAttachedProcessConnections()
                                                .remove(linkObject);
                                        em.merge(new PReport(
                                                SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": "
                                                        + myValue.getTitle() + " ID: " + myValue.getID(),
                                                PReportTools.PREPORT_TYPE_REMOVE_ELEMENT,
                                                linkObject.getQProcess()));
                                        em.remove(linkObject);
                                    }
                                }
                                attached.clear();

                                for (QProcess qProcess : assigned) {
                                    java.util.List<QProcessElement> listElements = qProcess.getElements();
                                    if (!listElements.contains(myValue)) {
                                        QProcess myQProcess = em.merge(qProcess);
                                        SYSVAL2PROCESS myLinkObject = em
                                                .merge(new SYSVAL2PROCESS(myQProcess, myValue));
                                        em.merge(new PReport(
                                                SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": "
                                                        + myValue.getTitle() + " ID: " + myValue.getID(),
                                                PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess));
                                        qProcess.getAttachedResValueConnections().add(myLinkObject);
                                        myValue.getAttachedProcessConnections().add(myLinkObject);
                                    }
                                }

                                em.getTransaction().commit();

                                synchronized (mapType2Values) {
                                    mapType2Values.get(keyYears).remove(resValue);
                                    mapType2Values.get(keyYears).add(myValue);
                                    Collections.sort(mapType2Values.get(keyYears));
                                }
                                createCP4Year(vtype, year);

                                buildPanel();

                            } catch (OptimisticLockException ole) {
                                OPDE.warn(ole);
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                }
                                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            } catch (RollbackException ole) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                    OPDE.getMainframe().emptyFrame();
                                    OPDE.getMainframe().afterLogin();
                                }
                                OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                            } catch (Exception e) {
                                if (em.getTransaction().isActive()) {
                                    em.getTransaction().rollback();
                                }
                                OPDE.fatal(e);
                            } finally {
                                em.close();
                            }
                        }
                    });
                }
            });
            btnProcess.setEnabled(OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID));
            pnlTitle.getRight().add(btnProcess);
        }
        /***
         *      __  __
         *     |  \/  | ___ _ __  _   _
         *     | |\/| |/ _ \ '_ \| | | |
         *     | |  | |  __/ | | | |_| |
         *     |_|  |_|\___|_| |_|\__,_|
         *
         */
        final JButton btnMenu = new JButton(SYSConst.icon22menu);
        btnMenu.setPressedIcon(SYSConst.icon22Pressed);
        btnMenu.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnMenu.setAlignmentY(Component.TOP_ALIGNMENT);
        btnMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        btnMenu.setContentAreaFilled(false);
        btnMenu.setBorder(null);
        btnMenu.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JidePopup popup = new JidePopup();
                popup.setMovable(false);
                popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS));
                popup.setOwner(btnMenu);
                popup.removeExcludedComponent(btnMenu);
                JPanel pnl = getMenu(resValue);
                popup.getContentPane().add(pnl);
                popup.setDefaultFocusComponent(pnl);

                GUITools.showPopup(popup, SwingConstants.WEST);
            }
        });
        btnMenu.setEnabled(!resValue.isObsolete());
        pnlTitle.getRight().add(btnMenu);

        pnlYear.add(pnlTitle.getMain());
        synchronized (linemap) {
            linemap.put(resValue, pnlTitle.getMain());
        }
    }
    return pnlYear;
}

From source file:op.allowance.PnlAllowance.java

private CollapsiblePane createCP4(final Resident resident, final LocalDate month) {
    final String key = getKey(resident, month);
    if (!cpMap.containsKey(key)) {
        cpMap.put(key, new CollapsiblePane());
        try {//from  ww  w .j  a  va2s  . c om
            cpMap.get(key).setCollapsed(true);
        } catch (PropertyVetoException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

    }
    final CollapsiblePane cpMonth = cpMap.get(key);

    if (!carrySums.containsKey(key)) {
        carrySums.put(key, AllowanceTools.getSUM(resident, SYSCalendar.eom(month)));
    }

    String title = "<html><table border=\"0\">" + "<tr>" +

            "<td width=\"520\" align=\"left\">" + monthFormatter.format(month.toDate()) + "</td>"
            + "<td width=\"200\" align=\"right\">"
            + (carrySums.get(key).compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "")
            + cf.format(carrySums.get(key))
            + (carrySums.get(key).compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>"
            + "</table>" +

            "</font></html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                cpMonth.setCollapsed(!cpMonth.isCollapsed());
            } catch (PropertyVetoException pve) {
                // BAH!
            }
        }
    });

    /***
     *      ____       _       _   __  __             _   _
     *     |  _ \ _ __(_)_ __ | |_|  \/  | ___  _ __ | |_| |__
     *     | |_) | '__| | '_ \| __| |\/| |/ _ \| '_ \| __| '_ \
     *     |  __/| |  | | | | | |_| |  | | (_) | | | | |_| | | |
     *     |_|   |_|  |_|_| |_|\__|_|  |_|\___/|_| |_|\__|_| |_|
     *
     */
    final JButton btnPrintMonth = new JButton(SYSConst.icon22print2);
    btnPrintMonth.setPressedIcon(SYSConst.icon22print2Pressed);
    btnPrintMonth.setAlignmentX(Component.RIGHT_ALIGNMENT);
    btnPrintMonth.setContentAreaFilled(false);
    btnPrintMonth.setBorder(null);
    btnPrintMonth.setToolTipText(SYSTools.xx("misc.tooltips.btnprintmonth"));
    btnPrintMonth.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            if (!cashmap.containsKey(key)) {
                cashmap.put(key, AllowanceTools.getMonth(resident, month.toDate()));
            }

            final BigDecimal carry4print = AllowanceTools.getSUM(resident,
                    SYSCalendar.eom(month.minusMonths(1)));
            SYSFilesTools.print(AllowanceTools.getAsHTML(cashmap.get(key), carry4print, resident), true);
        }
    });

    cptitle.getRight().add(btnPrintMonth);

    cpMonth.setTitleLabelComponent(cptitle.getMain());
    cpMonth.setSlidingDirection(SwingConstants.SOUTH);

    cpMonth.setBackground(getBG(resident, 10));

    /***
     *           _ _      _            _                                       _   _
     *       ___| (_) ___| | _____  __| |   ___  _ __    _ __ ___   ___  _ __ | |_| |__
     *      / __| | |/ __| |/ / _ \/ _` |  / _ \| '_ \  | '_ ` _ \ / _ \| '_ \| __| '_ \
     *     | (__| | | (__|   <  __/ (_| | | (_) | | | | | | | | | | (_) | | | | |_| | | |
     *      \___|_|_|\___|_|\_\___|\__,_|  \___/|_| |_| |_| |_| |_|\___/|_| |_|\__|_| |_|
     *
     */
    cpMonth.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {

            cpMonth.setContentPane(createContentPanel4(resident, month));
            cpMonth.setOpaque(false);
        }
    });

    if (!cpMonth.isCollapsed()) {
        cpMonth.setContentPane(createContentPanel4(resident, month));
    }

    cpMonth.setHorizontalAlignment(SwingConstants.LEADING);
    cpMonth.setOpaque(false);

    return cpMonth;
}

From source file:op.care.dfn.PnlDFN.java

private CollapsiblePane createCP4(final DFN dfn) {
    final CollapsiblePane dfnPane = new CollapsiblePane();

    ActionListener applyActionListener = new ActionListener() {
        @Override// w  ww. ja  v a2s  .  co  m
        public void actionPerformed(ActionEvent actionEvent) {
            if (dfn.getState() == DFNTools.STATE_DONE) {
                return;
            }
            if (!dfn.isOnDemand() && dfn.getNursingProcess().isClosed()) {
                return;
            }

            if (DFNTools.isChangeable(dfn)) {
                EntityManager em = OPDE.createEM();
                try {
                    em.getTransaction().begin();

                    em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                    DFN myDFN = em.merge(dfn);
                    em.lock(myDFN, LockModeType.OPTIMISTIC);
                    if (!myDFN.isOnDemand()) {
                        em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                    }

                    myDFN.setState(DFNTools.STATE_DONE);
                    myDFN.setUser(em.merge(OPDE.getLogin().getUser()));
                    myDFN.setIst(new Date());
                    myDFN.setiZeit(SYSCalendar.whatTimeIDIs(new Date()));
                    myDFN.setMdate(new Date());

                    em.getTransaction().commit();

                    CollapsiblePane cp1 = createCP4(myDFN);

                    synchronized (mapDFN2Pane) {
                        mapDFN2Pane.put(myDFN, cp1);
                    }
                    synchronized (mapShift2DFN) {
                        int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                        mapShift2DFN.get(myDFN.getShift()).remove(position);
                        mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                    }

                    CollapsiblePane cp2 = createCP4(myDFN.getShift());
                    synchronized (mapShift2Pane) {
                        mapShift2Pane.put(myDFN.getShift(), cp2);
                    }

                    buildPanel(false);

                } catch (OptimisticLockException ole) {
                    OPDE.warn(ole);
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                        OPDE.getMainframe().emptyFrame();
                        OPDE.getMainframe().afterLogin();
                    }
                    OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                } catch (Exception e) {
                    if (em.getTransaction().isActive()) {
                        em.getTransaction().rollback();
                    }
                    OPDE.fatal(e);
                } finally {
                    em.close();
                }

            } else {
                OPDE.getDisplayManager()
                        .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
            }
        }
    };

    String title = "<html><font size=+1>" +
    //                (dfn.isFloating() ? (dfn.isActive() ? "(!) " : "(OK) ") : "") +
            SYSTools.left(dfn.getIntervention().getBezeichnung(), MAX_TEXT_LENGTH)
            + DFNTools.getScheduleText(dfn, " [", "]") + ", " + dfn.getMinutes() + " "
            + SYSTools.xx("misc.msg.Minute(s)")
            + (dfn.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(dfn.getUser().getUID()) + "</i>" : "")
            + "</font></html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title,
            OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? applyActionListener
                    : null);
    dfnPane.setCollapseOnTitleClick(false);
    //        cptitle.getTitleButton().setIcon(DFNTools.getIcon(dfn));
    JLabel icon1 = new JLabel(DFNTools.getIcon(dfn));
    icon1.setOpaque(false);
    JLabel icon2 = new JLabel(DFNTools.getFloatingIcon(dfn));
    icon2.setOpaque(false);
    cptitle.getAdditionalIconPanel().add(icon1);
    cptitle.getAdditionalIconPanel().add(icon2);

    if (dfn.isFloating()) {
        cptitle.getButton().setToolTipText(SYSTools.xx("nursingrecords.dfn.enforced.tooltip") + ": "
                + DateFormat.getDateInstance().format(dfn.getStDatum()));
    }

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)
            && (dfn.isOnDemand() || !dfn.getNursingProcess().isClosed())) {
        /***
         *      _     _            _                _
         *     | |__ | |_ _ __    / \   _ __  _ __ | |_   _
         *     | '_ \| __| '_ \  / _ \ | '_ \| '_ \| | | | |
         *     | |_) | |_| | | |/ ___ \| |_) | |_) | | |_| |
         *     |_.__/ \__|_| |_/_/   \_\ .__/| .__/|_|\__, |
         *                             |_|   |_|      |___/
         */
        JButton btnApply = new JButton(SYSConst.icon22apply);
        btnApply.setPressedIcon(SYSConst.icon22applyPressed);
        btnApply.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnApply.setContentAreaFilled(false);
        btnApply.setBorder(null);
        btnApply.addActionListener(applyActionListener);
        btnApply.setEnabled(!dfn.isOnDemand() && dfn.isOpen());
        cptitle.getRight().add(btnApply);
        //            JPanel spacer = new JPanel();
        //            spacer.setOpaque(false);
        //            cptitle.getRight().add(spacer);
        /***
         *      _     _          ____                     _
         *     | |__ | |_ _ __  / ___|__ _ _ __   ___ ___| |
         *     | '_ \| __| '_ \| |   / _` | '_ \ / __/ _ \ |
         *     | |_) | |_| | | | |__| (_| | | | | (_|  __/ |
         *     |_.__/ \__|_| |_|\____\__,_|_| |_|\___\___|_|
         *
         */
        final JButton btnCancel = new JButton(SYSConst.icon22cancel);
        btnCancel.setPressedIcon(SYSConst.icon22cancelPressed);
        btnCancel.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnCancel.setContentAreaFilled(false);
        btnCancel.setBorder(null);
        //            btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip"));
        btnCancel.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (dfn.getState() == DFNTools.STATE_REFUSED) {
                    return;
                }

                if (DFNTools.isChangeable(dfn)) {
                    EntityManager em = OPDE.createEM();
                    try {
                        em.getTransaction().begin();

                        em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                        DFN myDFN = em.merge(dfn);
                        em.lock(myDFN, LockModeType.OPTIMISTIC);
                        if (!myDFN.isOnDemand()) {
                            em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                        }

                        myDFN.setState(DFNTools.STATE_REFUSED);
                        myDFN.setUser(em.merge(OPDE.getLogin().getUser()));
                        myDFN.setIst(new Date());
                        myDFN.setiZeit(SYSCalendar.whatTimeIDIs(new Date()));
                        myDFN.setMdate(new Date());

                        em.getTransaction().commit();

                        CollapsiblePane cp1 = createCP4(myDFN);
                        synchronized (mapDFN2Pane) {
                            mapDFN2Pane.put(myDFN, cp1);
                        }
                        synchronized (mapShift2DFN) {
                            int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                            mapShift2DFN.get(myDFN.getShift()).remove(position);
                            mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                        }
                        CollapsiblePane cp2 = createCP4(myDFN.getShift());
                        synchronized (mapShift2Pane) {
                            mapShift2Pane.put(myDFN.getShift(), cp2);
                        }
                        buildPanel(false);
                    } catch (OptimisticLockException ole) {
                        OPDE.warn(ole);
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                            OPDE.getMainframe().emptyFrame();
                            OPDE.getMainframe().afterLogin();
                        }
                        OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                    } catch (Exception e) {
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        OPDE.fatal(e);
                    } finally {
                        em.close();
                    }

                } else {
                    OPDE.getDisplayManager()
                            .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
                }
            }
        });
        btnCancel.setEnabled(!dfn.isOnDemand() && dfn.isOpen());
        cptitle.getRight().add(btnCancel);

        /***
         *      _     _         _____                 _
         *     | |__ | |_ _ __ | ____|_ __ ___  _ __ | |_ _   _
         *     | '_ \| __| '_ \|  _| | '_ ` _ \| '_ \| __| | | |
         *     | |_) | |_| | | | |___| | | | | | |_) | |_| |_| |
         *     |_.__/ \__|_| |_|_____|_| |_| |_| .__/ \__|\__, |
         *                                     |_|        |___/
         */
        final JButton btnEmpty = new JButton(SYSConst.icon22empty);
        btnEmpty.setPressedIcon(SYSConst.icon22emptyPressed);
        btnEmpty.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnEmpty.setContentAreaFilled(false);
        btnEmpty.setBorder(null);
        //            btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip"));
        btnEmpty.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (dfn.getState() == DFNTools.STATE_OPEN) {
                    return;
                }

                if (DFNTools.isChangeable(dfn)) {
                    EntityManager em = OPDE.createEM();
                    try {
                        em.getTransaction().begin();

                        em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                        DFN myDFN = em.merge(dfn);
                        em.lock(myDFN, LockModeType.OPTIMISTIC);
                        if (!myDFN.isOnDemand()) {
                            em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                        }

                        // on demand DFNs are deleted if they not wanted anymore
                        if (myDFN.isOnDemand()) {
                            em.remove(myDFN);
                            synchronized (mapDFN2Pane) {
                                mapDFN2Pane.remove(myDFN);
                            }
                            synchronized (mapShift2DFN) {
                                mapShift2DFN.get(myDFN.getShift()).remove(myDFN);
                            }
                        } else {
                            // the normal DFNs (those assigned to a NursingProcess) are reset to the OPEN state.
                            myDFN.setState(DFNTools.STATE_OPEN);
                            myDFN.setUser(null);
                            myDFN.setIst(null);
                            myDFN.setiZeit(null);
                            myDFN.setMdate(new Date());
                            CollapsiblePane cp1 = createCP4(myDFN);
                            synchronized (mapDFN2Pane) {
                                mapDFN2Pane.put(myDFN, cp1);
                            }
                            synchronized (mapShift2DFN) {
                                int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                                mapShift2DFN.get(myDFN.getShift()).remove(position);
                                mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                            }
                        }
                        em.getTransaction().commit();

                        CollapsiblePane cp2 = createCP4(myDFN.getShift());
                        synchronized (mapShift2Pane) {
                            mapShift2Pane.put(myDFN.getShift(), cp2);
                        }
                        buildPanel(false);
                    } catch (OptimisticLockException ole) {
                        OPDE.warn(ole);
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                            OPDE.getMainframe().emptyFrame();
                            OPDE.getMainframe().afterLogin();
                        }
                        OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                    } catch (Exception e) {
                        if (em.getTransaction().isActive()) {
                            em.getTransaction().rollback();
                        }
                        OPDE.fatal(e);
                    } finally {
                        em.close();
                    }

                } else {
                    OPDE.getDisplayManager()
                            .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
                }
            }
        });
        btnEmpty.setEnabled(!dfn.isOpen());
        cptitle.getRight().add(btnEmpty);

        /***
         *      _     _         __  __ _             _
         *     | |__ | |_ _ __ |  \/  (_)_ __  _   _| |_ ___  ___
         *     | '_ \| __| '_ \| |\/| | | '_ \| | | | __/ _ \/ __|
         *     | |_) | |_| | | | |  | | | | | | |_| | ||  __/\__ \
         *     |_.__/ \__|_| |_|_|  |_|_|_| |_|\__,_|\__\___||___/
         *
         */
        final JButton btnMinutes = new JButton(SYSConst.icon22clock);
        btnMinutes.setPressedIcon(SYSConst.icon22clockPressed);
        btnMinutes.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnMinutes.setContentAreaFilled(false);
        btnMinutes.setBorder(null);
        //            btnCancel.setToolTipText(SYSTools.xx("nursingrecords.dfn.btneval.tooltip"));
        btnMinutes.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                if (!DFNTools.isChangeable(dfn)) {
                    OPDE.getDisplayManager()
                            .addSubMessage(new DisplayMessage(SYSTools.xx("nursingrecords.dfn.notchangeable")));
                    return;
                }
                final JPopupMenu menu = SYSCalendar.getMinutesMenu(
                        new int[] { 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60, 120, 240, 360 }, new Closure() {
                            @Override
                            public void execute(Object o) {
                                EntityManager em = OPDE.createEM();
                                try {
                                    em.getTransaction().begin();

                                    em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                    DFN myDFN = em.merge(dfn);
                                    em.lock(myDFN, LockModeType.OPTIMISTIC);
                                    if (!myDFN.isOnDemand()) {
                                        em.lock(myDFN.getNursingProcess(), LockModeType.OPTIMISTIC);
                                    }

                                    myDFN.setMinutes(new BigDecimal((Integer) o));
                                    myDFN.setUser(em.merge(OPDE.getLogin().getUser()));
                                    myDFN.setMdate(new Date());
                                    em.getTransaction().commit();

                                    CollapsiblePane cp1 = createCP4(myDFN);
                                    synchronized (mapDFN2Pane) {
                                        mapDFN2Pane.put(myDFN, cp1);
                                    }
                                    synchronized (mapShift2DFN) {
                                        int position = mapShift2DFN.get(myDFN.getShift()).indexOf(myDFN);
                                        mapShift2DFN.get(myDFN.getShift()).remove(position);
                                        mapShift2DFN.get(myDFN.getShift()).add(position, myDFN);
                                    }
                                    CollapsiblePane cp2 = createCP4(myDFN.getShift());
                                    synchronized (mapShift2Pane) {
                                        mapShift2Pane.put(myDFN.getShift(), cp2);
                                    }

                                    buildPanel(false);
                                } catch (OptimisticLockException ole) {
                                    OPDE.warn(ole);
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                        OPDE.getMainframe().emptyFrame();
                                        OPDE.getMainframe().afterLogin();
                                    }
                                    OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                                } catch (Exception e) {
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    OPDE.fatal(e);
                                } finally {
                                    em.close();
                                }
                            }
                        });

                menu.show(btnMinutes, 0, btnMinutes.getHeight());
            }
        });
        btnMinutes.setEnabled(dfn.getState() != DFNTools.STATE_OPEN);
        cptitle.getRight().add(btnMinutes);
    }

    /***
     *      _     _         ___        __
     *     | |__ | |_ _ __ |_ _|_ __  / _| ___
     *     | '_ \| __| '_ \ | || '_ \| |_ / _ \
     *     | |_) | |_| | | || || | | |  _| (_) |
     *     |_.__/ \__|_| |_|___|_| |_|_|  \___/
     *
     */
    final JButton btnInfo = new JButton(SYSConst.icon22info);
    final JidePopup popupInfo = new JidePopup();
    btnInfo.setPressedIcon(SYSConst.icon22infoPressed);
    btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT);
    btnInfo.setContentAreaFilled(false);
    btnInfo.setBorder(null);
    final JTextPane txt = new JTextPane();
    txt.setContentType("text/html");
    txt.setEditable(false);

    popupInfo.setMovable(false);
    popupInfo.getContentPane().setLayout(new BoxLayout(popupInfo.getContentPane(), BoxLayout.LINE_AXIS));
    popupInfo.getContentPane().add(new JScrollPane(txt));
    popupInfo.removeExcludedComponent(txt);
    popupInfo.setDefaultFocusComponent(txt);

    btnInfo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            popupInfo.setOwner(btnInfo);
            txt.setText(SYSTools.toHTML(SYSConst.html_div(dfn.getInterventionSchedule().getBemerkung())));
            GUITools.showPopup(popupInfo, SwingConstants.WEST);
        }
    });

    btnInfo.setEnabled(
            !dfn.isOnDemand() && !SYSTools.catchNull(dfn.getInterventionSchedule().getBemerkung()).isEmpty());
    cptitle.getRight().add(btnInfo);

    dfnPane.setTitleLabelComponent(cptitle.getMain());

    dfnPane.setBackground(dfn.getBG());
    dfnPane.setForeground(dfn.getFG());
    try {
        dfnPane.setCollapsed(true);
    } catch (PropertyVetoException e) {
        OPDE.error(e);
    }
    dfnPane.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            JTextPane contentPane = new JTextPane();
            contentPane.setContentType("text/html");
            contentPane.setEditable(false);
            contentPane.setText(SYSTools
                    .toHTML(NursingProcessTools.getAsHTML(dfn.getNursingProcess(), false, true, false, false)));
            dfnPane.setContentPane(contentPane);
        }
    });
    dfnPane.setCollapsible(dfn.getNursingProcess() != null);
    dfnPane.setHorizontalAlignment(SwingConstants.LEADING);
    dfnPane.setOpaque(false);
    return dfnPane;
}

From source file:org.neuroph.netbeans.main.easyneurons.NeuralGraphRenderer.java

/**
 * @param jp//  www .  ja  v a  2s  . com
 *            panel to which controls will be added
 */
protected void addControls(final JPanel jp) {
    final JPanel control_panel = new JPanel();
    jp.add(control_panel, BorderLayout.EAST);

    control_panel.setLayout(new GridBagLayout());

    java.awt.GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;

    // control_panel.setBackground(new Color(00, 255, 00));

    final Box vertex_panel = Box.createVerticalBox();
    vertex_panel.setBorder(BorderFactory.createTitledBorder("Neurons"));
    final Box edge_panel = Box.createVerticalBox();
    edge_panel.setBorder(BorderFactory.createTitledBorder("Connections"));

    final Box edges_and_vertex_panel = Box.createVerticalBox();
    // Box zoom_and_mode_panel = Box.createVerticalBox();
    // zoom_and_mode_panel.setBorder(BorderFactory.createTitledBorder("Other controls"));
    //      final Box layout_panel = Box.createVerticalBox();
    //      layout_panel.setBorder(BorderFactory.createTitledBorder("Layout"));
    // JPanel zoom_and_mode_panel = new JPanel();
    // zoom_and_mode_panel.setLayout(new GridBagLayout() );
    // //GridLayout(3,1)
    // zoom_and_mode_panel.setBackground(new Color(0,255,0));

    edges_and_vertex_panel.add(vertex_panel);
    edges_and_vertex_panel.add(edge_panel);
    // edges_and_vertex_panel.add(layout_panel);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    control_panel.add(edges_and_vertex_panel, gridBagConstraints);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    //      control_panel.add(layout_panel, gridBagConstraints);

    // originalni layout
    // control_panel.add(vertex_panel, BorderLayout.WEST);
    // control_panel.add(edge_panel, BorderLayout.EAST);
    // control_panel.add(edges_and_vertex_panel, BorderLayout.CENTER);

    // set up vertex controls
    v_color = new JCheckBox("vertex seed coloring");
    v_color.addActionListener(this);
    //      v_stroke = new JCheckBox("<html>stroke highlight selected</html>");
    //      v_stroke.addActionListener(this);

    v_shape = new JCheckBox("vertex degree shapes");
    v_shape.addActionListener(this);
    v_size = new JCheckBox("activation size");
    v_size.addActionListener(this);
    v_size.setSelected(false);
    v_aspect = new JCheckBox("vertex degree ratio stretch");
    v_aspect.addActionListener(this);
    v_small = new JCheckBox("filter vertices of degree < " + VertexDisplayPredicate.MIN_DEGREE);
    v_small.addActionListener(this);

    // vertex_panel.add(v_color);

    vertex_panel.add(v_labels);
    // vertex_panel.add(v_shape);
    vertex_panel.add(v_size);
    // vertex_panel.add(v_aspect);
    // vertex_panel.add(v_small);
    // vertex_panel.add(v_stroke);

    // set up edge controls
    // JPanel gradient_panel = new JPanel(new GridLayout(1, 0));
    // gradient_panel.setBorder(BorderFactory.createTitledBorder("Edge paint"));
    // no_gradient = new JRadioButton("Solid color");
    // no_gradient.addActionListener(this);
    // no_gradient.setSelected(true);
    // // gradient_absolute = new JRadioButton("Absolute gradient");
    // // gradient_absolute.addActionListener(this);
    // gradient_relative = new JRadioButton("Gradient");
    // gradient_relative.addActionListener(this);
    // ButtonGroup bg_grad = new ButtonGroup();
    // bg_grad.add(no_gradient);
    // bg_grad.add(gradient_relative);
    // //bg_grad.add(gradient_absolute);
    // gradient_panel.add(no_gradient);
    // //gradientGrid.add(gradient_absolute);
    // gradient_panel.add(gradient_relative);

    //      JPanel shape_panel = new JPanel(new GridLayout(3, 2));
    //      shape_panel.setBorder(BorderFactory
    //            .createTitledBorder("Connection shape"));
    //      e_line = new JRadioButton("line");
    //      e_line.addActionListener(this);
    //      e_line.setSelected(true);
    //      // e_bent = new JRadioButton("bent line");
    //      // e_bent.addActionListener(this);
    //      e_wedge = new JRadioButton("wedge");
    //      e_wedge.addActionListener(this);
    //      e_quad = new JRadioButton("quad curve");
    //      e_quad.addActionListener(this);
    //      e_cubic = new JRadioButton("cubic curve");
    //      e_cubic.addActionListener(this);
    //      ButtonGroup bg_shape = new ButtonGroup();
    //      bg_shape.add(e_line);
    //      // bg.add(e_bent);
    //      bg_shape.add(e_wedge);
    //      bg_shape.add(e_quad);
    //      bg_shape.add(e_cubic);
    //      shape_panel.add(e_line);
    //      // shape_panel.add(e_bent);
    //      // shape_panel.add(e_wedge);
    //      shape_panel.add(e_quad);
    //      shape_panel.add(e_cubic);
    //      // fill_edges = new JCheckBox("fill edge shapes");
    //      // fill_edges.setSelected(false);
    //      // fill_edges.addActionListener(this);
    //      // shape_panel.add(fill_edges);
    //      shape_panel.setOpaque(true);
    e_color = new JCheckBox("weight highlighting");
    e_color.addActionListener(this);
    e_uarrow_pred = new JCheckBox("undirected");
    e_uarrow_pred.addActionListener(this);
    e_darrow_pred = new JCheckBox("directed");
    e_darrow_pred.addActionListener(this);
    e_darrow_pred.setSelected(true);
    // JPanel arrow_panel = new JPanel(new GridLayout(1,0));
    // arrow_panel.setBorder(BorderFactory.createTitledBorder("Show arrows"));
    // arrow_panel.add(e_uarrow_pred);
    // arrow_panel.add(e_darrow_pred);

    e_show_d = new JCheckBox("directed");
    e_show_d.addActionListener(this);
    e_show_d.setSelected(true);
    e_show_u = new JCheckBox("undirected");
    e_show_u.addActionListener(this);
    e_show_u.setSelected(true);
    JPanel show_edge_panel = new JPanel(new GridLayout(1, 0));
    show_edge_panel.setBorder(BorderFactory.createTitledBorder("Show edges"));
    show_edge_panel.add(e_show_u);
    show_edge_panel.add(e_show_d);

    //      shape_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    //      edge_panel.add(shape_panel);
    // gradient_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // edge_panel.add(gradient_panel);
    // show_edge_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // edge_panel.add(show_edge_panel);
    // arrow_panel.setAlignmentX(Component.LEFT_ALIGNMENT);
    // edge_panel.add(arrow_panel);

    e_color.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(e_color);
    e_labels.setAlignmentX(Component.LEFT_ALIGNMENT);
    edge_panel.add(e_labels);

    //      Class<?>[] combos = getLayoutOptions();
    //      final JComboBox layoutCombo = new JComboBox(combos);
    //      // use a renderer to shorten the layout name presentation
    //      layoutCombo.setRenderer(new DefaultListCellRenderer() {
    //         public Component getListCellRendererComponent(JList list,
    //               Object value, int index, boolean isSelected,
    //               boolean cellHasFocus) {
    //            String valueString = value.toString();
    //            valueString = valueString.substring(valueString
    //                  .lastIndexOf('.') + 1);
    //            return super.getListCellRendererComponent(list, valueString,
    //                  index, isSelected, cellHasFocus);
    //         }
    //      });
    //      layoutCombo.addActionListener(new LayoutChooser(layoutCombo, vv));
    //// UNDO:      layoutCombo.setSelectedItem(FRLayout.class);
    //      layout_panel.add(layoutCombo);

    // set up zoom controls
    zoom_at_mouse = new JCheckBox("<html><center>zoom at mouse<p>(wheel only)</center></html>");
    zoom_at_mouse.addActionListener(this);

    final ScalingControl scaler = new CrossoverScalingControl();

    JButton plus = new JButton("+");
    plus.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    JButton minus = new JButton("-");
    minus.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            scaler.scale(vv, 1 / 1.1f, vv.getCenter());
        }
    });

    JPanel zoomPanel = new JPanel();
    zoomPanel.setAlignmentX(Component.RIGHT_ALIGNMENT);
    zoomPanel.setBorder(BorderFactory.createTitledBorder("Zoom"));
    zoomPanel.add(plus);
    zoomPanel.add(minus);

    gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
    gridBagConstraints.insets = new java.awt.Insets(5, 5, 0, 5);
    gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;

    JComboBox modeBox = graphMouse.getModeComboBox();
    modeBox.setAlignmentX(Component.RIGHT_ALIGNMENT);

    JPanel modePanel = new JPanel(new BorderLayout()) {
        @Override
        public Dimension getMaximumSize() {
            return getPreferredSize();
        }
    };
    modePanel.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    modePanel.add(modeBox);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 2;
    control_panel.add(modePanel, gridBagConstraints);

    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 3;
    control_panel.add(zoomPanel, gridBagConstraints);

    // add font control to center panel
    font = new JCheckBox("bold text");
    font.addActionListener(this);
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 4;
    control_panel.add(font, gridBagConstraints);
}

From source file:op.users.PnlUser.java

private CollapsiblePane createCP4(final Groups group) {
    final String key = group.getGID() + ".xgroups";
    if (!cpMap.containsKey(key)) {
        cpMap.put(key, new CollapsiblePane());
        cpMap.get(key).setSlidingDirection(SwingConstants.SOUTH);

        cpMap.get(key).setBackground(bg);
        cpMap.get(key).setForeground(fg);

        cpMap.get(key).addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
            @Override/*  w ww. j  a v  a2s .  c o m*/
            public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
                if (!contentMap.containsKey(key)) {
                    contentMap.put(key, createContentPanel4(group));
                }
                cpMap.get(key).setContentPane(contentMap.get(key));
            }
        });
        cpMap.get(key).setHorizontalAlignment(SwingConstants.LEADING);
        cpMap.get(key).setOpaque(false);
        try {
            cpMap.get(key).setCollapsed(true);
        } catch (PropertyVetoException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

    }
    final CollapsiblePane cp = cpMap.get(key);

    DefaultCPTitle cpTitle = new DefaultCPTitle("<html><font size=+1>" + group.getGID().toUpperCase()
            + (group.isQualified() ? ", " + SYSTools.xx("opde.users.qualifiedGroup") : "") + "</font></html>",
            new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    try {
                        cp.setCollapsed(!cp.isCollapsed());
                    } catch (PropertyVetoException pve) {
                        // BAH!
                    }
                }
            });

    /***
     *          _      _      _
     *       __| | ___| | ___| |_ ___    __ _ _ __ ___  _   _ _ __
     *      / _` |/ _ \ |/ _ \ __/ _ \  / _` | '__/ _ \| | | | '_ \
     *     | (_| |  __/ |  __/ ||  __/ | (_| | | | (_) | |_| | |_) |
     *      \__,_|\___|_|\___|\__\___|  \__, |_|  \___/ \__,_| .__/
     *                                  |___/                |_|
     */
    final JButton btnDeleteGroup = new JButton(SYSConst.icon22delete);
    btnDeleteGroup.setPressedIcon(SYSConst.icon22deletePressed);
    btnDeleteGroup.setAlignmentX(Component.RIGHT_ALIGNMENT);
    btnDeleteGroup.setContentAreaFilled(false);
    btnDeleteGroup.setBorder(null);
    btnDeleteGroup.setToolTipText(SYSTools.xx("opde.users.btnDeleteGroup"));
    btnDeleteGroup.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            new DlgYesNo(SYSTools.xx("misc.questions.delete1") + "<br/><i>" + group.getGID() + "</i><br/>"
                    + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() {
                        @Override
                        public void execute(Object o) {
                            if (o.equals(JOptionPane.YES_OPTION)) {
                                EntityManager em = OPDE.createEM();
                                try {
                                    em.getTransaction().begin();
                                    Groups myGroup = em.merge(group);
                                    em.remove(myGroup);
                                    em.getTransaction().commit();
                                    lstGroups.remove(group);
                                    cpMap.remove(key);
                                    buildPanel();
                                } catch (OptimisticLockException ole) {
                                    OPDE.warn(ole);
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                        OPDE.getMainframe().emptyFrame();
                                        OPDE.getMainframe().afterLogin();
                                    }
                                    OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                                } catch (Exception e) {
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    OPDE.fatal(e);
                                } finally {
                                    em.close();
                                }
                            }
                        }
                    });

        }

    });
    btnDeleteGroup.setEnabled(!group.isSystem());
    cpTitle.getRight().add(btnDeleteGroup);

    cp.setTitleLabelComponent(cpTitle.getMain());

    if (!cp.isCollapsed()) {
        if (!contentMap.containsKey(key)) {
            contentMap.put(key, createContentPanel4(group));
        }
        cp.setContentPane(contentMap.get(key));
    }

    return cp;
}

From source file:op.care.reports.PnlReport.java

private CollapsiblePane createCP4Month(final LocalDate month) {
    /***//www  .jav  a2  s. co m
     *                          _        ____ ____     __                      __  __  ___  _   _ _____ _   _
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \   / _| ___  _ __    __ _  |  \/  |/ _ \| \ | |_   _| | | |
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | | |_ / _ \| '__|  / _` | | |\/| | | | |  \| | | | | |_| |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/  |  _| (_) | |    | (_| | | |  | | |_| | |\  | | | |  _  |
     *      \___|_|  \___|\__,_|\__\___|\____|_|     |_|  \___/|_|     \__,_| |_|  |_|\___/|_| \_| |_| |_| |_|
     *
     */
    final String key = monthFormatter.format(month.toDate()) + ".month";
    synchronized (cpMap) {
        if (!cpMap.containsKey(key)) {
            cpMap.put(key, new CollapsiblePane());
            try {
                cpMap.get(key).setCollapsed(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
            }

        }
    }
    final CollapsiblePane cpMonth = cpMap.get(key);

    String title = "<html><font size=+1><b>" + monthFormatter.format(month.toDate()) + "</b>"
            + "</font></html>";

    DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                cpMonth.setCollapsed(!cpMonth.isCollapsed());
            } catch (PropertyVetoException pve) {
                // BAH!
            }
        }
    });

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.PRINT, internalClassID)) {
        /***
         *      ____       _       _   __  __             _   _
         *     |  _ \ _ __(_)_ __ | |_|  \/  | ___  _ __ | |_| |__
         *     | |_) | '__| | '_ \| __| |\/| |/ _ \| '_ \| __| '_ \
         *     |  __/| |  | | | | | |_| |  | | (_) | | | | |_| | | |
         *     |_|   |_|  |_|_| |_|\__|_|  |_|\___/|_| |_|\__|_| |_|
         *
         */
        final JButton btnPrintMonth = new JButton(SYSConst.icon22print2);
        btnPrintMonth.setPressedIcon(SYSConst.icon22print2Pressed);
        btnPrintMonth.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnPrintMonth.setContentAreaFilled(false);
        btnPrintMonth.setBorder(null);
        btnPrintMonth.setToolTipText(SYSTools.xx("misc.tooltips.btnprintmonth"));
        btnPrintMonth.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                SYSFilesTools.print(NReportTools.getNReportsAsHTML(
                        NReportTools.getNReports4Month(resident, month), true, null, null), false);
            }
        });
        cptitle.getRight().add(btnPrintMonth);
    }
    cpMonth.setTitleLabelComponent(cptitle.getMain());
    cpMonth.setSlidingDirection(SwingConstants.SOUTH);
    cpMonth.setBackground(SYSConst.orange1[SYSConst.medium2]);
    cpMonth.setOpaque(true);
    cpMonth.setHorizontalAlignment(SwingConstants.LEADING);

    cpMonth.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            cpMonth.setContentPane(createContentPanel4Month(month));
        }
    });

    if (!cpMonth.isCollapsed()) {
        cpMonth.setContentPane(createContentPanel4Month(month));
    }

    return cpMonth;
}

From source file:op.care.supervisor.PnlHandover.java

private void createContentPanel4Day(final LocalDate day, final CollapsiblePane cpDay) {

    final JPanel dayPanel = new JPanel(new VerticalLayout());

    OPDE.getDisplayManager().setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));
    OPDE.getMainframe().setBlocked(true);

    SwingWorker worker = new SwingWorker() {

        @Override//w  ww.  j ava2 s  . c o m
        protected Object doInBackground() throws Exception {

            //                final JPanel dayPanel = new JPanel(new VerticalLayout());
            dayPanel.setOpaque(false);

            ArrayList<Handovers> listHO = HandoversTools.getBy(day, (Homes) cmbHomes.getSelectedItem());
            ArrayList<NReport> listNR = NReportTools.getNReports4Handover(day,
                    (Homes) cmbHomes.getSelectedItem());

            Collections.sort(listNR, myComparator);

            int max = listHO.size() + listNR.size();
            int i = 0; // for zebra pattern and progress
            for (final Handovers handover : listHO) {
                OPDE.getDisplayManager()
                        .setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), i, max));

                String title = "<html><table border=\"0\">" + "<tr valign=\"top\">"
                        + "<td width=\"100\" align=\"left\">"
                        + DateFormat.getTimeInstance(DateFormat.SHORT).format(handover.getPit()) + " "
                        + SYSTools.xx("misc.msg.Time.short") + "</td>"
                        + "<td width=\"100\" align=\"center\">--</td>" + "<td width=\"400\" align=\"left\">"
                        + handover.getText() + "</td>" +

                        "<td width=\"100\" align=\"left\">" + handover.getUser().getFullname() + "</td>"
                        + "</tr>" + "</table>" + "</html>";

                final DefaultCPTitle pnlSingle = new DefaultCPTitle(SYSTools.toHTMLForScreen(title),
                        new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent evt) {
                                EntityManager em = OPDE.createEM();
                                if (Handover2UserTools.containsUser(em, handover, OPDE.getLogin().getUser())) {
                                    em.close();
                                    return;
                                }
                                try {
                                    em.getTransaction().begin();
                                    Handovers myHO = em.merge(handover);
                                    Handover2User connObj = em.merge(
                                            new Handover2User(myHO, em.merge(OPDE.getLogin().getUser())));
                                    myHO.getUsersAcknowledged().add(connObj);
                                    em.getTransaction().commit();

                                    createCP4Day(day);
                                    buildPanel();

                                } catch (OptimisticLockException ole) {
                                    OPDE.warn(ole);
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                        OPDE.getMainframe().emptyFrame();
                                        OPDE.getMainframe().afterLogin();
                                    }
                                    OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                                } catch (Exception e) {
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    OPDE.fatal(e);
                                } finally {
                                    em.close();
                                }
                            }
                        });

                final JButton btnInfo = new JButton(SYSConst.icon22info);
                btnInfo.setPressedIcon(SYSConst.icon22infoPressed);
                btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnInfo.setAlignmentY(Component.TOP_ALIGNMENT);
                btnInfo.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnInfo.setContentAreaFilled(false);
                btnInfo.setBorder(null);
                btnInfo.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        OPDE.getDisplayManager().setProgressBarMessage(
                                new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));
                        OPDE.getMainframe().setBlocked(true);

                        SwingWorker worker = new SwingWorker() {

                            @Override
                            protected Object doInBackground() throws Exception {
                                SYSFilesTools.print(Handover2UserTools.getAsHTML(handover), false);
                                return null;
                            }

                            @Override
                            protected void done() {
                                try {
                                    get();
                                } catch (Exception ex1) {
                                    OPDE.fatal(ex1);
                                }
                                OPDE.getDisplayManager().setProgressBarMessage(null);
                                OPDE.getMainframe().setBlocked(false);
                            }

                        };
                        worker.execute();

                    }
                });
                pnlSingle.getRight().add(btnInfo);

                EntityManager em = OPDE.createEM();
                pnlSingle.getButton()
                        .setIcon(Handover2UserTools.containsUser(em, handover, OPDE.getLogin().getUser())
                                ? SYSConst.icon22ledGreenOn
                                : SYSConst.icon22ledRedOn);
                em.close();

                pnlSingle.getButton().setVerticalTextPosition(SwingConstants.TOP);

                JPanel zebra = new JPanel();
                zebra.setLayout(new BoxLayout(zebra, BoxLayout.LINE_AXIS));
                zebra.setOpaque(true);
                if (i % 2 == 0) {
                    zebra.setBackground(SYSConst.orange1[SYSConst.light2]);
                } else {
                    zebra.setBackground(Color.WHITE);
                }
                zebra.add(pnlSingle.getMain());
                i++;
                dayPanel.add(zebra);
            }
            for (final NReport nreport : listNR) {
                OPDE.getDisplayManager()
                        .setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), i, max));

                String title = "<html><table border=\"0\">" + "<tr valign=\"top\">"
                        + "<td width=\"100\" align=\"left\">"
                        + DateFormat.getTimeInstance(DateFormat.SHORT).format(nreport.getPit()) + " "
                        + SYSTools.xx("misc.msg.Time.short") + "<br/>" + nreport.getMinutes() + " "
                        + SYSTools.xx("misc.msg.Minute(s)") + "</td>" + "<td width=\"100\" align=\"left\">"
                        + ResidentTools.getTextCompact(nreport.getResident()) + "</td>"
                        + "<td width=\"400\" align=\"left\">" + nreport.getText() + "</td>" +

                        "<td width=\"100\" align=\"left\">" + nreport.getUser().getFullname() + "</td>"
                        + "</tr>" + "</table>" + "</html>";

                final DefaultCPTitle pnlSingle = new DefaultCPTitle(SYSTools.toHTMLForScreen(title),
                        new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent evt) {
                                EntityManager em = OPDE.createEM();
                                if (NR2UserTools.containsUser(em, nreport, OPDE.getLogin().getUser())) {
                                    em.close();
                                    return;
                                }

                                try {
                                    em.getTransaction().begin();
                                    NReport myNR = em.merge(nreport);
                                    NR2User connObj = em
                                            .merge(new NR2User(myNR, em.merge(OPDE.getLogin().getUser())));
                                    myNR.getUsersAcknowledged().add(connObj);
                                    em.getTransaction().commit();
                                    createCP4Day(day);
                                    buildPanel();
                                } catch (OptimisticLockException ole) {
                                    OPDE.warn(ole);
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                                        OPDE.getMainframe().emptyFrame();
                                        OPDE.getMainframe().afterLogin();
                                    }
                                    OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                                } catch (Exception e) {
                                    if (em.getTransaction().isActive()) {
                                        em.getTransaction().rollback();
                                    }
                                    OPDE.fatal(e);
                                } finally {
                                    em.close();
                                }
                            }
                        });

                final JButton btnInfo = new JButton(SYSConst.icon22info);
                btnInfo.setPressedIcon(SYSConst.icon22infoPressed);
                btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnInfo.setAlignmentY(Component.TOP_ALIGNMENT);
                btnInfo.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnInfo.setContentAreaFilled(false);
                btnInfo.setBorder(null);
                btnInfo.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {

                        SYSFilesTools.print(NR2UserTools.getAsHTML(nreport), false);

                        //                            OPDE.getDisplayManager().setProgressBarMessage(new DisplayMessage(SYSTools.xx("misc.msg.wait"), -1, 100));
                        //                            OPDE.getMainframe().setBlocked(true);
                        //
                        //                            SwingWorker worker = new SwingWorker() {
                        //
                        //                                @Override
                        //                                protected Object doInBackground() throws Exception {
                        //
                        //                                    return null;
                        //                                }
                        //
                        //                                @Override
                        //                                protected void done() {
                        //                                    OPDE.getDisplayManager().setProgressBarMessage(null);
                        //                                    OPDE.getMainframe().setBlocked(false);
                        //                                }
                        //
                        //                            };
                        //                            worker.execute();

                    }
                });
                pnlSingle.getRight().add(btnInfo);

                EntityManager em = OPDE.createEM();
                pnlSingle.getButton()
                        .setIcon(NR2UserTools.containsUser(em, nreport, OPDE.getLogin().getUser())
                                ? SYSConst.icon22ledGreenOn
                                : SYSConst.icon22ledRedOn);
                em.close();

                pnlSingle.getButton().setVerticalTextPosition(SwingConstants.TOP);

                JPanel zebra = new JPanel();
                zebra.setLayout(new BoxLayout(zebra, BoxLayout.LINE_AXIS));
                zebra.setOpaque(true);
                if (i % 2 == 0) {
                    zebra.setBackground(SYSConst.orange1[SYSConst.light2]);
                } else {
                    zebra.setBackground(Color.WHITE);
                }
                zebra.add(pnlSingle.getMain());
                i++;

                dayPanel.add(zebra);
            }
            final String key = DateFormat.getDateInstance().format(day.toDate());
            synchronized (cacheHO) {
                cacheHO.put(key, listHO);
            }
            synchronized (cacheNR) {
                cacheNR.put(key, listNR);
            }
            return null;

        }

        @Override
        protected void done() {
            try {
                get();
            } catch (Exception ex2) {
                OPDE.fatal(ex2);
            }
            cpDay.setContentPane(dayPanel);
            OPDE.getDisplayManager().setProgressBarMessage(null);
            OPDE.getMainframe().setBlocked(false);
        }
    };
    worker.execute();

}