Example usage for java.awt Point Point

List of usage examples for java.awt Point Point

Introduction

In this page you can find the example usage for java.awt Point Point.

Prototype

public Point(int x, int y) 

Source Link

Document

Constructs and initializes a point at the specified (x,y) location in the coordinate space.

Usage

From source file:edu.ucla.stat.SOCR.applications.demo.BinomialTradingApplication.java

void updateGraph() {
    //This method will later update/redraw/repaint the (Node, Edge)-Graph
    // For now, we just print out the results in JTextArea

    // Price of the Stock Price[k][l] is the price of the stock at level k (0<=k<=n)
    // and outcome l (0<=l<n+1)
    GraphModel model = new DefaultGraphModel();
    jgraph = new JGraph(model);
    cells = new DefaultGraphCell[((n + 1) * (n + 2) / 2) * 3];
    cellCount = 0;/*w w  w  .j  a  va 2s . c  o m*/

    int XSpace = 130;
    int YSpace = 30;
    int YMiddle = 20 + n * YSpace; //150

    for (int k = 0; k <= n; k++) {
        //System.out.println("============Start-of-level("+k+")==================");
        for (int l = 0; l <= k; l++) {
            // Print to GraphPanel's JTextArea
            int j = -k + l * 2;

            if (choice.charAt(9) == 'P') { //For put option
                if (k == n) { // For the last column, k=n, (in the money), 
                    // we need to color GREEN or BLUE the node-background 
                    // to indicate if the Call Price (C) is > 0 (green) or
                    // <= 0 (blue)
                    if (j < 0) {
                        if (Diff[k][l] > 0)
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace - 20), Color.green);
                        else
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace - 20), Color.blue);
                    } else if (j > 0) {
                        if (Diff[k][l] > 0)
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace + 20), Color.green);
                        else
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace + 20), Color.blue);
                    } else {
                        if (Diff[k][l] > 0)
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle,
                                    Color.green);
                        else
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle,
                                    Color.blue);
                    }
                } else { // For all columns before the last (in the money) column, k<n)!
                    if (j < 0)
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                (YMiddle + j * YSpace - 20));
                    else if (j > 0)
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                (YMiddle + j * YSpace + 20));
                    else
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " P[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle);
                }
            } else { //For call option
                if (k == n) { // For the last column, k=n, (in the money), 
                    // we need to color GREEN or BLUE the node-background 
                    // to indicate if the Call Price (C) is > 0 (green) or
                    // <= 0 (blue)
                    if (j < 0) {
                        if (Diff[k][l] > 0)
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace - 20), Color.green);
                        else
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace - 20), Color.blue);
                    } else if (j > 0) {
                        if (Diff[k][l] > 0)
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace + 20), Color.green);
                        else
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                    (YMiddle + j * YSpace + 20), Color.blue);
                    } else {
                        if (Diff[k][l] > 0)
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle,
                                    Color.green);
                        else
                            addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + ","
                                    + l + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle,
                                    Color.blue);
                    }
                } else if (choice.charAt(0) == 'A' && Diff[k][l] == Math.abs(Price[k][l] - EP)) {
                    // For all columns before the last (in the money) column, k<n)! and possibly exercised early
                    if (j < 0)
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                (YMiddle + j * YSpace - 20), Color.magenta);
                    else if (j > 0)
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                (YMiddle + j * YSpace + 20), Color.magenta);
                    else
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle,
                                Color.magenta);
                } else { // For all columns before the last (in the money) column, k<n)!
                    if (j < 0)
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                (YMiddle + j * YSpace - 20));
                    else if (j > 0)
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace),
                                (YMiddle + j * YSpace + 20));
                    else
                        addNode("S[" + k + "," + l + "]=" + formatter.format(Price[k][l]) + " C[" + k + "," + l
                                + "]=" + formatter.format(Diff[k][l]), (10 + k * XSpace), YMiddle);
                    // Also Print to STD_OUT
                    //   System.out.println("j="+j);
                    //   System.out.println("Price["+k+"]["+l+"]="+Price[k][l]);
                    //   System.out.println("Diff["+k+"]["+l+"]="+Diff[k][l]);
                }
            }
        }
        //System.out.println("============End-of-level("+k+")==================\n");
    }
    //System.out.println("cellCount="+cellCount);

    for (int k = 0; k < n; k++) {
        //System.out.println("============Start-of-level("+k+")==================");
        for (int l = 0; l <= k; l++) {
            //   System.out.println((k*(k+1)/2+l)+"->"+((k+1)*(k+2)/2+l) );

            addEdge((k * (k + 1) / 2 + l), ((k + 1) * (k + 2) / 2 + l));
            //System.out.println((k*(k+1)/2+l)+"->"+((k+1)*(k+2)/2+l+1) );
            addEdge((k * (k + 1) / 2 + l), ((k + 1) * (k + 2) / 2 + l + 1));
        }
        //   System.out.println("============End-of-level("+k+")==================\n");
    }

    //   System.out.println("cellCount="+cellCount);
    DefaultGraphCell[] cellsCache = new DefaultGraphCell[cellCount];

    for (int i = 0; i < cellCount; i++)
        cellsCache[i] = cells[i];

    jgraph.getGraphLayoutCache().insert(cellsCache);
    Dimension d = jgraph.getPreferredSize();
    //System.out.println(d.width +","+d.height);
    jgraph.setPreferredSize(new Dimension(d.width + 150, d.height));

    jgraphPanel.removeAll();
    JScrollPane jsp = new JScrollPane(jgraph);
    jgraphPanel.add(jsp);
    jgraphPanel.setPreferredSize(new Dimension(CHART_SIZE_X, CHART_SIZE_Y));
    JViewport jv = jsp.getViewport();
    jv.setViewPosition(new Point(0, YMiddle - 150));
    jgraphPanel.validate();
}

