Search in sources :

Example 1 with ToolButton

use of com.sldeditor.tool.ToolButton in project sldeditor by robward-scisys.

the class MapBoxToolTest method testSetSelectedItems.

/**
 * Test method for
 * {@link com.sldeditor.tool.mapbox.MapBoxTool#setSelectedItems(java.util.List, java.util.List)}.
 */
@Test
public void testSetSelectedItems() {
    MapBoxTool tool = new MapBoxTool();
    JPanel panel = tool.getPanel();
    ToolButton toSLD = null;
    for (Component c : panel.getComponents()) {
        if (c instanceof ToolButton) {
            ToolButton button = (ToolButton) c;
            String toolTipText = button.getToolTipText();
            if (toolTipText.compareTo(Localisation.getString(MapBoxTool.class, "MapBoxTool.exportToSLD")) == 0) {
                toSLD = button;
            }
        }
    }
    File testFile1 = null;
    File testFile3 = null;
    try {
        testFile1 = File.createTempFile("invalid", ".tst");
        testFile3 = File.createTempFile("valid", ".json");
    } catch (IOException e1) {
        e1.printStackTrace();
    }
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    tool.setSelectedItems(null, null);
    // Invalid file
    List<SLDDataInterface> sldDataList = new ArrayList<SLDDataInterface>();
    SLDData sldData1 = new SLDData(null, null);
    sldData1.setSLDFile(testFile1);
    sldDataList.add(sldData1);
    tool.setSelectedItems(null, sldDataList);
    // Should both be disabled
    assertFalse(toSLD.isEnabled());
    /*
         * // Try with valid mapbox file sldDataList = new ArrayList<SLDDataInterface>(); SLDData
         * sldData3 = getSLDDataFile("/point/mapbox/circleStyleTest.json");
         * sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList);
         * 
         * // SLD should be enabled assertTrue(toSLD.isEnabled()); toSLD.doClick();
         * 
         * // Try with valid sld files sldDataList = new ArrayList<SLDDataInterface>();
         * sldDataList.add(sldData3); tool.setSelectedItems(null, sldDataList);
         * 
         * // SLD should be enabled assertTrue(toSLD.isEnabled());
         */
    testFile1.delete();
    testFile3.delete();
// tidyUpTempFiles(sldData3.getSLDFile());
}
Also used : JPanel(javax.swing.JPanel) SLDData(com.sldeditor.common.data.SLDData) ToolButton(com.sldeditor.tool.ToolButton) SLDDataInterface(com.sldeditor.common.SLDDataInterface) MapBoxTool(com.sldeditor.tool.mapbox.MapBoxTool) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Component(java.awt.Component) File(java.io.File) Test(org.junit.Test)

Example 2 with ToolButton

use of com.sldeditor.tool.ToolButton in project sldeditor by robward-scisys.

the class DatabaseConnectionTool method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    panel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) panel.getLayout();
    flowLayout.setVgap(0);
    flowLayout.setHgap(0);
    panel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(DatabaseConnectionTool.class, "DatabaseConnectionTool.title")));
    // 
    // Connect button
    // 
    connectButton = new ToolButton(Localisation.getString(DatabaseConnectionTool.class, "DatabaseConnectionTool.connect"), "tool/connect.png");
    connectButton.setEnabled(true);
    connectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            connect();
        }
    });
    panel.add(connectButton);
    // 
    // Disconnect button
    // 
    disconnectButton = new ToolButton(Localisation.getString(DatabaseConnectionTool.class, "DatabaseConnectionTool.disconnect"), "tool/disconnect.png");
    disconnectButton.setEnabled(false);
    disconnectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            disconnect();
        }
    });
    panel.add(disconnectButton);
    panel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionListener(java.awt.event.ActionListener) ToolButton(com.sldeditor.tool.ToolButton) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension)

Example 3 with ToolButton

use of com.sldeditor.tool.ToolButton in project sldeditor by robward-scisys.

