Example usage for java.awt Toolkit getDefaultToolkit

List of usage examples for java.awt Toolkit getDefaultToolkit

Introduction

In this page you can find the example usage for java.awt Toolkit getDefaultToolkit.

Prototype

public static synchronized Toolkit getDefaultToolkit() 

Source Link

Document

Gets the default toolkit.

Usage

From source file:RotateImage45Degrees.java

public RotateImage45Degrees(String imageFile) {
    addNotify();//from  w ww  .j  a  v  a  2s.c  o  m
    frameInsets = getInsets();
    inputImage = Toolkit.getDefaultToolkit().getImage(imageFile);

    MediaTracker mt = new MediaTracker(this);
    mt.addImage(inputImage, 0);
    try {
        mt.waitForID(0);
    } catch (InterruptedException ie) {
    }

    sourceBI = new BufferedImage(inputImage.getWidth(null), inputImage.getHeight(null),
            BufferedImage.TYPE_INT_ARGB);

    Graphics2D g = (Graphics2D) sourceBI.getGraphics();
    g.drawImage(inputImage, 0, 0, null);

    AffineTransform at = new AffineTransform();

    // scale image
    at.scale(2.0, 2.0);

    // rotate 45 degrees around image center
    at.rotate(45.0 * Math.PI / 180.0, sourceBI.getWidth() / 2.0, sourceBI.getHeight() / 2.0);

    /*
     * translate to make sure the rotation doesn't cut off any image data
     */
    AffineTransform translationTransform;
    translationTransform = findTranslation(at, sourceBI);
    at.preConcatenate(translationTransform);

    // instantiate and apply affine transformation filter
    BufferedImageOp bio;
    bio = new AffineTransformOp(at, AffineTransformOp.TYPE_BILINEAR);

    destinationBI = bio.filter(sourceBI, null);

    int frameInsetsHorizontal = frameInsets.right + frameInsets.left;
    int frameInsetsVertical = frameInsets.top + frameInsets.bottom;
    setSize(destinationBI.getWidth() + frameInsetsHorizontal, destinationBI.getHeight() + frameInsetsVertical);
    show();
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.actions.CopyChartAction.java

/**
 * Copies the current chart to the system clipboard.
 *//*from   w  w w  .  ja v  a2  s .c o  m*/
public static synchronized void copyChart(final JFreeChartPlotEngine engine) {
    Clipboard systemClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    Insets insets = engine.getChartPanel().getInsets();
    int w = engine.getChartPanel().getWidth() - insets.left - insets.right;
    int h = engine.getChartPanel().getHeight() - insets.top - insets.bottom;
    ChartTransferable selection = new ChartTransferable(engine.getChartPanel().getChart(), w, h);
    systemClipboard.setContents(selection, null);
}

From source file:Main.java

/**
 * Gets the insets of the screen.//  w  ww  . j  a v  a2s. c  om
 * <p>
 * <b>Attention: </b>Due to <a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6899304">Java bug 6899304</a>
 * this method only returns correct insets values for the primary screen device. For other screen devices empty insets
 * will be returned. In Windows environments these circumstances (task bar on a none primary screen) will be very rare
 * and therefore ignored until the bug will be fixed in a future Java version.
 * </p>
 *
 * @param screenDevice
 *          a screen thats {@link GraphicsConfiguration} will be used to determine the insets
 * @return the insets of this toolkit's screen, in pixels, if the given screen device is the primary screen, otherwise
 *         empty insets
 * @see Toolkit#getScreenInsets(GraphicsConfiguration)
 */
public static Insets getScreenInsets(GraphicsDevice screenDevice) {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    // <bko 2012-02-29>
    // "Fix" for Sun bug 6899304 ("java.awt.Toolkit.getScreenInsets(GraphicsConfiguration) returns incorrect values")
    // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6699851
    if (screenDevice == ge.getDefaultScreenDevice()) {
        // only return Toolkit.getScreenInsets for primary screen device
        return Toolkit.getDefaultToolkit().getScreenInsets(screenDevice.getDefaultConfiguration());
    } else {
        // return empty insets for other screen devices
        return new Insets(0, 0, 0, 0);
    }
    // </bko>
}

From source file:de.tor.tribes.util.parser.TroopsParser70.java

public static void main(String[] args) {

    Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    try {//from w  ww  . java 2  s  .  c  o  m

        /*
         * String data = "Rattennest (0|0) (486|833) K84 eigene 14 8 6490 0 181 2550 300 0 300 30 0 +3 + Befehle\n" + "im Dorf    15000
         * 15000    5493    15000    950    2449    257    5000    300    30    0    1    Truppen\n" + "auswrts    0    0    0    0    0    0    0    0    0    0    0    0\n" + "unterwegs    0    0    0    0    0    0    0    0
         * 0    0    0    0    Befehle\n";
         *
         */
        String data = (String) t.getTransferData(DataFlavor.stringFlavor);
        new TroopsParser70().parse(data);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // TroopsParser.parse(pTroopsString);
}

From source file:ImageFileFilterImageScale.java

public void actionPerformed(ActionEvent e) {
    String file = getImageFile();
    if (file != null) {
        Toolkit kit = Toolkit.getDefaultToolkit();
        img = kit.getImage(file);//from  w ww  .jav a  2  s.co  m
        img = img.getScaledInstance(300, -1, Image.SCALE_SMOOTH);
        this.repaint();
    }
}

From source file:coolmap.canvas.action.PasteRowNodesAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {/*from  www . j  av  a  2s. c  o m*/
        CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
        Transferable content = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);
        String data = (String) content.getTransferData(DataFlavor.stringFlavor);
        JSONObject json = new JSONObject(data);

        ArrayList<Range<Integer>> selectedRows = obj.getCoolMapView().getSelectedRows();
        //            System.out.println(selectedColumns);
        //if there are selections
        int insertionIndex = 0;
        if (selectedRows != null && !selectedRows.isEmpty()) {
            insertionIndex = selectedRows.get(0).lowerEndpoint();
            //System.out.println(lower);

        } //else
        else {
            //append at beginning

        }

        JSONArray terms = json.getJSONArray("Terms");
        String ontologyID = json.getString("OntologyID");

        COntology ontology = CoolMapMaster.getCOntologyByID(ontologyID);

        System.out.println("Ontology:" + ontology);

        if (ontology == null) {
            return;
        }

        ArrayList<VNode> newNodes = new ArrayList<VNode>();

        for (int i = 0; i < terms.length(); i++) {
            VNode node = new VNode(terms.getString(i), ontology);
            newNodes.add(node);
            System.out.println(node);
        }

        Rectangle centerTo = new Rectangle(0, insertionIndex, 1, 1);
        if (obj.getCoolMapView().getSelectedColumns() != null
                && !obj.getCoolMapView().getSelectedColumns().isEmpty()) {
            centerTo.x = ((Range<Integer>) (obj.getCoolMapView().getSelectedColumns().get(0))).lowerEndpoint();
        }

        CoolMapState state = CoolMapState.createStateRows("Insert Row Nodes", obj, null);
        obj.insertRowNodes(insertionIndex, newNodes, true);
        obj.getCoolMapView().centerToRegion(centerTo);
        StateStorageMaster.addState(state);

    } catch (Exception ex) {
        System.err.println("Exception in pasting rows:" + ex);
    }
}

From source file:historyView.HistoryJFrame.java

/**
 * Creates new form HistoryJFrame//w  ww .  j ava2s .  c o  m
 */
public HistoryJFrame() {
    initComponents();
    //set window in the center of the screen
    //Get the size of the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    //Determine the new location of the window
    int w = this.getSize().width;
    int h = this.getSize().height;
    int x = (dim.width - w) / 2;
    int y = (dim.height - h) / 2;
    //Move the window
    this.setLocation(x, y);

    XYSeries breathingSeries = new XYSeries("Breathing Rate");
    XYSeries oxygenSeries = new XYSeries("Oxygen");
    XYSeries temperatureSeries = new XYSeries("Temperature");
    XYSeries bloodPressureSeries = new XYSeries("Blood Pressure");
    XYSeries heartRateSeries = new XYSeries("Heart Rate");

    // add date to all the series
    for (Map.Entry<String, PatientData> entry : model.getSelectedPatient().data.entrySet()) {
        breathingSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getBreathing());
        oxygenSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getOxygen());
        temperatureSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getTemperature());
        bloodPressureSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getBloodPressure());
        heartRateSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getHeartRate());
    }

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(breathingSeries);
    dataset.addSeries(oxygenSeries);
    dataset.addSeries(temperatureSeries);
    dataset.addSeries(bloodPressureSeries);
    dataset.addSeries(heartRateSeries);

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("XY Chart", // Title
            "time(s)", // x-axis Label
            "Rate", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    this.setLayout(new java.awt.BorderLayout());
    ChartPanel CP = new ChartPanel(chart);
    chart.getPlot().setBackgroundAlpha(1);
    chart.getPlot().setBackgroundPaint(Color.BLUE);

    HistoryButtonsJPanel buttonPanel = new HistoryButtonsJPanel();

    ChartUtilities.applyCurrentTheme(chart);
    this.add(CP, BorderLayout.CENTER);
    this.add(buttonPanel, BorderLayout.PAGE_END);
    this.validate();
}

