/* * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2007 - 2008, Open Source Geospatial Foundation (OSGeo) * (C) 2008 - 2009, Johann Sorel * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotoolkit.gui.swing.render2d.control; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Font; import java.util.ArrayList; import java.util.List; import javax.measure.Unit; import org.geotoolkit.display2d.canvas.painter.BackgroundPainter; import org.geotoolkit.display2d.canvas.painter.BackgroundPainterGroup; import org.geotoolkit.display2d.canvas.painter.SolidColorPainter; import org.geotoolkit.display2d.ext.grid.DefaultGridTemplate; import org.geotoolkit.display2d.ext.grid.GridPainter; import org.geotoolkit.display2d.ext.grid.GridTemplate; import org.geotoolkit.gui.swing.crschooser.JCRSChooser; import org.geotoolkit.gui.swing.crschooser.JCRSChooser.ACTION; import org.geotoolkit.gui.swing.render2d.JMap2D; import org.geotoolkit.gui.swing.render2d.decoration.JNorthArrowDecoration; import org.geotoolkit.gui.swing.render2d.decoration.JScaleBarDecoration; import org.geotoolkit.gui.swing.render2d.decoration.MapDecoration; import org.geotoolkit.gui.swing.resource.MessageBundle; import org.geotoolkit.gui.swing.util.SwingUtilities; import org.jdesktop.swingx.combobox.ListComboBoxModel; import org.opengis.referencing.crs.CoordinateReferenceSystem; import org.apache.sis.measure.Units; /** * * @author Johann Sorel (Puzzle-GIS) * @module */ public class JConfigDialog extends javax.swing.JDialog { private final JMap2D map; private CoordinateReferenceSystem crs = null; /** Creates new form JConfigDialog */ public JConfigDialog(final java.awt.Frame parent, final JMap2D map) { super((parent==null) ? SwingUtilities.windowForComponent(map) : parent); setModal(true); this.map = map; initComponents(); guiNorthActivate.setSelected(getNorthDecoration() != null); JScaleBarDecoration deco = getScaleDecoration(); if(deco != null){ guiScaleActivate.setSelected(true); guiUnit.setSelectedItem(deco.getUnit()); }else{ guiScaleActivate.setSelected(false); } List<Unit> list = new ArrayList<Unit>(); list.add(Units.METRE); list.add(Units.KILOMETRE); list.add(Units.FOOT); list.add(Units.STATUTE_MILE); guiUnit.setModel(new ListComboBoxModel(list)); if(crs == null){ guiCRS.setText(" "); }else{ guiCRS.setText(crs.getName().toString()); } } private JNorthArrowDecoration getNorthDecoration(){ for(MapDecoration deco : map.getDecorations()){ if(deco instanceof JNorthArrowDecoration){ return (JNorthArrowDecoration) deco; } } return null; } private JScaleBarDecoration getScaleDecoration(){ for(MapDecoration deco : map.getDecorations()){ if(deco instanceof JScaleBarDecoration){ return (JScaleBarDecoration) deco; } } return null; } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ @SuppressWarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jTabbedPane1 = new javax.swing.JTabbedPane(); jPanel3 = new javax.swing.JPanel(); guiColor = new javax.swing.JColorChooser(); colorApply = new javax.swing.JButton(); guiGrid = new javax.swing.JCheckBox(); guiCRS = new javax.swing.JButton(); jPanel2 = new javax.swing.JPanel(); guiScaleActivate = new javax.swing.JCheckBox(); jLabel1 = new javax.swing.JLabel(); guiUnit = new javax.swing.JComboBox(); jPanel1 = new javax.swing.JPanel(); guiNorthActivate = new javax.swing.JCheckBox(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); jTabbedPane1.setTabPlacement(javax.swing.JTabbedPane.LEFT); colorApply.setText(MessageBundle.format("apply")); // NOI18N colorApply.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { colorApplyActionPerformed(evt); } }); guiGrid.setText(MessageBundle.format("grid")); // NOI18N guiCRS.setText(MessageBundle.format("crs")); // NOI18N guiCRS.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { choose(evt); } }); javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3); jPanel3.setLayout(jPanel3Layout); jPanel3Layout.setHorizontalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(guiColor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 583, Short.MAX_VALUE) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(guiGrid) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(guiCRS)) .addComponent(colorApply, javax.swing.GroupLayout.Alignment.TRAILING)) .addContainerGap()) ); jPanel3Layout.setVerticalGroup( jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel3Layout.createSequentialGroup() .addComponent(guiColor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(guiGrid) .addComponent(guiCRS)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 11, Short.MAX_VALUE) .addComponent(colorApply) .addContainerGap()) ); jTabbedPane1.addTab("Background", jPanel3); guiScaleActivate.setText(MessageBundle.format("map_control_activate")); // NOI18N guiScaleActivate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { guiScaleActivateActionPerformed(evt); } }); jLabel1.setText(MessageBundle.format("map_control_unit")); // NOI18N guiUnit.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { guiUnitItemStateChanged(evt); } }); javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); jPanel2.setLayout(jPanel2Layout); jPanel2Layout.setHorizontalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(guiScaleActivate) .addGroup(jPanel2Layout.createSequentialGroup() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(guiUnit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))) .addContainerGap(405, Short.MAX_VALUE)) ); jPanel2Layout.setVerticalGroup( jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel2Layout.createSequentialGroup() .addContainerGap() .addComponent(guiScaleActivate) .addGap(18, 18, 18) .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(guiUnit, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(326, Short.MAX_VALUE)) ); jTabbedPane1.addTab("Scale bar", jPanel2); guiNorthActivate.setText(MessageBundle.format("map_control_activate")); // NOI18N guiNorthActivate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { guiNorthActivateActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(guiNorthActivate) .addContainerGap(413, Short.MAX_VALUE)) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(guiNorthActivate) .addContainerGap(373, Short.MAX_VALUE)) ); jTabbedPane1.addTab("North arrow", jPanel1); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 716, Short.MAX_VALUE) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 417, Short.MAX_VALUE) ); jTabbedPane1.getAccessibleContext().setAccessibleName("ScaleBar"); pack(); }// </editor-fold>//GEN-END:initComponents private void guiNorthActivateActionPerformed(final java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guiNorthActivateActionPerformed if(guiNorthActivate.isSelected()){ if(getNorthDecoration() == null)map.addDecoration(new JNorthArrowDecoration()); }else{ map.removeDecoration(getNorthDecoration()); } }//GEN-LAST:event_guiNorthActivateActionPerformed private void guiScaleActivateActionPerformed(final java.awt.event.ActionEvent evt) {//GEN-FIRST:event_guiScaleActivateActionPerformed if(guiScaleActivate.isSelected()){ if(getScaleDecoration() == null)map.addDecoration(new JScaleBarDecoration()); }else{ map.removeDecoration(getScaleDecoration()); } }//GEN-LAST:event_guiScaleActivateActionPerformed private void guiUnitItemStateChanged(final java.awt.event.ItemEvent evt) {//GEN-FIRST:event_guiUnitItemStateChanged JScaleBarDecoration deco = getScaleDecoration(); if(deco != null){ deco.setUnit((Unit) guiUnit.getSelectedItem()); } }//GEN-LAST:event_guiUnitItemStateChanged private void colorApplyActionPerformed(final java.awt.event.ActionEvent evt) {//GEN-FIRST:event_colorApplyActionPerformed BackgroundPainter deco = new SolidColorPainter(guiColor.getColor()); if(guiGrid.isSelected()){ GridTemplate template = new DefaultGridTemplate( crs, new BasicStroke(2), Color.DARK_GRAY, new BasicStroke(1), Color.GRAY, new Font("Arial", Font.BOLD, 12), Color.DARK_GRAY, 2, Color.white, new Font("Arial", Font.PLAIN, 11), Color.GRAY, 2, Color.white ); BackgroundPainter gridPaint = new GridPainter(template); map.getCanvas().setBackgroundPainter(BackgroundPainterGroup.wrap(deco,gridPaint)); }else{ map.getCanvas().setBackgroundPainter(deco); } map.getCanvas().repaint(); }//GEN-LAST:event_colorApplyActionPerformed private void choose(final java.awt.event.ActionEvent evt) {//GEN-FIRST:event_choose final JCRSChooser chooser = new JCRSChooser(this, true); chooser.setCRS(map.getCanvas().getObjectiveCRS()); ACTION act = chooser.showDialog(); if(ACTION.APPROVE.equals(act)){ crs = chooser.getCRS(); if(crs == null){ guiCRS.setText(" "); }else{ guiCRS.setText(crs.getName().toString()); } } }//GEN-LAST:event_choose // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton colorApply; private javax.swing.JButton guiCRS; private javax.swing.JColorChooser guiColor; private javax.swing.JCheckBox guiGrid; private javax.swing.JCheckBox guiNorthActivate; private javax.swing.JCheckBox guiScaleActivate; private javax.swing.JComboBox guiUnit; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JPanel jPanel2; private javax.swing.JPanel jPanel3; private javax.swing.JTabbedPane jTabbedPane1; // End of variables declaration//GEN-END:variables }