From source file:de.tor.tribes.ui.wiz.ref.SupportRefillCalculationPanel.java

private void scroll() {
    Point point = new Point(0, (int) (jTextPane1.getSize().getHeight()));
    JViewport vp = jScrollPane1.getViewport();
    if (vp == null) {
        return;//from  w w w.  ja  v a 2 s  . c o  m
    }
    vp.setViewPosition(point);
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.java

/**
 * This tests that copying and pasting a table from one session to another
 * session within the same context will add the data source to the new session
 * and add the table properly.//from  w w w  . j a  v  a2s . c  o m
 */
public void testPasteTableAcrossSessions() throws Exception {
    ArchitectSwingSessionContext context = pp.getSession().getContext();
    context.setPlDotIniPath("pl.regression.ini");
    DataSourceCollection<JDBCDataSource> pl = context.getPlDotIni();
    JDBCDataSource ds = pl.getDataSource("regression_test");
    Connection con = ds.createConnection();
    Statement stmt = con.createStatement();
    stmt.execute("Create table newtable (newcol1 varchar(50), newcol2 varchar(50))");
    stmt.close();
    con.close();

    SQLDatabase db = new SQLDatabase(ds);
    SQLTable table = db.getTableByName("newtable");

    //New play pen in same context
    PlayPen newPP = pp.getSession().getContext().createSession().getPlayPen();

    DuplicateProperties duplicateProperties = ASUtils.createDuplicateProperties(newPP.getSession(), table);
    newPP.importTableCopy(table, new Point(0, 0), duplicateProperties);
    assertEquals(1, newPP.getTables().size());
    SQLTable copy = newPP.getTables().get(0);
    assertEquals("NEWTABLE", copy.getName().toUpperCase());
    assertEquals(2, copy.getColumns().size());
    assertTrue(copy.getColumnByName("NewCol1") != null);
    assertTrue(copy.getColumnByName("NewCol2") != null);
    assertTrue(table.getColumnByName("newcol1") != copy.getColumnByName("NewCol1").getSourceColumn());
    assertTrue(table.getColumnByName("newcol2") != copy.getColumnByName("NewCol2").getSourceColumn());
}

From source file:at.tuwien.ifs.somtoolbox.apps.viewer.MapPNode.java

/**
 * Computes the locations of each input vector within a specific unit
 *///from ww  w.j ava  2  s  .  c  om
private Point[][] initInputLocations(Unit unit) {

    int size = unit.getNumberOfMappedInputs();
    // Store XY displacements in a temporary array
    double[][] locdxy = new double[size][2];
    double[][] locdxyShifted = new double[size][2];

    // Process all mapped inputs in the unit
    for (int index = 0; index < size; index++) {
        // Find vector position for this mapped input
        String label = unit.getMappedInputName(index);

        int vindex;
        try {
            vindex = inputObjects.getDataWinnerMapping().getVectPos(label);
        } catch (SOMToolboxException e1) {
            Logger.getLogger("at.tuwien.ifs.somtoolbox")
                    .warning(e1.getMessage() + " Could not draw exact point on unit!");
            // e1.printStackTrace();
            continue;
        }

        // Get winners information
        int[] xpos = inputObjects.getDataWinnerMapping().getXPos(vindex);
        int[] ypos = inputObjects.getDataWinnerMapping().getYPos(vindex);
        double[] dist = inputObjects.getDataWinnerMapping().getDists(vindex);

        // Computes displacement of the input vector against the next best winning unit.
        for (int uindex = 1; uindex <= 3; uindex++) {
            double vx = xpos[uindex] - xpos[0];
            double vy = ypos[uindex] - ypos[0];

            // Find x-axis and y-axis pull force of the winner. The pull force of 2nd unit is higher than the 3rd
            // and so on
            double force = dist[0] / (dist[uindex] * uindex);

            // Now calculate displacement. The key is: farther the unit, lesser must be the displacement.
            // Additionally the displacement is zero if units are not pulling in different directions.
            // Consider unit U1 being positioned at [2, 4] and unit U2's position being [3, 4].
            // Now clearly both units lie on the same position on y-axis and thus there is no need to compute
            // displacement for y-axis
            locdxy[index][0] += vx == 0 ? 0 : UNIT_WIDTH / 2 * force / vx;
            locdxy[index][1] += vy == 0 ? 0 : UNIT_WIDTH / 2 * force / vy;
        }

        locdxyShifted[index][0] = locdxy[index][0];
        locdxyShifted[index][1] = locdxy[index][1];

        // Compute force of replusion if the current input is ovlapping with any of the previous inputs
        // store locations into separate field to allow easy switching
        for (int rindex = 0; rindex < index; rindex++) {
            double distance = Point2D.distanceSq(locdxy[rindex][0], locdxy[rindex][1], locdxy[index][0],
                    locdxy[index][1]);
            if (distance < InputPNode.MIN_DISTANCE_SQ) {
                // Its like other input pushing the this input towards boundary if its trying to overlap
                locdxyShifted[index][0] *= 1.03;
                locdxyShifted[index][1] *= 1.03;
                // And on the other sie this input is forcing that input to leave a free space for him by moving
                // towards center.
                // double factor = distance/InputPNode.MIN_DISTANCE_SQ;
                double factor = 0.8;
                locdxyShifted[rindex][0] *= factor;
                locdxyShifted[rindex][1] *= factor;
            }
        }
    }
    // Now calculate the actual XY position for display
    Point[][] locations = new Point[2][size];
    for (int i = 0; i < size; i++) {
        locations[0][i] = new Point((int) (UNIT_WIDTH / 2 + locdxy[i][0]),
                (int) (UNIT_WIDTH / 2 + locdxy[i][1]));
        locations[1][i] = new Point((int) (UNIT_WIDTH / 2 + locdxyShifted[i][0]),
                (int) (UNIT_WIDTH / 2 + locdxyShifted[i][1]));
    }
    return locations;
}

From source file:com.rapidminer.gui.new_plotter.engine.jfreechart.PlotInstanceLegendCreator.java

/**
 * Creates a continuous legend item for one item in dimensionSet, i.e. dimensionSet must be a
 * set containing exactly one value./*from w  ww.  ja  va 2 s .c o  m*/
 * 
 * @param dateFormat
 *            format used to format minValue and maxValue as dates, or null if they should be
 *            displayed numerically instead of as dates
 * @throws ChartPlottimeException
 */
private LegendItem createContinuousLegendItem(PlotInstance plotInstance, Set<PlotDimension> dimensionSet,
        double minValue, double maxValue, DateFormat dateFormat) {
    PlotConfiguration plotConfiguration = plotInstance.getCurrentPlotConfigurationClone();
    PlotDimension dimension = dimensionSet.iterator().next();
    DefaultDimensionConfig dimensionConfig = (DefaultDimensionConfig) plotConfiguration
            .getDimensionConfig(dimension);
    DimensionConfigData dimensionConfigData = plotInstance.getPlotData()
            .getDimensionConfigData(dimensionConfig);
    // String label = dimensionConfig.getLabel();
    // if(label == null) {
    // label = I18N.getGUILabel("plotter.unnamed_value_label");
    // }
    String label = "";

    if (dimension == PlotDimension.COLOR) {
        ColorProvider colorProvider = dimensionConfigData.getColorProvider();
        if (!colorProvider.supportsNumericalValues()) {
            throw new RuntimeException(
                    "Color provider for continuous legend item does not support numerical values.");
        }

        // shape dimensions
        final int width = 50;
        final int height = 10;

        // create item paint

        // first disable logarithmic scale on color provider ( -> linear gradient in legend)
        // ContinuousColorProvider continuousColorProvider = null;
        // if (dimensionConfig.isLogarithmic() && colorProvider instanceof
        // ContinuousColorProvider) {
        // continuousColorProvider = (ContinuousColorProvider)colorProvider;
        // continuousColorProvider.setLogarithmic(false);
        // }

        // calculate gradient
        float fractions[] = new float[width];
        Color colors[] = new Color[width];
        for (int i = 0; i < width; ++i) {

            float fraction = i / (width - 1.0f);
            double fractionValue;
            if (colorProvider instanceof ContinuousColorProvider
                    && ((ContinuousColorProvider) colorProvider).isColorMinMaxValueDifferentFromOriginal(
                            ((ContinuousColorProvider) colorProvider).getMinValue(),
                            ((ContinuousColorProvider) colorProvider).getMaxValue())) {
                fractionValue = ((ContinuousColorProvider) colorProvider).getMinValue()
                        + fraction * (((ContinuousColorProvider) colorProvider).getMaxValue()
                                - ((ContinuousColorProvider) colorProvider).getMinValue());
            } else {
                fractionValue = minValue + fraction * (maxValue - minValue);
            }
            colors[i] = colorProvider.getColorForValue(fractionValue);
            fractions[i] = fraction;
        }
        LinearGradientPaint shapeFillPaint = new LinearGradientPaint(new Point(0, 0), new Point(width, 0),
                fractions, colors, CycleMethod.REPEAT);

        // reset color provider to logarithmic if necessary
        // if (continuousColorProvider != null && dimensionConfig.isLogarithmic()) {
        // continuousColorProvider.setLogarithmic(true);
        // }

        // create item shape
        Rectangle itemShape = new Rectangle(width, height);

        if (colorProvider instanceof ContinuousColorProvider) {
            return createFlankedShapeLegendItem(label, ((ContinuousColorProvider) colorProvider).getMinValue(),
                    ((ContinuousColorProvider) colorProvider).getMaxValue(), itemShape, shapeFillPaint, true,
                    dateFormat);
        } else {
            return createFlankedShapeLegendItem(label, minValue, maxValue, itemShape, shapeFillPaint, true,
                    dateFormat);
        }
    } else if (dimension == PlotDimension.SHAPE) {
        // shape provider probably never supports numerical values
        return null;
    } else if (dimension == PlotDimension.SIZE) {
        SizeProvider sizeProvider = dimensionConfigData.getSizeProvider();

        if (!sizeProvider.supportsNumericalValues()) {
            throw new RuntimeException(
                    "Size provider for continuous legend item does not support numerical values.");
        }

        double minScalingFactor = sizeProvider.getMinScalingFactor();
        double maxScalingFactor = sizeProvider.getMaxScalingFactor();
        ContinuousSizeProvider legendSizeProvider = new ContinuousSizeProvider(minScalingFactor,
                maxScalingFactor, MIN_LEGEND_ITEM_SCALING_FACTOR, MAX_LEGEND_ITEM_SCALING_FACTOR, false);

        int legendItemCount = 4;
        Area composedShape = new Area();
        Shape originalShape = UNDEFINED_SHAPE;
        if (dimensionSet.contains(PlotDimension.SIZE) && dimensionSet.size() == 1) {
            originalShape = UNDEFINED_SHAPE_AND_COLOR;
        }
        double maxHeight = originalShape.getBounds().getHeight() * MAX_LEGEND_ITEM_SCALING_FACTOR;
        for (int i = 0; i < legendItemCount; ++i) {
            double fraction = minScalingFactor
                    + ((double) i / legendItemCount * (maxScalingFactor - minScalingFactor));
            double legendScalingFactor = legendSizeProvider.getScalingFactorForValue(fraction);

            double composedWidth = composedShape.getBounds().getWidth();

            AffineTransform t = new AffineTransform();
            t.scale(legendScalingFactor, legendScalingFactor);
            Shape shape = t.createTransformedShape(originalShape);

            t = new AffineTransform();
            double shapeWidth = shape.getBounds().getWidth();
            double shapeHeight = shape.getBounds().getHeight();
            t.translate(composedWidth + shapeWidth * .1, (maxHeight - shapeHeight) / 2.0);
            t.translate(-shape.getBounds().getMinX(), -shape.getBounds().getMinY());
            shape = t.createTransformedShape(shape);
            composedShape.add(new Area(shape));
        }

        return createFlankedShapeLegendItem(label, minValue, maxValue, composedShape, UNDEFINED_COLOR_PAINT,
                false, dateFormat);

    } else {
        throw new RuntimeException("Unsupported dimension. Execution path should never reach this line.");
    }
}

From source file:ca.sqlpower.matchmaker.MatchMakerTestCase.java

/**
 * Returns a new value that is not equal to oldVal. The returned object
 * will always be a NEW instance compatible with oldVal. This differs from
 * {@link #modifyObject(MatchMakerObject, PropertyDescriptor, Object)} in that
 * this does not take mutability into account.
 * /* w w  w.  j av  a 2  s .c o m*/
 * @param mmo The object to which the property belongs.  You might need this
 *  if you have a special case for certain types of objects.
 * @param property The property that should be modified.  It belongs to mmo.
 * @param oldVal The existing value of the property.
 */
private Object getNewDifferentValue(MatchMakerObject mmo, PropertyDescriptor property, Object oldVal)
        throws IOException {
    Object newVal; // don't init here so compiler can warn if the
    // following code doesn't always give it a value
    if (property.getPropertyType() == Integer.TYPE || property.getPropertyType() == Integer.class) {
        if (oldVal == null)
            newVal = new Integer(0);
        else {
            newVal = ((Integer) oldVal) + 1;
        }
    } else if (property.getPropertyType() == Short.TYPE || property.getPropertyType() == Short.class) {
        if (oldVal == null)
            newVal = new Short("0");
        else {
            Integer temp = (Short) oldVal + 1;
            newVal = Short.valueOf(temp.toString());
        }
    } else if (property.getPropertyType() == String.class) {
        // make sure it's unique
        newVal = "new " + oldVal;

    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        if (oldVal == null) {
            newVal = new Boolean(false);
        } else {
            newVal = new Boolean(!((Boolean) oldVal).booleanValue());
        }
    } else if (property.getPropertyType() == Long.class) {
        if (oldVal == null) {
            newVal = new Long(0L);
        } else {
            newVal = new Long(((Long) oldVal).longValue() + 1L);
        }
    } else if (property.getPropertyType() == BigDecimal.class) {
        if (oldVal == null) {
            newVal = new BigDecimal(0);
        } else {
            newVal = new BigDecimal(((BigDecimal) oldVal).longValue() + 1L);
        }
    } else if (property.getPropertyType() == MungeSettings.class) {
        newVal = new MungeSettings();
        Integer processCount = ((MatchMakerSettings) newVal).getProcessCount();
        if (processCount == null) {
            processCount = new Integer(0);
        } else {
            processCount = new Integer(processCount + 1);
        }
        ((MatchMakerSettings) newVal).setProcessCount(processCount);
    } else if (property.getPropertyType() == MergeSettings.class) {
        newVal = new MergeSettings();
        Integer processCount = ((MatchMakerSettings) newVal).getProcessCount();
        if (processCount == null) {
            processCount = new Integer(0);
        } else {
            processCount = new Integer(processCount + 1);
        }
        ((MatchMakerSettings) newVal).setProcessCount(processCount);
    } else if (property.getPropertyType() == SQLTable.class) {
        newVal = new SQLTable();
    } else if (property.getPropertyType() == ViewSpec.class) {
        newVal = new ViewSpec("*", "test_table", "true");
    } else if (property.getPropertyType() == File.class) {
        newVal = File.createTempFile("mmTest", ".tmp");
        ((File) newVal).deleteOnExit();
    } else if (property.getPropertyType() == PlFolder.class) {
        newVal = new PlFolder();
    } else if (property.getPropertyType() == ProjectMode.class) {
        if (oldVal == ProjectMode.BUILD_XREF) {
            newVal = ProjectMode.FIND_DUPES;
        } else {
            newVal = ProjectMode.BUILD_XREF;
        }
    } else if (property.getPropertyType() == MergeActionType.class) {
        if (oldVal == MergeActionType.AUGMENT) {
            newVal = MergeActionType.SUM;
        } else {
            newVal = MergeActionType.AUGMENT;
        }
    } else if (property.getPropertyType() == MatchMakerTranslateGroup.class) {
        newVal = new MatchMakerTranslateGroup();
    } else if (property.getPropertyType() == MatchMakerObject.class) {
        newVal = new TestingAbstractMatchMakerObject();
    } else if (property.getPropertyType() == SQLColumn.class) {
        newVal = new SQLColumn();
    } else if (property.getPropertyType() == Date.class) {
        newVal = new Date();
    } else if (property.getPropertyType() == List.class) {
        newVal = new ArrayList();
    } else if (property.getPropertyType() == Project.class) {
        newVal = new Project();
        ((Project) newVal).setName("Fake_Project_" + System.currentTimeMillis());
    } else if (property.getPropertyType() == SQLIndex.class) {
        return new SQLIndex("new index", false, "", "HASHED", "");
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            newVal = new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == ChildMergeActionType.class) {
        if (oldVal != null && oldVal.equals(ChildMergeActionType.DELETE_ALL_DUP_CHILD)) {
            newVal = ChildMergeActionType.UPDATE_DELETE_ON_CONFLICT;
        } else {
            newVal = ChildMergeActionType.DELETE_ALL_DUP_CHILD;
        }
    } else if (property.getPropertyType() == MungeResultStep.class
            || property.getPropertyType() == DeDupeResultStep.class) {
        newVal = new DeDupeResultStep();
    } else if (property.getPropertyType() == TableMergeRules.class) {
        if (oldVal == null) {
            newVal = mmo;
        } else {
            newVal = null;
        }
    } else if (property.getPropertyType() == PoolFilterSetting.class) {
        if (oldVal != PoolFilterSetting.EVERYTHING) {
            newVal = PoolFilterSetting.EVERYTHING;
        } else {
            newVal = PoolFilterSetting.INVALID_ONLY;
        }
    } else if (property.getPropertyType() == AutoValidateSetting.class) {
        if (oldVal != AutoValidateSetting.NOTHING) {
            newVal = AutoValidateSetting.NOTHING;
        } else {
            newVal = AutoValidateSetting.SERP_CORRECTABLE;
        }
    } else if (property.getPropertyType() == Point.class) {
        if (oldVal == null) {
            newVal = new Point(0, 0);
        } else {
            newVal = new Point(((Point) oldVal).x + 1, ((Point) oldVal).y + 1);
        }
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") from " + mmo.getClass());
    }

    if (newVal instanceof MatchMakerObject) {
        ((MatchMakerObject) newVal).setSession(session);
    }
    return newVal;
}

