Example usage for java.lang Float MAX_VALUE

List of usage examples for java.lang Float MAX_VALUE

Introduction

In this page you can find the example usage for java.lang Float MAX_VALUE.

Prototype

float MAX_VALUE

To view the source code for java.lang Float MAX_VALUE.

Click Source Link

Document

A constant holding the largest positive finite value of type float , (2-2-23)·2127.

Usage

From source file:au.org.ala.delta.editor.slotfile.directive.DirOutDefault.java

private void writeKeyStates(MutableDeltaDataSet dataSet, DirectiveArguments directiveArgs) {
    int prevNo;//w w  w . j  a  v a 2 s .  c  o m
    int curNo;
    List<DirectiveArgument<?>> args;
    List<Integer> data;
    // The comparison function will sort all the key states, grouping
    // all those belonging to a single character, sorted in order by
    // there pseudo-value.
    args = directiveArgs.getDirectiveArguments();
    Collections.sort(args);
    prevNo = 0;
    for (DirectiveArgument<?> vectIter : directiveArgs.getDirectiveArguments()) {
        au.org.ala.delta.model.Character charBase = dataSet.getCharacter((Integer) vectIter.getId());
        CharacterType charType = charBase.getCharacterType();
        curNo = charBase.getCharacterId();
        if (curNo != prevNo) {
            _textBuffer.append(" ").append(curNo).append(",");
            prevNo = curNo;
        } else
            _textBuffer.append('/');

        switch (charType) {
        case UnorderedMultiState:
            data = vectIter.getDataList();
            Collections.sort(data);
            for (int j = 0; j < data.size(); j++) {
                if (j != 0)
                    _textBuffer.append('&');
                _textBuffer.append(data.get(j));
            }
            break;

        case OrderedMultiState:

        {
            data = vectIter.getDataList();
            int loState, hiState, aState;

            if (data.size() < 2)
                throw new RuntimeException("ED_INTERNAL_ERROR");
            aState = data.get(0);
            hiState = data.get(1);
            loState = Math.min(aState, hiState);
            hiState = Math.max(aState, hiState);
            _textBuffer.append(loState);
            if (hiState > loState) {
                _textBuffer.append('-');
                _textBuffer.append(hiState);
            }
        }
            break;

        case IntegerNumeric:
        case RealNumeric: {
            List<BigDecimal> bigDecimals = vectIter.getData();
            BigDecimal loNumb, hiNumb;
            if (bigDecimals.size() < 2)
                throw new RuntimeException("ED_INTERNAL_ERROR");
            loNumb = bigDecimals.get(0);
            hiNumb = bigDecimals.get(1);
            if (loNumb.floatValue() == -Float.MAX_VALUE)
                _textBuffer.append('~');
            else {
                _textBuffer.append(loNumb.toPlainString());
            }
            if (hiNumb.floatValue() == Float.MAX_VALUE)
                _textBuffer.append('~');
            else if (loNumb.compareTo(hiNumb) < 0) {
                if (!(loNumb.floatValue() == -Float.MAX_VALUE))
                    _textBuffer.append('-');

                _textBuffer.append(hiNumb.toPlainString());
            }
        }
            break;

        default:
            throw new RuntimeException("ED_INAPPROPRIATE_TYPE");
            // break;
        }
    }
}

From source file:nuke.bq.activities.BarcodeCaptureActivity.java

/**
 * onTap returns the tapped barcode result to the calling Activity.
 *
 * @param rawX - the raw position of the tap
 * @param rawY - the raw position of the tap.
 * @return true if the activity is ending.
 *///  w  w w.  ja v  a 2s.  co  m
private boolean onTap(float rawX, float rawY) {
    // Find tap point in preview frame coordinates.
    int[] location = new int[2];
    mGraphicOverlay.getLocationOnScreen(location);
    float x = (rawX - location[0]) / mGraphicOverlay.getWidthScaleFactor();
    float y = (rawY - location[1]) / mGraphicOverlay.getHeightScaleFactor();

    // Find the barcode whose center is closest to the tapped point.
    Barcode best = null;
    float bestDistance = Float.MAX_VALUE;
    for (BarcodeGraphic graphic : mGraphicOverlay.getGraphics()) {
        Barcode barcode = graphic.getBarcode();
        Log.e("BARR", barcode.rawValue);
        if (barcode.getBoundingBox().contains((int) x, (int) y)) {
            // Exact hit, no need to keep looking.
            best = barcode;
            break;
        }
        float dx = x - barcode.getBoundingBox().centerX();
        float dy = y - barcode.getBoundingBox().centerY();
        float distance = (dx * dx) + (dy * dy); // actually squared distance
        if (distance < bestDistance) {
            best = barcode;
            bestDistance = distance;
        }
    }

    if (best != null) {
        Intent data = new Intent();
        data.putExtra(BarcodeObject, best);
        setResult(CommonStatusCodes.SUCCESS, data);
        finish();
        return true;
    }
    return false;
}

From source file:com.spoiledmilk.ibikecph.navigation.routing_engine.SMRoute.java

