alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * GazoogleOpenSupport.java
 *
 * Created on Friday, 13 July 2001 1430 MDT
 */

package com.example.nb.tutorial.chapter_5;

import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.openide.NotifyDescriptor;
import org.openide.TopManager;
import org.openide.cookies.OpenCookie;
import org.openide.filesystems.FileObject;
import org.openide.windows.WindowManager;
import org.openide.windows.Workspace;

/**
 *
 * @author  adams
 * @version 1.0
 */
public class GazoogleOpenSupport implements OpenCookie 
{
    protected GazoogleDataObject dataObject;

    /** Creates new GazoogleOpenSupport */
    public GazoogleOpenSupport(GazoogleDataObject dObj) 
    {
        dataObject = dObj;
    }

    /** for now, just pop a JOptionPane to prove this method is being called */
    public void open() 
    {
        TopManager tm = TopManager.getDefault();
        
        // before doing anything, switch to our new Workspace:
        WindowManager wm = tm.getWindowManager();
        Workspace tutorial = wm.findWorkspace("tutorial"); //NOI18N
        if (tutorial != null)
        {
            tutorial.activate();
        }
        
        // get the FileObject from the GazoogleDataObject reference
        // we saved in the constructor; this is the FileObject that
        // was associated with the OpenCookie (this support class)
        // when it was instantiated:
        FileObject fo = dataObject.getPrimaryFile();
        try
        {
            // get contents of the gazoogle:
            BufferedReader br = new BufferedReader(new InputStreamReader(fo.getInputStream()));
            String gazoogle = "";
            String nextLine = br.readLine();
            while (nextLine != null)
            {
                gazoogle += nextLine + "\n";
                nextLine = br.readLine();
            }
            NotifyDescriptor nd = new NotifyDescriptor.Message(gazoogle, NotifyDescriptor.INFORMATION_MESSAGE);
            tm.notify(nd);
        } catch (Exception e) {
            tm.notifyException(e);
        }
    }
    
}

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.