Example usage for javax.swing SwingConstants SOUTH

List of usage examples for javax.swing SwingConstants SOUTH

Introduction

In this page you can find the example usage for javax.swing SwingConstants SOUTH.

Prototype

int SOUTH

To view the source code for javax.swing SwingConstants SOUTH.

Click Source Link

Document

Compass-direction south (down).

Usage

From source file:net.sf.dvstar.transmission.TransmissionView.java

private void setAdditionalButtons() {
    ResizableIcon ri = new ArrowResizableIcon(9, SwingConstants.SOUTH);
    JCommandButton dropDownButton = new JCommandButton("Text Button", ri);

    ImageIcon imco = globalResourceMap.getImageIcon("btExit.icon");
    Dimension idim = new Dimension(imco.getIconWidth(), imco.getIconHeight());
    idim = new Dimension(40, 40);
    Image im = imco.getImage();//from  w  w w .  j a  va 2s.  c  om

    ImageWrapperResizableIcon iwri = ImageWrapperResizableIcon.getIcon(im, idim);

    JCommandButton taskbarButtonPaste = new JCommandButton("", iwri);

    taskbarButtonPaste.setHorizontalAlignment(SwingConstants.LEFT);
    taskbarButtonPaste.setCommandButtonKind(CommandButtonKind.ACTION_AND_POPUP_MAIN_POPUP);
    //taskbarButtonPaste.setPopupOrientationKind(CommandButtonPopupOrientationKind.DOWNWARD);
    taskbarButtonPaste.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    taskbarButtonPaste.setDisplayState(TILE_36); // !!!!
    //taskbarButtonPaste.setPreferredSize(new Dimension(80, 48));
    System.out.println("Pref " + taskbarButtonPaste.getPreferredSize());
    System.out.println("Maxi " + taskbarButtonPaste.getMaximumSize());
    System.out.println("Mini " + taskbarButtonPaste.getMinimumSize());
    System.out.println("Size " + taskbarButtonPaste.getSize());
    Dimension d = new Dimension(taskbarButtonPaste.getPreferredSize().width, 48);
    taskbarButtonPaste.setMaximumSize(d);

    taskbarButtonPaste.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            System.out.println("Taskbar Paste activated");
        }
    });
    taskbarButtonPaste.setPopupCallback(new PopupPanelCallback() {

        @Override
        public JPopupPanel getPopupPanel(JCommandButton commandButton) {
            return new SamplePopupMenu();
        }
    });

    taskbarButtonPaste.setActionRichTooltip(new RichTooltip("Paste", "Paste the contents of the Clipboard"));
    taskbarButtonPaste.setPopupRichTooltip(new RichTooltip("Paste",
            "Click here for more options such as pasting only the values or formatting"));
    taskbarButtonPaste.setActionKeyTip("1");

    //maiToolBar.add( rb );

    /*
    JRibbonBand rb = new JRibbonBand("", new EmptyResizableIcon(1));
    rb.addCommandButton(dropDownButton, RibbonElementPriority.MEDIUM);
     *
    JButton dropDownButton = DropDownButtonFactory.createDropDownButton(
    resourceMap.getIcon("btConnect.icon"),
    popup);
     */
    //dropDownButton.setBorder(javax.swing.BorderFactory.createEmptyBorder(2,2,2,2));
    //dropDownButton.setBorderPainted( false );

    //btConnect = taskbarButtonPaste;
    maiToolBar.add(taskbarButtonPaste);

}

From source file:op.allowance.PnlAllowance.java

private CollapsiblePane createCP4(final Resident resident) {
    /***// ww w  .j  av a 2  s  .  c  o m
     *                          _        ____ ____  _  _    ______           _     _            _ __
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |  / /  _ \ ___  ___(_) __| | ___ _ __ | |\ \
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_| || |_) / _ \/ __| |/ _` |/ _ \ '_ \| __| |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _| ||  _ <  __/\__ \ | (_| |  __/ | | | |_| |
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_| | ||_| \_\___||___/_|\__,_|\___|_| |_|\__| |
     *                                                     \_\                                    /_/
     */
    final String key = resident.getRID();
    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 cpResident = cpMap.get(key);

    if (!carrySums.containsKey(getKey(resident, SYSCalendar.eoy(new LocalDate())))) {
        carrySums.put(getKey(resident, SYSCalendar.eoy(new LocalDate())),
                AllowanceTools.getSUM(resident, SYSCalendar.eoy(new LocalDate())));
    }

    BigDecimal sumOverall = carrySums.get(getKey(resident, SYSCalendar.eoy(new LocalDate())));

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

            "<td width=\"520\" align=\"left\"><font size=+1>" + resident.toString() + "</font></td>"
            + "<td width=\"200\" align=\"right\"><font size=+1"
            + (sumOverall.compareTo(BigDecimal.ZERO) < 0 ? " color=\"red\" " : "") + ">" + cf.format(sumOverall)
            + "</font></td>" +

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

            "</html>";

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

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.ARCHIVE, internalClassID)
            && OPDE.getAppInfo().isAllowedTo(InternalClassACL.PRINT, internalClassID)) {
        /***
         *      ____       _       _   ____           _     _            _
         *     |  _ \ _ __(_)_ __ | |_|  _ \ ___  ___(_) __| | ___ _ __ | |_
         *     | |_) | '__| | '_ \| __| |_) / _ \/ __| |/ _` |/ _ \ '_ \| __|
         *     |  __/| |  | | | | | |_|  _ <  __/\__ \ | (_| |  __/ | | | |_
         *     |_|   |_|  |_|_| |_|\__|_| \_\___||___/_|\__,_|\___|_| |_|\__|
         *
         */
        final JButton btnPrintResident = new JButton(SYSConst.icon22print2);
        btnPrintResident.setPressedIcon(SYSConst.icon22print2Pressed);
        btnPrintResident.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnPrintResident.setContentAreaFilled(false);
        btnPrintResident.setBorder(null);
        btnPrintResident.setToolTipText(SYSTools.xx("admin.residents.cash.btnprintresident.tooltip"));
        btnPrintResident.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                SYSFilesTools.print(
                        AllowanceTools.getAsHTML(AllowanceTools.getAll(resident), BigDecimal.ZERO, resident),
                        true);
            }

        });
        cptitle.getRight().add(btnPrintResident);
    }

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

    /***
     *           _ _      _            _                               _     _            _
     *       ___| (_) ___| | _____  __| |   ___  _ __    _ __ ___  ___(_) __| | ___ _ __ | |_
     *      / __| | |/ __| |/ / _ \/ _` |  / _ \| '_ \  | '__/ _ \/ __| |/ _` |/ _ \ '_ \| __|
     *     | (__| | | (__|   <  __/ (_| | | (_) | | | | | | |  __/\__ \ | (_| |  __/ | | | |_
     *      \___|_|_|\___|_|\_\___|\__,_|  \___/|_| |_| |_|  \___||___/_|\__,_|\___|_| |_|\__|
     *
     */
    cpResident.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            // somebody clicks on the name of the resident. the cash informations
            // are loaded from the database, if necessary.
            cpResident.setContentPane(createContentPanel4(resident));
        }
    });
    cpResident.setBackground(getBG(resident, 7));

    if (!cpResident.isCollapsed()) {
        cpResident.setContentPane(createContentPanel4(resident));
    }

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

    return cpResident;
}