boolean parseFromJson(JsonNode jsonRoot, SMRouteListener listener, boolean isBrokenRoute) {
    LOG.d("SMRoute parseFromJson() json = " + jsonRoot);
    synchronized (this) {
        if (jsonRoot == null) {
            return false;
        }/*  w ww . j  a  v  a2s  .  c  o m*/
        waypoints = decodePolyline(jsonRoot.path("route_geometry").textValue());

        if (waypoints.size() < 2) {
            return false;
        }

        turnInstructions = new ArrayList<SMTurnInstruction>();
        pastTurnInstructions = new LinkedList<SMTurnInstruction>();
        visitedLocations = new ArrayList<Location>();
        estimatedArrivalTime = jsonRoot.path("route_summary").path("total_time").asInt();
        arrivalTime = estimatedArrivalTime;
        distancePassed = 0d;
        if (estimatedRouteDistance < 0)
            estimatedRouteDistance = jsonRoot.path("route_summary").path("total_distance").asInt();

        routeChecksum = null;
        destinationHint = null;

        if (!jsonRoot.path("hint_data").path("checksum").isMissingNode()) {
            routeChecksum = jsonRoot.path("hint_data").path("checksum").asText();
        }

        JsonNode hint_locations = jsonRoot.path("hint_data").path("locations");
        if (hint_locations != null && !hint_locations.isMissingNode() && hint_locations.size() > 0) {
            destinationHint = jsonRoot.path("hint_data").path("locations").get(hint_locations.size() - 1)
                    .asText();
        }

        JsonNode routeInstructionsArr = jsonRoot.path("route_instructions");
        if (routeInstructionsArr != null && routeInstructionsArr.size() > 0) {
            int prevlengthInMeters = 0;
            String prevlengthWithUnit = "";
            boolean isFirst = true;
            for (JsonNode instructionNode : routeInstructionsArr) {
                SMTurnInstruction instruction = new SMTurnInstruction();

                String[] arr = instructionNode.get(0).asText().split("-");
                if (arr.length < 1)
                    continue;
                int pos = Integer.valueOf(arr[0]);
                if (pos <= 17) {
                    instruction.drivingDirection = TurnDirection.values()[pos];
                    if (arr.length > 1 && arr[1] != null) {
                        instruction.ordinalDirection = arr[1];
                    } else {
                        instruction.ordinalDirection = "";
                    }

                    instruction.wayName = instructionNode.get(1).asText();
                    if (instruction.wayName.matches("\\{.+\\:.+\\}"))
                        instruction.wayName = IbikeApplication.getString(instruction.wayName);
                    instruction.wayName = instruction.wayName.replaceAll("&#39;", "'");
                    instruction.lengthInMeters = prevlengthInMeters;
                    prevlengthInMeters = instructionNode.get(2).asInt();
                    instruction.timeInSeconds = instructionNode.get(4).asInt();
                    instruction.lengthWithUnit = prevlengthWithUnit;
                    if (instructionNode.size() > 8) {
                        instruction.vehicle = instructionNode.get(8).asInt();
                    }
                    /**
                     * Save length to next turn with units so we don't have to generate it each time It's formatted just the way we like it
                     */
                    instruction.fixedLengthWithUnit = Util.formatDistance(prevlengthInMeters);
                    prevlengthWithUnit = instructionNode.get(5).asText();
                    instruction.directionAbrevation = instructionNode.get(6).asText();
                    instruction.azimuth = (float) instructionNode.get(7).asDouble();

                    if (isFirst) {
                        instruction.generateStartDescriptionString();
                        isFirst = false;
                    } else {
                        instruction.generateDescriptionString();
                    }
                    instruction.generateFullDescriptionString();
                    int position = instructionNode.get(3).asInt();
                    instruction.waypointsIndex = position;
                    if (waypoints != null && position >= 0 && position < waypoints.size())
                        instruction.loc = waypoints.get(position);
                    turnInstructions.add(instruction);
                }
            }
        }
        if (isRouteBroken && turnInstructions != null) {

            double dStat1 = Double.MAX_VALUE, dStat2 = Double.MAX_VALUE;
            for (int i = 0; i < waypoints.size(); i++) {
                if (startStation.distanceTo(waypoints.get(i)) < dStat1) {
                    dStat1 = startStation.distanceTo(waypoints.get(i));
                    waypointStation1 = i;
                }
                if (endStation.distanceTo(waypoints.get(i)) < dStat2) {
                    dStat2 = endStation.distanceTo(waypoints.get(i));
                    waypointStation2 = i;
                }
            }

            Iterator<SMTurnInstruction> it2 = turnInstructions.iterator();
            float distToStart = Float.MAX_VALUE, distToEnd = Float.MAX_VALUE;
            while (it2.hasNext()) {
                SMTurnInstruction smt = it2.next();
                if (smt.loc.distanceTo(startStation) < distToStart && smt.waypointsIndex <= waypointStation1) {
                    distToStart = smt.loc.distanceTo(startStation);
                    station1 = smt;
                }
                if (smt.loc.distanceTo(endStation) < distToEnd && smt.waypointsIndex <= waypointStation2) {
                    distToEnd = smt.loc.distanceTo(endStation);
                    station2 = smt;
                }
            }

            station1.convertToStation(startStationName, stationIcon);
            station2.convertToStation(endStationName, stationIcon);
            int startIndex = turnInstructions.indexOf(station1);
            int endIndex = turnInstructions.indexOf(station2);
            while (startIndex < endIndex - 1) {
                turnInstructions.remove(startIndex + 1);
                startIndex = turnInstructions.indexOf(station1);
                endIndex = turnInstructions.indexOf(station2);
            }
        }

        int longestStreet = 0;
        viaStreets = "";

        int n = jsonRoot.path("route_name").size();
        if (n > 0) {
            int i = 0;
            for (JsonNode streetNode : jsonRoot.path("route_name")) {
                i++;
                viaStreets += streetNode.asText() + (i == n ? "" : ", ");
            }
        }
        if (viaStreets == null || viaStreets.trim().equals("")) {
            for (int i = 1; i < turnInstructions.size() - 1; i++) {
                SMTurnInstruction inst = turnInstructions.get(i);
                if (inst.lengthInMeters > longestStreet) {
                    longestStreet = inst.lengthInMeters;
                    viaStreets = turnInstructions.get(i - 1).wayName;
                }
            }
        }

        lastVisitedWaypointIndex = 0;
    }
    return true;
}

From source file:it.uniroma2.sag.kelp.learningalgorithm.classification.libsvm.solver.LibSvmSolver.java

/**
 * It solves the SMO algorithm in [CC Chang & CJ Lin, 2011]
 * /*ww  w  .  j  av  a2 s .  c om*/
 * min 0.5(\alpha^T Q \alpha) + p^T \alpha
 * 
 * y^T \alpha = \delta <br>
 * y_i = +1 or -1 <br>
 * 0 <= alpha_i <= Cp for y_i = 1 <br>
 * 0 <= alpha_i <= Cn for y_i = -1 <br>
 * 
 * Given:
 * 
 * Q, p, y, Cp, Cn, and an initial feasible point \alpha l is the size of
 * vectors and matrices eps is the stopping tolerance
 * 
 * solution will be put in \alpha, objective value will be put in obj
 * 
 * 
 * @param l_
 *            the size of input examples
 * @param dataset
 *            the dataset
 * @param p_
 * @param y_
 *            the labels of the examples
 * @param initial_alpha
 *            the initial \(\alpha\) values
 * @return the solution of the SMO problem
 */
