List of usage examples for java.awt Rectangle Rectangle
public Rectangle(int x, int y, int width, int height)
From source file:GUIUtils.java
public static Rectangle getScreenBoundsFor(Rectangle rc) { final GraphicsDevice[] gds = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); final List<GraphicsConfiguration> configs = new ArrayList<GraphicsConfiguration>(); for (int i = 0; i < gds.length; i++) { GraphicsConfiguration gc = gds[i].getDefaultConfiguration(); if (rc.intersects(gc.getBounds())) { configs.add(gc);//from w w w.j a v a 2 s . com } } GraphicsConfiguration selected = null; if (configs.size() > 0) { for (Iterator<GraphicsConfiguration> it = configs.iterator(); it.hasNext();) { GraphicsConfiguration gcc = it.next(); if (selected == null) selected = gcc; else { if (gcc.getBounds().contains(rc.x + 20, rc.y + 20)) { selected = gcc; break; } } } } else { selected = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); } int x = selected.getBounds().x; int y = selected.getBounds().y; int w = selected.getBounds().width; int h = selected.getBounds().height; return new Rectangle(x, y, w, h); }
From source file:org.streamspinner.harmonica.application.CQGraphTerminal.java
private JScrollPane getJScrollPane1() { if (jScrollPane1 == null) { jScrollPane1 = new JScrollPane(); jScrollPane1.setBounds(new Rectangle(0, 151, 400, 259)); jScrollPane1.setViewportView(getJTable()); }//from w w w . ja v a 2 s . c o m return jScrollPane1; }
From source file:GraphPaperLayout.java
public static void main(String[] a) { JFrame frame = new JFrame(); frame.setLayout(new GraphPaperLayout(new Dimension(5, 5))); // Add a 1x1 Rect at (0,0) frame.add(new Button("1"), new Rectangle(0, 0, 1, 1)); // Add a 2x1 Rect at (2,0) frame.add(new Button("2"), new Rectangle(2, 0, 2, 1)); // Add a 1x2 Rect at (1,1) frame.add(new Button("3"), new Rectangle(1, 1, 1, 2)); // Add a 2x2 Rect at (3,2) frame.add(new Button("4"), new Rectangle(3, 2, 2, 2)); // Add a 1x1 Rect at (0,4) frame.add(new Button("5"), new Rectangle(0, 4, 1, 1)); // Add a 1x2 Rect at (2,3) frame.add(new Button("6"), new Rectangle(2, 3, 1, 2)); frame.pack();/*from w w w. ja va2s. c o m*/ frame.setVisible(true); }
From source file:com.jakemadethis.graphite.visualization.renderers.HyperedgeLabelRenderer.java
public void labelEdge(RenderContext<V, E> rc, Layout<V, E> layout, E e, String label) { if (label == null || label.length() == 0) return;/*from w w w. j a v a2s . com*/ Graph<V, E> g = layout.getGraph(); EdgeLayout<E> edgeLayout = EdgeLayout$.MODULE$.apply(layout); Hypergraph<V, E> hg = g; if (!drawPredicate.evaluate(Context.<Hypergraph<V, E>, E>getInstance(hg, e))) return; if (!rc.getEdgeIncludePredicate().evaluate(Context.<Graph<V, E>, E>getInstance(g, e))) return; Point2D edgePos = edgeLayout.getEdgeLocation(e); edgePos = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, edgePos); GraphicsDecorator gd = rc.getGraphicsContext(); Component component = prepareRenderer(rc, rc.getEdgeLabelRenderer(), label, rc.getPickedEdgeState().isPicked(e), e); Dimension d = component.getPreferredSize(); AffineTransform old = gd.getTransform(); AffineTransform xform = new AffineTransform(old); xform.translate(edgePos.getX(), edgePos.getY()); gd.setTransform(xform); gd.setStroke(new BasicStroke(1)); Rectangle rect = new Rectangle(-10, -10, 20, 20); gd.setPaint(Color.WHITE); gd.fill(rect); gd.setPaint(Color.GRAY); gd.draw(rect); xform.translate(-d.width / 2, -d.height / 2); gd.setTransform(xform); gd.draw(component, rc.getRendererPane(), 0, 0, d.width, d.height, true); gd.setTransform(old); }
From source file:peakml.util.swt.widget.IntensityTrendGraph.java
public BufferedImage getGraphImage(int width, int height) { BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = img.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); linechart.draw(g, new Rectangle(0, 0, width, height)); return img;//from w ww . j ava2 s .com }
From source file:ca.ubc.cs.ferret.cg.VertexLabelAsShapeRenderer.java
/** * Labels the specified vertex with the specified label. * Uses the font specified by this instance's * <code>VertexFontFunction</code>. (If the font is unspecified, the existing * font for the graphics context is used.) If vertex label centering * is active, the label is centered on the position of the vertex; otherwise * the label is offset slightly.//w w w .j a v a2 s . c o m */ public void labelVertex(RenderContext<V, E> rc, Layout<V, E> layout, V v, String label) { Graph<V, E> graph = layout.getGraph(); if (rc.getVertexIncludePredicate().evaluate(Context.<Graph<V, E>, V>getInstance(graph, v)) == false) { return; } GraphicsDecorator g = rc.getGraphicsContext(); Component component = prepareRenderer(rc, rc.getVertexLabelRenderer(), label, rc.getPickedVertexState().isPicked(v), v); Dimension d = component.getPreferredSize(); int h_offset = -d.width / 2; int v_offset = -d.height / 2; Point2D p = layout.transform(v); p = rc.getMultiLayerTransformer().transform(Layer.LAYOUT, p); int x = (int) p.getX(); int y = (int) p.getY(); g.draw(component, rc.getRendererPane(), x + h_offset, y + v_offset, d.width, d.height, true); Dimension size = component.getPreferredSize(); Rectangle bounds = new Rectangle(-size.width / 2 - 2, -size.height / 2 - 2, size.width + 4, size.height); shapes.put(v, bounds); }
From source file:ca.inverse.sogo.admin.SOGoSyncSourceConfigPanel.java
/** * //from www. ja v a 2s.c o m */ private void init() { this.setLayout(null); titledBorder1 = new TitledBorder(""); panelName.setFont(titlePanelFont); panelName.setText("Edit SOGo SyncSource"); panelName.setBounds(new Rectangle(14, 5, 316, 28)); panelName.setAlignmentX(SwingConstants.CENTER); panelName.setBorder(titledBorder1); int y = 60; int dy = 30; sourceURILabel.setText("Source URI: "); sourceURILabel.setFont(defaultFont); sourceURILabel.setBounds(new Rectangle(14, y, 150, 18)); sourceURIValue.setFont(defaultFont); sourceURIValue.setBounds(new Rectangle(170, y, 350, 18)); y += dy; nameLabel.setText("Name: "); nameLabel.setFont(defaultFont); nameLabel.setBounds(new Rectangle(14, y, 150, 18)); nameValue.setFont(defaultFont); nameValue.setBounds(new Rectangle(170, y, 350, 18)); y += dy; typeLabel.setText("Supported type: "); typeLabel.setFont(defaultFont); typeLabel.setBounds(new Rectangle(14, y, 150, 18)); typeValue.setFont(defaultFont); typeValue.setBounds(new Rectangle(170, y, 150, 18)); y += dy; dbURLLabel.setText("Database URL: "); dbURLLabel.setFont(defaultFont); dbURLLabel.setBounds(new Rectangle(14, y, 150, 18)); dbURLValue.setFont(defaultFont); dbURLValue.setBounds(new Rectangle(170, y, 350, 18)); y += dy; dbUsernameLabel.setText("Database username:"); dbUsernameLabel.setFont(defaultFont); dbUsernameLabel.setBounds(new Rectangle(14, y, 150, 18)); dbUsernameValue.setFont(defaultFont); dbUsernameValue.setBounds(new Rectangle(170, y, 150, 18)); y += dy; dbPasswordLabel.setText("Database password:"); dbPasswordLabel.setFont(defaultFont); dbPasswordLabel.setBounds(new Rectangle(14, y, 150, 18)); dbPasswordValue.setFont(defaultFont); dbPasswordValue.setBounds(new Rectangle(170, y, 150, 18)); y += dy; button.setFont(defaultFont); button.setText("Add"); button.setBounds(170, y, 70, 25); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { validateValues(); getValues(); if (getState() == STATE_INSERT) { SOGoSyncSourceConfigPanel.this.actionPerformed(new ActionEvent( SOGoSyncSourceConfigPanel.this, ACTION_EVENT_INSERT, event.getActionCommand())); } else { SOGoSyncSourceConfigPanel.this.actionPerformed(new ActionEvent( SOGoSyncSourceConfigPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand())); } } catch (Exception e) { notifyError(new AdminException(e.getMessage())); } } }); this.add(panelName, null); this.add(nameLabel, null); this.add(nameValue, null); this.add(typeLabel, null); this.add(typeValue, null); this.add(sourceURILabel, null); this.add(sourceURIValue, null); this.add(dbURLLabel); this.add(dbURLValue); this.add(dbUsernameLabel); this.add(dbUsernameValue); this.add(dbPasswordLabel); this.add(dbPasswordValue); this.add(button, null); }
From source file:endrov.typeTimeRemap.TimeRemapWindow.java
/** * Make a new window//from ww w . j av a 2 s .c om */ public TimeRemapWindow() { bAdd.addActionListener(this); bRefresh.addActionListener(this); objectCombo.addActionListener(this); XYDataset xyDataset = new XYSeriesCollection(frametimeSeries); JFreeChart chart = ChartFactory.createXYLineChart("", "New time", "Original time", xyDataset, PlotOrientation.HORIZONTAL, false/*legend*/, false/*tooltips*/, false/*urls*/); ChartPanel graphpanel = new ChartPanel(chart); //Put GUI together JPanel datapanel = new JPanel(new BorderLayout()); JPanel dataparto = new JPanel(new BorderLayout()); dataparto.add(datapart, BorderLayout.NORTH); JScrollPane datapartscroll = new JScrollPane(dataparto, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); JPanel buttonpanel = new JPanel(new GridLayout(1, 2)); buttonpanel.add(bAdd); buttonpanel.add(bRefresh); datapanel.add(buttonpanel, BorderLayout.SOUTH); datapanel.add(datapartscroll, BorderLayout.CENTER); setLayout(new BorderLayout()); add(datapanel, BorderLayout.EAST); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.add(graphpanel, BorderLayout.CENTER); leftPanel.add(objectCombo, BorderLayout.SOUTH); add(leftPanel, BorderLayout.CENTER); loadData(); //Window overall things setTitleEvWindow("Time remapper"); packEvWindow(); setBoundsEvWindow(new Rectangle(100, 100, 1000, 600)); setVisibleEvWindow(true); }
From source file:PaintUtils.java
/** * Returns the bounds that the text of a label will be drawn into. * Takes into account the current font metrics. *//* w w w . jav a 2 s.c om*/ public static Rectangle getTextBounds(Graphics g, JLabel label) { FontMetrics fm = g.getFontMetrics(); Rectangle2D r2d = fm.getStringBounds(label.getText(), g); Rectangle rect = r2d.getBounds(); int xOffset = 0; switch (label.getHorizontalAlignment()) { case SwingConstants.RIGHT: case SwingConstants.TRAILING: xOffset = label.getBounds().width - rect.width; break; case SwingConstants.CENTER: xOffset = (label.getBounds().width - rect.width) / 2; break; default: case SwingConstants.LEFT: case SwingConstants.LEADING: xOffset = 0; break; } int yOffset = 0; switch (label.getVerticalAlignment()) { case SwingConstants.TOP: yOffset = 0; break; case SwingConstants.CENTER: yOffset = (label.getBounds().height - rect.height) / 2; break; case SwingConstants.BOTTOM: yOffset = label.getBounds().height - rect.height; break; } return new Rectangle(xOffset, yOffset, rect.width, rect.height); }
From source file:com.funambol.json.admin.JsonConnectorConfigPanel.java
/** * Create the panel/* ww w.ja v a 2s. c om*/ */ private void init() { JLabel title, serverLabel; JPanel seccPanel; JPanel behaviourOnErrorsPanel; title = new JLabel(); seccPanel = new JPanel(); behaviourOnErrorsPanel = new JPanel(); serverLabel = new JLabel(); serverValue = new JTextField(); setLayout(null); title.setFont(titlePanelFont); title.setText("Funambol Json Connector"); title.setBounds(new Rectangle(14, 5, 316, 28)); title.setAlignmentX(SwingConstants.CENTER); title.setBorder(new TitledBorder("")); seccPanel.setLayout(null); seccPanel.setBorder(new TitledBorder("HTTP Server Configuration")); serverLabel.setText("Server:"); seccPanel.add(serverLabel); serverLabel.setBounds(10, 20, 116, 15); seccPanel.add(serverValue); serverValue.setBounds(150, 20, 220, 19); serverValue.setFont(defaultFont); add(seccPanel); seccPanel.setBounds(10, 50, 380, 70); //the ssl option panel behaviourOnErrorsPanel.setBorder(new TitledBorder("Behaviour on errors")); behaviourOnErrorsPanel.setLayout(null); stopSyncOnFatalError.setText("Stop sync on fatal errors"); stopSyncOnFatalError.setBounds(10, 25, 200, 15); behaviourOnErrorsPanel.add(stopSyncOnFatalError); add(behaviourOnErrorsPanel); behaviourOnErrorsPanel.setBounds(10, 130, 380, 60); confirmButton.setFont(defaultFont); confirmButton.setText("Save"); add(confirmButton); confirmButton.setBounds(160, 200, 70, 25); confirmButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { validateValues(); getValues(); JsonConnectorConfigPanel.this.actionPerformed(new ActionEvent(JsonConnectorConfigPanel.this, ACTION_EVENT_UPDATE, event.getActionCommand())); } catch (Exception e) { notifyError(new AdminException(e.getMessage())); } } }); // // Setting font... // Component[] components = getComponents(); for (int i = 0; (components != null) && (i < components.length); ++i) { components[i].setFont(defaultFont); } // // We add it as the last one so that the font won't be changed // add(title); }