From source file:edu.ku.brc.specify.utilapps.ERDVisualizer.java

/**
 * //from w  w w  .ja v  a2s .co m
 */
public void generate() {
    Rectangle rect = getPanel().getParent().getBounds();
    System.out.println("MAIN[" + rect + "]");
    if (rect.width == 0 || rect.height == 0) {
        return;
    }

    BufferedImage bufImage = new BufferedImage(rect.width, rect.height,
            (doPNG ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB));
    Graphics2D g2 = bufImage.createGraphics();
    if (!doPNG) {
        g2.setColor(Color.WHITE);
        g2.fillRect(0, 0, rect.width, rect.height);
    }
    g2.setRenderingHints(createTextRenderingHints());
    g2.setFont(tblTracker.getFont());
    getPanel().getParent().paint(g2);

    g2.dispose();

    Component stop = getPanel().getParent();
    Point p = new Point(0, 0);
    calcLoc(p, getPanel().getMainTable(), stop);

    String name = StringUtils.substringAfterLast(getPanel().getMainTable().getClassName(), ".");
    DBTableInfo tblInfo = DBTableIdMgr.getInstance().getByShortClassName(name);
    String fName = schemaDir.getAbsolutePath() + File.separator + name;
    try {
        String origName = fName;
        int i = 1;
        while (pngNameHash.contains(fName)) {
            fName = origName + i;
        }
        pngNameHash.add(fName);

        File html = new File(fName + ".html");
        BufferedWriter output = new BufferedWriter(new FileWriter(html));

        int index = mapTemplate.indexOf(contentTag);
        String subContent = mapTemplate.substring(0, index);
        output.write(StringUtils.replace(subContent, "<!-- Title -->", tblInfo.getTitle()));

        File imgFile = new File(fName + (doPNG ? ".png" : ".jpg"));
        output.write("<map name=\"schema\" id=\"schema\">\n");

        Vector<ERDTable> nList = mainPanel.isRoot() ? tblTracker.getTreeAsList(mainPanel.getMainTable())
                : getPanel().getRelTables();
        for (ERDTable erdt : nList) {
            p = new Point(0, 0);
            calcLoc(p, erdt, stop);
            Dimension s = erdt.getSize();
            String linkname = StringUtils.substringAfterLast(erdt.getClassName(), ".");
            output.write("<area shape=\"rect\" coords=\"" + p.x + "," + p.y + "," + (p.x + s.width) + ","
                    + (p.y + s.height) + "\" href=\"" + linkname + ".html\"/>\n");
        }

        output.write("</map>\n");
        output.write("<img border=\"0\" usemap=\"#schema\" src=\"" + imgFile.getName() + "\"/>\n");

        output.write(mapTemplate.substring(index + contentTag.length() + 1, mapTemplate.length()));

        output.close();

        File oFile = new File(schemaDir + File.separator + imgFile.getName());
        System.out.println(oFile.getAbsolutePath());
        if (doPNG) {
            ImageIO.write(bufImage, "PNG", oFile);
        } else {
            writeJPEG(oFile, bufImage, 0.75f);
        }
        //ImageIO.write(bufImage, "JPG", new File(schemaDir + File.separator + imgFile.getName()+".jpg"));

    } catch (Exception e) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ERDVisualizer.class, e);
        e.printStackTrace();
    }
}