public SvmSolution solve(int l_, Dataset dataset, float[] p_, int y_[], float[] initial_alpha) {

    SvmSolution solution = new SvmSolution();

    /**
     * INITIALIZE VARIABLES
     */

    this.l = l_;

    this.examples = new Example[dataset.getNumberOfExamples()];
    for (int i = 0; i < dataset.getNumberOfExamples(); i++) {
        examples[i] = dataset.getExamples().get(i);
    }

    // CHECK
    this.QD = get_QD();
    this.p = p_.clone();

    this.y = y_.clone();

    this.alpha = initial_alpha.clone();

    // initialize alpha_status
    {
        alpha_status = new AlphaStatus[l];
        for (int i = 0; i < l; i++)
            update_alpha_status(i);
    }

    // initialize active set (for shrinking)
    {
        active_set = new int[l];
        for (int i = 0; i < l; i++)
            active_set[i] = i;
        active_size = l;
    }

    // initialize gradient
    {
        G = new float[l];
        G_bar = new float[l];
        int i;
        for (i = 0; i < l; i++) {
            G[i] = p[i];
            G_bar[i] = 0;
        }
        for (i = 0; i < l; i++)
            if (!is_lower_bound(i)) {
                // float[] Q_i = get_Q(i, l);
                double alpha_i = alpha[i];
                int j;
                for (j = 0; j < l; j++)
                    G[j] += alpha_i * get_Qij(i, j);
                if (is_upper_bound(i))
                    for (j = 0; j < l; j++)
                        G_bar[j] += get_C(i) * get_Qij(i, j);
            }
    }

    this.unshrink = false;

    /**
     * optimization step
     */

    int iter = 0;
    int max_iter = (int) Math.max(MAX_ITERATION,
            l > (float) Float.MAX_VALUE / 100f ? Float.MAX_VALUE : 100f * l);
    int counter = Math.min(l, shrinkingIteration) + 1;

    /*
     * USED TO GET i and j from the select_working_set()
     */
    Pair pair = new Pair();

    while (iter < max_iter) {

        // show progress and do shrinking

        if (iter % logIteration == 0)
            info(".");

        if (--counter == 0) {
            counter = Math.min(l, shrinkingIteration);
            if (doShrinking)
                do_shrinking();
            info("s");
        }

        if (select_working_set(pair) != 0) {
            // reconstruct the whole gradient
            reconstruct_gradient();
            // reset active set size and check
            active_size = l;
            info("d");
            if (select_working_set(pair) != 0) {
                /*
                 * DONE
                 */
                break;
            } else
                counter = 1; // do shrinking next iteration
        }

        int i = pair.i;
        int j = pair.j;

        // System.out.println(i+" "+j);

        ++iter;

        // update alpha[i] and alpha[j], handle bounds carefully

        // float[] Q_i = get_Q(i, active_size);
        // float[] Q_j = get_Q(j, active_size);

        float C_i = get_C(i);
        float C_j = get_C(j);

        float old_alpha_i = alpha[i];
        float old_alpha_j = alpha[j];

        if (y[i] != y[j]) {

            float quad_coef = QD[i] + QD[j] + 2 * get_Qij(i, j);

            // System.out.println(i +" "+ j +" "+ QD[i]+ " "+QD[j]+ " "+
            // get_Qij(i, j));
            if (quad_coef <= 0)
                quad_coef = TAU;
            float delta = (-G[i] - G[j]) / quad_coef;
            float diff = alpha[i] - alpha[j];
            alpha[i] += delta;
            alpha[j] += delta;

            if (diff > 0) {
                if (alpha[j] < 0) {
                    alpha[j] = 0;
                    alpha[i] = diff;
                }
            } else {
                if (alpha[i] < 0) {
                    alpha[i] = 0;
                    alpha[j] = -diff;
                }
            }
            if (diff > C_i - C_j) {
                if (alpha[i] > C_i) {
                    alpha[i] = C_i;
                    alpha[j] = C_i - diff;
                }
            } else {
                if (alpha[j] > C_j) {
                    alpha[j] = C_j;
                    alpha[i] = C_j + diff;
                }
            }
        } else {
            float quad_coef = QD[i] + QD[j] - 2 * get_Qij(i, j);
            if (quad_coef <= 0)
                quad_coef = TAU;
            float delta = (G[i] - G[j]) / quad_coef;
            float sum = alpha[i] + alpha[j];
            alpha[i] -= delta;
            alpha[j] += delta;

            if (sum > C_i) {
                if (alpha[i] > C_i) {
                    alpha[i] = C_i;
                    alpha[j] = sum - C_i;
                }
            } else {
                if (alpha[j] < 0) {
                    alpha[j] = 0;
                    alpha[i] = sum;
                }
            }
            if (sum > C_j) {
                if (alpha[j] > C_j) {
                    alpha[j] = C_j;
                    alpha[i] = sum - C_j;
                }
            } else {
                if (alpha[i] < 0) {
                    alpha[i] = 0;
                    alpha[j] = sum;
                }
            }
        }

        // update G
        double delta_alpha_i = alpha[i] - old_alpha_i;
        double delta_alpha_j = alpha[j] - old_alpha_j;

        for (int k = 0; k < active_size; k++) {
            G[k] += get_Qij(i, k) * delta_alpha_i + get_Qij(j, k) * delta_alpha_j;
        }

        // update alpha_status and G_bar
        {
            boolean ui = is_upper_bound(i);
            boolean uj = is_upper_bound(j);
            update_alpha_status(i);
            update_alpha_status(j);
            int k;
            if (ui != is_upper_bound(i)) {

                if (ui)
                    for (k = 0; k < l; k++)
                        G_bar[k] -= C_i * get_Qij(i, k);
                else
                    for (k = 0; k < l; k++)
                        G_bar[k] += C_i * get_Qij(i, k);
            }

            if (uj != is_upper_bound(j)) {
                // Q_j = get_Q(j, l);
                if (uj)
                    for (k = 0; k < l; k++)
                        G_bar[k] -= C_j * get_Qij(j, k);
                else
                    for (k = 0; k < l; k++)
                        G_bar[k] += C_j * get_Qij(j, k);
            }
        }
    }

    if (iter > max_iter) {
        if (active_size < l) {
            // reconstruct the whole gradient to calculate objective value
            reconstruct_gradient();
            active_size = l;
            info("*");
        }
        info("\nWARNING: reaching max number of iterations\n");
    }

    // calculate rho
    solution.setRho(calculate_rho());

    // calculate objective value
    {
        float v = 0;
        int i;
        for (i = 0; i < l; i++)
            v += alpha[i] * (G[i] + p[i]);

        solution.setObj(v / 2);
    }

    // juggle everything back
    /*
     * { for(int i=0;i<l;i++) while(active_set[i] != i)
     * swap_index(i,active_set[i]); // or Q.swap_index(i,active_set[i]); }
     */

    solution.setUpper_bound_p(cp);
    solution.setUpper_bound_n(cn);

    float[] newAlphas = new float[alpha.length];

    for (int i = 0; i < l; i++)
        newAlphas[active_set[i]] = alpha[i];

    solution.setAlphas(newAlphas);

    info("\nOptimization finished after #iter = " + iter + "\n");

    return solution;
}

