List of usage examples for java.awt Dimension getHeight
public double getHeight()
From source file:org.zaproxy.zap.extension.callgraph.CallGraphFrame.java
private void setupFrame() { // define a visual layout on the graph mxHierarchicalLayout layout = new com.mxgraph.layout.hierarchical.mxHierarchicalLayout(graph, SwingConstants.WEST); final mxGraphComponent graphComponent = new mxGraphComponent(graph); graphComponent.setConnectable(false); graphComponent.setToolTips(true);//from w w w .j a v a 2s.c o m graphComponent.setAutoExtend(true); graphComponent.setAutoScroll(true); // add the graph component to the frame in the centre. getContentPane().add(graphComponent, BorderLayout.CENTER); // and set up a panel below that JPanel toolBar = new JPanel(); toolBar.setLayout(new BorderLayout()); // with an outline of the graph, and have it settle in the west.. final mxGraphOutline graphOutline = new mxGraphOutline(graphComponent); graphOutline.setPreferredSize(new Dimension(100, 100)); toolBar.add(graphOutline, BorderLayout.WEST); // and some buttons in the panel JPanel buttonBar = new JPanel(); buttonBar.setLayout(new FlowLayout()); // zoom to fit button JButton btZoomToFit = new JButton(Constant.messages.getString("callgraph.button.zoomfit")); btZoomToFit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { double newScale = 1; Dimension graphSize = graphComponent.getGraphControl().getSize(); Dimension viewPortSize = graphComponent.getViewport().getSize(); int gw = (int) graphSize.getWidth(); int gh = (int) graphSize.getHeight(); if (gw > 0 && gh > 0) { int w = (int) viewPortSize.getWidth(); int h = (int) viewPortSize.getHeight(); newScale = Math.min((double) w / gw, (double) h / gh); } graphComponent.zoomTo(newScale, true); } }); buttonBar.add(btZoomToFit); // center graph JButton btCenter = new JButton(Constant.messages.getString("callgraph.button.centregraph")); btCenter.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent arg0) { Dimension graphSize = graphComponent.getGraphControl().getSize(); Dimension viewPortSize = graphComponent.getViewport().getSize(); int x = graphSize.width / 2 - viewPortSize.width / 2; int y = graphSize.height / 2 - viewPortSize.height / 2; int w = viewPortSize.width; int h = viewPortSize.height; graphComponent.getGraphControl().scrollRectToVisible(new Rectangle(x, y, w, h)); } }); buttonBar.add(btCenter); // add a rubberband zoom on the mouse selection event new mxRubberband(graphComponent) { public void mouseReleased(MouseEvent e) { // get bounds before they are reset Rectangle rect = bounds; // invoke usual behaviour super.mouseReleased(e); if (rect != null) { double newScale = 1; Dimension graphSize = new Dimension(rect.width, rect.height); Dimension viewPortSize = graphComponent.getViewport().getSize(); int gw = (int) graphSize.getWidth(); int gh = (int) graphSize.getHeight(); if (gw > 0 && gh > 0) { int w = (int) viewPortSize.getWidth(); int h = (int) viewPortSize.getHeight(); newScale = Math.min((double) w / gw, (double) h / gh); } // zoom to fit the selected area on screen graphComponent.zoom(newScale); // make the selected area visible graphComponent.getGraphControl() .scrollRectToVisible(new Rectangle((int) (rect.x * newScale), (int) (rect.y * newScale), (int) (rect.width * newScale), (int) (rect.height * newScale))); } } }; // put the components on frame toolBar.add(buttonBar, BorderLayout.CENTER); getContentPane().add(toolBar, BorderLayout.SOUTH); // TODO: Do we need this here? // frame.setVisible(true); // lay it out graph.getModel().beginUpdate(); try { layout.execute(graph.getDefaultParent()); } finally { graph.getModel().endUpdate(); } // setDefaultCloseOperation(JFrame.); // setSize(400, 400); pack(); setVisible(true); }
From source file:org.opennms.features.topology.app.internal.jung.FRLayoutTest.java
private TopoFRLayout<VertexRef, EdgeRef> runFRLayout(Graph g, Layout graphLayout, List<Vertex> vertices) { TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<>(createJungGraph(g)); Dimension size = selectLayoutSize(m_graphContainer); //layout.setRepulsionMultiplier(3/8.0); //layout.setAttractionMultiplier(3/8.0); layout.setInitializer(initializer(graphLayout, size)); layout.setSize(size);/*from www . j ava 2 s . c om*/ while (!layout.done()) { layout.step(); } LOG.info("/******** FRLayout Run **********/"); for (Vertex v : vertices) { graphLayout.setLocation(v, new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0)); LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v)); } LOG.info("/******** End FRLayout Run **********/"); return layout; }
From source file:org.photovault.swingui.JAIPhotoViewer.java
/** Finds the best instance of the current photo and shows it. The instance is selected so that it needs as little postprocessing as possible. Hovewer, the operations in {@link dynOps} must not be preapplied in the instance since these may be changing during viewing of the image. //from ww w .j ava2s. c om */ private void showBestInstance() throws PhotovaultException { EnumSet<ImageOperations> allowedOps = EnumSet.allOf(ImageOperations.class); allowedOps.removeAll(dynOps); int w = imageView.getWidth(); int h = imageView.getHeight(); Dimension croppedSize = photo.getCroppedSize(); double ar = croppedSize.getWidth() / croppedSize.getHeight(); if (w > ar * h) { w = (int) (h * ar); } else { h = (int) (w / ar); } ImageDescriptorBase image = photo.getPreferredImage(EnumSet.noneOf(ImageOperations.class), allowedOps, w, h, Integer.MAX_VALUE, Integer.MAX_VALUE); if (image != null && image.getLocator().equals("image#0")) { File imageFile = image.getFile().findAvailableCopy(); if (imageFile != null && imageFile.canRead()) { // TODO: is this really needed? String fname = imageFile.getName(); int lastDotPos = fname.lastIndexOf("."); if (lastDotPos <= 0 || lastDotPos >= fname.length() - 1) { // TODO: error handling needs thinking!!!! // throw new IOException( "Cannot determine file type extension of " + imageFile.getAbsolutePath() ); fireViewChangeEvent(); return; } PhotovaultImageFactory imageFactory = new PhotovaultImageFactory(); PhotovaultImage img = null; try { /* Do not read the image yet since setting raw conversion parameters later may force a re-read. */ img = imageFactory.create(imageFile, false, false); } catch (PhotovaultException ex) { final JAIPhotoViewer component = this; final String msg = ex.getMessage(); SwingUtilities.invokeLater(new Runnable() { public void run() { JOptionPane.showMessageDialog(component, msg, "Error loading file", JOptionPane.ERROR_MESSAGE); } }); } if (img != null) { appliedOps = EnumSet.noneOf(ImageOperations.class); if (rawImage != null) { rawImage.removeChangeListener(this); } if (img instanceof RawImage) { rawImage = (RawImage) img; rawImage.setRawSettings( localRawSettings != null ? localRawSettings : photo.getRawSettings()); rawImage.addChangeListener(this); // Check the correct resolution for this image if (isFit) { fit(); } else { setScale(getScale()); } } else { rawImage = null; rawConvScaling = 1.0f; } } if (image instanceof CopyImageDescriptor) { // This is a copy, so it may be cropped already appliedOps = ((CopyImageDescriptor) image).getAppliedOperations(); if (!appliedOps.contains(ImageOperations.COLOR_MAP)) { img.setColorAdjustment( localChanMap != null ? localChanMap : photo.getColorChannelMapping()); } if (!appliedOps.contains(ImageOperations.CROP)) { instanceRotation = ((CopyImageDescriptor) image).getRotation(); double rot = photo.getPrefRotation() - instanceRotation; imageView.setRotation(rot); imageView.setCrop(photo.getCropBounds()); } } else { // This is original so we must apply corrections img.setColorAdjustment(localChanMap != null ? localChanMap : photo.getColorChannelMapping()); imageView.setRotation(photo.getPrefRotation()); imageView.setCrop(photo.getCropBounds()); } setImage(img); fireViewChangeEvent(); return; } } // if we get this far no instance of the original image has been found setImage(null); throw new PhotovaultException("No suitable instance of photo " + photo.getUuid() + " found"); }
From source file:org.echocat.velma.dialogs.AboutDialog.java
@Nonnull @Override// w ww. j a v a 2 s .c o m protected Container createContainer() { return new JPanel() { @Override protected void paintComponent(Graphics g) { super.paintComponent(g); final Graphics2D g2d = (Graphics2D) g; final Dimension size = getSize(); g2d.setRenderingHint(KEY_INTERPOLATION, VALUE_INTERPOLATION_BILINEAR); g2d.setRenderingHint(KEY_RENDERING, VALUE_RENDER_QUALITY); g2d.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON); final double sourceWidth = _backgroundImage.getWidth(); final double sourceHeight = _backgroundImage.getHeight(); final double targetWidth = size.getWidth(); final double targetHeight = size.getHeight(); final double relWidth = sourceWidth / targetWidth; final double relHeight = sourceHeight / targetHeight; final double width; final double height; final double x; final double y; if (relWidth > relHeight) { width = sourceWidth / relHeight; height = sourceHeight / relHeight; x = ((targetWidth - width) / 2); y = 0; } else { width = sourceWidth / relWidth; height = sourceHeight / relWidth; x = 0; y = ((targetHeight - height) / 2); } g2d.drawImage(_backgroundImage, (int) x, (int) y, (int) width, (int) height, this); } }; }
From source file:org.opennms.features.topology.app.internal.jung.D3LayoutTest.java
protected Transformer<VertexRef, Point2D> initializer(final Layout graphLayout, final Dimension dim) { return new Transformer<VertexRef, Point2D>() { @Override/*from w w w . j a v a 2 s.com*/ public Point2D transform(VertexRef v) { if (v == null) { LOG.info("Algorithm tried to layout a null vertex"); return new java.awt.Point(0, 0); } org.opennms.features.topology.api.Point location = graphLayout.getLocation(v); return new Point2D.Double(location.getX() + dim.getWidth() / 2.0, location.getY() + dim.getHeight() / 2.0); } }; }
From source file:org.zaproxy.zap.extension.callgraph.CallGraphFrame.java
/** * sets up the graph by retrieving the nodes and edges from the history table in the database * * @param urlPattern//from w w w. j a va2s .co m * @throws SQLException */ private void setupGraph(Pattern urlPattern) throws SQLException { Connection conn = null; Statement st = null; ResultSet rs = null; Map<String, String> schemaAuthorityToColor = new HashMap<String, String>(); // use some web safe colours. Currently, there are 24 colours. String[] colors = { "#FFFF00", "#FFCC00", "#FF9900", "#FF6600", "#FF3300", "#CCFF00", "#CCCC00", "#CC9900", "#CC6600", "#99FF00", "#999900", "#996600", "#CCFFCC", "#CCCCCC", "#99CCCC", "#9999CC", "#9966CC", "#66FFCC", "#6699CC", "#6666CC", "#33FFCC", "#33CCCC", "#3399CC", "#00FFCC" }; int colorsUsed = 0; try { // Create a pattern for the specified // get a new connection to the database to query it, since the existing database classes // do not cater for // ad-hoc queries on the table /* * TODO Add-ons should NOT make their own connections to the db any more - the db layer is plugable * so could be implemented in a completely different way * TODO: how? There is currently no API to do this. */ // Note: the db is a singleton instance, so do *not* close it!! Database db = Model.getSingleton().getDb(); if (!(db instanceof ParosDatabase)) { throw new InvalidParameterException(db.getClass().getCanonicalName()); } conn = ((ParosDatabaseServer) db.getDatabaseServer()).getNewConnection(); // we begin adding stuff to the graph, so begin a "transaction" on it. // we will close this after we add all the vertexes and edges to the graph graph.getModel().beginUpdate(); // prepare to add the vertices to the graph // this must include all URLs references as vertices, even if those URLs did not feature // in the history table in their own right // include entries of type 1 (proxied), 2 (spidered), 10 (Ajax spidered) from the // history st = conn.createStatement(); rs = st.executeQuery( "select distinct URI from HISTORY where histtype in (1,2,10) union distinct select distinct RIGHT(REGEXP_SUBSTRING (REQHEADER, 'Referer:.+') , LENGTH(REGEXP_SUBSTRING (REQHEADER, 'Referer:.+'))-LENGTH('Referer: ')) from HISTORY where REQHEADER like '%Referer%' and histtype in (1,2,10) order by 1"); for (; rs.next();) { String url = rs.getString(1); // remove urls that do not match the pattern specified (all sites / one site) Matcher urlmatcher = urlPattern.matcher(url); if (urlmatcher.find()) { // addVertex(url , url); try { URI uri = new URI(url, false); String schemaAuthority = uri.getScheme() + "://" + uri.getAuthority(); String path = uri.getPathQuery(); if (path == null) path = "/"; String color = schemaAuthorityToColor.get(schemaAuthority); if (color == null) { // not found already.. so assign this scheme and authority a color. if (colorsUsed >= colors.length) { throw new Exception("Too many scheme/authority combinations. Ne need more colours"); } color = colors[colorsUsed++]; schemaAuthorityToColor.put(schemaAuthority, color); } addVertex(path, url, "fillColor=" + color); } catch (Exception e) { log.error("Error graphing node for URL " + url, e); } } else { if (log.isDebugEnabled()) log.debug("URL " + url + " does not match the specified pattern " + urlPattern + ", so not adding it as a vertex"); } } // close the resultset and statement rs.close(); st.close(); // set up the edges in the graph st = conn.createStatement(); rs = st.executeQuery( "select distinct RIGHT(REGEXP_SUBSTRING (REQHEADER, 'Referer:.+') , LENGTH(REGEXP_SUBSTRING (REQHEADER, 'Referer:.+'))-LENGTH('Referer: ')), URI from HISTORY where REQHEADER like '%Referer%' and histtype in (1,2,10) order by 2"); mxGraphModel graphmodel = (mxGraphModel) graph.getModel(); for (; rs.next();) { String predecessor = rs.getString(1); String url = rs.getString(2); // now trim back all urls from the base url // Matcher predecessorurlmatcher = urlpattern.matcher(predecessor); // if (predecessorurlmatcher.find()) { // predecessor = predecessorurlmatcher.group(1); // } // Matcher urlmatcher = urlpattern.matcher(url); // if (urlmatcher.find()) { // url = urlmatcher.group(1); // } // remove urls that do not match the pattern specified (all sites / one site) Matcher urlmatcher1 = urlPattern.matcher(predecessor); if (!urlmatcher1.find()) { if (log.isDebugEnabled()) log.debug("Predecessor URL " + predecessor + " does not match the specified pattern " + urlPattern + ", so not adding it as a vertex"); continue; // to the next iteration } Matcher urlmatcher2 = urlPattern.matcher(url); if (!urlmatcher2.find()) { if (log.isDebugEnabled()) log.debug("URL " + url + " does not match the specified pattern " + urlPattern + ", so not adding it as a vertex"); continue; // to the next iteration } // check that we have added the url as a vertex in its own right.. definitely should // have happened.. mxCell predecessorVertex = (mxCell) graphmodel.getCell(predecessor); mxCell postdecessorVertex = (mxCell) graphmodel.getCell(url); if (predecessorVertex == null || postdecessorVertex == null) { log.warn("Could not find graph node for " + predecessor + " or for " + url + ". Ignoring it."); continue; } // add the edge (ie, add the dependency between 2 URLs) graph.insertEdge(parent, predecessorVertex.getId() + "-->" + postdecessorVertex.getId(), null, predecessorVertex, postdecessorVertex); } // once all the vertices and edges are drawn, look for root nodes (nodes with no // incoming edges) // we will display the full URl for these, rather than just the path, to aid viewing the // graph Object[] vertices = graph.getChildVertices(graph.getDefaultParent()); for (Object vertex : vertices) { Object[] incomingEdgesForVertex = graph.getIncomingEdges(vertex); if (incomingEdgesForVertex == null || (incomingEdgesForVertex != null && incomingEdgesForVertex.length == 0)) { // it's a root node. Set it's value (displayed label) to the same as it's id // (the full URL) mxCell vertextCasted = (mxCell) vertex; vertextCasted.setValue(vertextCasted.getId()); // now sort out the text metrics for the vertex, since the size of the displayed // text has been changed Dimension textsize = this.getTextDimension((String) vertextCasted.getValue(), this.fontmetrics); mxGeometry cellGeometry = vertextCasted.getGeometry(); cellGeometry.setHeight(textsize.getHeight()); cellGeometry.setWidth(textsize.getWidth()); vertextCasted.setGeometry(cellGeometry); } } } catch (SQLException e) { log.error("Error trying to setup the graph", e); throw e; } finally { if (rs != null && !rs.isClosed()) rs.close(); if (st != null && !st.isClosed()) st.close(); if (conn != null && !conn.isClosed()) conn.close(); // mark the "transaction" on the graph as complete graph.getModel().endUpdate(); } }
From source file:tpp.TPPFrame.java
/** * This method initializes this//w w w. ja va 2 s . c om * */ private void initialize() { this.setJMenuBar(getBar()); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); this.setLocation((int) (screenSize.getWidth() - DEFAULT_DIMENSION.getWidth()) / 2, (int) (screenSize.getHeight() - DEFAULT_DIMENSION.getHeight()) / 2); this.setSize(DEFAULT_DIMENSION); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); }
From source file:org.richfaces.component.InputNumberSliderComponentTest.java
public void testArrowsImages() throws Exception { InternetResource image;//from ww w. j a v a2s .c o m Dimension imageDim; image = InternetResourceBuilder.getInstance().createResource(null, SliderTrackGradientVertical.class.getName()); imageDim = ((Java2Dresource) image).getDimensions(facesContext, null); assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 10); image = InternetResourceBuilder.getInstance().createResource(null, SliderArrowImageLeft.class.getName()); imageDim = ((Java2Dresource) image).getDimensions(facesContext, null); assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8); image = InternetResourceBuilder.getInstance().createResource(null, SliderArrowImageRight.class.getName()); imageDim = ((Java2Dresource) image).getDimensions(facesContext, null); assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8); image = InternetResourceBuilder.getInstance().createResource(null, SliderArrowImageTop.class.getName()); imageDim = ((Java2Dresource) image).getDimensions(facesContext, null); assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8); image = InternetResourceBuilder.getInstance().createResource(null, SliderArrowSelectedImageLeft.class.getName()); imageDim = ((Java2Dresource) image).getDimensions(facesContext, null); assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8); image = InternetResourceBuilder.getInstance().createResource(null, SliderArrowSelectedImageRight.class.getName()); imageDim = ((Java2Dresource) image).getDimensions(facesContext, null); assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8); image = InternetResourceBuilder.getInstance().createResource(null, SliderArrowSelectedImageTop.class.getName()); imageDim = ((Java2Dresource) image).getDimensions(facesContext, null); assertTrue(imageDim.getWidth() == 7 && imageDim.getHeight() == 8); }
From source file:edu.wustl.xipHost.application.Application.java
public Rectangle getApplicationPreferredSize() { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Rectangle rect = new Rectangle(); logger.debug("Screen width: " + new Double(screenSize.getWidth()).intValue()); logger.debug("Screen height: " + new Double(screenSize.getHeight()).intValue()); rect.setWidth(new Double(screenSize.getWidth()).intValue()); rect.setHeight(new Double(screenSize.getHeight()).intValue()); return rect;//w w w. j a v a2 s. co m }
From source file:eu.europa.esig.dss.pdf.pdfbox.PdfBoxSignatureService.java
private void fillImageParameters(final PDDocument doc, final SignatureImageParameters imgParams, SignatureOptions options) throws IOException { Dimension optimalSize = ImageFactory.getOptimalSize(imgParams); PDVisibleSignDesigner visibleSig = new PDVisibleSignDesigner(doc, ImageFactory.create(imgParams), imgParams.getPage());// w w w .jav a 2 s .c om visibleSig.xAxis(imgParams.getxAxis()).yAxis(imgParams.getyAxis()).width((float) optimalSize.getWidth()) .height((float) optimalSize.getHeight()); PDVisibleSigProperties signatureProperties = new PDVisibleSigProperties(); signatureProperties.visualSignEnabled(true).setPdVisibleSignature(visibleSig).buildSignature(); options.setVisualSignature(signatureProperties); options.setPage(imgParams.getPage()); }