Example usage for javax.swing JFrame setLocation

List of usage examples for javax.swing JFrame setLocation

Introduction

In this page you can find the example usage for javax.swing JFrame setLocation.

Prototype

@Override
public void setLocation(int x, int y) 

Source Link

Document

The method changes the geometry-related data.

Usage

From source file:org.openscience.jchempaint.application.JChemPaint.java

public static JChemPaintPanel showInstance(IChemModel chemModel, String title, boolean debug) {
    JFrame f = new JFrame(title + " - JChemPaint");
    chemModel.setID(title);//from w  ww. j ava2s. c  o  m
    f.addWindowListener(new JChemPaintPanel.AppCloser());
    f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    JChemPaintPanel p = new JChemPaintPanel(chemModel, GUI_APPLICATION, debug, null);
    p.updateStatusBar();
    f.setPreferredSize(new Dimension(800, 494)); //1.618
    f.add(p);
    f.pack();
    Point point = GraphicsEnvironment.getLocalGraphicsEnvironment().getCenterPoint();
    int w2 = (f.getWidth() / 2);
    int h2 = (f.getHeight() / 2);
    f.setLocation(point.x - w2, point.y - h2);
    f.setVisible(true);
    frameList.add(f);
    return p;
}

From source file:org.squidy.nodes.ReacTIVision.java

public static void showErrorPopUp(String errorMessage) {
    //get screen size
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    //create pop up
    final JFrame frame = new JFrame();
    frame.setResizable(false);//from  w w w .ja va 2 s  .  c o m
    frame.setAlwaysOnTop(true);
    frame.setUndecorated(true);
    JLabel text = new JLabel(" " + errorMessage + " ");
    frame.getContentPane().setBackground(Color.RED);
    text.setForeground(Color.WHITE);
    frame.add(text);
    frame.pack();
    frame.setLocation((dim.width - frame.getWidth()) / 2, (dim.height - frame.getHeight()) / 2);
    frame.setVisible(true);
    frame.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent arg0) {
            frame.dispose();
        }
    });
}

From source file:org.swiftexplorer.SwiftExplorer.java

private static void openMainWindow(final MainPanel cp) throws IOException {
    JFrame frame = new JFrame(Configuration.INSTANCE.getAppName());

    Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

    float ratio = (float) 0.8;
    Dimension windowSize = new Dimension((int) (screenSize.getWidth() * ratio),
            (int) (screenSize.getHeight() * ratio));

    frame.setSize(windowSize.getSize());
    frame.setLocationByPlatform(true);/*w w  w. j  a  va2 s .  c om*/
    frame.setIconImage(ImageIO.read(SwiftExplorer.class.getResource("/icons/logo.png")));
    frame.getContentPane().add(cp);
    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            if (cp.onClose()) {
                System.exit(0);
            }
        }
    });
    cp.setOwner(frame);
    frame.setJMenuBar(cp.createMenuBar());

    // center the frame
    int x = (int) ((screenSize.getWidth() - frame.getWidth()) / 2);
    int y = (int) ((screenSize.getHeight() - frame.getHeight()) / 2);
    frame.setLocation(x, y);

    frame.setVisible(true);
}

From source file:test.integ.be.fedict.commons.eid.client.JCATest.java

@Test
public void testSwingParentLocale() throws Exception {
    Security.addProvider(new BeIDProvider());

    final JFrame frame = new JFrame("Test Parent frame");
    frame.setSize(200, 200);// w  ww  .j  ava 2s  . c  o  m
    frame.setLocation(300, 300);
    frame.setVisible(true);

    final KeyStore keyStore = KeyStore.getInstance("BeID");
    final BeIDKeyStoreParameter keyStoreParameter = new BeIDKeyStoreParameter();
    keyStoreParameter.setLogoff(true);
    keyStoreParameter.setParentComponent(frame);
    keyStoreParameter.setLocale(new Locale("nl"));
    keyStore.load(keyStoreParameter);

    final PrivateKey authnPrivateKey = (PrivateKey) keyStore.getKey("Authentication", null);
    final Signature signature = Signature.getInstance("SHA1withRSA");
    signature.initSign(authnPrivateKey);

    final byte[] toBeSigned = "hello world".getBytes();
    signature.update(toBeSigned);
    signature.sign();
}

From source file:ucar.unidata.idv.ui.ImageGenerator.java

/**
 * Capture the movie/*from  w w w .j  a va2s .  c o m*/
 *
 * @param filename The file
 * @param globalPalette Whether or not animated GIF output should use a
 * {@literal "global"} color palette.
 * @param scriptingNode Node form isl.
 */
