Example usage for java.lang Double MIN_VALUE

List of usage examples for java.lang Double MIN_VALUE

Introduction

In this page you can find the example usage for java.lang Double MIN_VALUE.

Prototype

double MIN_VALUE

To view the source code for java.lang Double MIN_VALUE.

Click Source Link

Document

A constant holding the smallest positive nonzero value of type double , 2-1074.

Usage

From source file:ArrayUtils.java

public static double max(final double[] array) {
    double d = Double.MIN_VALUE;
    for (int i = 0; i < array.length; i++) {
        d = Math.max(array[i], d);
    }//from ww w .j  av a2s . c o m
    return d;
}

From source file:whitebox.stats.Kriging.java

/**
 * Draw Semivariogram surface map and also draw the search are if
 * Anisotropic//from w w  w  . ja  v a 2 s .  c  o  m
 *
 * @param Radius
 * @param AnIsotropic
 */
public void DrawSemivariogramSurface(double Radius, boolean AnIsotropic) {
    double[][] data = new double[3][BinSurface.length * BinSurface[0].length];
    int n = 0;
    double max = Double.MIN_VALUE;
    for (int i = 0; i < BinSurface.length; i++) {
        for (int j = 0; j < BinSurface[i].length; j++) {
            data[0][n] = BinSurface[i][j].GridHorDistance;
            data[1][n] = BinSurface[i][j].GridVerDistance;
            if ((Math.pow(data[0][n], 2) + Math.pow(data[1][n], 2)) <= Radius * Radius
                    && !Double.isNaN(BinSurface[i][j].Value)) {
                data[2][n] = BinSurface[i][j].Value;
                if (max < data[2][n]) {
                    max = data[2][n];
                }
            } else {
                data[2][n] = -1;
            }
            n++;
        }
    }
    DefaultXYZDataset dataset = new DefaultXYZDataset();
    dataset.addSeries("Value", data);
    NumberAxis xAxis = new NumberAxis();

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis();
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setLowerMargin(0.0);
    yAxis.setUpperMargin(0.0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(LagSize);
    renderer.setBlockHeight(LagSize);
    renderer.setBlockAnchor(RectangleAnchor.CENTER);

    LookupPaintScale paintScale = new LookupPaintScale(0, max, Color.white);
    double colorRange = max / 6;
    //double colorRange = 23013;
    paintScale.add(0.0, Color.blue);
    paintScale.add(1 * colorRange, Color.green);
    paintScale.add(2 * colorRange, Color.cyan);
    paintScale.add(3 * colorRange, Color.yellow);
    paintScale.add(4 * colorRange, Color.ORANGE);
    paintScale.add(5 * colorRange, Color.red);

    renderer.setPaintScale(paintScale);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinePaint(Color.white);

    if (AnIsotropic) {
        CombinedRangeXYPlot combinedrangexyplot = new CombinedRangeXYPlot();
        XYSeries seriesT1 = new XYSeries("1");
        XYSeriesCollection AngleCollct = new XYSeriesCollection();

        double bw = BandWidth;
        double r = bw / Math.sin(Tolerance);
        if (r > Radius) {
            bw = Radius * Math.sin(Tolerance);
            r = Radius;
        }
        seriesT1.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));

        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = 2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 + bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 + bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x2, y2);
                }
            } else {
                double x1 = -bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT1.add(x1, y1);
                } else {
                    seriesT1.add(x1, y2);
                }
            }
        } else {
            double y1 = bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT1.add(x1, y1);
            } else {
                seriesT1.add(x2, y1);
            }
        }

        AngleCollct.addSeries(seriesT1);

        XYSeries seriesT2 = new XYSeries("2");
        seriesT2.add(r * Math.cos(Angle + Tolerance), r * Math.sin(Angle + Tolerance));
        seriesT2.add(0.0, 0.0);
        AngleCollct.addSeries(seriesT2);

        XYSeries seriesT3 = new XYSeries("3");
        seriesT3.add(Radius * Math.cos(Angle), Radius * Math.sin(Angle));
        seriesT3.add(0, 0);
        AngleCollct.addSeries(seriesT3);

        XYSeries seriesT4 = new XYSeries("4");
        seriesT4.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        seriesT4.add(0, 0);
        AngleCollct.addSeries(seriesT4);

        XYSeries seriesT5 = new XYSeries("5");

        seriesT5.add(r * Math.cos(Angle - Tolerance), r * Math.sin(Angle - Tolerance));
        if ((double) Math.round(Math.sin(Angle) * 10000) / 10000 != 0) {
            if ((double) Math.round(Math.cos(Angle) * 10000) / 10000 != 0) {
                double a = (1 + Math.pow(Math.tan(Angle), 2));
                double b = -2 * bw / Math.sin(Angle) * Math.pow(Math.tan(Angle), 2);
                double c = Math.pow(Math.tan(Angle), 2) * Math.pow(bw / Math.sin(Angle), 2)
                        - Math.pow(Radius, 2);
                double x1 = (-b + Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y1 = Math.tan(Angle) * (x1 - bw / Math.sin(Angle));
                double x2 = (-b - Math.sqrt(Math.pow(b, 2) - 4 * a * c)) / (2 * a);
                double y2 = Math.tan(Angle) * (x2 - bw / Math.sin(Angle));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));
                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x2, y2);
                }
            } else {
                double x1 = bw * Math.sin(Angle);
                double y1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double y2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(x1, 2));
                double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
                double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                        + (Math.pow((Radius * Math.sin(Angle) - y2), 2)));

                if (d1 < d2) {
                    seriesT5.add(x1, y1);
                } else {
                    seriesT5.add(x1, y2);
                }
            }
        } else {
            double y1 = -bw * Math.cos(Angle);
            double x1 = Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double x2 = -Math.sqrt(Math.pow(Radius, 2) - Math.pow(y1, 2));
            double d1 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x1), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));
            double d2 = Math.sqrt((Math.pow((Radius * Math.cos(Angle) - x2), 2))
                    + (Math.pow((Radius * Math.sin(Angle) - y1), 2)));

            if (d1 < d2) {
                seriesT5.add(x1, y1);
            } else {
                seriesT5.add(x2, y1);
            }
        }
        AngleCollct.addSeries(seriesT5);
        plot.setDataset(1, AngleCollct);
        XYLineAndShapeRenderer lineshapRend = new XYLineAndShapeRenderer(true, false);
        for (int i = 0; i < AngleCollct.getSeriesCount(); i++) {
            //plot.getRenderer().setSeriesPaint(i , Color.BLUE);
            lineshapRend.setSeriesPaint(i, Color.BLACK);
        }
        plot.setRenderer(1, lineshapRend);
        combinedrangexyplot.add(plot);
    }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    JFreeChart chart = new JFreeChart("Semivariogram Surface", plot);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);

    // create and display a frame...
    ChartFrame frame = new ChartFrame("", chart);
    frame.pack();
    //frame.setSize(100, 50);
    frame.setVisible(true);
}