From source file:com.markupartist.sthlmtraveling.ViewOnMapActivity.java

private void drawPolyline(List<LatLng> latLngs, @ColorInt int color) {
    Polyline poly = mMap.addPolyline(new PolylineOptions().zIndex(1000).addAll(latLngs)
            .width(ViewHelper.dipsToPix(getResources(), 8)).color(color).geodesic(true));
    poly.setZIndex(Float.MAX_VALUE);
}

From source file:com.zzmstring.viewset.View.DragTopLayout.DragTopLayout.java

private void resetDispatchingContentView() {
    ExLog.l(ExLog.getCurrentMethodName());
    dispatchingChildrenDownFaked = false;
    dispatchingChildrenContentView = false;
    dispatchingChildrenStartedAtY = Float.MAX_VALUE;
}

From source file:com.stromberglabs.jopensurf.Surf.java

public Map<SURFInterestPoint, SURFInterestPoint> getMatchingPoints(Surf descriptor, boolean upright) {
    //System.out.println("Finding matching points..");
    Map<SURFInterestPoint, SURFInterestPoint> matchingPoints = new HashMap<SURFInterestPoint, SURFInterestPoint>();
    List<SURFInterestPoint> points = upright ? getUprightInterestPoints() : getFreeOrientedInterestPoints();

    for (SURFInterestPoint a : points) {
        double smallestDistance = Float.MAX_VALUE;
        double nextSmallestDistance = Float.MAX_VALUE;
        SURFInterestPoint possibleMatch = null;

        for (SURFInterestPoint b : upright ? descriptor.getUprightInterestPoints()
                : descriptor.getFreeOrientedInterestPoints()) {
            double distance = a.getDistance(b);
            //System.out.println("Distance = " + distance);
            if (distance < smallestDistance) {
                nextSmallestDistance = smallestDistance;
                smallestDistance = distance;
                possibleMatch = b;/* www.j  av  a  2  s .  c om*/
            } else if (distance < nextSmallestDistance) {
                nextSmallestDistance = distance;
            }
        }

        // If match has a d1:d2 ratio < 0.65 ipoints are a match
        //if ( smallestDistance/nextSmallestDistance < 0.65d ){
        if (smallestDistance / nextSmallestDistance < 0.75d) {
            //not storing change in position
            matchingPoints.put(a, possibleMatch);
        }
    }
    //System.out.println("Done finding matching points");
    return matchingPoints;
}

From source file:org.qi4j.runtime.value.CollectionTypeTest.java

private Collection<Float> floatCollection() {
    Collection<Float> value = new ArrayList<Float>();
    value.add(-1f);/*w  w w .  ja  v  a 2 s. co  m*/
    value.add(1f);
    value.add(1f);
    value.add(0f);
    value.add(Float.MAX_VALUE);
    value.add(Float.MIN_VALUE);
    value.add(null);
    value.add(0.123456f);
    value.add(-0.232321f);
    return value;
}

From source file:org.metawidget.integrationtest.swing.allwidgets.SwingAllWidgetsTest.java

