Example usage for java.awt MediaTracker waitForAll

List of usage examples for java.awt MediaTracker waitForAll

Introduction

In this page you can find the example usage for java.awt MediaTracker waitForAll.

Prototype

public void waitForAll() throws InterruptedException 

Source Link

Document

Starts loading all images tracked by this media tracker.

Usage

From source file:SlidePuzzle.java

public void run() {
    if (!m_fAllLoaded) {
        m_Graphics = getGraphics();
        MediaTracker tracker = new MediaTracker(this);
        logo = getImage(getDocumentBase(), "vjlogo.gif");
        tracker.addImage(logo, 0);/*from   w ww  .  ja v a 2  s . co m*/

        try {
            tracker.waitForAll();
            m_fAllLoaded = !tracker.isErrorAny();
        } catch (InterruptedException e) {
        }

        if (!m_fAllLoaded) {
            stop();
            m_Graphics.drawString("Error loading images!", 10, 40);
            return;
        }
    }

    //Clear the screen and draw first image
    repaint();

    //Move the squares
    while (true) {
        for (x = 1; x < 9; x++) {
            //Slow down the animation
            try {
                Thread.sleep(350);
            } catch (InterruptedException e) {
            }

            //Move square to next location

            m_Graphics.copyArea(squares[order[x]].x, squares[order[x]].y, 60, 60,
                    squares[order[x - 1]].x - squares[order[x]].x,
                    squares[order[x - 1]].y - squares[order[x]].y);

            //Clear most recently copied square

            m_Graphics.clearRect(squares[order[x]].x, squares[order[x]].y, 60, 60);
        }

        //Repaint original graphic after two cycles
        y++;
        if (y == 2) {
            repaint();
            y = 0;
        }
    }
}

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * Return the loaded picture from a local place.
 * //w  ww  .j  a v  a  2  s  . c om
 * @param localFile
 *          the local file name.
 * @return the local picture.
 * @throws InterruptedException
 */
public static Image getLocalPicture(String localFile) throws InterruptedException {
    final Image result = Toolkit.getDefaultToolkit().getImage(getFile(localFile, true).getAbsolutePath());
    if (result == null) {
        throw new InterruptedException("Picture " + localFile + " has not been found");
    }
    final MediaTracker tracker = new MediaTracker(MagicUIComponents.magicForm);
    tracker.addImage(result, 0);
    tracker.waitForAll();
    if (tracker.isErrorAny()) {
        tracker.removeImage(result, 0);
        tracker.waitForAll();
        result.flush();
        throw new InterruptedException("Malformed picture " + localFile);
    }
    return result;
}

From source file:org.colombbus.tangara.EditorFrame.java

/**
 * This method initializes the design of the frame.
 *
 */// w ww  . ja  va2  s.co m
private void initialize() {
    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle bounds = graphicsEnvironment.getMaximumWindowBounds();
    setPreferredSize(bounds.getSize());

    this.setJMenuBar(getBanner());

    this.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    // Sets the main menu (the one separated by jsplitPane1)
    this.setContentPane(getBasePanel());
    this.setTitle(Messages.getString("EditorFrame.application.title")); //$NON-NLS-1$
    addWindowListener(this.windowListener);
    try {
        // Associates the icon (frame.icon = icon_tangara.png) to Tangara
        URL url = EditorFrame.class.getResource(ICON_PATH);
        MediaTracker attenteChargement = new MediaTracker(this);
        Image image = Toolkit.getDefaultToolkit().getImage(url);
        attenteChargement.addImage(image, 0);
        attenteChargement.waitForAll();
        setIconImage(image);
    } catch (InterruptedException e) {
        LOG.warn("Error while loading icon"); //$NON-NLS-1$
    }
    // fileChooser allows to easily choose a file
    // when you open (FILE->OPEN...) you have the choice between .txt or
    // .tgr
    fileChooser = new JFileChooser(Program.instance().getCurrentDirectory());

    // for TangaraFile ".tgr"
    fileChooser.addChoosableFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            if (f.isDirectory())
                return true;
            return FileUtils.isTangaraFile(f);
        }

        @Override
        public String getDescription() {
            return Messages.getString("EditorFrame.file.programFilesDescription"); //$NON-NLS-1$
        }
    });

    fileChooserWithoutFilter = new JFileChooser(Program.instance().getCurrentDirectory());
    pack();
    setVisible(true);
    setExtendedState(java.awt.Frame.MAXIMIZED_BOTH);
}

From source file:org.pmedv.core.gui.ApplicationWindowAdvisorImpl.java