public synchronized void captureMovie(String filename, boolean globalPalette, Element scriptingNode) {

    if ((filename == null) && (scriptingNode != null)) {
        filename = XmlUtil.getAttribute(scriptingNode, ATTR_FILE);
    }

    if (scriptingNode != null) {
        List files = findFiles(scriptingNode);
        if (files != null) {
            debug("Making movie from existing images " + filename);
            logger.trace("#1: creating '{}'", filename);
            filename = applyMacros(filename);
            Dimension size = new Dimension(applyMacros(scriptingNode, ATTR_WIDTH, 400),
                    applyMacros(scriptingNode, ATTR_HEIGHT, 300));
            ImageSequenceGrabber isg = new ImageSequenceGrabber(filename, getIdv(), this, scriptingNode, files,
                    size, applyMacros(scriptingNode, ATTR_FRAMERATE, 2),
                    applyMacros(scriptingNode, ATTR_ENDFRAMEPAUSE, -1));
            return;
        }
    }

    List<ViewManager> viewManagers = null;
    if ((scriptingNode != null) && XmlUtil.hasAttribute(scriptingNode, ATTR_DISPLAY)) {
        DisplayControlImpl display = findDisplayControl(scriptingNode);
        if (display == null) {
            throw new IllegalArgumentException("Could not find display:" + XmlUtil.toString(scriptingNode));
        }
        String what = applyMacros(scriptingNode, ATTR_WHAT, (String) null);

        ViewManager viewManager = null;
        try {
            viewManager = display.getViewManagerForCapture(what);
            if (viewManager != null) {
                viewManager.updateDisplayIfNeeded();
            }
        } catch (Exception exc) {
            throw new RuntimeException(exc);
        }

        if (viewManager != null) {
            viewManagers = (List<ViewManager>) Misc.newList(viewManager);
        } else {
            throw new IllegalArgumentException(
                    "Cannot capture a movie with display:" + XmlUtil.toString(scriptingNode));
        }
    }

    if (viewManagers == null) {
        viewManagers = (List<ViewManager>) getViewManagers(scriptingNode);
    }

    boolean combine = XmlUtil.getAttribute(scriptingNode, ImageGenerator.ATTR_COMBINE, false);

    if (combine) {
        ViewManager viewManager = getIdv().getVMManager().getLastActiveViewManager();

        getProperties().put(PROP_VIEWINDEX, new Integer(0));
        String name = viewManager.getName();
        if (name == null) {
            name = "view" + 0;
        }
        getProperties().put(PROP_VIEWNAME, name);

        if (!getIdv().getArgsManager().getIsOffScreen()) {
            JFrame frame = GuiUtils.getFrame(viewManager.getContents());
            if (frame != null) {
                LogUtil.registerWindow(frame);
                frame.setVisible(true);
                GuiUtils.toFront(frame);
                frame.setLocation(50, 50);
                Misc.sleep(50);
            }
        }
        String loopFilename = applyMacros(filename);
        debug("Making movie:" + loopFilename);
        logger.trace("#2: creating '{}'", filename);
        ImageSequenceGrabber isg = new ImageSequenceGrabber(viewManager, loopFilename, globalPalette, getIdv(),
                this, scriptingNode);
        try {
            wait();
        } catch (Exception exc) {
            logException("Doing the captureMovie wait", exc);
        }
        debug("Done making movie:" + loopFilename);

    } else {

        for (int i = 0; i < viewManagers.size(); i++) {
            ViewManager viewManager = viewManagers.get(i);

            getProperties().put(PROP_VIEWINDEX, new Integer(i));
            String name = viewManager.getName();
            if (name == null) {
                name = "view" + i;
            }
            getProperties().put(PROP_VIEWNAME, name);

            if (!getIdv().getArgsManager().getIsOffScreen()) {
                JFrame frame = GuiUtils.getFrame(viewManager.getContents());
                if (frame != null) {
                    LogUtil.registerWindow(frame);
                    frame.setVisible(true);
                    GuiUtils.toFront(frame);
                    frame.setLocation(50, 50);
                    Misc.sleep(50);
                }
            }
            String loopFilename = applyMacros(filename);
            debug("Making movie:" + loopFilename);
            logger.trace("#3: creating '{}'", filename);
            ImageSequenceGrabber isg = new ImageSequenceGrabber(viewManager, loopFilename, globalPalette,
                    getIdv(), this, scriptingNode);
            try {
                wait();
            } catch (Exception exc) {
                logException("Doing the captureMovie wait", exc);
            }
            debug("Done making movie:" + loopFilename);
        }
    }

}

From source file:uiuc.dm.miningTools.ui.ParametersSelectionFrame.java