From source file:op.allowance.PnlAllowance.java

private CollapsiblePane createCP4(final Resident resident, final int year) {
    LocalDate min = SYSCalendar.bom(minmax.get(resident).getFirst());
    LocalDate max = resident.isActive() ? new LocalDate() : SYSCalendar.eom(minmax.get(resident).getSecond());
    final LocalDate start = new LocalDate(year, 1, 1).isBefore(min.dayOfMonth().withMinimumValue())
            ? min.dayOfMonth().withMinimumValue()
            : new LocalDate(year, 1, 1);
    final LocalDate end = new LocalDate(year, 12, 31).isAfter(max.dayOfMonth().withMaximumValue())
            ? max.dayOfMonth().withMaximumValue()
            : new LocalDate(year, 12, 31);

    final String key = resident.getRID() + "-" + year;
    if (!cpMap.containsKey(key)) {
        cpMap.put(key, new CollapsiblePane());
        try {/*ww  w . ja  v a 2  s . c  o m*/
            cpMap.get(key).setCollapsed(true);
        } catch (PropertyVetoException e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }

    }

    final CollapsiblePane cpYear = cpMap.get(key);

    if (!carrySums.containsKey(key + "-12")) {
        carrySums.put(key + "-12", AllowanceTools.getSUM(resident, SYSCalendar.eoy(start)));
    }

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

            "<td width=\"520\" align=\"left\"><font size=+1>" + Integer.toString(year) + "</font></td>"
            + "<td width=\"200\" align=\"right\">"
            + (carrySums.get(key + "-12").compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "")
            + cf.format(carrySums.get(key + "-12"))
            + (carrySums.get(key + "-12").compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" +

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

            "</font></html>";

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

    GUITools.addExpandCollapseButtons(cpYear, cptitle.getRight());

    /***
     *      ____       _       _ __   __
     *     |  _ \ _ __(_)_ __ | |\ \ / /__  __ _ _ __
     *     | |_) | '__| | '_ \| __\ V / _ \/ _` | '__|
     *     |  __/| |  | | | | | |_ | |  __/ (_| | |
     *     |_|   |_|  |_|_| |_|\__||_|\___|\__,_|_|
     *
     */
    final JButton btnPrintYear = new JButton(SYSConst.icon22print2);
    btnPrintYear.setPressedIcon(SYSConst.icon22print2Pressed);
    btnPrintYear.setAlignmentX(Component.RIGHT_ALIGNMENT);
    btnPrintYear.setContentAreaFilled(false);
    btnPrintYear.setBorder(null);
    btnPrintYear.setToolTipText(SYSTools.xx("misc.tooltips.btnprintyear"));
    btnPrintYear.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            String carry4printKey = resident.getRID() + "-" + (year - 1) + "-12";
            if (!carrySums.containsKey(carry4printKey)) {
                carrySums.put(carry4printKey,
                        AllowanceTools.getSUM(resident, SYSCalendar.eoy(start.minusYears(1))));
            }
            SYSFilesTools.print(AllowanceTools.getAsHTML(AllowanceTools.getYear(resident, start.toDate()),
                    carrySums.get(carry4printKey), resident), true);
        }

    });
    cptitle.getRight().add(btnPrintYear);

    cpYear.setTitleLabelComponent(cptitle.getMain());
    cpYear.setSlidingDirection(SwingConstants.SOUTH);
    cpYear.setBackground(SYSConst.orange1[SYSConst.medium3]);
    cpYear.setOpaque(true);

    /***
     *           _ _      _            _
     *       ___| (_) ___| | _____  __| |   ___  _ __    _   _  ___  __ _ _ __
     *      / __| | |/ __| |/ / _ \/ _` |  / _ \| '_ \  | | | |/ _ \/ _` | '__|
     *     | (__| | | (__|   <  __/ (_| | | (_) | | | | | |_| |  __/ (_| | |
     *      \___|_|_|\___|_|\_\___|\__,_|  \___/|_| |_|  \__, |\___|\__,_|_|
     *                                                   |___/
     */
    cpYear.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            JPanel pnlContent = new JPanel(new VerticalLayout());

            // somebody clicked on the year
            // monthly informations will be generated. even if there
            // are no allowances for that month
            for (LocalDate month = end; month.compareTo(start) >= 0; month = month.minusMonths(1)) {
                pnlContent.add(createCP4(resident, month));
            }

            cpYear.setContentPane(pnlContent);
            cpYear.setOpaque(false);
        }

    });
    cpYear.setBackground(getBG(resident, 9));

    if (!cpYear.isCollapsed()) {
        JPanel pnlContent = new JPanel(new VerticalLayout());
        for (LocalDate month = end; month.compareTo(start) > 0; month = month.minusMonths(1)) {
            pnlContent.add(createCP4(resident, month));
        }
        cpYear.setContentPane(pnlContent);
    }

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

    return cpYear;
}

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 {/* w  w  w .j  a v a 2 s  . 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.bhp.PnlBHP.java

private CollapsiblePane createCP4Outcome() {
    /***//ww  w  .j av  a  2s.  co  m
     *       ____ ____  _  _    ___        _
     *      / ___|  _ \| || |  / _ \ _   _| |_ ___ ___  _ __ ___   ___
     *     | |   | |_) | || |_| | | | | | | __/ __/ _ \| '_ ` _ \ / _ \
     *     | |___|  __/|__   _| |_| | |_| | || (_| (_) | | | | | |  __/
     *      \____|_|      |_|  \___/ \__,_|\__\___\___/|_| |_| |_|\___|
     *
     */
    String title = "<html><font size=+1><b>"
            + SYSTools.xx("nursingrecords.prescription.dlgOnDemand.outcomeCheck") + "</b></font></html>";

    final CollapsiblePane mainPane = new CollapsiblePane(title);
    mainPane.setSlidingDirection(SwingConstants.SOUTH);
    mainPane.setBackground(SYSCalendar.getBGSHIFT(BHPTools.SHIFT_OUTCOMES));
    mainPane.setForeground(SYSCalendar.getFGSHIFT(BHPTools.SHIFT_OUTCOMES));
    mainPane.setLayout(new VerticalLayout());
    mainPane.setOpaque(false);

    if (!mapShift2BHP.get(BHPTools.SHIFT_OUTCOMES).isEmpty()) {
        //            Prescription currentPrescription = null;
        //            CollapsiblePane sitPane = null;
        //            JPanel sitPanel = null;
        //            JPanel panel = new JPanel();
        //            panel.setLayout(new VerticalLayout());
        for (BHP bhp : mapShift2BHP.get(BHPTools.SHIFT_OUTCOMES)) {

            mapBHP2Pane.put(bhp, createCP4(bhp));
            mainPane.add(mapBHP2Pane.get(bhp));
        }
        //            mainPane.setContentPane(sitOuterPanel);
        mainPane.setCollapsible(true);
    } else {
        mainPane.setContentPane(new JPanel());
        mainPane.setCollapsible(false);
    }

    return mainPane;
}