From source file:org.openmicroscopy.shoola.agents.metadata.rnd.RendererModel.java

/**
 * Returns the global maximum of the currently selected channel
 * or of all channels if the number of channels is greater
 * {@link Renderer#MAX_CHANNELS}./*ww w  .  j  av  a  2 s .c  om*/
 *
 * @return See above.
 */
double getGlobalMax() {
    if (getMaxC() > Renderer.MAX_CHANNELS) {
        if (globalMaxChannels == null) {
            double max = Double.MIN_VALUE;
            double value;
            for (int i = 0; i < getMaxC(); i++) {
                value = getGlobalMax(i);
                if (value > max)
                    max = value;
            }
            globalMaxChannels = max;
        }
        return globalMaxChannels.doubleValue();
    }
    return getGlobalMax(selectedChannelIndex);
}

From source file:eu.ascetic.zabbixdatalogger.datasource.ZabbixDirectDbDataSourceAdaptor.java

@Override
public double getHighestHostPowerUsage(Host host) {
    long currentTime = TimeUnit.MILLISECONDS.toSeconds(new GregorianCalendar().getTimeInMillis());
    long timeInPast = currentTime - TimeUnit.MINUTES.toSeconds(10);
    //NOTE: The semantics do not match the other Zabbix Datasource adaptor
    List<Double> energyData = getHistoryDataItems(POWER_KPI_NAME, host.getId(), timeInPast, currentTime);
    double highestValue = Double.MIN_VALUE;
    for (Double current : energyData) {
        if (current > highestValue) {
            highestValue = current;//w  w w. j a  v a 2 s  .c o m
        }
    }
    return highestValue;
}

From source file:ArrayUtils.java

public static <T> T max(final T[] array, final double[] scores) {
    if (array.length != scores.length) {
        throw new IllegalArgumentException(
                "array.length(" + array.length + ") != scores.length(" + scores.length + ")");
    }/*www .  ja v a  2 s . com*/
    T obj = null;
    double d = Double.MIN_VALUE;
    for (int i = 0; i < scores.length; i++) {
        final double score = scores[i];
        if (score > d) {
            d = score;
            obj = array[i];
        }
    }
    return obj;
}

From source file:mil.jpeojtrs.sca.util.tests.AnyUtilsTest.java

