List of usage examples for java.awt Dimension Dimension
public Dimension(int width, int height)
From source file:de.codesourcery.geoip.Main.java
public static void main(String[] args) throws Exception { final IGeoLocator<StringSubject> locator = createGeoLocator(); final JFrame frame = new JFrame("GeoIP"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.addWindowListener(new WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { try { locator.dispose();/* w ww .j av a 2 s . c o m*/ } catch (Exception e1) { e1.printStackTrace(); } }; }); final MapImage image = MapImage.getRobinsonWorldMap(); // MapImage.getMillerWorldMap(); final MapCanvas canvas = new MapCanvas(image); for (GeoLocation<StringSubject> loc : locator.locate(getSpammers())) { if (loc.hasValidCoordinates()) { canvas.addCoordinate(PointRenderer.createPoint(loc, Color.YELLOW)); } } // canvas.addCoordinate( PointRenderer.createPoint( ZERO , Color.YELLOW ) ); // canvas.addCoordinate( PointRenderer.createPoint( WELLINGTON , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( MELBOURNE , Color.RED ) ); // canvas.addCoordinate( PointRenderer.createPoint( HAMBURG , Color.RED ) ); final double heightToWidth = image.height() / (double) image.width(); // preserve aspect ratio of map canvas.setPreferredSize(new Dimension(640, (int) Math.round(640 * heightToWidth))); JPanel panel = new JPanel(); panel.setLayout(new FlowLayout()); panel.add(new JLabel("Scale-X")); final JTextField scaleX = new JTextField(Double.toString(image.getScaleX())); scaleX.setColumns(5); final JTextField scaleY = new JTextField(Double.toString(image.getScaleY())); scaleY.setColumns(5); final ActionListener listener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { double x = Double.parseDouble(scaleX.getText()); double y = Double.parseDouble(scaleY.getText()); image.setScale(x, y); canvas.repaint(); } }; scaleX.addActionListener(listener); scaleY.addActionListener(listener); panel.add(new JLabel("Scale-X")); panel.add(scaleX); panel.add(new JLabel("Scale-Y")); panel.add(scaleY); final JTextField ipAddress = new JTextField("www.kickstarter.com"); ipAddress.setColumns(20); final ActionListener ipListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { final String destinationIP = ipAddress.getText(); if (StringUtils.isBlank(destinationIP)) { return; } /* * Perform traceroute. */ final List<String> hops; try { if (TracePath.isPathTracingAvailable()) { hops = TracePath.trace(destinationIP); } else { System.err.println("tracepath not available."); if (TracePath.isValidAddress(destinationIP)) { hops = new ArrayList<>(); hops.add(destinationIP); } else { System.err.println(destinationIP + " is no valid IP"); return; } } } catch (Exception ex) { System.err.println("Failed to trace " + destinationIP); ex.printStackTrace(); return; } System.out.println("Trace contains " + hops.size() + " IPs"); /* * Gather locations. */ final List<StringSubject> subjects = new ArrayList<>(); for (String ip : hops) { subjects.add(new StringSubject(ip)); } final List<GeoLocation<StringSubject>> locations; try { long time = -System.currentTimeMillis(); locations = locator.locate(subjects); time += System.currentTimeMillis(); System.out.println("Locating hops for " + destinationIP + " returned " + locations.size() + " valid locations ( time: " + time + " ms)"); System.out.flush(); } catch (Exception e2) { e2.printStackTrace(); return; } /* * Weed-out invalid/unknown locations. */ { GeoLocation<StringSubject> previous = null; for (Iterator<GeoLocation<StringSubject>> it = locations.iterator(); it.hasNext();) { final GeoLocation<StringSubject> location = it.next(); if (!location.hasValidCoordinates() || (previous != null && previous.coordinate().equals(location.coordinate()))) { it.remove(); System.err.println("Ignoring invalid/duplicate location for " + location); } else { previous = location; } } } /* * Populate chart. */ System.out.println("Adding " + locations.size() + " hops to chart"); System.out.flush(); canvas.removeAllCoordinates(); if (locations.size() == 1) { canvas.addCoordinate( PointRenderer.createPoint(locations.get(0), getLabel(locations.get(0)), Color.BLACK)); } else if (locations.size() > 1) { GeoLocation<StringSubject> previous = locations.get(0); MapPoint previousPoint = PointRenderer.createPoint(previous, getLabel(previous), Color.BLACK); final int len = locations.size(); for (int i = 1; i < len; i++) { final GeoLocation<StringSubject> current = locations.get(i); // final MapPoint currentPoint = PointRenderer.createPoint( current , getLabel( current ) , Color.BLACK ); final MapPoint currentPoint = PointRenderer.createPoint(current, Color.BLACK); // canvas.addCoordinate( LineRenderer.createLine( previousPoint , currentPoint , Color.RED ) ); canvas.addCoordinate(CurvedLineRenderer.createLine(previousPoint, currentPoint, Color.RED)); previous = locations.get(i); previousPoint = currentPoint; } } System.out.println("Finished adding"); System.out.flush(); canvas.repaint(); } }; ipAddress.addActionListener(ipListener); panel.add(new JLabel("IP")); panel.add(ipAddress); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(panel, BorderLayout.NORTH); frame.getContentPane().add(canvas, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:ListInput.java
public static void main(String[] a) { String[] fontNames = new String[] { "Roman", "Times Roman" }; ListInput lstFontName = new ListInput(fontNames, "Name:"); lstFontName.setDisplayedMnemonic('n'); lstFontName.setToolTipText("Font name"); JFrame f = new JFrame(); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from ww w. j ava 2 s . c o m*/ } }); f.getContentPane().add(lstFontName); f.pack(); f.setSize(new Dimension(300, 200)); f.show(); }
From source file:ClipImage.java
public static void main(String s[]) { final ClipImage demo = new ClipImage(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from w ww .j av a 2 s . c om*/ } public void windowDeiconified(WindowEvent e) { demo.start(); } public void windowIconified(WindowEvent e) { demo.stop(); } }; JFrame f = new JFrame("Java 2D Demo - ClipImage"); f.addWindowListener(l); f.getContentPane().add("Center", demo); f.setSize(new Dimension(400, 300)); f.show(); demo.start(); }
From source file:ClipImage.java
public static void main(String s[]) { final ClipImage demo = new ClipImage(); WindowListener l = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);//from www .ja v a2s .c o m } public void windowDeiconified(WindowEvent e) { demo.start(); } public void windowIconified(WindowEvent e) { demo.stop(); } }; JFrame f = new JFrame("Java 2D Demo - ClipImage"); f.addWindowListener(l); f.getContentPane().add("Center", demo); f.setSize(new Dimension(400, 300)); f.setVisible(true); demo.start(); }
From source file:jmemorize.gui.swing.panels.HistoryChartPanel.java
public static void main(String[] args) { JFrame frame = new JFrame(); frame.setContentPane(new HistoryChartPanel(new LearnHistory(Main.STATS_FILE))); frame.setSize(new Dimension(800, 800)); frame.setVisible(true);/* w w w . j a v a 2 s. com*/ frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
From source file:Main.java
public static Dimension getLabelDimension(int w, int h) { return new Dimension(w, h); }
From source file:Main.java
public static Dimension getControlDimension(int w, int h) { return new Dimension(w, h); }
From source file:Main.java
public static void setPreferredWidth(Component c, int width) { c.setPreferredSize(new Dimension(width, c.getPreferredSize().height)); }
From source file:Main.java
public static void setPreferredWidth(JComponent component, int width) { component.setPreferredSize(new Dimension(width, component.getPreferredSize().height)); }
From source file:Main.java
public static void setMinimumWidth(Component c, int width) { if (c.getPreferredSize().width < width) c.setPreferredSize(new Dimension(width, c.getPreferredSize().height)); }