/* JRG, the Resource Geology Seismic Processing System for Java, and Viewmat for Java are Copyright 1998-2006 by John N. Louie The software and methods here are the subject of academic research, not commercial products. I would like to know what use you make of my methods, and have your feedback on their success or failure. Also, by letting me know who you are, I can inform you if bugs or errors are discovered. Please send me an email message with: your name and email address; whether you are a student or faculty member, consultant or employee; the name of your university or company, and department; and a sentence or two describing what use you intend to make of these methods. Send your message to louie@seismo.unr.edu */ import java.util.*; import java.io.*; import java.lang.Math; import java.awt.*; import java.awt.image.*; import java.awt.event.*; import java.applet.Applet; public class Viewmat { static final int MinImSize=200; static int MaxImSize=2000; static int MaxFrWidth=760; static int MaxFrHeight=560; static int npsras; int cw, ch, imx, imy, imw, imh, fw, fh, sbw, sb0, sbf; int sclx, scly, sclw, sclh, psplane; int scale[]; String title, PlaneUnits; CheckboxMenuItem inplace; TextField titletf; boolean rowsdown, positive; Checkbox rowsdowncb, positivecb; float ve, clip, Plane0, DPlane; TextField vetf, cliptf, Amp0tf, AmpFactf, AmpUnitstf; TextField Elem0tf, DElemtf, ElemUnitstf; TextField Vec0tf, DVectf, VecUnitstf; TextField Plane0tf, DPlanetf, PlaneUnitstf; RgRGB ctab[]; Choice ctabchoice; FltPlane fp; FltVol fvol; int plane; MemoryImageSource sclmis; Image sclim; Color ltgray; ScrollPane sp; ViewmatFrame f; FltPlaneCanvas cvs; Applet applet; Menu exagg, zoom, file; MenuItem openbin; float fzoom; /* Methods related to AWT properties panel */ void applyPropsPanel(ViewmatProps f, Panel pp) { int multi; float mfac; title = f.vm.titletf.getText(); rowsdown = f.vm.rowsdowncb.getState(); positive = f.vm.positivecb.getState(); float vetemp; try {vetemp = Float.valueOf(f.vm.vetf.getText()).floatValue(); } catch (NumberFormatException nfe) {vetemp = ve; } ve = vetemp != 0F ? vetemp : 1F; float cliptemp, Amp0temp, AmpFactemp, Elem0temp, DElemtemp; float Vec0temp, DVectemp, Plane0temp, DPlanetemp; if (fvol == null) { try {Amp0temp = Float.valueOf(f.vm.Amp0tf.getText()).floatValue(); } catch (NumberFormatException nfe) {Amp0temp = fp.getAmp0(); } fp.setAmp0(Amp0temp); try {AmpFactemp = Float.valueOf(f.vm.AmpFactf.getText()).floatValue(); } catch (NumberFormatException nfe) {AmpFactemp = fp.getAmpFac(); } if (AmpFactemp == 0F ) AmpFactemp = fp.getAmpFac(); fp.setAmpFac(AmpFactemp); fp.setAmpUnits(f.vm.AmpUnitstf.getText()); if (f.vm.cliptf.getText().equalsIgnoreCase("max")) clip = fp.max(); else if (f.vm.cliptf.getText().equalsIgnoreCase("rms")) clip = fp.rms(); else if ((multi=f.vm.cliptf.getText().indexOf("*max")) > 0 && multi < f.vm.cliptf.getText().length()) { try {mfac = Float.valueOf(f.vm.cliptf.getText().substring(0, multi)).floatValue(); } catch (NumberFormatException nfe) {mfac = 1F; } clip = mfac*fp.max(); } else if ((multi=f.vm.cliptf.getText().indexOf("*rms")) > 0 && multi < f.vm.cliptf.getText().length()) { try {mfac = Float.valueOf(f.vm.cliptf.getText().substring(0, multi)).floatValue(); } catch (NumberFormatException nfe) {mfac = 1F; } clip = mfac*fp.rms(); } else { try {cliptemp = Float.valueOf(f.vm.cliptf.getText()).floatValue(); } catch (NumberFormatException nfe) {cliptemp = clip*fp.getAmpFac() + fp.getAmp0(); } if (cliptemp < 0F) cliptemp = -cliptemp; if (fp.getAmpFac() == 0F) clip = cliptemp - fp.getAmp0(); else clip = (cliptemp - fp.getAmp0())/fp.getAmpFac(); } try {Elem0temp = Float.valueOf(f.vm.Elem0tf.getText()).floatValue(); } catch (NumberFormatException nfe) {Elem0temp = fp.getUnit0ofDim(0); } fp.setUnit0ofDim(0, Elem0temp); try {DElemtemp = Float.valueOf(f.vm.DElemtf.getText()).floatValue(); } catch (NumberFormatException nfe) {DElemtemp = fp.getDUnitofDim(0); } fp.setDUnitofDim(0, DElemtemp); fp.setUnitsofDim(0, f.vm.ElemUnitstf.getText()); try {Vec0temp = Float.valueOf(f.vm.Vec0tf.getText()).floatValue(); } catch (NumberFormatException nfe) {Vec0temp = fp.getUnit0ofDim(1); } fp.setUnit0ofDim(1, Vec0temp); try {DVectemp = Float.valueOf(f.vm.DVectf.getText()).floatValue(); } catch (NumberFormatException nfe) {DVectemp = fp.getDUnitofDim(1); } fp.setDUnitofDim(1, DVectemp); fp.setUnitsofDim(1, f.vm.VecUnitstf.getText()); } else { try {Amp0temp = Float.valueOf(f.vm.Amp0tf.getText()).floatValue(); } catch (NumberFormatException nfe) {Amp0temp = fvol.getAmp0(); } fvol.setAmp0(Amp0temp); fp.setAmp0(Amp0temp); try {AmpFactemp = Float.valueOf(f.vm.AmpFactf.getText()).floatValue(); } catch (NumberFormatException nfe) {AmpFactemp = fvol.getAmpFac(); } fvol.setAmpFac(AmpFactemp); fp.setAmpFac(AmpFactemp); fvol.setAmpUnits(f.vm.AmpUnitstf.getText()); fp.setAmpUnits(f.vm.AmpUnitstf.getText()); if (f.vm.cliptf.getText().equalsIgnoreCase("max")) { FltPlane fpl = new FltPlane(fvol.getNMembofDim(1), fvol.getNMembofDim(0)); fpl.setNoticeOn(false); fpl.windowof(fvol, plane, 0, 1, 0, 1); clip = fpl.max(); fpl = null; } else if (f.vm.cliptf.getText().equalsIgnoreCase("rms")) { FltPlane fpl = new FltPlane(fvol.getNMembofDim(1), fvol.getNMembofDim(0)); fpl.setNoticeOn(false); fpl.windowof(fvol, plane, 0, 1, 0, 1); clip = fpl.rms(); fpl = null; } else if ((multi=f.vm.cliptf.getText().indexOf("*max")) > 0 && multi < f.vm.cliptf.getText().length()) { try {mfac = Float.valueOf(f.vm.cliptf.getText().substring(0, multi)).floatValue(); } catch (NumberFormatException nfe) {mfac = 1F; } FltPlane fpl = new FltPlane(fvol.getNMembofDim(1), fvol.getNMembofDim(0)); fpl.setNoticeOn(false); fpl.windowof(fvol, plane, 0, 1, 0, 1); clip = mfac*fpl.max(); fpl = null; } else if ((multi=f.vm.cliptf.getText().indexOf("*rms")) > 0 && multi < f.vm.cliptf.getText().length()) { try {mfac = Float.valueOf(f.vm.cliptf.getText().substring(0, multi)).floatValue(); } catch (NumberFormatException nfe) {mfac = 1F; } FltPlane fpl = new FltPlane(fvol.getNMembofDim(1), fvol.getNMembofDim(0)); fpl.setNoticeOn(false); fpl.windowof(fvol, plane, 0, 1, 0, 1); clip = mfac*fpl.rms(); fpl = null; } else { try {cliptemp = Float.valueOf(f.vm.cliptf.getText()).floatValue(); } catch (NumberFormatException nfe) {cliptemp = clip*fvol.getAmpFac() + fvol.getAmp0(); } if (cliptemp < 0F) cliptemp = -cliptemp; if (fvol.getAmpFac() == 0F) clip = cliptemp - fvol.getAmp0(); else clip = (cliptemp - fvol.getAmp0())/fvol.getAmpFac(); } try {Elem0temp = Float.valueOf(f.vm.Elem0tf.getText()).floatValue(); } catch (NumberFormatException nfe) {Elem0temp = fvol.getUnit0ofDim(0); } fvol.setUnit0ofDim(0, Elem0temp); fp.setUnit0ofDim(0, Elem0temp); try {DElemtemp = Float.valueOf(f.vm.DElemtf.getText()).floatValue(); } catch (NumberFormatException nfe) {DElemtemp = fvol.getDUnitofDim(0); } fvol.setDUnitofDim(0, DElemtemp); fp.setDUnitofDim(0, DElemtemp); fvol.setUnitsofDim(0, f.vm.ElemUnitstf.getText()); fp.setUnitsofDim(0, f.vm.ElemUnitstf.getText()); try {Vec0temp = Float.valueOf(f.vm.Vec0tf.getText()).floatValue(); } catch (NumberFormatException nfe) {Vec0temp = fvol.getUnit0ofDim(1); } fvol.setUnit0ofDim(1, Vec0temp); fp.setUnit0ofDim(1, Vec0temp); try {DVectemp = Float.valueOf(f.vm.DVectf.getText()).floatValue(); } catch (NumberFormatException nfe) {DVectemp = fvol.getDUnitofDim(1); } fvol.setDUnitofDim(1, DVectemp); fp.setDUnitofDim(1, DVectemp); fvol.setUnitsofDim(1, f.vm.VecUnitstf.getText()); fp.setUnitsofDim(1, f.vm.VecUnitstf.getText()); try {Plane0temp = Float.valueOf(f.vm.Plane0tf.getText()).floatValue(); } catch (NumberFormatException nfe) {Plane0temp = fvol.getUnit0ofDim(2); } fvol.setUnit0ofDim(2, Plane0temp); fp.setUnit0ofDim(2, Plane0temp); this.Plane0 = Plane0temp; try {DPlanetemp = Float.valueOf(f.vm.DPlanetf.getText()).floatValue(); } catch (NumberFormatException nfe) {DPlanetemp = fvol.getDUnitofDim(2); } fvol.setDUnitofDim(2, DPlanetemp); fp.setDUnitofDim(2, DPlanetemp); this.DPlane = DPlanetemp; fvol.setUnitsofDim(2, f.vm.PlaneUnitstf.getText()); fp.setUnitsofDim(2, f.vm.PlaneUnitstf.getText()); this.PlaneUnits = f.vm.PlaneUnitstf.getText(); } if (f.vm.ctabchoice.getSelectedIndex() > 0) { ctab = RgCtab.RgCtabs[f.vm.ctabchoice.getSelectedIndex() - 1].ctab; f.props.put("ctable", RgCtab.RgCtabs[f.vm.ctabchoice.getSelectedIndex() - 1].descrip); } } void resetPropsPanel(ViewmatProps f, Panel pp) { f.vm.titletf.setText(title); f.vm.rowsdowncb.setState(rowsdown); f.vm.positivecb.setState(positive); f.vm.vetf.setText("" + ve); if (fvol == null) { f.vm.Amp0tf.setText("" + fp.getAmp0()); f.vm.AmpFactf.setText("" + fp.getAmpFac()); f.vm.AmpUnitstf.setText(fp.getAmpUnits()); /*f.vm.cliptf.setText("" + (clip*fp.getAmpFac() + fp.getAmp0()));*/ f.vm.Elem0tf.setText("" + fp.getUnit0ofDim(0)); f.vm.DElemtf.setText("" + fp.getDUnitofDim(0)); f.vm.ElemUnitstf.setText(fp.getUnitsofDim(0)); f.vm.Vec0tf.setText("" + fp.getUnit0ofDim(1)); f.vm.DVectf.setText("" + fp.getDUnitofDim(1)); f.vm.VecUnitstf.setText(fp.getUnitsofDim(1)); } else { f.vm.Amp0tf.setText("" + fvol.getAmp0()); f.vm.AmpFactf.setText("" + fvol.getAmpFac()); f.vm.AmpUnitstf.setText(fvol.getAmpUnits()); /*f.vm.cliptf.setText("" + (clip*fvol.getAmpFac() + fvol.getAmp0()));*/ f.vm.Elem0tf.setText("" + fvol.getUnit0ofDim(0)); f.vm.DElemtf.setText("" + fvol.getDUnitofDim(0)); f.vm.ElemUnitstf.setText(fvol.getUnitsofDim(0)); f.vm.Vec0tf.setText("" + fvol.getUnit0ofDim(1)); f.vm.DVectf.setText("" + fvol.getDUnitofDim(1)); f.vm.VecUnitstf.setText(fvol.getUnitsofDim(1)); f.vm.Plane0tf.setText("" + fvol.getUnit0ofDim(2)); f.vm.DPlanetf.setText("" + fvol.getDUnitofDim(2)); f.vm.PlaneUnitstf.setText(fvol.getUnitsofDim(2)); } f.vm.ctabchoice.select(0); for (int i=0; i < RgCtab.RgCtabs.length; i++) { if (RgCtab.RgCtabs[i].descrip.equalsIgnoreCase(f.props.getProperty("ctable", ""))) { f.vm.ctabchoice.select(i+1); break; } } } void applyParameters(ViewmatProps f, Panel pp) { f.vm.titletf.setText(f.props.getProperty("title", title)); String tsense = "" + rowsdown; String tpos = "" + positive; boolean temp; temp = Boolean.valueOf(f.props.getProperty("sense", tsense)).booleanValue(); if (f.props.getProperty("sense", tsense).equals("1")) temp = true; else temp = Boolean.valueOf(f.props.getProperty("sense", tsense)).booleanValue(); f.vm.rowsdowncb.setState(temp); temp = Boolean.valueOf(f.props.getProperty("positive", tpos)).booleanValue(); if (f.props.getProperty("positive", tpos).equals("1")) temp = true; else temp = Boolean.valueOf(f.props.getProperty("positive", tpos)).booleanValue(); f.vm.positivecb.setState(temp); f.vm.vetf.setText(f.props.getProperty("ve", "" + ve)); if (fvol == null) { f.vm.Amp0tf.setText(f.props.getProperty("scalelab0", "" + fp.getAmp0())); f.vm.AmpFactf.setText(f.props.getProperty("scalelabfac", "" + fp.getAmpFac())); f.vm.AmpUnitstf.setText(f.props.getProperty("scalelab", fp.getAmpUnits())); f.vm.cliptf.setText(f.props.getProperty("clip", "" + (clip*fp.getAmpFac() + fp.getAmp0()))); f.vm.Elem0tf.setText(f.props.getProperty("xlab0", "" + fp.getUnit0ofDim(0))); f.vm.DElemtf.setText(f.props.getProperty("xlabfac", "" + fp.getDUnitofDim(0))); f.vm.ElemUnitstf.setText(f.props.getProperty("xlab", fp.getUnitsofDim(0))); f.vm.Vec0tf.setText(f.props.getProperty("ylab0", "" + fp.getUnit0ofDim(1))); f.vm.DVectf.setText(f.props.getProperty("ylabfac", "" + fp.getDUnitofDim(1))); f.vm.VecUnitstf.setText(f.props.getProperty("ylab", fp.getUnitsofDim(1))); } else { f.vm.Amp0tf.setText(f.props.getProperty("scalelab0", "" + fvol.getAmp0())); f.vm.AmpFactf.setText(f.props.getProperty("scalelabfac", "" + fvol.getAmpFac())); f.vm.AmpUnitstf.setText(f.props.getProperty("scalelab", fvol.getAmpUnits())); f.vm.cliptf.setText(f.props.getProperty("clip", "" + (clip*fvol.getAmpFac() + fvol.getAmp0()))); f.vm.Elem0tf.setText(f.props.getProperty("xlab0", "" + fvol.getUnit0ofDim(0))); f.vm.DElemtf.setText(f.props.getProperty("xlabfac", "" + fvol.getDUnitofDim(0))); f.vm.ElemUnitstf.setText(f.props.getProperty("xlab", fvol.getUnitsofDim(0))); f.vm.Vec0tf.setText(f.props.getProperty("ylab0", "" + fvol.getUnit0ofDim(1))); f.vm.DVectf.setText(f.props.getProperty("ylabfac", "" + fvol.getDUnitofDim(1))); f.vm.VecUnitstf.setText(f.props.getProperty("ylab", fvol.getUnitsofDim(1))); f.vm.Plane0tf.setText(f.props.getProperty("plab0", "" + fvol.getUnit0ofDim(2))); f.vm.DPlanetf.setText(f.props.getProperty("plabfac", "" + fvol.getDUnitofDim(2))); f.vm.PlaneUnitstf.setText(f.props.getProperty("plab", fvol.getUnitsofDim(2))); } for (int i=0; i < RgCtab.RgCtabs.length; i++) { if (RgCtab.RgCtabs[i].descrip.equalsIgnoreCase(f.props.getProperty("ctable", ""))) { f.vm.ctabchoice.select(i+1); break; } } } void setParameters(ViewmatProps f, Panel pp) { f.props.put("title", title); f.props.put("sense", "" + rowsdown); f.props.put("positive", "" + positive); f.props.put("ve", "" + ve); f.props.put("clip", f.vm.cliptf.getText()); if (fvol == null) { /*f.props.put("clip", "" + (clip*fp.getAmpFac() + fp.getAmp0()));*/ f.props.put("scalelab0", "" + fp.getAmp0()); f.props.put("scalelabfac", "" + fp.getAmpFac()); f.props.put("scalelab", fp.getAmpUnits()); f.props.put("xlab0", "" + fp.getUnit0ofDim(0)); f.props.put("xlabfac", "" + fp.getDUnitofDim(0)); f.props.put("xlab", fp.getUnitsofDim(0)); f.props.put("ylab0", "" + fp.getUnit0ofDim(1)); f.props.put("ylabfac", "" + fp.getDUnitofDim(1)); f.props.put("ylab", fp.getUnitsofDim(1)); } else { /*f.props.put("clip", "" + (clip*fvol.getAmpFac() + fvol.getAmp0()));*/ f.props.put("scalelab0", "" + fvol.getAmp0()); f.props.put("scalelabfac", "" + fvol.getAmpFac()); f.props.put("scalelab", fvol.getAmpUnits()); f.props.put("xlab0", "" + fvol.getUnit0ofDim(0)); f.props.put("xlabfac", "" + fvol.getDUnitofDim(0)); f.props.put("xlab", fvol.getUnitsofDim(0)); f.props.put("ylab0", "" + fvol.getUnit0ofDim(1)); f.props.put("ylabfac", "" + fvol.getDUnitofDim(1)); f.props.put("ylab", fvol.getUnitsofDim(1)); f.props.put("plab0", "" + fvol.getUnit0ofDim(2)); f.props.put("plabfac", "" + fvol.getDUnitofDim(2)); f.props.put("plab", fvol.getUnitsofDim(2)); } } void makePropsPanel(ViewmatProps f, Panel pp) { Label titlelab = new Label("Title:"); pp.add(titlelab); titletf = new TextField(title, 45); pp.add(titletf); rowsdowncb = new Checkbox("Rows Point Down?"); pp.add(rowsdowncb); rowsdowncb.addItemListener(f); Label velab = new Label("Vert. Exagg.:"); pp.add(velab); vetf = new TextField("" + ve, 8); pp.add(vetf); positivecb = new Checkbox("Positive Amplitudes Only?"); pp.add(positivecb); if (fvol == null) { cliptf = new TextField("" + (clip*fp.getAmpFac() + fp.getAmp0()), 8); Amp0tf = new TextField("" + fp.getAmp0(), 4); AmpFactf = new TextField("" + fp.getAmpFac(), 4); AmpUnitstf = new TextField("" + fp.getAmpUnits(), 8); } else { cliptf = new TextField("" + (clip*fvol.getAmpFac() + fvol.getAmp0()), 8); Amp0tf = new TextField("" + fvol.getAmp0(), 4); AmpFactf = new TextField("" + fvol.getAmpFac(), 4); AmpUnitstf = new TextField("" + fvol.getAmpUnits(), 8); } Label cliplab = new Label("Amplitude Clip:"); pp.add(cliplab); pp.add(cliptf); Label Amp0lab = new Label("Ampl.: Zero"); pp.add(Amp0lab); pp.add(Amp0tf); Label AmpFaclab = new Label("Factor"); pp.add(AmpFaclab); pp.add(AmpFactf); Label AmpUnitslab = new Label("Units"); pp.add(AmpUnitslab); pp.add(AmpUnitstf); Label ctablab = new Label("Color Table for Image:"); pp.add(ctablab); ctabchoice = new Choice(); ctabchoice.add("Current Colors"); for (int i=0; i 1) { view.add(new MenuItem("Animation", new MenuShortcut(KeyEvent.VK_A))); view.add(new MenuItem("-")); } zoom = new Menu("Zoom Image To:", true); zoom.add(new MenuItem("100%", new MenuShortcut(KeyEvent.VK_1))); zoom.add(new MenuItem("-")); zoom.add(new MenuItem("10%")); zoom.add(new MenuItem("25%")); zoom.add(new MenuItem("50%", new MenuShortcut(KeyEvent.VK_5))); zoom.add(new MenuItem("75%", new MenuShortcut(KeyEvent.VK_7))); zoom.add(new MenuItem("150%")); zoom.add(new MenuItem("200%", new MenuShortcut(KeyEvent.VK_2))); zoom.add(new MenuItem("500%")); zoom.getItem(0).setEnabled(false); view.add(zoom); zoom.addActionListener(f); view.add(new MenuItem("-")); view.add(openpick = new MenuItem("Pick Window...", new MenuShortcut(KeyEvent.VK_I))); /*openpick.setEnabled(false);*/ view.add(openslope = new MenuItem("Slope Window...", new MenuShortcut(KeyEvent.VK_L))); openslope.setEnabled(false); view.add(new MenuItem("-")); view.add(new MenuItem("About JRG...")); mb.add(view); view.addActionListener(f); /*zoom.addActionListener(f);*/ Menu methods = new Menu("Methods", false); this.inplace = new CheckboxMenuItem("In Place"); methods.add(this.inplace); this.inplace.setState(true); Menu fvmenu = FltVec.makeMethodsMenu(); methods.add(fvmenu); fvmenu.addActionListener(f); Menu fpmenu = FltPlane.makeMethodsMenu(fvol); methods.add(fpmenu); fpmenu.addActionListener(f); if (fvol != null) { Menu fvolmenu = FltVol.makeMethodsMenu(); methods.add(fvolmenu); fvolmenu.addActionListener(f); } mb.add(methods); methods.addActionListener(f); f.makeWindowMenu(); return mb; } public void disableZoom(int ind) { int i; if (ind < 0 || ind >= this.zoom.getItemCount()) return; for (i=0; i 1) { label = new String(getSignif("" + (Plane0 + plane*DPlane)) + " " + PlaneUnits); g.drawString(label, 5, labfm.getAscent()); } /* Scale Bar */ sclx = imx + 40; scly = imy+imh+labfm.getHeight(); sclh = labfm.getAscent(); g.drawImage(sclim, sclx, scly, sclw, sclh, cvs); g.drawRect(sclx, scly, sclw, sclh); lab1 = (positive ? 0F : -clip*fp.AmpFac) + fp.Amp0; lab2 = clip*fp.AmpFac + fp.Amp0; label = fp.getAmpUnits(); g.drawString(label, sclx+(sclw/2)-(labfm.stringWidth(label)/2), scly-labfm.getDescent()); label = getSignif(String.valueOf(lab1)); g.drawString(label, sclx-2-labfm.stringWidth(label), scly+labfm.getAscent()); label = getSignif(String.valueOf(lab2)); g.drawString(label, sclx+sclw+2, scly+labfm.getAscent()); /* Title */ Font titlef = new Font("Helvetica", Font.BOLD|Font.ITALIC, 12); FontMetrics titlefm = g.getFontMetrics(titlef); g.setFont(titlef); g.drawString(title, imx+imw-titlefm.stringWidth(title), imy-titlefm.getAscent()-titlefm.getDescent()); } /* Constructors */ Viewmat(FltVol fvol, int plane, FltPlane fp, String Title, boolean RowsDown, float VertExagg, RgRGB[] ColorTable, boolean PositiveOnly, float Clip) { this.fvol = fvol; this.plane = plane; this.fp = fp; title = Title; rowsdown = RowsDown; ve = VertExagg; ctab = ColorTable; positive = PositiveOnly; this.psplane = 0; npsras = 0; exagg = null; zoom = null; fzoom = 1F; file = null; openbin = null; this.PlaneUnits = new String(fvol.PlaneUnits); this.Plane0 = fvol.Plane0; this.DPlane = fvol.DPlane; if (Clip < 0F) clip = fp.max(); else clip = Clip; sb0 = 0; sbf = fvol.getNMembofDim(2) - 1; this.ConstructWidths(); ch += 48; fh += 48; if (fvol.getNMembofDim(2) < 50) sbw = 50; else if (fvol.getNMembofDim(2) < 100) sbw = 100; else sbw = 200; sbw += 52; } Viewmat(FltPlane fp, String Title, boolean RowsDown, float VertExagg, RgRGB[] ColorTable, boolean PositiveOnly, float Clip) { this.fp = fp; this.fvol = null; this.plane = 0; title = Title; rowsdown = RowsDown; ve = VertExagg; ctab = ColorTable; positive = PositiveOnly; this.psplane = -1; npsras = 0; exagg = null; zoom = null; fzoom = 1F; file = null; openbin = null; PlaneUnits = ""; Plane0 = 0F; DPlane = 1F; if (Clip < 0F) clip = fp.max(); else clip = Clip; sb0 = 0; sbf = 0; sbw = 100; this.ConstructWidths(); } Viewmat(FltPlane fp, String Title, boolean RowsDown, float VertExagg, RgRGB[] ColorTable, boolean PositiveOnly, float Clip, Applet applet) { this.fp = fp; this.fvol = null; this.plane = 0; this.applet = applet; title = Title; rowsdown = RowsDown; ve = VertExagg; ctab = ColorTable; positive = PositiveOnly; this.psplane = -1; npsras = 0; exagg = null; zoom = null; fzoom = 1F; file = null; openbin = null; PlaneUnits = ""; Plane0 = 0F; DPlane = 1F; if (Clip < 0F) clip = fp.max(); else clip = Clip; sb0 = 0; sbf = 0; sbw = 100; this.ConstructWidths(applet.getSize().width, applet.getSize().height); } /* Methods related to construction and plot layout */ void ConstructWidths() { ltgray = new Color(220, 220, 220); imx = 80; imy = 24; setMaxSizes(); imw = fp.getNMembofDim(rowsdown ? 1 : 0); imh = (int)(fp.getNMembofDim(rowsdown ? 0 : 1)*ve); if (imw > MaxImSize) { imh = (int)((float)(MaxImSize)/imw*imh); imw = MaxImSize; } else if (imw < MinImSize) { imh = (int)((float)(MinImSize)/imw*imh); imw = MinImSize; } if (imh > MaxImSize) { imw = (int)((float)(MaxImSize)/imh*imw); imh = MaxImSize; } else if (imh < MinImSize) { imw = (int)((float)(MinImSize)/imh*imw); imh = MinImSize; } if (imw > MaxImSize) { imh = (int)((float)(MaxImSize)/imw*imh); imw = MaxImSize; } if (imh > MaxImSize) { imw = (int)((float)(MaxImSize)/imh*imw); imh = MaxImSize; } cw = imx + imw + 25; ch = imy + imh + 34; if (cw < 300) cw = 300; if (ch < 250) ch = 250; fw = cw+20; fh = ch + 50; if (fw > MaxFrWidth) { fw = MaxFrWidth; } if (fh > MaxFrHeight) { fh = MaxFrHeight; } sclw = 100; } void ConstructWidths(int width, int height) { ltgray = new Color(220, 220, 220); imx = 80; imy = 24; setMaxSizes(); int maxwidth = width - imx -10; if (maxwidth < MinImSize) maxwidth = MinImSize; int maxheight = height - imy - 15; if (maxheight < MinImSize) maxheight = MinImSize; imw = fp.getNMembofDim(rowsdown ? 1 : 0); imh = (int)(fp.getNMembofDim(rowsdown ? 0 : 1)*ve); if (imw > maxwidth) { imh = (int)((float)(MaxFrWidth)/imw*imh); imw = MaxFrWidth; } else if (imw < MinImSize) { imh = (int)((float)(MinImSize)/imw*imh); imw = MinImSize; } if (imh > maxheight) { imw = (int)((float)(MaxFrHeight)/imh*imw); imh = MaxFrHeight; } else if (imh < MinImSize) { imw = (int)((float)(MinImSize)/imh*imw); imh = MinImSize; } if (imw > maxwidth) { imh = (int)((float)(MaxImSize)/imw*imh); imw = MaxImSize; } if (imh > maxheight) { imw = (int)((float)(MaxImSize)/imh*imw); imh = MaxImSize; } cw = imx + imw + 10; ch = imy + imh + 15; if (cw < 300) cw = 300; if (ch < 250) ch = 250; fw = cw; fh = ch + 10; int i; scale = new int[256]; for (i=0; i<256; i++) scale[i] = (255 << 24) | (ctab[i].R << 16) | (ctab[i].G << 8) | ctab[i].B; sclmis = new MemoryImageSource(256, 1, scale, 0, 256); sclim = applet.getToolkit().createImage(sclmis); sclw = 100; } void setMaxSizes() { Dimension screendim = Toolkit.getDefaultToolkit().getScreenSize(); MaxFrWidth = screendim.width - 40; MaxFrHeight = screendim.height - 105; MaxImSize = 2*MaxFrWidth; } void zoom(float zm) { fzoom = zm; imx = 80; imy = 24; setMaxSizes(); imw = fp.getNMembofDim(rowsdown ? 1 : 0); imh = (int)(fp.getNMembofDim(rowsdown ? 0 : 1)*ve); if (imw > MaxImSize) { imh = (int)((float)(MaxImSize)/imw*imh); imw = MaxImSize; } else if (imw < MinImSize) { imh = (int)((float)(MinImSize)/imw*imh); imw = MinImSize; } if (imh > MaxImSize) { imw = (int)((float)(MaxImSize)/imh*imw); imh = MaxImSize; } else if (imh < MinImSize) { imw = (int)((float)(MinImSize)/imh*imw); imh = MinImSize; } imw = (int)(imw*zm); if (imw < 1) imw = 1; imh = (int)(imh*zm); if (imh < 1) imh = 1; if (imw > MaxImSize) { imh = (int)((float)(MaxImSize)/imw*imh); imw = MaxImSize; } if (imh > MaxImSize) { imw = (int)((float)(MaxImSize)/imh*imw); imh = MaxImSize; } cw = imx + imw + 25; ch = imy + imh + 34; if (cw < 300) cw = 300; if (ch < 250) ch = 250; fw = cw+20; fh = ch + 50; if (fw > MaxFrWidth) { fw = MaxFrWidth; } if (fh > MaxFrHeight) { fh = MaxFrHeight; } sclw = 100; if (fvol != null) { ch += 48; fh += 48; } if (f != null && f.picks != null) f.picks.setPickSize(); } void makeScale(ViewmatFrame f) { int i; scale = new int[256]; for (i=0; i<256; i++) scale[i] = (255 << 24) | (ctab[i].R << 16) | (ctab[i].G << 8) | ctab[i].B; sclmis = new MemoryImageSource(256, 1, scale, 0, 256); sclim = f.getToolkit().createImage(sclmis); } /* Methods for creating plots in PostScript */ public void createPSFile(String path, int plane) { if (this.fvol == null) { createPSFile(path); return; } psplane = plane; FltPlane fpl = new FltPlane(this.fvol.nv, this.fvol.ne); fpl.windowof(this.fvol, plane, 0, 1, 0, 1); this.fp = fpl; this.fp.f = this.fvol.f; createPSFile(path); /*fpl.vec = null;*/ } public void createPSFile(String path) { FileOutputStream fos = null; BufferedOutputStream bos = null; PrintStream ps = null; fp.Notice("createPSFile: writing " + fp.vec.length + " elements to file " + path + "... "); try {fos = new FileOutputStream(path); } catch(IOException ioe) { fp.Errout("Can't create file " + path); fp.Errout(ioe.toString()); return; } bos = new BufferedOutputStream(fos); ps = new PrintStream(bos); writePS(ps); try { ps.flush(); bos.flush(); fos.close(); } catch(IOException ioe) { fp.Errout("Can't close PostScript file " + path); fp.Errout(ioe.toString()); return; } fp.Noticeln("done."); } public void writePS(PrintStream ps) { int BITS=8; float LETSIZE=20.0F; float MARGIN=4F; float SEPAR=2.0F; float WINTAB=40F; float RASTERS=300.0F; float POINTS=72.0F; float LM=0.5F; float BM=0.25F; int nx, ny; boolean sense; float letfac=1F; int it, nscale, scalethick; boolean setup; int winwidth, winheight; int num2; int tableread=0; float plotwidth, plotheight, scalewidth, scaleheight, letsize=LETSIZE; float buf[], scalebuf[]; float val, x0, y00, x, y, dx, dy, xbase=0.0F, ybase=0.0F; int pscolor=1, forcecolor=0, pstemp=1; float psfac=1.0F, psx=LM, psy=BM; sense = rowsdown; nx = fp.getNMembofDim(0); ny = fp.getNMembofDim(1); String scalelab = fp.getAmpUnits(); String xlab = fp.getUnitsofDim(0); String ylab = fp.getUnitsofDim(1); float scalelab0 = fp.getAmp0(); float xlab0 = fp.getUnit0ofDim(0); float ylab0 = fp.getUnit0ofDim(1); float scalelabfac = fp.getAmpFac(); float xlabfac = fp.getDUnitofDim(0); float ylabfac = fp.getDUnitofDim(1); float plabfac=1F, plab0=0F; String plab=""; if (psplane > -1) { plabfac = fvol.getDUnitofDim(2); plab0 = fvol.getUnit0ofDim(2); plab = fvol.getUnitsofDim(2); } String picks=""; if (fp.f != null) picks = fp.f.picks.picktext.getText(); letsize = LETSIZE * letfac; float xfac, yfac; if (rowsdown) { yfac = RASTERS/POINTS*(float)(imw)/ny; xfac = RASTERS/POINTS*(float)(imh)/nx; } else { yfac = RASTERS/POINTS*(float)(imh)/ny; xfac = RASTERS/POINTS*(float)(imw)/nx; } scalethick = (int)(yfac>xfac ? yfac : xfac); if (scalethick < 16) scalethick = 16; /*if ((yfac>xfac && !sense) || (yfac<=xfac && sense))*/ if (imw > imh) setup = true; else setup = false; if (!sense) { plotwidth = (float)(xfac * nx); plotheight = (float)(yfac * ny); } else { plotwidth = (float)(yfac * ny); plotheight = (float)(xfac * nx); } if (setup) { winwidth = (int)(RASTERS/POINTS*imw) + (int)(MARGIN*letsize) + 3*(int)(SEPAR); winheight = (int)(RASTERS/POINTS*imh) + (int)(MARGIN*letsize) + 8*(int)(SEPAR) + (int)(letsize); } else { winwidth = (int)(RASTERS/POINTS*imw) + 3*(int)(MARGIN*letsize) + 5*(int)(SEPAR); winheight = (int)(RASTERS/POINTS*imh) + 3*(int)(letsize) + 6*(int)(SEPAR); } winheight += WINTAB; winwidth += WINTAB; /* Send PS Prologue */ int index; ps.println("%!PS-Adobe-2.0"); ps.println("%%BoundingBox: " + ((psx)*POINTS-2F*letsize) + " " + (psy*POINTS) + " " + (POINTS*(psx + winwidth*psfac/RASTERS) + 2F*letsize) + " " + (POINTS*(psy + winheight*psfac/RASTERS)) ); ps.println("%%Title: " + title); ps.println("%%Creator: Viewmat for Java"); ps.println("%%DocumentFonts: Helvetica"); String user; try {user = System.getProperties().getProperty("user.name"); } catch (SecurityException e) {user = "User"; } ps.println("%%For: " + user); Date dt = new Date(); ps.println("%%CreationDate: " + dt.toString()); ps.println("%%Pages: 1"); ps.println("%%EndComments"); ps.println("% PostScript output of Viewmat for Java"); ps.println("% Copyright (c) 1998 John N. Louie"); ps.println("/rast { 0.24 mul } def"); ps.println("/inch { 72 mul } def"); ps.println( "% Change the following 3 lines to move and scale this plot:"); ps.println("/rx0 " + psx + " inch def % Horizontal displacement from bottom left corner"); ps.println("/ry0 " + psy + " inch def % Vertical displacement from bottom left corner"); ps.println("/rscl " + psfac + " def % Scale factor for entire plot"); ps.println("/zerosat 0.35 def % Hardware fill saturation at mid-scale"); ps.println("/colorplot " + (pscolor==1?"true":"false") + " def % true for color Postscript device, false for monochrome"); ps.println("/forcecolor " + (forcecolor==1?"true":"false") + " def % if true laboriously emulate colorimage if not available"); ps.println("/imagetype"); ps.println("\tforcecolor"); ps.println("\t{systemdict /colorimage known {1} {2} ifelse}"); ps.println("\t{colorplot systemdict /colorimage known and {1} {0} ifelse}"); ps.println("\tifelse"); ps.println("def"); ps.println("/sclras {rast rscl mul} def"); ps.println("/rxpos {rx0 exch sclras add} def"); ps.println("/rypos {ry0 exch sclras add} def"); ps.println("/ltext { % x y size rot (string) ltext -"); ps.println(" gsave"); ps.println(" /tstring exch def"); ps.println(" /trot exch def"); ps.println(" /tsize exch def"); ps.println(" /ty exch def"); ps.println(" /tx exch def"); ps.println(" /Helvetica findfont tsize rast rscl mul scalefont setfont"); ps.println(" tx rxpos ty rypos translate"); ps.println(" trot rotate"); ps.println(" 0 0 moveto"); ps.println(" tstring show"); ps.println(" grestore"); ps.println("} def"); ps.println("/rtext { % x y size rot (string) ltext -"); ps.println(" gsave"); ps.println(" /tstring exch def"); ps.println(" /trot exch def"); ps.println(" /tsize exch def"); ps.println(" /ty exch def"); ps.println(" /tx exch def"); ps.println(" /Helvetica findfont tsize rast rscl mul scalefont setfont"); ps.println(" tx rxpos ty rypos translate"); ps.println(" trot rotate"); ps.println(" 0 0 moveto"); ps.println(" tstring dup stringwidth pop neg 0 rmoveto show"); ps.println(" grestore"); ps.println("} def"); ps.println("/ctext { % x y size rot (string) ltext -"); ps.println(" gsave"); ps.println(" /tstring exch def"); ps.println(" /trot exch def"); ps.println(" /tsize exch def"); ps.println(" /ty exch def"); ps.println(" /tx exch def"); ps.println(" /Helvetica findfont tsize rast rscl mul scalefont setfont"); ps.println(" tx rxpos ty rypos translate"); ps.println(" trot rotate"); ps.println(" 0 0 moveto"); ps.println(" tstring dup stringwidth pop 2 div neg 0 rmoveto show"); ps.println(" grestore"); ps.println("} def"); ps.println("/satexp {zerosat ln 2 ln div neg} def"); ps.println("/concatprocs"); ps.println(" { /proc2 exch cvlit def"); ps.println(" /proc1 exch cvlit def"); ps.println(" /newproc proc1 length proc2 length add"); ps.println(" array def"); ps.println(" newproc 0 proc1 putinterval"); ps.println(" newproc proc1 length proc2 putinterval"); ps.println(" newproc cvx"); ps.println(" } def"); ps.println("/box {"); ps.println("/dy exch def"); ps.println("/dx exch def"); ps.println("/y exch def"); ps.println("/x exch def"); ps.println("gsave"); ps.println("newpath"); ps.println("x y moveto"); ps.println("0 dy rlineto"); ps.println("dx 0 rlineto"); ps.println("0 0 dy sub rlineto"); ps.println("closepath"); ps.println("0.2 setlinewidth"); ps.println("stroke"); ps.println("grestore"); ps.println("} def"); ps.println("/pbox {"); ps.println("/dy exch def"); ps.println("/dx exch def"); ps.println("/y exch def"); ps.println("/x exch def"); ps.println("gsave"); ps.println("newpath"); ps.println("x y moveto"); ps.println("0 dy rlineto"); ps.println("dx 0 rlineto"); ps.println("0 0 dy sub rlineto"); ps.println("closepath"); ps.println("1 setlinewidth"); ps.println("stroke"); ps.println("grestore"); ps.println("} def"); ps.println("% define color table"); ps.println("/colortable {"); ps.println(" /colarray ["); ps.println(" 256 {"); ps.println(" [ 3 { currentfile token pop } repeat ]"); ps.println(" } repeat"); ps.println(" ] def } def"); ps.println("colortable"); for (index=0; index<256; index++) ps.println("" + ctab[index].R/255F + " " + ctab[index].G/255F + " " + ctab[index].B/255F); ps.println(""); ps.println("imagetype 1 eq {"); ps.println(" /indexstr 1 string def"); ps.println(" /colstrarray 256 array def"); ps.println(" /ind 0 def"); ps.println(" colarray {"); ps.println(" aload pop 3 {255 mul cvi 3 1 roll} repeat"); ps.println(" /rgbstr 3 string def"); ps.println(" rgbstr exch 2 exch put"); ps.println(" rgbstr exch 1 exch put"); ps.println(" rgbstr exch 0 exch put"); ps.println(" colstrarray ind rgbstr put /ind ind 1 add def"); ps.println(" } forall"); ps.println("} if"); ps.println("/setacolor { colarray exch get aload pop setrgbcolor } bind def"); ps.println("false { % no background, draw with default"); ps.println("%colorplot { % fill background with ctab[0] and draw with ctab[127]"); ps.println(" newpath"); ps.println(" 0 0 moveto"); ps.println(" 0 11 inch lineto"); ps.println(" 8.5 inch 11 inch lineto"); ps.println(" 8.5 inch 0 inch lineto"); ps.println(" closepath"); ps.println(" 0 setacolor"); ps.println(" fill"); ps.println(" 127 setacolor"); ps.println(" } if"); ps.println("/cimage {"); ps.println(" /readproc exch def"); ps.println(" concat"); ps.println(" /cheight exch def"); ps.println(" /cwidth exch def"); ps.println(" /dheight 1 cheight div def"); ps.println(" /dwidth 1 cwidth div def"); ps.println(" newpath"); ps.println(" 0 1 cheight 1 sub {"); ps.println(" /yheight exch def"); ps.println(" /datastring readproc def"); ps.println(" 0 1 cwidth 1 sub {"); ps.println(" yheight exch dup datastring exch get cpixel"); ps.println(" } for"); ps.println(" } for"); ps.println(" } def"); ps.println("/cpixel {"); ps.println(" 3 1 roll"); ps.println(" dwidth mul exch dheight mul moveto"); ps.println(" 0 dheight rlineto"); ps.println(" dwidth 0 rlineto"); ps.println(" 0 dheight neg rlineto"); ps.println(" closepath"); ps.println(" setacolor fill"); ps.println(" } bind def"); ps.println("%%EndProlog"); ps.println("%%Page: ? ?"); if (ps.checkError()) { fp.Errout("Could not write PostScript Prologue to PrintStream " + ps.toString()); return; } nscale = sclw; scalebuf = new float[nscale]; int scalenx, scaleny; for (it=0; it plotwidth) scalewidth = plotwidth; } else { if (scaleheight < 20F*letsize) scaleheight = 20F*letsize; if (scaleheight > plotheight) scaleheight = plotheight; } if (scalewidth < 16.0F) scalewidth = 16.0F; if (scaleheight < 16.0F) scaleheight = 16.0F; if (setup) { x0 = MARGIN*letsize + 2.0F*SEPAR; y00 = scaleheight+SEPAR+1.5F*letsize+2.0F*SEPAR + letsize; } else { x0 = scalewidth + 3.0F*MARGIN*letsize + 4.0F*SEPAR; y00 = SEPAR + letsize; } /* Send converted images */ if (!sense) psputrast(ps, x0, y00, fp.vec, nx, ny, plotwidth, plotheight, positive, clip, sense); else psputrast(ps, x0, y00, fp.vec, ny, nx, plotwidth, plotheight, positive, clip, sense); if (ps.checkError()) { fp.Errout("Could not write " + fp.vec.length + "-pixel PostScript Image to PrintStream " + ps.toString()); return; } /* Send picks */ if (picks.length() > 7) { ps.println("% Pick marks follow:"); ps.println("gsave"); ps.println("0.5 0 0 setrgbcolor"); if (!sense) ViewmatPicks.pspicks(ps, x0, y00, picks, nx, ny, plotwidth, plotheight, sense, psplane); else ViewmatPicks.pspicks(ps, x0, y00, picks, ny, nx, plotwidth, plotheight, sense, psplane); ps.println("grestore"); if (ps.checkError()) { fp.Errout("Could not write picks to PrintStream " + ps.toString()); return; } } /* Send labels */ if (psplane > -1) { x0 = 2.0F*SEPAR - xbase; y00 = (float)(winheight) - 5.0F*SEPAR - 1.2F*letsize - ybase; pstext(ps, x0, y00, letsize, 0.0F, getSignif("" + (plab0+(float)(psplane)*plabfac)) + " " + plab); } if (setup) { x0 = MARGIN*letsize + 1.0F*SEPAR; y00 = scaleheight + plotheight + 2.0F*letsize + 3.0F*SEPAR; } else { x0 = scalewidth + 3.0F*MARGIN*letsize + 3.0F*SEPAR; y00 = plotheight + SEPAR; } psrtext(ps, x0-2.0F*SEPAR, y00-(setup?letsize/2.0F:letsize/3.0F), letsize, 0.0F, getSignif("" + (sense?xlab0:ylab0))); psrtext(ps, x0-2.0F*SEPAR, y00-plotheight+letsize -(setup?letsize/2.0F:0.0F*SEPAR), letsize, 0.0F, getSignif("" + (sense?xlab0+nx*xlabfac:ylab0+ny*ylabfac))); psctext(ps, x0-2.0F*SEPAR-letsize, y00-plotheight/2.0F, letsize, 90.0F, (sense?xlab:ylab)); pstext(ps, x0, y00+2.0F*SEPAR+0.5F*letsize+(setup?letsize/4.0F:letsize/1.7F), letsize, 0.0F, getSignif("" + (sense?ylab0:xlab0))); psrtext(ps, x0+plotwidth, y00+2.0F*SEPAR+0.5F*letsize +(setup?letsize/4.0F:letsize/1.7F), letsize, 0.0F, getSignif("" + (sense?ylab0+ny*ylabfac:xlab0+nx*xlabfac))); psctext(ps, x0+plotwidth/2.0F, y00+SEPAR+1.5F*letsize, letsize, 0.0F, (sense?ylab:xlab)); x0 = (float)(winwidth) - xbase - 4F*SEPAR; y00 = (float)(winheight) - 5.0F*SEPAR - letsize/2F - ybase; psrtext(ps, x0, y00-letsize/1.7F, 1.2F*letsize, 0.0F, title); /* Send labeled scale bar */ if (setup) { x0 = MARGIN*letsize + 2.0F*SEPAR; y00 = SEPAR; psputrast(ps, x0, y00, scalebuf, scalenx, scaleny, scalewidth, scaleheight, positive, clip, sense); psrtext(ps, x0-2.0F*SEPAR, y00, letsize, 0.0F, getSignif("" + (scalelab0+scalelabfac*(positive?0.0F:-clip)))); pstext(ps, x0+scalewidth+2.0F*SEPAR, y00, letsize, 0.0F, getSignif("" + (scalelab0+scalelabfac*clip))); y00 = scaleheight+2.0F*SEPAR; psctext(ps, x0+scalewidth/2.0F, y00+SEPAR+letsize/2.0F, letsize, 0.0F, scalelab); } else { x0 = 1.5F*MARGIN*letsize + 4.0F*SEPAR; y00 = SEPAR + letsize; psputrast(ps, x0, y00, scalebuf, scalenx, scaleny, scalewidth, scaleheight, positive, clip, sense); x0 = 1.5F*MARGIN*letsize + 2.0F*SEPAR; y00 = SEPAR; psrtext(ps, x0-2.0F*SEPAR, y00+scaleheight-letsize/3.0F, letsize, 0.0F, getSignif("" + (scalelab0+scalelabfac*(positive?0.0F:-clip)))); psrtext(ps, x0-2.0F*SEPAR, y00+letsize, letsize, 0.0F, getSignif("" + (scalelab0+scalelabfac*clip))); psctext(ps, x0-SEPAR-letsize, y00+scaleheight/2.0F, letsize, 90.0F, scalelab); } if (ps.checkError()) { fp.Errout("Could not write labels to PrintStream " + ps.toString()); return; } /* Send end of PostScript plot */ ps.println("/#copies 1 def"); ps.println("showpage"); ps.println("%%EndPage"); ps.println("%%Trailer"); ps.println("%%EOF"); if (ps.checkError()) { fp.Errout("Could not write PostScript Trailer to PrintStream " + ps.toString()); return; } } /* Methods leftover from /rg/viewmat.c */ public static void pstext(PrintStream ps, float x, float y, float size, float orient, String s) { ps.println("" + x + " " + y + " " + (1.8*size) + " " + orient + " (" + s + ") ltext"); } public static void psrtext(PrintStream ps, float x, float y, float size, float orient, String s) { ps.println("" + x + " " + y + " " + (1.8*size) + " " + orient + " (" + s + ") rtext"); } public static void psctext(PrintStream ps, float x, float y, float size, float orient, String s) { ps.println("" + x + " " + y + " " + (1.8*size) + " " + orient + " (" + s + ") ctext"); } public static void psltext(PrintStream ps, float x, float y, float size, float orient, String s) { pstext(ps, x, y, size, orient, s); } public static void psputrast(PrintStream ps, float xr, float yr, float fbuf[], int rnx, int rny, float xrsize, float yrsize, boolean positive, float clip, boolean sense) { int lines, chars, index; float pclip, val; npsras++; pclip = positive ? clip : 2.0F*clip; if (pclip == 0.0F) pclip = 1.0F; ps.println("/picstr" + npsras + " " + rnx + " string def"); ps.println("/imagefile" + npsras); ps.println("{ imagetype 1 eq imagetype 2 eq or"); ps.println(" { imagetype 1 eq"); ps.println(" { " + rnx + " " + rny + " 8 [" + rnx + " 0 0 -" + rny + " 0 " + rny + "]"); ps.println(" { currentfile indexstr readhexstring pop 0 get colstrarray exch get }"); ps.println(" false 3 colorimage }"); ps.println(" { " + rnx + " " + rny + " [1 0 0 -1 0 1] { currentfile picstr" + npsras + " readhexstring pop } cimage}"); ps.println(" ifelse }"); ps.println(" { " + rnx + " " + rny + " 8 [" + rnx + " 0 0 -" + rny + " 0 " + rny + "]"); ps.println(" { currentfile picstr" + npsras + " readhexstring pop } image}"); ps.println("ifelse } def"); ps.println(""); ps.println("gsave"); ps.println(""); ps.println(" " + xr + " rxpos " + yr + " rypos translate"); ps.println(" " + xrsize + " sclras " + yrsize + " sclras scale"); ps.println(" imagetype 0 eq {"); ps.println(" {satexp exp 1 exch sub} currenttransfer concatprocs"); ps.println(" settransfer} if"); ps.println(""); ps.println(" imagefile" + npsras); for (lines=0; lines 0) index = (int)(254.0F*val/pclip) + 1; else index = 0; if (index > 255) index = 255; if (index < 16) ps.print("0" + Integer.toHexString(index)); else ps.print(Integer.toHexString(index)); if ((chars*2)%80 == 0 && chars != 0) { ps.println(""); ps.print(" "); } } ps.println(""); } ps.println(""); ps.println("grestore"); ps.println("" + xr + " rxpos " + yr + " rypos "); ps.println("" + xrsize + " sclras " + yrsize + " sclras box"); ps.println(""); } /* Method helping display of float numbers */ static String getSignif(String flt) { return getSignif(flt, 8); } static String getSignif(String flt, int sig) { int i, dot, exp; float val, aval; if (sig < 8) sig = 8; if (flt.length() < sig) return flt; dot = flt.indexOf('.'); exp = flt.indexOf('E'); if (exp < 0 || exp >= flt.length()) exp = flt.indexOf('e'); if (dot < 1 || dot >= flt.length()) return flt; try {val = Float.valueOf(flt).floatValue(); } catch (NumberFormatException nfe) {return flt; } aval = val < 0F ? -val : val; if (aval < 1F && (exp < 0 || exp > flt.length())) { if (val < 0F) return flt.substring(0, sig); return flt.substring(0, sig-1); } if (val < 0F) { if (dot > (sig-1)) return flt.substring(0, dot-1); if (dot == (sig-1)) return flt.substring(0, sig); if (dot == 2 && exp > dot && exp < flt.length()) return flt.substring(0, sig-2) + flt.substring(exp); return flt.substring(0, sig-1); } if (dot > (sig-2)) return flt.substring(0, dot-1); if (dot == (sig-2)) return flt.substring(0, sig-1); if (dot == 1 && exp > dot && exp < flt.length()) return flt.substring(0, sig-3) + flt.substring(exp); return flt.substring(0, sig-2); } /* Standalone application to bring up frame and menus for interactive processing */ public static void main(String args[]) { FltPlane fp = new FltPlane(100, 100); fp.Noticeln(""); fp.Noticeln(RgCopyright.Statement); fp.viewinFrame("100x100 Zero Plane", false, 1F, RgCtab.vagray, false, 1F); } /* End of Viewmat class */ }