List of usage examples for java.awt Dimension getSize
@Transient
public Dimension getSize()
From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java
protected void showNotificationPopup(String popupText, NotificationType type) { JPanel panel = new JPanel(new MigLayout("flowy")); panel.setBorder(BorderFactory.createLineBorder(Color.gray)); switch (type) { case WARNING: case WARNING_HTML: panel.setBackground(Color.yellow); break;/*from w ww. j a v a 2s . c o m*/ case ERROR: case ERROR_HTML: panel.setBackground(Color.orange); break; default: panel.setBackground(Color.cyan); } JLabel label = new JLabel(popupText); panel.add(label); Dimension labelSize = DesktopComponentsHelper.measureHtmlText(popupText); int x = frame.getX() + frame.getWidth() - (50 + labelSize.getSize().width); int y = frame.getY() + frame.getHeight() - (50 + labelSize.getSize().height); PopupFactory factory = PopupFactory.getSharedInstance(); final Popup popup = factory.getPopup(frame, panel, x, y); popup.show(); panel.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { popup.hide(); } }); PointerInfo pointerInfo = MouseInfo.getPointerInfo(); if (pointerInfo != null) { final Point location = pointerInfo.getLocation(); final Timer timer = new Timer(3000, null); timer.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { PointerInfo currentPointer = MouseInfo.getPointerInfo(); if (currentPointer == null) { timer.stop(); } else if (!currentPointer.getLocation().equals(location)) { popup.hide(); timer.stop(); } } }); timer.start(); } }
From source file:org.apache.fop.render.pcl.PCLPainter.java
/** {@inheritDoc} */ public void drawBorderRect(final Rectangle rect, final BorderProps before, final BorderProps after, final BorderProps start, final BorderProps end) throws IFException { if (isSpeedOptimized()) { super.drawBorderRect(rect, before, after, start, end); return;//ww w . jav a 2s . c o m } if (before != null || after != null || start != null || end != null) { final Rectangle boundingBox = rect; final Dimension dim = boundingBox.getSize(); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.translate(-rect.x, -rect.y); Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state); try { painter.drawBorderRect(rect, before, after, start, end); } catch (IFException e) { //This should never happen with the Java2DPainter throw new RuntimeException("Unexpected error while painting borders", e); } } public Dimension getImageSize() { return dim.getSize(); } }; paintMarksAsBitmap(painter, boundingBox); } }
From source file:org.apache.fop.render.pcl.PCLPainter.java
/** {@inheritDoc} */ public void drawLine(final Point start, final Point end, final int width, final Color color, final RuleStyle style) throws IFException { if (isSpeedOptimized()) { super.drawLine(start, end, width, color, style); return;/* w w w .j a v a 2 s . c o m*/ } final Rectangle boundingBox = getLineBoundingBox(start, end, width); final Dimension dim = boundingBox.getSize(); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { g2d.translate(-boundingBox.x, -boundingBox.y); Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state); try { painter.drawLine(start, end, width, color, style); } catch (IFException e) { //This should never happen with the Java2DPainter throw new RuntimeException("Unexpected error while painting a line", e); } } public Dimension getImageSize() { return dim.getSize(); } }; paintMarksAsBitmap(painter, boundingBox); }
From source file:org.apache.fop.render.pcl.PCLPainter.java
private void drawTextAsBitmap(final int x, final int y, final int letterSpacing, final int wordSpacing, final int[] dx, final String text, FontTriplet triplet) throws IFException { //Use Java2D to paint different fonts via bitmap final Font font = parent.getFontInfo().getFontInstance(triplet, state.getFontSize()); //for cursive fonts, so the text isn't clipped final FontMetricsMapper mapper = (FontMetricsMapper) parent.getFontInfo().getMetricsFor(font.getFontName()); final int maxAscent = mapper.getMaxAscent(font.getFontSize()) / 1000; final int ascent = mapper.getAscender(font.getFontSize()) / 1000; final int descent = mapper.getDescender(font.getFontSize()) / 1000; int safetyMargin = (int) (SAFETY_MARGIN_FACTOR * font.getFontSize()); final int baselineOffset = maxAscent + safetyMargin; final Rectangle boundingBox = getTextBoundingBox(x, y, letterSpacing, wordSpacing, dx, text, font, mapper); final Dimension dim = boundingBox.getSize(); Graphics2DImagePainter painter = new Graphics2DImagePainter() { public void paint(Graphics2D g2d, Rectangle2D area) { if (DEBUG) { g2d.setBackground(Color.LIGHT_GRAY); g2d.clearRect(0, 0, (int) area.getWidth(), (int) area.getHeight()); }//from w w w .j ava 2 s . co m g2d.translate(-x, -y + baselineOffset); if (DEBUG) { Rectangle rect = new Rectangle(x, y - maxAscent, 3000, maxAscent); g2d.draw(rect); rect = new Rectangle(x, y - ascent, 2000, ascent); g2d.draw(rect); rect = new Rectangle(x, y, 1000, -descent); g2d.draw(rect); } Java2DPainter painter = new Java2DPainter(g2d, getContext(), parent.getFontInfo(), state); try { painter.drawText(x, y, letterSpacing, wordSpacing, dx, text); } catch (IFException e) { //This should never happen with the Java2DPainter throw new RuntimeException("Unexpected error while painting text", e); } } public Dimension getImageSize() { return dim.getSize(); } }; paintMarksAsBitmap(painter, boundingBox); }
From source file:org.swiftexplorer.SwiftExplorer.java
private static void openMainWindow(final MainPanel cp) throws IOException { JFrame frame = new JFrame(Configuration.INSTANCE.getAppName()); Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize(); float ratio = (float) 0.8; Dimension windowSize = new Dimension((int) (screenSize.getWidth() * ratio), (int) (screenSize.getHeight() * ratio)); frame.setSize(windowSize.getSize()); frame.setLocationByPlatform(true);//w ww.j a v a2 s . c om frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png"))); frame.getContentPane().add(cp); frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { if (cp.onClose()) { System.exit(0); } } }); cp.setOwner(frame); frame.setJMenuBar(cp.createMenuBar()); // center the frame int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2); int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2); frame.setLocation(x, y); frame.setVisible(true); }
From source file:ryerson.daspub.mobile.AssignmentPage.java
/** * HTML thumbnail index of video submissions matching the evaluation value * E.//from www. ja va2 s . c o m * @param A Assignment * @param Evaluation Evaluation value * @param Id Block identifier * @param Title Block title * @param Output Assignment output folder * @return Video gallery index */ public static String buildVideoSubmissionIndex(Assignment A, SUBMISSION_EVALUATION Evaluation, String Id, String Title, File Output) { StringBuilder sb = new StringBuilder(); List<Submission> ls = A.getSubmissions(SUBMISSION_TYPE.VIDEO, Evaluation); if (ls.size() > 0) { // create output subdirectory if it does not exist File output = new File(Output, VIDEO_DIR); if (!output.exists()) { output.mkdirs(); } // submission index sb.append("\n<div data-role=\"collapsible\" data-collapsed=\"true\">"); sb.append("\n\t<h3>"); sb.append(Title); sb.append("</h3>"); sb.append("\n\t<ul id=\""); sb.append(Id); sb.append("\" class=\"videogallery\">"); Iterator<Submission> its = ls.iterator(); // for each video, create a player and a poster image, copy the // source file to the output folder Dimension dim = null; File poster = null; while (its.hasNext()) { Submission s = its.next(); if (s.getSourceFile().exists()) { try { // get video metadata dim = VideoUtils.getSize(s.getSourceFile()); // write poster for video poster = VideoUtils.writePosterImage(s.getSourceFile(), output); // copy the source file to the output folder copyVideo(s.getSourceFile(), output); // write html player sb.append("\n<li>"); sb.append("\n\t<video id=\""); sb.append("randomplayerid"); sb.append("\" "); sb.append("\n\t\tclass=\"video-js vjs-default-skin\" "); sb.append("\n\t\tcontrols preload=\"none\" "); sb.append("\n\t\twidth=\""); sb.append(String.valueOf(dim.getSize().getWidth())); // do you really want to do this or should all video be the same size?? sb.append("\" "); sb.append("\n\t\theight=\""); sb.append(String.valueOf(dim.getSize().getHeight())); sb.append("\" "); sb.append("\n\t\tposter=\""); sb.append(A.getURLSafeName()); sb.append("/"); sb.append(VIDEO_DIR); sb.append("/"); sb.append(poster.getName()); sb.append("\""); sb.append("\n\t\tdata-setup=\"{}\">"); sb.append("\n\t\t<source src=\""); sb.append(A.getURLSafeName()); sb.append("/"); sb.append(VIDEO_DIR); sb.append("/"); sb.append(s.getSourceFileName()); sb.append("\" type=\""); sb.append(VideoUtils.getMimeType(s.getSourceFile())); sb.append("\" />"); sb.append("\n\t</video>"); sb.append("\n</li>"); } catch (Exception ex) { String stack = ExceptionUtils.getStackTrace(ex); logger.log(Level.SEVERE, "Could not process video file {0}\n\n{1}", new Object[] { s.getSourceFile().getAbsolutePath(), stack }); } } } sb.append("\n\t</ul>"); sb.append("\n</div>"); } // return result return sb.toString(); }