protected void runTest(AdvancedWidgetProcessor<JComponent, SwingMetawidget> processor) throws Exception {

    // Model/*w  ww.  ja  va  2 s  . c o  m*/

    AllWidgets allWidgets = new AllWidgets$$EnhancerByCGLIB$$1234();

    // App

    SwingMetawidget metawidget = new SwingMetawidget();
    metawidget.setConfig("org/metawidget/integrationtest/swing/allwidgets/metawidget.xml");
    metawidget.addWidgetProcessor(processor);
    metawidget.addWidgetProcessor(new ReflectionBindingProcessor());
    metawidget.setMetawidgetLayout(new SeparatorLayoutDecorator(new SeparatorLayoutDecoratorConfig().setLayout(
            new org.metawidget.swing.layout.GridBagLayout(new GridBagLayoutConfig().setNumberOfColumns(2)))));

    metawidget.setToInspect(allWidgets);

    metawidget.add(new Stub("mystery"));

    // Test missing components

    try {
        metawidget.getValue("no-such-component");
        fail();
    } catch (MetawidgetException e1) {
        assertEquals("No component named 'no-such-component'", e1.getMessage());

        try {
            metawidget.getValue("textbox", "no-such-component");
            fail();
        } catch (MetawidgetException e2) {
            assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage());

            try {
                metawidget.getValue("textbox", "no-such-component1", "no-such-component2");
                fail();
            } catch (MetawidgetException e3) {
                assertEquals(
                        "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'",
                        e3.getMessage());
            }
        }
    }

    try {
        metawidget.setValue(null, "no-such-component");
        fail();
    } catch (MetawidgetException e1) {
        assertEquals("No component named 'no-such-component'", e1.getMessage());

        try {
            metawidget.setValue(null, "textbox", "no-such-component");
            fail();
        } catch (MetawidgetException e2) {
            assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage());

            try {
                metawidget.setValue(null, "textbox", "no-such-component1", "no-such-component2");
                fail();
            } catch (MetawidgetException e3) {
                assertEquals(
                        "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'",
                        e3.getMessage());
            }
        }
    }

    // Check what created, and edit it

    assertEquals("Textbox*:", ((JLabel) metawidget.getComponent(0)).getText());
    assertTrue(metawidget.getComponent(1) instanceof JTextField);
    assertEquals("Textbox", metawidget.getValue("textbox"));
    ((JTextField) metawidget.getComponent(1)).setText("Textbox1");

    assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText());
    assertTrue(metawidget.getComponent(3) instanceof JTextField);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(3)).gridx);
    assertEquals("Limited Textbox", metawidget.getValue("limitedTextbox"));
    ((JTextField) metawidget.getComponent(3)).setText("Limited Textbox1");

    assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText());
    assertTrue(metawidget.getComponent(5) instanceof JScrollPane);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(5)).gridx);
    assertEquals("Textarea", metawidget.getValue("textarea"));

    JTextArea textarea = (JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView();
    assertEquals(2, textarea.getRows());
    assertEquals(true, textarea.getLineWrap());
    assertEquals(true, textarea.getWrapStyleWord());
    textarea.setText("Textarea1");

    assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText());
    assertTrue(metawidget.getComponent(7) instanceof JPasswordField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(7)).gridx);
    assertEquals("Password", metawidget.getValue("password"));
    ((JPasswordField) metawidget.getComponent(7)).setText("Password1");

    // Primitives

    assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText());
    assertTrue(metawidget.getComponent(9) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(9)).gridx);
    assertTrue(Byte.MAX_VALUE == (Byte) metawidget.getValue("bytePrimitive"));
    assertTrue(-5 == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel())
            .getMinimum());
    assertTrue(
            Byte.MAX_VALUE == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel())
                    .getMaximum());
    assertEquals(0, ((JSpinner.DefaultEditor) ((JSpinner) metawidget.getComponent(9)).getEditor())
            .getTextField().getColumns());
    JSpinner spinner = (JSpinner) metawidget.getComponent(9);
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText());
    assertTrue(metawidget.getComponent(11) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(11)).gridx);
    assertEquals(String.valueOf(Byte.MIN_VALUE), metawidget.getValue("byteObject"));
    ((JTextField) metawidget.getComponent(11)).setText(String.valueOf(Byte.MIN_VALUE + 1));

    assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText());
    assertTrue(metawidget.getComponent(13) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(13)).gridx);
    assertTrue(Short.MAX_VALUE == (Short) metawidget.getValue("shortPrimitive"));
    assertTrue(-6 == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13)).getModel())
            .getMinimum());
    assertTrue(Short.MAX_VALUE == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13))
            .getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(13);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText());
    assertTrue(metawidget.getComponent(15) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(15)).gridx);
    assertEquals(String.valueOf(Short.MIN_VALUE), metawidget.getValue("shortObject"));
    ((JTextField) metawidget.getComponent(15)).setText(String.valueOf(Short.MIN_VALUE + 1));

    assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText());
    assertTrue(metawidget.getComponent(17) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(17)).gridx);
    assertTrue(Integer.MAX_VALUE == (Integer) metawidget.getValue("intPrimitive"));
    assertTrue(Integer.MIN_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17))
            .getModel()).getMinimum());
    assertTrue(Integer.MAX_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17))
            .getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(17);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getPreviousValue());

    assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText());
    assertTrue(metawidget.getComponent(19) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(19)).gridx);
    assertEquals(String.valueOf(Integer.MIN_VALUE), metawidget.getValue("integerObject"));
    ((JTextField) metawidget.getComponent(19)).setText(String.valueOf(Integer.MIN_VALUE + 1));

    assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText());
    assertTrue(metawidget.getComponent(21) instanceof JSlider);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(21)).gridx);
    assertEquals(1, ((JSlider) metawidget.getComponent(21)).getMinimum());
    assertEquals(100, ((JSlider) metawidget.getComponent(21)).getMaximum());
    assertTrue(32 == (Integer) metawidget.getValue("rangedInt"));
    ((JSlider) metawidget.getComponent(21)).setValue(33);

    assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText());
    assertTrue(metawidget.getComponent(23) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(23)).gridx);
    assertEquals("33", metawidget.getValue("rangedInteger"));
    ((JTextField) metawidget.getComponent(23)).setText(String.valueOf(34));

    assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText());
    assertTrue(metawidget.getComponent(25) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(25)).gridx);
    assertTrue(42 == (Long) metawidget.getValue("longPrimitive"));
    assertTrue(-7 == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel())
            .getMinimum());
    assertTrue(
            Long.MAX_VALUE == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel())
                    .getMaximum());
    spinner = (JSpinner) metawidget.getComponent(25);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertTrue(metawidget.getComponent(26) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(26)).gridx);
    assertEquals("43", metawidget.getValue("longObject"));
    ((JTextField) metawidget.getComponent(26)).setText("44");

    assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText());
    assertTrue(metawidget.getComponent(28) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(28)).gridx);
    assertEquals(4.2f, metawidget.getValue("floatPrimitive"));
    assertEquals(-Float.MAX_VALUE,
            ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel()).getMinimum());
    assertTrue(2048 == (Float) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel())
            .getMaximum());
    spinner = (JSpinner) metawidget.getComponent(28);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText());
    assertTrue(metawidget.getComponent(30) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(30)).gridx);
    assertEquals("4.3", metawidget.getValue("floatObject"));
    ((JTextField) metawidget.getComponent(30)).setText("5.4");

    assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText());
    assertTrue(metawidget.getComponent(32) instanceof JSpinner);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(32)).gridx);
    assertEquals(42.2d, metawidget.getValue("doublePrimitive"));
    assertTrue(-8 == (Double) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel())
            .getMinimum());
    assertEquals(Double.MAX_VALUE,
            ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel()).getMaximum());
    spinner = (JSpinner) metawidget.getComponent(32);
    assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns());
    spinner.setValue(spinner.getModel().getNextValue());

    assertTrue(metawidget.getComponent(33) instanceof JTextField);
    assertEquals(0, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridx);
    assertEquals(2,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridwidth);
    assertEquals("43.3", metawidget.getValue("doubleObject"));
    ((JTextField) metawidget.getComponent(33)).setText("54.4");

    assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText());
    assertTrue(metawidget.getComponent(35) instanceof JTextField);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(35)).gridx);
    assertEquals("A", metawidget.getValue("charPrimitive"));
    ((JTextField) metawidget.getComponent(35)).setText("Z");

    assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText());
    assertTrue(metawidget.getComponent(37) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx);
    assertEquals("Z", metawidget.getValue("characterObject"));
    ((JTextField) metawidget.getComponent(37)).setText("A");

    assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText());
    assertTrue(metawidget.getComponent(39) instanceof JCheckBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(39)).gridx);
    assertTrue(false == (Boolean) metawidget.getValue("booleanPrimitive"));
    ((JCheckBox) metawidget.getComponent(39)).setSelected(true);

    assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText());
    assertTrue(metawidget.getComponent(41) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx);
    assertEquals(3, ((JComboBox) metawidget.getComponent(41)).getItemCount());
    assertEquals(Boolean.TRUE, metawidget.getValue("booleanObject"));
    ((JComboBox) metawidget.getComponent(41)).setSelectedItem(Boolean.FALSE);

    assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText());
    assertTrue(metawidget.getComponent(43) instanceof JComboBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(43)).gridx);
    assertEquals(4, ((JComboBox) metawidget.getComponent(43)).getItemCount());
    assertEquals("dropdown1", metawidget.getValue("dropdown"));
    ((JComboBox) metawidget.getComponent(43)).setSelectedItem("foo1");

    assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText());
    assertTrue(metawidget.getComponent(45) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(45)).gridx);

    JComboBox combo = (JComboBox) metawidget.getComponent(45);
    assertEquals(5, combo.getItemCount());
    assertEquals("Foo #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "foo2", 1, false, false))
                    .getText());
    assertEquals("Dropdown #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(),
            "dropdown2", 1, false, false)).getText());
    assertEquals("Bar #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "bar2", 1, false, false))
                    .getText());
    assertEquals("Baz #2",
            ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "baz2", 1, false, false))
                    .getText());
    assertEquals("dropdown2", metawidget.getValue("dropdownWithLabels"));
    ((JComboBox) metawidget.getComponent(45)).setSelectedItem("bar2");

    assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText());
    assertTrue(metawidget.getComponent(47) instanceof JComboBox);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(47)).gridx);
    assertEquals(3, ((JComboBox) metawidget.getComponent(47)).getItemCount());
    assertTrue(0 == (Byte) metawidget.getValue("notNullDropdown"));
    ((JComboBox) metawidget.getComponent(47)).setSelectedItem((byte) 1);

    assertEquals("Not Null Object Dropdown*:", ((JLabel) metawidget.getComponent(48)).getText());
    assertTrue(metawidget.getComponent(49) instanceof JComboBox);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(49)).gridx);
    assertEquals(6, ((JComboBox) metawidget.getComponent(49)).getItemCount());
    assertEquals("dropdown3", metawidget.getValue("notNullObjectDropdown"));
    ((JComboBox) metawidget.getComponent(49)).setSelectedIndex(0);

    assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText());
    assertTrue(metawidget.getComponent(51) instanceof SwingMetawidget);

    SwingMetawidget metawidgetNested = (SwingMetawidget) metawidget.getComponent(51);

    assertEquals("Further Nested Widgets:", ((JLabel) metawidgetNested.getComponent(0)).getText());
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(1)).gridx);

    SwingMetawidget metawidgetFurtherNested = (SwingMetawidget) metawidgetNested.getComponent(1);
    assertEquals("Further Nested Widgets:", ((JLabel) metawidgetFurtherNested.getComponent(0)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(1) instanceof SwingMetawidget);
    assertEquals(((SwingMetawidget) metawidgetFurtherNested.getComponent(1)).getComponentCount(), 0);

    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetFurtherNested.getComponent(2)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(3) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout())
            .getConstraints(metawidgetFurtherNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1",
            metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox1"));
    ((JTextField) metawidgetFurtherNested.getComponent(3)).setText("Nested Textbox 1.1 (further)");

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetFurtherNested.getComponent(4)).getText());
    assertTrue(metawidgetFurtherNested.getComponent(5) instanceof JTextField);

    // (should be 1, as in next row, if getEffectiveNumberOfColumns is working)

    assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout())
            .getConstraints(metawidgetFurtherNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2",
            metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox2"));
    ((JTextField) metawidgetFurtherNested.getComponent(5)).setText("Nested Textbox 2.2 (further)");

    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText());
    assertTrue(metawidgetNested.getComponent(3) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1", metawidget.getValue("nestedWidgets", "nestedTextbox1"));
    ((JTextField) metawidgetNested.getComponent(3)).setText("Nested Textbox 1.1");

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText());
    assertTrue(metawidgetNested.getComponent(5) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2", metawidget.getValue("nestedWidgets", "nestedTextbox2"));
    ((JTextField) metawidgetNested.getComponent(5)).setText("Nested Textbox 2.2");

    assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText());
    assertTrue(metawidget.getComponent(53) instanceof SwingMetawidget);

    metawidgetNested = (SwingMetawidget) metawidget.getComponent(53);
    assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText());
    assertTrue(metawidgetNested.getComponent(3) instanceof JLabel);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(3)).gridx);
    assertEquals("Nested Textbox 1", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox1"));

    assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText());
    assertTrue(metawidgetNested.getComponent(5) instanceof JLabel);
    assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout())
            .getConstraints(metawidgetNested.getComponent(5)).gridx);
    assertEquals("Nested Textbox 2", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox2"));

    assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JTextField) metawidget.getComponent(55)).getText());
    ((JTextField) metawidget.getComponent(55)).setText("Nested Textbox 1.01, Nested Textbox 2.02");

    assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText());

    assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText());
    assertTrue(metawidget.getComponent(59) instanceof JTextField);
    assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(59)).gridx);

    DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
    assertEquals(dateFormat.format(allWidgets.getDate()), metawidget.getValue("date"));
    ((JTextField) metawidget.getComponent(59)).setText("bad date");

    JPanel separatorPanel = (JPanel) metawidget.getComponent(60);
    assertEquals("Section Break", ((JLabel) separatorPanel.getComponent(0)).getText());
    assertEquals(GridBagConstraints.REMAINDER,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(60)).gridwidth);
    assertTrue(separatorPanel.getComponent(1) instanceof JSeparator);

    assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText());
    assertTrue(metawidget.getComponent(62) instanceof JLabel);
    assertEquals("Read Only", metawidget.getValue("readOnly"));

    assertTrue(metawidget.getComponent(63) instanceof JButton);
    assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).gridx);
    assertEquals(GridBagConstraints.NONE,
            ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).fill);
    JButton button = ((JButton) metawidget.getComponent(63));
    assertEquals("Do Action", button.getText());
    assertTrue(button.isEnabled());
    try {
        button.doClick();
        fail();
    } catch (Exception e) {
        assertEquals("doAction called", e.getCause().getCause().getMessage());
    }

    assertEquals(64, metawidget.getComponentCount());

    // Check painting

    JFrame frame = new JFrame();
    metawidget.paint(frame.getGraphics());

    // Check MetawidgetException

    try {
        processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget);
        fail();
    } catch (Exception e) {
        assertEquals("Could not parse 'bad date'", e.getCause().getCause().getMessage());
    }

    // Check saving

    String now = dateFormat.format(new GregorianCalendar().getTime());
    ((JTextField) metawidget.getComponent(59)).setText(now);
    processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget);

    // Check read-only

    metawidget.setReadOnly(true);

    assertEquals("Textbox:", ((JLabel) metawidget.getComponent(0)).getText());
    assertEquals("Textbox1", ((JLabel) metawidget.getComponent(1)).getText());
    assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText());
    assertEquals("Limited Textbox1", ((JLabel) metawidget.getComponent(3)).getText());
    assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText());
    assertEquals("Textarea1",
            ((JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView()).getText());
    assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText());
    assertTrue(metawidget.getComponent(7) instanceof JPanel);
    assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText());
    assertEquals("126", ((JLabel) metawidget.getComponent(9)).getText());
    assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText());
    assertEquals("-127", ((JLabel) metawidget.getComponent(11)).getText());
    assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText());
    assertEquals("32766", ((JLabel) metawidget.getComponent(13)).getText());
    assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText());
    assertEquals("-32767", ((JLabel) metawidget.getComponent(15)).getText());
    assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText());
    assertEquals("2147483646", ((JLabel) metawidget.getComponent(17)).getText());
    assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText());
    assertEquals("-2147483647", ((JLabel) metawidget.getComponent(19)).getText());
    assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText());
    assertEquals("33", ((JLabel) metawidget.getComponent(21)).getText());
    assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText());
    assertEquals("34", ((JLabel) metawidget.getComponent(23)).getText());
    assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText());
    assertEquals("43", ((JLabel) metawidget.getComponent(25)).getText());
    assertEquals("44", ((JLabel) metawidget.getComponent(26)).getText());
    assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText());
    assertTrue(((JLabel) metawidget.getComponent(28)).getText().startsWith("4.3")
            || ((JLabel) metawidget.getComponent(28)).getText().startsWith("4.299"));
    assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText());
    assertEquals("5.4", ((JLabel) metawidget.getComponent(30)).getText());
    assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText());
    assertTrue(((JLabel) metawidget.getComponent(32)).getText().startsWith("42.3")
            || ((JLabel) metawidget.getComponent(32)).getText().startsWith("42.299"));
    assertEquals("54.4", ((JLabel) metawidget.getComponent(33)).getText());
    assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText());
    assertEquals("Z", ((JLabel) metawidget.getComponent(35)).getText());
    assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText());
    assertEquals("A", ((JLabel) metawidget.getComponent(37)).getText());
    assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText());
    assertEquals("true", ((JLabel) metawidget.getComponent(39)).getText());
    assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText());
    assertEquals("No", ((JLabel) metawidget.getComponent(41)).getText());
    assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText());
    assertEquals("foo1", ((JLabel) metawidget.getComponent(43)).getText());
    assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText());
    assertEquals("Bar #2", ((JLabel) metawidget.getComponent(45)).getText());
    assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText());
    assertEquals("1", ((JLabel) metawidget.getComponent(47)).getText());
    assertEquals("Not Null Object Dropdown:", ((JLabel) metawidget.getComponent(48)).getText());
    assertEquals("foo3", ((JLabel) metawidget.getComponent(49)).getText());
    assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(0)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(0)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(2)).getText());
    assertEquals("Nested Textbox 1.1 (further)",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(4)).getText());
    assertEquals("Nested Textbox 2.2 (further)",
            ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1))
                    .getComponent(5)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(2)).getText());
    assertEquals("Nested Textbox 1.1",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(4)).getText());
    assertEquals("Nested Textbox 2.2",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(5)).getText());
    assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText());
    assertEquals("Further Nested Widgets:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(0)).getText());
    assertEquals("Nested Textbox 1:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(2)).getText());
    assertEquals("Nested Textbox 1",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(3)).getText());
    assertEquals("Nested Textbox 2:",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(4)).getText());
    assertEquals("Nested Textbox 2",
            ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(5)).getText());
    assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText());
    assertEquals("Nested Textbox 1.01, Nested Textbox 2.02", ((JLabel) metawidget.getComponent(55)).getText());
    assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText());
    assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText());
    assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText());
    assertEquals(now, ((JLabel) metawidget.getComponent(59)).getText());
    assertEquals("Section Break", ((JLabel) ((JPanel) metawidget.getComponent(60)).getComponent(0)).getText());
    assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText());
    assertEquals("Read Only", ((JLabel) metawidget.getComponent(62)).getText());
    assertEquals("Do Action", ((JButton) metawidget.getComponent(63)).getText());
    assertTrue(!((JButton) metawidget.getComponent(63)).isEnabled());

    assertEquals(metawidget.getComponentCount(), 64);

    // Test Binding.onStartBuild clears the state

    assertTrue(null != metawidget.getClientProperty(processor.getClass()));
    processor.onStartBuild(metawidget);
    assertEquals(null, metawidget.getClientProperty(processor.getClass()));
}