From source file:edu.jhuapl.graphs.jfreechart.utils.HighResChartUtil.java

/**
 * Returns a high resolution BufferedImage of the chart. Uses the default DPI_FILE_RESOLUTION.
 *
 * @param resolution The resolution, in dots per inch, of the image to generate.
 * @return the buffered image./*from   w ww  .  j av a2s.  c o m*/
 */
public static BufferedImage getHighResChartImage(ChartPanel chartPanel, int resolution) {
    int screenResolution = Toolkit.getDefaultToolkit().getScreenResolution();
    double scaleRatio = resolution / screenResolution;
    int width = chartPanel.getWidth();
    int height = chartPanel.getHeight();
    int rasterWidth = (int) (width * scaleRatio);
    int rasterHeight = (int) (height * scaleRatio);

    BufferedImage image = new BufferedImage(rasterWidth, rasterHeight, BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();

    g2.transform(AffineTransform.getScaleInstance(scaleRatio, scaleRatio));
    chartPanel.getChart().draw(g2, new Rectangle2D.Double(0, 0, width, height), null);
    g2.dispose();

    return image;
}

From source file:SplashScreen.java

public void showSplash() {
    JPanel content = (JPanel) getContentPane();
    content.setBackground(Color.white);

    // Set the window's bounds, centering the window
    int width = 450;
    int height = 115;
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screen.width - width) / 2;
    int y = (screen.height - height) / 2;
    setBounds(x, y, width, height);/*from w w  w. j av  a  2 s  . c  o  m*/

    // Build the splash screen
    JLabel label = new JLabel(new ImageIcon("1.gif"));
    JLabel copyrt = new JLabel("Copyright 2002, O'Reilly & Associates", JLabel.CENTER);
    copyrt.setFont(new Font("Sans-Serif", Font.BOLD, 12));
    content.add(label, BorderLayout.CENTER);
    content.add(copyrt, BorderLayout.SOUTH);
    Color oraRed = new Color(156, 20, 20, 255);
    content.setBorder(BorderFactory.createLineBorder(oraRed, 10));

    // Display it
    setVisible(true);

    // Wait a little while, maybe while loading resources
    try {
        Thread.sleep(duration);
    } catch (Exception e) {
    }

    setVisible(false);
}

From source file:coolmap.canvas.action.PasteColumnNodesAction.java

@Override
public void actionPerformed(ActionEvent e) {
    try {/*from   w w  w.  j  ava2 s.c o m*/
        CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject();
        Transferable content = (Transferable) Toolkit.getDefaultToolkit().getSystemClipboard()
                .getContents(null);
        String data = (String) content.getTransferData(DataFlavor.stringFlavor);
        JSONObject json = new JSONObject(data);

        System.out.println(json);

        //System.out.println(((JMenuItem)(e.getSource())).getParent());
        ArrayList<Range<Integer>> selectedColumns = obj.getCoolMapView().getSelectedColumns();
        //            System.out.println(selectedColumns);
        //if there are selections
        int insertionIndex = 0;
        if (selectedColumns != null && !selectedColumns.isEmpty()) {
            insertionIndex = selectedColumns.get(0).lowerEndpoint();

        } //else

        System.out.println(insertionIndex);

        JSONArray terms = json.getJSONArray("Terms");
        String ontologyID = json.getString("OntologyID");

        COntology ontology = CoolMapMaster.getCOntologyByID(ontologyID);

        System.out.println("Ontology:" + ontology);

        if (ontology == null) {
            return;
        }

        ArrayList<VNode> newNodes = new ArrayList<VNode>();

        for (int i = 0; i < terms.length(); i++) {
            VNode node = new VNode(terms.getString(i), ontology);
            newNodes.add(node);
            System.out.println(node);
        }

        Rectangle centerTo = new Rectangle(insertionIndex, 0, 1, 1);
        if (obj.getCoolMapView().getSelectedRows() != null
                && !obj.getCoolMapView().getSelectedRows().isEmpty()) {
            centerTo.y = ((Range<Integer>) (obj.getCoolMapView().getSelectedRows().get(0))).lowerEndpoint();
        }

        CoolMapState state = CoolMapState.createStateColumns("Insert Column Nodes", obj, null);
        obj.insertColumnNodes(insertionIndex, newNodes, true);
        //need to center to inserted
        obj.getCoolMapView().centerToRegion(centerTo);

        StateStorageMaster.addState(state);

    } catch (Exception ex) {
        //Return
        System.err.println("Exception in pasting columns:" + ex);
    }
}