From source file:org.mwc.cmap.grideditor.chart.FixedChartComposite.java

/**
 * Decreases the length of the domain axis, centered about the given
 * coordinate on the screen. The length of the domain axis is reduced by the
 * value of {@link #getZoomInFactor()}.//  w  w  w  .  ja  v  a2  s. c om
 * 
 * @param x
 *          the x coordinate (in screen coordinates).
 * @param y
 *          the y-coordinate (in screen coordinates).
 */
public void zoomInDomain(final double x, final double y) {
    final Plot p = this.chart.getPlot();
    if (p instanceof Zoomable) {
        final Zoomable plot = (Zoomable) p;
        plot.zoomDomainAxes(this.zoomInFactor, this.info.getPlotInfo(),
                translateScreenToJava2D(new Point((int) x, (int) y)));
    }
}

From source file:ca.sqlpower.architect.swingui.TestPlayPen.java

/**
 * Returns a new value that is not equal to oldVal. The
 * returned object will be a new instance compatible with oldVal.  
 * //from   ww  w.  ja  va 2  s. com
 * @param property The property that should be modified.
 * @param oldVal The existing value of the property to modify.  The returned value
 * will not equal this one at the time this method was first called.
 */
private Object getNewDifferentValue(PropertyDescriptor property, Object oldVal) {
    Object newVal; // don't init here so compiler can warn if the
    // following code doesn't always give it a value
    if (property.getPropertyType() == String.class) {
        newVal = "new " + oldVal;
    } else if (property.getPropertyType() == Boolean.class || property.getPropertyType() == Boolean.TYPE) {
        if (oldVal == null) {
            newVal = new Boolean(false);
        } else {
            newVal = new Boolean(!((Boolean) oldVal).booleanValue());
        }
    } else if (property.getPropertyType() == Double.class || property.getPropertyType() == Double.TYPE) {
        if (oldVal == null) {
            newVal = new Double(0);
        } else {
            newVal = new Double(((Double) oldVal).doubleValue() + 1);
        }
    } else if (property.getPropertyType() == Integer.class || property.getPropertyType() == Integer.TYPE) {
        if (oldVal == null) {
            newVal = new Integer(0);
        } else {
            newVal = new Integer(((Integer) oldVal).intValue() + 1);
        }
    } else if (property.getPropertyType() == Color.class) {
        if (oldVal == null) {
            newVal = new Color(0xFAC157);
        } else {
            Color oldColor = (Color) oldVal;
            newVal = new Color((oldColor.getRGB() + 0xF00) % 0x1000000);
        }
    } else if (property.getPropertyType() == Font.class) {
        if (oldVal == null) {
            newVal = FontManager.getDefaultPhysicalFont();
        } else {
            Font oldFont = (Font) oldVal;
            newVal = new Font(oldFont.getFontName(), oldFont.getSize() + 2, oldFont.getStyle());
        }
    } else if (property.getPropertyType() == Set.class) {
        newVal = new HashSet();
        ((Set) newVal).add("test");
    } else if (property.getPropertyType() == List.class) {
        newVal = new ArrayList();
        ((List) newVal).add("test");
    } else if (property.getPropertyType() == Point.class) {
        newVal = new Point(1, 3);
    } else {
        throw new RuntimeException("This test case lacks a value for " + property.getName() + " (type "
                + property.getPropertyType().getName() + ") in getNewDifferentValue()");
    }

    return newVal;
}