@Override
public void actionPerformed(ActionEvent e) {
    String selectedFunction = (String) functionCombo.getSelectedItem();
    if (e.getSource() == functionCombo) {
        if (selectedFunction.equals(comboOptions.getFunctionOptions()[0])) {
            // show necessary input arguments for computing distance matrix
            showPanel(displayInstructionPanel);
            hidePanel(performancePanel);
            hidePanel(miningFunctionParamsSelectionPanel);
            hidePanel(plotDensityMapPanel);
        } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[1])) {
            // show necessary input arguments for computing sigLevel
            showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE);
            showPanel(sigLevelParamsPanel);
            showPanel(displayInstructionPanel);
            hidePanel(plotMapParamsPanel);
            hidePanel(performancePanel);
            hidePanel(this.followingParamsPanel);
            hidePanel(this.plotDensityMapPanel);
        } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[2])) {
            // show necessary input arguments for ploting a map
            showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE);
            showPanel(plotMapParamsPanel);
            hidePanel(sigLevelParamsPanel);
            hidePanel(performancePanel);
            hidePanel(displayInstructionPanel);
            hidePanel(this.followingParamsPanel);
            hidePanel(this.plotDensityMapPanel);
        } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[3])) {
            showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE);
            showPanel(this.followingParamsPanel);
            showPanel(displayInstructionPanel);
            hidePanel(plotMapParamsPanel);
            hidePanel(sigLevelParamsPanel);
            hidePanel(performancePanel);
            hidePanel(this.plotDensityMapPanel);
        } else if (selectedFunction.equals(comboOptions.getFunctionOptions()[4])) {
            showPanel(miningFunctionParamsSelectionPanel, MINING_FUNC_PARAMS_SELECTION_PANEL_TITLE);
            showPanel(this.plotDensityMapPanel);
            hidePanel(this.followingParamsPanel);
            hidePanel(displayInstructionPanel);
            hidePanel(plotMapParamsPanel);
            hidePanel(sigLevelParamsPanel);
            hidePanel(performancePanel);
        }/*from w  ww .ja va2 s  .c om*/
    }

    if (e.getSource() == useLocalCopyButton) {
        useLocalCopyButton.setEnabled(false);
        loadDatasetButton.setEnabled(false);
        downloadOnlineButton.setEnabled(false);
        stats.setText("");
        showPanel(downloadDatasetProgressPanel);
        datasetCombo.setEnabled(false);
        downloadDatasetProgressBar.setValue(0);
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        showPanel(selectTimespanPanel);
        showPanel(displayStatsPanel, DISPLAY_STATS_PANEL_TITLE);
        stats.setText("Fetching License Terms from server ...");
        String selectedDatasetName = (String) datasetCombo.getSelectedItem();
        downloadTask = new DownloadDatasetTask(selectedDatasetName);
        downloadTask.addPropertyChangeListener(this);
        downloadTask.execute();
    }

    if (e.getSource() == downloadOnlineButton) {
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
        useLocalCopyButton.setEnabled(false);
        loadDatasetButton.setEnabled(false);
        downloadOnlineButton.setEnabled(false);
        hidePanel(interpolationParamsSelectionPanel);
        hidePanel(miningFunctionSelectionPanel);
        hidePanel(miningFunctionParamsSelectionPanel);
        hidePanel(displayInstructionPanel);
        hidePanel(performancePanel);
        hidePanel(displayStatsPanel);
        hidePanel(selectIndividualsPanel);
        hidePanel(selectTimespanPanel);

        stats.setText("");

        showPanel(downloadDatasetProgressPanel);
        showPanel(displayStatsPanel, DISPLAY_STATS_PANEL_TITLE);
        instructionLabel.setText("");
        datasetCombo.setEnabled(false);
        downloadDatasetProgressBar.setValue(0);

        stats.setText("Fetching License Terms from server ...");
        String selectedDatasetName = (String) datasetCombo.getSelectedItem();
        downloadTask = new DownloadDatasetTask(selectedDatasetName, true);
        downloadTask.addPropertyChangeListener(this);
        downloadTask.execute();
    }

    if (e.getSource() == loadDatasetButton) {

        if (useLocalCopyButton != null) {
            useLocalCopyButton.setEnabled(false);
        }
        if (downloadOnlineButton != null) {
            downloadOnlineButton.setEnabled(false);
        }
        loadDatasetButton.setEnabled(false);

        JFileChooser fc = new JFileChooser();
        String workingDir = System.getProperty("user.dir");
        fc.setCurrentDirectory(new File(workingDir));
        int returnVal = fc.showOpenDialog(ParametersSelectionFrame.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            final File file = fc.getSelectedFile();
            setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
            System.out.println("Opening " + file.getName());
            downloadDatasetProgressBar.setVisible(true);
            downloadDatasetProgressBar.setIndeterminate(true);
            downloadDatasetProgressBar.setStringPainted(false);

            hidePanel(interpolationParamsSelectionPanel);
            hidePanel(miningFunctionSelectionPanel);
            hidePanel(miningFunctionParamsSelectionPanel);
            hidePanel(displayInstructionPanel);
            hidePanel(performancePanel);
            hidePanel(displayStatsPanel);
            hidePanel(selectIndividualsPanel);
            hidePanel(selectTimespanPanel);

            stats.setText("");

            showPanel(downloadDatasetProgressPanel);
            showPanel(displayStatsPanel, DISPLAY_STATS_PANEL_TITLE);
            instructionLabel.setText("");

            LoadDatasetTask loadDatasetTask = new LoadDatasetTask(file.getAbsolutePath()) {
                @Override
                public void done() {
                    if (this.isFailToParse()) {
                        stats.setText(this.getErrorMsg());
                        downloadDatasetProgressPanel.setVisible(false);
                        hidePanel(interpolationParamsSelectionPanel);
                        hidePanel(miningFunctionSelectionPanel);
                        hidePanel(miningFunctionParamsSelectionPanel);
                        hidePanel(displayInstructionPanel);
                        hidePanel(performancePanel);
                        hidePanel(selectIndividualsPanel);
                        hidePanel(selectTimespanPanel);
                    } else {
                        trajsMap = this.getTrajsMap();
                        ArrayList<Trajectory> trajs = new ArrayList(trajsMap.values());

                        Dataset dataset = new Dataset();
                        dataset.storeData(trajs, trajsMap);
                        dataset.setDatasetName(file.getName());
                        curSelectedDatasetName = file.getName();
                        initIndividualNames();
                        downloadDatasetProgressPanel.setVisible(false);
                        showStats(dataset);
                        initSelectTimespanRange(dataset.getStartTime(), dataset.getEndTime());

                        showPanel(selectTimespanPanel);
                        showPanel(interpolationParamsSelectionPanel, INTERPOLATE_PARAMS_PANEL_TITLE);
                        showPanel(selectIndividualsPanel);
                        showPanel(selectTimespanPanel);

                        setCursor(null); //turn off the wait cursor
                        downloadDatasetProgressBar.setIndeterminate(false);
                        downloadDatasetProgressBar.setStringPainted(true);
                    }
                }
            };
            loadDatasetTask.addPropertyChangeListener(this);
            loadDatasetTask.execute();
        } else {
            System.out.println("Open command cancelled by user.");
        }
        loadDatasetButton.setEnabled(true);
        setCursor(null);
        if (useLocalCopyButton != null) {
            useLocalCopyButton.setEnabled(true);
        }
        if (downloadOnlineButton != null) {
            downloadOnlineButton.setEnabled(true);
        }
    }

    if (e.getSource() == goButton) {
        showPanel(performancePanel);
        //            String selectedDatasetName = (String) datasetCombo
        //                    .getSelectedItem();
        String selectedDatasetName = curSelectedDatasetName;
        instructionLabel.setText("Loading ...");
        String displayMethod = (String) displayMethodCombo.getSelectedItem();
        String gap = (String) gapCombo.getSelectedItem();
        String thresGap = (String) thresGapCombo.getSelectedItem();
        String numRound = (String) numRoundCombo.getSelectedItem();
        String distThres = distThresTextedField.getText();

        /*Fei*/
        String ml = (String) this.minIntervalLengthField.getText();
        String lMax = (String) this.lMaxLabelTextedField.getText();
        String dMax = (String) this.dMaxLabelTextedField.getText();
        /**/
        boolean needInterpolation = this.interpFlag;
        try {
            MiningFunctionParameters params;
            instructionLabel.setText("Running mining algorithm ...");
            params = new MiningFunctionParameters();
            params.setSelectedDatasetName(selectedDatasetName);
            params.setSelectedFunction(selectedFunction);
            params.setDisplayMethod(displayMethod);
            params.setNeedInterpolation(needInterpolation);
            params.setGap(gap);
            params.setThresGap(thresGap);
            params.setNumRound(numRound);
            params.setDistThres(distThres);
            /*Fei*/
            int lmax_int = (int) Math.floor(Double.parseDouble(lMax));
            params.setlMax("" + lmax_int);
            params.setdMax(dMax);
            params.setMinL(ml);
            /**/
            params.setStartTime(selectStartTimePicker.getDate());
            params.setEndTime(selectEndTimePicker.getDate());
            ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv);
            List<Trajectory> subTrajs = getSubTrajectory(trajs, selectStartTimePicker.getDate(),
                    selectEndTimePicker.getDate());
            if (selectedFunction.equalsIgnoreCase("Following mining") && trajs.size() != 2) {
                JOptionPane.showMessageDialog(this.contentPane,
                        "Please select two animals for following mining.");
            } else if (!selectedFunction.equalsIgnoreCase("Following mining") && needInterpolation == false) {
                JOptionPane.showMessageDialog(this.contentPane,
                        "Selected function requires interpolation. Please check the interpolation option.");
            } else if (!selectedFunction.equalsIgnoreCase("Plotting") && trajs.size() < 2) {
                JOptionPane.showMessageDialog(this.contentPane, "Please select at least two animals.");

            } else {
                boolean dothejob = false;
                int dialogresult = JOptionPane.YES_OPTION;
                if (this.aveSampling >= 1 && selectedFunction.equalsIgnoreCase("Following mining")) {
                    dialogresult = JOptionPane.showConfirmDialog(this.contentPane,
                            "Recommend to use dataset having higher sampling rate (less than 1 minper sample) for this function. \n Do you still want to proceed?",
                            "", JOptionPane.YES_NO_OPTION);
                }
                if (dialogresult == JOptionPane.YES_OPTION)
                    dothejob = true;
                if (dothejob) {
                    goButton.setEnabled(false);
                    disablePanel(datasetSelectionPanel);
                    disablePanel(interpolationParamsSelectionPanel);
                    disablePanel(miningFunctionSelectionPanel);
                    disablePanel(miningFunctionParamsSelectionPanel);
                    disablePanel(selectIndividualsPanel);
                    disablePanel(sigLevelParamsPanel);
                    disablePanel(selectTimespanPanel);
                    /*Fei*/
                    disablePanel(this.followingParamsPanel);
                    /**/

                    JFrame dvPanel = new DataVisualization(subTrajs, params, this);
                    dvPanel.setLocation(this.getX() + this.getWidth(), this.getY());
                    dvPanel.setVisible(true);
                }

                //this.saveKmlButtonF.setVisible(true);
            }

        } catch (Exception ex) {
            Logger.getLogger(ParametersSelectionFrame.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    if (e.getSource() == saveDensityMapButton) {
        String selectedDatasetName = curSelectedDatasetName;
        String displayMethod = (String) displayMethodCombo.getSelectedItem();
        MiningFunctionParameters params = new MiningFunctionParameters();
        String gap = (String) gapCombo.getSelectedItem();
        String thresGap = (String) thresGapCombo.getSelectedItem();
        boolean needInterpolation = false;
        params.setSelectedDatasetName(selectedDatasetName);
        params.setSelectedFunction(selectedFunction);
        params.setDisplayMethod(displayMethod);
        params.setNeedInterpolation(needInterpolation);
        params.setGap(gap);
        params.setThresGap(thresGap);

        ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv);
        List<Trajectory> subTrajs = getSubTrajectory(trajs, selectStartTimePicker.getDate(),
                selectEndTimePicker.getDate());
        JFrame dvPanel = new DataVisualization(subTrajs, params, this);
        dvPanel.setLocation(this.getX() + this.getWidth(), this.getY());
        dvPanel.setVisible(true);
    }

    if (e.getSource() == selectIndividualsButton) {
        ArrayList<String> selectedNames = ListDialog.showDialog(this, selectIndividualsButton,
                "All the individuals in the data set: ( hold Ctrl key to select multiple objects)",
                "Select individuals: ", individualNames, selectedIndividualIndicesForDv, "Index 1234567890");
        selectedIndividualIndicesForDv = getSelectedIndices(selectedNames);
        ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv);
        updateTimeSpanRange(trajs);
    }

    if (e.getSource() == saveKmlButton) {
        String selectedDatasetName = curSelectedDatasetName;
        String displayMethod = (String) displayMethodCombo.getSelectedItem();
        String gap = (String) gapCombo.getSelectedItem();
        String thresGap = (String) thresGapCombo.getSelectedItem();
        String numRound = (String) numRoundCombo.getSelectedItem();
        String distThres = distThresTextedField.getText();
        boolean needInterpolation = this.interpFlag;

        MiningFunctionParameters params = new MiningFunctionParameters();
        params.setSelectedDatasetName(selectedDatasetName);
        params.setSelectedFunction(selectedFunction);
        params.setDisplayMethod(displayMethod);
        params.setNeedInterpolation(needInterpolation);
        params.setGap(gap);
        params.setThresGap(thresGap);
        params.setNumRound(numRound);
        params.setDistThres(distThres);

        params.setStartTime(selectStartTimePicker.getDate());
        params.setEndTime(selectEndTimePicker.getDate());
        DateFormat dateFormat = new SimpleDateFormat("yyyy_MM_dd_HHmmss");
        //get current date time with Date()
        Date date = new Date();
        String outputPath = "result/" + "Plot_"
                + params.getSelectedDatasetName().substring(0, 4).replace(" ", "_") + "_"
                + dateFormat.format(date) + "/";
        new File(outputPath).mkdirs();
        ArrayList<Trajectory> trajs = getSelectedTrajectories(selectedIndividualIndicesForDv);
        List<Trajectory> subTrajs = getSubTrajectory(trajs, selectStartTimePicker.getDate(),
                selectEndTimePicker.getDate());
        JFrame computeKML = new GenerateKMLFile(trajsMap, params, outputPath, subTrajs);
        computeKML.setVisible(true);
    }
}