From source file:op.care.bhp.PnlBHP.java

private CollapsiblePane createCP4OnDemand() {
    /***//w  w w.ja va 2  s. c  o m
     *                          _        ____ ____  _  _    ___        ____                                 _
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |  / _ \ _ __ |  _ \  ___ _ __ ___   __ _ _ __   __| |
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_| | | | '_ \| | | |/ _ \ '_ ` _ \ / _` | '_ \ / _` |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _| |_| | | | | |_| |  __/ | | | | | (_| | | | | (_| |
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_|  \___/|_| |_|____/ \___|_| |_| |_|\__,_|_| |_|\__,_|
     *
     */
    String title = "<html><font size=+1><b>" + SYSTools.xx("nursingrecords.bhp.ondemand")
            + "</b></font></html>";

    final CollapsiblePane mainPane = new CollapsiblePane(title);
    mainPane.setSlidingDirection(SwingConstants.SOUTH);
    mainPane.setBackground(SYSCalendar.getBGSHIFT(BHPTools.SHIFT_ON_DEMAND));
    mainPane.setForeground(SYSCalendar.getFGSHIFT(BHPTools.SHIFT_ON_DEMAND));
    mainPane.setOpaque(false);

    if (!mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND).isEmpty()) {
        Prescription currentPrescription = null;
        CollapsiblePane sitPane = null;
        JPanel sitPanel = null;
        JPanel sitOuterPanel = new JPanel();
        sitOuterPanel.setLayout(new VerticalLayout());
        for (BHP bhp : mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND)) {
            if (currentPrescription == null || bhp.getPrescription().getID() != currentPrescription.getID()) {
                if (currentPrescription != null) {
                    sitPane.setContentPane(sitPanel);
                    sitOuterPanel.add(sitPane);
                }
                currentPrescription = bhp.getPrescription();
                sitPanel = new JPanel();
                sitPanel.setLayout(new VerticalLayout());
                sitPanel.setBackground(bhp.getBG());
                sitPane = new CollapsiblePane(
                        SYSTools.toHTMLForScreen("<b>" + currentPrescription.getSituation().getText())
                                + "</b>");
                sitPane.setSlidingDirection(SwingConstants.SOUTH);
                sitPane.setBackground(
                        ColorUtils.getDerivedColor(SYSCalendar.getBGSHIFT(BHPTools.SHIFT_ON_DEMAND), 0.4f)); // a little darker
                sitPane.setForeground(Color.BLACK);
                sitPane.setOpaque(false);
            }

            sitPane.setContentPane(sitPanel);
            sitOuterPanel.add(sitPane);

            mapBHP2Pane.put(bhp, createCP4(bhp));
            sitPanel.add(mapBHP2Pane.get(bhp));
        }
        mainPane.setContentPane(sitOuterPanel);
        mainPane.setCollapsible(true);
    } else {
        mainPane.setContentPane(new JPanel());
        mainPane.setCollapsible(false);
    }

    return mainPane;
}

From source file:op.care.bhp.PnlBHP.java

