etopolayer.java
来自「openmap java写的开源数字地图程序. 用applet实现,可以像g」· Java 代码 · 共 879 行 · 第 1/3 页
JAVA
879 行
int lat_idx = (int) ((90. - lat) * scy); int lon_idx = (int) (lon * scx); // offset int ofs = lon_idx + lat_idx * bufferWidth; // make a color int idx = 0; int gray = 0; try { // get elevation short el = dataBuffer[ofs]; // slope byte sl = slopeMap[ofs]; // our index idx = y * width + x; // create a color Color pix = null; if (viewType == SLOPESHADING) { // HACK (see method description above) if ((llp.getLatitude() == center.getLatitude()) && (llp.getLongitude() == center.getLongitude())) gray = 0; else gray = 127 + sl; pix = new Color(gray, gray, gray, opaqueness); } else if (viewType == COLOREDSHADING) { // HACK (see method description above) if ((llp.getLatitude() == center.getLatitude()) && (llp.getLongitude() == center.getLongitude())) pix = new Color(0, 0, 0, opaqueness); else pix = getColor(el, sl); } // set colors[idx] = pix.getRGB(); } // tried to set a bad color level catch (IllegalArgumentException e) { Debug.error(e.toString() + ":" + gray); } // bad index catch (ArrayIndexOutOfBoundsException e) { Debug.error(e.toString() + ":" + idx); } } } // create the raster ret = new OMRaster(0, 0, width, height, colors); } // return or raster return ret; } /** * Prepares the graphics for the layer. This is where the * getRectangle() method call is made on the etopo. * <p> * Occasionally it is necessary to abort a prepare call. When this * happens, the map will set the cancel bit in the LayerThread, * (the thread that is running the prepare). If this Layer needs * to do any cleanups during the abort, it should do so, but * return out of the prepare asap. */ public synchronized OMGraphicList prepare() { if (isCancelled()) { Debug.message("etopo", getName() + "|ETOPOLayer.prepare(): aborted."); return null; } Projection projection = getProjection(); if (projection == null) { Debug.error("ETOPO Layer needs to be added to the MapBean before it can draw images!"); return new OMGraphicList(); } // load the buffer if (dataBuffer == null || spacingReset) { loadBuffer(); spacingReset = false; slopeReset = true; } // re-do the slope map if (slopeReset) { buildSlopeMap(); slopeReset = false; } Debug.message("basic", getName() + "|ETOPOLayer.prepare(): doing it"); // Setting the OMGraphicsList for this layer. Remember, the // OMGraphicList is made up of OMGraphics, which are generated // (projected) when the graphics are added to the list. So, // after this call, the list is ready for painting. // call getRectangle(); if (Debug.debugging("etopo")) { Debug.output(getName() + "|ETOPOLayer.prepare(): " + "calling getRectangle " + " with projection: " + projection + " ul = " + projection.getUpperLeft() + " lr = " + projection.getLowerRight()); } // build graphics list OMGraphicList omGraphicList = new OMGraphicList(); omGraphicList.addOMGraphic(buildRaster()); ///////////////////// // safe quit int size = 0; if (omGraphicList != null) { size = omGraphicList.size(); Debug.message("basic", getName() + "|ETOPOLayer.prepare(): finished with " + size + " graphics"); } else { Debug.message("basic", getName() + "|ETOPOLayer.prepare(): finished with null graphics list"); omGraphicList = new OMGraphicList(); } // Don't forget to project them. Since they are only being // recalled if the projection hase changed, then we need to // force a reprojection of all of them because the screen // position has changed. omGraphicList.project(projection, true); return omGraphicList; } //---------------------------------------------------------------------- // GUI //---------------------------------------------------------------------- /** The user interface palette for the ETOPO layer. */ protected Box palette = null; /** Creates the interface palette. */ public Component getGUI() { if (palette == null) { if (Debug.debugging("etopo")) Debug.output("ETOPOLayer: creating ETOPO Palette."); palette = Box.createVerticalBox(); Box subbox0 = Box.createHorizontalBox(); Box subbox1 = Box.createHorizontalBox(); Box subbox2 = Box.createVerticalBox(); Box subbox3 = Box.createHorizontalBox(); // The ETOPO resolution selector JPanel resPanel = PaletteHelper.createPaletteJPanel("Lat/Lon Spacing"); String[] resStrings = { "2 Minute", "5 Minute", "10 Minute", "15 Minute" }; //ep-g JComboBox resList = new JComboBox(resStrings); resList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox jcb = (JComboBox) e.getSource(); int newRes = jcb.getSelectedIndex(); int curRes = minuteSpacing / 5; //ep-g if (curRes != newRes) spacingReset = true; switch (newRes) { case 0: minuteSpacing = 2; break; //ep-g case 1: minuteSpacing = 5; break; //ep-g case 2: minuteSpacing = 10; break; //ep-g case 3: minuteSpacing = 15; break; //ep-g } } }); resList.setSelectedIndex(minuteSpacing / 5); //ep-g resPanel.add(resList); // The ETOPO view selector JPanel viewPanel = PaletteHelper.createPaletteJPanel("View Type"); String[] viewStrings = { "Grayscale Shading", "Color Shading" }; JComboBox viewList = new JComboBox(viewStrings); viewList.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JComboBox jcb = (JComboBox) e.getSource(); int newView = jcb.getSelectedIndex(); if (newView != viewType) slopeReset = true; switch (newView) { case 0: viewType = SLOPESHADING; break; case 1: viewType = COLOREDSHADING; break; } } }); viewList.setSelectedIndex(viewType); viewPanel.add(viewList); // The ETOPO Contrast Adjuster JPanel contrastPanel = PaletteHelper.createPaletteJPanel("Contrast Adjustment"); JSlider contrastSlide = new JSlider(JSlider.HORIZONTAL, 1/* min */, 5/* max */, 3/* inital */); java.util.Hashtable dict = new java.util.Hashtable(); dict.put(new Integer(1), new JLabel("min")); dict.put(new Integer(5), new JLabel("max")); contrastSlide.setLabelTable(dict); contrastSlide.setPaintLabels(true); contrastSlide.setMajorTickSpacing(1); contrastSlide.setPaintTicks(true); contrastSlide.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { JSlider slider = (JSlider) ce.getSource(); if (slider.getValueIsAdjusting()) { Debug.output("ETOPOLayer - Contrast Slider value = " + slider.getValue()); slopeAdjust = slider.getValue(); } } }); contrastPanel.add(contrastSlide); // The ETOPO Opaqueness JPanel opaquenessPanel = PaletteHelper.createPaletteJPanel("Opaqueness"); JSlider opaquenessSlide = new JSlider(JSlider.HORIZONTAL, 0/* min */, 255/* max */, opaqueness/* inital */); opaquenessSlide.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent ce) { JSlider slider = (JSlider) ce.getSource(); if (slider.getValueIsAdjusting()) { fireRequestInfoLine("ETOPOLayer - Opaqueness Slider value = " + slider.getValue()); opaqueness = slider.getValue(); } } }); opaquenessPanel.add(opaquenessSlide); JButton redraw = new JButton("Redraw ETOPO Layer"); redraw.addActionListener(this); redraw.setActionCommand(RedrawCmd); subbox0.add(resPanel); palette.add(subbox0); subbox1.add(viewPanel); palette.add(subbox1); subbox2.add(contrastPanel); subbox2.add(opaquenessPanel); palette.add(subbox2); subbox3.add(redraw); palette.add(subbox3); } return palette; } //---------------------------------------------------------------------- // ActionListener interface implementation //---------------------------------------------------------------------- /** * Used just for the redraw button. */ public void actionPerformed(ActionEvent e) { super.actionPerformed(e); if (e.getActionCommand() == RedrawCmd) { doPrepare(); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?