@Test
public void test_convertAnySequences() throws Exception {
    // Test Strings
    Object obj = null;/*from  w ww.  j a  v  a  2  s.  c  o m*/
    Any theAny = JacorbUtil.init().create_any();

    final String[] stringInitialValue = new String[] { "a", "b", "c" };
    StringSeqHelper.insert(theAny, stringInitialValue);
    final String[] stringExtractedValue = StringSeqHelper.extract(theAny);
    // Sanity Check
    Assert.assertTrue(Arrays.equals(stringInitialValue, stringExtractedValue));

    // The real test
    obj = AnyUtils.convertAny(theAny);
    Assert.assertTrue(obj instanceof String[]);
    Assert.assertTrue(Arrays.equals(stringInitialValue, (String[]) obj));

    // Test Doubles
    obj = null;
    theAny = JacorbUtil.init().create_any();

    final double[] doubleInitialValue = new double[] { 0.1, 0.2, 0.3 };
    DoubleSeqHelper.insert(theAny, doubleInitialValue);
    final double[] doubleExtractedValue = DoubleSeqHelper.extract(theAny);
    // Sanity Check
    Assert.assertTrue(Arrays.equals(doubleInitialValue, doubleExtractedValue));

    // The real test
    obj = AnyUtils.convertAny(theAny);
    Assert.assertTrue(obj instanceof Double[]);
    Assert.assertTrue(Arrays.equals(ArrayUtils.toObject(doubleInitialValue), (Double[]) obj));

    // Test Integers
    obj = null;
    theAny = JacorbUtil.init().create_any();

    final int[] intInitialValue = new int[] { 1, 2, 3 };
    LongSeqHelper.insert(theAny, intInitialValue);
    final int[] intExtractedValue = LongSeqHelper.extract(theAny);
    // Sanity Check
    Assert.assertTrue(Arrays.equals(intInitialValue, intExtractedValue));

    // The real test
    obj = AnyUtils.convertAny(theAny);
    Assert.assertTrue(obj instanceof Integer[]);
    Assert.assertTrue(Arrays.equals(ArrayUtils.toObject(intInitialValue), (Integer[]) obj));

    // Test Recursive Sequence
    obj = null;
    final Any[] theAnys = new Any[2];
    theAnys[0] = JacorbUtil.init().create_any();
    theAnys[1] = JacorbUtil.init().create_any();

    LongSeqHelper.insert(theAnys[0], intInitialValue);
    LongSeqHelper.insert(theAnys[1], intInitialValue);
    AnySeqHelper.insert(theAny, theAnys);

    // The real test
    obj = AnyUtils.convertAny(theAny);
    Assert.assertTrue(obj instanceof Object[]);
    int[] extractedIntArray = ArrayUtils.toPrimitive((Integer[]) ((Object[]) obj)[0]);
    Assert.assertTrue(Arrays.equals(intInitialValue, extractedIntArray));
    extractedIntArray = ArrayUtils.toPrimitive((Integer[]) ((Object[]) obj)[1]);
    Assert.assertTrue(Arrays.equals(intInitialValue, extractedIntArray));

    String[] str = (String[]) AnyUtils
            .convertAny(AnyUtils.toAnySequence(new String[] { "2", "3" }, TCKind.tk_string));
    Assert.assertEquals("2", str[0]);
    str = (String[]) AnyUtils.convertAny(AnyUtils.toAnySequence(new String[] { "3", "4" }, TCKind.tk_wstring));
    Assert.assertEquals("3", str[0]);
    final Boolean[] bool = (Boolean[]) AnyUtils
            .convertAny(AnyUtils.toAnySequence(new boolean[] { false, true }, TCKind.tk_boolean));
    Assert.assertTrue(bool[1].booleanValue());
    final Short[] b = (Short[]) AnyUtils
            .convertAny(AnyUtils.toAnySequence(new byte[] { Byte.MIN_VALUE, Byte.MAX_VALUE }, TCKind.tk_octet));
    Assert.assertEquals(Byte.MAX_VALUE, b[1].byteValue());
    Character[] c = (Character[]) AnyUtils
            .convertAny(AnyUtils.toAnySequence(new char[] { 'r', 'h' }, TCKind.tk_char));
    Assert.assertEquals('h', c[1].charValue());
    c = (Character[]) AnyUtils
            .convertAny(AnyUtils.toAnySequence(new Character[] { '2', '3' }, TCKind.tk_wchar));
    Assert.assertEquals('2', c[0].charValue());
    final Short[] s = (Short[]) AnyUtils.convertAny(
            AnyUtils.toAnySequence(new short[] { Short.MIN_VALUE, Short.MAX_VALUE }, TCKind.tk_short));
    Assert.assertEquals(Short.MAX_VALUE, s[1].shortValue());
    final Integer[] i = (Integer[]) AnyUtils.convertAny(
            AnyUtils.toAnySequence(new int[] { Integer.MIN_VALUE, Integer.MAX_VALUE }, TCKind.tk_long));
    Assert.assertEquals(Integer.MAX_VALUE, i[1].intValue());
    final Long[] l = (Long[]) AnyUtils.convertAny(
            AnyUtils.toAnySequence(new long[] { Long.MIN_VALUE, Long.MAX_VALUE }, TCKind.tk_longlong));
    Assert.assertEquals(Long.MAX_VALUE, l[1].longValue());
    final Float[] f = (Float[]) AnyUtils.convertAny(
            AnyUtils.toAnySequence(new float[] { Float.MIN_VALUE, Float.MAX_VALUE }, TCKind.tk_float));
    Assert.assertEquals(Float.MAX_VALUE, f[1].floatValue(), 0.00001);
    final Double[] d = (Double[]) AnyUtils.convertAny(
            AnyUtils.toAnySequence(new double[] { Double.MIN_VALUE, Double.MAX_VALUE }, TCKind.tk_double));
    Assert.assertEquals(Double.MAX_VALUE, d[1].doubleValue(), 0.00001);
    final Integer[] us = (Integer[]) AnyUtils.convertAny(
            AnyUtils.toAnySequence(new short[] { Short.MIN_VALUE, Short.MAX_VALUE }, TCKind.tk_ushort));
    Assert.assertEquals(Short.MAX_VALUE, us[1].intValue());
    final Long[] ui = (Long[]) AnyUtils.convertAny(
            AnyUtils.toAnySequence(new int[] { Integer.MIN_VALUE, Integer.MAX_VALUE }, TCKind.tk_ulong));
    Assert.assertEquals(Integer.MAX_VALUE, ui[1].longValue());
    final BigInteger[] ul = (BigInteger[]) AnyUtils.convertAny(AnyUtils
            .toAnySequence(new BigInteger[] { new BigInteger("2"), new BigInteger("3") }, TCKind.tk_ulonglong));
    Assert.assertEquals(3L, ul[1].longValue());

}

