Example usage for java.awt Cursor HAND_CURSOR

List of usage examples for java.awt Cursor HAND_CURSOR

Introduction

In this page you can find the example usage for java.awt Cursor HAND_CURSOR.

Prototype

int HAND_CURSOR

To view the source code for java.awt Cursor HAND_CURSOR.

Click Source Link

Document

The hand cursor type.

Usage

From source file:com.rapidminer.gui.viewer.metadata.AttributeStatisticsPanel.java

/**
 * Initializes the GUI.//from w ww  .  j  a va2 s  . c o m
 *
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void initGUI() {
    setLayout(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();

    // add attribute name
    panelAttName = new JPanel();
    panelAttName.setLayout(new BoxLayout(panelAttName, BoxLayout.PAGE_AXIS));
    panelAttName.setOpaque(false);
    // this border is to visualize that the name column can be enlarged/shrinked
    panelAttName.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.LIGHT_GRAY));

    labelAttHeader = new JLabel(LABEL_DOTS);
    labelAttHeader.setFont(labelAttHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelAttHeader.setForeground(Color.GRAY);
    panelAttName.add(labelAttHeader);

    labelAttName = new JLabel(LABEL_DOTS);
    labelAttName.setFont(labelAttName.getFont().deriveFont(Font.BOLD, FONT_SIZE_LABEL_VALUE));
    labelAttName.setMinimumSize(DIMENSION_LABEL_ATTRIBUTE);
    labelAttName.setPreferredSize(DIMENSION_LABEL_ATTRIBUTE);
    panelAttName.add(labelAttName);

    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.insets = new Insets(3, 20, 3, 10);
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 0.0;
    gbc.weighty = 1.0;
    gbc.gridheight = 2;
    add(panelAttName, gbc);

    // create value type name and bring it to a nice to read format (aka uppercase first letter
    // and replace '_' with ' '
    gbc.gridx += 1;
    gbc.insets = new Insets(5, 15, 5, 10);
    labelAttType = new JLabel(LABEL_DOTS);
    labelAttType.setMinimumSize(DIMENSION_LABEL_TYPE);
    labelAttType.setPreferredSize(DIMENSION_LABEL_TYPE);
    add(labelAttType, gbc);

    // missings panel
    JPanel panelStatsMissing = new JPanel();
    panelStatsMissing.setLayout(new BoxLayout(panelStatsMissing, BoxLayout.PAGE_AXIS));
    panelStatsMissing.setOpaque(false);

    labelStatsMissing = new JLabel(LABEL_DOTS);
    labelStatsMissing.setMinimumSize(DIMENSION_LABEL_MISSINGS);
    labelStatsMissing.setPreferredSize(DIMENSION_LABEL_MISSINGS);
    panelStatsMissing.add(labelStatsMissing);

    gbc.gridx += 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 0.0;
    add(panelStatsMissing, gbc);

    // chart panel(s) (only visible when enlarged)
    JPanel chartPanel = new JPanel(new BorderLayout());
    chartPanel.setBackground(COLOR_TRANSPARENT);
    chartPanel.setOpaque(false);
    listOfChartPanels.add(chartPanel);
    updateVisibilityOfChartPanels();

    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 0.0;
    gbc.insets = new Insets(0, 10, 0, 10);
    for (JPanel panel : listOfChartPanels) {
        gbc.gridx += 1;
        add(panel, gbc);
    }

    // (hidden) construction panel
    String constructionLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.construction.label");
    panelStatsConstruction = new JPanel();
    panelStatsConstruction.setLayout(new BoxLayout(panelStatsConstruction, BoxLayout.PAGE_AXIS));
    panelStatsConstruction.setOpaque(false);
    panelStatsConstruction.setVisible(false);

    JLabel labelConstructionHeader = new JLabel(constructionLabel);
    labelConstructionHeader.setFont(labelConstructionHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelConstructionHeader.setForeground(Color.GRAY);
    panelStatsConstruction.add(labelConstructionHeader);

    labelStatsConstruction = new JLabel(LABEL_DOTS);
    labelStatsConstruction.setFont(labelStatsConstruction.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    labelStatsConstruction.setMinimumSize(DIMENSION_LABEL_CONSTRUCTION);
    labelStatsConstruction.setPreferredSize(DIMENSION_LABEL_CONSTRUCTION);
    panelStatsConstruction.add(labelStatsConstruction);

    gbc.gridx += 1;
    gbc.fill = GridBagConstraints.NONE;
    gbc.weightx = 0.0;
    add(panelStatsConstruction, gbc);

    // statistics panel, contains different statistics panels for numerical/nominal/date_time on
    // a card layout
    // needed to switch between for model swapping
    cardStatsPanel = new JPanel();
    cardStatsPanel.setOpaque(false);
    cardLayout = new CardLayout();
    cardStatsPanel.setLayout(cardLayout);

    // numerical version
    JPanel statsNumPanel = new JPanel();
    GridBagLayout layout = new GridBagLayout();
    GridBagConstraints gbcStatPanel = new GridBagConstraints();
    statsNumPanel.setLayout(layout);
    statsNumPanel.setOpaque(false);

    String avgLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.avg.label");
    String devianceLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.variance.label");
    String minLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.min.label");
    String maxLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.max.label");

    // min value panel
    JPanel panelStatsMin = new JPanel();
    panelStatsMin.setLayout(new BoxLayout(panelStatsMin, BoxLayout.PAGE_AXIS));
    panelStatsMin.setOpaque(false);

    JLabel labelMinHeader = new JLabel(minLabel);
    labelMinHeader.setFont(labelMinHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelMinHeader.setForeground(Color.GRAY);
    panelStatsMin.add(labelMinHeader);

    labelStatsMin = new JLabel(LABEL_DOTS);
    labelStatsMin.setFont(labelStatsMin.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsMin.add(labelStatsMin);

    // max value panel
    JPanel panelStatsMax = new JPanel();
    panelStatsMax.setLayout(new BoxLayout(panelStatsMax, BoxLayout.PAGE_AXIS));
    panelStatsMax.setOpaque(false);

    JLabel labelMaxHeader = new JLabel(maxLabel);
    labelMaxHeader.setFont(labelMaxHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelMaxHeader.setForeground(Color.GRAY);
    panelStatsMax.add(labelMaxHeader);

    labelStatsMax = new JLabel(LABEL_DOTS);
    labelStatsMax.setFont(labelStatsMax.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsMax.add(labelStatsMax);

    // average value panel
    JPanel panelStatsAvg = new JPanel();
    panelStatsAvg.setLayout(new BoxLayout(panelStatsAvg, BoxLayout.PAGE_AXIS));
    panelStatsAvg.setOpaque(false);

    JLabel labelAvgHeader = new JLabel(avgLabel);
    labelAvgHeader.setFont(labelAvgHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelAvgHeader.setForeground(Color.GRAY);
    panelStatsAvg.add(labelAvgHeader);

    labelStatsAvg = new JLabel(LABEL_DOTS);
    labelStatsAvg.setFont(labelStatsAvg.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsAvg.add(labelStatsAvg);

    // deviance value panel
    JPanel panelStatsDeviance = new JPanel();
    panelStatsDeviance.setLayout(new BoxLayout(panelStatsDeviance, BoxLayout.PAGE_AXIS));
    panelStatsDeviance.setOpaque(false);

    JLabel labelDevianceHeader = new JLabel(devianceLabel);
    labelDevianceHeader.setFont(labelDevianceHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelDevianceHeader.setForeground(Color.GRAY);
    panelStatsDeviance.add(labelDevianceHeader);

    labelStatsDeviation = new JLabel(LABEL_DOTS);
    labelStatsDeviation.setFont(labelStatsDeviation.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsDeviance.add(labelStatsDeviation);

    // add sub panels to stats panel
    gbcStatPanel.gridx = 0;
    gbcStatPanel.weightx = 0.0;
    gbcStatPanel.fill = GridBagConstraints.NONE;
    gbcStatPanel.insets = new Insets(0, 0, 0, 4);
    panelStatsMin.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsMin, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsMax.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsMax, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsAvg.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsAvg, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsDeviance.setPreferredSize(DIMENSION_PANEL_NUMERIC_PREF_SIZE);
    statsNumPanel.add(panelStatsDeviance, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    gbcStatPanel.weightx = 1.0;
    gbcStatPanel.fill = GridBagConstraints.HORIZONTAL;
    statsNumPanel.add(new JLabel(), gbcStatPanel);
    cardStatsPanel.add(statsNumPanel, CARD_NUMERICAL);

    // nominal version
    JPanel statsNomPanel = new JPanel();
    statsNomPanel.setLayout(layout);
    statsNomPanel.setOpaque(false);
    String leastLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.least.label");
    String mostLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.most.label");
    String valuesLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.values.label");

    // least panel
    JPanel panelStatsLeast = new JPanel();
    panelStatsLeast.setLayout(new BoxLayout(panelStatsLeast, BoxLayout.PAGE_AXIS));
    panelStatsLeast.setOpaque(false);

    JLabel labelLeastHeader = new JLabel(leastLabel);
    labelLeastHeader.setFont(labelLeastHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelLeastHeader.setForeground(Color.GRAY);
    labelLeastHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    panelStatsLeast.add(labelLeastHeader);

    labelStatsLeast = new JLabel(LABEL_DOTS);
    labelStatsLeast.setFont(labelStatsLeast.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsLeast.add(labelStatsLeast);

    // most panel
    JPanel panelStatsMost = new JPanel();
    panelStatsMost.setLayout(new BoxLayout(panelStatsMost, BoxLayout.PAGE_AXIS));
    panelStatsMost.setOpaque(false);

    JLabel labelMostHeader = new JLabel(mostLabel);
    labelMostHeader.setFont(labelMostHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelMostHeader.setForeground(Color.GRAY);
    labelMostHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    panelStatsMost.add(labelMostHeader);

    labelStatsMost = new JLabel(LABEL_DOTS);
    labelStatsMost.setFont(labelStatsMost.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsMost.add(labelStatsMost);

    // values panel
    JPanel panelStatsValues = new JPanel();
    panelStatsValues.setLayout(new BoxLayout(panelStatsValues, BoxLayout.PAGE_AXIS));
    panelStatsValues.setOpaque(false);

    JLabel labelValuesHeader = new JLabel(valuesLabel);
    labelValuesHeader.setFont(labelValuesHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelValuesHeader.setForeground(Color.GRAY);
    labelValuesHeader.setAlignmentX(Component.LEFT_ALIGNMENT);
    panelStatsValues.add(labelValuesHeader);

    labelStatsValues = new JLabel(LABEL_DOTS);
    labelStatsValues.setFont(labelStatsValues.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsValues.add(labelStatsValues);

    detailsButton = new JButton(new ShowNomValueAction(this));
    detailsButton.setVisible(false);
    detailsButton.setOpaque(false);
    detailsButton.setContentAreaFilled(false);
    detailsButton.setBorderPainted(false);
    detailsButton.addMouseListener(enlargeAndHoverAndPopupMouseAdapter);
    detailsButton.setHorizontalAlignment(SwingConstants.LEFT);
    detailsButton.setHorizontalTextPosition(SwingConstants.LEFT);
    detailsButton.setIcon(null);
    Font font = detailsButton.getFont();
    Map attributes = font.getAttributes();
    attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON);
    detailsButton.setFont(font.deriveFont(attributes));
    panelStatsValues.add(detailsButton);

    // add sub panel to stats panel
    gbcStatPanel.gridx = 0;
    gbcStatPanel.weightx = 0.0;
    gbcStatPanel.fill = GridBagConstraints.NONE;
    gbcStatPanel.insets = new Insets(0, 0, 0, 6);
    panelStatsLeast.setPreferredSize(DIMENSION_PANEL_NOMINAL_PREF_SIZE);
    statsNomPanel.add(panelStatsLeast, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsMost.setPreferredSize(DIMENSION_PANEL_NOMINAL_PREF_SIZE);
    statsNomPanel.add(panelStatsMost, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    statsNomPanel.add(panelStatsValues, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    gbcStatPanel.weightx = 1.0;
    gbcStatPanel.fill = GridBagConstraints.HORIZONTAL;
    statsNomPanel.add(new JLabel(), gbcStatPanel);
    cardStatsPanel.add(statsNomPanel, CARD_NOMINAL);

    // date_time version
    JPanel statsDateTimePanel = new JPanel();
    statsDateTimePanel.setLayout(layout);
    statsDateTimePanel.setOpaque(false);

    String durationLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.duration.label");
    String fromLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.from.label");
    String untilLabel = I18N.getMessage(I18N.getGUIBundle(),
            "gui.label.attribute_statistics.statistics.until.label");

    // min value panel
    JPanel panelStatsFrom = new JPanel();
    panelStatsFrom.setLayout(new BoxLayout(panelStatsFrom, BoxLayout.PAGE_AXIS));
    panelStatsFrom.setOpaque(false);

    JLabel labelFromHeader = new JLabel(fromLabel);
    labelFromHeader.setFont(labelFromHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelFromHeader.setForeground(Color.GRAY);
    panelStatsFrom.add(labelFromHeader);

    labelStatsFrom = new JLabel(LABEL_DOTS);
    labelStatsFrom.setFont(labelStatsFrom.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsFrom.add(labelStatsFrom);

    // until value panel
    JPanel panelStatsUntil = new JPanel();
    panelStatsUntil.setLayout(new BoxLayout(panelStatsUntil, BoxLayout.PAGE_AXIS));
    panelStatsUntil.setOpaque(false);

    JLabel labelUntilHeader = new JLabel(untilLabel);
    labelUntilHeader.setFont(labelUntilHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelUntilHeader.setForeground(Color.GRAY);
    panelStatsUntil.add(labelUntilHeader);

    labelStatsUntil = new JLabel(LABEL_DOTS);
    labelStatsUntil.setFont(labelStatsUntil.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsUntil.add(labelStatsUntil);

    // duration value panel
    JPanel panelStatsDuration = new JPanel();
    panelStatsDuration.setLayout(new BoxLayout(panelStatsDuration, BoxLayout.PAGE_AXIS));
    panelStatsDuration.setOpaque(false);

    JLabel labelDurationHeader = new JLabel(durationLabel);
    labelDurationHeader.setFont(labelDurationHeader.getFont().deriveFont(FONT_SIZE_LABEL_HEADER));
    labelDurationHeader.setForeground(Color.GRAY);
    panelStatsDuration.add(labelDurationHeader);

    labelStatsDuration = new JLabel(LABEL_DOTS);
    labelStatsDuration.setFont(labelStatsDuration.getFont().deriveFont(FONT_SIZE_LABEL_VALUE));
    panelStatsDuration.add(labelStatsDuration);

    // add sub panels to stats panel
    gbcStatPanel.gridx = 0;
    gbcStatPanel.weightx = 0.0;
    gbcStatPanel.fill = GridBagConstraints.NONE;
    gbcStatPanel.insets = new Insets(0, 0, 0, 6);
    panelStatsFrom.setPreferredSize(DIMENSION_PANEL_DATE_PREF_SIZE);
    statsDateTimePanel.add(panelStatsFrom, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsUntil.setPreferredSize(DIMENSION_PANEL_DATE_PREF_SIZE);
    statsDateTimePanel.add(panelStatsUntil, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    panelStatsDuration.setPreferredSize(DIMENSION_PANEL_DATE_PREF_SIZE);
    statsDateTimePanel.add(panelStatsDuration, gbcStatPanel);
    gbcStatPanel.gridx += 1;
    gbcStatPanel.weightx = 1.0;
    gbcStatPanel.fill = GridBagConstraints.HORIZONTAL;
    statsDateTimePanel.add(new JLabel(), gbcStatPanel);
    cardStatsPanel.add(statsDateTimePanel, CARD_DATE_TIME);

    // add stats panel to main gui
    gbc.gridx += 1;
    gbc.insets = new Insets(5, 10, 5, 10);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.anchor = GridBagConstraints.WEST;
    add(cardStatsPanel, gbc);

    // needed so we can draw our own background
    setOpaque(false);

    // handle mouse events for hover effect and enlarging/shrinking
    addMouseListener(enlargeAndHoverAndPopupMouseAdapter);

    // change cursor to indicate this component can be clicked
    setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}

From source file:ca.phon.ipamap.IpaMap.java

private JXButton getToggleButton(Grid grid, JXCollapsiblePane cp) {
    Action toggleAction = cp.getActionMap().get(JXCollapsiblePane.TOGGLE_ACTION);

    // use the collapse/expand icons from the JTree UI
    toggleAction.putValue(JXCollapsiblePane.COLLAPSE_ICON, UIManager.getIcon("Tree.expandedIcon"));
    toggleAction.putValue(JXCollapsiblePane.EXPAND_ICON, UIManager.getIcon("Tree.collapsedIcon"));
    toggleAction.putValue(Action.NAME, grid.getName());

    JXButton btn = new JXButton(toggleAction) {
        @Override/*  ww  w .ja  v a2  s.  co  m*/
        public Insets getInsets() {
            Insets retVal = super.getInsets();

            retVal.top = 0;
            retVal.bottom = 0;

            return retVal;
        }

        @Override
        public Dimension getPreferredSize() {
            return new Dimension(0, 20);
        }

    };

    btn.setHorizontalAlignment(SwingConstants.LEFT);

    btn.setBackgroundPainter(new Painter<JXButton>() {

        @Override
        public void paint(Graphics2D g, JXButton object, int width, int height) {
            MattePainter mp = new MattePainter(UIManager.getColor("Button.background"));
            mp.paint(g, object, width, height);
        }
    });

    btn.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    btn.setBorderPainted(false);
    btn.setFocusable(false);

    btn.putClientProperty("JComponent.sizeVariant", "small");

    btn.revalidate();

    return btn;
}

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