private CollapsiblePane createCP4Shift(final Byte shift) {
    /***/*from  w ww . ja v  a2 s .c  om*/
     *                          _        ____ ____  _  _
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _|
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_|
     *
     */
    String title = "<html><font size=+1><b>" + GUITools.getLocalizedMessages(BHPTools.SHIFT_TEXT)[shift]
            + "</b></font></html>";

    final CollapsiblePane prPane = new CollapsiblePane(title);
    prPane.setSlidingDirection(SwingConstants.SOUTH);
    prPane.setBackground(SYSCalendar.getBGSHIFT(shift));
    prPane.setForeground(SYSCalendar.getFGSHIFT(shift));
    prPane.setOpaque(false);

    JPanel prPanel = new JPanel();
    prPanel.setLayout(new VerticalLayout());

    if (mapShift2BHP.containsKey(shift)) {

        if (shift == BHPTools.SHIFT_EARLY) {

            final CollapsiblePane morning = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.morning.long") + "</font></html>", null);
            morning.setSlidingDirection(SwingConstants.SOUTH);
            morning.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            morning.setForeground(Color.white);
            morning.setOpaque(false);
            JPanel pnlMorning = new JPanel();
            pnlMorning.setLayout(new VerticalLayout());
            morning.setContentPane(pnlMorning);

            final CollapsiblePane noon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.noon.long") + "</font></html>", null);
            noon.setSlidingDirection(SwingConstants.SOUTH);
            noon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            noon.setForeground(Color.white);
            noon.setOpaque(false);
            JPanel pnlNoon = new JPanel();
            pnlNoon.setLayout(new VerticalLayout());
            noon.setContentPane(pnlNoon);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            for (BHP bhp : mapShift2BHP.get(shift)) {
                prPanel.setBackground(bhp.getBG());
                mapBHP2Pane.put(bhp, createCP4(bhp));
                if (bhp.getSollZeit() == BHPTools.BYTE_MORNING) {
                    pnlMorning.add(mapBHP2Pane.get(bhp));
                } else if (bhp.getSollZeit() == BHPTools.BYTE_NOON) {
                    pnlNoon.add(mapBHP2Pane.get(bhp));
                } else {
                    pnlClock.add(mapBHP2Pane.get(bhp));
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                prPanel.add(clock);
            }
            if (pnlMorning.getComponentCount() > 0) {
                prPanel.add(morning);
            }
            if (pnlNoon.getComponentCount() > 0) {
                prPanel.add(noon);
            }

        } else if (shift == BHPTools.SHIFT_LATE) {
            final CollapsiblePane afternoon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.afternoon.long") + "</font></html>", null);
            afternoon.setSlidingDirection(SwingConstants.SOUTH);
            afternoon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            afternoon.setForeground(Color.white);
            afternoon.setOpaque(false);
            JPanel pnlAfternoon = new JPanel();
            pnlAfternoon.setLayout(new VerticalLayout());
            afternoon.setContentPane(pnlAfternoon);

            final CollapsiblePane evening = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.evening.long") + "</font></html>", null);
            evening.setSlidingDirection(SwingConstants.SOUTH);
            evening.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            evening.setForeground(Color.white);
            evening.setOpaque(false);
            JPanel pnlEvening = new JPanel();
            pnlEvening.setLayout(new VerticalLayout());
            evening.setContentPane(pnlEvening);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            for (BHP bhp : mapShift2BHP.get(shift)) {
                prPanel.setBackground(bhp.getBG());
                mapBHP2Pane.put(bhp, createCP4(bhp));
                if (bhp.getSollZeit() == BHPTools.BYTE_AFTERNOON) {
                    pnlAfternoon.add(mapBHP2Pane.get(bhp));
                } else if (bhp.getSollZeit() == BHPTools.BYTE_EVENING) {
                    pnlEvening.add(mapBHP2Pane.get(bhp));
                } else {
                    pnlClock.add(mapBHP2Pane.get(bhp));
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                prPanel.add(clock);
            }
            if (pnlAfternoon.getComponentCount() > 0) {
                prPanel.add(afternoon);
            }
            if (pnlEvening.getComponentCount() > 0) {
                prPanel.add(evening);
            }
        } else {
            for (BHP bhp : mapShift2BHP.get(shift)) {
                prPanel.setBackground(bhp.getBG());
                mapBHP2Pane.put(bhp, createCP4(bhp));
                prPanel.add(mapBHP2Pane.get(bhp));
            }
        }
        prPane.setContentPane(prPanel);
        prPane.setCollapsible(true);
    } else {
        prPane.setContentPane(prPanel);
        prPane.setCollapsible(false);
    }

    return prPane;
}

From source file:op.care.bhp.PnlBHP.java

private CollapsiblePane createCP4(final BHP bhp) {
    final CollapsiblePane bhpPane = new CollapsiblePane();
    bhpPane.setCollapseOnTitleClick(false);

    ActionListener applyActionListener = new ActionListener() {
        @Override/* w ww .  ja v  a 2s .  c  o  m*/
        public void actionPerformed(ActionEvent actionEvent) {
            if (bhp.getState() != BHPTools.STATE_OPEN) {
                return;
            }
            if (bhp.getPrescription().isClosed()) {
                return;
            }

            if (BHPTools.isChangeable(bhp)) {
                outcomeText = null;
                if (bhp.getNeedsText()) {
                    new DlgYesNo(SYSConst.icon48comment, new Closure() {
                        @Override
                        public void execute(Object o) {
                            if (SYSTools.catchNull(o).isEmpty()) {
                                outcomeText = null;
                            } else {
                                outcomeText = o.toString();
                            }
                        }
                    }, "nursingrecords.bhp.describe.outcome", null, null);

                }

                if (bhp.getNeedsText() && outcomeText == null) {
                    OPDE.getDisplayManager().addSubMessage(
                            new DisplayMessage("nursingrecords.bhp.notext.nooutcome", DisplayMessage.WARNING));
                    return;
                }

                if (bhp.getPrescription().isWeightControlled()) {
                    new DlgYesNo(SYSConst.icon48scales, new Closure() {
                        @Override
                        public void execute(Object o) {
                            if (SYSTools.catchNull(o).isEmpty()) {
                                weight = null;
                            } else {
                                weight = (BigDecimal) o;
                            }
                        }
                    }, "nursingrecords.bhp.weight", null, new Validator<BigDecimal>() {
                        @Override
                        public boolean isValid(String value) {
                            BigDecimal bd = parse(value);
                            return bd != null && bd.compareTo(BigDecimal.ZERO) > 0;

                        }

                        @Override
                        public BigDecimal parse(String text) {
                            return SYSTools.parseDecimal(text);
                        }
                    });

                }

                if (bhp.getPrescription().isWeightControlled() && weight == null) {
                    OPDE.getDisplayManager().addSubMessage(new DisplayMessage(
                            "nursingrecords.bhp.noweight.nosuccess", DisplayMessage.WARNING));
                    return;
                }

                EntityManager em = OPDE.createEM();
                try {
                    em.getTransaction().begin();

                    em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                    BHP myBHP = em.merge(bhp);
                    em.lock(myBHP, LockModeType.OPTIMISTIC);

                    if (myBHP.isOnDemand()) {
                        em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC_FORCE_INCREMENT);
                        em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC_FORCE_INCREMENT);
                    } else {
                        em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC);
                        em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC);
                    }

                    myBHP.setState(BHPTools.STATE_DONE);
                    myBHP.setUser(em.merge(OPDE.getLogin().getUser()));
                    myBHP.setIst(new Date());
                    myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date()));
                    myBHP.setMDate(new Date());
                    myBHP.setText(outcomeText);

                    Prescription involvedPresciption = null;
                    if (myBHP.shouldBeCalculated()) {
                        MedInventory inventory = TradeFormTools.getInventory4TradeForm(resident,
                                myBHP.getTradeForm());
                        MedInventoryTools.withdraw(em, em.merge(inventory), myBHP.getDose(), weight, myBHP);
                        // Was the prescription closed during this withdraw ?
                        involvedPresciption = em.find(Prescription.class, myBHP.getPrescription().getID());
                    }

                    BHP outcomeBHP = null;
                    // add outcome check BHP if necessary
                    if (!myBHP.isOutcomeText()
                            && myBHP.getPrescriptionSchedule().getCheckAfterHours() != null) {
                        outcomeBHP = em.merge(new BHP(myBHP));
                        mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND).add(outcomeBHP);
                    }

                    em.getTransaction().commit();

                    if (myBHP.shouldBeCalculated() && involvedPresciption.isClosed()) { // &&
                        reload();
                    } else if (outcomeBHP != null) {
                        reload();
                    } else {
                        mapBHP2Pane.put(myBHP, createCP4(myBHP));
                        int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp);
                        mapShift2BHP.get(myBHP.getShift()).remove(position);
                        mapShift2BHP.get(myBHP.getShift()).add(position, myBHP);
                        if (myBHP.isOnDemand()) {
                            // This whole thing here is only to handle the BPHs on Demand
                            // Fix the other BHPs on demand. If not, you will get locking exceptions,
                            // we FORCED INCREMENTED LOCKS on the Schedule and the Prescription.
                            ArrayList<BHP> changeList = new ArrayList<BHP>();
                            for (BHP bhp : mapShift2BHP.get(BHPTools.SHIFT_ON_DEMAND)) {
                                if (bhp.getPrescription().getID() == myBHP.getPrescription().getID()
                                        && bhp.getBHPid() != myBHP.getBHPid()) {
                                    bhp.setPrescription(myBHP.getPrescription());
                                    bhp.setPrescriptionSchedule(myBHP.getPrescriptionSchedule());
                                    changeList.add(bhp);
                                }
                            }
                            for (BHP bhp : changeList) {
                                mapBHP2Pane.put(bhp, createCP4(myBHP));
                                position = mapShift2BHP.get(bhp.getShift()).indexOf(bhp);
                                mapShift2BHP.get(myBHP.getShift()).remove(position);
                                mapShift2BHP.get(myBHP.getShift()).add(position, bhp);
                            }

                            Collections.sort(mapShift2BHP.get(myBHP.getShift()),
                                    BHPTools.getOnDemandComparator());
                        } else {
                            Collections.sort(mapShift2BHP.get(myBHP.getShift()));
                        }

                        mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift()));
                        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 (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();
                }

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

    //        JPanel titlePanelleft = new JPanel();
    //        titlePanelleft.setLayout(new BoxLayout(titlePanelleft, BoxLayout.LINE_AXIS));

    MedStock stock = mapPrescription2Stock.get(bhp.getPrescription());
    if (bhp.hasMed() && stock == null) {
        stock = MedStockTools
                .getStockInUse(TradeFormTools.getInventory4TradeForm(resident, bhp.getTradeForm()));
        mapPrescription2Stock.put(bhp.getPrescription(), stock);
    }

    String title;

    if (bhp.isOutcomeText()) {
        title = "<html><font size=+1>"
                + SYSConst.html_italic(SYSTools
                        .left("&ldquo;" + PrescriptionTools.getShortDescriptionAsCompactText(
                                bhp.getPrescriptionSchedule().getPrescription()), MAX_TEXT_LENGTH)
                        + BHPTools.getScheduleText(bhp.getOutcome4(), "&rdquo;, ", ""))
                + " [" + bhp.getPrescriptionSchedule().getCheckAfterHours() + " "
                + SYSTools.xx("misc.msg.Hour(s)") + "] " + BHPTools.getScheduleText(bhp, ", ", "")
                + (bhp.getPrescription().isWeightControlled()
                        ? " " + SYSConst.html_16x16_scales_internal + (bhp.isOpen() ? ""
                                : (bhp.getStockTransaction().isEmpty() ? " "
                                        : NumberFormat.getNumberInstance()
                                                .format(bhp.getStockTransaction().get(0).getWeight()) + "g "))
                        : "")
                + (bhp.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(bhp.getUser().getUID()) + "</i>"
                        : "")
                +

                "</font></html>";
    } else {
        title = "<html><font size=+1>"
                + SYSTools.left(PrescriptionTools.getShortDescriptionAsCompactText(
                        bhp.getPrescriptionSchedule().getPrescription()), MAX_TEXT_LENGTH)
                + (bhp.hasMed()
                        ? ", <b>" + SYSTools.getAsHTML(bhp.getDose()) + " "
                                + DosageFormTools.getUsageText(
                                        bhp.getPrescription().getTradeForm().getDosageForm())
                                + "</b>"
                        : "")
                + BHPTools.getScheduleText(bhp, ", ", "")
                + (bhp.getPrescription().isWeightControlled()
                        ? " " + SYSConst.html_16x16_scales_internal + (bhp.isOpen() ? ""
                                : (bhp.getStockTransaction().isEmpty() ? " "
                                        : NumberFormat.getNumberInstance()
                                                .format(bhp.getStockTransaction().get(0).getWeight()) + "g "))
                        : "")
                + (bhp.getUser() != null ? ", <i>" + SYSTools.anonymizeUser(bhp.getUser().getUID()) + "</i>"
                        : "")
                + "</font></html>";
    }

    DefaultCPTitle cptitle = new DefaultCPTitle(title,
            OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? applyActionListener
                    : null);

    JLabel icon1 = new JLabel(BHPTools.getIcon(bhp));
    icon1.setOpaque(false);
    if (!bhp.isOpen()) {
        icon1.setToolTipText(DateFormat.getDateTimeInstance().format(bhp.getIst()));
    }

    JLabel icon2 = new JLabel(BHPTools.getWarningIcon(bhp, stock));
    icon2.setOpaque(false);

    cptitle.getAdditionalIconPanel().add(icon1);
    cptitle.getAdditionalIconPanel().add(icon2);

    if (bhp.getPrescription().isClosed()) {
        JLabel icon3 = new JLabel(SYSConst.icon22stopSign);
        icon3.setOpaque(false);
        cptitle.getAdditionalIconPanel().add(icon3);
    }

    if (bhp.isOutcomeText()) {
        JLabel icon4 = new JLabel(SYSConst.icon22comment);
        icon4.setOpaque(false);
        cptitle.getAdditionalIconPanel().add(icon4);
    }

    if (!bhp.isOutcomeText() && bhp.getPrescriptionSchedule().getCheckAfterHours() != null) {
        JLabel icon4 = new JLabel(SYSConst.icon22intervalBySecond);
        icon4.setOpaque(false);
        cptitle.getAdditionalIconPanel().add(icon4);
    }

    if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {
        if (!bhp.getPrescription().isClosed()) {

            /***
             *      _     _            _                _
             *     | |__ | |_ _ __    / \   _ __  _ __ | |_   _
             *     | '_ \| __| '_ \  / _ \ | '_ \| '_ \| | | | |
             *     | |_) | |_| | | |/ ___ \| |_) | |_) | | |_| |
             *     |_.__/ \__|_| |_/_/   \_\ .__/| .__/|_|\__, |
             *                             |_|   |_|      |___/
             */
            JButton btnApply = new JButton(SYSConst.icon22apply);
            btnApply.setPressedIcon(SYSConst.icon22applyPressed);
            btnApply.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnApply.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnApply.tooltip"));
            btnApply.addActionListener(applyActionListener);
            btnApply.setContentAreaFilled(false);
            btnApply.setBorder(null);
            btnApply.setEnabled(bhp.isOpen()
                    && (!bhp.hasMed() || mapPrescription2Stock.containsKey(bhp.getPrescription())));
            cptitle.getRight().add(btnApply);

            /***
             *                             ____  _             _
             *       ___  _ __   ___ _ __ / ___|| |_ ___   ___| | __
             *      / _ \| '_ \ / _ \ '_ \\___ \| __/ _ \ / __| |/ /
             *     | (_) | |_) |  __/ | | |___) | || (_) | (__|   <
             *      \___/| .__/ \___|_| |_|____/ \__\___/ \___|_|\_\
             *           |_|
             */
            if (bhp.hasMed() && stock == null && MedInventoryTools.getNextToOpen(
                    TradeFormTools.getInventory4TradeForm(resident, bhp.getTradeForm())) != null) {
                final JButton btnOpenStock = new JButton(SYSConst.icon22ledGreenOn);
                btnOpenStock.setPressedIcon(SYSConst.icon22ledGreenOff);
                btnOpenStock.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnOpenStock.setContentAreaFilled(false);
                btnOpenStock.setBorder(null);
                btnOpenStock.setToolTipText(SYSTools
                        .toHTMLForScreen(SYSTools.xx("nursingrecords.inventory.stock.btnopen.tooltip")));
                btnOpenStock.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {

                        EntityManager em = OPDE.createEM();
                        try {
                            em.getTransaction().begin();
                            em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                            BHP myBHP = em.merge(bhp);
                            em.lock(myBHP, LockModeType.OPTIMISTIC);
                            em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC);
                            em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC);

                            MedStock myStock = em.merge(MedInventoryTools.openNext(
                                    TradeFormTools.getInventory4TradeForm(resident, myBHP.getTradeForm())));
                            em.lock(myStock, LockModeType.OPTIMISTIC);
                            em.getTransaction().commit();

                            OPDE.getDisplayManager()
                                    .addSubMessage(new DisplayMessage(
                                            String.format(SYSTools.xx("newstocks.stock.has.been.opened"),
                                                    myStock.getID().toString())));
                            reload();

                        } 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(btnOpenStock);
            }

            if (!bhp.isOutcomeText()) {
                /***
                 *      _     _         ____       __
                 *     | |__ | |_ _ __ |  _ \ ___ / _|_   _ ___  ___
                 *     | '_ \| __| '_ \| |_) / _ \ |_| | | / __|/ _ \
                 *     | |_) | |_| | | |  _ <  __/  _| |_| \__ \  __/
                 *     |_.__/ \__|_| |_|_| \_\___|_|  \__,_|___/\___|
                 *
                 */
                final JButton btnRefuse = new JButton(SYSConst.icon22cancel);
                btnRefuse.setPressedIcon(SYSConst.icon22cancelPressed);
                btnRefuse.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnRefuse.setContentAreaFilled(false);
                btnRefuse.setBorder(null);
                btnRefuse.setToolTipText(
                        SYSTools.toHTMLForScreen(SYSTools.xx("nursingrecords.bhp.btnRefuse.tooltip")));
                btnRefuse.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        if (bhp.getState() != BHPTools.STATE_OPEN) {
                            return;
                        }

                        if (BHPTools.isChangeable(bhp)) {
                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();

                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                BHP myBHP = em.merge(bhp);
                                em.lock(myBHP, LockModeType.OPTIMISTIC);
                                em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC);
                                em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC);

                                myBHP.setState(BHPTools.STATE_REFUSED);
                                myBHP.setUser(em.merge(OPDE.getLogin().getUser()));
                                myBHP.setIst(new Date());
                                myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date()));
                                myBHP.setMDate(new Date());

                                mapBHP2Pane.put(myBHP, createCP4(myBHP));
                                int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp);
                                mapShift2BHP.get(bhp.getShift()).remove(position);
                                mapShift2BHP.get(bhp.getShift()).add(position, myBHP);
                                if (myBHP.isOnDemand()) {
                                    Collections.sort(mapShift2BHP.get(myBHP.getShift()),
                                            BHPTools.getOnDemandComparator());
                                } else {
                                    Collections.sort(mapShift2BHP.get(myBHP.getShift()));
                                }

                                em.getTransaction().commit();
                                mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift()));
                                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.bhp.notchangeable")));
                        }
                    }
                });
                btnRefuse.setEnabled(!bhp.isOnDemand() && bhp.isOpen());
                cptitle.getRight().add(btnRefuse);

                /***
                 *      _     _         ____       __                ____  _                       _
                 *     | |__ | |_ _ __ |  _ \ ___ / _|_   _ ___  ___|  _ \(_)___  ___ __ _ _ __ __| |
                 *     | '_ \| __| '_ \| |_) / _ \ |_| | | / __|/ _ \ | | | / __|/ __/ _` | '__/ _` |
                 *     | |_) | |_| | | |  _ <  __/  _| |_| \__ \  __/ |_| | \__ \ (_| (_| | | | (_| |
                 *     |_.__/ \__|_| |_|_| \_\___|_|  \__,_|___/\___|____/|_|___/\___\__,_|_|  \__,_|
                 *
                 */
                final JButton btnRefuseDiscard = new JButton(SYSConst.icon22deleteall);
                btnRefuseDiscard.setPressedIcon(SYSConst.icon22deleteallPressed);
                btnRefuseDiscard.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnRefuseDiscard.setContentAreaFilled(false);
                btnRefuseDiscard.setBorder(null);
                btnRefuseDiscard.setToolTipText(
                        SYSTools.toHTMLForScreen(SYSTools.xx("nursingrecords.bhp.btnRefuseDiscard.tooltip")));
                btnRefuseDiscard.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        if (bhp.getState() != BHPTools.STATE_OPEN) {
                            return;
                        }

                        if (BHPTools.isChangeable(bhp)) {

                            if (bhp.getPrescription().isWeightControlled()) {
                                new DlgYesNo(SYSConst.icon48scales, new Closure() {
                                    @Override
                                    public void execute(Object o) {
                                        if (SYSTools.catchNull(o).isEmpty()) {
                                            weight = null;
                                        } else {
                                            weight = (BigDecimal) o;
                                        }
                                    }
                                }, "nursingrecords.bhp.weight", null, new Validator<BigDecimal>() {
                                    @Override
                                    public boolean isValid(String value) {
                                        BigDecimal bd = parse(value);
                                        return bd != null && bd.compareTo(BigDecimal.ZERO) > 0;

                                    }

                                    @Override
                                    public BigDecimal parse(String text) {
                                        return SYSTools.parseDecimal(text);
                                    }
                                });

                            }

                            if (bhp.getPrescription().isWeightControlled() && weight == null) {
                                OPDE.getDisplayManager().addSubMessage(new DisplayMessage(
                                        "nursingrecords.bhp.noweight.nosuccess", DisplayMessage.WARNING));
                                return;
                            }

                            EntityManager em = OPDE.createEM();
                            try {
                                em.getTransaction().begin();

                                em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                                BHP myBHP = em.merge(bhp);
                                em.lock(myBHP, LockModeType.OPTIMISTIC);
                                em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC);
                                em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC);

                                myBHP.setState(BHPTools.STATE_REFUSED_DISCARDED);
                                myBHP.setUser(em.merge(OPDE.getLogin().getUser()));
                                myBHP.setIst(new Date());
                                myBHP.setiZeit(SYSCalendar.whatTimeIDIs(new Date()));
                                myBHP.setMDate(new Date());

                                if (myBHP.shouldBeCalculated()) {
                                    MedInventory inventory = TradeFormTools.getInventory4TradeForm(resident,
                                            myBHP.getTradeForm());
                                    if (inventory != null) {
                                        MedInventoryTools.withdraw(em, em.merge(inventory), myBHP.getDose(),
                                                weight, myBHP);
                                    } else {
                                        OPDE.getDisplayManager().addSubMessage(
                                                new DisplayMessage("nursingrecords.bhp.NoInventory"));
                                    }
                                }

                                mapBHP2Pane.put(myBHP, createCP4(myBHP));
                                int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp);
                                mapShift2BHP.get(bhp.getShift()).remove(position);
                                mapShift2BHP.get(bhp.getShift()).add(position, myBHP);
                                if (myBHP.isOnDemand()) {
                                    Collections.sort(mapShift2BHP.get(myBHP.getShift()),
                                            BHPTools.getOnDemandComparator());
                                } else {
                                    Collections.sort(mapShift2BHP.get(myBHP.getShift()));
                                }

                                em.getTransaction().commit();
                                mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift()));
                                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.bhp.notchangeable")));
                        }
                    }
                });

                btnRefuseDiscard.setEnabled(
                        !bhp.isOnDemand() && bhp.hasMed() && bhp.shouldBeCalculated() && bhp.isOpen());
                cptitle.getRight().add(btnRefuseDiscard);
            }

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

                    BHP outcomeBHP = BHPTools.getComment(bhp);

                    if (outcomeBHP != null && !outcomeBHP.isOpen()) {
                        // already commented
                        return;
                    }

                    if (BHPTools.isChangeable(bhp)) {
                        EntityManager em = OPDE.createEM();
                        try {
                            em.getTransaction().begin();

                            em.lock(em.merge(resident), LockModeType.OPTIMISTIC);
                            BHP myBHP = em.merge(bhp);

                            em.lock(myBHP, LockModeType.OPTIMISTIC);
                            em.lock(myBHP.getPrescriptionSchedule(), LockModeType.OPTIMISTIC);
                            em.lock(myBHP.getPrescription(), LockModeType.OPTIMISTIC);

                            // the normal BHPs (those assigned to a NursingProcess) are reset to the OPEN state.
                            // TXs are deleted
                            myBHP.setState(BHPTools.STATE_OPEN);
                            myBHP.setUser(null);
                            myBHP.setIst(null);
                            myBHP.setiZeit(null);
                            myBHP.setMDate(new Date());
                            myBHP.setText(null);

                            if (myBHP.shouldBeCalculated()) {
                                for (MedStockTransaction tx : myBHP.getStockTransaction()) {
                                    em.remove(tx);
                                }
                                myBHP.getStockTransaction().clear();
                            }

                            if (outcomeBHP != null) {
                                BHP myOutcomeBHP = em.merge(outcomeBHP);
                                em.remove(myOutcomeBHP);
                            }

                            if (myBHP.isOnDemand()) {
                                em.remove(myBHP);
                            }

                            em.getTransaction().commit();

                            if (myBHP.isOnDemand()) {
                                reload();
                            } else {

                                mapBHP2Pane.put(myBHP, createCP4(myBHP));
                                int position = mapShift2BHP.get(myBHP.getShift()).indexOf(bhp);
                                mapShift2BHP.get(bhp.getShift()).remove(position);
                                mapShift2BHP.get(bhp.getShift()).add(position, myBHP);
                                if (myBHP.isOnDemand()) {
                                    Collections.sort(mapShift2BHP.get(myBHP.getShift()),
                                            BHPTools.getOnDemandComparator());
                                } else {
                                    Collections.sort(mapShift2BHP.get(myBHP.getShift()));
                                }

                                mapShift2Pane.put(myBHP.getShift(), createCP4(myBHP.getShift()));
                                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.bhp.notchangeable")));
                    }
                }
            });
            btnEmpty.setEnabled(!bhp.isOpen());
            cptitle.getRight().add(btnEmpty);
        }

        /***
         *      _     _         ___        __
         *     | |__ | |_ _ __ |_ _|_ __  / _| ___
         *     | '_ \| __| '_ \ | || '_ \| |_ / _ \
         *     | |_) | |_| | | || || | | |  _| (_) |
         *     |_.__/ \__|_| |_|___|_| |_|_|  \___/
         *
         */
        final JButton btnInfo = new JButton(SYSConst.icon22info);

        btnInfo.setPressedIcon(SYSConst.icon22infoPressed);
        btnInfo.setAlignmentX(Component.RIGHT_ALIGNMENT);
        btnInfo.setContentAreaFilled(false);
        btnInfo.setBorder(null);
        btnInfo.setToolTipText(SYSTools.xx("nursingrecords.bhp.btnInfo.tooltip"));
        final JTextPane txt = new JTextPane();
        txt.setContentType("text/html");
        txt.setEditable(false);
        final JidePopup popupInfo = new JidePopup();
        popupInfo.setMovable(false);
        popupInfo.setContentPane(new JScrollPane(txt));
        popupInfo.removeExcludedComponent(txt);
        popupInfo.setDefaultFocusComponent(txt);

        btnInfo.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                popupInfo.setOwner(btnInfo);

                if (bhp.isOutcomeText() && !bhp.isOpen()) {
                    txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getText())));
                } else {
                    txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getPrescription().getText())));
                }

                //                    txt.setText(SYSTools.toHTML(SYSConst.html_div(bhp.getPrescription().getText())));
                GUITools.showPopup(popupInfo, SwingConstants.SOUTH_WEST);
            }
        });

        if (bhp.isOutcomeText() && !bhp.isOpen()) {
            btnInfo.setEnabled(true);
        } else {
            btnInfo.setEnabled(!SYSTools.catchNull(bhp.getPrescription().getText()).isEmpty());
        }

        cptitle.getRight().add(btnInfo);

    }

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

    final JTextPane contentPane = new JTextPane();
    contentPane.setEditable(false);
    contentPane.setContentType("text/html");
    bhpPane.setContentPane(contentPane);
    bhpPane.setBackground(bhp.getBG());
    bhpPane.setForeground(bhp.getFG());

    try {
        bhpPane.setCollapsed(true);
    } catch (PropertyVetoException e) {
        OPDE.error(e);
    }

    bhpPane.addCollapsiblePaneListener(new CollapsiblePaneAdapter() {
        @Override
        public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
            contentPane.setText(SYSTools.toHTML(
                    PrescriptionTools.getPrescriptionAsHTML(bhp.getPrescription(), false, false, true, false)));
        }
    });

    bhpPane.setHorizontalAlignment(SwingConstants.LEADING);
    bhpPane.setOpaque(false);
    return bhpPane;
}

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

