/** * Creates the Control for the associated DisplayScalar. This method invokes the method {@link * ScalarMapListener#controlChanged(ScalarMapControlEvent)} on all registered {@link * ScalarMapListener}s with this instance as the event source and {@link * ScalarMapEvent#CONTROL_ADDED} or {@link ScalarMapEvent#CONTROL_REPLACED} as the event ID -- * depending on whether this is the first control or not. The event control is the previous * control if the event ID is {@link ScalarMapEvent#CONTROL_REPLACED}. If the event ID is {@link * ScalarMapEvent#CONTROL_ADDED}, then the event control is the created control or <code>null * </code> -- depending on whether or not the control was successfully created. * * @throws RemoteException Java RMI failure * @throws VisADException VisAD failure */ synchronized void setControl() throws VisADException, RemoteException { int evtID; Control evtCtl; if (control != null) { evtID = ScalarMapEvent.CONTROL_REPLACED; evtCtl = control; } else { evtID = ScalarMapEvent.CONTROL_ADDED; evtCtl = null; } if (display == null) { throw new DisplayException("ScalarMap.setControl: not part of " + "any Display"); } control = display.getDisplayRenderer().makeControl(this); if (control != null) { display.addControl(control); if (evtCtl == null) { evtCtl = control; } } if (control != null || evtCtl != null) { notifyCtlListeners(new ScalarMapControlEvent(this, evtID, evtCtl)); } }
/** * Create the scale that is displayed. This is called automatically when <CODE>setRange(lo, hi) * </CODE> and <CODE>setDisplay</CODE> are called. It makes a call to <CODE>AxisScale.makeScale() * </CODE> where the actual hard work is done. * * @throws VisADException VisAD error. */ public void makeScale() throws VisADException { if (axisScale != null) { DisplayRenderer displayRenderer = null; if (display == null) return; displayRenderer = display.getDisplayRenderer(); if (displayRenderer == null) return; boolean scaleMade = axisScale.makeScale(); if (scaleMade) { // displayRenderer.setScale(axis, axis_ordinal, array, scale_color); if (scale_on) { displayRenderer.setScale(axisScale); } else { displayRenderer.clearScale(axisScale); } scale_flag = false; } } }
public void displayChanged(DisplayEvent e) throws RemoteException, VisADException { if (e.getId() == DisplayEvent.FRAME_DONE) { DisplayImpl display = (DisplayImpl) e.getDisplay(); DisplayRenderer dr = display.getDisplayRenderer(); MouseBehavior mb = dr.getMouseBehavior(); double[] position1 = null; double[] position2 = null; if (display instanceof DisplayImplJ3D) { position1 = new double[] {1.0, 1.0, 1.0}; position2 = new double[] {-1.0, -1.0, -1.0}; } else { position1 = new double[] {1.0, 1.0}; position2 = new double[] {-1.0, -1.0}; } int[] screen1 = mb.getScreenCoords(position1); int[] screen2 = mb.getScreenCoords(position2); // System.out.println("screen1 = (" + screen1[0] + ", " + screen1[1] +")"); // System.out.println("screen2 = (" + screen2[0] + ", " + screen2[1] +")"); } }
public static void main(String[] args) throws Exception { DisplayImpl display = new DisplayImplJ2D("display"); display.getDisplayRenderer().setBoxOn(false); double[] matrix = display.getProjectionControl().getMatrix(); matrix[0] = 1.25; matrix[3] = -1.25; display.getProjectionControl().setMatrix(matrix); display.addMap(new ScalarMap(RealType.YAxis, Display.YAxis)); display.addMap(new ScalarMap(RealType.XAxis, Display.XAxis)); float[][] values = new float[3][220]; int l = 0; for (int x = 0; x < 11; x++) { for (int y = 0; y < 20; y++) { values[0][l] = -1.f + y / 10.f; values[1][l] = 1.f - x / 4.f; values[2][l] = l++; } } Gridded3DSet set = new Gridded3DSet(RealTupleType.SpatialCartesian3DTuple, values, l); ScalarMap shapeMap = new ScalarMap(RealType.ZAxis, Display.Shape); display.addMap(shapeMap); ShapeControl sc = (ShapeControl) shapeMap.getControl(); sc.setShapeSet(new Integer1DSet(l)); sc.setShapes(WeatherSymbols.getAllMetSymbols()); sc.setScale(0.1f); DataReference ref = new DataReferenceImpl("ref"); ref.setData(set); display.addReference(ref); JFrame frame = new JFrame("Weather Symbol Plot Test"); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); frame.getContentPane().add(display.getComponent()); frame.pack(); frame.setSize(500, 500); frame.setVisible(true); }
/** * Returns the dimensionality of the display. * * @return The dimensionality of the display (either 2 or 3). */ public int getDimensionality() { return display.getDisplayRenderer().getMode2D() ? 2 : 3; }