private CollapsiblePane createCP4(final MedStock stock) {
    /***//from ww w.j a  va 2  s.c o m
     *                          _        ____ ____  _  _    __   _             _   __
     *       ___ _ __ ___  __ _| |_ ___ / ___|  _ \| || |  / /__| |_ ___   ___| | _\ \
     *      / __| '__/ _ \/ _` | __/ _ \ |   | |_) | || |_| / __| __/ _ \ / __| |/ /| |
     *     | (__| | |  __/ (_| | ||  __/ |___|  __/|__   _| \__ \ || (_) | (__|   < | |
     *      \___|_|  \___|\__,_|\__\___|\____|_|      |_| | |___/\__\___/ \___|_|\_\| |
     *                                                     \_\                     /_/
     */
    final String key = stock.getID() + ".xstock";
    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("stock");

        BigDecimal sumStock = BigDecimal.ZERO;
        try {
            EntityManager em = OPDE.createEM();
            sumStock = MedStockTools.getSum(em, stock);
            em.close();
        } catch (Exception e) {
            OPDE.fatal(e);
        }

        String title = "<html><table border=\"0\">" + "<tr>" + (stock.isClosed() ? "<s>" : "")
                + "<td width=\"600\" align=\"left\">" + MedStockTools.getAsHTML(stock) + "</td>"
                + "<td width=\"200\" align=\"right\">" + NumberFormat.getNumberInstance().format(sumStock) + " "
                + DosageFormTools.getPackageText(MedInventoryTools.getForm(stock.getInventory())) + "</td>"
                + (stock.isClosed() ? "</s>" : "") + "</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.getRight().add(new StockPanel(stock));

        if (!stock.getInventory().isClosed()) {
            /***
             *      ____       _       _   _          _          _
             *     |  _ \ _ __(_)_ __ | |_| |    __ _| |__   ___| |
             *     | |_) | '__| | '_ \| __| |   / _` | '_ \ / _ \ |
             *     |  __/| |  | | | | | |_| |__| (_| | |_) |  __/ |
             *     |_|   |_|  |_|_| |_|\__|_____\__,_|_.__/ \___|_|
             *
             */
            final JButton btnPrintLabel = new JButton(SYSConst.icon22print2);
            btnPrintLabel.setPressedIcon(SYSConst.icon22print2Pressed);
            btnPrintLabel.setAlignmentX(Component.RIGHT_ALIGNMENT);
            btnPrintLabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
            btnPrintLabel.setContentAreaFilled(false);
            btnPrintLabel.setBorder(null);
            btnPrintLabel.setToolTipText(SYSTools.xx("nursingrecords.inventory.stock.btnprintlabel.tooltip"));
            btnPrintLabel.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent actionEvent) {
                    LogicalPrinter logicalPrinter = OPDE.getLogicalPrinters().getMapName2LogicalPrinter()
                            .get(OPDE.getProps().getProperty(SYSPropsTools.KEY_LOGICAL_PRINTER));
                    PrinterForm printerForm1 = logicalPrinter.getForms()
                            .get(OPDE.getProps().getProperty(SYSPropsTools.KEY_MEDSTOCK_LABEL));
                    OPDE.getPrintProcessor().addPrintJob(new PrintListElement(stock, logicalPrinter,
                            printerForm1, OPDE.getProps().getProperty(SYSPropsTools.KEY_PHYSICAL_PRINTER)));
                }
            });
            btnPrintLabel.setEnabled(OPDE.getPrintProcessor().isWorking());
            cptitle.getRight().add(btnPrintLabel);
        }

        /***
         *      __  __
         *     |  \/  | ___ _ __  _   _
         *     | |\/| |/ _ \ '_ \| | | |
         *     | |  | |  __/ | | | |_| |
         *     |_|  |_|\___|_| |_|\__,_|
         *
         */
        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(stock);
                popup.getContentPane().add(pnl);
                popup.setDefaultFocusComponent(pnl);

                GUITools.showPopup(popup, SwingConstants.WEST);
            }
        });
        cptitle.getRight().add(btnMenu);

        CollapsiblePaneAdapter adapter = new CollapsiblePaneAdapter() {
            @Override
            public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) {
                cpMap.get(key).setContentPane(createContentPanel4(stock));
            }
        };
        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()) {
            JPanel contentPane = createContentPanel4(stock);
            cpMap.get(key).setContentPane(contentPane);
        }

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

        return cpMap.get(key);
    }
}

From source file:convcao.com.agent.ConvcaoNeptusInteraction.java

@Override
public void initSubPanel() {
    jPanelMain = new JPanel();
    jPanel1 = new JPanel();
    jPanel2 = new JPanel();
    jLabel2 = new JLabel();
    jScrollPane1 = new JScrollPane();
    jTextPane1 = new JTextPane();
    renewButton = new JButton();
    jLabel4 = new JLabel();
    jTextField1 = new JTextField();
    jLabel5 = new JLabel();
    jPasswordField1 = new JPasswordField();
    connectButton = new JButton();
    jScrollPane2 = new JScrollPane();
    jTextArea1 = new JTextArea();
    jLabel7 = new JLabel();
    jLabel8 = new JLabel();
    jButton1 = new JButton();
    jButton2 = new JButton();
    jLabel1 = new JLabel();
    jLabel9 = new JLabel();
    jLabel10 = new JLabel();
    jLabel11 = new JLabel();
    jLabel12 = new JLabel();
    jLabel6 = new JLabel();
    jLabel3 = new JLabel();

    jLabel11.setIcon(noptilusLogo);//  w w w.  j  a v a 2  s .  c  o  m

    jLabel12.setHorizontalAlignment(SwingConstants.LEFT);
    jLabel12.setText("<html>www.convcao.com<br>version 0.01</html>");
    jLabel12.setToolTipText("");
    jLabel12.setHorizontalTextPosition(SwingConstants.RIGHT);

    GroupLayout jPanel1Layout = new GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addComponent(jLabel11, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(GroupLayout.Alignment.TRAILING,
                    jPanel1Layout.createSequentialGroup().addGap(0, 19, Short.MAX_VALUE).addComponent(jLabel12,
                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)));
    jPanel1Layout.setVerticalGroup(jPanel1Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                    .addComponent(jLabel11, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED).addComponent(jLabel12,
                            GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)));

    jLabel2.setFont(new Font("Tahoma", 0, 10)); // NOI18N
    jLabel2.setText("Unique ID");

    jTextPane1.setEditable(true);
    jScrollPane1.setViewportView(jTextPane1);
    //jTextPane1.getAccessibleContext().setAccessibleName("");

    renewButton.setText("RENEW");
    renewButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            renewButtonActionPerformed(evt);
        }
    });

    jLabel4.setFont(new Font("Tahoma", 0, 12)); // NOI18N
    jLabel4.setText("Username");

    jTextField1.setText("FTPUser");

    jLabel5.setFont(new Font("Tahoma", 0, 12)); // NOI18N
    jLabel5.setText("Password");

    jPasswordField1.setText("FTPUser123");

    connectButton.setText("Connect");
    connectButton.setEnabled(false);
    connectButton.setActionCommand("connect");
    connectButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            try {
                connectButtonActionPerformed(evt);
            } catch (FileNotFoundException | UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (SocketException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    });

    jTextArea1.setEditable(false);
    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane2.setViewportView(jTextArea1);

    jLabel7.setFont(new Font("Tahoma", 0, 12)); // NOI18N
    jLabel7.setText("Command Monitor");

    jButton1.setFont(new Font("Tahoma", 1, 12)); // NOI18N
    jButton1.setText("START");
    jButton1.setEnabled(false);
    jButton1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            startButtonActionPerformed(evt);
        }
    });

    jButton2.setFont(new Font("Tahoma", 1, 12)); // NOI18N
    jButton2.setText("STOP");
    jButton2.setEnabled(false);
    jButton2.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            stopButtonActionPerformed(evt);
        }
    });

    jLabel1.setForeground(new Color(255, 0, 0));
    jLabel1.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel1.setText(
            "<html>Click HERE to activate the web service using your ID<br>When the web application is ready, press Start </html>");
    jLabel1.setCursor(new Cursor(Cursor.HAND_CURSOR));
    jLabel1.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent evt) {
            try {
                jLabel1MouseClicked(evt);
            } catch (URISyntaxException | IOException e) {
                e.printStackTrace();
            }
        }
    });

    //jLabel9.setText("Working...");
    jLabel9.setIcon(runIcon);
    jLabel9.setVisible(false);

    jLabel10.setText("---");

    jLabel6.setForeground(new Color(0, 204, 0));
    jLabel6.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel6.setText("---");

    GroupLayout jPanel2Layout = new GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
            GroupLayout.Alignment.TRAILING,
            jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                    .createParallelGroup(GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup().addContainerGap().addComponent(jLabel6,
                            GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                                    .addGroup(jPanel2Layout.createSequentialGroup().addGap(126, 126, 126)
                                            .addComponent(jLabel7, GroupLayout.PREFERRED_SIZE, 110,
                                                    GroupLayout.PREFERRED_SIZE))
                                    .addGroup(jPanel2Layout.createSequentialGroup().addGap(23, 23, 23)
                                            .addGroup(jPanel2Layout
                                                    .createParallelGroup(GroupLayout.Alignment.TRAILING)
                                                    .addGroup(jPanel2Layout
                                                            .createParallelGroup(GroupLayout.Alignment.LEADING,
                                                                    false)
                                                            .addGroup(GroupLayout.Alignment.TRAILING,
                                                                    jPanel2Layout.createSequentialGroup()
                                                                            .addComponent(jLabel9,
                                                                                    GroupLayout.PREFERRED_SIZE,
                                                                                    56,
                                                                                    GroupLayout.PREFERRED_SIZE)
                                                                            .addPreferredGap(
                                                                                    LayoutStyle.ComponentPlacement.RELATED,
                                                                                    GroupLayout.DEFAULT_SIZE,
                                                                                    Short.MAX_VALUE)
                                                                            .addComponent(jButton1,
                                                                                    GroupLayout.PREFERRED_SIZE,
                                                                                    80,
                                                                                    GroupLayout.PREFERRED_SIZE)
                                                                            .addGap(29, 29, 29)
                                                                            .addComponent(jButton2,
                                                                                    GroupLayout.PREFERRED_SIZE,
                                                                                    77,
                                                                                    GroupLayout.PREFERRED_SIZE))
                                                            .addComponent(jScrollPane2,
                                                                    GroupLayout.Alignment.TRAILING,
                                                                    GroupLayout.PREFERRED_SIZE, 308,
                                                                    GroupLayout.PREFERRED_SIZE))
                                                    .addComponent(jLabel10, GroupLayout.Alignment.LEADING,
                                                            GroupLayout.PREFERRED_SIZE, 103,
                                                            GroupLayout.PREFERRED_SIZE)
                                                    .addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 299,
                                                            GroupLayout.PREFERRED_SIZE))))
                            .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup().addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(
                                    GroupLayout.Alignment.TRAILING,
                                    jPanel2Layout.createSequentialGroup()
                                            .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 80,
                                                    GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18)
                                            .addComponent(jScrollPane1, GroupLayout.PREFERRED_SIZE, 130,
                                                    GroupLayout.PREFERRED_SIZE)
                                            .addGap(18, 18, 18).addComponent(renewButton))
                                    .addGroup(GroupLayout.Alignment.TRAILING,
                                            jPanel2Layout.createSequentialGroup().addGroup(jPanel2Layout
                                                    .createParallelGroup(GroupLayout.Alignment.LEADING, false)
                                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                                            .addComponent(jLabel4, GroupLayout.PREFERRED_SIZE,
                                                                    64, GroupLayout.PREFERRED_SIZE)
                                                            .addGap(18, 18, 18).addComponent(jTextField1,
                                                                    GroupLayout.PREFERRED_SIZE, 130,
                                                                    GroupLayout.PREFERRED_SIZE))
                                                    .addGroup(jPanel2Layout.createSequentialGroup()
                                                            .addComponent(jLabel5, GroupLayout.PREFERRED_SIZE,
                                                                    64, GroupLayout.PREFERRED_SIZE)
                                                            .addGap(18, 18, 18).addComponent(jPasswordField1)))
                                                    .addGap(14, 14, 14).addComponent(connectButton)))))
                    .addContainerGap()));
    jPanel2Layout.setVerticalGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                    .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.LEADING, false)
                            .addComponent(renewButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(jScrollPane1)
                            .addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE))
                    .addGap(18, 18, 18)
                    .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel4, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(jTextField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel5, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(jPasswordField1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
                                    GroupLayout.PREFERRED_SIZE)
                            .addComponent(connectButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel6, GroupLayout.PREFERRED_SIZE, 21, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel1)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel7, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jScrollPane2, GroupLayout.PREFERRED_SIZE, 113, GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel2Layout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(jButton1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(jLabel9, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel10, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
                    .addGap(5, 5, 5)));

    jLabel1.getAccessibleContext().setAccessibleName("jLabel1");

    jLabel3.setFont(new Font("Tahoma", 1, 22)); // NOI18N
    jLabel3.setText("Real Time Navigation");

    jLabel8.setIcon(appLogo);

    GroupLayout layout = new GroupLayout(jPanelMain);
    jPanelMain.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel3)
                    .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE)
                            .addComponent(jLabel8, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
                                    Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel2, GroupLayout.PREFERRED_SIZE, 331, GroupLayout.PREFERRED_SIZE)
                    .addContainerGap()));
    layout.setVerticalGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING).addGroup(layout
            .createSequentialGroup().addComponent(jLabel3)
            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel8, GroupLayout.PREFERRED_SIZE, 110, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED).addComponent(jPanel1,
                                    GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jPanel2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap()));

    addMenuItem("Settings>Noptilus>Coordinate Settings",
            ImageUtils.getIcon(PluginUtils.getPluginIcon(getClass())), new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    PluginUtils.editPluginProperties(coords, true);
                    coords.saveProps();
                }
            });

    addMenuItem("Settings>Noptilus>ConvCAO Settings", ImageUtils.getIcon(PluginUtils.getPluginIcon(getClass())),
            new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    PluginUtils.editPluginProperties(ConvcaoNeptusInteraction.this, true);
                }
            });

    addMenuItem("Settings>Noptilus>Force vehicle depth",
            ImageUtils.getIcon(PluginUtils.getPluginIcon(getClass())), new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    if (positions.isEmpty()) {
                        GuiUtils.errorMessage(getConsole(), "Force vehicle depth",
                                "ConvCAO control is not active");
                        return;
                    }
                    String[] choices = nameTable.values().toArray(new String[0]);

                    String vehicle = (String) JOptionPane.showInputDialog(getConsole(), "Force vehicle depth",
                            "Choose vehicle", JOptionPane.QUESTION_MESSAGE, null, choices, choices[0]);

                    if (vehicle != null) {
                        double depth = depths.get(vehicle);
                        String newDepth = JOptionPane.showInputDialog(getConsole(), "New depth", "" + depth);
                        try {
                            double dd = Double.parseDouble(newDepth);
                            depths.put(vehicle, dd);
                        } catch (Exception ex) {
                            GuiUtils.errorMessage(getConsole(), ex);
                        }
                    }
                }
            });

    add(jPanelMain);

    renewButtonActionPerformed(null);
}

From source file:savant.view.swing.GraphPane.java

/**
 * {@inheritDoc}//from  ww w  . j a va2s  .  c o  m
 */
@Override
public void mouseDragged(MouseEvent event) {

    setMouseModifier(event);

    GraphPaneController gpc = GraphPaneController.getInstance();
    int x2 = getConstrainedX(event);

    isDragging = true;

    if (gpc.isPanning()) {
        setCursor(new Cursor(Cursor.HAND_CURSOR));
    } else if (gpc.isZooming() || gpc.isSelecting()) {
        setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
    }

    // Check if scrollbar is present (only vertical pan if present)
    JScrollBar scroller = getVerticalScrollBar();
    boolean scroll = scroller.isVisible();

    if (scroll) {

        //get new points
        Point l = event.getLocationOnScreen();
        int currX = l.x;
        int currY = l.y;

        //magnitude
        int magX = Math.abs(currX - startX);
        int magY = Math.abs(currY - startY);

        if (magX >= magY) {
            //pan horizontally, reset vertical pan
            panVert = false;
            gpc.setMouseReleasePosition(transformXPixel(x2));
            scroller.setValue(initialScroll);
        } else {
            //pan vertically, reset horizontal pan
            panVert = true;
            gpc.setMouseReleasePosition(baseX);
            scroller.setValue(initialScroll - (currY - startY));
        }
    } else {
        //pan horizontally
        panVert = false;
        gpc.setMouseReleasePosition(transformXPixel(x2));
    }
}