From source file:uk.ac.abdn.csd.p2p.server.ServerGUI.java

/**
 * This method prepares all the graphical components that are contained with P2P Visualisation Server.
 *//*from  w  w w .j  a va2s.  com*/
// <editor-fold defaultstate="collapsed" desc="...GUI">
private void initializeComponent() {
    listeningPort = 0;

    JFrame frame = new JFrame();
    BorderLayout layout = new BorderLayout();

    //create a graph
    overlay = new UndirectedSparseGraph<Vertex, Edge>();
    ObservableGraph<Vertex, Edge> og = new ObservableGraph<Vertex, Edge>(overlay);
    /*   og.addGraphEventListener(new GraphEventListener<Vertex, Edge>() {
       @Override
       public void handleGraphEvent(
       GraphEvent<Vertex, Edge> evt) {
    System.err.println("got " + evt);
            
       }
    });*/
    this.overlay = og;
    layout1 = new FRLayout2<Vertex, Edge>(overlay);
    vv = new VisualizationViewer<Vertex, Edge>(layout1, new Dimension(700, 200));
    vv.setGraphMouse(new DefaultModalGraphMouse<Vertex, Edge>());
    vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller<Vertex>());
    vv.getRenderContext().setEdgeLabelTransformer(new ToStringLabeller<Edge>());
    vv.getRenderer().getVertexLabelRenderer().setPosition(Position.CNTR);
    vv.getRenderContext().setVertexFillPaintTransformer(new VertexPainter());

    DefaultModalGraphMouse gm1 = new DefaultModalGraphMouse();
    gm1.setMode(ModalGraphMouse.Mode.TRANSFORMING);
    gm1.setMode(ModalGraphMouse.Mode.PICKING);
    gm1.add(new MyPopupGraphMousePlugin());
    vv.setGraphMouse(gm1);
    vv.addKeyListener(gm1.getModeKeyListener());

    contentPane = new JPanel(layout);

    displayPanel = new javax.swing.JPanel();

    consoleTextArea = new JTextArea();
    jScrollPane2 = new JScrollPane();
    clearButton = new JButton();
    consolePanel = new JPanel();
    clearButton = new javax.swing.JButton();

    nodeTextArea = new JTextArea();
    jScrollPane1 = new JScrollPane();
    nodePanel = new JPanel();

    linkTextArea = new JTextArea();
    jScrollPane3 = new JScrollPane();
    linkPanel = new JPanel();

    menuBar = new javax.swing.JMenuBar();
    serverMenu = new javax.swing.JMenu();
    startServerMenuItem = new javax.swing.JMenuItem();
    jSeparator1 = new javax.swing.JPopupMenu.Separator();
    exitMenuItem = new javax.swing.JMenuItem();
    editMenu = new javax.swing.JMenu();
    settingMenuItem = new javax.swing.JMenuItem();
    colorSettingMenuItem = new javax.swing.JMenuItem();
    toolMenuItem = new javax.swing.JMenu();
    clearMenuItem = new javax.swing.JMenuItem();
    helpMenu = new javax.swing.JMenu();
    aboutMenuItem = new javax.swing.JMenuItem();
    zoominMenuItem = new javax.swing.JMenuItem();
    zoomoutMenuItem = new javax.swing.JMenuItem();
    layoutSettingMenuItem = new javax.swing.JMenuItem();
    labelPositionMenuItem = new javax.swing.JMenuItem();
    speedSettingMenuItem = new javax.swing.JMenuItem();
    topologySettingMenuItem = new javax.swing.JMenuItem();
    findNodeMenuItem = new javax.swing.JMenuItem();

    serverMenu.setText("Server");
    serverMenu.setToolTipText("Server");

    startServerMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C,
            java.awt.event.InputEvent.ALT_MASK));
    startServerMenuItem.setText("Start Server");
    startServerMenuItem.setToolTipText("Start Server");
    startServerMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            startServerMenuItemActionPerformed(evt);
        }
    });
    serverMenu.add(startServerMenuItem);
    serverMenu.add(jSeparator1);

    exitMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X,
            java.awt.event.InputEvent.ALT_MASK));
    exitMenuItem.setText("Exit");
    exitMenuItem.setToolTipText("Exit");
    exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            exitMenuItemActionPerformed(evt);
        }
    });
    serverMenu.add(exitMenuItem);

    menuBar.add(serverMenu);

    editMenu.setText("Edit");
    editMenu.setToolTipText("Edit");

    settingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S,
            java.awt.event.InputEvent.ALT_MASK));
    settingMenuItem.setText("Server Settings");
    settingMenuItem.setToolTipText("Server Settings");
    settingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            settingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(settingMenuItem);

    colorSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_M,
            java.awt.event.InputEvent.ALT_MASK));
    colorSettingMenuItem.setText("Colour Settings");
    colorSettingMenuItem.setToolTipText("Colour Settings");
    colorSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            colorSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(colorSettingMenuItem);

    layoutSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_L,
            java.awt.event.InputEvent.ALT_MASK));
    layoutSettingMenuItem.setText("Layout Settings");
    layoutSettingMenuItem.setToolTipText("Layout Settings");
    layoutSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            layoutSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(layoutSettingMenuItem);

    speedSettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_V,
            java.awt.event.InputEvent.ALT_MASK));
    speedSettingMenuItem.setText("Speed Settings");
    speedSettingMenuItem.setToolTipText("Speed Settings");
    speedSettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            speedSettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(speedSettingMenuItem);

    topologySettingMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T,
            java.awt.event.InputEvent.ALT_MASK));
    topologySettingMenuItem.setText("Topology Settings");
    topologySettingMenuItem.setToolTipText("Topology Settings");
    topologySettingMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            topologySettingMenuItemActionPerformed(evt);
        }
    });
    editMenu.add(topologySettingMenuItem);

    menuBar.add(editMenu);

    toolMenuItem.setText("Tools");
    toolMenuItem.setToolTipText("Tools");

    labelPositionMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_P,
            java.awt.event.InputEvent.ALT_MASK));
    labelPositionMenuItem.setText("Vertex Label Position");
    labelPositionMenuItem.setToolTipText("Vertex Label Position");
    toolMenuItem.add(labelPositionMenuItem);
    labelPositionMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            labelPositionMenuItemActionPerformed(evt);

        }
    });

    final ScalingControl scaler = new CrossoverScalingControl();

    zoominMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_I,
            java.awt.event.InputEvent.ALT_MASK));
    zoominMenuItem.setText("Zoom-In");
    zoominMenuItem.setToolTipText("Zoom-In");
    toolMenuItem.add(zoominMenuItem);
    zoominMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            scaler.scale(vv, 1.1f, vv.getCenter());
        }
    });
    zoomoutMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
            java.awt.event.InputEvent.ALT_MASK));
    zoomoutMenuItem.setText("Zoom-Out");
    zoomoutMenuItem.setToolTipText("Zoom-Out");
    toolMenuItem.add(zoomoutMenuItem);
    zoomoutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            scaler.scale(vv, 0.9f, vv.getCenter());
        }
    });

    findNodeMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F,
            java.awt.event.InputEvent.ALT_MASK));
    findNodeMenuItem.setText("Find Node on Overlay");
    findNodeMenuItem.setToolTipText("Find Node");
    toolMenuItem.add(findNodeMenuItem);
    findNodeMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            findNodeMenuItemMenuItemActionPerformed(evt);
        }
    });

    menuBar.add(toolMenuItem);

    helpMenu.setText("Help");
    helpMenu.setToolTipText("Help");

    aboutMenuItem.setText("About");
    aboutMenuItem.setToolTipText("About");
    aboutMenuItem.addActionListener(new java.awt.event.ActionListener() {
        @Override
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            aboutMenuItemActionPerformed(evt);
        }
    });
    helpMenu.add(aboutMenuItem);

    menuBar.add(helpMenu);

    displayPanel.setLayout(new BorderLayout());
    displayPanel.setBorder(new TitledBorder("P2P Overlay"));
    displayPanel.add(vv);
    validate();
    //
    // nodeTextArea
    //
    nodeTextArea.setEditable(false);
    nodeTextArea.setLineWrap(true);

    //
    // jScrollPane1
    //
    jScrollPane1.setViewportView(nodeTextArea);
    //jScrollPane1.setsi
    //
    // nodePanel
    //
    nodePanel.setLayout(new BoxLayout(nodePanel, BoxLayout.X_AXIS));
    nodePanel.add(jScrollPane1, 0);

    nodePanel.setBorder(new TitledBorder("Nodes Active"));
    //
    // linkTextArea
    //
    linkTextArea.setEditable(false);
    linkTextArea.setLineWrap(true);
    //
    // jScrollPane3
    //
    jScrollPane3.setViewportView(linkTextArea);
    //
    // linkPanel
    //
    linkPanel.setLayout(new BoxLayout(linkPanel, BoxLayout.X_AXIS));
    linkPanel.add(jScrollPane3, 0);
    linkPanel.setBorder(new TitledBorder("Node Links"));
    //
    // consoleTextArea
    //
    consoleTextArea.setEditable(false);
    consoleTextArea.setLineWrap(true);
    //
    // jScrollPane2
    //
    jScrollPane2.setViewportView(consoleTextArea);
    //
    // clearButton
    //
    clearButton.setText("Clear");
    clearButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            clearButton_actionPerformed(e);
        }

    });
    //
    // consolePanel
    //
    consolePanel.setLayout(new BoxLayout(consolePanel, BoxLayout.X_AXIS));
    consolePanel.add(jScrollPane2, 0);
    consolePanel.add(clearButton, 1);
    consolePanel.setBorder(new TitledBorder("Console"));
    //
    // ServerGUI
    //
    Dimension panelD = new Dimension(700, 330); // display Panel
    Dimension panelD1 = new Dimension(700, 134); // control Panel      
    Dimension panelD2 = new Dimension(350, 140); // nodepanel and linkpanel
    Dimension panelD3 = new Dimension(700, 140); // nodepanel and linkpanel togther
    consolePanel.setPreferredSize(panelD1);
    displayPanel.setPreferredSize(panelD);
    nodePanel.setPreferredSize(panelD2);
    linkPanel.setPreferredSize(panelD2);
    Box box = new Box(BoxLayout.X_AXIS); // put nodepanel and linkpanel in one box
    box.add(nodePanel);
    box.add(linkPanel);
    box.setSize(panelD3);

    //contentPane.add(BorderLayout.NORTH,displayPanel);
    //contentPane.add(BorderLayout.CENTER,box);
    contentPane.add(BorderLayout.NORTH, box);
    contentPane.add(BorderLayout.CENTER, displayPanel);
    contentPane.add(BorderLayout.SOUTH, consolePanel);

    frame.setJMenuBar(menuBar);
    frame.getContentPane().add(contentPane);
    frame.setTitle("P2P Visualisation Server");
    frame.setSize(new Dimension(800, 600));
    frame.setResizable(true);
    // This code has been adapted from http://lookass.ch/?id=4&area=art&art=47
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension size = frame.getSize();
    screenSize.height = screenSize.height / 2;
    screenSize.width = screenSize.width / 2;
    size.height = size.height / 2;
    size.width = size.width / 2;
    int y = screenSize.height - size.height;
    int x = screenSize.width - size.width;
    frame.setLocation(x, y);
    frame.setVisible(true);

    frame.setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
        public void windowClosing(java.awt.event.WindowEvent evt) {
            formWindowClosing(evt);
        }
    });
}

