Example usage for javax.swing JPanel setCursor

List of usage examples for javax.swing JPanel setCursor

Introduction

In this page you can find the example usage for javax.swing JPanel setCursor.

Prototype

public void setCursor(Cursor cursor) 

Source Link

Document

Sets the cursor image to the specified cursor.

Usage

From source file:com.igormaznitsa.sciareto.ui.MainFrame.java

public MainFrame(@Nonnull @MustNotContainNull final String... args) {
    super();/*  ww  w .  j  a  va  2  s  .c  om*/
    initComponents();

    this.stackPanel = new JPanel();
    this.stackPanel.setFocusable(false);
    this.stackPanel.setOpaque(false);
    this.stackPanel.setBorder(BorderFactory.createEmptyBorder(32, 32, 16, 32));
    this.stackPanel.setLayout(new BoxLayout(this.stackPanel, BoxLayout.Y_AXIS));

    final JPanel glassPanel = (JPanel) this.getGlassPane();
    glassPanel.setOpaque(false);

    this.setGlassPane(glassPanel);

    glassPanel.setLayout(new BorderLayout(8, 8));
    glassPanel.add(Box.createGlue(), BorderLayout.CENTER);

    final JPanel ppanel = new JPanel(new BorderLayout(0, 0));
    ppanel.setFocusable(false);
    ppanel.setOpaque(false);
    ppanel.setCursor(null);
    ppanel.add(this.stackPanel, BorderLayout.SOUTH);

    glassPanel.add(ppanel, BorderLayout.EAST);

    this.stackPanel.add(Box.createGlue());

    glassPanel.setVisible(false);

    this.setTitle("Scia Reto");

    setIconImage(UiUtils.loadImage("logo256x256.png"));

    this.stateless = args.length > 0;

    final MainFrame theInstance = this;

    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(@Nonnull final WindowEvent e) {
            if (doClosing()) {
                dispose();
            }
        }
    });

    this.tabPane = new EditorTabPane(this);

    this.explorerTree = new ExplorerTree(this);

    final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPane.setOneTouchExpandable(true);
    splitPane.setDividerLocation(250);
    splitPane.setResizeWeight(0.0d);
    splitPane.setLeftComponent(this.explorerTree);
    splitPane.setRightComponent(this.tabPane);

    add(splitPane, BorderLayout.CENTER);

    this.menuOpenRecentProject.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedProjects = FileHistoryManager.getInstance().getLastOpenedProjects();
            if (lastOpenedProjects.length > 0) {
                for (final File folder : lastOpenedProjects) {
                    final JMenuItem item = new JMenuItem(folder.getName());
                    item.setToolTipText(folder.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openProject(folder, false);
                        }
                    });
                    menuOpenRecentProject.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentProject.removeAll();
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    this.menuOpenRecentFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            final File[] lastOpenedFiles = FileHistoryManager.getInstance().getLastOpenedFiles();
            if (lastOpenedFiles.length > 0) {
                for (final File file : lastOpenedFiles) {
                    final JMenuItem item = new JMenuItem(file.getName());
                    item.setToolTipText(file.getAbsolutePath());
                    item.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            openFileAsTab(file);
                        }
                    });
                    menuOpenRecentFile.add(item);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            menuOpenRecentFile.removeAll();
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });

    if (!this.stateless) {
        restoreState();
    } else {
        boolean openedProject = false;
        for (final String filePath : args) {
            final File file = new File(filePath);
            if (file.isDirectory()) {
                openedProject = true;
                openProject(file, true);
            } else if (file.isFile()) {
                openFileAsTab(file);
            }
        }
        if (!openedProject) {
            //TODO try to hide project panel!
        }
    }

    final LookAndFeel current = UIManager.getLookAndFeel();
    final ButtonGroup lfGroup = new ButtonGroup();
    final String currentLFClassName = current.getClass().getName();
    for (final UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
        final JRadioButtonMenuItem menuItem = new JRadioButtonMenuItem(info.getName());
        lfGroup.add(menuItem);
        if (currentLFClassName.equals(info.getClassName())) {
            menuItem.setSelected(true);
        }
        menuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(@Nonnull final ActionEvent e) {
                try {
                    UIManager.setLookAndFeel(info.getClassName());
                    SwingUtilities.updateComponentTreeUI(theInstance);
                    PreferencesManager.getInstance().getPreferences().put(Main.PROPERTY_LOOKANDFEEL,
                            info.getClassName());
                    PreferencesManager.getInstance().flush();
                } catch (Exception ex) {
                    LOGGER.error("Can't change LF", ex);
                }
            }
        });
        this.menuLookAndFeel.add(menuItem);
    }
}

