- 积分
- 863
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2016-10-14
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package midemo;
import java.awt.Color;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import org.meteoinfo.data.GridData;
import org.meteoinfo.data.StationData;
import org.meteoinfo.data.mapdata.MapDataManage;
import org.meteoinfo.data.meteodata.DrawMeteoData;
import org.meteoinfo.data.meteodata.GridDataSetting;
import org.meteoinfo.data.meteodata.InterpolationMethods;
import org.meteoinfo.data.meteodata.InterpolationSetting;
import org.meteoinfo.data.meteodata.MeteoDataInfo;
import org.meteoinfo.global.event.ActiveMapFrameChangedEvent;
import org.meteoinfo.global.event.IActiveMapFrameChangedListener;
import org.meteoinfo.layer.LabelSet;
import org.meteoinfo.layer.MapLayer;
import org.meteoinfo.layer.VectorLayer;
import org.meteoinfo.layout.LayoutGraphic;
import org.meteoinfo.layout.LayoutLegend;
import org.meteoinfo.layout.LayoutMap;
import org.meteoinfo.layout.LegendStyles;
import org.meteoinfo.layout.MouseMode;
import org.meteoinfo.legend.AlignType;
import org.meteoinfo.legend.LegendManage;
import org.meteoinfo.legend.LegendScheme;
import org.meteoinfo.legend.LegendType;
import org.meteoinfo.legend.MapFrame;
import org.meteoinfo.legend.PointBreak;
import org.meteoinfo.legend.PolygonBreak;
import org.meteoinfo.legend.PolylineBreak;
import org.meteoinfo.map.MaskOut;
import org.meteoinfo.map.MouseTools;
import org.meteoinfo.shape.ShapeTypes;
/**
*
* @author Administrator
*/
public class FramMain extends javax.swing.JFrame {
//private MapLayout mapLayout1;
/**
* Creates new form FramMain
*/
public FramMain() {
initComponents();
this.layersLegend1.getActiveMapFrame().setMapView(this.mapView1);
this.layersLegend1.setMapLayout(this.mapLayout1);
this.layersLegend1.setIsLayoutView(false);
//setMapView
//Set width and heigth
this.setSize(1000, 650);
//Load layer
this.loadLayers();
//Set initial tool
this.Button_Pan.doClick();
this.addMapFrame_ChinaSouthSea();
this.AddTitle();
this.setMapView();
this.layersLegend1.addActiveMapFrameChangedListener(new IActiveMapFrameChangedListener(){
@Override
public void activeMapFrameChangedEvent(ActiveMapFrameChangedEvent event) {
mapView1 = layersLegend1.getActiveMapFrame().getMapView();
setMapView();
if (jTabbedPane1.getSelectedIndex() == 0) {
mapView1.paintLayers();
}
}
});
}
private void AddTitle() {
this.mapLayout1.addText("MeteoInfo Class Library Demo", mapLayout1.getWidth() / 2, 20, 16);
}
private void addMapFrame_ChinaSouthSea() {
//Add an empty map frame
MapFrame aMF = new MapFrame();
aMF.setText("China South Sea");
this.layersLegend1.addMapFrame(aMF);
//Add a layer to this map frame
try {
String mapDir = "E:\\MeteoInfo_Java_1.3.6R4_Files\\MeteoInfo\\map\\";
String aFile = mapDir + "country1.shp";
MapLayer aLayer = MapDataManage.loadLayer(aFile);
aLayer.getLegendScheme().getLegendBreaks().get(0).setColor(new Color(232, 232, 232));
aMF.addLayer(aLayer);
//Set layout map property
LayoutMap aLM = this.mapLayout1.getLayoutMaps().get(1);
aMF.setDrawGridLabel(false);
aLM.setLeft(550);
aLM.setTop(330);
aLM.setWidth(80);
aLM.setHeight(100);
aMF.getMapView().zoomToExtent(105, 120, 0, 20);
aMF.getLayerNodeByName(aFile);
//aLayer = MapDataManage.loadLayer(aFile);
this.layersLegend1.repaint();
} catch (IOException ex) {
Logger.getLogger(FramMain.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(FramMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void loadLayers() {
try {
this.layersLegend1.getActiveMapFrame().getMapView().setLockViewUpdate(true);
//Load country layer
String mapDir = "E:\\MeteoInfo_Java_1.3.6R4_Files\\MeteoInfo\\map\\";
String fileName = mapDir + "country1.shp";
MapLayer aLayer = MapDataManage.loadLayer(fileName);
aLayer.setVisible(false);
// aLayer.getLegendScheme().getLegendBreaks().get(0).setColor(Color.WHITE);
this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
//Load river layer
fileName = mapDir + "rivers.shp";
aLayer = MapDataManage.loadLayer(fileName);
PolylineBreak lineBreak = (PolylineBreak) aLayer.getLegendScheme().getLegendBreaks().get(0);
lineBreak.setColor(Color.cyan);
lineBreak.setSize(2);
this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
//Load china layer
fileName = mapDir + "bou2_4l.shp";
aLayer = MapDataManage.loadLayer(fileName);
this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
//Load Fujian_province layer
fileName = mapDir + "Fujian_province.shp";
aLayer = MapDataManage.loadLayer(fileName);
aLayer.setVisible(false);
// PointBreak pointBreak = (PointBreak) aLayer.getLegendScheme().getLegendBreaks().get(1);
this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
//Load Fujian_county layer
fileName = mapDir + "XianCh_point.shp";
aLayer = MapDataManage.loadLayer(fileName);
// PointBreak XianCh_pointBreak = (PointBreak) aLayer.getLegendScheme().getLegendBreaks().get(0);
// aLayer.setVisible(false);
//Load Fujian_county Name
VectorLayer countyLayer = (VectorLayer) aLayer;
LabelSet countylabelSet = countyLayer.getLabelSet();
countylabelSet.setFieldName("NAME");
countylabelSet.setAvoidCollision(true);
countylabelSet.setLabelAlignType(AlignType.Center);
countylabelSet.setYOffset(0);
//countylabelSet.setLabelFont(new Font("Arial", Font.PLAIN, 14));
countylabelSet.setLabelColor(Color.red);
countylabelSet.setDrawShadow(false);
countylabelSet.setColorByLegend(false);
countyLayer.addLabels();
this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
//Load City layer
// fileName = mapDir + "CITIES.shp";
// aLayer = MapDataManage.loadLayer(fileName);
// PointBreak pointBreak = (PointBreak) aLayer.getLegendScheme().getLegendBreaks().get(0);
// pointBreak.setColor(Color.red);
// aLayer.setExpanded(true);
// //Load City Name
// VectorLayer cityLayer = (VectorLayer) aLayer;
// LabelSet labelSet = cityLayer.getLabelSet();
// labelSet.setFieldName("NAME");
// labelSet.setAvoidCollision(true);
// labelSet.setLabelAlignType(AlignType.Center);
// labelSet.setYOffset(0);
// labelSet.setLabelFont(new Font("Arial", Font.PLAIN, 14));
// labelSet.setLabelColor(Color.red);
// labelSet.setDrawShadow(false);
// labelSet.setColorByLegend(false);
// cityLayer.addLabels();
// this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
//Set layout map size
LayoutMap layoutMap = this.mapLayout1.getActiveLayoutMap();
layoutMap.setLeft(40);
layoutMap.setTop(40);
layoutMap.setWidth(600);
layoutMap.setHeight(400);
//Repaint
this.layersLegend1.getActiveMapFrame().getMapView().setLockViewUpdate(false);
this.layersLegend1.getActiveMapFrame().getMapView().zoomToExtent(70, 140, 10, 60);
this.layersLegend1.repaint();
} catch (IOException ex) {
Logger.getLogger(FramMain.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(FramMain.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void setMapView(){
//Add map view
this.mapView1.setLockViewUpdate(true);
this.jPanel_Map.removeAll();
javax.swing.GroupLayout jPanel_MapLayout=new javax.swing.GroupLayout(jPanel_Map);
jPanel_Map.setLayout(jPanel_MapLayout);
jPanel_MapLayout.setHorizontalGroup(
jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
jPanel_MapLayout.setVerticalGroup(
jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE));
this.mapView1.setLockViewUpdate(false);
if (_currentTool != null) {
_currentTool.doClick();
}
this.mapView1.setFocusable(true);
this.mapView1.requestFocusInWindow();
}
// private void jMenuItem_ContourActionPerformed(java.awt.event.ActionEvent evt) {
// // TODO add your handling code here:
// //Create a MeteoDataInfo object
// MeteoDataInfo aDataInfo = new MeteoDataInfo();
//
// //Open GrADS data file
// String dataDir = "E:\\MeteoInfo_Java_1.3.6R4_Files\\MeteoInfo\\sample\\GrADS\\";
// String fileName = dataDir + "model.ctl";
// aDataInfo.openGrADSData(fileName);
//
// //Get GridData
// GridData press = aDataInfo.getGridData("PS");
//
// //Create a legend scheme
// LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(press,LegendType.UniqueValue, ShapeTypes.Polyline);
//
// //Create a contour layer
// VectorLayer aLayer = DrawMeteoData.createContourLayer(press, aLS, "Contour_PS", "PS", true);
//
// //Add layer
// layersLegend1.getActiveMapFrame().addLayer(aLayer);
// layersLegend1.getActiveMapFrame().moveLayer(aLayer.getHandle(), 2);
// layersLegend1.repaint();
//
// //Change title of the layout
// LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
// aTitle.setLabelText("MeteoInfo Class Library Demo - Contour Layer");
//
// //Add a legend in layout
// LayoutLegend aLegend = mapLayout1.addLegend(650, 100);
// aLegend.setLegendStyle(LegendStyles.Normal);
// aLegend.setLegendLayer(aLayer);
// mapLayout1.paintGraphics();
// }
private JButton _currentTool = null;
private void setCurrentTool(JButton currentTool) {
if (!(_currentTool == null)) {
_currentTool.setSelected(false);
}
_currentTool = currentTool;
_currentTool.setSelected(true);
jLabel_Status.setText(_currentTool.getToolTipText());
}
/**
* 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">
private void initComponents() {
jToolBar1 = new javax.swing.JToolBar();
jButton1 = new javax.swing.JButton();
Button_Select = new javax.swing.JButton();
Button_ZoomIn = new javax.swing.JButton();
Button_ZoomOut = new javax.swing.JButton();
Button_Pan = new javax.swing.JButton();
Button_Identifer = new javax.swing.JButton();
jSplitPane1 = new javax.swing.JSplitPane();
layersLegend1 = new org.meteoinfo.legend.LayersLegend();
jTabbedPane1 = new javax.swing.JTabbedPane();
jPanel_Map = new javax.swing.JPanel();
mapView1 = new org.meteoinfo.map.MapView();
jPanel_Layout = new javax.swing.JPanel();
mapLayout1 = new org.meteoinfo.layout.MapLayout();
jToolBar2 = new javax.swing.JToolBar();
jLabel_Status = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();
jMenu3 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jToolBar1.setRollover(true);
jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/midemo/open_file_16px_1187339_easyicon.net.png"))); // NOI18N
jButton1.setFocusable(false);
jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
jToolBar1.add(jButton1);
Button_Select.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/jt.png"))); // NOI18N
Button_Select.setFocusable(false);
Button_Select.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
Button_Select.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
Button_Select.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Button_SelectActionPerformed(evt);
}
});
jToolBar1.add(Button_Select);
Button_ZoomIn.setIcon(new javax.swing.ImageIcon(getClass().getResource("/midemo/fd1.png"))); // NOI18N
Button_ZoomIn.setFocusable(false);
Button_ZoomIn.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
Button_ZoomIn.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
Button_ZoomIn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Button_ZoomInActionPerformed(evt);
}
});
jToolBar1.add(Button_ZoomIn);
Button_ZoomOut.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/sx1.png"))); // NOI18N
Button_ZoomOut.setFocusable(false);
Button_ZoomOut.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
Button_ZoomOut.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
Button_ZoomOut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Button_ZoomOutActionPerformed(evt);
}
});
jToolBar1.add(Button_ZoomOut);
Button_Pan.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/s.png"))); // NOI18N
Button_Pan.setFocusable(false);
Button_Pan.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
Button_Pan.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
Button_Pan.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Button_PanActionPerformed(evt);
}
});
jToolBar1.add(Button_Pan);
Button_Identifer.setIcon(new javax.swing.ImageIcon(getClass().getResource("/img/i_16px_1152407_easyicon.net.png"))); // NOI18N
Button_Identifer.setFocusable(false);
Button_Identifer.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
Button_Identifer.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
Button_Identifer.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Button_IdentiferActionPerformed(evt);
}
});
jToolBar1.add(Button_Identifer);
layersLegend1.setMinimumSize(new java.awt.Dimension(200, 280));
layersLegend1.setName(""); // NOI18N
jSplitPane1.setLeftComponent(layersLegend1);
jTabbedPane1.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
jTabbedPane1StateChanged(evt);
}
});
jPanel_Map.setPreferredSize(new java.awt.Dimension(400, 243));
javax.swing.GroupLayout mapView1Layout = new javax.swing.GroupLayout(mapView1);
mapView1.setLayout(mapView1Layout);
mapView1Layout.setHorizontalGroup(
mapView1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 902, Short.MAX_VALUE)
);
mapView1Layout.setVerticalGroup(
mapView1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 339, Short.MAX_VALUE)
);
javax.swing.GroupLayout jPanel_MapLayout = new javax.swing.GroupLayout(jPanel_Map);
jPanel_Map.setLayout(jPanel_MapLayout);
jPanel_MapLayout.setHorizontalGroup(
jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 922, Short.MAX_VALUE)
.addGroup(jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel_MapLayout.createSequentialGroup()
.addContainerGap()
.addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()))
);
jPanel_MapLayout.setVerticalGroup(
jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 359, Short.MAX_VALUE)
.addGroup(jPanel_MapLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel_MapLayout.createSequentialGroup()
.addContainerGap()
.addComponent(mapView1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap()))
);
jTabbedPane1.addTab("地图", jPanel_Map);
jPanel_Layout.setPreferredSize(new java.awt.Dimension(400, 243));
javax.swing.GroupLayout jPanel_LayoutLayout = new javax.swing.GroupLayout(jPanel_Layout);
jPanel_Layout.setLayout(jPanel_LayoutLayout);
jPanel_LayoutLayout.setHorizontalGroup(
jPanel_LayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel_LayoutLayout.createSequentialGroup()
.addContainerGap()
.addComponent(mapLayout1, javax.swing.GroupLayout.DEFAULT_SIZE, 902, Short.MAX_VALUE)
.addContainerGap())
);
jPanel_LayoutLayout.setVerticalGroup(
jPanel_LayoutLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel_LayoutLayout.createSequentialGroup()
.addContainerGap()
.addComponent(mapLayout1, javax.swing.GroupLayout.DEFAULT_SIZE, 339, Short.MAX_VALUE)
.addContainerGap())
);
jTabbedPane1.addTab("布局", jPanel_Layout);
jSplitPane1.setRightComponent(jTabbedPane1);
jToolBar2.setRollover(true);
jLabel_Status.setText("Status");
jToolBar2.add(jLabel_Status);
jMenu1.setText("文件");
jMenuBar1.add(jMenu1);
jMenu2.setText("编辑");
jMenu3.setText("GrADS Data");
jMenuItem1.setText("Countour");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem1);
jMenuItem2.setText("shaded_ps");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem2);
jMenuItem3.setText("mask");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu3.add(jMenuItem3);
jMenu2.add(jMenu3);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 991, Short.MAX_VALUE)
.addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(jToolBar2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 390, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
);
pack();
}// </editor-fold>
private void jTabbedPane1StateChanged(javax.swing.event.ChangeEvent evt) {
// TODO add your handling code here:
int selIndex = this.jTabbedPane1.getSelectedIndex();
switch (selIndex) {
case 0:
this.layersLegend1.setIsLayoutView(false);
this.mapView1.setIsLayoutMap(false);
this.mapView1.zoomToExtent(this.mapView1.getViewExtent());
break;
case 1:
this.layersLegend1.setIsLayoutView(true);
this.layersLegend1.getMapLayout().paintGraphics();
break;
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
String path = System.getProperty("user.dir");
File pathDir = new File(path);
JFileChooser aDlg = new JFileChooser();
aDlg.setAcceptAllFileFilterUsed(false);
aDlg.setCurrentDirectory(pathDir);
String[] fileExts = new String[]{"shp", "bmp", "gif", "jpg", "png"};
GenericFileFilter mapFileFilter = new GenericFileFilter(fileExts, "Supported Formats");
aDlg.setFileFilter(mapFileFilter);
fileExts = new String[]{"shp"};
mapFileFilter = new GenericFileFilter(fileExts, "Shape File (*.shp)");
aDlg.addChoosableFileFilter(mapFileFilter);
if (JFileChooser.APPROVE_OPTION == aDlg.showOpenDialog(this)) {
File aFile = aDlg.getSelectedFile();
System.setProperty("User.dir", aFile.getParent());
MapLayer aLayer = null;
try {
//aLayer=ShapeFileManage.loadShapeFile(aFile.getAbsolutePath());
aLayer = MapDataManage.loadLayer(aFile.getAbsolutePath());
} catch (IOException ex) {
Logger.getLogger(FramMain.class.getName()).log(Level.SEVERE, null, ex);
} catch (Exception ex) {
Logger.getLogger(FramMain.class.getName()).log(Level.SEVERE, null, ex);
}
if (aLayer != null) {
this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
}
}
}
private void Button_SelectActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.mapView1.setMouseTool(MouseTools.SelectElements);
this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Select);
setCurrentTool((JButton) evt.getSource());
}
private void Button_ZoomInActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.mapView1.setMouseTool(MouseTools.Zoom_In);
this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_ZoomIn);
setCurrentTool((JButton) evt.getSource());
}
private void Button_ZoomOutActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.mapView1.setMouseTool(MouseTools.Zoom_Out);
this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_ZoomOut);
setCurrentTool((JButton) evt.getSource());
}
private void Button_PanActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.mapView1.setMouseTool(MouseTools.Pan);
this.layersLegend1.getMapLayout().setMouseMode(MouseMode.PanMap);
setCurrentTool((JButton) evt.getSource());
}
private void Button_IdentiferActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.mapView1.setMouseTool(MouseTools.Identifer);
this.layersLegend1.getMapLayout().setMouseMode(MouseMode.Map_Identifer);
setCurrentTool((JButton) evt.getSource());
}
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MeteoDataInfo aDataInfo = new MeteoDataInfo();
//Open GrADS data file
String dataDir = "E:\\MeteoInfo_Java_1.3.6R4_Files\\MeteoInfo\\sample\\GrADS\\";
String fileName = dataDir + "model.ctl";
aDataInfo.openGrADSData(fileName);
//Get GridData
GridData press = aDataInfo.getGridData("PS");
//Create a legend scheme
LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(press,LegendType.GraduatedColor, ShapeTypes.Polygon);
//Create a shaded layer
VectorLayer aLayer = DrawMeteoData.createShadedLayer(press, aLS, "Shaded_PS", "PS", true);
//Add layer
layersLegend1.getActiveMapFrame().addLayer(aLayer);
layersLegend1.getActiveMapFrame().moveLayer(aLayer.getHandle(), 0);
layersLegend1.repaint();
//Change title of the layout
LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
aTitle.setLabelText("MeteoInfo Class Library Demo - Shaded Layer");
//Add or change the legend in layout
LayoutLegend aLegend;
if (this.mapLayout1.getLegends().size() > 0) {
aLegend = mapLayout1.getLegends().get(0);
} else {
aLegend = mapLayout1.addLegend(650, 100);
}
aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
aLegend.setLegendLayer(aLayer);
mapLayout1.paintGraphics();
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MeteoDataInfo aDataInfo = new MeteoDataInfo();
String dataDir = "E:\\MeteoInfo_Java_1.3.6R4_Files\\MeteoInfo\\sample\\MICAPS\\";
String fileName = dataDir + "000.000";
aDataInfo.openMICAPSData(fileName);
//Get station data
StationData stationData = aDataInfo.getStationData("Precipitation6h");
System.out.println(aDataInfo.getStationData("Precipitation6h"));
//Interpolate
GridDataSetting aGDP = new GridDataSetting();
aGDP.dataExtent.minX = 115;
aGDP.dataExtent.maxX = 121;
aGDP.dataExtent.minY = 23;
aGDP.dataExtent.maxY = 30;
aGDP.xNum = 500;
aGDP.yNum = 500;
InterpolationSetting gridInterp = new InterpolationSetting();
gridInterp.setGridDataSetting(aGDP);
gridInterp.setInterpolationMethod(InterpolationMethods.IDW_Radius);
gridInterp.setRadius(2);
gridInterp.setMinPointNum(1);
GridData gridData = stationData.interpolateData(gridInterp);
//Create legend scheme
LegendScheme aLS = LegendManage.createLegendSchemeFromGridData(gridData, LegendType.GraduatedColor,ShapeTypes.Polygon);
((PolygonBreak) aLS.getLegendBreaks().get(0)).setDrawFill(false);
//Create layer
VectorLayer aLayer = new VectorLayer(ShapeTypes.Polygon);
aLayer = DrawMeteoData.createShadedLayer(gridData, aLS, "Rain", "Rain", true);
aLayer.setMaskout(true);
//Add layer
layersLegend1.getActiveMapFrame().addLayer(aLayer);
layersLegend1.getActiveMapFrame().moveLayer(aLayer, 0);
layersLegend1.repaint();
//Change title of the layout
LayoutGraphic aTitle = mapLayout1.getTexts().get(0);
aTitle.setLabelText("MeteoInfo Class Library Demo - Station Shaded Layer");
//Add or change the legend in layout
LayoutLegend aLegend;
if (mapLayout1.getLegends().size() > 0) {
aLegend = mapLayout1.getLegends().get(0);
} else {
aLegend = mapLayout1.addLegend(650, 100);
}
aLegend.setLegendStyle(LegendStyles.Bar_Vertical);
aLegend.setLegendLayer(aLayer);
//Load china layer
// fileName = "E:\\MeteoInfo_Java_1.3.6R4_Files\\MeteoInfo\\map\\Fujian_province.shp";
// try {
// aLayer = (VectorLayer) MapDataManage.loadLayer(fileName);
// } catch (Exception ex) {
// Logger.getLogger(FramMain.class.getName()).log(Level.SEVERE, null, ex);
// }
// // aLayer.setVisible(false);
// aLayer.getLegendScheme().getLegendBreaks().get(0).setColor(Color.WHITE);
//// PointBreak pointBreak = (PointBreak) aLayer.getLegendScheme().getLegendBreaks().get(0);
// this.layersLegend1.getActiveMapFrame().addLayer(aLayer);
if (this.jTabbedPane1.getSelectedIndex() == 1) {
mapLayout1.paintGraphics();
}
MaskOut mo = layersLegend1.getActiveMapFrame().getMapView().getMaskOut();
mo.setMask(true);
mo.setMaskLayer("Fujian_province.shp");
layersLegend1.getActiveMapFrame().getMapView().paintLayers();
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
MaskOut mo = layersLegend1.getActiveMapFrame().getMapView().getMaskOut();
mo.setMask(true);
mo.setMaskLayer("Fujian_province.shp");
layersLegend1.getActiveMapFrame().getMapView().paintLayers();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FramMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FramMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FramMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FramMain.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new FramMain().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Button_Identifer;
private javax.swing.JButton Button_Pan;
private javax.swing.JButton Button_Select;
private javax.swing.JButton Button_ZoomIn;
private javax.swing.JButton Button_ZoomOut;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel_Status;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenu jMenu3;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPanel jPanel_Layout;
private javax.swing.JPanel jPanel_Map;
private javax.swing.JSplitPane jSplitPane1;
private javax.swing.JTabbedPane jTabbedPane1;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JToolBar jToolBar2;
private org.meteoinfo.legend.LayersLegend layersLegend1;
private org.meteoinfo.layout.MapLayout mapLayout1;
private org.meteoinfo.map.MapView mapView1;
// End of variables declaration
}
|
|