@Override
public void preWindowCreate() {

    log.info("initializing.");

    String laf = (String) Preferences.values.get("org.pmedv.blackboard.BoardDesignerPerspective.lookAndFeel");

    try {//from w w w  .  ja  v a2 s.c o m
        if (laf.equals("Nimbus")) {
            UIManager.setLookAndFeel(new NimbusLookAndFeel());
        } else if (laf.equals("SkyBlue")) {
            Plastic3DLookAndFeel.setPlasticTheme(new SkyBluer());
            UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
            com.jgoodies.looks.Options.setPopupDropShadowEnabled(true);
        } else {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        }
    } catch (Exception e2) {
        log.info("failed to set look and feel.");
    }

    final Color blackboardLightBlue = new Color(225, 234, 242);
    final Color blackBoardDarkBlue = new Color(182, 191, 205);
    final Color blackboardLightGrey = new Color(220, 220, 222);

    UIManager.put("TaskPane.titleBackgroundGradientStart", Color.WHITE);
    UIManager.put("TaskPane.titleBackgroundGradientEnd", blackboardLightBlue);
    UIManager.put("TaksPane.specialTitleBackground", blackboardLightBlue);
    UIManager.put("TaskPane.titleBackground", blackboardLightBlue);
    UIManager.put("TaskPane.borderColor", blackboardLightBlue);
    UIManager.put("TaskPane.background", blackboardLightGrey);
    UIManager.put("TaskPaneContainer.backgroundPainter", new MattePainter(blackBoardDarkBlue));

    log.info("setting look and feel to: " + UIManager.getLookAndFeel());

    // construct app icon

    Image iconImage = resources.getIcon("icon.application").getImage();

    MediaTracker mt = new MediaTracker(win);
    mt.addImage(iconImage, 0);

    try {
        mt.waitForAll();
    } catch (InterruptedException e) {
        // Silently ignore
    }

    InputStream is = getClass().getClassLoader().getResourceAsStream("application.properties");
    Properties properties = new Properties();
    try {
        properties.load(is);
    } catch (IOException e1) {
        properties.setProperty("version", "not set");
    }

    win.setTitle(windowConfig.getConfig().getTitle() + " Version " + properties.get("version"));
    win.setIconImage(iconImage);
    win.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    win.addWindowListener(win);

    ToolTipManager.sharedInstance().setInitialDelay(100);
    ToolTipManager.sharedInstance().setDismissDelay(1000);

}

From source file:processing.app.Theme.java

/**
 * Return an Image object from inside the Processing lib folder.
 *///  w  w  w.j a  va  2s  .c om
static public Image getLibImage(String filename, Component who, int width, int height) {
    Image image = null;

    // Use vector image when available
    Resource vectorFile = getThemeResource(filename + ".svg");
    if (vectorFile.exists()) {
        try {
            image = imageFromSVG(vectorFile.getUrl(), width, height);
        } catch (Exception e) {
            System.err.println("Failed to load " + vectorFile + ": " + e.getMessage());
        }
    }

    Resource bitmapFile = getThemeResource(filename + ".png");

    // Otherwise fall-back to PNG bitmaps, allowing user-defined bitmaps to
    // override built-in svgs
    if (image == null || bitmapFile.getPriority() > vectorFile.getPriority()) {
        Resource bitmap2xFile = getThemeResource(filename + "@2x.png");

        Resource imageFile;
        if (((getScale() > 125 && bitmap2xFile.exists()) || !bitmapFile.exists())
                && (bitmapFile.isUserDefined() && bitmap2xFile.isUserDefined())) {
            imageFile = bitmap2xFile;
        } else {
            imageFile = bitmapFile;
        }
        Toolkit tk = Toolkit.getDefaultToolkit();
        image = tk.getImage(imageFile.getUrl());
    }

    MediaTracker tracker = new MediaTracker(who);
    try {
        tracker.addImage(image, 0);
        tracker.waitForAll();
    } catch (InterruptedException e) {
    }

    if (image.getWidth(null) != width || image.getHeight(null) != height) {
        image = image.getScaledInstance(width, height, Image.SCALE_SMOOTH);
        try {
            tracker.addImage(image, 1);
            tracker.waitForAll();
        } catch (InterruptedException e) {
        }
    }

    return image;
}

From source file:sim.model.entity.Category.java

/**
 * Prepare the entity image//from w  w  w. j  a va  2s .  c  om
 */
protected void prepareEntityImage(JComponent c, String path) {
    // Prepare the entity image
    super.prepareEntityImage(c, path);
    // Adjust the image
    ImageFilter filter = new WhiteFilter();
    FilteredImageSource filteredImage = new FilteredImageSource(display.getImage().getSource(), filter);
    Image image = Toolkit.getDefaultToolkit().createImage(filteredImage);
    MediaTracker tracker = new MediaTracker(c);
    try {
        tracker.addImage(image, 0);
        tracker.waitForAll();
    } catch (InterruptedException e) {
    }
    display.setImage(image);
    display.setImagePath(path);
}

From source file:unikn.dbis.univis.explorer.VSplashScreen.java

/**
 * Erzeugt eine neue <code>VSplashScreen</code> und sobald das Splashable gesetzt wurde
 * beendet sich die Screen von selbst.//ww w  .  j  ava  2 s .c o m
 *
 * @param inputStream Der Dateiname incl. des relativen Pfades des anzuzeigenden Images.
 */
public VSplashScreen(InputStream inputStream) {

    // Splash screen have to be always on top until the explorer
    // isn't loaded.
    setAlwaysOnTop(true);

    try {
        image = ImageIO.read(inputStream);
    } catch (IOException ioe) {
        ioe.printStackTrace();
    }

    MediaTracker mt = new MediaTracker(this);

    mt.addImage(image, 0);

    try {
        mt.waitForAll();
    } catch (InterruptedException e) {
        if (LOG.isErrorEnabled()) {
            LOG.error(e.getMessage(), e);
        }
    }

    thread = new Thread(this);
    thread.setPriority(Thread.MAX_PRIORITY);
    thread.start();

    center();

    setVisible(true);
}