private CollapsiblePane createCP4Shift(Byte shift) {
    String title = "<html><font size=+1><b>" + GUITools.getLocalizedMessages(DFNTools.SHIFT_TEXT)[shift]
            + "</b></font></html>";
    final CollapsiblePane mainPane = new CollapsiblePane(title);
    mainPane.setSlidingDirection(SwingConstants.SOUTH);
    mainPane.setBackground(SYSCalendar.getBGSHIFT(shift));
    mainPane.setForeground(SYSCalendar.getFGSHIFT(shift));
    mainPane.setOpaque(false);// ww w.j a  v a  2 s . co  m

    JPanel npPanel = new JPanel();
    npPanel.setLayout(new VerticalLayout());

    boolean containsKey = false;
    synchronized (mapShift2DFN) {
        containsKey = mapShift2DFN.containsKey(shift);
    }

    if (containsKey) {
        if (shift == DFNTools.SHIFT_EARLY) {

            final CollapsiblePane morning = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.morning.long") + "</font></html>", null);
            morning.setSlidingDirection(SwingConstants.SOUTH);
            morning.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            morning.setForeground(Color.white);
            morning.setOpaque(false);
            JPanel pnlMorning = new JPanel();
            pnlMorning.setLayout(new VerticalLayout());
            morning.setContentPane(pnlMorning);

            final CollapsiblePane noon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.noon.long") + "</font></html>", null);
            noon.setSlidingDirection(SwingConstants.SOUTH);
            noon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            noon.setForeground(Color.white);
            noon.setOpaque(false);
            JPanel pnlNoon = new JPanel();
            pnlNoon.setLayout(new VerticalLayout());
            noon.setContentPane(pnlNoon);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            ArrayList<DFN> listDFN = null;
            synchronized (mapShift2DFN) {
                listDFN = mapShift2DFN.get(shift);
            }

            for (DFN dfn : listDFN) {
                npPanel.setBackground(dfn.getBG());
                CollapsiblePane cp1 = createCP4(dfn);
                synchronized (mapDFN2Pane) {
                    mapDFN2Pane.put(dfn, cp1);
                    if (dfn.getSollZeit() == DFNTools.BYTE_MORNING) {
                        pnlMorning.add(mapDFN2Pane.get(dfn));
                    } else if (dfn.getSollZeit() == DFNTools.BYTE_NOON) {
                        pnlNoon.add(mapDFN2Pane.get(dfn));
                    } else {
                        pnlClock.add(mapDFN2Pane.get(dfn));
                    }
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                npPanel.add(clock);
            }
            if (pnlMorning.getComponentCount() > 0) {
                npPanel.add(morning);
            }
            if (pnlNoon.getComponentCount() > 0) {
                npPanel.add(noon);
            }

        } else if (shift == DFNTools.SHIFT_LATE) {
            final CollapsiblePane afternoon = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.afternoon.long") + "</font></html>", null);
            afternoon.setSlidingDirection(SwingConstants.SOUTH);
            afternoon.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            afternoon.setForeground(Color.white);
            afternoon.setOpaque(false);
            JPanel pnlAfternoon = new JPanel();
            pnlAfternoon.setLayout(new VerticalLayout());
            afternoon.setContentPane(pnlAfternoon);

            final CollapsiblePane evening = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.evening.long") + "</font></html>", null);
            evening.setSlidingDirection(SwingConstants.SOUTH);
            evening.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            evening.setForeground(Color.white);
            evening.setOpaque(false);
            JPanel pnlEvening = new JPanel();
            pnlEvening.setLayout(new VerticalLayout());
            evening.setContentPane(pnlEvening);

            final CollapsiblePane clock = new CollapsiblePane(
                    "<html><font size=+1>" + SYSTools.xx("misc.msg.Time.long") + "</font></html>", null);
            clock.setSlidingDirection(SwingConstants.SOUTH);
            clock.setBackground(SYSCalendar.getBGSHIFT(shift).darker());
            clock.setForeground(Color.white);
            clock.setOpaque(false);
            JPanel pnlClock = new JPanel();
            pnlClock.setLayout(new VerticalLayout());
            clock.setContentPane(pnlClock);

            ArrayList<DFN> listDFN = null;
            synchronized (mapShift2DFN) {
                listDFN = mapShift2DFN.get(shift);
            }

            for (DFN dfn : listDFN) {
                npPanel.setBackground(dfn.getBG());
                CollapsiblePane cp1 = createCP4(dfn);
                synchronized (mapDFN2Pane) {
                    mapDFN2Pane.put(dfn, cp1);
                    if (dfn.getSollZeit() == DFNTools.BYTE_AFTERNOON) {
                        pnlAfternoon.add(mapDFN2Pane.get(dfn));
                    } else if (dfn.getSollZeit() == DFNTools.BYTE_EVENING) {
                        pnlEvening.add(mapDFN2Pane.get(dfn));
                    } else {
                        pnlClock.add(mapDFN2Pane.get(dfn));
                    }
                }
            }

            if (pnlClock.getComponentCount() > 0) {
                npPanel.add(clock);
            }
            if (pnlAfternoon.getComponentCount() > 0) {
                npPanel.add(afternoon);
            }
            if (pnlEvening.getComponentCount() > 0) {
                npPanel.add(evening);
            }

        } else {
            ArrayList<DFN> listDFN = null;
            synchronized (mapShift2DFN) {
                listDFN = mapShift2DFN.get(shift);
            }
            for (DFN dfn : listDFN) {
                npPanel.setBackground(dfn.getBG());
                CollapsiblePane cp1 = createCP4(dfn);
                synchronized (mapDFN2Pane) {
                    mapDFN2Pane.put(dfn, cp1);
                    npPanel.add(mapDFN2Pane.get(dfn));
                }
            }
        }
        mainPane.setContentPane(npPanel);
        mainPane.setCollapsible(true);
    } else {
        mainPane.setContentPane(npPanel);
        mainPane.setCollapsible(false);
    }

    return mainPane;
}

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

private CollapsiblePane createCP4OnDemand() {
    /***/*from   ww w.j av  a  2  s.c  o  m*/
     *                          _        ____ ____  _  _
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _|
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_|
     *
     */
    String title = "<html><font size=+1><b>" + SYSTools.xx("nursingrecords.dfn.ondemand")
            + "</b></font></html>";

    final CollapsiblePane npPane = new CollapsiblePane(title);
    npPane.setSlidingDirection(SwingConstants.SOUTH);
    npPane.setBackground(SYSCalendar.getBGSHIFT(DFNTools.SHIFT_ON_DEMAND));
    npPane.setForeground(SYSCalendar.getFGSHIFT(DFNTools.SHIFT_ON_DEMAND));
    npPane.setOpaque(false);

    JPanel npPanel = new JPanel();
    npPanel.setLayout(new VerticalLayout());

    ArrayList<DFN> list = null;
    synchronized (mapShift2DFN) {
        list = mapShift2DFN.containsKey(DFNTools.SHIFT_ON_DEMAND) ? mapShift2DFN.get(DFNTools.SHIFT_ON_DEMAND)
                : null;
    }

    if (list != null && !list.isEmpty()) {
        for (DFN dfn : list) {
            npPanel.setBackground(dfn.getBG());
            CollapsiblePane cp = createCP4(dfn);
            synchronized (mapDFN2Pane) {
                mapDFN2Pane.put(dfn, cp);
                npPanel.add(mapDFN2Pane.get(dfn));
            }
        }
        npPane.setContentPane(npPanel);
        npPane.setCollapsible(true);
    } else {
        npPane.setContentPane(npPanel);
        npPane.setCollapsible(false);
    }

    return npPane;
}