From source file:uk.chromis.pos.forms.JRootApp.java

private void poweredbyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_poweredbyMouseClicked

    JFrame sampleFrame = new JFrame();
    final Action exit = new AbstractAction("Exit") {
        @Override/*w w  w .j  a  v a 2  s .co  m*/
        public final void actionPerformed(final ActionEvent e) {
            sampleFrame.setVisible(false);
            sampleFrame.dispose();
        }
    };

    String currentPath = null;

    if (OSValidator.isMac()) {
        try {
            currentPath = new File(
                    JRootApp.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath())
                            .toString();
        } catch (URISyntaxException ex) {
        }
    } else {
        currentPath = System.getProperty("user.dir") + "\\chromispos.jar";
    }

    String md5 = null;
    try {
        FileInputStream fis = new FileInputStream(new File(currentPath));
        md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
        fis.close();

    } catch (FileNotFoundException ex) {
        Logger.getLogger(JRootApp.class.getName()).log(Level.SEVERE, null, ex);

    } catch (IOException ex) {
        Logger.getLogger(JRootApp.class.getName()).log(Level.SEVERE, null, ex);
    }

    /*
    int mb = 1024*1024;         
    //Getting the runtime reference from system
    Runtime runtime = Runtime.getRuntime();         
    System.out.println("##### Heap utilization statistics [MB] #####");         
    //Print used memory
    System.out.println("Used Memory:"
    + (runtime.totalMemory() - runtime.freeMemory()) / mb); 
    //Print free memory
    System.out.println("Free Memory:"
    + runtime.freeMemory() / mb);         
    //Print total available memory
    System.out.println("Total Memory:" + runtime.totalMemory() / mb); 
    //Print Maximum available memory
    System.out.println("Max Memory:" + runtime.maxMemory() / mb);
     */
    AboutDialog dialog = new AboutDialog();
    JPanel dialogPanel = new JPanel();
    MigLayout layout = new MigLayout("", "[fill]");
    DefaultTableModel model = new DefaultTableModel();
    JTable table = new JTable(model);
    model.addColumn("Details");
    model.addColumn("Value");
    model.addRow(new Object[] { "Database Version", readDataBaseVersion() });
    model.addRow(new Object[] { "Java Version", System.getProperty("java.version") });
    model.addRow(new Object[] { "Jar MD5", md5 });
    model.addRow(new Object[] { "Operating System", System.getProperty("os.name") });
    model.addRow(new Object[] { "Sync library", Sync.getVersion() });

    JScrollPane scrollPane = new JScrollPane(table);
    JPanel mainPanel = new JPanel(layout);
    JLabel label = new JLabel();
    JPanel btnPanel = new JPanel();
    dialogPanel.add(dialog);
    mainPanel.add(dialogPanel, "wrap");
    mainPanel.add(scrollPane, "wrap");
    JButton btnExit = new JButton(exit);
    btnPanel.add(btnExit, "width 100!");
    mainPanel.add(btnPanel, "right, wrap");
    mainPanel.add(new JLabel(), "wrap");
    sampleFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    sampleFrame.setPreferredSize(new Dimension(500, 300));
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    sampleFrame.setLocation(dim.width / 2 - 250, dim.height / 2 - 150);
    sampleFrame.setUndecorated(true);
    mainPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0), 4));
    sampleFrame.add(mainPanel);
    sampleFrame.pack();
    sampleFrame.setVisible(true);

}