From source file:User.Interface.InventoryAdminRole.InventoryAdminWorkAreaJPanel.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    // TODO add your handling code here:
    //check if the supplier has products in the product list
    if (inventoryEnterprise.getWarehouse().getMdeciDeviceCatalog().getMedicalDeviceList().size() < 0) {
        JOptionPane.showMessageDialog(this, "No devices found in the inventory.", "Warning",
                JOptionPane.WARNING_MESSAGE);
        return;//from w  w w .  ja v a  2 s .  c o  m
    }

    MedicalDevice[] product;
    product = new MedicalDevice[100];

    int numberOfProducts = inventoryEnterprise.getWarehouse().getMdeciDeviceCatalog().getMedicalDeviceList()
            .size();
    DefaultCategoryDataset dataSetProduct = new DefaultCategoryDataset();

    for (int i = 0; i < numberOfProducts; i++) {
        product[i] = inventoryEnterprise.getWarehouse().getMdeciDeviceCatalog().getMedicalDeviceList().get(i);
        int soldQuantity = 0;
        soldQuantity = product[i].getNumUses();
        String prodName = product[i].getDeviceName();
        dataSetProduct.setValue(soldQuantity, "Medical Device", prodName);
    }

    JFreeChart chartProduct = ChartFactory.createBarChart("Device Usage Report", "Device",
            "Number of times usdr", dataSetProduct, PlotOrientation.VERTICAL, false, true, false);

    CategoryPlot p1 = chartProduct.getCategoryPlot();
    p1.setRangeGridlinePaint(Color.black);
    ChartFrame frame1 = new ChartFrame("Device Usage Report", chartProduct);
    frame1.setVisible(true);
    frame1.setSize(400, 400);
    Point pt1 = new Point(0, 0);
    frame1.setLocation(pt1);
}