From source file:com.nadmm.airports.wx.TafFragment.java

protected void showTaf(Intent intent) {
    if (getActivity() == null) {
        return;//  w  w w .  j  a  v a2s  . com
    }

    Taf taf = (Taf) intent.getSerializableExtra(NoaaService.RESULT);
    if (taf == null) {
        return;
    }

    View detail = findViewById(R.id.wx_detail_layout);
    LinearLayout layout = (LinearLayout) findViewById(R.id.wx_status_layout);
    TextView tv = (TextView) findViewById(R.id.status_msg);
    layout.removeAllViews();
    if (!taf.isValid) {
        tv.setVisibility(View.VISIBLE);
        layout.setVisibility(View.VISIBLE);
        tv.setText("Unable to get TAF for this location.");
        addRow(layout, "This could be due to the following reasons:");
        addBulletedRow(layout, "Network connection is not available");
        addBulletedRow(layout, "ADDS does not publish TAF for this station");
        addBulletedRow(layout, "Station is currently out of service");
        addBulletedRow(layout, "Station has not updated the TAF for more than 12 hours");
        detail.setVisibility(View.GONE);
        stopRefreshAnimation();
        setFragmentContentShown(true);
        return;
    } else {
        tv.setText("");
        tv.setVisibility(View.GONE);
        layout.setVisibility(View.GONE);
        detail.setVisibility(View.VISIBLE);
    }

    tv = (TextView) findViewById(R.id.wx_age);
    tv.setText(TimeUtils.formatElapsedTime(taf.issueTime));

    // Raw Text
    tv = (TextView) findViewById(R.id.wx_raw_taf);
    tv.setText(taf.rawText.replaceAll("(FM|BECMG|TEMPO)", "\n    $1"));

    layout = (LinearLayout) findViewById(R.id.taf_summary_layout);
    layout.removeAllViews();
    String fcstType;
    if (taf.rawText.startsWith("TAF AMD ")) {
        fcstType = "Amendment";
    } else if (taf.rawText.startsWith("TAF COR ")) {
        fcstType = "Correction";
    } else {
        fcstType = "Normal";
    }
    addRow(layout, "Forecast type", fcstType);
    addRow(layout, "Issued at", TimeUtils.formatDateTime(getActivity(), taf.issueTime));
    addRow(layout, "Valid from", TimeUtils.formatDateTime(getActivity(), taf.validTimeFrom));
    addRow(layout, "Valid to", TimeUtils.formatDateTime(getActivity(), taf.validTimeTo));
    if (taf.remarks != null && taf.remarks.length() > 0 && !taf.remarks.equals("AMD")) {
        addRow(layout, "\u2022 " + taf.remarks);
    }

    LinearLayout topLayout = (LinearLayout) findViewById(R.id.taf_forecasts_layout);
    topLayout.removeAllViews();

    StringBuilder sb = new StringBuilder();
    for (Forecast forecast : taf.forecasts) {
        RelativeLayout grp_layout = (RelativeLayout) inflate(R.layout.grouped_detail_item);

        // Keep track of forecast conditions across all change groups
        if (mLastForecast == null || forecast.changeIndicator == null
                || forecast.changeIndicator.equals("FM")) {
            mLastForecast = forecast;
        } else {
            if (forecast.visibilitySM < Float.MAX_VALUE) {
                mLastForecast.visibilitySM = forecast.visibilitySM;
            }
            if (forecast.skyConditions.size() > 0) {
                mLastForecast.skyConditions = forecast.skyConditions;
            }
        }

        sb.setLength(0);
        if (forecast.changeIndicator != null) {
            sb.append(forecast.changeIndicator);
            sb.append(" ");
        }
        sb.append(TimeUtils.formatDateRange(getActivity(), forecast.timeFrom, forecast.timeTo));
        tv = (TextView) grp_layout.findViewById(R.id.group_extra);
        tv.setVisibility(View.GONE);
        tv = (TextView) grp_layout.findViewById(R.id.group_name);
        tv.setText(sb.toString());
        String flightCategory = WxUtils.computeFlightCategory(mLastForecast.skyConditions,
                mLastForecast.visibilitySM);
        WxUtils.setFlightCategoryDrawable(tv, flightCategory);

        LinearLayout fcst_layout = (LinearLayout) grp_layout.findViewById(R.id.group_details);

        if (forecast.probability < Integer.MAX_VALUE) {
            addRow(fcst_layout, "Probability", String.format("%d%%", forecast.probability));
        }

        if (forecast.changeIndicator != null && forecast.changeIndicator.equals("BECMG")) {
            addRow(fcst_layout, "Becoming at", TimeUtils.formatDateTime(getActivity(), forecast.timeBecoming));
        }

        if (forecast.windSpeedKnots < Integer.MAX_VALUE) {
            String wind;
            if (forecast.windDirDegrees == 0 && forecast.windSpeedKnots == 0) {
                wind = "Calm";
            } else if (forecast.windDirDegrees == 0) {
                wind = String.format(Locale.US, "Variable at %d knots", forecast.windSpeedKnots);
            } else {
                wind = String.format(Locale.US, "%s (%s true) at %d knots",
                        GeoUtils.getCardinalDirection(forecast.windDirDegrees),
                        FormatUtils.formatDegrees(forecast.windDirDegrees), forecast.windSpeedKnots);
            }
            String gust = "";
            if (forecast.windGustKnots < Integer.MAX_VALUE) {
                gust = String.format(Locale.US, "Gusting to %d knots", forecast.windGustKnots);
            }
            addRow(fcst_layout, "Winds", wind, gust);
        }

        if (forecast.visibilitySM < Float.MAX_VALUE) {
            String value = forecast.visibilitySM > 6 ? "6+ SM"
                    : FormatUtils.formatStatuteMiles(forecast.visibilitySM);
            addRow(fcst_layout, "Visibility", value);
        }

        if (forecast.vertVisibilityFeet < Integer.MAX_VALUE) {
            addRow(fcst_layout, "Visibility", FormatUtils.formatFeetAgl(forecast.vertVisibilityFeet));
        }

        for (WxSymbol wx : forecast.wxList) {
            addRow(fcst_layout, "Weather", wx.toString());
        }

        for (SkyCondition sky : forecast.skyConditions) {
            addRow(fcst_layout, "Clouds", sky.toString());
        }

        if (forecast.windShearSpeedKnots < Integer.MAX_VALUE) {
            String shear = String.format(Locale.US, "%s (%s true) at %d knots",
                    GeoUtils.getCardinalDirection(forecast.windShearDirDegrees),
                    FormatUtils.formatDegrees(forecast.windShearDirDegrees), forecast.windShearSpeedKnots);
            String height = FormatUtils.formatFeetAgl(forecast.windShearHeightFeetAGL);
            addRow(fcst_layout, "Wind shear", shear, height);
        }

        if (forecast.altimeterHg < Float.MAX_VALUE) {
            addRow(fcst_layout, "Altimeter", FormatUtils.formatAltimeter(forecast.altimeterHg));
        }

        for (TurbulenceCondition turbulence : forecast.turbulenceConditions) {
            String value = WxUtils.decodeTurbulenceIntensity(turbulence.intensity);
            String height = FormatUtils.formatFeetRangeAgl(turbulence.minAltitudeFeetAGL,
                    turbulence.maxAltitudeFeetAGL);
            addRow(fcst_layout, "Turbulence", value, height);
        }

        for (IcingCondition icing : forecast.icingConditions) {
            String value = WxUtils.decodeIcingIntensity(icing.intensity);
            String height = FormatUtils.formatFeetRangeAgl(icing.minAltitudeFeetAGL, icing.maxAltitudeFeetAGL);
            addRow(fcst_layout, "Icing", value, height);
        }

        topLayout.addView(grp_layout, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    }

    tv = (TextView) findViewById(R.id.wx_fetch_time);
    tv.setText("Fetched on " + TimeUtils.formatDateTime(getActivity(), taf.fetchTime));
    tv.setVisibility(View.VISIBLE);

    stopRefreshAnimation();
    setFragmentContentShown(true);
}