Forgot to attach the source code.
Sorry bout that.
SS
On Wed, Jun 25, 2008 at 12:07 PM, Sunburned Surveyor
<[EMAIL PROTECTED]> wrote:
> My bad.
>
> The plug-in JAR can be downloaded here:
>
> http://www.redefinedhorizons.com/shared_files/
>
> The source code is attached.
>
> Please note that I'm only detailing the plug-in source code file in
> this first example, not the extension source code. I'll tackle
> extensions in a subsequent section. I only wrote the extension to see
> if I could get the stupid plug-in to work. :]
>
> The Sunburned Surveyor
>
> P.S. - I put the plug-in command under a top-level SurveyOS menu.
> However, I think it best to keep the number of top-level menus to a
> minimum. I was thinking of moving this plug-in under Layers>Layer
> Utilities.
>
> Would anyone have a problem with that menu structure? (I'm not talking
> about putting this in the core, just about where to place the plug-in
> command when someone chooses to install the plug-in JAR.)
>
> On Tue, Jun 24, 2008 at 7:34 PM, Stefan Steiniger <[EMAIL PROTECTED]> wrote:
>> Hei Sunburned,
>>
>> did you forgot an attachement or link?
>>
>> stefan
>>
>> Sunburned Surveyor schrieb:
>>> I've finished my first example for the plug-in programmer's guide. In
>>> this example the user selects a text file and the plug-in writes the
>>> feature count of each layer to the file. I've tried to make the
>>> plug-in user friendly without being to complex from a programmer's
>>> prespective. However, I wanted to do a little more than the typical
>>> "hello world" example, because I know I had trouble figuring out how
>>> to organize the actions of my own plug-in attempts.
>>>
>>> At any rate, if you would be willing to do a review of the source code
>>> before I include it in the guide I would be cery grateful. I want to
>>> make sure I don't do anything careless in the code of my first example
>>> for the guide.
>>>
>>> If you are a user that is interested in using the plug-in, let me
>>> know. I didn't think it would be that practical, so I didn't put the
>>> plug-in JAR online, but it is "working" code if someone thinks they
>>> would use it.
>>>
>>> The Sunburned Surveyor
>>>
>>> P.S. - I think most of my code examples in the guide will deal with
>>> Layers. This will allow for some consistency and will keep the reader
>>> from drowning in the OpenJUMP API.
>>>
>>> -------------------------------------------------------------------------
>>> Check out the new SourceForge.net Marketplace.
>>> It's the best place to buy or sell services for
>>> just about anything Open Source.
>>> http://sourceforge.net/services/buy/index.php
>>> _______________________________________________
>>> Jump-pilot-devel mailing list
>>> Jump-pilot-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>>
>>>
>>
>> -------------------------------------------------------------------------
>> Check out the new SourceForge.net Marketplace.
>> It's the best place to buy or sell services for
>> just about anything Open Source.
>> http://sourceforge.net/services/buy/index.php
>> _______________________________________________
>> Jump-pilot-devel mailing list
>> Jump-pilot-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel
>>
>
/*
* Project Name: OJ Plug-In Programmer Guide Examples
* Original Organization Name: The SurveyOs Project
* Original Programmer Name: The Sunburned Surveyor
* Current Maintainer Name: The SurveyOS Project
* Current Maintainer Contact Information
* E-Mail Address: [EMAIL PROTECTED]
* Copyright Holder: The SurveyOS Project
* Date Last Modified: June 20, 2008
* Current Version Number: 00.00.10
* IDE Name: Eclipse
* IDE Version: 3.3.2
* Type: Java Class
*/
package net.surveyos.sourceforge.openjump.plugins.layerutils;
import java.io.*;
import java.util.*;
import javax.swing.JFileChooser;
import com.vividsolutions.jump.feature.*;
import com.vividsolutions.jump.workbench.model.*;
import com.vividsolutions.jump.workbench.plugin.*;
import com.vividsolutions.jump.workbench.ui.WorkbenchFrame;
/**
* An OpenJUMP plug-in that writes a text file containing the name of each
* layer in a task and the number of features in that layer (feature count).
* <br>
* <br>
* A JFileChooser dialog is presented to the user that allows them to select
* or create the text file that the information will be written to.
* <br>
* <br>
* This plug-in was designed as part of the OpenJUMP Plug-In
* Programmer's Guide.
* @author lblake
*
*/
public final class CountFeaturesInAllLayersPlugIn implements PlugIn
{
// Stores the output file that will be written to by the performAction
// method of this plug-in. This file will be chosen by the user in the
// JFileChooser displayed by the execute method of this class.
private File outputFile;
/**
* Writes the name of each layer and the number of features in each
* layer to the output file selected by the user. This method could
* throw an exception if it encounters i/o problems when writing to
* the output file.
*/
public boolean execute(PlugInContext argPlugInContext) throws Exception
{
// Display the dialog that allows the user to choose the output
file.
// IF the user selects a file the showGuiForOutpoutFile method
// will automatically call the performAction method which
performs
// the real action of this plug-in.
this.showGUIForOutputFile(argPlugInContext);
return true;
}
@Override
public String getName()
{
return "Count Features In All Layers";
}
@Override
public void initialize(PlugInContext arg0) throws Exception
{
// No initialization is performed by this plug-in.
}
/**
* Displays a JFileChooser dialog that allows the user to select the
* output file the performAction method wil write to.
*/
private void showGUIForOutputFile(PlugInContext argPlugInContext) throws
IOException
{
// Create and set-up the JFileChooser that will be displayed to
the
// user.
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
// Get the WorkbenchFrame from the PlugInContext passed to this
plug
// -in. This will be the parent component needed to display the
// JFileChooser dialog.
WorkbenchFrame frame = argPlugInContext.getWorkbenchFrame();
// Show the dialog.
int returnValue = chooser.showOpenDialog(frame);
// See if the user selected a file. If they did set the output
file
// that will be used by the performAction method.
if(returnValue == JFileChooser.APPROVE_OPTION)
{
this.outputFile = chooser.getSelectedFile();
// We only want to perform the action if a file was
chosen.
this.performAction(argPlugInContext);
}
// If the user did not select a file nothing will happen. We
could
// add some code here to warn the user that a file was not
selected
// and that the output file was not written.
}
/**
* Writes the feature count of each layer in a Task to the text file
* selected by the user. The name of the layer is also written to the
file,
* and each entry in the file is separated by blank lines.
* <br>
* <br>
* This method performs the main action of the plug-in. Modifications
* to the format of the output file would need to be made within this
* method.
*/
private void performAction(PlugInContext argPlugInContext) throws
IOException
{
// Obtain a list of all the layers in the current task.
LayerManager manager = argPlugInContext.getLayerManager();
List<Layer> layers = manager.getLayers();
Iterator<Layer> goOverEach = layers.iterator();
// Get a writer to the text file that we will write the
information
// to.
BufferedWriter writer = this.getBufferedWriter();
// Iterate, or go over each layer in the task, obtain the
number of
// features it contains, and write this information, along with
the
// layer name, to the output file.
while(goOverEach.hasNext() == true)
{
Layer currentLayer = goOverEach.next();
String currentLayerName = currentLayer.getName();
FeatureCollection wrapper = currentLayer
.getFeatureCollectionWrapper();
int numberOfFeatures = wrapper.size();
String numberOfFeaturesAsString = Integer
.toString(numberOfFeatures);
writer.write("Layer Name: " + currentLayerName);
writer.newLine();
writer.write("Number of Features: " +
numberOfFeaturesAsString);
writer.newLine();
writer.newLine();
}
// Perform clean-up by flushing and closing the file writer.
writer.flush();
writer.close();
//Display a message to let the user now the operation was a
success.
this.tellUserOfSuccess(argPlugInContext);
}
/**
* Prepares a BufferedWriter object that can be used by the
* execute method of this plug-in to write the layer names and
* feature counts.
*/
private BufferedWriter getBufferedWriter() throws IOException
{
// Make sure the file exists. If it doesn't, then create it.
if(this.outputFile.exists() == false)
{
this.outputFile.createNewFile();
}
FileWriter out = new FileWriter(this.outputFile);
BufferedWriter writer = new BufferedWriter(out);
return writer;
}
/** Displays a message to the user indicating that the plug-in operation
* was executed successfully.
*/
private void tellUserOfSuccess(PlugInContext argPlugInContext)
{
WorkbenchFrame frame = argPlugInContext.getWorkbenchFrame();
frame.warnUser("The feature count of each layer was written to"
+
" the output file you selected.");
}
}
/*
* Project Name: OJ Plug-In Programmer Guide Examples
* Original Organization Name: The SurveyOs Project
* Original Programmer Name: The Sunburned Surveyor
* Current Maintainer Name: The SurveyOS Project
* Current Maintainer Contact Information
* E-Mail Address: The Sunburned Surveyor
* Copyright Holder: The SurveyOS Project
* Date Last Modified: Jun 20, 2008
* Current Version Number: 00.00.01
* IDE Name: Eclipse
* IDE Version: 3.2.1
* Type: Java Class
*/
package net.surveyos.sourceforge.openjump.plugins.layerutils;
import com.vividsolutions.jump.workbench.WorkbenchContext;
import com.vividsolutions.jump.workbench.plugin.*;
import com.vividsolutions.jump.workbench.ui.plugin.FeatureInstaller;
/**
* Loads the plug-ins that implement the layer utilities for OpenJUMP created
* as part of the SurveyOS Project.
*/
public final class SurveyOSLayerUtilsExtension extends Extension
{
@Override
public void configure(PlugInContext argPlugInContext) throws Exception
{
// Create and initialize the plug-ins installed by this
Extension.
CountFeaturesInAllLayersPlugIn plugIn = new
CountFeaturesInAllLayersPlugIn();
plugIn.initialize(argPlugInContext);
// Add the plug-in to the main menu bar in OpenJUMP.
FeatureInstaller installer =
argPlugInContext.getFeatureInstaller();
String[] menuPath = new String[2];
menuPath[0] = "SurveyOS";
menuPath[1] = "Layers";
WorkbenchContext workbenchContext = argPlugInContext
.getWorkbenchContext();
EnableCheckFactory factory = new
EnableCheckFactory(workbenchContext);
EnableCheck check =
factory.createAtLeastNLayersMustExistCheck(1);
installer.addMainMenuItem(plugIn, menuPath,
"Count Features In All Layers", false, null,
check);
}
}
-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel