Example usage for java.awt Dimension setSize

List of usage examples for java.awt Dimension setSize

Introduction

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

Prototype

public void setSize(int width, int height) 

Source Link

Document

Sets the size of this Dimension object to the specified width and height.

Usage

From source file:org.geotools.gce.imagemosaic.CatalogBuilderTest.java

@Test
public void buildCatalog() throws FileNotFoundException, IOException {
    if (hostnameDefined) {
        CatalogBuilder builder = null;//from ww  w.java2  s  . c o m
        ImageMosaicReader reader = null;
        ParameterValue<GridGeometry2D> gg = null;
        GeneralEnvelope envelope = null;
        Dimension dim = null;
        Rectangle rasterArea = null;
        GridEnvelope2D range = null;
        GridCoverage2D coverage = null;
        final ParameterValue<Boolean> useJai = AbstractGridFormat.USE_JAI_IMAGEREAD.createValue();
        useJai.setValue(false);

        final ParameterValue<String> tileSize = AbstractGridFormat.SUGGESTED_TILE_SIZE.createValue();
        tileSize.setValue("128,128");

        //build a relative index and then make it run
        CatalogBuilderConfiguration c1 = new CatalogBuilderConfiguration();
        c1.setIndexName("shpindex");
        c1.setLocationAttribute("location");
        c1.setAbsolute(false);
        c1.setRootMosaicDirectory(TestData.file(this, "/overview").toString());
        c1.setIndexingDirectories(Arrays.asList(TestData.file(this, "/overview/0").toString()));
        assertNotNull(c1.toString());
        //build the index
        builder = new CatalogBuilder(c1);
        builder.addProcessingEventListener(new CatalogBuilderListener());
        builder.run();
        final File relativeMosaic = TestData.file(this, "/overview/" + c1.getIndexName() + ".shp");
        assertTrue(relativeMosaic.exists());

        assertTrue(new ImageMosaicFormat().accepts(relativeMosaic));
        reader = (ImageMosaicReader) new ImageMosaicReader(relativeMosaic);

        // limit yourself to reading just a bit of it
        gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
        envelope = reader.getOriginalEnvelope();
        dim = new Dimension();
        dim.setSize(reader.getOriginalGridRange().getSpan(0) / 2.0,
                reader.getOriginalGridRange().getSpan(1) / 2.0);
        rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange());
        rasterArea.setSize(dim);
        range = new GridEnvelope2D(rasterArea);
        gg.setValue(new GridGeometry2D(range, envelope));

        // use imageio with defined tiles

        // Test the output coverage
        coverage = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg, useJai, tileSize });
        Assert.assertNotNull(coverage);
        PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();

        //caching should be false by default
        Properties props = new Properties();
        InputStream in = null;
        try {
            in = TestData.openStream(this, "/overview/" + c1.getIndexName() + ".properties");
            assertNotNull("unable to find mosaic properties file", in);
            props.load(in);

            assertTrue(props.containsKey("Caching"));
            assertTrue(props.getProperty("Caching").equalsIgnoreCase("false"));
        } finally {
            if (in != null) {
                IOUtils.closeQuietly(in);
            }
        }

        // dispose
        coverage.dispose(true);
        reader.dispose();

        //build an absolute index and then make it run
        CatalogBuilderConfiguration c2 = new CatalogBuilderConfiguration();
        c2.setIndexName("shpindex_absolute");
        c2.setLocationAttribute("location");
        c2.setAbsolute(true);
        c2.setCaching(true);
        c2.setRootMosaicDirectory(TestData.file(this, "/overview").toString());
        c2.setIndexingDirectories(Arrays.asList(TestData.file(this, "/overview/0").toString()));
        assertNotNull(c2.toString());
        //build the index
        builder = new CatalogBuilder(c2);
        builder.addProcessingEventListener(new CatalogBuilderListener());
        builder.run();
        final File absoluteMosaic = TestData.file(this, "/overview/" + c2.getIndexName() + ".shp");
        assertTrue(absoluteMosaic.exists());

        //caching should be false by default
        props = new Properties();
        in = null;
        try {
            in = TestData.openStream(this, "/overview/" + c2.getIndexName() + ".properties");
            assertNotNull("unable to find mosaic properties file", in);
            props.load(in);

            assertTrue(props.containsKey("Caching"));
            assertTrue(props.getProperty("Caching").equalsIgnoreCase("true"));
        } finally {
            if (in != null) {
                IOUtils.closeQuietly(in);
            }
        }

        assertTrue(new ImageMosaicFormat().accepts(absoluteMosaic));
        reader = (ImageMosaicReader) new ImageMosaicReader(absoluteMosaic);

        // limit yourself to reading just a bit of it
        gg = AbstractGridFormat.READ_GRIDGEOMETRY2D.createValue();
        envelope = reader.getOriginalEnvelope();
        dim = new Dimension();
        dim.setSize(reader.getOriginalGridRange().getSpan(0) / 2.0,
                reader.getOriginalGridRange().getSpan(1) / 2.0);
        rasterArea = ((GridEnvelope2D) reader.getOriginalGridRange());
        rasterArea.setSize(dim);
        range = new GridEnvelope2D(rasterArea);
        gg.setValue(new GridGeometry2D(range, envelope));

        // use imageio with defined tiles

        // Test the output coverage
        coverage = (GridCoverage2D) reader.read(new GeneralParameterValue[] { gg, useJai, tileSize });
        Assert.assertNotNull(coverage);
        PlanarImage.wrapRenderedImage(coverage.getRenderedImage()).getTiles();

        // dispose
        coverage.dispose(true);
        reader.dispose();
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