the class GeoServerLayerUpdateTool method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    panel = new JPanel();
    panel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(GeoServerLayerUpdateTool.class, "GeoServerLayerUpdateTool.title")));
    button = new ToolButton(Localisation.getString(GeoServerLayerUpdateTool.class, "GeoServerLayerUpdateTool.layer"), "tool/layerupdate.png");
    button.setEnabled(true);
    button.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ConfigureLayerStyleDialog dlg = new ConfigureLayerStyleDialog();
            Map<String, List<StyleWrapper>> styleMap = geoServerLayerUpdate.getStyleMap(connection);
            if (dlg.populate(styleMap, layerList)) {
                geoServerLayerUpdate.updateLayerStyle(dlg.getUpdatedLayerStyles());
            }
        }
    });
    panel.add(button);
    panel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
Also used : JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) ToolButton(com.sldeditor.tool.ToolButton) StyleWrapper(com.sldeditor.common.data.StyleWrapper) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension) Map(java.util.Map)

Example 4 with ToolButton

use of com.sldeditor.tool.ToolButton in project sldeditor by robward-scisys.

the class ScaleTool method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    scaleGroupPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) scaleGroupPanel.getLayout();
    flowLayout.setVgap(0);
    flowLayout.setHgap(0);
    scaleGroupPanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(ScaleTool.class, "ScaleTool.scale")));
    scaleButton = new ToolButton(Localisation.getString(ScaleTool.class, "ScaleTool.scale"), "tool/scaletool.png");
    scaleGroupPanel.add(scaleButton);
    scaleButton.setEnabled(false);
    scaleButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            ScaleToolPanel scalePanel = new ScaleToolPanel(application);
            scalePanel.populate(sldDataList);
            scalePanel.setVisible(true);
        }
    });
    scaleGroupPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionListener(java.awt.event.ActionListener) ToolButton(com.sldeditor.tool.ToolButton) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension)

Example 5 with ToolButton

use of com.sldeditor.tool.ToolButton in project sldeditor by robward-scisys.

the class RasterTool method createUI.

/**
 * Creates the ui.
 */