From source file:com.floreantpos.jasperreport.swing.JRViewerPanel.java

protected void createHyperlinks(List elements, int offsetX, int offsetY) {
    if (elements != null && elements.size() > 0) {
        for (Iterator it = elements.iterator(); it.hasNext();) {
            JRPrintElement element = (JRPrintElement) it.next();

            JRImageMapRenderer imageMap = null;
            if (element instanceof JRPrintImage) {
                JRRenderable renderer = ((JRPrintImage) element).getRenderer();
                if (renderer instanceof JRImageMapRenderer) {
                    imageMap = (JRImageMapRenderer) renderer;
                    if (!imageMap.hasImageAreaHyperlinks()) {
                        imageMap = null;
                    }/*from  w  w  w .j av  a 2s. co  m*/
                }
            }
            boolean hasImageMap = imageMap != null;

            JRPrintHyperlink hyperlink = null;
            if (element instanceof JRPrintHyperlink) {
                hyperlink = (JRPrintHyperlink) element;
            }
            boolean hasHyperlink = !hasImageMap && hyperlink != null
                    && hyperlink.getHyperlinkTypeValue() != HyperlinkTypeEnum.NONE;
            boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null;

            if (hasHyperlink || hasImageMap || hasTooltip) {
                JPanel link;
                if (hasImageMap) {
                    Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight());
                    link = new ImageMapPanel(renderingArea, imageMap);
                } else //hasImageMap
                {
                    link = new JPanel();
                    if (hasHyperlink) {
                        link.addMouseListener(mouseListener);
                    }
                }

                if (hasHyperlink) {
                    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                link.setLocation((int) ((element.getX() + offsetX) * realZoom),
                        (int) ((element.getY() + offsetY) * realZoom));
                link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom));
                link.setOpaque(false);

                String toolTip = getHyperlinkTooltip(hyperlink);
                if (toolTip == null && hasImageMap) {
                    toolTip = "";//not null to register the panel as having a tool tip
                }
                link.setToolTipText(toolTip);

                pnlLinks.add(link);
                linksMap.put(link, element);
            }

            if (element instanceof JRPrintFrame) {
                JRPrintFrame frame = (JRPrintFrame) element;
                int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding().intValue();
                int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding().intValue();
                createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY);
            }
        }
    }
}

From source file:net.sf.jasperreports.swing.JRViewerPanel.java

protected void createHyperlinks(List<JRPrintElement> elements, int offsetX, int offsetY) {
    if (elements != null && elements.size() > 0) {
        for (Iterator<JRPrintElement> it = elements.iterator(); it.hasNext();) {
            JRPrintElement element = it.next();

            AreaHyperlinksRenderable imageMap = null;
            if (element instanceof JRPrintImage) {
                Renderable renderer = ((JRPrintImage) element).getRenderer();
                if (renderer instanceof AreaHyperlinksRenderable) {
                    imageMap = (AreaHyperlinksRenderable) renderer;
                    if (!imageMap.hasImageAreaHyperlinks()) {
                        imageMap = null;
                    }//from  w w  w  .  ja  v a2 s .co m
                }
            }
            boolean hasImageMap = imageMap != null;

            JRPrintHyperlink hyperlink = null;
            if (element instanceof JRPrintHyperlink) {
                hyperlink = (JRPrintHyperlink) element;
            }
            boolean hasHyperlink = !hasImageMap && hyperlink != null
                    && hyperlink.getHyperlinkTypeValue() != HyperlinkTypeEnum.NONE;
            boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null;

            if (hasHyperlink || hasImageMap || hasTooltip) {
                JPanel link;
                if (hasImageMap) {
                    Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight());
                    link = new ImageMapPanel(renderingArea, imageMap);
                } else //hasImageMap
                {
                    link = new JPanel();
                    if (hasHyperlink) {
                        link.addMouseListener(mouseListener);
                    }
                }

                if (hasHyperlink) {
                    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                link.setLocation((int) ((element.getX() + offsetX) * realZoom),
                        (int) ((element.getY() + offsetY) * realZoom));
                link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom));
                link.setOpaque(false);

                String toolTip = getHyperlinkTooltip(hyperlink);
                if (toolTip == null && hasImageMap) {
                    toolTip = "";//not null to register the panel as having a tool tip
                }
                link.setToolTipText(toolTip);

                pnlLinks.add(link);
                linksMap.put(link, hyperlink);
            }

            if (element instanceof JRPrintFrame) {
                JRPrintFrame frame = (JRPrintFrame) element;
                int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding();
                int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding();
                createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY);
            }
        }
    }
}