From source file:gr.iti.mklab.reveal.forensics.util.Util.java

public static double minDouble3DArrayD(double[][][] arrayIn) {
    // Calculate the minimum value of a 3D float array
    double min = Double.MIN_VALUE;
    double colMin;
    for (double[][] twoDInRow : arrayIn) {
        colMin = Arrays.stream(twoDInRow).flatMapToDouble(a -> Arrays.stream(a)).min().getAsDouble();
        if (colMin < min) {
            min = colMin;//w  w w .  j  ava  2 s .c  om
        }
    }
    return min;
}

From source file:de.xirp.ui.widgets.dialogs.ChartConfigDialog.java

/**
 * Constructs the dialog and opens it./*from w  w w. ja  v a2s . co m*/
 */
public void open() {
    dialogShell = new XShell(parent, SWT.DIALOG_TRIM | SWT.APPLICATION_MODAL);

    dialogShell.addShellListener(new ShellAdapter() {

        @Override
        public void shellClosed(ShellEvent e) {
            SWTUtil.secureDispose(dialogShell);
        }
    });
    dialogShell.setSize(WIDTH, HEIGHT);
    dialogShell.setTextForLocaleKey("ChartConfigDialog.gui.title.createChart"); //$NON-NLS-1$
    dialogShell.setImage(ImageManager.getSystemImage(SystemImage.CHART));
    SWTUtil.setGridLayout(dialogShell, 2, true);

    XGroup chartType = new XGroup(dialogShell, SWT.NONE);
    chartType.setTextForLocaleKey("ChartConfigDialog.group.chartType"); //$NON-NLS-1$
    SWTUtil.setGridData(chartType, true, false, SWT.FILL, SWT.FILL, 1, 1);
    SWTUtil.setGridLayout(chartType, 2, true);

    XLabel label = new XLabel(chartType, SWT.NONE);
    label.setTextForLocaleKey("ChartConfigDialog.label.chooseChartType"); //$NON-NLS-1$
    SWTUtil.setGridData(label, true, false, SWT.FILL, SWT.FILL, 1, 1);

    final XCombo types = new XCombo(chartType, SWT.BORDER | SWT.READ_ONLY);
    SWTUtil.setGridData(types, true, false, SWT.FILL, SWT.FILL, 1, 1);
    for (ChartType type : ChartType.values()) {
        types.add(type.getName());
    }
    types.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            selectedChartType = ChartType.getTypeForName(types.getItem(types.getSelectionIndex()));
            setOptions();
        }

    });

    XGroup compare = new XGroup(dialogShell, SWT.NONE);
    compare.setTextForLocaleKey("ChartConfigDialog.group.compareRecords"); //$NON-NLS-1$
    compare.setToolTipTextForLocaleKey("ChartConfigDialog.group.tooltip.compareRecords"); //$NON-NLS-1$
    SWTUtil.setGridData(compare, true, false, SWT.FILL, SWT.FILL, 1, 1);
    SWTUtil.setGridLayout(compare, 1, true);

    compareRecords = new XCheckBox(compare);
    compareRecords.setTextForLocaleKey("ChartConfigDialog.checkbox.compareRecords"); //$NON-NLS-1$
    compareRecords.setSelection(false);
    compareRecords.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (!compareRecords.getSelection()) {
                try {
                    currentRecord = currentRecords.get(0);
                } catch (Exception ex) {
                    logClass.debug("Error: " + ex.getMessage() + Constants.LINE_SEPARATOR, ex); //$NON-NLS-1$
                }
                setTimes();
            } else {
                if (currentRecord != null) {
                    currentRecords = new ArrayList<Record>();
                    currentRecords.add(currentRecord);
                }
                setTimes();
            }
        }

    });
    SWTUtil.setGridData(compareRecords, true, false, SWT.FILL, SWT.FILL, 1, 1);

    XGroup general = new XGroup(dialogShell, SWT.NONE);
    general.setTextForLocaleKey("ChartConfigDialog.group.generalValues"); //$NON-NLS-1$
    SWTUtil.setGridData(general, true, false, SWT.FILL, SWT.FILL, 1, 1);
    SWTUtil.setGridLayout(general, 2, false);

    label = new XLabel(general, SWT.NONE);
    label.setTextForLocaleKey("ChartConfigDialog.label.robotsInDatabase"); //$NON-NLS-1$
    SWTUtil.setGridData(label, true, false, SWT.FILL, SWT.CENTER, 1, 1);

    robots = new XCombo(general, SWT.READ_ONLY);
    SWTUtil.setGridData(robots, true, false, SWT.FILL, SWT.CENTER, 1, 1);
    for (String robot : ChartDatabaseUtil.getAvailableRobots()) {
        robots.add(robot);
    }
    robots.select(-1);
    robots.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = ((XCombo) e.widget).getSelectionIndex();
            robotName = ((XCombo) e.widget).getItem(idx);
            if (idx >= 0) {
                lookup.setEnabled(true);
            } else {
                lookup.setEnabled(false);
            }
        }

    });

    label = new XLabel(general, SWT.NONE);
    label.setTextForLocaleKey("ChartConfigDialog.label.lookupRecords"); //$NON-NLS-1$
    SWTUtil.setGridData(label, true, false, SWT.FILL, SWT.FILL, 1, 1);

    lookup = new XButton(general, XButtonType.LOOKUP);
    SWTUtil.setGridData(lookup, true, false, SWT.FILL, SWT.FILL, 1, 1);
    lookup.setEnabled(false);
    lookup.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            int idx = robots.getSelectionIndex();
            String selection = robots.getItem(idx);
            RecordLookupDialog rld = new RecordLookupDialog(dialogShell, selection);

            if (compareRecords.getSelection()) {
                List<Record> records = rld.openMulti();
                if (!records.isEmpty() && records != null) {
                    currentRecords = records;
                    setKeysList();
                    setTimes();
                    generate.setEnabled(false);
                }
            } else {
                Record record = rld.openSingle();
                if (record != null) {
                    currentRecord = record;
                    setKeysList();
                    setTimes();
                    generate.setEnabled(false);
                }
            }
            if (allKeys.getSelection()) {
                generate.setEnabled(true);
            }
        }

    });

    XGroup keys = new XGroup(dialogShell, SWT.NONE);
    keys.setTextForLocaleKey("ChartConfigDialog.group.chooseKey"); //$NON-NLS-1$
    SWTUtil.setGridData(keys, true, false, SWT.FILL, SWT.FILL, 1, 1);
    SWTUtil.setGridLayout(keys, 1, true);

    keysList = new XList(keys, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL);
    SWTUtil.setGridData(keysList, true, true, SWT.FILL, SWT.FILL, 1, 1);
    keysList.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (keysList.getSelectionCount() > 0) {
                generate.setEnabled(true);
            } else {
                generate.setEnabled(false);
            }
        }

    });

    time = new XGroup(dialogShell, SWT.NONE);
    time.setTextForLocaleKey("ChartConfigDialog.group.timeInterval"); //$NON-NLS-1$
    SWTUtil.setGridData(time, true, false, SWT.FILL, SWT.FILL, 2, 1);
    SWTUtil.setGridLayout(time, 1, false);

    XGroup chartOptions = new XGroup(dialogShell, SWT.NONE);
    chartOptions.setTextForLocaleKey("ChartConfigDialog.group.chartOptions"); //$NON-NLS-1$
    SWTUtil.setGridData(chartOptions, true, false, SWT.FILL, SWT.FILL, 2, 1);
    SWTUtil.setGridLayout(chartOptions, 2, true);

    relative = new XCheckBox(chartOptions);
    relative.setTextForLocaleKey("ChartConfigDialog.checkbox.relativeValues"); //$NON-NLS-1$
    relative.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.relativeValues"); //$NON-NLS-1$
    relative.setSelection(false);
    relative.setEnabled(false);
    optionCheckBoxes.add(relative);
    SWTUtil.setGridData(relative, true, false, SWT.FILL, SWT.FILL, 2, 1);
    relative.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (selectedChartType == ChartType.PIE) {
                if (relative.getSelection()) {
                    allKeys.setSelection(true);
                    keysList.selectAll();
                    keysList.setEnabled(false);
                    generate.setEnabled(true);
                } else {
                    allKeys.setSelection(false);
                    keysList.setEnabled(true);
                    keysList.deselectAll();
                    generate.setEnabled(false);
                }
            }
            setOptions();
        }

    });

    allKeys = new XCheckBox(chartOptions);
    allKeys.setTextForLocaleKey("ChartConfigDialog.checkbox.allKeys"); //$NON-NLS-1$
    allKeys.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.allKeys"); //$NON-NLS-1$
    allKeys.setSelection(false);
    allKeys.setEnabled(false);
    optionCheckBoxes.add(allKeys);
    allKeys.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (allKeys.getSelection()) {
                keysList.selectAll();
                keysList.setEnabled(false);
                generate.setEnabled(true);
            } else {
                keysList.setEnabled(true);
                keysList.deselectAll();
                generate.setEnabled(false);
            }
        }

    });
    SWTUtil.setGridData(allKeys, true, false, SWT.FILL, SWT.FILL, 2, 1);

    // showAverage = new HCheckBox(chartOptions);
    // showAverage.setTextForLocaleKey("Show average");
    // showAverage
    // .setToolTipTextForLocaleKey("Show average line in
    // regression chart.");
    // showAverage.setSelection(false);
    // showAverage.setEnabled(false);
    // optionCheckBoxes.add(showAverage);
    // SWTUtil.setGridData(showAverage, true, false, SWT.FILL,
    // SWT.FILL, 2, 1);

    showThreshold = new XCheckBox(chartOptions);
    showThreshold.setTextForLocaleKey("ChartConfigDialog.checkbox.threshold"); //$NON-NLS-1$
    showThreshold.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.threshold"); //$NON-NLS-1$
    showThreshold.setSelection(false);
    showThreshold.setEnabled(false);
    optionCheckBoxes.add(showThreshold);
    SWTUtil.setGridData(showThreshold, true, false, SWT.FILL, SWT.FILL, 2, 1);
    showThreshold.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            setThresholdSpinner();
        }

    });

    threeD = new XCheckBox(chartOptions);
    threeD.setTextForLocaleKey("ChartConfigDialog.checkbox.threeDee"); //$NON-NLS-1$
    threeD.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.threeDee"); //$NON-NLS-1$
    threeD.setSelection(false);
    threeD.setEnabled(false);
    optionCheckBoxes.add(threeD);
    SWTUtil.setGridData(threeD, true, false, SWT.FILL, SWT.FILL, 2, 1);

    exportPDF = new XCheckBox(chartOptions);
    exportPDF.setTextForLocaleKey("ChartConfigDialog.checkbox.export.pdf"); //$NON-NLS-1$
    exportPDF.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.export.pdf"); //$NON-NLS-1$
    exportPDF.setSelection(false);
    exportPDF.setEnabled(false);
    optionCheckBoxes.add(exportPDF);
    SWTUtil.setGridData(exportPDF, true, false, SWT.FILL, SWT.FILL, 2, 1);

    exportPNG = new XCheckBox(chartOptions);
    exportPNG.setTextForLocaleKey("ChartConfigDialog.checkbox.export.png"); //$NON-NLS-1$
    exportPNG.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.export.png"); //$NON-NLS-1$
    exportPNG.setSelection(false);
    exportPNG.setEnabled(false);
    optionCheckBoxes.add(exportPNG);
    SWTUtil.setGridData(exportPNG, true, false, SWT.FILL, SWT.FILL, 2, 1);

    exportJPEG = new XCheckBox(chartOptions);
    exportJPEG.setTextForLocaleKey("ChartConfigDialog.checkbox.export.jpg"); //$NON-NLS-1$
    exportJPEG.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.export.jpg"); //$NON-NLS-1$
    exportJPEG.setSelection(false);
    exportJPEG.setEnabled(false);
    optionCheckBoxes.add(exportJPEG);
    SWTUtil.setGridData(exportJPEG, true, false, SWT.FILL, SWT.FILL, 2, 1);

    exportCSV = new XCheckBox(chartOptions);
    exportCSV.setTextForLocaleKey("ChartConfigDialog.checkbox.export.csv"); //$NON-NLS-1$
    exportCSV.setToolTipTextForLocaleKey("ChartConfigDialog.checkbox.tooltip.export.csv"); //$NON-NLS-1$
    exportCSV.setSelection(false);
    exportCSV.setEnabled(false);
    optionCheckBoxes.add(exportCSV);
    SWTUtil.setGridData(exportCSV, true, false, SWT.FILL, SWT.FILL, 2, 1);

    thresLabel = new XLabel(chartOptions, SWT.NONE);
    thresLabel.setTextForLocaleKey("ChartConfigDialog.label.thresholdToShoe"); //$NON-NLS-1$
    SWTUtil.setGridData(thresLabel, true, false, SWT.FILL, SWT.FILL, 1, 1);
    thresLabel.setEnabled(false);

    threshold = new XStyledSpinner(chartOptions, SWT.BORDER, SpinnerStyle.ALL);
    SWTUtil.setGridData(threshold, true, false, SWT.FILL, SWT.FILL, 1, 1);
    threshold.setEnabled(false);
    threshold.setIncrement(1);
    threshold.setMinimum(Double.MIN_VALUE);
    threshold.setMaximum(Double.MAX_VALUE);

    generate = new XButton(dialogShell);
    generate.setTextForLocaleKey("ChartConfigDialog.button.generateChart"); //$NON-NLS-1$
    generate.setEnabled(false);
    SWTUtil.setGridData(generate, true, false, SWT.FILL, SWT.END, 2, 1);
    generate.addSelectionListener(new SelectionAdapter() {

        /*
         * (non-Javadoc)
         * 
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            SWTUtil.showBusyWhile(dialogShell, new Runnable() {

                public void run() {
                    showChart(dialogShell, generateChart());
                }

            });
        }

    });

    dialogShell.pack();
    dialogShell.layout();
    SWTUtil.centerDialog(dialogShell);
    dialogShell.open();

    SWTUtil.blockDialogFromReturning(dialogShell);

    return;
}

From source file:org.nmrfx.processor.gui.PropertyManager.java

void setupItems() {
    ArrayList pyDocs = processorController.chartProcessor.getDocs();
    for (int i = 0; i < pyDocs.size(); i += 3) {
        String op = (String) pyDocs.get(i);
        ArrayList parList = (ArrayList) pyDocs.get(i + 1);
        String description = (String) pyDocs.get(i + 2);

        for (Object parObj : parList) {
            HashMap parMap = (HashMap) parObj;
            String name = (String) parMap.get("name");
            String parDesc = (String) parMap.get("desc");
            Boolean optional = (Boolean) parMap.get("optional");
            ArrayList types = (ArrayList) parMap.get("type");

            if (types.size() == 1) {
                String type = (String) types.get(0);
                switch (type) {
                case "string": {
                    String defaultString;
                    Object defObj = parMap.get("default");
                    if (defObj instanceof String) {
                        defaultString = (String) defObj;
                    } else if (defObj == null) {
                        defaultString = ""; // fixme  what to do when no default
                    } else {
                        defaultString = defObj.toString();
                    }//from  w ww . j  a  v a2 s. co m
                    propItems.add(new TextOperationItem(stringListener, defaultString, op, name, parDesc));

                    break;
                }
                case "wstring": {
                    String defaultString;
                    Object defObj = parMap.get("default");
                    if (defObj instanceof String) {
                        defaultString = (String) defObj;
                    } else if (defObj == null) {
                        defaultString = ""; // fixme  what to do when no default
                    } else {
                        defaultString = defObj.toString();
                    }
                    propItems.add(new TextWaitingOperationItem(null, this::updateOp, defaultString, op, name,
                            parDesc));
                    break;
                }
                case "file":
                    String defaultString;
                    Object defObj = parMap.get("default");
                    if (defObj instanceof String) {
                        defaultString = (String) defObj;
                    } else if (defObj == null) {
                        defaultString = ""; // fixme  what to do when no default
                    } else {
                        defaultString = defObj.toString();
                    }
                    propItems.add(new FileOperationItem(stringListener, defaultString, op, name, parDesc));
                    break;
                case "bool":
                    boolean defaultBool;
                    defObj = parMap.get("default");
                    if (defObj instanceof Boolean) {
                        defaultBool = ((Boolean) defObj);
                    } else if (defObj == null) {
                        defaultBool = false; // fixme  what to do when no default
                    } else {
                        String defStr = (String) defObj;
                        defaultBool = Boolean.parseBoolean(defStr);
                    }
                    propItems.add(new BooleanOperationItem(boolListener, defaultBool, op, name, parDesc));
                    break;
                case "int":
                    int minInt = -16384;
                    int maxInt = 16384;
                    if (parMap.containsKey("min")) {
                        Object minObj = parMap.get("min");
                        if (minObj instanceof Integer) {
                            minInt = ((Integer) minObj).intValue();
                        } else {
                            String minStr = (String) minObj;
                            if (minStr.startsWith("size")) {
                                minInt = 0;
                            } else {
                                minInt = Integer.parseInt(minStr);
                            }
                        }
                    }
                    if (parMap.containsKey("max")) {
                        Object maxObj = parMap.get("max");
                        if (maxObj instanceof Integer) {
                            maxInt = ((Integer) maxObj).intValue();
                        } else {

                            String maxStr = (String) maxObj;
                            if (maxStr.startsWith("size")) {
                                maxInt = 16384;
                            } else {
                                maxInt = Integer.parseInt(maxStr);
                            }
                        }
                    }
                    int defaultInt;
                    defObj = parMap.get("default");
                    if (defObj instanceof Integer) {
                        defaultInt = ((Integer) defObj).intValue();
                    } else if (defObj == null) {
                        defaultInt = 0; // fixme  what to do when no default
                    } else {
                        String defStr = (String) defObj;
                        defaultInt = Integer.parseInt(defStr);
                    }
                    if ((maxInt - minInt) < 2048) {
                        propItems.add(new IntRangeOperationItem(intListener, defaultInt, minInt, maxInt, op,
                                name, parDesc));
                    } else {
                        propItems.add(new IntOperationItem(intListener, defaultInt, minInt, maxInt, op, name,
                                parDesc));

                    }

                    break;
                case "complex":
                    Object defComplexObj = parMap.get("default");
                    if (defComplexObj instanceof PyComplex) {
                        PyComplex defPyComplex = (PyComplex) defComplexObj;
                        Complex defComplex = new Complex(defPyComplex.real, defPyComplex.imag);
                        ComplexOperationItem crItem = new ComplexOperationItem(complexListener, defComplex, op,
                                name, parDesc);
                        propItems.add(crItem);
                    } else if (defComplexObj instanceof Number) {
                        PyComplex defPyComplex = (PyComplex) defComplexObj;
                        Complex defComplex = new Complex(defPyComplex.real, defPyComplex.imag);
                        ComplexOperationItem crItem = new ComplexOperationItem(complexListener, defComplex, op,
                                name, parDesc);
                        propItems.add(crItem);
                    }
                    break;

                case "real":
                case "double":
                case "position":
                    double minDouble = -100000.0;
                    double maxDouble = 100000.0;
                    if (parMap.containsKey("min")) {
                        Object minObj = parMap.get("min");
                        if (minObj instanceof Double) {
                            minDouble = ((Double) minObj).doubleValue();
                        } else {
                            String minStr = (String) minObj;
                            if (minStr.startsWith("size")) {
                                minDouble = 0;
                            } else if (minStr.startsWith("Double.MIN")) {
                                minDouble = Double.MIN_VALUE;
                            } else {
                                minDouble = Double.parseDouble(minStr);
                            }
                        }
                    }
                    if (parMap.containsKey("max")) {
                        Object maxObj = parMap.get("max");
                        if (maxObj instanceof Double) {
                            maxDouble = ((Double) maxObj).doubleValue();
                        } else {

                            String maxStr = (String) maxObj;
                            if (maxStr.startsWith("size")) {
                                maxDouble = 1;
                            } else if (maxStr.startsWith("Double.MAX")) {
                                maxDouble = 100000.0;
                            } else {
                                maxDouble = Double.parseDouble(maxStr);
                            }
                        }
                    }
                    double aminDouble = Double.NEGATIVE_INFINITY;
                    double amaxDouble = Double.MAX_VALUE;
                    if (parMap.containsKey("amin")) {
                        Object minObj = parMap.get("amin");
                        if (minObj instanceof Double) {
                            aminDouble = ((Double) minObj).doubleValue();
                        } else {
                            String minStr = (String) minObj;
                            if (minStr.startsWith("size")) {
                                aminDouble = 0;
                            } else if (minStr.startsWith("Double.MIN")) {
                                aminDouble = Double.MIN_VALUE;
                            } else {
                                aminDouble = Double.parseDouble(minStr);
                            }
                        }

                    }
                    if (parMap.containsKey("amax")) {
                        Object maxObj = parMap.get("amax");
                        if (maxObj instanceof Double) {
                            amaxDouble = ((Double) maxObj).doubleValue();
                        } else {

                            String maxStr = (String) maxObj;
                            if (maxStr.startsWith("size")) {
                                amaxDouble = 1;
                            } else if (maxStr.startsWith("Double.MAX")) {
                                amaxDouble = 100000.0;
                            } else {
                                amaxDouble = Double.parseDouble(maxStr);
                            }
                        }

                    }
                    double defaultDouble;
                    char lastChar = (char) -1;
                    Object defDoubleObj = parMap.get("default");
                    if (defDoubleObj instanceof Double) {
                        defaultDouble = ((Double) defDoubleObj).doubleValue();
                    } else if (defDoubleObj instanceof Integer) {
                        defaultDouble = ((Integer) defDoubleObj).doubleValue();
                    } else if (defDoubleObj == null) {
                        defaultDouble = 0.0; // fixme  what to do when no default
                    } else {
                        String defStr = (String) defDoubleObj;
                        if (type.equals("position")) {
                            lastChar = defStr.charAt(defStr.length() - 1);
                            if (!Character.isLetter(lastChar)) {
                                lastChar = (char) -1;
                            }
                        }
                        defaultDouble = Double.parseDouble(defStr);
                    }

                    DoubleRangeOperationItem drItem = new DoubleRangeOperationItem(doubleListener,
                            defaultDouble, minDouble, maxDouble, aminDouble, amaxDouble, op, name, parDesc);
                    drItem.setLastChar(lastChar);
                    propItems.add(drItem);

                    break;
                case "list":
                    ArrayList listTypes = (ArrayList) parMap.get("listTypes");
                    ListOperationItem lstItem;
                    ArrayList defaultList = (ArrayList) parMap.get("default");
                    //ListOperationItemTypeSelector typeSelector = new ListOperationItemTypeSelector(stringListener, (String) listTypes.get(0), listTypes, op, "listType", parDesc);
                    ListOperationItemTypeSelector typeSelector = null;

                    if (listTypes == null || listTypes.isEmpty()) { // just a default list, so treat them as real values.
                        lstItem = new ListOperationItem(listListener, defaultList, listTypes, op, name, parDesc,
                                typeSelector);
                    } else {
                        lstItem = new ListOperationItem(listListener, defaultList, listTypes, op, name, parDesc,
                                typeSelector);
                    }

                    propItems.add(lstItem);
                    //propItems.add(typeSelector);
                    //propItems.add(listItemTypeSelector(listType));

                    //                            ListOperationItem lstItem = new ListOperationItem(listListener, defaultList, listType, op, name, parDesc)
                    break;
                default:
                    break;
                }
            } else {
                boolean isInt = true;
                for (Object type : types) {
                    if (!(type instanceof Integer)) {
                        isInt = false;
                        break;

                    }
                }
                if (isInt) {
                    propItems.add(new IntChoiceOperationItem(intListener, (Integer) types.get(0), types, op,
                            name, parDesc));
                } else {
                    propItems.add(new ChoiceOperationItem(stringListener, (String) types.get(0), types, op,
                            name, parDesc));

                }
            }
            // propItems.add(new DoubleRangeOperationItem(doubleListener, 1.0, 0.5, 1.0, "SB", "c", "First point multiplier"));

        }
        propItems.add(new BooleanOperationItem(boolListener, false, op, "disabled", "Disable this operation"));
    }

    //propItems.add(new DoubleRangeOperationItem(doubleListener, 1.0, 0.5, 1.0, "SB", "c", "First point multiplier"));
}

From source file:com.bytelightning.opensource.pokerface.PokerFace.java

/**
 * Utility method that allows us to be very flexible in how many reactor processors are allocated to a reactor.
 * @param num   If not a finite number, returns 1.
 *             If <= 0, returns the actual number of Runtime.getRuntime().availableProcessors().
 *             If >= 1, returns the minimum of <code>num</code> or (Runtime.getRuntime().availableProcessors(). * 2)
 *             If > 0 && < 1, returns (num * Runtime.getRuntime().availableProcessors()).
 * @return   The translated number of IOProcessors for a reactor.
 *//* w  w  w .ja  va2  s  . com*/
private static int ComputeReactorProcessors(double num) {
    if (!Double.isFinite(num))
        num = 1d;
    if (num <= 0)
        return Runtime.getRuntime().availableProcessors();
    if (num >= (1d - Double.MIN_VALUE))
        return Math.min((int) Math.rint(num), (Runtime.getRuntime().availableProcessors() * 2));
    return Math.max(1, (int) Math.rint(Runtime.getRuntime().availableProcessors() * num));
}