From source file:ExText.java

/**
 * Respond to a button1 event (press, release, or drag).
 * /*from  ww  w .  j  ava 2  s.com*/
 * @param mouseEvent
 *            A MouseEvent to respond to.
 */
public void onButton1(MouseEvent mev) {
    if (subjectTransformGroup == null)
        return;

    int x = mev.getX();
    int y = mev.getY();

    if (mev.getID() == MouseEvent.MOUSE_PRESSED) {
        // Mouse button pressed: record position
        previousX = x;
        previousY = y;

        // Change to a "move" cursor
        if (parentComponent != null) {
            savedCursor = parentComponent.getCursor();
            parentComponent.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        }
        return;
    }
    if (mev.getID() == MouseEvent.MOUSE_RELEASED) {
        // Mouse button released: do nothing

        // Switch the cursor back
        if (parentComponent != null)
            parentComponent.setCursor(savedCursor);
        return;
    }

    //
    // Mouse moved while button down: create a rotation
    //
    // Compute the delta in X and Y from the previous
    // position. Use the delta to compute rotation
    // angles with the mapping:
    //
    //   positive X mouse delta --> positive Y-axis rotation
    //   positive Y mouse delta --> positive X-axis rotation
    //
    // where positive X mouse movement is to the right, and
    // positive Y mouse movement is **down** the screen.
    //
    int deltaX = x - previousX;
    int deltaY = y - previousY;

    if (deltaX > UNUSUAL_XDELTA || deltaX < -UNUSUAL_XDELTA || deltaY > UNUSUAL_YDELTA
            || deltaY < -UNUSUAL_YDELTA) {
        // Deltas are too huge to be believable. Probably a glitch.
        // Don't record the new XY location, or do anything.
        return;
    }

    double xRotationAngle = deltaY * XRotationFactor;
    double yRotationAngle = deltaX * YRotationFactor;

    //
    // Build transforms
    //
    transform1.rotX(xRotationAngle);
    transform2.rotY(yRotationAngle);

    // Get and save the current transform matrix
    subjectTransformGroup.getTransform(currentTransform);
    currentTransform.get(matrix);
    translate.set(matrix.m03, matrix.m13, matrix.m23);

    // Translate to the origin, rotate, then translate back
    currentTransform.setTranslation(origin);
    currentTransform.mul(transform1, currentTransform);
    currentTransform.mul(transform2, currentTransform);
    currentTransform.setTranslation(translate);

    // Update the transform group
    subjectTransformGroup.setTransform(currentTransform);

    previousX = x;
    previousY = y;
}

From source file:userinterface.properties.GUIGraphHandler.java

public void plotNewFunction() {

    JDialog dialog;//from w ww.j a  v a2  s .  c  o  m
    JRadioButton radio2d, radio3d, newGraph, existingGraph;
    JTextField functionField, seriesName;
    JButton ok, cancel;
    JComboBox<String> chartOptions;
    JLabel example;

    //init all the fields of the dialog
    dialog = new JDialog(GUIPrism.getGUI());
    radio2d = new JRadioButton("2D");
    radio3d = new JRadioButton("3D");
    newGraph = new JRadioButton("New Graph");
    existingGraph = new JRadioButton("Exisiting");
    chartOptions = new JComboBox<String>();
    functionField = new JTextField();
    ok = new JButton("Plot");
    cancel = new JButton("Cancel");
    seriesName = new JTextField();
    example = new JLabel("<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
    example.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseEntered(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.HAND_CURSOR));
            example.setForeground(Color.BLUE);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            example.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
            example.setForeground(Color.BLACK);
        }

        @Override
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {

                if (radio2d.isSelected()) {
                    functionField.setText("x/2 + 5");
                } else {
                    functionField.setText("x+y+5");
                }

                functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
                functionField.setForeground(Color.BLACK);

            }
        }

    });

    //set dialog properties
    dialog.setSize(400, 350);
    dialog.setTitle("Plot a new function");
    dialog.setModal(true);
    dialog.setLayout(new BoxLayout(dialog.getContentPane(), BoxLayout.Y_AXIS));
    dialog.setLocationRelativeTo(GUIPrism.getGUI());

    //add every component to their dedicated panels
    JPanel graphTypePanel = new JPanel(new FlowLayout());
    graphTypePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function type"));
    graphTypePanel.add(radio2d);
    graphTypePanel.add(radio3d);

    JPanel functionFieldPanel = new JPanel(new BorderLayout());
    functionFieldPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Function"));
    functionFieldPanel.add(functionField, BorderLayout.CENTER);
    functionFieldPanel.add(example, BorderLayout.SOUTH);

    JPanel chartSelectPanel = new JPanel();
    chartSelectPanel.setLayout(new BoxLayout(chartSelectPanel, BoxLayout.Y_AXIS));
    chartSelectPanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Plot function to"));
    JPanel radioPlotPanel = new JPanel(new FlowLayout());
    radioPlotPanel.add(newGraph);
    radioPlotPanel.add(existingGraph);
    JPanel chartOptionsPanel = new JPanel(new FlowLayout());
    chartOptionsPanel.add(chartOptions);
    chartSelectPanel.add(radioPlotPanel);
    chartSelectPanel.add(chartOptionsPanel);

    JPanel bottomControlPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    bottomControlPanel.add(ok);
    bottomControlPanel.add(cancel);

    JPanel seriesNamePanel = new JPanel(new BorderLayout());
    seriesNamePanel.setBorder(BorderFactory
            .createTitledBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), "Series name"));
    seriesNamePanel.add(seriesName, BorderLayout.CENTER);

    // add all the panels to the dialog

    dialog.add(graphTypePanel);
    dialog.add(functionFieldPanel);
    dialog.add(chartSelectPanel);
    dialog.add(seriesNamePanel);
    dialog.add(bottomControlPanel);

    // do all the enables and set properties

    radio2d.setSelected(true);
    newGraph.setSelected(true);
    chartOptions.setEnabled(false);
    functionField.setText("Add function expression here....");
    functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
    functionField.setForeground(Color.GRAY);
    seriesName.setText("New function");
    ok.setMnemonic('P');
    cancel.setMnemonic('C');
    example.setToolTipText("click to try out");

    ok.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "ok");
    ok.getActionMap().put("ok", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            ok.doClick();
        }
    });

    cancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            "cancel");
    cancel.getActionMap().put("cancel", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            cancel.doClick();
        }
    });

    boolean found = false;

    for (int i = 0; i < theTabs.getTabCount(); i++) {

        if (theTabs.getComponentAt(i) instanceof Graph) {
            chartOptions.addItem(getGraphName(i));
            found = true;
        }
    }

    if (!found) {

        existingGraph.setEnabled(false);
        chartOptions.setEnabled(false);
    }

    //add all the action listeners

    radio2d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio2d.isSelected()) {

                radio3d.setSelected(false);

                if (chartOptions.getItemCount() > 0) {
                    existingGraph.setEnabled(true);
                    chartOptions.setEnabled(true);
                }

                example.setText(
                        "<html><font size=3 color=red>Example:</font><font size=3>x/2 + 5</font></html>");
            }
        }
    });

    radio3d.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (radio3d.isSelected()) {

                radio2d.setSelected(false);
                newGraph.setSelected(true);
                existingGraph.setEnabled(false);
                chartOptions.setEnabled(false);
                example.setText("<html><font size=3 color=red>Example:</font><font size=3>x+y+5</font></html>");

            }

        }
    });

    newGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (newGraph.isSelected()) {
                existingGraph.setSelected(false);
                chartOptions.setEnabled(false);
            }
        }
    });

    existingGraph.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (existingGraph.isSelected()) {

                newGraph.setSelected(false);
                chartOptions.setEnabled(true);
            }
        }
    });

    ok.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {

            String function = functionField.getText();

            Expression expr = null;

            try {

                expr = GUIPrism.getGUI().getPrism().parseSingleExpressionString(function);
                expr = (Expression) expr.accept(new ASTTraverseModify() {

                    @Override
                    public Object visit(ExpressionIdent e) throws PrismLangException {
                        return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                    }

                });

                expr.typeCheck();
                expr.semanticCheck();

            } catch (PrismLangException e1) {

                // for copying style
                JLabel label = new JLabel();

                // html content in our case the error we want to show
                JEditorPane ep = new JEditorPane("text/html",
                        "<html> There was an error parsing the function. To read about what built-in"
                                + " functions are supported <br>and some more information on the functions, visit "
                                + "<a href='http://www.prismmodelchecker.org/manual/ThePRISMLanguage/Expressions'>Prism expressions site</a>."
                                + "<br><br><font color=red>Error: </font>" + e1.getMessage() + " </html>");

                // handle link events
                ep.addHyperlinkListener(new HyperlinkListener() {
                    @Override
                    public void hyperlinkUpdate(HyperlinkEvent e) {
                        if (e.getEventType().equals(HyperlinkEvent.EventType.ACTIVATED)) {
                            try {
                                Desktop.getDesktop().browse(e.getURL().toURI());
                            } catch (IOException | URISyntaxException e1) {

                                e1.printStackTrace();
                            }
                        }
                    }
                });
                ep.setEditable(false);
                ep.setBackground(label.getBackground());

                // show the error dialog
                JOptionPane.showMessageDialog(dialog, ep, "Parse Error", JOptionPane.ERROR_MESSAGE);
                return;
            }

            if (radio2d.isSelected()) {

                ParametricGraph graph = null;

                if (newGraph.isSelected()) {

                    graph = new ParametricGraph("");
                } else {

                    for (int i = 0; i < theTabs.getComponentCount(); i++) {

                        if (theTabs.getTitleAt(i).equals(chartOptions.getSelectedItem())) {

                            graph = (ParametricGraph) theTabs.getComponent(i);
                        }
                    }

                }

                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), newGraph.isSelected(), true);

            } else if (radio3d.isSelected()) {

                try {

                    expr = (Expression) expr.accept(new ASTTraverseModify() {
                        @Override
                        public Object visit(ExpressionIdent e) throws PrismLangException {
                            return new ExpressionConstant(e.getName(), TypeDouble.getInstance());
                        }

                    });

                    expr.semanticCheck();
                    expr.typeCheck();

                } catch (PrismLangException e1) {
                    e1.printStackTrace();
                }

                if (expr.getAllConstants().size() < 2) {

                    JOptionPane.showMessageDialog(dialog,
                            "There are not enough variables in the function to plot a 3D chart!", "Error",
                            JOptionPane.ERROR_MESSAGE);
                    return;
                }

                // its always a new graph
                ParametricGraph3D graph = new ParametricGraph3D(expr);
                dialog.dispose();
                defineConstantsAndPlot(expr, graph, seriesName.getText(), true, false);
            }

            dialog.dispose();
        }
    });

    cancel.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    });

    // we will show info about the function when field is out of focus
    functionField.addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {

            if (!functionField.getText().equals("")) {
                return;
            }

            functionField.setText("Add function expression here....");
            functionField.setFont(new Font(Font.SANS_SERIF, Font.ITALIC, 15));
            functionField.setForeground(Color.GRAY);
        }

        @Override
        public void focusGained(FocusEvent e) {

            if (!functionField.getText().equals("Add function expression here....")) {
                return;
            }

            functionField.setForeground(Color.BLACK);
            functionField.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 15));
            functionField.setText("");
        }
    });

    // show the dialog
    dialog.setVisible(true);
}