From source file:com.openbravo.pos.util.JRViewer411.java

protected void createHyperlinks(List<JRPrintElement> elements, int offsetX, int offsetY) {
    if (elements != null && elements.size() > 0) {
        for (Iterator<JRPrintElement> it = elements.iterator(); it.hasNext();) {
            JRPrintElement element = it.next();

            JRImageMapRenderer imageMap = null;
            if (element instanceof JRPrintImage) {
                JRRenderable renderer = ((JRPrintImage) element).getRenderer();
                if (renderer instanceof JRImageMapRenderer) {
                    imageMap = (JRImageMapRenderer) renderer;
                    if (!imageMap.hasImageAreaHyperlinks()) {
                        imageMap = null;
                    }//from  w  w  w .  j  av a2  s .co  m
                }
            }
            boolean hasImageMap = imageMap != null;

            JRPrintHyperlink hyperlink = null;
            if (element instanceof JRPrintHyperlink) {
                hyperlink = (JRPrintHyperlink) element;
            }
            boolean hasHyperlink = !hasImageMap && hyperlink != null
                    && hyperlink.getHyperlinkTypeValue() != HyperlinkTypeEnum.NONE;
            boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null;

            if (hasHyperlink || hasImageMap || hasTooltip) {
                JPanel link;
                if (hasImageMap) {
                    Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight());
                    link = new ImageMapPanel(renderingArea, imageMap);
                } else //hasImageMap
                {
                    link = new JPanel();
                    if (hasHyperlink) {
                        link.addMouseListener(mouseListener);
                    }
                }

                if (hasHyperlink) {
                    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                link.setLocation((int) ((element.getX() + offsetX) * realZoom),
                        (int) ((element.getY() + offsetY) * realZoom));
                link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom));
                link.setOpaque(false);

                String toolTip = getHyperlinkTooltip(hyperlink);
                if (toolTip == null && hasImageMap) {
                    toolTip = "";//not null to register the panel as having a tool tip
                }
                link.setToolTipText(toolTip);

                pnlLinks.add(link);
                linksMap.put(link, hyperlink);
            }

            if (element instanceof JRPrintFrame) {
                JRPrintFrame frame = (JRPrintFrame) element;
                int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding().intValue();
                int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding().intValue();
                createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY);
            }
        }
    }
}

From source file:neg.JRViewer.java

protected void createHyperlinks(List elements, int offsetX, int offsetY) {
    if (elements != null && elements.size() > 0) {
        for (Iterator it = elements.iterator(); it.hasNext();) {
            JRPrintElement element = (JRPrintElement) it.next();

            JRImageMapRenderer imageMap = null;
            if (element instanceof JRPrintImage) {
                JRRenderable renderer = ((JRPrintImage) element).getRenderer();
                if (renderer instanceof JRImageMapRenderer) {
                    imageMap = (JRImageMapRenderer) renderer;
                    if (!imageMap.hasImageAreaHyperlinks()) {
                        imageMap = null;
                    }//from w w w.  j  av a  2s.c  o  m
                }
            }
            boolean hasImageMap = imageMap != null;

            JRPrintHyperlink hyperlink = null;
            if (element instanceof JRPrintHyperlink) {
                hyperlink = (JRPrintHyperlink) element;
            }
            boolean hasHyperlink = !hasImageMap && hyperlink != null
                    && hyperlink.getHyperlinkType() != JRHyperlink.HYPERLINK_TYPE_NONE;
            boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null;

            if (hasHyperlink || hasImageMap || hasTooltip) {
                JPanel link;
                if (hasImageMap) {
                    Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight());
                    link = new ImageMapPanel(renderingArea, imageMap);
                } else //hasImageMap
                {
                    link = new JPanel();
                    if (hasHyperlink) {
                        link.addMouseListener(mouseListener);
                    }
                }

                if (hasHyperlink) {
                    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                link.setLocation((int) ((element.getX() + offsetX) * realZoom),
                        (int) ((element.getY() + offsetY) * realZoom));
                link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom));
                link.setOpaque(false);

                String toolTip = getHyperlinkTooltip(hyperlink);
                if (toolTip == null && hasImageMap) {
                    toolTip = "";//not null to register the panel as having a tool tip
                }
                link.setToolTipText(toolTip);

                pnlLinks.add(link);
                linksMap.put(link, element);
            }

            if (element instanceof JRPrintFrame) {
                JRPrintFrame frame = (JRPrintFrame) element;
                int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding().intValue();
                int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding().intValue();
                createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY);
            }
        }
    }
}

