Example usage for java.awt Frame toFront

List of usage examples for java.awt Frame toFront

Introduction

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

Prototype

public void toFront() 

Source Link

Document

If this Window is visible, brings this Window to the front and may make it the focused Window.

Usage

From source file:ModalFrameUtil.java

public static void showAsModal(final Frame frame, final Frame owner) {
    frame.addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            owner.setEnabled(false);//from   w  w w.java 2 s.  co  m
        }

        public void windowClosing(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }

        public void windowClosed(WindowEvent e) {
            owner.setEnabled(true);
            frame.removeWindowListener(this);
        }
    });

    owner.addWindowListener(new WindowAdapter() {
        public void windowActivated(WindowEvent e) {
            if (frame.isShowing()) {
                frame.setExtendedState(JFrame.NORMAL);
                frame.toFront();
            } else {
                owner.removeWindowListener(this);
            }
        }
    });

    frame.setVisible(true);
    try {
        new EventPump(frame).start();
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

@Override
public void showingPane(boolean show) {
    //System.out.println("WBPane.showingPane(" + show + ") " + isVisible());
    if (formPane != null) {
        formPane.showingPane(show);//from  w  ww  .  j  av a2 s .  c  om
    }

    if (show) {
        UIRegistry.getLaunchFindReplaceAction().setSearchReplacePanel(findPanel);

        if (imageFrameWasShowing) {
            toggleImageFrameVisible();

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    final Frame f = (Frame) UIRegistry.get(UIRegistry.FRAME);
                    f.toFront();
                    f.requestFocus();
                }
            });
        }
    } else if (isVisible() == show /*fix for #9182*/) {
        checkCurrentEditState();

        if (imageFrame != null && imageFrame.isVisible()) {
            imageFrameWasShowing = true;
            toggleImageFrameVisible();
        } else {
            imageFrameWasShowing = false;
        }

        if (mapFrame != null && mapFrame.isVisible()) {
            mapFrame.setVisible(false);

        }
    }
    super.showingPane(show);
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Constructs the pane for the spreadsheet.
 * /*from  w  w w . j  a va 2s  . c o m*/
 * @param name the name of the pane
 * @param task the owning task
 * @param workbench the workbench to be edited
 * @param showImageView shows image window when first showing the window
 */
