public void setBackgroundImage(Image backgroundImage) { Rectangle rect = new Rectangle(0, 0, backgroundImage.getWidth(null), backgroundImage.getHeight(null)); try { new TexturePaint(GraphicUtils.convert(backgroundImage), rect); } catch (Exception e) { Log.error(e); } }
/** * Puts the focus on the first component in the tree of <code>c</code> that * can accept the focus. * * @see #getFocusableComponentOrChild * @param c * Component to focus on. * @return Component that was focused on. */ public static Component focusComponentOrChild(Component c) { return focusComponentOrChild(c, false); }
/** * Creates an {@link ImageIcon} with a Shadow * * @param buf * , the {@link Image} where a Shadow will be applied * @return {@link ImageIcon} with shadow */ public static ImageIcon createShadowPicture(Image buf) { buf = removeTransparency(buf); BufferedImage splash; JLabel label = new JLabel(); int width = buf.getWidth(null); int height = buf.getHeight(null); int extra = 4; splash = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = (Graphics2D) splash.getGraphics(); BufferedImage shadow = new BufferedImage(width + extra, height + extra, BufferedImage.TYPE_INT_ARGB); Graphics g = shadow.getGraphics(); g.setColor(new Color(0.0f, 0.0f, 0.0f, 0.3f)); g.fillRoundRect(0, 0, width, height, 12, 12); g2.drawImage(shadow, getBlurOp(7), 0, 0); g2.drawImage(buf, 0, 0, label); return new ImageIcon(splash); }
/** * Displays the Spark error log. */ private void showErrorLog() { final File logDir = new File(Spark.getLogDirectory(), "errors.log"); // Read file and show final String errorLogs = URLFileSystem.getContents(logDir); final JFrame frame = new JFrame(Res.getString("title.client.logs")); frame.setLayout(new BorderLayout()); frame.setIconImage(SparkManager.getApplicationImage().getImage()); final JTextPane pane = new JTextPane(); pane.setBackground(Color.white); pane.setFont(new Font("Dialog", Font.PLAIN, 12)); pane.setEditable(false); pane.setText(errorLogs); frame.add(new JScrollPane(pane), BorderLayout.CENTER); final JButton copyButton = new JButton(Res.getString("button.copy.to.clipboard")); frame.add(copyButton, BorderLayout.SOUTH); copyButton.addActionListener( e -> { SparkManager.setClipboard(errorLogs); copyButton.setEnabled(false); } ); frame.pack(); frame.setSize(600, 400); GraphicUtils.centerWindowOnScreen(frame); frame.setVisible(true); }
imageLabel.setIcon(GraphicUtils.getIcon(downloadedFile)); imageLabel.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { URL imageURL = downloadedFile.toURI().toURL(); ImageIcon image = new ImageIcon(imageURL); image = GraphicUtils.scaleImageIcon(image, 64, 64); imageLabel.setIcon(image);
/** * Invoke the Dialog. */ public void invoke() { dialog = new JDialog(SparkManager.getMainWindow(), transport.getTitle(), false); dialog.add(this); dialog.pack(); dialog.setSize(400, 200); dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); GraphicUtils.centerWindowOnComponent(dialog, SparkManager.getMainWindow()); dialog.setVisible(true); usernameField.requestFocus(); usernameField.addKeyListener(this); passwordField.addKeyListener(this); registerButton.addActionListener(this); cancelButton.addActionListener( actionEvent -> dialog.dispose() ); }
activeButton.addActionListener(showActiveAction); GraphicUtils.makeSameSize(allButton, activeButton); GraphicUtils.centerWindowOnComponent(frame, SparkManager.getMainWindow()); frame.setVisible(true);
public String getToolTipText(MouseEvent e) { int r = rowAtPoint(e.getPoint()); int c = columnAtPoint(e.getPoint()); Object value; try { value = getValueAt(r, c); } catch (Exception e1) { // If we encounter a row that should not actually exist and therefore // has a null value. Just return an empty string for the tooltip. return ""; } String tooltipValue = null; if (value instanceof JLabel) { tooltipValue = ((JLabel)value).getToolTipText(); } if (value instanceof JLabel && tooltipValue == null) { tooltipValue = ((JLabel)value).getText(); } else if (value != null && tooltipValue == null) { tooltipValue = value.toString(); } else if (tooltipValue == null) { tooltipValue = ""; } return GraphicUtils.createToolTip(tooltipValue); }
/** * Returns the first component in the tree of <code>c</code> that can accept * the focus. * * @param c * the root of the component hierarchy to search * @see #focusComponentOrChild * @deprecated replaced by * {@link #getFocusableComponentOrChild(Component,boolean)} * @return Component that was focused on. */ public static Component getFocusableComponentOrChild(Component c) { return getFocusableComponentOrChild(c, false); }
protected static boolean isValidWindowPosition( Point location, Dimension dimension ) { Rectangle windowTitleBounds = new Rectangle( location.x, location.y, dimension.width, 20 ); double windowTitleArea = windowTitleBounds.getWidth() * windowTitleBounds.getHeight(); Rectangle[] screenBounds = GraphicUtils.getScreenBounds(); for ( Rectangle screenBound : screenBounds ) { Rectangle screen = screenBound.getBounds(); Rectangle intersection = screen.intersection( windowTitleBounds ); double visibleArea = intersection.getWidth() * intersection.getHeight(); // if 25% of it is visible in the device, then it is good if ( ( visibleArea / windowTitleArea ) > 0.25 ) { return true; } } return false; }
/** * Returns a point where the given popup menu should be shown. The point is * calculated by adjusting the X and Y coordinates from the given mouse * event so that the popup menu will not be clipped by the screen * boundaries. * * @param popup * the popup menu * @param event * the mouse event * @return the point where the popup menu should be shown */ public static Point getPopupMenuShowPoint(JPopupMenu popup, MouseEvent event) { Component source = (Component) event.getSource(); Point topLeftSource = source.getLocationOnScreen(); Point ptRet = getPopupMenuShowPoint(popup, topLeftSource.x + event.getX(), topLeftSource.y + event.getY()); ptRet.translate(-topLeftSource.x, -topLeftSource.y); return ptRet; }
out.close(); imageLabel.setIcon(GraphicUtils.getIcon(file));
centerWindowOnScreen(window); return;
URL imageURL = new File(transfer.getFilePath()).toURI().toURL(); ImageIcon image = new ImageIcon(imageURL); image = GraphicUtils.scaleImageIcon(image, 64, 64); imageLabel.setIcon(image); Icon icon = GraphicUtils.getIcon(file); imageLabel.setIcon(icon);
GraphicUtils.centerWindowOnComponent(window, SparkManager.getMainWindow());
public String getToolTipText(MouseEvent e) { int r = rowAtPoint(e.getPoint()); int c = columnAtPoint(e.getPoint()); Object value; try { value = getValueAt(r, c); } catch (Exception e1) { // If we encounter a row that should not actually exist and therefore // has a null value. Just return an empty string for the tooltip. return ""; } String tooltipValue = null; if (value instanceof JLabel) { tooltipValue = ((JLabel)value).getToolTipText(); } if (value instanceof JLabel && tooltipValue == null) { tooltipValue = ((JLabel)value).getText(); } else if (value != null && tooltipValue == null) { tooltipValue = value.toString(); } else if (tooltipValue == null) { tooltipValue = ""; } return GraphicUtils.createToolTip(tooltipValue); }
/** * Puts the focus on the first component in the tree of <code>c</code> that * can accept the focus. * * @param c * the root of the component hierarchy to search * @param deepest * if <code>deepest</code> is true the method will focus the * first and deepest component that can accept the focus. For * example, if both a child and its parent are focusable and * <code>deepest</code> is true, the child is focused. * @see #getFocusableComponentOrChild * @return Component that was focused on. */ public static Component focusComponentOrChild(Component c, boolean deepest) { final Component focusable = getFocusableComponentOrChild(c, deepest); if (focusable != null) { focusable.requestFocus(); } return focusable; }
+ sizeMenu.height); Rectangle[] screensBounds = getScreenBounds(); int n = screensBounds.length; for (int i = 0; i < n; i++) {
dialog.pack(); dialog.setSize(600, 400); GraphicUtils.centerWindowOnScreen(dialog); dialog.setVisible(true);
GraphicUtils.centerWindowOnComponent(frame, SparkManager.getMainWindow()); frame.setVisible(true); pane.setCaretPosition(0);