/** * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>, * <code>nohref</code> Attribute for the specified figure and ellipse. * * @return Returns true, if the circle is inside of the image bounds. */ private boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, Ellipse2D.Double ellipse) { AffineTransform t = TRANSFORM.getClone(f); if (t == null) { t = drawingTransform; } else { t.preConcatenate(drawingTransform); } if ((t.getType() & (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) == t.getType() && ellipse.width == ellipse.height ) { Point2D.Double start = new Point2D.Double(ellipse.x, ellipse.y); Point2D.Double end = new Point2D.Double(ellipse.x + ellipse.width, ellipse.y + ellipse.height); t.transform(start, start); t.transform(end, end); ellipse.x = Math.min(start.x, end.x); ellipse.y = Math.min(start.y, end.y); ellipse.width = Math.abs(start.x - end.x); ellipse.height = Math.abs(start.y - end.y); elem.setAttribute("shape", "circle"); elem.setAttribute("coords", (int) (ellipse.x + ellipse.width / 2d)+","+ (int) (ellipse.y + ellipse.height / 2d)+","+ (int) (ellipse.width / 2d) ); writeHrefAttribute(elem, f); return bounds.intersects(ellipse.getBounds()); } else { return writePolyAttributes(elem, f, (Shape) ellipse); } }
@Override public void keyTyped(final KeyEvent e) { if (undo == null || control(e) || DELNEXT.is(e) || DELPREV.is(e) || ESCAPE.is(e)) return; text.pos(text.cursor()); // string to be added String ch = String.valueOf(e.getKeyChar()); // remember if marked text is to be deleted boolean del = true; final byte[] txt = text.text(); if (TAB.is(e)) { if (text.marked()) { // check if lines are to be indented final int s = Math.min(text.pos(), text.start()); final int l = Math.max(text.pos(), text.start()) - 1; for (int p = s; p <= l && p < txt.length; p++) del &= txt[p] != '\n'; if (!del) { text.indent(s, l, e.isShiftDown()); ch = null; } } else { boolean c = true; for (int p = text.pos() - 1; p >= 0 && c; p--) { final byte b = txt[p]; c = ws(b); if (b == '\n') break; } if (c) ch = " "; } } // delete marked text if (text.marked() && del) text.delete(); if (ENTER.is(e)) { // adopt indentation from previous line final StringBuilder sb = new StringBuilder(1).append(e.getKeyChar()); int s = 0; for (int p = text.pos() - 1; p >= 0; p--) { final byte b = txt[p]; if (b == '\n') break; if (b == '\t') { s += 2; } else if (b == ' ') { s++; } else { s = 0; } } for (int p = 0; p < s; p++) sb.append(' '); ch = sb.toString(); } if (ch != null) text.add(ch); text.setCaret(); rend.calc(); showCursor(2); e.consume(); }
/** * Ensures that the caret is visible by scrolling the text area if necessary. * * @return True if scrolling was actually performed, false if the caret was already visible */ public boolean scrollToCaret() { int line = getCaretLine(); int lineStart = getLineStartOffset(line); int offset = Math.max(0, Math.min(getLineLength(line) - 1, getCaretPosition() - lineStart)); return scrollTo(line, offset); }
/** * Ensures that the specified line and offset is visible by scrolling the text area if necessary. * * @param line The line to scroll to * @param offset The offset in the line to scroll to * @return True if scrolling was actually performed, false if the line and offset was already * visible */ public boolean scrollTo(int line, int offset) { // visibleLines == 0 before the component is realized // we can't do any proper scrolling then, so we have // this hack... if (visibleLines == 0) { setFirstLine(Math.max(0, line - electricScroll)); return true; } int newFirstLine = firstLine; int newHorizontalOffset = horizontalOffset; if (line < firstLine + electricScroll) { newFirstLine = Math.max(0, line - electricScroll); } else if (line + electricScroll >= firstLine + visibleLines) { newFirstLine = (line - visibleLines) + electricScroll + 1; if (newFirstLine + visibleLines >= getLineCount()) newFirstLine = getLineCount() - visibleLines; if (newFirstLine < 0) newFirstLine = 0; } int x = _offsetToX(line, offset); int width = painter.getFontMetrics().charWidth('w'); if (x < 0) { newHorizontalOffset = Math.min(0, horizontalOffset - x + width + 5); } else if (x + width >= painter.getWidth()) { newHorizontalOffset = horizontalOffset + (painter.getWidth() - x) - width - 5; } return setOrigin(newFirstLine, newHorizontalOffset); }
private void getintbright() { weights = new float[ncurves][xpts][ypts]; for (int i = 0; i < ncurves; i++) { nmeas[i] = 0; for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { nmeas[i] += (int) pch[i][j][k]; } } double tempavg = 0.0; double tempavg2 = 0.0; double temp2avg = 0.0; double temp2avg2 = 0.0; double tempccavg = 0.0; for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { double normed = (double) pch[i][j][k] / (double) nmeas[i]; if (pch[i][j][k] > 0.0f) { weights[i][j][k] = (float) ((double) nmeas[i] / (normed * (1.0f - normed))); } else { weights[i][j][k] = 1.0f; } tempavg += normed * (double) j; tempavg2 += normed * (double) j * (double) j; temp2avg += normed * (double) k; temp2avg2 += normed * (double) k * (double) k; tempccavg += normed * (double) k * (double) j; } } tempccavg -= tempavg * temp2avg; brightcc[i] = tempccavg / Math.sqrt(tempavg * temp2avg); tempavg2 -= tempavg * tempavg; tempavg2 /= tempavg; bright1[i] = (tempavg2 - 1.0); temp2avg2 -= temp2avg * temp2avg; temp2avg2 /= temp2avg; bright2[i] = (temp2avg2 - 1.0); intensity1[i] = tempavg; intensity2[i] = temp2avg; if (psfflag == 0) { bright1[i] /= 0.3536; bright2[i] /= 0.3536; brightcc[i] /= 0.3536; } else { if (psfflag == 1) { bright1[i] /= 0.078; bright2[i] /= 0.078; brightcc[i] /= 0.078; } else { bright1[i] /= 0.5; bright2[i] /= 0.5; brightcc[i] /= 0.5; } } number1[i] = intensity1[i] / bright1[i]; number2[i] = intensity2[i] / bright2[i]; brightmincc[i] = (bright1[i] * beta) * Math.sqrt(intensity1[i] / intensity2[i]); } }
@Override public final void mouseDragged(final MouseEvent e) { if (!SwingUtilities.isLeftMouseButton(e)) return; // selection mode select(e.getPoint(), false); final int y = Math.max(20, Math.min(e.getY(), getHeight() - 20)); if (y != e.getY()) scroll.pos(scroll.pos() + e.getY() - y); }
/** * Draw every char in separate terminal cell to guaranty equal width for different lines. * Nevertheless to improve kerning we draw word characters as one block for monospaced fonts. */ private void drawChars(int x, int y, CharBuffer buf, TextStyle style, Graphics2D gfx) { final int blockLen = 1; int offset = 0; int drawCharsOffset = 0; // workaround to fix Swing bad rendering of bold special chars on Linux // TODO required for italic? CharBuffer renderingBuffer; if (mySettingsProvider.DECCompatibilityMode() && style.hasOption(TextStyle.Option.BOLD)) { renderingBuffer = CharUtils.heavyDecCompatibleBuffer(buf); } else { renderingBuffer = buf; } while (offset + blockLen <= buf.length()) { if (renderingBuffer.getBuf()[buf.getStart() + offset] == CharUtils.DWC) { offset += blockLen; drawCharsOffset += blockLen; continue; // dont' draw second part(fake one) of double width character } Font font = getFontToDisplay(buf.charAt(offset + blockLen - 1), style); // while (myMonospaced && (offset + blockLen < buf.getLength()) && // isWordCharacter(buf.charAt(offset + blockLen - 1)) // && (font == getFontToDisplay(buf.charAt(offset + blockLen - 1), style))) { // blockLen++; // } gfx.setFont(font); int descent = gfx.getFontMetrics(font).getDescent(); int baseLine = (y + 1) * myCharSize.height - descent; int xCoord = (x + drawCharsOffset) * myCharSize.width; int textLength = CharUtils.getTextLengthDoubleWidthAware( buf.getBuf(), buf.getStart() + offset, blockLen, mySettingsProvider.ambiguousCharsAreDoubleWidth()); int yCoord = y * myCharSize.height; gfx.setClip( xCoord, yCoord, Math.min(textLength * myCharSize.width, getWidth() - xCoord), Math.min(myCharSize.height, getHeight() - yCoord)); gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun()))); gfx.drawChars(renderingBuffer.getBuf(), buf.getStart() + offset, blockLen, xCoord, baseLine); drawCharsOffset += blockLen; offset += blockLen; } gfx.setClip(null); }
/** * Move the cursor <i>where</i> characters, withough checking the current buffer. * * @see #where * @param where the number of characters to move to the right or left. */ private final void moveInternal(final int where) throws IOException { // debug ("move cursor " + where + " (" // + buf.cursor + " => " + (buf.cursor + where) + ")"); buf.cursor += where; char c; if (where < 0) { int len = 0; for (int i = buf.cursor; i < buf.cursor - where; i++) { if (buf.getBuffer().charAt(i) == '\t') len += TAB_WIDTH; else len++; } char cbuf[] = new char[len]; Arrays.fill(cbuf, BACKSPACE); out.write(cbuf); return; } else if (buf.cursor == 0) { return; } else if (mask != null) { c = mask.charValue(); } else { printCharacters(buf.buffer.substring(buf.cursor - where, buf.cursor).toCharArray()); return; } // null character mask: don't output anything if (NULL_MASK.equals(mask)) { return; } printCharacters(c, Math.abs(where)); }
/** * Draws the specified string. * * @param g graphics reference * @param s text * @param x x coordinate * @param y y coordinate * @param w width * @param fs font size */ public static void chopString( final Graphics g, final byte[] s, final int x, final int y, final int w, final int fs) { if (w < 12) return; final int[] cw = fontWidths(g.getFont()); int j = s.length; try { int l = 0; int fw = 0; for (int k = 0; k < j; k += l) { final int ww = width(g, cw, cp(s, k)); if (fw + ww >= w - 4) { j = Math.max(1, k - l); if (k > 1) fw -= width(g, cw, cp(s, k - 1)); g.drawString("..", x + fw, y + fs); break; } fw += ww; l = cl(s, k); } } catch (final Exception ex) { Util.debug(ex); } g.drawString(string(s, 0, j), x, y + fs); }
@Override public void keyTyped(final KeyEvent e) { if (!hist.active() || control(e) || DELNEXT.is(e) || DELPREV.is(e) || ESCAPE.is(e) || CUT2.is(e)) return; final int caret = editor.pos(); // remember if marked text is to be deleted final StringBuilder sb = new StringBuilder(1).append(e.getKeyChar()); final boolean indent = TAB.is(e) && editor.indent(sb, e.isShiftDown()); // delete marked text final boolean selected = editor.selected() && !indent; if (selected) editor.delete(); final int move = ENTER.is(e) ? editor.enter(sb) : editor.add(sb, selected); // refresh history and adjust cursor position hist.store(editor.text(), caret, editor.pos()); if (move != 0) editor.pos(Math.min(editor.size(), caret + move)); // adjust text height scrollCode.invokeLater(true); e.consume(); }
private static Color lighter(Color col) { int hsl[] = new int[3]; Utils.rgb2hsl(col.getRed(), col.getGreen(), col.getBlue(), hsl); hsl[1] = Math.round(0.7f * hsl[1]); hsl[2] = 100; int rgb[] = Utils.hsl2rgb(hsl); return new Color(rgb[0], rgb[1], rgb[2]); }
public void drop(DropTargetDropEvent dtde) { dtde.acceptDrop(DnDConstants.ACTION_COPY); DataFlavor[] flavors = null; try { Transferable t = dtde.getTransferable(); iterator = null; flavors = t.getTransferDataFlavors(); if (IJ.debugMode) IJ.log("DragAndDrop.drop: " + flavors.length + " flavors"); for (int i = 0; i < flavors.length; i++) { if (IJ.debugMode) IJ.log(" flavor[" + i + "]: " + flavors[i].getMimeType()); if (flavors[i].isFlavorJavaFileListType()) { Object data = t.getTransferData(DataFlavor.javaFileListFlavor); iterator = ((List) data).iterator(); break; } else if (flavors[i].isFlavorTextType()) { Object ob = t.getTransferData(flavors[i]); if (!(ob instanceof String)) continue; String s = ob.toString().trim(); if (IJ.isLinux() && s.length() > 1 && (int) s.charAt(1) == 0) s = fixLinuxString(s); ArrayList list = new ArrayList(); if (s.indexOf("href=\"") != -1 || s.indexOf("src=\"") != -1) { s = parseHTML(s); if (IJ.debugMode) IJ.log(" url: " + s); list.add(s); this.iterator = list.iterator(); break; } BufferedReader br = new BufferedReader(new StringReader(s)); String tmp; while (null != (tmp = br.readLine())) { tmp = java.net.URLDecoder.decode(tmp.replaceAll("\\+", "%2b"), "UTF-8"); if (tmp.startsWith("file://")) tmp = tmp.substring(7); if (IJ.debugMode) IJ.log(" content: " + tmp); if (tmp.startsWith("http://")) list.add(s); else list.add(new File(tmp)); } this.iterator = list.iterator(); break; } } if (iterator != null) { Thread thread = new Thread(this, "DrawAndDrop"); thread.setPriority(Math.max(thread.getPriority() - 1, Thread.MIN_PRIORITY)); thread.start(); } } catch (Exception e) { dtde.dropComplete(false); return; } dtde.dropComplete(true); if (flavors == null || flavors.length == 0) { if (IJ.isMacOSX()) IJ.error( "First drag and drop ignored. Please try again. You can avoid this\n" + "problem by dragging to the toolbar instead of the status bar."); else IJ.error("Drag and drop failed"); } }
/** * Computes CPU usage (fraction of 1.0) between <code>start[1]</code> and <code>end[1]</code> time * points [1.0 corresponds to 100% utilization of all processors]. * * @throws IllegalArgumentException if start and end time points are less than #MIN_ELAPSED_TIME * ms apart. * @throws IllegalArgumentException if either argument is null * @param start,end long[2]: [0] system time stamp, [1] process CPU time (as returned by * makeCPUUsageSnapshot()). */ public static double getProcessCPUUsage(long[] start, long[] end) { if (start == null) throw new IllegalArgumentException("null input: start"); if (end == null) throw new IllegalArgumentException("null input: end"); // if (end[0] < start[0] + MIN_ELAPSED_TIME) throw new IllegalArgumentException("end time must // be at least " + MIN_ELAPSED_TIME + " ms later than start time"); end[0] = Math.max(end[0], start[0] + MIN_ELAPSED_TIME); return ((double) (end[1] - start[1])) / (double) (end[0] - start[0]); }
/** * Draws a visualization tooltip. * * @param g graphics reference * @param tt tooltip label * @param x horizontal position * @param y vertical position * @param w width * @param c color color depth */ public static void drawTooltip( final Graphics g, final String tt, final int x, final int y, final int w, final int c) { final int tw = width(g, tt); final int th = g.getFontMetrics().getHeight(); final int xx = Math.min(w - tw - 8, x); g.setColor(color(c)); g.fillRect(xx - 1, y - th, tw + 4, th); g.setColor(BACK); g.drawString(tt, xx, y - 4); }
/** Returns the selected text, or null if no selection is active. */ public final String getSelectedText() { if (selectionStart == selectionEnd) return null; if (rectSelect) { // Return each row of the selection on a new line Element map = document.getDefaultRootElement(); int start = selectionStart - map.getElement(selectionStartLine).getStartOffset(); int end = selectionEnd - map.getElement(selectionEndLine).getStartOffset(); // Certain rectangles satisfy this condition... if (end < start) { int tmp = end; end = start; start = tmp; } StringBuffer buf = new StringBuffer(); Segment seg = new Segment(); for (int i = selectionStartLine; i <= selectionEndLine; i++) { Element lineElement = map.getElement(i); int lineStart = lineElement.getStartOffset(); int lineEnd = lineElement.getEndOffset() - 1; int lineLen = lineEnd - lineStart; lineStart = Math.min(lineStart + start, lineEnd); lineLen = Math.min(end - start, lineEnd - lineStart); getText(lineStart, lineLen, seg); buf.append(seg.array, seg.offset, seg.count); if (i != selectionEndLine) buf.append('\n'); } return buf.toString(); } else { return getText(selectionStart, selectionEnd - selectionStart); } }
/** Returns the offset where the selection ends on the specified line. */ public int getSelectionEnd(int line) { if (line == selectionEndLine) return selectionEnd; else if (rectSelect) { Element map = document.getDefaultRootElement(); int end = selectionEnd - map.getElement(selectionEndLine).getStartOffset(); Element lineElement = map.getElement(line); int lineStart = lineElement.getStartOffset(); int lineEnd = lineElement.getEndOffset() - 1; return Math.min(lineEnd, lineStart + end); } else return getLineEndOffset(line) - 1; }
public final boolean replace(int num, String replacement) { buf.buffer.replace(buf.cursor - num, buf.cursor, replacement); try { moveCursor(-num); drawBuffer(Math.max(0, num - replacement.length())); moveCursor(replacement.length()); } catch (IOException e) { e.printStackTrace(); return false; } return true; }
/** * All other write methods delegate their work to here. */ public void write(OutputStream out, java.util.List<Figure> figures) throws IOException { Rectangle2D.Double drawingRect = null; for (Figure f : figures) { if (drawingRect == null) { drawingRect = f.getBounds(); } else { drawingRect.add(f.getBounds()); } } AffineTransform drawingTransform = new AffineTransform(); drawingTransform.translate( -Math.min(0, drawingRect.x), -Math.min(0, drawingRect.y) ); write(out, figures, drawingTransform, new Dimension( (int) (Math.abs(drawingRect.x) + drawingRect.width), (int) (Math.abs(drawingRect.y) + drawingRect.height)) ); }
/** * Writes the <code>shape</code>, <code>coords</code>, <code>href</code>, * <code>nohref</code> Attribute for the specified figure and rectangle. * * @return Returns true, if the rect is inside of the image bounds. */ private boolean writeRectAttributes(IXMLElement elem, SVGFigure f, Rectangle2D.Double rect) { AffineTransform t = TRANSFORM.getClone(f); if (t == null) { t = drawingTransform; } else { t.preConcatenate(drawingTransform); } if ((t.getType() & (AffineTransform.TYPE_UNIFORM_SCALE | AffineTransform.TYPE_TRANSLATION)) == t.getType() ) { Point2D.Double start = new Point2D.Double(rect.x, rect.y); Point2D.Double end = new Point2D.Double(rect.x + rect.width, rect.y + rect.height); t.transform(start, start); t.transform(end, end); Rectangle r = new Rectangle( (int) Math.min(start.x, end.x), (int) Math.min(start.y, end.y), (int) Math.abs(start.x - end.x), (int) Math.abs(start.y - end.y) ); elem.setAttribute("shape", "rect"); elem.setAttribute("coords", r.x + ","+ r.y + ","+ (r.x + r.width) + ","+ (r.y + r.height) ); writeHrefAttribute(elem, f); return bounds.intersects(r); } else { return writePolyAttributes(elem, f, (Shape) rect); } }
private void drawCharacters(int x, int y, TextStyle style, CharBuffer buf, Graphics2D gfx) { int xCoord = x * myCharSize.width; int yCoord = y * myCharSize.height; if (xCoord < 0 || xCoord > getWidth() || yCoord < 0 || yCoord > getHeight()) { return; } gfx.setColor(getPalette().getColor(myStyleState.getBackground(style.getBackgroundForRun()))); int textLength = CharUtils.getTextLengthDoubleWidthAware( buf.getBuf(), buf.getStart(), buf.length(), mySettingsProvider.ambiguousCharsAreDoubleWidth()); gfx.fillRect( xCoord, yCoord, Math.min(textLength * myCharSize.width, getWidth() - xCoord), Math.min(myCharSize.height, getHeight() - yCoord)); if (buf.isNul()) { return; // nothing more to do } drawChars(x, y, buf, style, gfx); gfx.setColor(getPalette().getColor(myStyleState.getForeground(style.getForegroundForRun()))); int baseLine = (y + 1) * myCharSize.height - myDescent; if (style.hasOption(TextStyle.Option.UNDERLINED)) { gfx.drawLine(xCoord, baseLine + 1, (x + textLength) * myCharSize.width, baseLine + 1); } }
/** * Output the specified {@link Collection} in proper columns. * * @param stuff the stuff to print */ public void printColumns(final Collection stuff) throws IOException { if ((stuff == null) || (stuff.size() == 0)) { return; } int width = getTermwidth(); int maxwidth = 0; for (Iterator i = stuff.iterator(); i.hasNext(); maxwidth = Math.max(maxwidth, i.next().toString().length())) {; } StringBuffer line = new StringBuffer(); int showLines; if (usePagination) showLines = getTermheight() - 1; // page limit else showLines = Integer.MAX_VALUE; for (Iterator i = stuff.iterator(); i.hasNext(); ) { String cur = (String) i.next(); if ((line.length() + maxwidth) > width) { printString(line.toString().trim()); printNewline(); line.setLength(0); if (--showLines == 0) { // Overflow printString(loc.getString("display-more")); flushConsole(); int c = readVirtualKey(); if (c == '\r' || c == '\n') showLines = 1; // one step forward else if (c != 'q') showLines = getTermheight() - 1; // page forward back(loc.getString("display-more").length()); if (c == 'q') break; // cancel } } pad(cur, maxwidth + 3, line); } if (line.length() > 0) { printString(line.toString().trim()); printNewline(); line.setLength(0); } }
private int clamp(int val, int min, int max) { return Math.max(Math.min(val, max), min); }
protected Point panelToCharCoords(final Point p) { int x = Math.min(p.x / myCharSize.width, getColumnCount() - 1); x = Math.max(0, x); int y = Math.min(p.y / myCharSize.height, getRowCount() - 1) + myClientScrollOrigin; return new Point(x, y); }
private void geterrors() { GenericDialog gd = new GenericDialog("Options"); float conf = 0.67f; gd.addNumericField("Confidence Limit", (int) (conf * 100.0f), 5, 10, null); gd.addChoice("Error Parameter", paramsnames, paramsnames[0]); double spacing = 0.01; gd.addNumericField("Chi^2 plot spacing (% of value)?", spacing * 100.0, 2, 10, null); boolean globalerror = false; gd.addCheckbox("Global Fit Error?", globalerror); int dataset = 0; gd.addNumericField("Data Set (for Global Error)", dataset, 0); gd.showDialog(); if (gd.wasCanceled()) { return; } conf = 0.01f * (float) gd.getNextNumber(); int paramindex = (int) gd.getNextChoiceIndex(); spacing = 0.01 * gd.getNextNumber(); globalerror = gd.getNextBoolean(); dataset = (int) gd.getNextNumber(); if (globalerror) { support_plane_errors erclass = new support_plane_errors(this, 0.0001, 50, true, 0.1); int[] erindeces = {paramindex, dataset}; // need to set up all the matrices int nsel = 0; int nparams = 11; for (int i = 0; i < ncurves; i++) { if (include[i]) { nsel++; } } double[][] params = new double[nsel][nparams]; String[][] tempformulas = new String[nsel][nparams]; double[][][] constraints = new double[2][nsel][nparams]; int[][] vflmatrix = new int[nsel][nparams]; float[][] tempdata = new float[nsel][xpts * ypts]; float[][] tempweights = new float[nsel][xpts * ypts]; int nfit = 0; int counter = 0; for (int i = 0; i < ncurves; i++) { if (include[i]) { for (int j = 0; j < nparams; j++) { params[counter][j] = globalparams[i][j]; tempformulas[counter][j] = globalformulas[i][j]; constraints[0][counter][j] = globalconstraints[0][i][j]; constraints[1][counter][j] = globalconstraints[1][i][j]; vflmatrix[counter][j] = globalvflmatrix[i][j]; if (vflmatrix[counter][j] == 0 || (j == 0 && vflmatrix[counter][j] == 2)) { nfit++; } } for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { tempdata[counter][j + k * xpts] = (float) ((double) pch[i][j][k] / (double) nmeas[i]); tempweights[counter][j + k * xpts] = weights[i][j][k]; } } counter++; } } int dofnum = xpts * ypts * nsel - (nfit - 1) - 1; int dofden = xpts * ypts * nsel - nfit - 1; // double flim=FLimit(dofnum,dofden,(double)conf); double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf); IJ.log("FLimit = " + (float) flim); if (flim == Double.NaN && flim < 1.0) { IJ.showMessage("Invalid Limiting F Value"); return; } double truespacing = Math.abs(params[erindeces[1]][erindeces[0]] * spacing); double[][] c2plot = erclass.geterrorsglobal( params, vflmatrix, tempformulas, paramsnames, constraints, tempdata, tempweights, flim, truespacing, erindeces); IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]); int templength = c2plot[0].length; float[][] c2plotf = new float[2][templength - 1]; for (int i = 0; i < (templength - 1); i++) { c2plotf[0][i] = (float) c2plot[0][i + 1]; c2plotf[1][i] = (float) c2plot[1][i + 1]; } new PlotWindow4( "c2 plot", paramsnames[paramindex] + "[" + dataset + "]", "Chi^2", c2plotf[0], c2plotf[1]) .draw(); } else { support_plane_errors erclass = new support_plane_errors(this, 0.0001, 50, false, 0.1); int errindex = paramindex; float[] tempdata = new float[xpts * ypts]; float[] tempweights = new float[xpts * ypts]; for (int i = 0; i < xpts; i++) { for (int j = 0; j < ypts; j++) { tempdata[i + j * xpts] = (float) ((double) avg[i][j] / (double) nmeas[ncurves]); tempweights[i + j * xpts] = avgweights[i][j]; } } int nfit = 0; for (int i = 0; i < 7; i++) { if (avgfixes[i] == 0) { nfit++; } } int dofnum = xpts * ypts - (nfit - 1) - 1; int dofden = xpts * ypts - nfit - 1; double flim = (new jdist()).FLimit(dofnum, dofden, (double) conf); IJ.log("FLimit = " + (float) flim); if (flim == Double.NaN && flim < 1.0) { IJ.showMessage("Invalid Limiting F Value"); return; } double truespacing = Math.abs(avgparams[errindex] * spacing); double[][] c2plot = erclass.geterrors( avgparams, avgfixes, avgconstraints, tempdata, tempweights, flim, truespacing, errindex); IJ.log("upper limit = " + c2plot[1][0] + " lower limit = " + c2plot[0][0]); int templength = c2plot[0].length; float[][] c2plotf = new float[2][templength - 1]; for (int i = 0; i < (templength - 1); i++) { c2plotf[0][i] = (float) c2plot[0][i + 1]; c2plotf[1][i] = (float) c2plot[1][i + 1]; } new PlotWindow4("c2 plot", paramsnames[errindex], "Chi^2", c2plotf[0], c2plotf[1]).draw(); } }
/** * Replaces the selection with the specified text. * * @param selectedText The replacement text for the selection */ public void setSelectedText(String selectedText) { if (!editable) { throw new InternalError("Text component" + " read only"); } document.beginCompoundEdit(); try { if (rectSelect) { Element map = document.getDefaultRootElement(); int start = selectionStart - map.getElement(selectionStartLine).getStartOffset(); int end = selectionEnd - map.getElement(selectionEndLine).getStartOffset(); // Certain rectangles satisfy this condition... if (end < start) { int tmp = end; end = start; start = tmp; } int lastNewline = 0; int currNewline = 0; for (int i = selectionStartLine; i <= selectionEndLine; i++) { Element lineElement = map.getElement(i); int lineStart = lineElement.getStartOffset(); int lineEnd = lineElement.getEndOffset() - 1; int rectStart = Math.min(lineEnd, lineStart + start); document.remove(rectStart, Math.min(lineEnd - rectStart, end - start)); if (selectedText == null) continue; currNewline = selectedText.indexOf('\n', lastNewline); if (currNewline == -1) currNewline = selectedText.length(); document.insertString(rectStart, selectedText.substring(lastNewline, currNewline), null); lastNewline = Math.min(selectedText.length(), currNewline + 1); } if (selectedText != null && currNewline != selectedText.length()) { int offset = map.getElement(selectionEndLine).getEndOffset() - 1; document.insertString(offset, "\n", null); document.insertString(offset + 1, selectedText.substring(currNewline + 1), null); } } else { document.remove(selectionStart, selectionEnd - selectionStart); if (selectedText != null) { document.insertString(selectionStart, selectedText, null); } } } catch (BadLocationException bl) { bl.printStackTrace(); throw new InternalError("Cannot replace" + " selection"); } // No matter what happends... stops us from leaving document // in a bad state finally { document.endCompoundEdit(); } setCaretPosition(selectionEnd); }
private void updateavg() { nmeas[ncurves] = 0; avg = new float[xpts][ypts]; avgweights = new float[xpts][ypts]; for (int i = 0; i < ncurves; i++) { if (include[i]) { for (int j = 0; j < xpts; j++) { for (int k = 0; k < ypts; k++) { avg[j][k] += pch[i][j][k]; nmeas[ncurves] += (int) pch[i][j][k]; } } } } double tempavg = 0.0; double tempavg2 = 0.0; double temp2avg = 0.0; double temp2avg2 = 0.0; double tempccavg = 0.0; for (int i = 0; i < xpts; i++) { for (int j = 0; j < ypts; j++) { double normed = (double) avg[i][j] / (double) nmeas[ncurves]; avgweights[i][j] = (float) ((double) nmeas[ncurves] / (normed * (1.0f - normed))); if (avg[i][j] > 0.0f) { avgweights[i][j] = (float) ((double) nmeas[ncurves] / (normed * (1.0f - normed))); } else { avgweights[i][j] = 1.0f; } tempavg += (double) i * normed; tempavg2 += (double) i * (double) i * normed; temp2avg += (double) j * normed; temp2avg2 += (double) j * (double) j * normed; tempccavg += (double) i * (double) j * normed; } } tempccavg -= tempavg * temp2avg; brightcc[ncurves] = tempccavg / Math.sqrt(tempavg * temp2avg); tempavg2 -= tempavg * tempavg; tempavg2 /= tempavg; bright1[ncurves] = (tempavg2 - 1.0); temp2avg2 -= temp2avg * temp2avg; temp2avg2 /= temp2avg; bright2[ncurves] = (temp2avg2 - 1.0); intensity1[ncurves] = tempavg; intensity2[ncurves] = temp2avg; if (psfflag == 0) { bright1[ncurves] /= 0.3536; bright2[ncurves] /= 0.3536; brightcc[ncurves] /= 0.3536; } else { if (psfflag == 1) { bright1[ncurves] /= 0.078; bright2[ncurves] /= 0.078; brightcc[ncurves] /= 0.078; } else { bright1[ncurves] /= 0.5; bright2[ncurves] /= 0.5; brightcc[ncurves] /= 0.5; } } number1[ncurves] = intensity1[ncurves] / bright1[ncurves]; number2[ncurves] = intensity2[ncurves] / bright2[ncurves]; brightmincc[ncurves] = (bright1[ncurves] * beta) * Math.sqrt(intensity1[ncurves] / intensity2[ncurves]); }
public void updatebeta() { for (int i = 0; i <= ncurves; i++) { brightmincc[i] = (bright1[i] * beta) / Math.sqrt(intensity1[i] / intensity2[i]); eminccarray[i].setText("" + (float) brightmincc[i]); } }
/** * Converts a y co-ordinate to a line index. * * @param y The y co-ordinate */ public int yToLine(int y) { FontMetrics fm = painter.getFontMetrics(); int height = fm.getHeight(); return Math.max(0, Math.min(getLineCount() - 1, y / height + firstLine)); }
private void doDoubleClick(MouseEvent evt, int line, int offset, int dot) throws BadLocationException { // Ignore empty lines if (getLineLength(line) == 0) return; try { int bracket = TextUtilities.findMatchingBracket(document, Math.max(0, dot - 1)); if (bracket != -1) { int mark = getMarkPosition(); // Hack if (bracket > mark) { bracket++; mark--; } select(mark, bracket); return; } } catch (BadLocationException bl) { bl.printStackTrace(); } // Ok, it's not a bracket... select the word String lineText = getLineText(line); char ch = lineText.charAt(Math.max(0, offset - 1)); String noWordSep = (String) document.getProperty("noWordSep"); if (noWordSep == null) noWordSep = ""; // If the user clicked on a non-letter char, // we select the surrounding non-letters boolean selectNoLetter = (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1); int wordStart = 0; for (int i = offset - 1; i >= 0; i--) { ch = lineText.charAt(i); if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) { wordStart = i + 1; break; } } int wordEnd = lineText.length(); for (int i = offset; i < lineText.length(); i++) { ch = lineText.charAt(i); if (selectNoLetter ^ (!Character.isLetterOrDigit(ch) && noWordSep.indexOf(ch) == -1)) { wordEnd = i; break; } } int lineStart = getLineStartOffset(line); select(lineStart + wordStart, lineStart + wordEnd); /* String lineText = getLineText(line); String noWordSep = (String)document.getProperty("noWordSep"); int wordStart = TextUtilities.findWordStart(lineText,offset,noWordSep); int wordEnd = TextUtilities.findWordEnd(lineText,offset,noWordSep); int lineStart = getLineStartOffset(line); select(lineStart + wordStart,lineStart + wordEnd); */ }