/**
 * @param report//  w  w w  . jav a2 s  .c  om
 * 
 * Loads and runs the query that acts as data source for report. Then runs report.
 */
public static void runReport(final SpReport report, final String title, final RecordSetIFace rs) {
    //XXX This is now also used to run Workbench reports. Really should extract the general stuff out
    //to a higher level...
    boolean isQueryBuilderRep = report.getReportObject() instanceof SpQuery;
    if (isQueryBuilderRep) {
        UsageTracker.incrUsageCount("QB.RunReport." + report.getQuery().getContextName());
    } else {
        UsageTracker.incrUsageCount("WB.RunReport");
    }
    TableTree tblTree = null;
    Hashtable<String, TableTree> ttHash = null;
    QueryParameterPanel qpp = null;
    if (isQueryBuilderRep) {
        UsageTracker.incrUsageCount("QB.RunReport." + report.getQuery().getContextName());
        QueryTask qt = (QueryTask) ContextMgr.getTaskByClass(QueryTask.class);
        if (qt != null) {
            Pair<TableTree, Hashtable<String, TableTree>> trees = qt.getTableTrees();
            tblTree = trees.getFirst();
            ttHash = trees.getSecond();
        } else {
            log.error("Could not find the Query task when running report " + report.getName());
            //blow up
            throw new RuntimeException("Could not find the Query task when running report " + report.getName());
        }
        qpp = new QueryParameterPanel();
        qpp.setQuery(report.getQuery(), tblTree, ttHash);
    }
    boolean go = true;
    try {
        JasperCompilerRunnable jcr = new JasperCompilerRunnable(null, report.getName(), null);
        jcr.findFiles();
        if (jcr.isCompileRequired()) {
            jcr.get();
        }
        //if isCompileRequired() is still true, then an error probably occurred compiling the report.
        JasperReport jr = !jcr.isCompileRequired() ? (JasperReport) JRLoader.loadObject(jcr.getCompiledFile())
                : null;
        ReportParametersPanel rpp = jr != null ? new ReportParametersPanel(jr, true) : null;
        JRDataSource src = null;
        if (rs == null && ((qpp != null && qpp.getHasPrompts()) || (rpp != null && rpp.getParamCount() > 0))) {
            Component pane = null;
            if (qpp != null && qpp.getHasPrompts() && rpp != null && rpp.getParamCount() > 0) {
                pane = new JTabbedPane();
                ((JTabbedPane) pane).addTab(UIRegistry.getResourceString("QB_REP_RUN_CRITERIA_TAB_TITLE"),
                        new JScrollPane(qpp, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));

                ((JTabbedPane) pane).addTab(UIRegistry.getResourceString("QB_REP_RUN_PARAM_TAB_TITLE"),
                        new JScrollPane(rpp, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                                ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
            } else if (qpp != null && qpp.getHasPrompts()) {
                pane = new JScrollPane(qpp, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            } else {
                pane = new JScrollPane(rpp, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
                        ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
            }
            CustomDialog cd = new CustomDialog((Frame) UIRegistry.getTopWindow(),
                    UIRegistry.getResourceString("QB_GET_REPORT_CONTENTS_TITLE"), true,
                    CustomDialog.OKCANCELHELP, pane);
            cd.setHelpContext("RepRunSettings");
            cd.createUI();
            Dimension ps = cd.getPreferredSize();
            ps.setSize(ps.getWidth() * 1.3, ps.getHeight());
            cd.setSize(ps);
            UIHelper.centerAndShow(cd);
            go = !cd.isCancelled();
            cd.dispose();
        }
        if (go) {
            if (isQueryBuilderRep) {
                TableQRI rootQRI = null;
                int cId = report.getQuery().getContextTableId();
                for (TableTree tt : ttHash.values()) {
                    if (cId == tt.getTableInfo().getTableId()) {
                        rootQRI = tt.getTableQRI();
                        break;
                    }
                }
                Vector<QueryFieldPanel> qfps = new Vector<QueryFieldPanel>(qpp.getFields());
                for (int f = 0; f < qpp.getFields(); f++) {
                    qfps.add(qpp.getField(f));
                }

                HQLSpecs sql = null;

                // XXX need to allow modification of SelectDistinct(etc) ???
                //boolean includeRecordIds = true;
                boolean includeRecordIds = !report.getQuery().isSelectDistinct();

                try {
                    //XXX Is it safe to assume that query is not an export query? 
                    sql = QueryBldrPane.buildHQL(rootQRI, !includeRecordIds, qfps, tblTree, rs,
                            report.getQuery().getSearchSynonymy() == null ? false
                                    : report.getQuery().getSearchSynonymy(),
                            false, null);
                } catch (Exception ex) {
                    String msg = StringUtils.isBlank(ex.getLocalizedMessage())
                            ? getResourceString("QB_RUN_ERROR")
                            : ex.getLocalizedMessage();
                    UIRegistry.getStatusBar().setErrorMessage(msg, ex);
                    UIRegistry.writeTimedSimpleGlassPaneMsg(msg, Color.RED);
                    return;
                }
                int smushedCol = (report.getQuery().getSmushed() != null && report.getQuery().getSmushed())
                        ? getSmushedCol(qfps) + 1
                        : -1;
                src = new QBDataSource(sql.getHql(), sql.getArgs(), sql.getSortElements(),
                        getColumnInfo(qfps, true, rootQRI.getTableInfo(), false), includeRecordIds,
                        report.getRepeats(), smushedCol, /*getRecordIdCol(qfps)*/0);
                ((QBDataSource) src).startDataAcquisition();
            } else {
                DataProviderSessionIFace session = DataProviderFactory.getInstance().createSession();
                try {
                    boolean loadedWB = false;
                    if (rs != null && rs.getOnlyItem() != null) {
                        Workbench wb = session.get(Workbench.class, rs.getOnlyItem().getRecordId());
                        if (wb != null) {
                            wb.forceLoad();
                            src = new WorkbenchJRDataSource(wb, true, report.getRepeats());
                            loadedWB = true;
                        }
                    }
                    if (!loadedWB) {
                        UIRegistry.displayErrorDlgLocalized("QueryBldrPane.WB_LOAD_ERROR_FOR_REPORT",
                                rs != null ? rs.getName() : "[" + UIRegistry.getResourceString("NONE") + "]");
                        return;
                    }
                } finally {
                    session.close();
                }
            }

            final CommandAction cmd = new CommandAction(ReportsBaseTask.REPORTS, ReportsBaseTask.PRINT_REPORT,
                    src);
            cmd.setProperty("title", title);
            cmd.setProperty("file", report.getName());
            if (rs == null) {
                cmd.setProperty("skip-parameter-prompt", "true");
            }
            //if isCompileRequired is true then an error probably occurred while compiling,
            //and, if so, it will be caught again and reported in the report results pane.
            if (!jcr.isCompileRequired()) {
                cmd.setProperty("compiled-file", jcr.getCompiledFile());
            }
            if (rpp != null && rpp.getParamCount() > 0) {
                StringBuilder params = new StringBuilder();
                for (int p = 0; p < rpp.getParamCount(); p++) {
                    Pair<String, String> param = rpp.getParam(p);
                    if (StringUtils.isNotBlank(param.getSecond())) {
                        params.append(param.getFirst());
                        params.append("=");
                        params.append(param.getSecond());
                        params.append(";");
                    }
                    cmd.setProperty("params", params.toString());
                }
            }
            CommandDispatcher.dispatch(cmd);
        }
    } catch (JRException ex) {
        UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryBldrPane.class, ex);
        log.error(ex);
        ex.printStackTrace();
    }
}

From source file:v800_trainer.JCicloTronic.java

/** Creates new form JCicloTronic */
public JCicloTronic() {

    ScreenSize = new Dimension();
    SelectionChanged = false;//w ww  .  j a  va 2s.c  o m
    ScreenSize.setSize(java.awt.Toolkit.getDefaultToolkit().getScreenSize().getWidth() - 50,
            java.awt.Toolkit.getDefaultToolkit().getScreenSize().getHeight() - 50);
    Size = new Dimension();

    Properties = new java.util.Properties();
    SystemProperties = java.lang.System.getProperties();
    chooser = new javax.swing.JFileChooser();
    RawData = new byte[98316];
    //        System.setProperty("jna.library.path" , "C:/WINDOWS/system32");

    try {
        FileInputStream in = new FileInputStream(SystemProperties.getProperty("user.dir")
                + SystemProperties.getProperty("file.separator") + "JCicloexp.cfg");
        Properties.load(in);
        in.close();
    } catch (Exception e) {
        FontSize = 20;
        setFontSizeGlobal("Tahoma", FontSize);

        JOptionPane.showMessageDialog(null,
                "Keine Config-Datei in:  " + SystemProperties.getProperty("user.dir"), "Achtung!",
                JOptionPane.ERROR_MESSAGE);
        Properties.put("working.dir", SystemProperties.getProperty("user.dir"));
        Eigenschaften = new Eigenschaften(new javax.swing.JFrame(), true, this);
        this.setExtendedState(Frame.MAXIMIZED_BOTH);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        double width = screenSize.getWidth();
        double height = screenSize.getHeight();
        this.setSize(new Dimension((int) width, (int) height));
        this.setPreferredSize(new Dimension((int) width, (int) height));
        this.setMinimumSize(new Dimension((int) width, (int) height));
        repaint();
    }
    try {

        UIManager.setLookAndFeel(Properties.getProperty("LookFeel"));
        SwingUtilities.updateComponentTreeUI(this);
        this.pack();
    } catch (Exception exc) {
    }

    if (debug) {
        try {
            System.setErr(new java.io.PrintStream(new FileOutputStream(Properties.getProperty("working.dir")
                    + SystemProperties.getProperty("file.separator") + "error.txt")));
            //        System.err =  new FileOutputStream(Properties.getProperty("working.dir") + SystemProperties.getProperty("file.separator") + "error.txt");
            System.setOut(new java.io.PrintStream(new FileOutputStream(Properties.getProperty("working.dir")
                    + SystemProperties.getProperty("file.separator") + "error.txt")));
        } catch (Exception err) {
        }
    }

    initComponents();

    setTitle("V800 Trainer    Datadir: " + Properties.getProperty("data.dir"));

    icon = new ImageIcon("hw.jpg");
    setIconImage(icon.getImage());

    if (Integer.parseInt(Properties.getProperty("View Geschw", "1")) == 1) {
        Graphik_check_Geschwindigkeit.setSelected(true);
    } else {
        Graphik_check_Geschwindigkeit.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Hhe", "1")) == 1) {
        Graphik_check_Hhe.setSelected(true);
    } else {
        Graphik_check_Hhe.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Hf", "1")) == 1) {
        Graphik_check_HF.setSelected(true);
    } else {
        Graphik_check_HF.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Temp", "1")) == 1) {
        Graphik_check_Temp.setSelected(true);
    } else {
        Graphik_check_Temp.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Steigp", "1")) == 1) {
        Graphik_check_Steigung_p.setSelected(true);
    } else {
        Graphik_check_Steigung_p.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Steigm", "1")) == 1) {
        Graphik_check_Steigung_m.setSelected(true);
    } else {
        Graphik_check_Steigung_m.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View av_Geschw", "1")) == 1) {
        Graphik_check_av_Geschw.setSelected(true);
    } else {
        Graphik_check_av_Geschw.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Cadence", "1")) == 1) {
        Graphik_check_Cadence.setSelected(true);
    } else {
        Graphik_check_Cadence.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("View Schrittlnge", "1")) == 1) {
        Graphik_check_Schrittlnge.setSelected(true);
    } else {
        Graphik_check_Schrittlnge.setSelected(false);
    }

    if (Integer.parseInt(Properties.getProperty("ZeitStreckeAbstnde", "1")) == 1) {
        Graphik_check_Abstand.setSelected(true);
    } else {
        Graphik_check_Abstand.setSelected(false);
    }
    if (Integer.parseInt(Properties.getProperty("SummenHisto", "1")) == 1) {
        Summenhistogramm_Check.setSelected(true);
    } else {
        Summenhistogramm_Check.setSelected(false);
    }

    if (Integer.parseInt(Properties.getProperty("xy_Strecke", "1")) == 1) {
        Graphik_Radio_Strecke.setSelected(true);
        Graphik_Radio_Zeit.setSelected(false);
    } else {
        Graphik_Radio_Strecke.setSelected(false);
        Graphik_Radio_Zeit.setSelected(true);
    }

    //Buttons fr XY-Darstellung   (ber Strecke oder ber Zeit)
    X_Axis = new ButtonGroup();
    X_Axis.add(Graphik_Radio_Strecke);
    X_Axis.add(Graphik_Radio_Zeit);

    //Buttons fr Jahresbersicht
    bersicht = new ButtonGroup();
    bersicht.add(jRadioButton_jahresverlauf);
    bersicht.add(jRadioButton_monatsbersicht);

    Datenliste_Zeitabschnitt.addItem("nicht aktiv");
    Datenliste_Zeitabschnitt.addItem("vergangene Woche");
    Datenliste_Zeitabschnitt.addItem("vergangener Monat");
    Datenliste_Zeitabschnitt.addItem("vergangenes Jahr");
    Datenliste_Zeitabschnitt.addItem("Alles");

    if (Datentabelle.getRowCount() != 0) {
        Datentabelle.addRowSelectionInterval(0, 0);
        Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0));
    }
    //        if (Properties.getProperty("CommPort").equals("nocom")) {
    //            jMenuReceive.setEnabled(false);
    //        } else {
    //            jMenuReceive.setEnabled(true);
    //        }

    jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount());

    setFileChooserFont(chooser.getComponents());
    locmap = true;
    Map_Type.removeAllItems();
    Map_Type.addItem("OpenStreetMap");
    Map_Type.addItem("Virtual Earth Map");
    Map_Type.addItem("Virtual Earth Satelite");
    Map_Type.addItem("Virtual Earth Hybrid");
    locmap = false;
    //    ChangeModel();
}