From source file:cn.pholance.datamanager.common.components.JRViewer.java

protected void createHyperlinks(List<JRPrintElement> elements, int offsetX, int offsetY) {
    if (elements != null && elements.size() > 0) {
        for (Iterator<JRPrintElement> it = elements.iterator(); it.hasNext();) {
            JRPrintElement element = it.next();

            ImageMapRenderable imageMap = null;
            if (element instanceof JRPrintImage) {
                Renderable renderer = ((JRPrintImage) element).getRenderable();
                if (renderer instanceof ImageMapRenderable) {
                    imageMap = (ImageMapRenderable) renderer;
                    if (!imageMap.hasImageAreaHyperlinks()) {
                        imageMap = null;
                    }//from  w  w  w. j  av a2  s .  c o  m
                }
            }
            boolean hasImageMap = imageMap != null;

            JRPrintHyperlink hyperlink = null;
            if (element instanceof JRPrintHyperlink) {
                hyperlink = (JRPrintHyperlink) element;
            }
            boolean hasHyperlink = !hasImageMap && hyperlink != null
                    && hyperlink.getHyperlinkTypeValue() != HyperlinkTypeEnum.NONE;
            boolean hasTooltip = hyperlink != null && hyperlink.getHyperlinkTooltip() != null;

            if (hasHyperlink || hasImageMap || hasTooltip) {
                JPanel link;
                if (hasImageMap) {
                    Rectangle renderingArea = new Rectangle(0, 0, element.getWidth(), element.getHeight());
                    link = new ImageMapPanel(renderingArea, imageMap);
                } else //hasImageMap
                {
                    link = new JPanel();
                    if (hasHyperlink) {
                        link.addMouseListener(mouseListener);
                    }
                }

                if (hasHyperlink) {
                    link.setCursor(new Cursor(Cursor.HAND_CURSOR));
                }

                link.setLocation((int) ((element.getX() + offsetX) * realZoom),
                        (int) ((element.getY() + offsetY) * realZoom));
                link.setSize((int) (element.getWidth() * realZoom), (int) (element.getHeight() * realZoom));
                link.setOpaque(false);

                String toolTip = getHyperlinkTooltip(hyperlink);
                if (toolTip == null && hasImageMap) {
                    toolTip = "";//not null to register the panel as having a tool tip
                }
                link.setToolTipText(toolTip);

                pnlLinks.add(link);
                linksMap.put(link, hyperlink);
            }

            if (element instanceof JRPrintFrame) {
                JRPrintFrame frame = (JRPrintFrame) element;
                int frameOffsetX = offsetX + frame.getX() + frame.getLineBox().getLeftPadding().intValue();
                int frameOffsetY = offsetY + frame.getY() + frame.getLineBox().getTopPadding().intValue();
                createHyperlinks(frame.getElements(), frameOffsetX, frameOffsetY);
            }
        }
    }
}

From source file:org.genedb.jogra.plugins.TermRationaliser.java

/**
 * Supplies the JPanel which is displayed in the main Jogra window.
 *//*from  w  w  w.j  a  v a 2 s.  co  m*/