From source file:visolate.Main.java

public static void main(final String[] argv) {

    CommandLineParser parser = new PosixParser();
    Options options = new Options();
    options.addOption("x", "flip-x", false, "flip around x axis");
    options.addOption("y", "flip-y", false, "flip around y axis");
    options.addOption("a", "absolute", false, "use absolute cooridnates");
    options.addOption("d", "dpi", true, "dpi to use for rastering");
    options.addOption("A", "auto", false, "auto-mode (run, save and exit)");
    options.addOption("o", "outfile", true, "name of output file");

    options.addOption("h", "help", false, "display this help and exit");
    options.addOption("V", "version", false, "output version information and exit");

    CommandLine commandline;//w  w w. j a  va 2 s.  c  o m
    try {
        commandline = parser.parse(options, argv);
    } catch (ParseException e) {
        System.err.println(e.getLocalizedMessage());
        System.exit(1);
        return; // make it clear to the compiler that the following code is not run
    }

    if (commandline.hasOption("version")) {
        System.out.println(APPNAME);
        return;
    }

    if (commandline.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("visolate [options] [filename]", options);
        return;
    }

    if (commandline.getArgs().length >= 2) {
        System.err.println("Error: Too many arguments.");
        System.exit(1);
    }

    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); //TODO: Make look and feel options
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (InstantiationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    final JFrame frame = new JFrame(APPNAME);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocation(DEF_LOC_X, DEF_LOC_Y);

    // Add the Enter key to the forward traversal keys, so fields loose focus
    // when using it in a field and we don't need to set up both, an ActionListener
    // and a FocusListener for each text/number field.
    Set<AWTKeyStroke> forwardKeys = new HashSet<AWTKeyStroke>(
            frame.getFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    Set<AWTKeyStroke> newForwardKeys = new HashSet<AWTKeyStroke>(forwardKeys);
    newForwardKeys.add(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));
    frame.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, newForwardKeys);

    final Visolate visolate = new Visolate();
    visolate.commandline = commandline;

    Container contentPane = frame.getContentPane();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(visolate, "Center");
    contentPane.setBackground(Color.WHITE);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {

            frame.pack();
            frame.setVisible(true);

            if (visolate.commandline.getArgs().length == 1) {
                visolate.loadFile(new File(visolate.commandline.getArgs()[0]));
            } else {
                visolate.loadDemo();
            }

            if (visolate.commandline.hasOption("auto")) {
                System.out.println("Automatic processing enabled! Files will be overwritten without asking!");
                visolate.auto_mode = true;
            }

            if (visolate.commandline.hasOption("dpi")) {
                visolate.getDisplay().setDPI(Integer.parseInt(visolate.commandline.getOptionValue("dpi")));
            }

            if (visolate.commandline.hasOption("flip-x")) {
                visolate.model.setFlipX(true);
            }
            if (visolate.commandline.hasOption("flip-y")) {
                visolate.model.setFlipY(true);
            }

            if (visolate.commandline.hasOption("absolute")) {
                visolate.setAbsoluteCoordinates(true);
            }

            if (visolate.commandline.hasOption("outfile")) {
                visolate.setGcodeFile(visolate.commandline.getOptionValue("outfile"));
            }

            if (visolate.commandline.hasOption("auto")) {
                System.out.println("now starting fixing topology due to automatic mode");
                visolate.processstatus = 1;

                visolate.fixTopology();
                // fix.Topology() calls visolate.processFinished after its done. Also, the Toolpathprocessor does so. processstatus discriminates this.
            }

            visolate.model.rebuild();
        }

    });
}