public WorkbenchPaneSS(final String name, final Taskable task, final Workbench workbenchArg,
        final boolean showImageView, final boolean isReadOnly) throws Exception {
    super(name, task);

    removeAll();

    if (workbenchArg == null) {
        return;
    }
    this.workbench = workbenchArg;

    this.isReadOnly = isReadOnly;

    headers.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    Collections.sort(headers);

    boolean hasOneOrMoreImages = false;
    // pre load all the data
    for (WorkbenchRow wbRow : workbench.getWorkbenchRows()) {
        for (WorkbenchDataItem wbdi : wbRow.getWorkbenchDataItems()) {
            wbdi.getCellData();
        }

        if (wbRow.getWorkbenchRowImages() != null && wbRow.getWorkbenchRowImages().size() > 0) {
            hasOneOrMoreImages = true;
        }
    }

    model = new GridTableModel(this);
    spreadSheet = new WorkbenchSpreadSheet(model, this);
    spreadSheet.setReadOnly(isReadOnly);
    model.setSpreadSheet(spreadSheet);

    Highlighter simpleStriping = HighlighterFactory.createSimpleStriping();
    GridCellHighlighter hl = new GridCellHighlighter(
            new GridCellPredicate(GridCellPredicate.AnyPredicate, null));
    Short[] errs = { WorkbenchDataItem.VAL_ERROR, WorkbenchDataItem.VAL_ERROR_EDIT };
    ColorHighlighter errColorHighlighter = new ColorHighlighter(
            new GridCellPredicate(GridCellPredicate.ValidationPredicate, errs),
            CellRenderingAttributes.errorBackground, null);
    Short[] newdata = { WorkbenchDataItem.VAL_NEW_DATA };
    ColorHighlighter noDataHighlighter = new ColorHighlighter(
            new GridCellPredicate(GridCellPredicate.MatchingPredicate, newdata),
            CellRenderingAttributes.newDataBackground, null);
    Short[] multimatch = { WorkbenchDataItem.VAL_MULTIPLE_MATCH };
    ColorHighlighter multiMatchHighlighter = new ColorHighlighter(
            new GridCellPredicate(GridCellPredicate.MatchingPredicate, multimatch),
            CellRenderingAttributes.multipleMatchBackground, null);

    spreadSheet.setHighlighters(simpleStriping, hl, errColorHighlighter, noDataHighlighter,
            multiMatchHighlighter);

    //add key mappings for cut, copy, paste
    //XXX Note: these are shortcuts directly to the SpreadSheet cut,copy,paste methods, NOT to the Specify edit menu.
    addRecordKeyMappings(spreadSheet, KeyEvent.VK_C, "Copy", new AbstractAction() {
        public void actionPerformed(ActionEvent ae) {
            SwingUtilities.invokeLater(new Runnable() {

                /* (non-Javadoc)
                 * @see java.lang.Runnable#run()
                 */
                @Override
                public void run() {
                    spreadSheet.cutOrCopy(false);
                }
            });
        }
    }, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    addRecordKeyMappings(spreadSheet, KeyEvent.VK_X, "Cut", new AbstractAction() {
        public void actionPerformed(ActionEvent ae) {
            SwingUtilities.invokeLater(new Runnable() {

                /* (non-Javadoc)
                 * @see java.lang.Runnable#run()
                 */
                @Override
                public void run() {
                    spreadSheet.cutOrCopy(true);
                }
            });
        }
    }, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    addRecordKeyMappings(spreadSheet, KeyEvent.VK_V, "Paste", new AbstractAction() {
        public void actionPerformed(ActionEvent ae) {
            SwingUtilities.invokeLater(new Runnable() {

                /* (non-Javadoc)
                 * @see java.lang.Runnable#run()
                 */
                @Override
                public void run() {
                    spreadSheet.paste();
                }
            });
        }
    }, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());

    findPanel = spreadSheet.getFindReplacePanel();
    UIRegistry.getLaunchFindReplaceAction().setSearchReplacePanel(findPanel);

    spreadSheet.setShowGrid(true);
    JTableHeader header = spreadSheet.getTableHeader();
    header.addMouseListener(new ColumnHeaderListener());
    header.setReorderingAllowed(false); // Turn Off column dragging

    // Put the model in image mode, and never change it.
    // Now we're showing/hiding the image column using JXTable's column hiding features.
    model.setInImageMode(true);
    int imageColIndex = model.getColumnCount() - 1;
    imageColExt = spreadSheet.getColumnExt(imageColIndex);
    imageColExt.setVisible(false);

    int sgrColIndex = model.getSgrHeading().getViewOrder();
    sgrColExt = spreadSheet.getColumnExt(sgrColIndex);
    sgrColExt.setComparator(((WorkbenchSpreadSheet) spreadSheet).new NumericColumnComparator());

    int cmpIdx = 0;
    for (Comparator<String> cmp : ((WorkbenchSpreadSheet) spreadSheet).getComparators()) {
        if (cmp != null) {
            spreadSheet.getColumnExt(cmpIdx++).setComparator(cmp);
        }
    }

    // Start off with the SGR score column hidden
    showHideSgrCol(false);

    model.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            setChanged(true);
        }
    });

    spreadSheet.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            UIRegistry.enableCutCopyPaste(true);
            UIRegistry.enableFind(findPanel, true);
        }

        @Override
        public void focusLost(FocusEvent e) {
            UIRegistry.enableCutCopyPaste(true);
            UIRegistry.enableFind(findPanel, true);
        }
    });

    if (isReadOnly) {
        saveBtn = null;
    } else {
        saveBtn = createButton(getResourceString("SAVE"));
        saveBtn.setToolTipText(
                String.format(getResourceString("WB_SAVE_DATASET_TT"), new Object[] { workbench.getName() }));
        saveBtn.setEnabled(false);
        saveBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                UsageTracker.incrUsageCount("WB.SaveDataSet");

                UIRegistry.writeSimpleGlassPaneMsg(
                        String.format(getResourceString("WB_SAVING"), new Object[] { workbench.getName() }),
                        WorkbenchTask.GLASSPANE_FONT_SIZE);
                UIRegistry.getStatusBar().setIndeterminate(workbench.getName(), true);
                final SwingWorker worker = new SwingWorker() {
                    @SuppressWarnings("synthetic-access")
                    @Override
                    public Object construct() {
                        try {
                            saveObject();

                        } catch (Exception ex) {
                            UsageTracker.incrHandledUsageCount();
                            edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(WorkbenchPaneSS.class,
                                    ex);
                            log.error(ex);
                            return ex;
                        }
                        return null;
                    }

                    // Runs on the event-dispatching thread.
                    @Override
                    public void finished() {
                        Object retVal = get();
                        if (retVal != null && retVal instanceof Exception) {
                            Exception ex = (Exception) retVal;
                            UIRegistry.getStatusBar().setErrorMessage(getResourceString("WB_ERROR_SAVING"), ex);
                        }

                        UIRegistry.clearSimpleGlassPaneMsg();
                        UIRegistry.getStatusBar().setProgressDone(workbench.getName());
                    }
                };
                worker.start();

            }
        });
    }

    Action delAction = addRecordKeyMappings(spreadSheet, KeyEvent.VK_F3, "DelRow", new AbstractAction() {
        public void actionPerformed(ActionEvent ae) {
            if (validationWorkerQueue.peek() == null) {
                deleteRows();
            }
        }
    }, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());

    if (isReadOnly) {
        deleteRowsBtn = null;
    } else {
        deleteRowsBtn = createIconBtn("DelRec", "WB_DELETE_ROW", delAction);
        selectionSensitiveButtons.add(deleteRowsBtn);
        spreadSheet.setDeleteAction(delAction);
    }

    //XXX Using the wb ID in the prefname to do pref setting per wb, may result in a bloated prefs file?? 
    doIncrementalValidation = AppPreferences.getLocalPrefs()
            .getBoolean(wbAutoValidatePrefName + "." + workbench.getId(), true);
    doIncrementalMatching = AppPreferences.getLocalPrefs()
            .getBoolean(wbAutoMatchPrefName + "." + workbench.getId(), false);

    if (isReadOnly) {
        clearCellsBtn = null;
    } else {
        clearCellsBtn = createIconBtn("Eraser", "WB_CLEAR_CELLS", new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                spreadSheet.clearSorter();

                if (spreadSheet.getCellEditor() != null) {
                    spreadSheet.getCellEditor().stopCellEditing();
                }
                int[] rows = spreadSheet.getSelectedRowModelIndexes();
                int[] cols = spreadSheet.getSelectedColumnModelIndexes();
                model.clearCells(rows, cols);
            }
        });
        selectionSensitiveButtons.add(clearCellsBtn);
    }

    Action addAction = addRecordKeyMappings(spreadSheet, KeyEvent.VK_N, "AddRow", new AbstractAction() {
        public void actionPerformed(ActionEvent ae) {
            if (workbench.getWorkbenchRows().size() < WorkbenchTask.MAX_ROWS) {
                if (validationWorkerQueue.peek() == null) {
                    addRowAfter();
                }
            }
        }
    }, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());

    if (isReadOnly) {
        addRowsBtn = null;
    } else {
        addRowsBtn = createIconBtn("AddRec", "WB_ADD_ROW", addAction);
        addRowsBtn.setEnabled(true);
        addAction.setEnabled(true);
    }

    if (isReadOnly) {
        carryForwardBtn = null;
    } else {
        carryForwardBtn = createIconBtn("CarryForward20x20", IconManager.IconSize.NonStd, "WB_CARRYFORWARD",
                false, new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        UsageTracker.getUsageCount("WBCarryForward");

                        configCarryFoward();
                    }
                });
        carryForwardBtn.setEnabled(true);
    }

    toggleImageFrameBtn = createIconBtn("CardImage", IconManager.IconSize.NonStd, "WB_SHOW_IMG_WIN", false,
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    toggleImageFrameVisible();
                }
            });
    toggleImageFrameBtn.setEnabled(true);

    importImagesBtn = createIconBtn("CardImage", IconManager.IconSize.NonStd, "WB_SHOW_IMG_WIN", false,
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    toggleImportImageFrameVisible();
                }
            });
    importImagesBtn.setEnabled(true);

    /*showMapBtn = createIconBtn("ShowMap", IconManager.IconSize.NonStd, "WB_SHOW_MAP", false, new ActionListener()
    {
    public void actionPerformed(ActionEvent ae)
    {
        showMapOfSelectedRecords();
    }
    });*/
    // enable or disable along with Google Earth and Geo Ref Convert buttons

    if (isReadOnly) {
        exportKmlBtn = null;
    } else {
        exportKmlBtn = createIconBtn("GoogleEarth", IconManager.IconSize.NonStd, "WB_SHOW_IN_GOOGLE_EARTH",
                false, new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        SwingUtilities.invokeLater(new Runnable() {
                            public void run() {
                                showRecordsInGoogleEarth();
                            }
                        });
                    }
                });
    }

    // 

    readRegisteries();

    // enable or disable along with Show Map and Geo Ref Convert buttons

    if (isReadOnly) {
        geoRefToolBtn = null;
    } else {
        AppPreferences remotePrefs = AppPreferences.getRemote();
        final String tool = remotePrefs.get("georef_tool", "geolocate");
        String iconName = "GEOLocate20"; //tool.equalsIgnoreCase("geolocate") ? "GeoLocate" : "BioGeoMancer";
        String toolTip = tool.equalsIgnoreCase("geolocate") ? "WB_DO_GEOLOCATE_LOOKUP"
                : "WB_DO_BIOGEOMANCER_LOOKUP";
        geoRefToolBtn = createIconBtn(iconName, IconManager.IconSize.NonStd, toolTip, false,
                new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        spreadSheet.clearSorter();

                        if (tool.equalsIgnoreCase("geolocate")) {
                            doGeoRef(new edu.ku.brc.services.geolocate.prototype.GeoCoordGeoLocateProvider(),
                                    "WB.GeoLocateRows");
                        } else {
                            doGeoRef(new GeoCoordBGMProvider(), "WB.BioGeomancerRows");
                        }
                    }
                });
        // only enable it if the workbench has the proper columns in it
        String[] missingColumnsForBG = getMissingButRequiredColumnsForGeoRefTool(tool);
        if (missingColumnsForBG.length > 0) {
            geoRefToolBtn.setEnabled(false);
            String ttText = "<p>" + getResourceString("WB_ADDITIONAL_FIELDS_REQD") + ":<ul>";
            for (String reqdField : missingColumnsForBG) {
                ttText += "<li>" + reqdField + "</li>";
            }
            ttText += "</ul>";
            String origTT = geoRefToolBtn.getToolTipText();
            geoRefToolBtn.setToolTipText("<html>" + origTT + ttText);
        } else {
            geoRefToolBtn.setEnabled(true);
        }
    }

    if (isReadOnly) {
        convertGeoRefFormatBtn = null;
    } else {
        convertGeoRefFormatBtn = createIconBtn("ConvertGeoRef", IconManager.IconSize.NonStd,
                "WB_CONVERT_GEO_FORMAT", false, new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        showGeoRefConvertDialog();
                    }
                });

        // now enable/disable the geo ref related buttons
        String[] missingGeoRefFields = getMissingGeoRefLatLonFields();
        if (missingGeoRefFields.length > 0) {
            convertGeoRefFormatBtn.setEnabled(false);
            exportKmlBtn.setEnabled(false);
            //showMapBtn.setEnabled(false);

            String ttText = "<p>" + getResourceString("WB_ADDITIONAL_FIELDS_REQD") + ":<ul>";
            for (String reqdField : missingGeoRefFields) {
                ttText += "<li>" + reqdField + "</li>";
            }
            ttText += "</ul>";
            String origTT1 = convertGeoRefFormatBtn.getToolTipText();
            convertGeoRefFormatBtn.setToolTipText("<html>" + origTT1 + ttText);
            String origTT2 = exportKmlBtn.getToolTipText();
            exportKmlBtn.setToolTipText("<html>" + origTT2 + ttText);
            //String origTT3 = showMapBtn.getToolTipText();
            //showMapBtn.setToolTipText("<html>" + origTT3 + ttText);
        } else {
            convertGeoRefFormatBtn.setEnabled(true);
            exportKmlBtn.setEnabled(true);
            //showMapBtn.setEnabled(true);
        }
    }

    if (AppContextMgr.isSecurityOn() && !task.getPermissions().canModify()) {
        exportExcelCsvBtn = null;
    } else {
        exportExcelCsvBtn = createIconBtn("Export", IconManager.IconSize.NonStd, "WB_EXPORT_DATA", false,
                new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        doExcelCsvExport();
                    }
                });
        exportExcelCsvBtn.setEnabled(true);
    }

    uploadDatasetBtn = createIconBtn("Upload", IconManager.IconSize.Std24, "WB_UPLOAD_DATA", false,
            new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    doDatasetUpload();
                }
            });
    uploadDatasetBtn.setVisible(isUploadPermitted() && !UIRegistry.isMobile());
    uploadDatasetBtn.setEnabled(canUpload());
    if (!uploadDatasetBtn.isEnabled()) {
        uploadDatasetBtn.setToolTipText(getResourceString("WB_UPLOAD_IN_PROGRESS"));
    }

    // listen to selection changes to enable/disable certain buttons
    spreadSheet.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                JStatusBar statusBar = UIRegistry.getStatusBar();
                statusBar.setText("");

                currentRow = spreadSheet.getSelectedRow();
                updateBtnUI();
            }
        }
    });

    for (int c = 0; c < spreadSheet.getTableHeader().getColumnModel().getColumnCount(); c++) {
        // TableColumn column =
        // spreadSheet.getTableHeader().getColumnModel().getColumn(spreadSheet.getTableHeader().getColumnModel().getColumnCount()-1);
        TableColumn column = spreadSheet.getTableHeader().getColumnModel().getColumn(c);
        column.setCellRenderer(new WbCellRenderer());
    }

    // setup the JFrame to show images attached to WorkbenchRows
    imageFrame = new ImageFrame(mapSize, this, this.workbench, task, isReadOnly);

    // setup the JFrame to show images attached to WorkbenchRows
    imageImportFrame = new ImageImportFrame(this, this.workbench);

    setupWorkbenchRowChangeListener();

    // setup window minimizing/maximizing listener
    JFrame topFrame = (JFrame) UIRegistry.getTopWindow();
    minMaxWindowListener = new WindowAdapter() {
        @Override
        public void windowDeiconified(WindowEvent e) {
            if (imageFrame != null && imageFrame.isVisible()) {
                imageFrame.setExtendedState(Frame.NORMAL);
            }
            if (mapFrame != null && mapFrame.isVisible()) {
                mapFrame.setExtendedState(Frame.NORMAL);
            }
        }

        @Override
        public void windowIconified(WindowEvent e) {
            if (imageFrame != null && imageFrame.isVisible()) {
                imageFrame.setExtendedState(Frame.ICONIFIED);
            }
            if (mapFrame != null && mapFrame.isVisible()) {
                mapFrame.setExtendedState(Frame.ICONIFIED);
            }
        }
    };
    topFrame.addWindowListener(minMaxWindowListener);

    if (!isReadOnly) {
        showHideUploadToolBtn = createIconBtn("ValidateWB", IconManager.IconSize.NonStd,
                "WB_HIDE_UPLOADTOOLPANEL", false, new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        if (uploadToolPanel.isExpanded()) {
                            hideUploadToolPanel();
                            showHideUploadToolBtn.setToolTipText(getResourceString("WB_SHOW_UPLOADTOOLPANEL"));
                        } else {
                            showUploadToolPanel();
                            showHideUploadToolBtn.setToolTipText(getResourceString("WB_HIDE_UPLOADTOOLPANEL"));
                        }
                    }
                });
        showHideUploadToolBtn.setEnabled(true);
    }

    // setup the mapping features
    mapFrame = new JFrame();
    mapFrame.setIconImage(IconManager.getImage("AppIcon").getImage());
    mapFrame.setTitle(getResourceString("WB_GEO_REF_DATA_MAP"));
    mapImageLabel = createLabel("");
    mapImageLabel.setSize(500, 500);
    mapFrame.add(mapImageLabel);
    mapFrame.setSize(500, 500);

    // start putting together the visible UI
    CellConstraints cc = new CellConstraints();

    JComponent[] compsArray = { addRowsBtn, deleteRowsBtn, clearCellsBtn, /*showMapBtn,*/ exportKmlBtn,
            geoRefToolBtn, convertGeoRefFormatBtn, exportExcelCsvBtn, uploadDatasetBtn, showHideUploadToolBtn };
    Vector<JComponent> availableComps = new Vector<JComponent>(
            compsArray.length + workBenchPluginSSBtns.size());
    for (JComponent c : compsArray) {
        if (c != null) {
            availableComps.add(c);
        }
    }
    for (JComponent c : workBenchPluginSSBtns) {
        availableComps.add(c);
    }

    PanelBuilder spreadSheetControlBar = new PanelBuilder(new FormLayout(
            "f:p:g,4px," + createDuplicateJGoodiesDef("p", "4px", availableComps.size()) + ",4px,", "c:p:g"));

    int x = 3;
    for (JComponent c : availableComps) {
        spreadSheetControlBar.add(c, cc.xy(x, 1));
        x += 2;
    }

    int h = 0;
    Vector<WorkbenchTemplateMappingItem> headers = new Vector<WorkbenchTemplateMappingItem>();
    headers.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    Collections.sort(headers);
    for (WorkbenchTemplateMappingItem mi : headers) {
        //using the workbench data model table. Not the actual specify table the column is mapped to.
        //This MIGHT be less confusing
        //System.out.println("setting header renderer for " + mi.getTableName() + "." + mi.getFieldName()); 
        spreadSheet.getColumnModel().getColumn(h++)
                .setHeaderRenderer(new WbTableHeaderRenderer(mi.getTableName()));
    }

    // NOTE: This needs to be done after the creation of the saveBtn. And after the creation of the header renderes.
    initColumnSizes(spreadSheet, saveBtn);

    // Create the Form Pane  -- needs to be done after initColumnSizes - which also sets cell editors for collumns
    if (task instanceof SGRTask) {
        formPane = new SGRFormPane(this, workbench, isReadOnly);
    } else {
        formPane = new FormPane(this, workbench, isReadOnly);
    }

    // This panel contains just the ResultSetContoller, it's needed so the RSC gets centered
    PanelBuilder rsPanel = new PanelBuilder(new FormLayout("c:p:g", "c:p:g"));
    FormValidator dummy = new FormValidator(null);
    dummy.setEnabled(true);
    resultsetController = new ResultSetController(dummy, !isReadOnly, !isReadOnly, false,
            getResourceString("Record"), model.getRowCount(), true);
    resultsetController.addListener(formPane);
    if (!isReadOnly) {
        resultsetController.getDelRecBtn().addActionListener(delAction);
    }
    //        else
    //        {
    //            resultsetController.getDelRecBtn().setVisible(false);
    //        }
    rsPanel.add(resultsetController.getPanel(), cc.xy(1, 1));

    // This panel is a single row containing the ResultSetContoller and the other controls for the Form Panel
    String colspec = "f:p:g, p, f:p:g, p";
    for (int i = 0; i < workBenchPluginFormBtns.size(); i++) {
        colspec = colspec + ", f:p, p";
    }

    PanelBuilder resultSetPanel = new PanelBuilder(new FormLayout(colspec, "c:p:g"));
    // Now put the two panel into the single row panel
    resultSetPanel.add(rsPanel.getPanel(), cc.xy(2, 1));
    if (!isReadOnly) {
        resultSetPanel.add(formPane.getControlPropsBtn(), cc.xy(4, 1));
    }
    int ccx = 6;
    for (JComponent c : workBenchPluginFormBtns) {
        resultSetPanel.add(c, cc.xy(ccx, 1));
        ccx += 2;
    }

    // Create the main panel that uses card layout for the form and spreasheet
    mainPanel = new JPanel(cardLayout = new CardLayout());

    // Add the Form and Spreadsheet to the CardLayout
    mainPanel.add(spreadSheet.getScrollPane(), PanelType.Spreadsheet.toString());
    mainPanel.add(formPane.getPane(), PanelType.Form.toString());

    // The controllerPane is a CardLayout that switches between the Spreadsheet control bar and the Form Control Bar
    controllerPane = new JPanel(cpCardLayout = new CardLayout());
    controllerPane.add(spreadSheetControlBar.getPanel(), PanelType.Spreadsheet.toString());
    controllerPane.add(resultSetPanel.getPanel(), PanelType.Form.toString());

    JLabel sep1 = new JLabel(IconManager.getIcon("Separator"));
    JLabel sep2 = new JLabel(IconManager.getIcon("Separator"));
    ssFormSwitcher = createSwitcher();

    // This works
    setLayout(new BorderLayout());

    boolean doDnDImages = AppPreferences.getLocalPrefs().getBoolean("WB_DND_IMAGES", false);
    JComponent[] ctrlCompArray1 = { importImagesBtn, toggleImageFrameBtn, carryForwardBtn, sep1, saveBtn, sep2,
            ssFormSwitcher };
    JComponent[] ctrlCompArray2 = { toggleImageFrameBtn, carryForwardBtn, sep1, saveBtn, sep2, ssFormSwitcher };
    JComponent[] ctrlCompArray = doDnDImages ? ctrlCompArray1 : ctrlCompArray2;

    Vector<Pair<JComponent, Integer>> ctrlComps = new Vector<Pair<JComponent, Integer>>();
    for (JComponent c : ctrlCompArray) {
        ctrlComps.add(new Pair<JComponent, Integer>(c, null));
    }

    String layoutStr = "";
    int compCount = 0;
    int col = 1;
    int pos = 0;
    for (Pair<JComponent, Integer> c : ctrlComps) {
        JComponent comp = c.getFirst();
        if (comp != null) {
            boolean addComp = !(comp == sep1 || comp == sep2) || compCount > 0;
            if (!addComp) {
                c.setFirst(null);
            } else {
                if (!StringUtils.isEmpty(layoutStr)) {
                    layoutStr += ",";
                    col++;
                    if (pos < ctrlComps.size() - 1) {
                        //this works because we know ssFormSwitcher is last and always non-null.
                        layoutStr += "6px,";
                        col++;
                    }
                }
                c.setSecond(col);
                if (comp == sep1 || comp == sep2) {
                    layoutStr += "6px";
                    compCount = 0;
                } else {
                    layoutStr += "p";
                    compCount++;
                }
            }
        }
        pos++;
    }
    PanelBuilder ctrlBtns = new PanelBuilder(new FormLayout(layoutStr, "c:p:g"));
    for (Pair<JComponent, Integer> c : ctrlComps) {
        if (c.getFirst() != null) {
            ctrlBtns.add(c.getFirst(), cc.xy(c.getSecond(), 1));
        }
    }

    add(mainPanel, BorderLayout.CENTER);

    FormLayout formLayout = new FormLayout("f:p:g,4px,p", "2px,f:p:g,p:g,p:g");
    PanelBuilder builder = new PanelBuilder(formLayout);

    builder.add(controllerPane, cc.xy(1, 2));
    builder.add(ctrlBtns.getPanel(), cc.xy(3, 2));

    if (!isReadOnly) {
        uploadToolPanel = new UploadToolPanel(this, UploadToolPanel.EXPANDED);
        uploadToolPanel.createUI();
        //            showHideUploadToolBtn = createIconBtn("ValidateWB", IconManager.IconSize.NonStd, "WB_HIDE_UPLOADTOOLPANEL", false, new ActionListener()
        //            {
        //                public void actionPerformed(ActionEvent ae)
        //                {
        //                    if (uploadToolPanel.isExpanded())
        //                    {
        //                       hideUploadToolPanel();
        //                       showHideUploadToolBtn.setToolTipText(getResourceString("WB_SHOW_UPLOADTOOLPANEL"));
        //                    } else
        //                    {
        //                       showUploadToolPanel();
        //                       showHideUploadToolBtn.setToolTipText(getResourceString("WB_HIDE_UPLOADTOOLPANEL"));
        //                   }
        //                }
        //            });
        //            showHideUploadToolBtn.setEnabled(true);
    }

    builder.add(uploadToolPanel, cc.xywh(1, 3, 3, 1));
    builder.add(findPanel, cc.xywh(1, 4, 3, 1));

    add(builder.getPanel(), BorderLayout.SOUTH);

    resultsetController.addListener(new ResultSetControllerListener() {
        public boolean indexAboutToChange(int oldIndex, int newIndex) {
            return true;
        }

        public void indexChanged(int newIndex) {
            if (imageFrame != null) {
                if (newIndex > -1) {
                    int index = spreadSheet.convertRowIndexToModel(newIndex);
                    imageFrame.setRow(workbench.getRow(index));
                } else {
                    imageFrame.setRow(null);
                }
            }
        }

        public void newRecordAdded() {
            // do nothing
        }
    });
    //compareSchemas();
    if (getIncremental() && workbenchValidator == null) {
        buildValidator();
    }

    //        int c = 0;
    //        Vector<WorkbenchTemplateMappingItem> headers = new Vector<WorkbenchTemplateMappingItem>();
    //        headers.addAll(workbench.getWorkbenchTemplate().getWorkbenchTemplateMappingItems());
    //        Collections.sort(headers);
    //        for (WorkbenchTemplateMappingItem mi : headers)
    //        {
    //           //using the workbench data model table. Not the actual specify table the column is mapped to.
    //           //This MIGHT be less confusing
    //           //System.out.println("setting header renderer for " + mi.getTableName() + "." + mi.getFieldName()); 
    //           spreadSheet.getColumnModel().getColumn(c++).setHeaderRenderer(new WbTableHeaderRenderer(mi.getTableName()));
    //        }
    //        
    //        // NOTE: This needs to be done after the creation of the saveBtn. And after the creation of the header renderes.
    //        initColumnSizes(spreadSheet, saveBtn);

    // See if we need to make the Image Frame visible
    // Commenting this out for now because it is so annoying.

    if (showImageView || hasOneOrMoreImages) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                toggleImageFrameVisible();

                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        final Frame f = (Frame) UIRegistry.get(UIRegistry.FRAME);
                        f.toFront();
                        f.requestFocus();
                    }
                });
            }
        });
    }

    ((WorkbenchTask) ContextMgr.getTaskByClass(WorkbenchTask.class)).opening(this);
    ((SGRTask) ContextMgr.getTaskByClass(SGRTask.class)).opening(this);
}

From source file:org.paxle.desktop.impl.DialogueServices.java

private static void show(final Frame frame) {
    final int extstate = frame.getExtendedState();
    if ((extstate & Frame.ICONIFIED) == Frame.ICONIFIED)
        frame.setExtendedState(extstate ^ Frame.ICONIFIED);
    if (!frame.isVisible())
        frame.setVisible(true);/*from   w  w w  .j  a v a 2s .c o  m*/
    frame.toFront();
}