public JPanel getMainWindowPlugin() {

    final JPanel ret = new JPanel();
    final JButton loadButton = new JButton("Load Term Rationaliser");
    final JLabel chooseType = new JLabel("Select term: ");
    final JComboBox termTypeBox = new JComboBox(instances.keySet().toArray());
    final JCheckBox showEVCFilter = new JCheckBox("Highlight terms with evidence codes", true);

    loadButton.addActionListener(new ActionListener() {
        public void actionPerformed(final ActionEvent ae) {

            new SwingWorker<JFrame, Void>() {
                @Override
                protected JFrame doInBackground() throws Exception {
                    ret.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                    setTermType(instances.get((String) termTypeBox.getSelectedItem()));
                    setShowEVC(showEVCFilter.isSelected());
                    return makeWindow();
                }

                @Override
                public void done() {
                    try {
                        final GeneDBMessage e = new OpenWindowEvent(TermRationaliser.this, get());
                        EventBus.publish(e);
                    } catch (final InterruptedException exp) {
                        exp.printStackTrace();
                    } catch (final ExecutionException exp) {
                        exp.printStackTrace();
                    }
                    ret.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
                }
            }.execute();
        }
    });
    Box verticalBox = Box.createVerticalBox();
    Box horizontalBox = Box.createHorizontalBox();
    horizontalBox.add(chooseType);
    horizontalBox.add(termTypeBox);
    verticalBox.add(horizontalBox);
    verticalBox.add(loadButton);
    verticalBox.add(showEVCFilter);
    ret.add(verticalBox);
    return ret;
}

From source file:view.ImagePanel.java

public void refreshSignatureValidationListPanels() {
    for (JPanel jp : panelList) {
        remove(jp);//from   www . j av a2 s. c om
    }

    if (buf == null) {
        return;
    }

    if (pdfDocument != null) {
        if (svList != null) {
            Point p = getImageLocation();
            for (final SignatureValidation sv : svList) {
                try {
                    int pgNumber = sv.getPosList().get(0).page - 1;
                    if (this.pageNumber == pgNumber) {
                        for (AcroFields.FieldPosition pos : sv.getPosList()) {
                            int p1 = (int) (p.x + (pos.position.getLeft() * scale));
                            int p2 = (int) (p.y
                                    + Math.floor((pdfDocument.getPage(pageNumber).getCropBox().getHeight()
                                            - pos.position.getTop()) * scale));
                            int p3 = (int) (pos.position.getWidth() * scale);
                            int p4 = (int) (pos.position.getHeight() * scale);

                            final JPanel jp1 = sv.getPanel();
                            jp1.setLocation(p1, p2);
                            jp1.setSize(p3, p4);

                            if (sv.equals(selectedSignature)) {
                                jp1.setBackground(new Color(0, 0, 0, 45));
                                jp1.setBorder(new LineBorder(Color.BLACK, 1));
                            } else {
                                jp1.setBackground(new Color(0, 0, 0, 0));
                                jp1.setBorder(null);
                            }

                            jp1.setVisible(true);
                            jp1.addMouseListener(new MouseAdapter() {
                                @Override
                                public void mouseEntered(java.awt.event.MouseEvent evt) {
                                    if (mainWindow.getWorkspacePanel()
                                            .getStatus() != WorkspacePanel.Status.SIGNING) {
                                        jp1.setCursor(new Cursor(Cursor.HAND_CURSOR));
                                        jp1.setBackground(new Color(0, 0, 0, 45));
                                        jp1.setBorder(new LineBorder(Color.BLACK, 1));
                                        repaint();
                                    } else {
                                        jp1.setCursor(null);
                                    }
                                }

                                @Override
                                public void mouseExited(java.awt.event.MouseEvent evt) {
                                    if (mainWindow.getWorkspacePanel()
                                            .getStatus() != WorkspacePanel.Status.SIGNING) {
                                        if (selectedSignature == null) {
                                            jp1.setBackground(new Color(0, 0, 0, 0));
                                            jp1.setBorder(null);
                                            repaint();
                                        } else if (!selectedSignature.equals(sv)) {
                                            jp1.setBackground(new Color(0, 0, 0, 0));
                                            jp1.setBorder(null);
                                            repaint();
                                        }
                                    }
                                }
                            });
                            panelList.add(jp1);
                            add(jp1);
                            repaint();
                        }
                    }
                } catch (Exception e) {
                }
            }
        }
    }
}