private void createUI() {
    rasterPanel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) rasterPanel.getLayout();
    flowLayout.setVgap(0);
    flowLayout.setHgap(0);
    rasterPanel.setBorder(BorderFactory.createTitledBorder(Localisation.getString(RasterTool.class, "RasterTool.title")));
    // 
    // Import raster
    // 
    importRasterButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.import"), "tool/importraster.png");
    rasterPanel.add(importRasterButton);
    importRasterButton.setEnabled(false);
    importRasterButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
                if (sldEditorInterface != null) {
                    FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
                    File rasterFile = fileTreeNode.getFile();
                    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.createSymbol"), rasterFile.getAbsolutePath()));
                    SLDDataInterface sldData = rasterReader.createRasterSLDData(rasterFile);
                    // Raster file
                    DataSourcePropertiesInterface dsProperties = SLDEditorFile.getInstance().getDataSource();
                    DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
                    dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFile.getAbsolutePath()));
                    SLDEditorFile.getInstance().setSLDData(sldData);
                    SLDEditorFile.getInstance().setDataSource(dsProperties);
                    // Clear the data change flag
                    SLDEditorFile.getInstance().fileOpenedSaved();
                    // Load sld
                    List<SLDDataInterface> sldFilesToLoad = new ArrayList<SLDDataInterface>();
                    sldFilesToLoad.add(sldData);
                    SelectedFiles selectedFiles = new SelectedFiles();
                    selectedFiles.setSldData(sldFilesToLoad);
                    selectedFiles.setFolderName(rasterFile.getParent());
                    LoadSLDInterface loadSLD = sldEditorInterface.getLoadSLDInterface();
                    loadSLD.loadSLDString(selectedFiles);
                }
            }
        }
    });
    // 
    // Set data source
    // 
    dataSourceButton = new ToolButton(Localisation.getString(RasterTool.class, "RasterTool.dataSource"), "tool/setdatasource.png");
    rasterPanel.add(dataSourceButton);
    dataSourceButton.setEnabled(false);
    dataSourceButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if ((nodeTypeList != null) && (nodeTypeList.size() == 1)) {
                if (sldEditorInterface != null) {
                    FileTreeNode fileTreeNode = (FileTreeNode) nodeTypeList.get(0);
                    File rasterFile = fileTreeNode.getFile();
                    ConsoleManager.getInstance().information(this, String.format("%s : %s", Localisation.getString(RasterTool.class, "RasterTool.setDataSource"), rasterFile.getAbsolutePath()));
                    // Raster file
                    DataSourceConnectorInterface dsc = DataSourceConnectorFactory.getDataSource(DataSourceConnector.class);
                    String rasterFilename = null;
                    try {
                        rasterFilename = rasterFile.toURI().toURL().toString();
                    } catch (MalformedURLException exceptionObj) {
                        ConsoleManager.getInstance().exception(RasterTool.class, exceptionObj);
                        return;
                    }
                    DataSourcePropertiesInterface dsProperties = dsc.getDataSourceProperties(DataSourceProperties.encodeFilename(rasterFilename));
                    SLDEditorFile.getInstance().setDataSource(dsProperties);
                    DataSourceInterface dataSource = DataSourceFactory.createDataSource(null);
                    if (dataSource != null) {
                        dataSource.connect(rasterFilename, SLDEditorFile.getInstance(), null);
                    }
                }
            }
        }
    });
    rasterPanel.setPreferredSize(new Dimension(PANEL_WIDTH, ToolPanel.TOOL_PANEL_HEIGHT));
}
Also used : DataSourceConnector(com.sldeditor.datasource.connector.instance.DataSourceConnector) JPanel(javax.swing.JPanel) MalformedURLException(java.net.MalformedURLException) FlowLayout(java.awt.FlowLayout) LoadSLDInterface(com.sldeditor.common.LoadSLDInterface) ToolButton(com.sldeditor.tool.ToolButton) ActionEvent(java.awt.event.ActionEvent) Dimension(java.awt.Dimension) DataSourcePropertiesInterface(com.sldeditor.common.DataSourcePropertiesInterface) FileTreeNode(com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode) DataSourceInterface(com.sldeditor.datasource.DataSourceInterface) ActionListener(java.awt.event.ActionListener) SLDDataInterface(com.sldeditor.common.SLDDataInterface) SelectedFiles(com.sldeditor.common.filesystem.SelectedFiles) DataSourceConnectorInterface(com.sldeditor.common.DataSourceConnectorInterface) ArrayList(java.util.ArrayList) List(java.util.List) SLDEditorFile(com.sldeditor.datasource.SLDEditorFile) File(java.io.File)

Aggregations

ToolButton (com.sldeditor.tool.ToolButton)15 JPanel (javax.swing.JPanel)15 Dimension (java.awt.Dimension)13 ActionEvent (java.awt.event.ActionEvent)13 ActionListener (java.awt.event.ActionListener)13 FlowLayout (java.awt.FlowLayout)12 File (java.io.File)5 SLDDataInterface (com.sldeditor.common.SLDDataInterface)3 ArrayList (java.util.ArrayList)3 GeoServerConnection (com.sldeditor.common.data.GeoServerConnection)2 SLDData (com.sldeditor.common.data.SLDData)2 SLDEditorFile (com.sldeditor.datasource.SLDEditorFile)2 FileTreeNode (com.sldeditor.datasource.extension.filesystem.node.file.FileTreeNode)2 Component (java.awt.Component)2 IOException (java.io.IOException)2 JFileChooser (javax.swing.JFileChooser)2 Test (org.junit.Test)2 DataSourceConnectorInterface (com.sldeditor.common.DataSourceConnectorInterface)1 DataSourcePropertiesInterface (com.sldeditor.common.DataSourcePropertiesInterface)1 LoadSLDInterface (com.sldeditor.common.LoadSLDInterface)1