From source file:op.allowance.PnlAllowance.java

private JPanel createContentPanel4(final Resident resident, LocalDate month) {
    final String key = getKey(resident, month);

    if (!contentmap.containsKey(key)) {

        JPanel pnlMonth = new JPanel(new VerticalLayout());

        pnlMonth.setBackground(getBG(resident, 11));
        pnlMonth.setOpaque(false);//from  w  ww  .j  a v  a2  s .co m

        //            final String prevKey = resident.getRID() + "-" + SYSCalendar.eom(month.minusMonths(1)).getYear() + "-" + SYSCalendar.eom(month.minusMonths(1)).getMonthOfYear();
        if (!carrySums.containsKey(key)) {
            carrySums.put(key, AllowanceTools.getSUM(resident, SYSCalendar.eom(month.minusMonths(1))));
        }

        BigDecimal rowsum = carrySums.get(key);

        if (!cashmap.containsKey(key)) {
            cashmap.put(key, AllowanceTools.getMonth(resident, month.toDate()));
        }

        JLabel lblEOM = new JLabel("<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">"
                + DateFormat.getDateInstance().format(month.dayOfMonth().withMaximumValue().toDate()) + "</td>"
                + "<td width=\"400\" align=\"left\">" + SYSTools.xx("admin.residents.cash.endofmonth") + "</td>"
                + "<td width=\"100\" align=\"right\"></td>" + "<td width=\"100\" align=\"right\">"
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum)
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>" +

                "</font></html>");
        pnlMonth.add(lblEOM);

        for (final Allowance allowance : cashmap.get(key)) {

            String title = "<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">"
                    + DateFormat.getDateInstance().format(allowance.getPit()) + "</td>"
                    + "<td width=\"400\" align=\"left\">" + allowance.getText() + "</td>"
                    + "<td width=\"100\" align=\"right\">"
                    + (allowance.getAmount().compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "")
                    + cf.format(allowance.getAmount())
                    + (allowance.getAmount().compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>"
                    + "<td width=\"100\" align=\"right\">"
                    + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum)
                    + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>"
                    +

                    "</font></html>";

            DefaultCPTitle cptitle = new DefaultCPTitle(title, new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {

                }
            });
            cptitle.getButton().setIcon(
                    allowance.isReplaced() || allowance.isReplacement() ? SYSConst.icon22eraser : null);

            if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) {
                /***
                 *      _____    _ _ _
                 *     | ____|__| (_) |_
                 *     |  _| / _` | | __|
                 *     | |__| (_| | | |_
                 *     |_____\__,_|_|\__|
                 *
                 */
                final JButton btnEdit = new JButton(SYSConst.icon22edit3);
                btnEdit.setPressedIcon(SYSConst.icon22edit3Pressed);
                btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnEdit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnEdit.setContentAreaFilled(false);
                btnEdit.setBorder(null);
                btnEdit.setToolTipText(SYSTools.xx("admin.residents.cash.btnedit.tooltip"));
                btnEdit.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {

                        final JidePopup popupTX = new JidePopup();
                        popupTX.setMovable(false);
                        PnlTX pnlTX = getPnlTX(resident, allowance);
                        popupTX.setContentPane(pnlTX);
                        popupTX.removeExcludedComponent(pnlTX);
                        popupTX.setDefaultFocusComponent(pnlTX);

                        popupTX.setOwner(btnEdit);
                        GUITools.showPopup(popupTX, SwingConstants.WEST);

                    }
                });
                cptitle.getRight().add(btnEdit);
                // you can edit your own entries or you are a manager. once they are replaced or a replacement record, its over.
                btnEdit.setEnabled((OPDE.getAppInfo().isAllowedTo(InternalClassACL.MANAGER, internalClassID)
                        || allowance.getUser().equals(OPDE.getLogin().getUser())) && !allowance.isReplaced()
                        && !allowance.isReplacement());

                /***
                 *      _   _           _         _______  __
                 *     | | | |_ __   __| | ___   |_   _\ \/ /
                 *     | | | | '_ \ / _` |/ _ \    | |  \  /
                 *     | |_| | | | | (_| | (_) |   | |  /  \
                 *      \___/|_| |_|\__,_|\___/    |_| /_/\_\
                 *
                 */
                final JButton btnUndoTX = new JButton(SYSConst.icon22undo);
                btnUndoTX.setPressedIcon(SYSConst.icon22Pressed);
                btnUndoTX.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnUndoTX.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnUndoTX.setContentAreaFilled(false);
                btnUndoTX.setBorder(null);
                btnUndoTX.setToolTipText(SYSTools.xx("admin.residents.cash.btnundotx.tooltip"));
                btnUndoTX.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {

                        new DlgYesNo(
                                SYSTools.xx("misc.questions.undo1") + "<br/><i>" + "<br/><i>"
                                        + allowance.getText() + "&nbsp;" + cf.format(allowance.getAmount())
                                        + "</i><br/>" + SYSTools.xx("misc.questions.undo2"),
                                SYSConst.icon48undo, new Closure() {
                                    @Override
                                    public void execute(Object answer) {
                                        if (answer.equals(JOptionPane.YES_OPTION)) {
                                            EntityManager em = OPDE.createEM();
                                            try {
                                                em.getTransaction().begin();

                                                Allowance myOldAllowance = em.merge(allowance);
                                                Allowance myCancelAllowance = em
                                                        .merge(new Allowance(myOldAllowance));
                                                em.lock(em.merge(myOldAllowance.getResident()),
                                                        LockModeType.OPTIMISTIC);
                                                em.lock(myOldAllowance, LockModeType.OPTIMISTIC);
                                                myOldAllowance.setReplacedBy(myCancelAllowance,
                                                        em.merge(OPDE.getLogin().getUser()));

                                                em.getTransaction().commit();

                                                DateTime txDate = new DateTime(myCancelAllowance.getPit());

                                                final String keyMonth = myCancelAllowance.getResident().getRID()
                                                        + "-" + txDate.getYear() + "-"
                                                        + txDate.getMonthOfYear();
                                                contentmap.remove(keyMonth);
                                                cpMap.remove(keyMonth);
                                                cashmap.get(keyMonth).remove(allowance);
                                                cashmap.get(keyMonth).add(myOldAllowance);
                                                cashmap.get(keyMonth).add(myCancelAllowance);
                                                Collections.sort(cashmap.get(keyMonth));

                                                updateCarrySums(myCancelAllowance);

                                                createCP4(myCancelAllowance.getResident());

                                                try {
                                                    cpMap.get(keyMonth).setCollapsed(false);
                                                } catch (PropertyVetoException e) {
                                                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                                                }

                                                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(btnUndoTX);
                btnUndoTX.setEnabled(!allowance.isReplaced() && !allowance.isReplacement());
            }

            if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) {
                /***
                 *      ____       _      _
                 *     |  _ \  ___| | ___| |_ ___
                 *     | | | |/ _ \ |/ _ \ __/ _ \
                 *     | |_| |  __/ |  __/ ||  __/
                 *     |____/ \___|_|\___|\__\___|
                 *
                 */
                final JButton btnDelete = new JButton(SYSConst.icon22delete);
                btnDelete.setPressedIcon(SYSConst.icon22deletePressed);
                btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT);
                btnDelete.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
                btnDelete.setContentAreaFilled(false);
                btnDelete.setBorder(null);
                btnDelete.setToolTipText(SYSTools.xx("admin.residents.cash.btndelete.tooltip"));
                btnDelete.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent actionEvent) {
                        new DlgYesNo(
                                SYSTools.xx("misc.questions.delete1") + "<br/><i>" + allowance.getText()
                                        + "&nbsp;" + cf.format(allowance.getAmount()) + "</i><br/>"
                                        + SYSTools.xx("misc.questions.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();
                                                Allowance myAllowance = em.merge(allowance);
                                                em.lock(em.merge(myAllowance.getResident()),
                                                        LockModeType.OPTIMISTIC);

                                                Allowance theOtherOne = null;
                                                // Check for special cases
                                                if (myAllowance.isReplacement()) {
                                                    theOtherOne = em.merge(myAllowance.getReplacementFor());
                                                    theOtherOne.setReplacedBy(null);
                                                    theOtherOne.setEditedBy(null);
                                                    myAllowance.setEditPit(null);
                                                }
                                                if (myAllowance.isReplaced()) {
                                                    theOtherOne = em.merge(myAllowance.getReplacedBy());
                                                    theOtherOne.setReplacementFor(null);
                                                }

                                                em.remove(myAllowance);
                                                em.getTransaction().commit();

                                                DateTime txDate = new DateTime(myAllowance.getPit());
                                                final String keyMonth = myAllowance.getResident().getRID() + "-"
                                                        + txDate.getYear() + "-" + txDate.getMonthOfYear();

                                                cpMap.remove(keyMonth);
                                                cashmap.get(keyMonth).remove(myAllowance);
                                                if (theOtherOne != null) {
                                                    cashmap.get(keyMonth).remove(theOtherOne);
                                                    cashmap.get(keyMonth).add(theOtherOne);
                                                    Collections.sort(cashmap.get(keyMonth));
                                                }

                                                // only to update the carrysums. myAllowance will be discarded soon.
                                                myAllowance.setAmount(myAllowance.getAmount().negate());
                                                updateCarrySums(myAllowance);

                                                createCP4(myAllowance.getResident());

                                                try {
                                                    if (cpMap.containsKey(keyMonth)) {
                                                        cpMap.get(keyMonth).setCollapsed(false);
                                                    }
                                                } catch (PropertyVetoException e) {
                                                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                                                }

                                                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(btnDelete);
            }
            pnlMonth.add(cptitle.getMain());
            linemap.put(allowance, cptitle.getMain());

            rowsum = rowsum.subtract(allowance.getAmount());
        }

        JLabel lblBOM = new JLabel("<html><table border=\"0\">" + "<tr>" + "<td width=\"130\" align=\"left\">"
                + DateFormat.getDateInstance().format(month.dayOfMonth().withMinimumValue().toDate()) + "</td>"
                + "<td width=\"400\" align=\"left\">" + SYSTools.xx("admin.residents.cash.startofmonth")
                + "</td>" + "<td width=\"100\" align=\"right\"></td>" + "<td width=\"100\" align=\"right\">"
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "<font color=\"red\">" : "") + cf.format(rowsum)
                + (rowsum.compareTo(BigDecimal.ZERO) < 0 ? "</font>" : "") + "</td>" + "</tr>" + "</table>" +

                "</font></html>");
        lblBOM.setBackground(getBG(resident, 11));
        pnlMonth.add(lblBOM);
        contentmap.put(key, pnlMonth);
    }

    return contentmap.get(key);
}

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

private JPanel createContentPanel4Day(LocalDate day) {
    //        OPDE.getDisplayManager().setProgressBarMessage(new DisplayMessage("misc.msg.wait", progress, progressMax));
    //        progress++;

    final String key = DateFormat.getDateInstance().format(day.toDate());
    synchronized (contentmap) {
        if (contentmap.containsKey(key)) {
            return contentmap.get(key);
        }/*from  w  w w. j  a  v a 2 s.  c  om*/
    }
    final JPanel dayPanel = new JPanel(new VerticalLayout());
    dayPanel.setOpaque(false);
    synchronized (valuecache) {
        if (!valuecache.containsKey(key)) {
            valuecache.put(key, NReportTools.getNReports4Day(resident, day));
        }

        int i = 0; // for zebra pattern
        for (final NReport nreport : valuecache.get(key)) {

            if (tbShowReplaced.isSelected() || !nreport.isObsolete()) {

                String title = SYSTools.toHTMLForScreen(SYSConst.html_table(SYSConst
                        .html_table_tr("<td width=\"800\" align=\"left\">" + "<b><p>"
                                + (nreport.isObsolete() ? SYSConst.html_16x16_Eraser_internal : "")
                                + (nreport.isReplacement() ? SYSConst.html_16x16_Edited_internal : "")
                                + DateFormat.getTimeInstance(DateFormat.SHORT).format(nreport.getPit()) + " "
                                + SYSTools.xx("misc.msg.Time.short") + ", " + nreport.getMinutes() + " "
                                + SYSTools.xx("misc.msg.Minute(s)") + ", " + nreport.getUser().getFullname()
                                + (nreport.getCommontags().isEmpty() ? ""
                                        : " " + CommontagsTools.getAsHTML(nreport.getCommontags(),
                                                SYSConst.html_16x16_tagPurple_internal))
                                + "</p></b></td>")
                        + SYSConst.html_table_tr("<td width=\"800\" align=\"left\">"
                                + SYSTools.replace(nreport.getText(), "\n", "<br/>", false) + "</td>"),
                        "0"));

                final DefaultCPTitle pnlSingle = new DefaultCPTitle(SYSTools.toHTMLForScreen(title), null);
                pnlSingle.getButton().addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        GUITools.showPopup(GUITools.getHTMLPopup(pnlSingle.getButton(),
                                NReportTools.getInfoAsHTML(nreport)), SwingConstants.NORTH);
                    }
                });

                if (!nreport.getAttachedFilesConnections().isEmpty()) {
                    /***
                     *      _     _         _____ _ _
                     *     | |__ | |_ _ __ |  ___(_) | ___  ___
                     *     | '_ \| __| '_ \| |_  | | |/ _ \/ __|
                     *     | |_) | |_| | | |  _| | | |  __/\__ \
                     *     |_.__/ \__|_| |_|_|   |_|_|\___||___/
                     *
                     */
                    final JButton btnFiles = new JButton(
                            Integer.toString(nreport.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) {
                            Closure fileHandleClosure = OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE,
                                    internalClassID) ? null : new Closure() {
                                        @Override
                                        public void execute(Object o) {
                                            EntityManager em = OPDE.createEM();
                                            final NReport myReport = em.find(NReport.class, nreport.getID());
                                            em.close();

                                            final String keyNewDay = DateFormat.getDateInstance()
                                                    .format(myReport.getPit());

                                            synchronized (contentmap) {
                                                contentmap.remove(keyNewDay);
                                            }
                                            synchronized (linemap) {
                                                linemap.remove(nreport);
                                            }

                                            synchronized (valuecache) {
                                                valuecache.get(keyNewDay).remove(nreport);
                                                valuecache.get(keyNewDay).add(myReport);
                                                Collections.sort(valuecache.get(keyNewDay));
                                            }

                                            createCP4Day(new LocalDate(myReport.getPit()));

                                            buildPanel();
                                            GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2);
                                        }
                                    };
                            new DlgFiles(nreport, fileHandleClosure);
                        }
                    });
                    btnFiles.setEnabled(OPDE.isFTPworking());
                    pnlSingle.getRight().add(btnFiles);
                }

                if (!nreport.getAttachedQProcessConnections().isEmpty()) {
                    /***
                     *      _     _         ____
                     *     | |__ | |_ _ __ |  _ \ _ __ ___   ___ ___  ___ ___
                     *     | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __|
                     *     | |_) | |_| | | |  __/| | | (_) | (_|  __/\__ \__ \
                     *     |_.__/ \__|_| |_|_|   |_|  \___/ \___\___||___/___/
                     *
                     */
                    final JButton btnProcess = new JButton(
                            Integer.toString(nreport.getAttachedQProcessConnections().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(nreport, 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);
                                        NReport myReport = em.merge(nreport);
                                        em.lock(myReport, LockModeType.OPTIMISTIC_FORCE_INCREMENT);

                                        ArrayList<SYSNR2PROCESS> attached = new ArrayList<SYSNR2PROCESS>(
                                                myReport.getAttachedQProcessConnections());
                                        for (SYSNR2PROCESS linkObject : attached) {
                                            if (unassigned.contains(linkObject.getQProcess())) {
                                                linkObject.getQProcess().getAttachedNReportConnections()
                                                        .remove(linkObject);
                                                linkObject.getNReport().getAttachedQProcessConnections()
                                                        .remove(linkObject);
                                                em.merge(new PReport(
                                                        SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT)
                                                                + ": " + nreport.getTitle() + " ID: "
                                                                + nreport.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(myReport)) {
                                                QProcess myQProcess = em.merge(qProcess);
                                                SYSNR2PROCESS myLinkObject = em
                                                        .merge(new SYSNR2PROCESS(myQProcess, myReport));
                                                em.merge(new PReport(
                                                        SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT)
                                                                + ": " + nreport.getTitle() + " ID: "
                                                                + nreport.getID(),
                                                        PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess));
                                                qProcess.getAttachedNReportConnections().add(myLinkObject);
                                                myReport.getAttachedQProcessConnections().add(myLinkObject);
                                            }
                                        }

                                        em.getTransaction().commit();

                                        final String keyNewDay = DateFormat.getDateInstance()
                                                .format(myReport.getPit());

                                        synchronized (contentmap) {
                                            contentmap.remove(keyNewDay);
                                        }
                                        synchronized (linemap) {
                                            linemap.remove(nreport);
                                        }

                                        synchronized (valuecache) {
                                            valuecache.get(keyNewDay).remove(nreport);
                                            valuecache.get(keyNewDay).add(myReport);
                                            Collections.sort(valuecache.get(keyNewDay));
                                        }

                                        createCP4Day(new LocalDate(myReport.getPit()));

                                        buildPanel();
                                        GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2);
                                    } 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();
                                        } else {
                                            reloadDisplay(true);
                                        }
                                    } 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));
                    pnlSingle.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(nreport);
                        popup.getContentPane().add(pnl);
                        popup.setDefaultFocusComponent(pnl);

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

                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);
                linemap.put(nreport, pnlSingle.getMain());
            }
        }
    }
    synchronized (contentmap) {
        contentmap.put(key, dayPanel);
    }
    return dayPanel;
}

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

private List<Component> addFilters() {
    List<Component> list = new ArrayList<Component>();

    jdcDate = new JDateChooser(new Date());
    jdcDate.setFont(new Font("Arial", Font.PLAIN, 14));

    jdcDate.setBackground(Color.WHITE);

    list.add(jdcDate);/*from   www.j  a v a 2s. c o  m*/

    JPanel buttonPanel = new JPanel();
    buttonPanel.setBackground(Color.WHITE);
    buttonPanel.setLayout(new HorizontalLayout(5));
    buttonPanel.setBorder(new EmptyBorder(0, 0, 0, 0));

    final JButton homeButton = new JButton(
            new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_start.png")));
    homeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            jdcDate.setDate(jdcDate.getMinSelectableDate());
        }
    });
    homeButton.setPressedIcon(
            new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_start_pressed.png")));
    homeButton.setBorder(null);
    homeButton.setBorderPainted(false);
    homeButton.setOpaque(false);
    homeButton.setContentAreaFilled(false);
    homeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    final JButton backButton = new JButton(
            new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_back.png")));
    backButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            DateMidnight current = new DateMidnight(jdcDate.getDate());
            DateMidnight min = new DateMidnight(jdcDate.getMinSelectableDate());
            if (current.equals(min)) {
                return;
            }
            jdcDate.setDate(SYSCalendar.addDate(jdcDate.getDate(), -1));
        }
    });
    backButton
            .setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_back_pressed.png")));
    backButton.setBorder(null);
    backButton.setBorderPainted(false);
    backButton.setOpaque(false);
    backButton.setContentAreaFilled(false);
    backButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    final JButton fwdButton = new JButton(
            new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_play.png")));
    fwdButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            DateMidnight current = new DateMidnight(jdcDate.getDate());
            if (current.equals(new DateMidnight())) {
                return;
            }
            jdcDate.setDate(SYSCalendar.addDate(jdcDate.getDate(), 1));
        }
    });
    fwdButton
            .setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_play_pressed.png")));
    fwdButton.setBorder(null);
    fwdButton.setBorderPainted(false);
    fwdButton.setOpaque(false);
    fwdButton.setContentAreaFilled(false);
    fwdButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    final JButton endButton = new JButton(
            new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_end.png")));
    endButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            jdcDate.setDate(new Date());
        }
    });
    endButton.setPressedIcon(new ImageIcon(getClass().getResource("/artwork/32x32/bw/player_end_pressed.png")));
    endButton.setBorder(null);
    endButton.setBorderPainted(false);
    endButton.setOpaque(false);
    endButton.setContentAreaFilled(false);
    endButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

    buttonPanel.add(homeButton);
    buttonPanel.add(backButton);
    buttonPanel.add(fwdButton);
    buttonPanel.add(endButton);

    list.add(buttonPanel);

    jdcDate.addPropertyChangeListener(new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (initPhase) {
                return;
            }
            if (evt.getPropertyName().equals("date")) {
                reloadDisplay();
            }
        }
    });

    return list;
}