Revision: 6357 http://sourceforge.net/p/jump-pilot/code/6357 Author: ma15569 Date: 2020-07-16 11:17:33 +0000 (Thu, 16 Jul 2020) Log Message: ----------- Added capability to open Python console and tools from CAD toolbar: added Align and Distribute tools
Modified Paths: -------------- plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/EditToolboxCADPlugIn.java plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/utils/WorkbenchUtils.java Modified: plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/EditToolboxCADPlugIn.java =================================================================== --- plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/EditToolboxCADPlugIn.java 2020-07-16 11:11:52 UTC (rev 6356) +++ plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/EditToolboxCADPlugIn.java 2020-07-16 11:17:33 UTC (rev 6357) @@ -20,7 +20,6 @@ * @since OpenJUMP 1.10 */ import java.awt.BorderLayout; -import java.awt.GridBagConstraints; import java.awt.event.ActionEvent; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; @@ -47,6 +46,7 @@ import org.openjump.advancedtools.plugins.RegularPolygonPlugIn; import org.openjump.advancedtools.plugins.ShortenLinePlugIn; import org.openjump.advancedtools.plugins.SimpleLinePlugIn; +import org.openjump.advancedtools.tools.AddAreaTool; import org.openjump.advancedtools.tools.CopyDraggingTool; import org.openjump.advancedtools.tools.CuadraticBezierCurveTool; import org.openjump.advancedtools.tools.DrawConstrainedParallelogramTool; @@ -55,10 +55,13 @@ import org.openjump.advancedtools.tools.ParalelAuxiliarylLineTool; import org.openjump.advancedtools.tools.ParalelLineTool; import org.openjump.advancedtools.tools.PerpendicularLineTool; +import org.openjump.advancedtools.tools.RemoveAreaTool; import org.openjump.advancedtools.tools.RemoveSectionInLineTool; import org.openjump.advancedtools.tools.SelectEditingFeaturesTool; import org.openjump.advancedtools.tools.cogo.CommandLineStringFrame; import org.openjump.advancedtools.tools.cogo.DrawGeometryCommandsTool; +import org.openjump.advancedtools.utils.WorkbenchUtils; +import org.openjump.core.ui.swing.DetachableInternalFrame; import com.vividsolutions.jump.workbench.JUMPWorkbench; import com.vividsolutions.jump.workbench.WorkbenchContext; @@ -76,6 +79,8 @@ import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog; import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxPlugIn; + + /** * @author Giuseppe Aruta * @since OpenJUMP 1.10 @@ -83,277 +88,301 @@ public class EditToolboxCADPlugIn extends ToolboxPlugIn { - public static final String CAD = I18NPlug - .getI18N("org.openjump.core.ui.CAD"); - public static final String CAD_OPTIONS_PANE_NAME = I18NPlug - .getI18N("org.openjump.core.ui.config.CADToolsOptionsPanel"); + public static final String CAD = I18NPlug + .getI18N("org.openjump.core.ui.CAD"); + public static final String CAD_OPTIONS_PANE_NAME = I18NPlug + .getI18N("org.openjump.core.ui.config.CADToolsOptionsPanel"); - PlugInContext context; + PlugInContext context; - public static ImageIcon ICON = org.openjump.advancedtools.icon.IconLoader - .icon("cadTools.png"); + public static ImageIcon ICON = org.openjump.advancedtools.icon.IconLoader + .icon("cadTools.png"); - @Override - public void initialize(PlugInContext context) throws Exception { - WorkbenchContext workbenchContext = context.getWorkbenchContext(); - new FeatureInstaller(workbenchContext); + @Override + public void initialize(PlugInContext context) throws Exception { + WorkbenchContext workbenchContext = context.getWorkbenchContext(); + new FeatureInstaller(workbenchContext); - context.getWorkbenchFrame().getToolBar().addSpacer(); - context.getWorkbenchFrame() - .getToolBar() - .addPlugIn(ICON, this, createEnableCheck(workbenchContext), - context.getWorkbenchContext()); - context.getFeatureInstaller().addMainMenuPlugin(this, - new String[] { MenuNames.PLUGINS }, CAD, false, ICON, - createEnableCheck(workbenchContext)); - OptionsDialog.instance(context.getWorkbenchContext().getWorkbench()) - .addTab(CAD_OPTIONS_PANE_NAME, GUIUtil.toSmallIcon(ICON), - new CADToolsOptionsPanel()); + context.getWorkbenchFrame().getToolBar().addSpacer(); + context.getWorkbenchFrame() + .getToolBar() + .addPlugIn(ICON, this, createEnableCheck(workbenchContext), + context.getWorkbenchContext()); + context.getFeatureInstaller().addMainMenuPlugin(this, + new String[] { MenuNames.PLUGINS }, CAD, false, ICON, + createEnableCheck(workbenchContext)); + OptionsDialog.instance(context.getWorkbenchContext().getWorkbench()) + .addTab(CAD_OPTIONS_PANE_NAME, GUIUtil.toSmallIcon(ICON), + new CADToolsOptionsPanel()); - } + } - private MultiEnableCheck createEnableCheck( - final WorkbenchContext workbenchContext) { - EnableCheckFactory checkFactory = new EnableCheckFactory( - workbenchContext); + private MultiEnableCheck createEnableCheck( + final WorkbenchContext workbenchContext) { + EnableCheckFactory checkFactory = new EnableCheckFactory( + workbenchContext); - MultiEnableCheck mec = new MultiEnableCheck(); - mec.add(checkFactory.createWindowWithLayerViewPanelMustBeActiveCheck()); - mec.add(new EnableCheck() { - @Override - public String check(JComponent component) { - component.setToolTipText(getName()); - return null; - } - }); + MultiEnableCheck mec = new MultiEnableCheck(); + mec.add(checkFactory.createWindowWithLayerViewPanelMustBeActiveCheck()); + mec.add(new EnableCheck() { + @Override + public String check(JComponent component) { + component.setToolTipText(getName()); + return null; + } + }); - return mec; - } + return mec; + } - @Override - public String getName() { - return CAD; - } + @Override + public String getName() { + return CAD; + } + DetachableInternalFrame dFrame = new DetachableInternalFrame(); + @Override + protected void initializeToolbox(final ToolboxDialog toolbox) { + WorkbenchUtils.loadPython(toolbox); + toolbox.setTitle(CAD); + EnableCheckFactory checkFactory = new EnableCheckFactory( + toolbox.getContext()); - @Override - protected void initializeToolbox(final ToolboxDialog toolbox) { - toolbox.setTitle(CAD); - EnableCheckFactory checkFactory = new EnableCheckFactory( - toolbox.getContext()); + /** + * Selecting tools/plugins + */ + // Select feature in only one selected layer + SelectEditingFeaturesTool select = new SelectEditingFeaturesTool(); + toolbox.add(select); + // Unselect features + ClearLayerSelectionPlugIn clearSelectionPlugIn2 = new ClearLayerSelectionPlugIn(); + toolbox.addPlugIn(clearSelectionPlugIn2, null, + ClearLayerSelectionPlugIn.ICON); + /** + * Drawing tools/plugIns + * + * Create new geometries giving defined parameters + */ + // Draw simple line with commands + SimpleLinePlugIn sl = new SimpleLinePlugIn(); + toolbox.addPlugIn(sl, null, sl.getIcon()); - /** - * Selecting tools/plugins - */ - // Select feature in only one selected layer - SelectEditingFeaturesTool select = new SelectEditingFeaturesTool(); - toolbox.add(select); - // Unselect features - ClearLayerSelectionPlugIn clearSelectionPlugIn2 = new ClearLayerSelectionPlugIn(); - toolbox.addPlugIn(clearSelectionPlugIn2, null, - ClearLayerSelectionPlugIn.ICON); - /** - * Drawing tools/plugIns - * - * Create new geometries giving defined parameters - */ - // Draw simple line with commands - SimpleLinePlugIn sl = new SimpleLinePlugIn(); - toolbox.addPlugIn(sl, null, sl.getIcon()); + // Draw Bezier curve tool + toolbox.add(CuadraticBezierCurveTool.create(toolbox.getContext())); - // Draw Bezier curve tool - toolbox.add(CuadraticBezierCurveTool.create(toolbox.getContext())); + // Draw arc plugin + ArcPlugIn arc = new ArcPlugIn(); + toolbox.addPlugIn(arc, null, arc.getIcon()); - // Draw arc plugin - ArcPlugIn arc = new ArcPlugIn(); - toolbox.addPlugIn(arc, null, arc.getIcon()); + // Draw Constrained parallelogramme + toolbox.add(DrawConstrainedParallelogramTool.create(toolbox + .getContext())); - // Draw Constrained parallelogramme - toolbox.add(DrawConstrainedParallelogramTool.create(toolbox - .getContext())); + // Draw regular polygon + RegularPolygonPlugIn regular = new RegularPolygonPlugIn(); + toolbox.addPlugIn(regular, null, regular.getIcon()); + ; + // Draw circle plugin + CirclePlugIn circle = new CirclePlugIn(); + toolbox.addPlugIn(circle, null, circle.getIcon()); + toolbox.addToolBar(); + // Simple draw ellipse by dragging + toolbox.add(EllipseByDraggingTool.create(toolbox.getContext())); - // Draw regular polygon - RegularPolygonPlugIn regular = new RegularPolygonPlugIn(); - toolbox.addPlugIn(regular, null, regular.getIcon()); - ; - // Draw circle plugin - CirclePlugIn circle = new CirclePlugIn(); - toolbox.addPlugIn(circle, null, circle.getIcon()); - toolbox.addToolBar(); - // Simple draw ellipse by dragging - toolbox.add(EllipseByDraggingTool.create(toolbox.getContext())); + // Draw with commands + DelegatingTool delLineCommandTool = (DelegatingTool) DrawGeometryCommandsTool + .create(toolbox.getContext()); + WorkbenchToolBar.ToolConfig toolConfig = toolbox + .add(delLineCommandTool); + final CommandLineStringFrame frame = new CommandLineStringFrame( + (DrawGeometryCommandsTool) delLineCommandTool.getDelegate()); + final JToggleButton cogoCommandButton = toolConfig.getButton(); + cogoCommandButton.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent e) { + super.mouseClicked(e); + frame.setVisible(cogoCommandButton.isSelected()); + } + }); + cogoCommandButton.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + frame.setVisible(cogoCommandButton.isSelected()); + } + }); + // cogoCommandButton.addChangeListener(new ChangeListener() { + // @Override + // public void stateChanged(ChangeEvent e) { + // frame.setVisible(cogoCommandButton.isSelected()); + // } + // }); - // Draw with commands - DelegatingTool delLineCommandTool = (DelegatingTool) DrawGeometryCommandsTool - .create(toolbox.getContext()); - WorkbenchToolBar.ToolConfig toolConfig = toolbox - .add(delLineCommandTool); - final CommandLineStringFrame frame = new CommandLineStringFrame( - (DrawGeometryCommandsTool) delLineCommandTool.getDelegate()); - final JToggleButton cogoCommandButton = toolConfig.getButton(); - cogoCommandButton.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent e) { - super.mouseClicked(e); - frame.setVisible(cogoCommandButton.isSelected()); - } - }); - cogoCommandButton.addItemListener(new ItemListener() { - @Override - public void itemStateChanged(ItemEvent e) { - frame.setVisible(cogoCommandButton.isSelected()); - } - }); - // cogoCommandButton.addChangeListener(new ChangeListener() { - // @Override - // public void stateChanged(ChangeEvent e) { - // frame.setVisible(cogoCommandButton.isSelected()); - // } - // }); + /** + * Generate tools/plugins + * + * Generate new geometries from selected one. Selected geometries are + * not deleted + */ + // Draw parallel line to a selected geometry + ParalelLineTool paralel = new ParalelLineTool(checkFactory); + toolbox.add(paralel); - /** - * Generate tools/plugins - * - * Generate new geometries from selected one. Selected geometries are - * not deleted - */ - // Draw parallel line to a selected geometry - ParalelLineTool paralel = new ParalelLineTool(checkFactory); - toolbox.add(paralel); + // Draw a parallel auxiliary line to a selected geometry + ParalelAuxiliarylLineTool auxiliaryParalel = new ParalelAuxiliarylLineTool( + checkFactory); + toolbox.add(auxiliaryParalel); - // Draw a parallel auxiliary line to a selected geometry - ParalelAuxiliarylLineTool auxiliaryParalel = new ParalelAuxiliarylLineTool( - checkFactory); - toolbox.add(auxiliaryParalel); + // Draw a perpendicular line to a selected geometry + PerpendicularLineTool perpendicular = new PerpendicularLineTool( + checkFactory); + toolbox.add(perpendicular); - // Draw a perpendicular line to a selected geometry - PerpendicularLineTool perpendicular = new PerpendicularLineTool( - checkFactory); - toolbox.add(perpendicular); + // Clone selected geometries + CopyDraggingTool copy = new CopyDraggingTool(checkFactory); + toolbox.add(copy); - // Clone selected geometries - CopyDraggingTool copy = new CopyDraggingTool(checkFactory); - toolbox.add(copy); + // Axial symmetry of selected geometries + MirrorPlugin mirror = new MirrorPlugin(); + toolbox.addPlugIn(mirror, null, mirror.getIcon()); - // Axial symmetry of selected geometries - MirrorPlugin mirror = new MirrorPlugin(); - toolbox.addPlugIn(mirror, null, mirror.getIcon()); + // Extend a lineString + ExtendLinePlugIn extendLinePlugIn = new ExtendLinePlugIn(); + toolbox.addPlugIn(extendLinePlugIn, null, extendLinePlugIn.getIcon()); + toolbox.addToolBar(); + // Shorten a lineString + ShortenLinePlugIn shortenLinePlugIn = new ShortenLinePlugIn(); + toolbox.addPlugIn(shortenLinePlugIn, null, shortenLinePlugIn.getIcon()); - // Extend a lineString - ExtendLinePlugIn extendLinePlugIn = new ExtendLinePlugIn(); - toolbox.addPlugIn(extendLinePlugIn, null, extendLinePlugIn.getIcon()); - toolbox.addToolBar(); - // Shorten a lineString - ShortenLinePlugIn shortenLinePlugIn = new ShortenLinePlugIn(); - toolbox.addPlugIn(shortenLinePlugIn, null, shortenLinePlugIn.getIcon()); + /** + * Modify tools/plugins + * + * Modify selected geometries. + */ - /** - * Modify tools/plugins - * - * Modify selected geometries. - */ + // Extend two convergent lineStrings and cut in the point they touch + toolbox.add(ExtendLinesAndCutWhereTheyTouchTool.create(toolbox + .getContext())); - // Extend two convergent lineStrings and cut in the point they touch - toolbox.add(ExtendLinesAndCutWhereTheyTouchTool.create(toolbox - .getContext())); + // Put vertex on crossing point of two lineStrings + PutVertexInCrossingLinesPlugIn putVertex = new PutVertexInCrossingLinesPlugIn(); + toolbox.addPlugIn(putVertex, null, putVertex.getIcon()); - // Put vertex on crossing point of two lineStrings - PutVertexInCrossingLinesPlugIn putVertex = new PutVertexInCrossingLinesPlugIn(); - toolbox.addPlugIn(putVertex, null, putVertex.getIcon()); + // Remove a section of a selected lineString + toolbox.add(QuasimodeTool + .createWithDefaults(new RemoveSectionInLineTool(checkFactory))); - // Remove a section of a selected lineString - toolbox.add(QuasimodeTool - .createWithDefaults(new RemoveSectionInLineTool(checkFactory))); - // toolbox.addToolBar(); - // toolbox.add(QuasimodeTool.createWithDefaults(new - // DrawOneVectorTool())); + AddAreaTool addAreaTool = new AddAreaTool(); + toolbox.add(addAreaTool); - /* - * The following working tools/plugins are deactivated as either always - * they have a correspondence in OpenJUMP or they are used for testing - * reasons - */ + RemoveAreaTool removeAreaTool = new RemoveAreaTool(); + toolbox.add(removeAreaTool); - // Rotate features by dragging - // toolbox.add(GeneralUtils.addStandardQuasimodes(new - // RotateTool(checkFactory))); - // Rotate features using a dilaog - // toolbox.add(GeneralUtils.addStandardQuasimodes(new - // RotateDialogTool(checkFactory))); - // ForceQuitPlugIn quit = new ForceQuitPlugIn(); - // toolbox.addPlugIn(quit, null, quit.getIcon()); + // toolbox.addToolBar(); + // toolbox.add(QuasimodeTool.createWithDefaults(new + // DrawOneVectorTool())); - /** - * Add lower panel - */ - // JPanel pan = new JPanel(); - // toolbox.getCenterPanel().add(pan, GridBagConstraints.RELATIVE); - toolbox.getCenterPanel().add(FullPanel(toolbox), - GridBagConstraints.RELATIVE); + /* + * The following working tools/plugins are deactivated as either always + * they have a correspondence in OpenJUMP or they are used for testing + * reasons + */ - toolbox.finishAddingComponents(); - toolbox.setIconImage(org.openjump.advancedtools.icon.IconLoader - .image("cadTools.png")); - toolbox.setResizable(false); - toolbox.setInitialLocation(new GUIUtil.Location(20, true, 20, true)); - toolbox.validate(); + // Rotate features by dragging + // toolbox.add(GeneralUtils.addStandardQuasimodes(new + // RotateTool(checkFactory))); + // Rotate features using a dilaog + // toolbox.add(GeneralUtils.addStandardQuasimodes(new + // RotateDialogTool(checkFactory))); - } + // ForceQuitPlugIn quit = new ForceQuitPlugIn(); + // toolbox.addPlugIn(quit, null, quit.getIcon()); - private JPanel optionPanel(final ToolboxDialog toolbox) { + /** + * Add lower panel + */ + // JPanel pan = new JPanel(); + // toolbox.getCenterPanel().add(pan, GridBagConstraints.RELATIVE); + toolbox.getCenterPanel().add(FullPanel(toolbox), + BorderLayout.NORTH); + /* JMenuItem console = new JMenuItem("Open Python console"); - JPanel optionPanel = new JPanel(); - optionPanel.setLayout(new BorderLayout()); - JPanel option = new JPanel(); - JButton optionsButton = new JButton(CAD_OPTIONS_PANE_NAME + "..."); + toolbox.getJMenuBar().getMenu(0).add(console); + console.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + dFrame.add(WorkbenchUtils.console); + WorkbenchFrame wFrame = JUMPWorkbench.getInstance().getFrame(); + dFrame.setPreferredSize(new Dimension(450, 120)); + wFrame + .addInternalFrame(dFrame); - optionsButton.addActionListener(new java.awt.event.ActionListener() { - @Override - public void actionPerformed(ActionEvent e) { - OptionsDialog optionsDialog = OptionsDialog - .instance(JUMPWorkbench.getInstance()); - JTabbedPane tabbedPane = optionsDialog.getTabbedPane(); - for (int i = 0; i < tabbedPane.getTabCount(); i++) { - if (tabbedPane.getComponentAt(i) instanceof CADToolsOptionsPanel) { - tabbedPane.setSelectedIndex(i); - break; - } - } - GUIUtil.centreOnWindow(optionsDialog); - optionsDialog.setVisible(true); - } - }); - optionsButton - .setIcon(com.vividsolutions.jump.workbench.ui.images.IconLoader - .icon("fugue/wrench-screwdriver.png")); - option.add(optionsButton); - optionPanel.add(option, BorderLayout.SOUTH); - return optionPanel; - } + } + });*/ - ; + toolbox.finishAddingComponents(); + toolbox.setIconImage(org.openjump.advancedtools.icon.IconLoader + .image("cadTools.png")); + toolbox.setResizable(false); + toolbox.setInitialLocation(new GUIUtil.Location(20, true, 20, true)); + toolbox.validate(); - JPanel fullPanel = new JPanel(); - TextPanel txtpan = new TextPanel(); - BlockPanel pan = new BlockPanel(); + } - /* - * Blocks, Annotation and Option panels resize together - */ - private JPanel FullPanel(final ToolboxDialog toolbox) { + private JPanel optionPanel(final ToolboxDialog toolbox) { - fullPanel.setLayout(new BorderLayout()); + JPanel optionPanel = new JPanel(); + optionPanel.setLayout(new BorderLayout()); + JPanel option = new JPanel(); + JButton optionsButton = new JButton(CAD_OPTIONS_PANE_NAME + "..."); - fullPanel.add( - txtpan.panel_text(toolbox.getContext().createPlugInContext()), - BorderLayout.CENTER); - fullPanel.add( - pan.panel_blocks(toolbox.getContext().createPlugInContext()), - BorderLayout.NORTH); - fullPanel.add(optionPanel(toolbox), BorderLayout.SOUTH); + optionsButton.addActionListener(new java.awt.event.ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + OptionsDialog optionsDialog = OptionsDialog + .instance(JUMPWorkbench.getInstance()); + JTabbedPane tabbedPane = optionsDialog.getTabbedPane(); + for (int i = 0; i < tabbedPane.getTabCount(); i++) { + if (tabbedPane.getComponentAt(i) instanceof CADToolsOptionsPanel) { + tabbedPane.setSelectedIndex(i); + break; + } + } + GUIUtil.centreOnWindow(optionsDialog); + optionsDialog.setVisible(true); + } + }); + optionsButton + .setIcon(com.vividsolutions.jump.workbench.ui.images.IconLoader + .icon("fugue/wrench-screwdriver.png")); + option.add(optionsButton); + optionPanel.add(option, BorderLayout.SOUTH); - return fullPanel; - } + return optionPanel; + } + ; + + JPanel fullPanel = new JPanel(); + TextPanel txtpan = new TextPanel(); + BlockPanel pan = new BlockPanel(); + + /* + * Blocks, Annotation and Option panels resize together + */ + private JPanel FullPanel(final ToolboxDialog toolbox) { + + fullPanel.setLayout(new BorderLayout()); + + fullPanel.add( + txtpan.panel_text(toolbox.getContext().createPlugInContext()), + BorderLayout.CENTER); + fullPanel.add( + pan.panel_blocks(toolbox.getContext().createPlugInContext()), + BorderLayout.NORTH); + fullPanel.add(optionPanel(toolbox), BorderLayout.SOUTH); + + return fullPanel; + } + } Modified: plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/utils/WorkbenchUtils.java =================================================================== --- plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/utils/WorkbenchUtils.java 2020-07-16 11:11:52 UTC (rev 6356) +++ plug-ins/CADExtension/trunk/src/org/openjump/advancedtools/utils/WorkbenchUtils.java 2020-07-16 11:17:33 UTC (rev 6357) @@ -1,5 +1,5 @@ /* - * Kosmo - Sistema Abierto de Informaci\xF3n Geogr\xE1fica + * Kosmo - Sistema Abierto de Informaci�n Geogr�fica * Kosmo - Open Geographical Information System * * http://www.saig.es @@ -21,16 +21,16 @@ * * For more information, contact: * - * Sistemas Abiertos de Informaci\xF3n Geogr\xE1fica, S.L. - * Avnda. Rep\xFAblica Argentina, 28 - * Edificio Domocenter Planta 2\xAA Oficina 7 + * Sistemas Abiertos de Informaci�n Geogr�fica, S.L. + * Avnda. Rep�blica Argentina, 28 + * Edificio Domocenter Planta 2� Oficina 7 * C.P.: 41930 - Bormujos (Sevilla) - * Espa\xF1a / Spain + * Espa�a / Spain * - * Tel\xE9fono / Phone Number + * Tel�fono / Phone Number * +34 954 788876 * - * Correo electr\xF3nico / Email + * Correo electr�nico / Email * i...@saig.es * */ @@ -44,17 +44,27 @@ import java.awt.Toolkit; import java.awt.geom.NoninvertibleTransformException; import java.awt.geom.Point2D; +import java.io.File; import java.text.NumberFormat; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Locale; +import java.util.Properties; +import javax.swing.ImageIcon; import javax.swing.JComponent; import javax.swing.JFormattedTextField; +import javax.swing.JMenu; +import javax.swing.JMenuBar; import org.apache.log4j.Logger; import org.openjump.advancedtools.language.I18NPlug; +import org.openjump.core.ui.plugin.customize.PythonToolsPlugIn; +import org.openjump.util.python.JUMP_GIS_Framework; +import org.openjump.util.python.ModifyGeometry; +import org.openjump.util.python.PythonInteractiveInterpreter; +import org.python.core.PySystemState; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Envelope; @@ -79,6 +89,7 @@ import com.vividsolutions.jump.workbench.ui.EditOptionsPanel; import com.vividsolutions.jump.workbench.ui.LayerNamePanel; import com.vividsolutions.jump.workbench.ui.LayerViewPanel; +import com.vividsolutions.jump.workbench.ui.MenuNames; import com.vividsolutions.jump.workbench.ui.SelectionManager; import com.vividsolutions.jump.workbench.ui.SelectionManagerProxy; import com.vividsolutions.jump.workbench.ui.TaskFrame; @@ -93,10 +104,13 @@ import com.vividsolutions.jump.workbench.ui.cursortool.SelectFeaturesTool; import com.vividsolutions.jump.workbench.ui.plugin.AddNewLayerPlugIn; import com.vividsolutions.jump.workbench.ui.plugin.PersistentBlackboardPlugIn; +import com.vividsolutions.jump.workbench.ui.toolbox.ToolboxDialog; import com.vividsolutions.jump.workbench.ui.zoom.PanTool; import com.vividsolutions.jump.workbench.ui.zoom.ZoomToSelectedItemsPlugIn; import com.vividsolutions.jump.workbench.ui.zoom.ZoomTool; +import bsh.util.JConsole; + /** * <p> * Helps to manage OpenJUMP Desktop actions @@ -289,7 +303,7 @@ * * @return List<Layer> de entre los layerables seleccioandos devuelve los * que sean de tipo Layer. Nunca devuelve null, a lo sumo una lista - * vac\xEDa. + * vac�a. */ public static List<Layer> getSelectedLayers() { Layerable[] selectedLayers = getSelectedLayerables(); @@ -1141,4 +1155,67 @@ modelCoordinate.y)); } + + + static WorkbenchContext context =JUMPWorkbench.getInstance().getContext(); + + public static JConsole console = new JConsole(); + +/** + * This code allows to load Python console and tools into a generic ToolboxDialog + * @param toolbox + */ + public static void loadPython(ToolboxDialog toolbox){ + + console.setPreferredSize(new Dimension(450, 120)); + PythonToolsPlugIn pPlugIn = new PythonToolsPlugIn(); + console + .println(new ImageIcon(pPlugIn.getClass().getResource("jython_small_c.png"))); + // toolbox.getCenterPanel().add(console, BorderLayout.CENTER); + // toolbox.setTitle("Jython"); + // setup the interpreter + ClassLoader classLoader = context.getWorkbench() + .getPlugInManager().getClassLoader(); + Properties preProperties = new Properties(System.getProperties()); + String homepath = preProperties.getProperty("user.home"); + + String sep = File.separator; + // -- [sstein] - old */ + /* + * String WORKING_DIR = empty.getAbsoluteFile().getParent() + sep; String + * jarpathX = new String(WORKING_DIR + "lib"); String startuppathX = new + * String(WORKING_DIR + "lib" + sep + "ext" + sep + "jython" + sep); + */ + // -- [sstein] - new + File plugInDirectory = context.getWorkbench() + .getPlugInManager().getPlugInDirectory(); + String jarpath = plugInDirectory.getPath(); + String startuppath = plugInDirectory.getPath() + sep + "jython" + sep; + + Properties postProperties = new Properties(); + postProperties.put("python.home", homepath); + postProperties.put("python.path", startuppath); + PySystemState.initialize(preProperties, postProperties, + new String[] { "" }, classLoader); + String startupfile = startuppath + "CADstartup.py"; + PySystemState.add_extdir(jarpath); + PySystemState.add_extdir(jarpath + sep + "ext"); + PythonInteractiveInterpreter interpreter = new PythonInteractiveInterpreter( + console); + interpreter.set("wc", context); + interpreter.set("toolbox", toolbox); + interpreter.set("startuppath", startuppath); + interpreter.exec("import sys"); + JUMP_GIS_Framework.setWorkbenchContext(context); + ModifyGeometry.setWorkbenchContext(context); + toolbox.addToolBar(); // add a new tool bar to the console + JMenuBar jMenuBar = new JMenuBar(); + jMenuBar.add(new JMenu(MenuNames.TOOLS)); + toolbox.setJMenuBar(jMenuBar); + if (new File(startupfile).exists()) + interpreter.execfile(startupfile); + new Thread(interpreter).start(); + } + + } _______________________________________________ Jump-pilot-devel mailing list Jump-pilot-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel