📄 dextractor.java
字号:
setFont(new Font("Helvetica", Font.PLAIN, 10)); apanel = new Steeringstuff(actbuts, 5, this); fnamefield = new TextField(targetFName, 20); this.setLayout(layout); this.magGlass = new MagGlass(); this.hgg = new GaugeGauge("x", this.hcolor, false, this); this.vgg = new GaugeGauge("y", this.vcolor, true, this); this.results = new TextArea("", 9, 40); this.rulerLabel = new Label(" "); this.imzone = new ImageWithPoints(this, magGlass, recSettings); helppanel.setLayout(new GridBagLayout()); c.fill = GridBagConstraints.BOTH; c.gridy = 0; ((GridBagLayout)helppanel.getLayout()).setConstraints(apanel,c); helppanel.add(apanel); c.gridy = 1; ((GridBagLayout)helppanel.getLayout()).setConstraints(vgg,c); helppanel.add(vgg); c.gridy = 2; ((GridBagLayout)helppanel.getLayout()).setConstraints(magGlass,c); helppanel.add(magGlass); c.gridheight = 3; c.gridwidth = 1; c.gridx = 0; c.gridy = 0; c.fill = GridBagConstraints.NONE; c.weightx = 0; c.weighty = 1; c.anchor = GridBagConstraints.NORTH; layout.setConstraints(helppanel, c); add(helppanel); c.anchor = GridBagConstraints.CENTER; c.fill = GridBagConstraints.BOTH; c.gridwidth=GridBagConstraints.REMAINDER; c.gridheight=1; c.weightx = 1; c.weighty = 1; c.gridx = 1; c.gridy = 0; layout.setConstraints(this.scrollp, c); add(this.scrollp); scrollp.add(this.imzone); c.fill = GridBagConstraints.NONE; c.gridwidth = 1; c.weightx = 1; c.weighty = 0; c.gridx = 1; c.gridy = 1; layout.setConstraints(hgg, c); add(hgg); zwp = new Panel(); lab = new Label("File name:"); zwp.add(lab); zwp.add(fnamefield); c.gridx = 2; add(zwp); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridwidth=GridBagConstraints.REMAINDER; c.gridy = 2; layout.setConstraints(results, c); add(results); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridwidth=GridBagConstraints.REMAINDER; c.gridy = 3; c.gridx = 0; rulerLabel.setBackground(Color.white); layout.setConstraints(rulerLabel, c); add(rulerLabel); } // the layout manager kept giving me rubbish here, so I fumble together // something that might be remotely sensible public Dimension getPreferredSize() { return new Dimension( Math.max(this.magGlass.getPreferredSize().width, this.apanel.getPreferredSize().width)+ this.imzone.getPreferredSize().width+20, Math.max(this.helppanel.getPreferredSize().height+20, this.imzone.getPreferredSize().height+40)+ this.hgg.getPreferredSize().height+ this.results.getPreferredSize().height+40+ this.rulerLabel.getPreferredSize().height); } public Dimension getMinimumSize() { return new Dimension(600,400); } public synchronized void resizeToPreferredSize() { Dimension pS=getPreferredSize(); Dimension screenS=java.awt.Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(new Dimension( Math.min(screenS.width-40, Math.max(600, pS.width)), Math.min(screenS.height-40, Math.max(400, pS.height)))); validate(); repaint(); // Incredibly nasty hack -- how do I keep the titlebar from // vanishing on some platforms sanely? And why is it that // setLocation(getLocation) is not idempotent? if (this.isShowing() && this.getLocation().y<10) { this.setLocation(20, 40); } } private void newimagescale(int newscale) { Image im; imzone.newScale(scale, newscale); im = imageGetter.getImage(newscale, bbox); imzone.setImage(im); magGlass.setImage(im); scale = newscale; resizeToPreferredSize(); } public void closeWin() { setVisible(false); if (recSettings.isShowing()) { recSettings.close(); } myparent.childClosed(); } public void actionPerformed(ActionEvent e) { if (e.getActionCommand()=="Close") { closeWin(); } if (e.getActionCommand()=="75 dpi") { newimagescale(8); } if (e.getActionCommand()=="100 dpi") { newimagescale(6); } if (e.getActionCommand()=="200 dpi") { newimagescale(3); } if (e.getActionCommand()=="300 dpi") { newimagescale(2); } if (e.getActionCommand()=="600 dpi") { newimagescale(1); } if ((e.getActionCommand()=="Show Data") || (e.getActionCommand()=="Send Data") || (e.getActionCommand()=="Save Data")) { try { makedata(); } catch (CantComputeException exc) { return; } if (e.getActionCommand()=="Save Data") { dataDeliverer.deliver(results.getText(), fnamefield.getText(), 1); } if (e.getActionCommand()=="Send Data") { dataDeliverer.deliver(results.getText(), fnamefield.getText(), 0); } } if (e.getActionCommand()=="Help") myparent.showHelp(); if (e.getActionCommand()=="About Dexter") { new AlertBox(this, "About Dexter", "Dexter -- Data extraction applet"+ "\nRelease 0.5"+ "\nA part of the NASA Astrophysics Data System\n"+ "http://adswww.harvard.edu\n"); } if (e.getActionCommand()=="Trace a Line") { this.startRecogniser("LineTracer"); } if (e.getActionCommand()=="Find Points") { this.startRecogniser("PointFinder"); } if (e.getActionCommand()=="Automatic Axes") { this.startRecogniser("AxisFinder"); } if (e.getActionCommand()=="Recognizer Settings") { this.recSettings.open(); } if (e.getActionCommand()=="Stop Recognizer") { this.stopRecogniser(); } if (e.getActionCommand()=="Delete all Points") { this.imzone.delAllPoints(); } } protected void enableCritical(boolean enable) { for (Iterator<Component> it=this.criticalComponents.iterator(); it.hasNext();) { it.next().setEnabled(enable); } for (Iterator<MenuItem> it=this.criticalMenuItems.iterator(); it.hasNext();) { it.next().setEnabled(enable); } } protected synchronized void startRecogniser(String recName) { if (!this.imzone.startRecogniser(recName)) { new AlertBox(this, "Dexter Error Message", "Unknown Recognizer or\n"+ "recognizer already running."); return; } recogniserRunning = true; enableCritical(false); stopRecogniserItem.setEnabled(true); } synchronized void recogniserStopped() { recogniserRunning = false; stopRecogniserItem.setEnabled(false); enableCritical(true); } synchronized void stopRecogniser() { if (recogniserRunning) imzone.stopRecogniser(); recogniserStopped(); } // Compute the transformation -- zerox and zeroy are the zero points // of the axes in pixel coordinates, xaxis and yaxis are unit vectors // of these axes, islog[i] is true when the respective axis is // logarithmic protected void computeTransform() throws CantComputeException { try { this.transformation = new AffineTrafo( imzone.hgauge.start, imzone.vgauge.start, imzone.hgauge.end, imzone.vgauge.end, this.hgg.getstart(), this.hgg.getend(), this.vgg.getstart(), this.vgg.getend(), this.hgg.isLogAxis(), this.vgg.isLogAxis()); } catch (java.lang.NumberFormatException e) { this.transformation = null; throw new CantComputeException("You must fill out both"+ " horizontal and vertical\n gauge number fields with sensible values"); } catch (NullPointerException e) { this.transformation = null; throw new CantComputeException("Both axes must be defined"+ " before value\nreadout is possible.\n Click and drag to"+ " define axes."); } catch (MissingData e) { this.transformation = null; throw new CantComputeException(e.getMessage()); } } private void makedata_orth() { Datapoint points[]; boolean needVertBars=false, needHorizBars=false; // Update transform and bail out if we don't have enough // data to transform try { this.computeTransform(); } catch (CantComputeException e) { new AlertBox(this, "Dexter Error", e.getMessage()); return; } points = this.imzone.getPoints(); // sort for abscissa value QuickSort.getInstance().sort( points, 0, points.length-1, points[0]); // check if we need to give error bars for (int i=0; i<points.length; i++) { Datapoint pt = points[i]; needHorizBars |= pt.hasHorizErrBars(); needVertBars |= pt.hasVertErrBars(); } results.setText(datasetName+"\n"); int sigFigX = this.hgg.computeUsefulSignificantDigits(); int sigFigY = this.vgg.computeUsefulSignificantDigits(); for (int i=0; i<points.length; i++) { results.append(points[i].getRepr( needHorizBars, needVertBars, sigFigX, sigFigY)); } } public void makedata() { makedata_orth(); } /** * returns logical coordinates for the screen coordinates coo if a * logical coordinate system is already defined, a DoublePoint for coo * otherwise. */ public DoublePoint transformPhysicalToLogical(Point coo) { DoublePoint pt = new DoublePoint(coo); if (this.transformation!=null) { pt = this.transformation.transformPhysicalToLogical(coo); } return pt; } public void displayMousePos(Point mousePos) { if (statusLocked) { return; } DoublePoint pt = this.transformPhysicalToLogical(mousePos); String posTx = Fmt.fmt(pt.getX(), 4, this.hgg.computeUsefulSignificantDigits())+" / "+ Fmt.fmt(pt.getY(), 4, this.vgg.computeUsefulSignificantDigits()); if (recogniserRunning) { posTx = posTx+" Recog. running"; } rulerLabel.setText(posTx); } public boolean allocStatusLine(String msg) { if (statusLocked) return false; statusLocked = true; rulerLabel.setText(msg); return true; } public void releaseStatusLine() { statusLocked = false; rulerLabel.setText(""); } public void componentHidden(ComponentEvent e) {} public void componentMoved(ComponentEvent e) {} public void componentResized(ComponentEvent e) {} public void componentShown(ComponentEvent e) { this.resizeToPreferredSize(); }}// vi:ts=2:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -