Example usage for java.awt GridBagConstraints CENTER

List of usage examples for java.awt GridBagConstraints CENTER

Introduction

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

Prototype

int CENTER

To view the source code for java.awt GridBagConstraints CENTER.

Click Source Link

Document

Put the component in the center of its display area.

Usage

From source file:junk.gui.HazardDataSetCalcCondorApp.java

/**
 * Initialise the IMT gui Bean/*  w ww. j av a  2s.  co  m*/
 */
private void initIMTGuiBean() {
    // get the selected IMR
    attenRel = (AttenuationRelationship) imrGuiBean.getSelectedIMR_Instance();
    /**
     * Initialize the IMT Gui Bean
     */

    // create the IMT Gui Bean object
    imtGuiBean = new IMT_GuiBean(attenRel, attenRel.getSupportedIntensityMeasuresIterator());

    imtPanel.add(imtGuiBean, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, defaultInsets, 0, 0));
}

From source file:org.jets3t.apps.cockpitlite.CockpitLite.java

/**
 * Initialises the application's GUI elements.
 */// w w w  .ja  v  a2s .c  o  m
private void initGui() {
    // Initialise skins factory.
    skinsFactory = SkinsFactory.getInstance(cockpitLiteProperties.getProperties());

    // Set Skinned Look and Feel.
    LookAndFeel lookAndFeel = skinsFactory.createSkinnedMetalTheme("SkinnedLookAndFeel");
    try {
        UIManager.setLookAndFeel(lookAndFeel);
    } catch (UnsupportedLookAndFeelException e) {
        log.error("Unable to set skinned LookAndFeel", e);
    }

    // Primary panel that contains all other items.
    JPanel primaryPanel = skinsFactory.createSkinnedJPanel("PrimaryPanel");
    primaryPanel.setLayout(new GridBagLayout());
    this.getContentPane().add(primaryPanel);

    // Setup the stack panel, which contains all other panels as a stack.
    stackPanel = skinsFactory.createSkinnedJPanel("StackPanel");
    stackPanelCardLayout = new CardLayout();
    stackPanel.setLayout(stackPanelCardLayout);
    primaryPanel.add(stackPanel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsZero, 0, 0));

    // Progress notification panel
    progressNotificationPanel = skinsFactory.createSkinnedJPanel("ProgressNotificationPanel");
    progressNotificationPanel.setLayout(new GridBagLayout());
    primaryPanel.add(progressNotificationPanel, new GridBagConstraints(0, 1, 1, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 0, 5, 0), 0, 0));

    int row = 0;

    // Login panel.
    row = 0;
    loginPanel = skinsFactory.createSkinnedJPanel("LoginPanel");
    loginPanel.setLayout(new GridBagLayout());

    userInputFields = new UserInputFields(insetsDefault, null, skinsFactory);
    userInputFields.buildFieldsPanel(loginPanel, cockpitLiteProperties);

    loginButton = skinsFactory.createSkinnedJButton("LoginButton");
    loginButton.setText("Log me in");
    loginButton.addActionListener(this);
    loginPanel.add(loginButton, new GridBagConstraints(0, loginPanel.getComponentCount(), 1, 1, 0, 0,
            GridBagConstraints.CENTER, GridBagConstraints.NONE, insetsDefault, 0, 0));

    // Filter panel.
    filterObjectsPanel = skinsFactory.createSkinnedJPanel("FilterPanel");
    filterObjectsPanel.setLayout(new GridBagLayout());
    filterObjectsPrefix = skinsFactory.createSkinnedJTextField("FilterPrefix");
    filterObjectsPrefix.setToolTipText("Only show files starting with this string");
    filterObjectsPrefix.addActionListener(this);
    filterObjectsPrefix.setActionCommand("RefreshObjects");
    JLabel filterPrefixLabel = skinsFactory.createSkinnedJHtmlLabel("FilterPrefixLable", this);
    filterPrefixLabel.setText("File name starts with: ");
    filterObjectsPanel.add(filterPrefixLabel, new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.add(filterObjectsPrefix, new GridBagConstraints(1, 0, 1, 1, 1, 0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    filterObjectsPanel.setVisible(false);

    // Objects panel.
    row = 0;
    JPanel objectsPanel = skinsFactory.createSkinnedJPanel("ObjectsPanel");
    objectsPanel.setLayout(new GridBagLayout());
    filterObjectsCheckBox = skinsFactory.createSkinnedJCheckBox("FilterCheckbox");
    filterObjectsCheckBox.setText("Search files");
    filterObjectsCheckBox.setEnabled(true);
    filterObjectsCheckBox.addActionListener(this);
    filterObjectsCheckBox.setToolTipText("Check this option to search your files");
    objectsHeadingLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectsHeadingLabel", this);
    objectsHeadingLabel.setText("Not logged in");
    objectsPanel.add(objectsHeadingLabel, new GridBagConstraints(0, row, 1, 1, 1, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    objectsPanel.add(filterObjectsCheckBox, new GridBagConstraints(1, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    JButton objectActionButton = skinsFactory.createSkinnedJButton("ObjectMenuButton");
    objectActionButton.setToolTipText("File actions menu");
    guiUtils.applyIcon(objectActionButton, "/images/nuvola/16x16/actions/misc.png");
    objectActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            objectActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    objectsPanel.add(objectActionButton, new GridBagConstraints(2, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsPanel.add(filterObjectsPanel, new GridBagConstraints(0, ++row, 3, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsTable = skinsFactory.createSkinnedJTable("ObjectsTable");
    objectTableModel = new CLObjectTableModel();
    objectTableModelSorter = new TableSorter(objectTableModel);
    objectTableModelSorter.setTableHeader(objectsTable.getTableHeader());
    objectsTable.setModel(objectTableModelSorter);
    objectsTable.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 7229656175879985698L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            String formattedSize = byteFormatter.formatByteSize(((Long) value).longValue());
            return super.getTableCellRendererComponent(table, formattedSize, isSelected, hasFocus, row, column);
        }
    });
    objectsTable.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = -4983176028291916397L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Date date = (Date) value;
            return super.getTableCellRendererComponent(table, yearAndTimeSDF.format(date), isSelected, hasFocus,
                    row, column);
        }
    });
    objectsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    objectsTable.getSelectionModel().addListSelectionListener(this);
    objectsTable.setShowHorizontalLines(true);
    objectsTable.setShowVerticalLines(true);
    objectsTable.addMouseListener(new ContextMenuListener());
    objectsTableSP = skinsFactory.createSkinnedJScrollPane("ObjectsTableSP", objectsTable);
    objectsPanel.add(objectsTableSP, new GridBagConstraints(0, ++row, 3, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsZero, 0, 0));
    objectsSummaryLabel = skinsFactory.createSkinnedJHtmlLabel("ObjectsSummary", this);
    objectsSummaryLabel.setHorizontalAlignment(JLabel.CENTER);
    objectsSummaryLabel.setFocusable(false);
    objectsPanel.add(objectsSummaryLabel, new GridBagConstraints(0, ++row, 3, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    // Object action menu.
    objectActionMenu = skinsFactory.createSkinnedJPopupMenu("ObjectPopupMenu");

    refreshObjectMenuItem = skinsFactory.createSkinnedJMenuItem("RefreshMenuItem");
    refreshObjectMenuItem.setText("Refresh file listing");
    refreshObjectMenuItem.setActionCommand("RefreshObjects");
    refreshObjectMenuItem.addActionListener(this);
    guiUtils.applyIcon(refreshObjectMenuItem, "/images/nuvola/16x16/actions/reload.png");
    objectActionMenu.add(refreshObjectMenuItem);

    viewObjectPropertiesMenuItem = skinsFactory.createSkinnedJMenuItem("PropertiesMenuItem");
    viewObjectPropertiesMenuItem.setText("View file properties...");
    viewObjectPropertiesMenuItem.setActionCommand("ViewObjectProperties");
    viewObjectPropertiesMenuItem.addActionListener(this);
    guiUtils.applyIcon(viewObjectPropertiesMenuItem, "/images/nuvola/16x16/actions/viewmag.png");
    objectActionMenu.add(viewObjectPropertiesMenuItem);

    downloadObjectMenuItem = skinsFactory.createSkinnedJMenuItem("DownloadMenuItem");
    downloadObjectMenuItem.setText("Download file(s)...");
    downloadObjectMenuItem.setActionCommand("DownloadObjects");
    downloadObjectMenuItem.addActionListener(this);
    guiUtils.applyIcon(downloadObjectMenuItem, "/images/nuvola/16x16/actions/1downarrow.png");
    objectActionMenu.add(downloadObjectMenuItem);

    uploadFilesMenuItem = skinsFactory.createSkinnedJMenuItem("UploadMenuItem");
    uploadFilesMenuItem.setText("Upload file(s)...");
    uploadFilesMenuItem.setActionCommand("UploadFiles");
    uploadFilesMenuItem.addActionListener(this);
    guiUtils.applyIcon(uploadFilesMenuItem, "/images/nuvola/16x16/actions/1uparrow.png");
    objectActionMenu.add(uploadFilesMenuItem);

    objectActionMenu.add(new JSeparator());

    togglePublicMenuItem = skinsFactory.createSkinnedJMenuItem("AclToggleMenuItem");
    togglePublicMenuItem.setText("Change privacy setting...");
    togglePublicMenuItem.setActionCommand("TogglePublicPrivate");
    togglePublicMenuItem.addActionListener(this);
    guiUtils.applyIcon(togglePublicMenuItem, "/images/nuvola/16x16/actions/encrypted.png");
    objectActionMenu.add(togglePublicMenuItem);

    generatePublicGetUrl = skinsFactory.createSkinnedJMenuItem("PublicUrlMenuItem");
    generatePublicGetUrl.setText("Public web link...");
    generatePublicGetUrl.setActionCommand("GeneratePublicGetURL");
    generatePublicGetUrl.addActionListener(this);
    guiUtils.applyIcon(generatePublicGetUrl, "/images/nuvola/16x16/actions/wizard.png");
    objectActionMenu.add(generatePublicGetUrl);

    objectActionMenu.add(new JSeparator());

    deleteObjectMenuItem = skinsFactory.createSkinnedJMenuItem("DeleteMenuItem");
    deleteObjectMenuItem.setText("Delete file(s)...");
    deleteObjectMenuItem.setActionCommand("DeleteObjects");
    deleteObjectMenuItem.addActionListener(this);
    guiUtils.applyIcon(deleteObjectMenuItem, "/images/nuvola/16x16/actions/cancel.png");
    objectActionMenu.add(deleteObjectMenuItem);

    viewObjectPropertiesMenuItem.setEnabled(false);
    refreshObjectMenuItem.setEnabled(false);
    togglePublicMenuItem.setEnabled(false);
    downloadObjectMenuItem.setEnabled(false);
    generatePublicGetUrl.setEnabled(false);
    deleteObjectMenuItem.setEnabled(false);

    // Card layout in stack panel
    stackPanel.add(loginPanel, "LoginPanel");
    stackPanel.add(objectsPanel, "ObjectsPanel");

    // Set preferred sizes
    int preferredWidth = 800;
    int preferredHeight = 600;
    this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight)));

    // Initialize drop target.
    initDropTarget(new JComponent[] { objectsPanel });
    objectsPanel.getDropTarget().setActive(true);
}

From source file:org.esa.beam.visat.toolviews.spectrum.SpectrumToolView.java

@Override
public JComponent createControl() {
    final JFreeChart chart = ChartFactory.createXYLineChart(CHART_TITLE, "Wavelength (nm)", "", null,
            PlotOrientation.VERTICAL, true, true, false);
    chart.getXYPlot().getRangeAxis().addChangeListener(new AxisChangeListener() {
        @Override/*from  w  w  w.  j a  v a 2 s. com*/
        public void axisChanged(AxisChangeEvent axisChangeEvent) {
            if (!isCodeInducedAxisChange) {
                rangeAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange();
            }
        }
    });
    chart.getXYPlot().getDomainAxis().addChangeListener(new AxisChangeListener() {
        @Override
        public void axisChanged(AxisChangeEvent axisChangeEvent) {
            if (!isCodeInducedAxisChange) {
                domainAxisAdjustmentIsFrozen = !((ValueAxis) axisChangeEvent.getAxis()).isAutoRange();
            }
        }
    });
    chart.getXYPlot().getRangeAxis().setAutoRange(false);
    rangeAxisAdjustmentIsFrozen = false;
    chart.getXYPlot().getDomainAxis().setAutoRange(false);
    domainAxisAdjustmentIsFrozen = false;
    chartPanel = new ChartPanel(chart);
    chartHandler = new ChartHandler(chart);
    final XYPlotMarker plotMarker = new XYPlotMarker(chartPanel, new XYPlotMarker.Listener() {
        @Override
        public void pointSelected(XYDataset xyDataset, int seriesIndex, Point2D dataPoint) {
            if (hasDiagram()) {
                if (cursorSynchronizer == null) {
                    cursorSynchronizer = new CursorSynchronizer(VisatApp.getApp());
                }
                if (!cursorSynchronizer.isEnabled()) {
                    cursorSynchronizer.setEnabled(true);
                }
            }
        }

        @Override
        public void pointDeselected() {
            cursorSynchronizer.setEnabled(false);
        }
    });

    titleBase = getDescriptor().getTitle();
    filterButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Filter24.gif"), false);
    filterButton.setName("filterButton");
    filterButton.setEnabled(false);
    filterButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            selectSpectralBands();
            recreateChart();
        }
    });

    showSpectrumForCursorButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/CursorSpectrum24.gif"), true);
    showSpectrumForCursorButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            recreateChart();
        }
    });
    showSpectrumForCursorButton.setName("showSpectrumForCursorButton");
    showSpectrumForCursorButton.setSelected(true);
    showSpectrumForCursorButton.setToolTipText("Show spectrum at cursor position.");

    showSpectraForSelectedPinsButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/SelectedPinSpectra24.gif"), true);
    showSpectraForSelectedPinsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isShowingSpectraForAllPins()) {
                showSpectraForAllPinsButton.setSelected(false);
            } else if (!isShowingSpectraForSelectedPins()) {
                plotMarker.setInvisible();
            }
            recreateChart();
        }
    });
    showSpectraForSelectedPinsButton.setName("showSpectraForSelectedPinsButton");
    showSpectraForSelectedPinsButton.setToolTipText("Show spectra for selected pins.");

    showSpectraForAllPinsButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/PinSpectra24.gif"), true);
    showSpectraForAllPinsButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (isShowingSpectraForSelectedPins()) {
                showSpectraForSelectedPinsButton.setSelected(false);
            } else if (!isShowingSpectraForAllPins()) {
                plotMarker.setInvisible();
            }
            recreateChart();
        }
    });
    showSpectraForAllPinsButton.setName("showSpectraForAllPinsButton");
    showSpectraForAllPinsButton.setToolTipText("Show spectra for all pins.");

    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        showAveragePinSpectrumButton = ToolButtonFactory.createButton(
    //                UIUtils.loadImageIcon("icons/AverageSpectrum24.gif"), true);
    //        showAveragePinSpectrumButton.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                // todo - implement
    //            }
    //        });
    //        showAveragePinSpectrumButton.setName("showAveragePinSpectrumButton");
    //        showAveragePinSpectrumButton.setToolTipText("Show average spectrum of all pin spectra.");

    showGridButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/SpectrumGrid24.gif"), true);
    showGridButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            chartHandler.setGridVisible(showGridButton.isSelected());
        }
    });
    showGridButton.setName("showGridButton");
    showGridButton.setToolTipText("Show diagram grid.");

    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        showGraphPointsButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/GraphPoints24.gif"), true);
    //        showGraphPointsButton.addActionListener(new ActionListener() {
    //            public void actionPerformed(ActionEvent e) {
    //                // todo - implement
    //                JOptionPane.showMessageDialog(null, "Not implemented");
    //            }
    //        });
    //        showGraphPointsButton.setName("showGraphPointsButton");
    //        showGraphPointsButton.setToolTipText("Show graph points grid.");

    AbstractButton exportSpectraButton = ToolButtonFactory
            .createButton(UIUtils.loadImageIcon("icons/Export24.gif"), false);
    exportSpectraButton.addActionListener(new SpectraExportAction(this));
    exportSpectraButton.setToolTipText("Export spectra to text file.");
    exportSpectraButton.setName("exportSpectraButton");

    AbstractButton helpButton = ToolButtonFactory.createButton(UIUtils.loadImageIcon("icons/Help22.png"),
            false);
    helpButton.setName("helpButton");
    helpButton.setToolTipText("Help."); /*I18N*/

    final JPanel buttonPane = GridBagUtils.createPanel();
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.fill = GridBagConstraints.NONE;
    gbc.insets.top = 2;
    gbc.gridy = 0;
    buttonPane.add(filterButton, gbc);
    gbc.gridy++;
    buttonPane.add(showSpectrumForCursorButton, gbc);
    gbc.gridy++;
    buttonPane.add(showSpectraForSelectedPinsButton, gbc);
    gbc.gridy++;
    buttonPane.add(showSpectraForAllPinsButton, gbc);
    gbc.gridy++;
    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        buttonPane.add(showAveragePinSpectrumButton, gbc);
    //        gbc.gridy++;
    buttonPane.add(showGridButton, gbc);
    gbc.gridy++;
    // todo - not yet implemented for 4.1 but planned for 4.2 (mp - 31.10.2007)
    //        buttonPane.add(showGraphPointsButton, gbc);
    //        gbc.gridy++;
    buttonPane.add(exportSpectraButton, gbc);

    gbc.gridy++;
    gbc.insets.bottom = 0;
    gbc.fill = GridBagConstraints.VERTICAL;
    gbc.weighty = 1.0;
    gbc.gridwidth = 2;
    buttonPane.add(new JLabel(" "), gbc); // filler
    gbc.fill = GridBagConstraints.NONE;
    gbc.weighty = 0.0;
    gbc.gridy = 10;
    gbc.anchor = GridBagConstraints.EAST;
    buttonPane.add(helpButton, gbc);

    chartPanel.setPreferredSize(new Dimension(300, 200));
    chartPanel.setBackground(Color.white);
    chartPanel.setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createBevelBorder(BevelBorder.LOWERED), BorderFactory.createEmptyBorder(2, 2, 2, 2)));
    chartPanel.addChartMouseListener(plotMarker);

    JPanel mainPane = new JPanel(new BorderLayout(4, 4));
    mainPane.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    mainPane.add(BorderLayout.CENTER, chartPanel);
    mainPane.add(BorderLayout.EAST, buttonPane);
    mainPane.setPreferredSize(new Dimension(320, 200));

    if (getDescriptor().getHelpId() != null) {
        HelpSys.enableHelpOnButton(helpButton, getDescriptor().getHelpId());
        HelpSys.enableHelpKey(mainPane, getDescriptor().getHelpId());
    }

    // Add an internal frame listener to VISAT so that we can update our
    // spectrum dialog with the information of the currently activated
    // product scene view.
    //
    VisatApp.getApp().addInternalFrameListener(new SpectrumIFL());

    VisatApp.getApp().getProductManager().addListener(new ProductManager.Listener() {
        @Override
        public void productAdded(ProductManager.Event event) {
            // ignored
        }

        @Override
        public void productRemoved(ProductManager.Event event) {
            final Product product = event.getProduct();
            if (getCurrentProduct() == product) {
                chartPanel.getChart().getXYPlot().setDataset(null);
                setCurrentView(null);
                setCurrentProduct(null);
            }
            if (productToAllSpectraMap.containsKey(product)) {
                productToAllSpectraMap.remove(product);
            }
            if (productToBandsMap.containsKey(product)) {
                productToBandsMap.remove(product);
            }
            PlacemarkGroup pinGroup = product.getPinGroup();
            for (int i = 0; i < pinGroup.getNodeCount(); i++) {
                chartHandler.removePinInformation(pinGroup.get(i));
            }
        }
    });

    final ProductSceneView view = VisatApp.getApp().getSelectedProductSceneView();
    if (view != null) {
        handleViewActivated(view);
    } else {
        setCurrentView(view);
    }
    updateUIState();
    return mainPane;
}

From source file:junk.gui.HazardDataSetCalcCondorApp.java

/**
 * Initialize the IMR Gui Bean// ww w. j  av  a 2s .c o  m
 */
private void initIMRGuiBean() {

    imrGuiBean = new IMR_GuiBean(this);
    imrGuiBean.getParameterEditor(imrGuiBean.IMR_PARAM_NAME).getParameter().addParameterChangeListener(this);

    // show this IMRgui bean the Panel
    imrSelectionPanel.add(this.imrGuiBean, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, defaultInsets, 0, 0));

}

From source file:org.jets3t.apps.cockpit.Cockpit.java

/**
 * Initialises the application's GUI elements.
 *//*w  ww.jav  a 2  s  . c  om*/
private void initGui() {
    initMenus();

    JPanel appContent = new JPanel(new GridBagLayout());
    this.getContentPane().add(appContent);

    // Buckets panel.
    JPanel bucketsPanel = new JPanel(new GridBagLayout());

    JButton bucketActionButton = new JButton();
    bucketActionButton.setToolTipText("Bucket actions menu");
    guiUtils.applyIcon(bucketActionButton, "/images/nuvola/16x16/actions/misc.png");
    bucketActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            bucketActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    bucketsPanel.add(new JHtmlLabel("<html><b>Buckets</b></html>", this), new GridBagConstraints(0, 0, 1, 1, 1,
            0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    bucketsPanel.add(bucketActionButton, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    bucketTableModel = new BucketTableModel(false);
    bucketTableModelSorter = new TableSorter(bucketTableModel);
    bucketsTable = new JTable(bucketTableModelSorter);
    bucketTableModelSorter.setTableHeader(bucketsTable.getTableHeader());
    bucketsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bucketsTable.getSelectionModel().addListSelectionListener(this);
    bucketsTable.setShowHorizontalLines(true);
    bucketsTable.setShowVerticalLines(false);
    bucketsTable.addMouseListener(new ContextMenuListener());
    bucketsPanel.add(new JScrollPane(bucketsTable), new GridBagConstraints(0, 1, 2, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
    bucketsPanel.add(new JLabel(" "), new GridBagConstraints(0, 2, 2, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsDefault, 0, 0));

    // Filter panel.
    filterObjectsPanel = new JPanel(new GridBagLayout());
    filterObjectsPrefix = new JTextField();
    filterObjectsPrefix.setToolTipText("Only show objects with this prefix");
    filterObjectsPrefix.addActionListener(this);
    filterObjectsPrefix.setActionCommand("RefreshObjects");
    filterObjectsDelimiter = new JComboBox(new String[] { "", "/", "?", "\\" });
    filterObjectsDelimiter.setEditable(true);
    filterObjectsDelimiter.setToolTipText("Object name delimiter");
    filterObjectsDelimiter.addActionListener(this);
    filterObjectsDelimiter.setActionCommand("RefreshObjects");
    filterObjectsPanel.add(new JHtmlLabel("Prefix:", this), new GridBagConstraints(0, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.add(filterObjectsPrefix, new GridBagConstraints(1, 0, 1, 1, 1, 0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    filterObjectsPanel.add(new JHtmlLabel("Delimiter:", this), new GridBagConstraints(2, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
    filterObjectsPanel.add(filterObjectsDelimiter, new GridBagConstraints(3, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.setVisible(false);

    // Objects panel.
    JPanel objectsPanel = new JPanel(new GridBagLayout());
    int row = 0;
    filterObjectsCheckBox = new JCheckBox("Filter objects");
    filterObjectsCheckBox.addActionListener(this);
    filterObjectsCheckBox.setToolTipText("Check this option to filter the objects listed");
    objectsPanel.add(new JHtmlLabel("<html><b>Objects</b></html>", this), new GridBagConstraints(0, row, 1, 1,
            1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    objectsPanel.add(filterObjectsCheckBox, new GridBagConstraints(1, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    JButton objectActionButton = new JButton();
    objectActionButton.setToolTipText("Object actions menu");
    guiUtils.applyIcon(objectActionButton, "/images/nuvola/16x16/actions/misc.png");
    objectActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            objectActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    objectsPanel.add(objectActionButton, new GridBagConstraints(2, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsPanel.add(filterObjectsPanel, new GridBagConstraints(0, ++row, 3, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsTable = new JTable();
    objectTableModel = new ObjectTableModel();
    objectTableModelSorter = new TableSorter(objectTableModel);
    objectTableModelSorter.setTableHeader(objectsTable.getTableHeader());
    objectsTable.setModel(objectTableModelSorter);
    objectsTable.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 301092191828910402L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            String formattedSize = byteFormatter.formatByteSize(((Long) value).longValue());
            return super.getTableCellRendererComponent(table, formattedSize, isSelected, hasFocus, row, column);
        }
    });
    objectsTable.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 7285511556343895652L;

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Date date = (Date) value;
            return super.getTableCellRendererComponent(table, yearAndTimeSDF.format(date), isSelected, hasFocus,
                    row, column);
        }
    });
    objectsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    objectsTable.getSelectionModel().addListSelectionListener(this);
    objectsTable.setShowHorizontalLines(true);
    objectsTable.setShowVerticalLines(true);
    objectsTable.addMouseListener(new ContextMenuListener());
    objectsTableSP = new JScrollPane(objectsTable);
    objectsPanel.add(objectsTableSP, new GridBagConstraints(0, ++row, 3, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsZero, 0, 0));
    objectsSummaryLabel = new JHtmlLabel("Please select a bucket", this);
    objectsSummaryLabel.setHorizontalAlignment(JLabel.CENTER);
    objectsSummaryLabel.setFocusable(false);
    objectsPanel.add(objectsSummaryLabel, new GridBagConstraints(0, ++row, 3, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    // Combine sections.
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bucketsPanel, objectsPanel);
    splitPane.setOneTouchExpandable(true);
    splitPane.setContinuousLayout(true);

    appContent.add(splitPane, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));

    // Set preferred sizes
    int preferredWidth = 800;
    int preferredHeight = 600;
    this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight)));

    splitPane.setResizeWeight(0.30);

    // Initialize drop target.
    initDropTarget(new JComponent[] { objectsTableSP, objectsTable });
    objectsTable.getDropTarget().setActive(false);
    objectsTableSP.getDropTarget().setActive(false);
}

From source file:org.eurocarbdb.application.glycoworkbench.plugin.s3.Cockpit.java

/**
 * Initialises the application's GUI elements.
 *//*from  w ww  . j a v  a  2  s .c  o  m*/
private void initGui() {
    initMenus();

    JPanel appContent = new JPanel(new GridBagLayout());
    this.getContentPane().add(appContent);

    // Buckets panel.
    JPanel bucketsPanel = new JPanel(new GridBagLayout());

    JButton bucketActionButton = new JButton();
    bucketActionButton.setToolTipText("Bucket actions menu");
    guiUtils.applyIcon(bucketActionButton, "/images/nuvola/16x16/actions/misc.png");
    bucketActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            bucketActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    bucketsPanel.add(new JHtmlLabel("<html><b>Buckets</b></html>", this), new GridBagConstraints(0, 0, 1, 1, 1,
            0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    bucketsPanel.add(bucketActionButton, new GridBagConstraints(1, 0, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    bucketTableModel = new BucketTableModel(false);
    bucketTableModelSorter = new TableSorter(bucketTableModel);
    bucketsTable = new JTable(bucketTableModelSorter);
    bucketTableModelSorter.setTableHeader(bucketsTable.getTableHeader());
    bucketsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bucketsTable.getSelectionModel().addListSelectionListener(this);
    bucketsTable.setShowHorizontalLines(true);
    bucketsTable.setShowVerticalLines(false);
    bucketsTable.addMouseListener(new ContextMenuListener());
    bucketsPanel.add(new JScrollPane(bucketsTable), new GridBagConstraints(0, 1, 2, 1, 1, 1,
            GridBagConstraints.CENTER, GridBagConstraints.BOTH, insetsZero, 0, 0));
    bucketsPanel.add(new JLabel(" "), new GridBagConstraints(0, 2, 2, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsDefault, 0, 0));

    // Filter panel.
    filterObjectsPanel = new JPanel(new GridBagLayout());
    filterObjectsPrefix = new JTextField();
    filterObjectsPrefix.setToolTipText("Only show objects with this prefix");
    filterObjectsPrefix.addActionListener(this);
    filterObjectsPrefix.setActionCommand("RefreshObjects");
    filterObjectsDelimiter = new JComboBox(new String[] { "", "/", "?", "\\" });
    filterObjectsDelimiter.setEditable(true);
    filterObjectsDelimiter.setToolTipText("Object name delimiter");
    filterObjectsDelimiter.addActionListener(this);
    filterObjectsDelimiter.setActionCommand("RefreshObjects");
    filterObjectsPanel.add(new JHtmlLabel("Prefix:", this), new GridBagConstraints(0, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.add(filterObjectsPrefix, new GridBagConstraints(1, 0, 1, 1, 1, 0,
            GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    filterObjectsPanel.add(new JHtmlLabel("Delimiter:", this), new GridBagConstraints(2, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsDefault, 0, 0));
    filterObjectsPanel.add(filterObjectsDelimiter, new GridBagConstraints(3, 0, 1, 1, 0, 0,
            GridBagConstraints.WEST, GridBagConstraints.NONE, insetsZero, 0, 0));
    filterObjectsPanel.setVisible(false);

    // Objects panel.
    JPanel objectsPanel = new JPanel(new GridBagLayout());
    int row = 0;
    filterObjectsCheckBox = new JCheckBox("Filter objects");
    filterObjectsCheckBox.addActionListener(this);
    filterObjectsCheckBox.setToolTipText("Check this option to filter the objects listed");
    objectsPanel.add(new JHtmlLabel("<html><b>Objects</b></html>", this), new GridBagConstraints(0, row, 1, 1,
            1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));
    objectsPanel.add(filterObjectsCheckBox, new GridBagConstraints(1, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    JButton objectActionButton = new JButton();
    objectActionButton.setToolTipText("Object actions menu");
    guiUtils.applyIcon(objectActionButton, "/images/nuvola/16x16/actions/misc.png");
    objectActionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            JButton sourceButton = (JButton) e.getSource();
            objectActionMenu.show(sourceButton, 0, sourceButton.getHeight());
        }
    });
    objectsPanel.add(objectActionButton, new GridBagConstraints(2, row, 1, 1, 0, 0, GridBagConstraints.EAST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsPanel.add(filterObjectsPanel, new GridBagConstraints(0, ++row, 3, 1, 0, 0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, insetsZero, 0, 0));

    objectsTable = new JTable();
    objectTableModel = new ObjectTableModel();
    objectTableModelSorter = new TableSorter(objectTableModel);
    objectTableModelSorter.setTableHeader(objectsTable.getTableHeader());
    objectsTable.setModel(objectTableModelSorter);
    objectsTable.setDefaultRenderer(Long.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 301092191828910402L;

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            String formattedSize = byteFormatter.formatByteSize(((Long) value).longValue());
            return super.getTableCellRendererComponent(table, formattedSize, isSelected, hasFocus, row, column);
        }
    });
    objectsTable.setDefaultRenderer(Date.class, new DefaultTableCellRenderer() {
        private static final long serialVersionUID = 7285511556343895652L;

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                boolean hasFocus, int row, int column) {
            Date date = (Date) value;
            return super.getTableCellRendererComponent(table, yearAndTimeSDF.format(date), isSelected, hasFocus,
                    row, column);
        }
    });
    objectsTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    objectsTable.getSelectionModel().addListSelectionListener(this);
    objectsTable.setShowHorizontalLines(true);
    objectsTable.setShowVerticalLines(true);
    objectsTable.addMouseListener(new ContextMenuListener());
    objectsTableSP = new JScrollPane(objectsTable);
    objectsPanel.add(objectsTableSP, new GridBagConstraints(0, ++row, 3, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsZero, 0, 0));
    objectsSummaryLabel = new JHtmlLabel("Please select a bucket", this);
    objectsSummaryLabel.setHorizontalAlignment(JLabel.CENTER);
    objectsSummaryLabel.setFocusable(false);
    objectsPanel.add(objectsSummaryLabel, new GridBagConstraints(0, ++row, 3, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));

    // Combine sections.
    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, bucketsPanel, objectsPanel);
    splitPane.setOneTouchExpandable(true);
    splitPane.setContinuousLayout(true);

    appContent.add(splitPane, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));

    // Set preferred sizes
    int preferredWidth = 800;
    int preferredHeight = 600;
    this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight)));

    splitPane.setResizeWeight(0.30);

    // Initialize drop target.
    initDropTarget(new JComponent[] { objectsTableSP, objectsTable });
    objectsTable.getDropTarget().setActive(false);
    objectsTableSP.getDropTarget().setActive(false);
}

From source file:shuffle.fwk.service.roster.EditRosterService.java

private JPanel createRosterComponent(Species s) {
    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.gridx = 1;//w  w w. j  ava2  s.c  om
    c.gridy = 1;
    c.anchor = GridBagConstraints.CENTER;

    MouseAdapter ma = new PressOrClickMouseAdapter() {

        @Override
        protected void onRight(MouseEvent e) {
            onLeft(e);
        }

        @Override
        protected void onLeft(MouseEvent e) {
            setSelected(s, ret);
            selectedDisplayLabel.repaint();
        }

        @Override
        protected void onEnter() {
            // Do nothing
        }
    };
    SpeciesPaint sp = new SpeciesPaint(s, false, getMegaFilter());
    ImageIcon icon = getUser().getImageManager().getImageFor(sp);
    JLabel iconLabel = new JLabel(icon);
    iconLabel.addMouseListener(ma);
    ret.add(iconLabel, c);
    c.gridy += 1;
    JLabel jLabel = new JLabel(s.getLocalizedName(getMegaFilter()));
    jLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    jLabel.setHorizontalAlignment(SwingConstants.CENTER);
    jLabel.addMouseListener(ma);
    ret.add(jLabel, c);
    JComboBox<Integer> level = new JComboBox<Integer>();
    for (int i = 0; i <= Species.MAX_LEVEL; i++) {
        level.addItem(i);
    }
    Integer thisLevel = getLevelFor(s);
    level.setSelectedItem(thisLevel);
    level.setToolTipText(getString(KEY_POKEMON_LEVEL_TOOLTIP));
    c.gridy += 1; // put the level selector below the icon.
    ret.add(level, c);
    level.addItemListener(new ItemListener() {
        @Override
        public void itemStateChanged(ItemEvent e) {
            int index = level.getSelectedIndex();
            myData.setLevelForSpecies(s, index);
            rebuildSelectedLabel();
        }
    });
    return ret;
}

From source file:com.digitalgeneralists.assurance.ui.components.ComparisonResultPanel.java

private void buildMergePanel(ComparisonResult result) {
    this.standardPanel.remove(this.mergePanel);

    GridBagConstraints mergePanelConstraints = new GridBagConstraints();
    mergePanelConstraints.anchor = GridBagConstraints.CENTER;
    mergePanelConstraints.fill = GridBagConstraints.BOTH;
    mergePanelConstraints.gridx = 1;/*from w  w w.j  a v  a 2s  . com*/
    mergePanelConstraints.gridy = 0;
    mergePanelConstraints.weightx = 0.2;
    mergePanelConstraints.weighty = 1.0;
    mergePanelConstraints.gridheight = 1;
    mergePanelConstraints.gridwidth = 1;
    mergePanelConstraints.insets = new Insets(0, 0, 0, 0);

    this.mergePanel = new JPanel();
    this.mergePanel.setOpaque(false);
    GridBagLayout mergePanelGridbag = new GridBagLayout();
    this.mergePanel.setLayout(mergePanelGridbag);
    this.standardPanel.add(this.mergePanel, mergePanelConstraints);

    AssuranceResultResolution resolution = AssuranceResultResolution.UNRESOLVED;
    if (result != null) {
        resolution = result.getResolution();
    }

    if (resolution == AssuranceResultResolution.UNRESOLVED) {
        if (this.editable) {
            GridBagConstraints mergeTargetToSourceButtonConstraints = new GridBagConstraints();
            mergeTargetToSourceButtonConstraints.anchor = GridBagConstraints.CENTER;
            mergeTargetToSourceButtonConstraints.gridx = 0;
            mergeTargetToSourceButtonConstraints.gridy = 0;
            mergeTargetToSourceButtonConstraints.weightx = 1.0;
            mergeTargetToSourceButtonConstraints.weighty = 1.0;
            mergeTargetToSourceButtonConstraints.gridheight = 1;
            mergeTargetToSourceButtonConstraints.gridwidth = 1;
            mergeTargetToSourceButtonConstraints.insets = new Insets(5, 5, 5, 5);

            this.mergeTargetToSourceButton.addActionListener(this);
            Image icon;
            try {
                icon = ImageIO.read(Application.class.getClassLoader().getResource("replace-source.png"));
                icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                this.mergeTargetToSourceButton.setIcon(new ImageIcon(icon));
                this.mergeTargetToSourceButton.setText("");
                this.mergeTargetToSourceButton.setToolTipText("Replace source with target.");
            } catch (IOException e) {
                logger.warn("Unable to load icon resources.", e);
            }
            this.mergeTargetToSourceButton.setActionCommand(AssuranceActions.replaceSourceAction);
            this.mergePanel.add(this.mergeTargetToSourceButton, mergeTargetToSourceButtonConstraints);

            GridBagConstraints mergeSourceToTargetButtonConstraints = new GridBagConstraints();
            mergeSourceToTargetButtonConstraints.anchor = GridBagConstraints.CENTER;
            mergeSourceToTargetButtonConstraints.gridx = 0;
            mergeSourceToTargetButtonConstraints.gridy = 1;
            mergeSourceToTargetButtonConstraints.weightx = 1.0;
            mergeSourceToTargetButtonConstraints.weighty = 1.0;
            mergeSourceToTargetButtonConstraints.gridheight = 1;
            mergeSourceToTargetButtonConstraints.gridwidth = 1;
            mergeSourceToTargetButtonConstraints.insets = new Insets(5, 5, 5, 5);

            this.mergeSourceToTargetButton.addActionListener(this);
            try {
                icon = ImageIO.read(Application.class.getClassLoader().getResource("replace-target.png"));
                icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                this.mergeSourceToTargetButton.setIcon(new ImageIcon(icon));
                this.mergeSourceToTargetButton.setText("");
                this.mergeSourceToTargetButton.setToolTipText("Replace target with source.");
            } catch (IOException e) {
                logger.warn("Unable to load icon resources.", e);
            }
            this.mergeSourceToTargetButton.setActionCommand(AssuranceActions.replaceTargetAction);
            this.mergePanel.add(this.mergeSourceToTargetButton, mergeSourceToTargetButtonConstraints);
        }
    } else {
        Image resolutionLabelValue = null;
        try {
            switch (result.getResolution()) {
            case REPLACE_SOURCE:
            case DELETE_SOURCE:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("replace-source.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            case REPLACE_TARGET:
            case DELETE_TARGET:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("replace-target.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            case PROCESSING_ERROR_ENCOUNTERED:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("resolution-error.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            default:
                resolutionLabelValue = ImageIO
                        .read(Application.class.getClassLoader().getResource("undetermined.png"));
                resolutionLabelValue = resolutionLabelValue.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                break;
            }
        } catch (IOException e) {
            logger.warn("Unable to load icon resources.", e);
        }

        GridBagConstraints mergeResolutionLabelConstraints = new GridBagConstraints();
        mergeResolutionLabelConstraints.anchor = GridBagConstraints.CENTER;
        mergeResolutionLabelConstraints.gridx = 0;
        mergeResolutionLabelConstraints.gridy = 0;
        mergeResolutionLabelConstraints.weightx = 1.0;
        mergeResolutionLabelConstraints.weighty = 1.0;
        mergeResolutionLabelConstraints.gridheight = 1;
        mergeResolutionLabelConstraints.gridwidth = 1;
        mergeResolutionLabelConstraints.insets = new Insets(5, 5, 5, 5);

        JLabel mergeResolutionLabel = new JLabel(new ImageIcon(resolutionLabelValue));
        this.mergePanel.add(mergeResolutionLabel, mergeResolutionLabelConstraints);

        if ((result.getResolution() == AssuranceResultResolution.DELETE_SOURCE)
                || (result.getResolution() == AssuranceResultResolution.DELETE_TARGET)) {
            File deletedFile = null;
            if (result.getResolution() == AssuranceResultResolution.DELETE_SOURCE) {
                deletedFile = result
                        .getSourceDeletedItemLocation(MergeEngine.getApplicationDeletedItemsLocation());
            }
            if (result.getResolution() == AssuranceResultResolution.DELETE_TARGET) {
                deletedFile = result
                        .getTargetDeletedItemLocation(MergeEngine.getApplicationDeletedItemsLocation());
            }

            if (deletedFile.exists()) {
                GridBagConstraints mergeRestoreButtonConstraints = new GridBagConstraints();
                mergeRestoreButtonConstraints.anchor = GridBagConstraints.CENTER;
                mergeRestoreButtonConstraints.gridx = 0;
                mergeRestoreButtonConstraints.gridy = 1;
                mergeRestoreButtonConstraints.weightx = 1.0;
                mergeRestoreButtonConstraints.weighty = 1.0;
                mergeRestoreButtonConstraints.gridheight = 1;
                mergeRestoreButtonConstraints.gridwidth = 1;
                mergeRestoreButtonConstraints.insets = new Insets(5, 5, 5, 5);

                Image icon = null;
                try {
                    icon = ImageIO.read(Application.class.getClassLoader().getResource("restore.png"));
                    icon = icon.getScaledInstance(25, 25, Image.SCALE_SMOOTH);
                } catch (IOException e) {
                    logger.warn("Unable to load icon resources.", e);
                }
                this.mergeRestoreButton.setIcon(new ImageIcon(icon));
                this.mergeRestoreButton.setText("");
                this.mergeRestoreButton.setToolTipText("Restore");
                this.mergeRestoreButton.addActionListener(this);
                this.mergeRestoreButton.setActionCommand(AssuranceActions.restoreDeletedItemAction);
                this.mergePanel.add(this.mergeRestoreButton, mergeRestoreButtonConstraints);
            }
            deletedFile = null;
        } else if (result.getResolution() == AssuranceResultResolution.PROCESSING_ERROR_ENCOUNTERED) {
            mergeResolutionLabel.setToolTipText(result.getResolutionError());
        }
    }
}

From source file:shuffle.fwk.service.teams.EditTeamService.java

@SuppressWarnings("serial")
private Component makeTeamPanel() {

    JPanel firstOptionRow = new JPanel(new GridBagLayout());
    GridBagConstraints rowc = new GridBagConstraints();
    rowc.fill = GridBagConstraints.HORIZONTAL;
    rowc.weightx = 0.0;/*from  w w  w.ja  v a  2  s.c  o m*/
    rowc.weighty = 0.0;

    rowc.weightx = 1.0;
    rowc.gridx = 1;
    stageChooser = new StageChooser(this);
    firstOptionRow.add(stageChooser, rowc);
    rowc.weightx = 0.0;

    JPanel secondOptionRow = new JPanel(new GridBagLayout());

    rowc.gridx = 1;
    JLabel megaLabel = new JLabel(getString(KEY_MEGA_LABEL));
    megaLabel.setToolTipText(getString(KEY_MEGA_TOOLTIP));
    secondOptionRow.add(megaLabel, rowc);

    rowc.gridx = 2;
    megaChooser = new JComboBox<String>();
    megaChooser.setToolTipText(getString(KEY_MEGA_TOOLTIP));
    secondOptionRow.add(megaChooser, rowc);

    rowc.gridx = 3;
    JPanel progressPanel = new JPanel(new BorderLayout());
    megaActive = new JCheckBox(getString(KEY_ACTIVE));
    megaActive.setSelected(false);
    megaActive.setToolTipText(getString(KEY_ACTIVE_TOOLTIP));
    progressPanel.add(megaActive, BorderLayout.WEST);
    megaProgressChooser = new JComboBox<Integer>();
    progressPanel.add(megaProgressChooser, BorderLayout.EAST);
    megaProgressChooser.setToolTipText(getString(KEY_MEGA_PROGRESS_TOOLTIP));
    secondOptionRow.add(progressPanel, rowc);

    JPanel thirdOptionRow = new JPanel(new GridBagLayout());

    rowc.gridx = 1;
    JButton clearTeamButton = new JButton(getString(KEY_CLEAR_TEAM));
    clearTeamButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            clearTeam();
        }
    });
    clearTeamButton.setToolTipText(getString(KEY_CLEAR_TEAM_TOOLTIP));
    thirdOptionRow.add(clearTeamButton, rowc);

    rowc.gridx = 2;
    woodCheckBox = new JCheckBox(getString(KEY_WOOD));
    woodCheckBox.setToolTipText(getString(KEY_WOOD_TOOLTIP));
    thirdOptionRow.add(woodCheckBox, rowc);

    rowc.gridx = 3;
    metalCheckBox = new JCheckBox(getString(KEY_METAL));
    metalCheckBox.setToolTipText(getString(KEY_METAL_TOOLTIP));
    thirdOptionRow.add(metalCheckBox, rowc);

    rowc.gridx = 4;
    coinCheckBox = new JCheckBox(getString(KEY_COIN));
    coinCheckBox.setToolTipText(getString(KEY_COIN_TOOLTIP));
    thirdOptionRow.add(coinCheckBox, rowc);

    rowc.gridx = 5;
    freezeCheckBox = new JCheckBox(getString(KEY_FREEZE));
    freezeCheckBox.setToolTipText(getString(KEY_FREEZE_TOOLTIP));
    thirdOptionRow.add(freezeCheckBox, rowc);

    JPanel topPart = new JPanel(new GridBagLayout());
    GridBagConstraints topC = new GridBagConstraints();
    topC.fill = GridBagConstraints.HORIZONTAL;
    topC.weightx = 0.0;
    topC.weighty = 0.0;
    topC.gridx = 1;
    topC.gridy = 1;
    topC.gridwidth = 1;
    topC.gridheight = 1;
    topC.anchor = GridBagConstraints.CENTER;

    topC.gridy = 1;
    topPart.add(firstOptionRow, topC);
    topC.gridy = 2;
    topPart.add(secondOptionRow, topC);
    topC.gridy = 3;
    topPart.add(thirdOptionRow, topC);

    addOptionListeners();

    teamPanel = new JPanel(new WrapLayout()) {
        // Fix to make it play nice with the scroll bar.
        @Override
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width = (int) (d.getWidth() - 20);
            return d;
        }
    };
    final JScrollPane scrollPane = new JScrollPane(teamPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER) {
        @Override
        public Dimension getMinimumSize() {
            Dimension d = super.getMinimumSize();
            d.width = topPart.getMinimumSize().width;
            d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height;
            return d;
        }

        @Override
        public Dimension getPreferredSize() {
            Dimension d = super.getPreferredSize();
            d.width = topPart.getMinimumSize().width;
            d.height = rosterScrollPane.getPreferredSize().height - topPart.getPreferredSize().height;
            return d;
        }
    };
    scrollPane.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            scrollPane.revalidate();
        }
    });
    scrollPane.getVerticalScrollBar().setUnitIncrement(27);

    JPanel ret = new JPanel(new GridBagLayout());
    GridBagConstraints rc = new GridBagConstraints();
    rc.fill = GridBagConstraints.VERTICAL;
    rc.weightx = 0.0;
    rc.weighty = 0.0;
    rc.gridx = 1;
    rc.gridy = 1;
    rc.insets = new Insets(5, 5, 5, 5);
    ret.add(topPart, rc);
    rc.gridy += 1;
    rc.weightx = 0.0;
    rc.weighty = 1.0;
    rc.insets = new Insets(0, 0, 0, 0);
    ret.add(scrollPane, rc);
    return ret;
}

From source file:org.jets3t.apps.uploader.Uploader.java

/**
 * Initialises the application's GUI elements.
 *///from w  ww. j a  va2  s .co m
private void initGui() {
    // Initialise skins factory.
    skinsFactory = SkinsFactory.getInstance(uploaderProperties.getProperties());

    // Set Skinned Look and Feel.
    LookAndFeel lookAndFeel = skinsFactory.createSkinnedMetalTheme("SkinnedLookAndFeel");
    try {
        UIManager.setLookAndFeel(lookAndFeel);
    } catch (UnsupportedLookAndFeelException e) {
        log.error("Unable to set skinned LookAndFeel", e);
    }

    // Apply branding
    String applicationTitle = replaceMessageVariables(
            uploaderProperties.getStringProperty("gui.applicationTitle", null));
    if (applicationTitle != null) {
        ownerFrame.setTitle(applicationTitle);
    }
    String applicationIconPath = uploaderProperties.getStringProperty("gui.applicationIcon", null);
    if (!isRunningAsApplet && applicationIconPath != null) {
        guiUtils.applyIcon(ownerFrame, applicationIconPath);
    }
    String footerHtml = uploaderProperties.getStringProperty("gui.footerHtml", null);
    String footerIconPath = uploaderProperties.getStringProperty("gui.footerIcon", null);

    // Footer for branding
    boolean includeFooter = false;
    JHtmlLabel footerLabel = skinsFactory.createSkinnedJHtmlLabel("FooterLabel");
    footerLabel.setHyperlinkeActivatedListener(this);
    footerLabel.setHorizontalAlignment(JLabel.CENTER);
    if (footerHtml != null) {
        footerLabel.setText(replaceMessageVariables(footerHtml));
        includeFooter = true;
    }
    if (footerIconPath != null) {
        guiUtils.applyIcon(footerLabel, footerIconPath);
    }

    userInputFields = new UserInputFields(insetsDefault, this, skinsFactory);

    // Screeen 1 : User input fields.
    JPanel screen1Panel = skinsFactory.createSkinnedJPanel("Screen1Panel");
    screen1Panel.setLayout(GRID_BAG_LAYOUT);
    userInputFields.buildFieldsPanel(screen1Panel, uploaderProperties);

    // Screen 2 : Drag/drop panel.
    JPanel screen2Panel = skinsFactory.createSkinnedJPanel("Screen2Panel");
    screen2Panel.setLayout(GRID_BAG_LAYOUT);
    dragDropTargetLabel = skinsFactory.createSkinnedJHtmlLabel("DragDropTargetLabel");
    dragDropTargetLabel.setHyperlinkeActivatedListener(this);
    dragDropTargetLabel.setHorizontalAlignment(JLabel.CENTER);
    dragDropTargetLabel.setVerticalAlignment(JLabel.CENTER);

    JButton chooseFileButton = skinsFactory.createSkinnedJButton("ChooseFileButton");
    chooseFileButton.setActionCommand("ChooseFile");
    chooseFileButton.addActionListener(this);
    configureButton(chooseFileButton, "screen.2.browseButton");

    screen2Panel.add(dragDropTargetLabel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));
    screen2Panel.add(chooseFileButton, new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.NORTH,
            GridBagConstraints.NONE, insetsDefault, 0, 0));

    // Screen 3 : Information about the file to be uploaded.
    JPanel screen3Panel = skinsFactory.createSkinnedJPanel("Screen3Panel");
    screen3Panel.setLayout(GRID_BAG_LAYOUT);
    fileToUploadLabel = skinsFactory.createSkinnedJHtmlLabel("FileToUploadLabel");
    fileToUploadLabel.setHyperlinkeActivatedListener(this);
    fileToUploadLabel.setHorizontalAlignment(JLabel.CENTER);
    fileToUploadLabel.setVerticalAlignment(JLabel.CENTER);
    screen3Panel.add(fileToUploadLabel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));

    // Screen 4 : Upload progress.
    JPanel screen4Panel = skinsFactory.createSkinnedJPanel("Screen4Panel");
    screen4Panel.setLayout(GRID_BAG_LAYOUT);
    fileInformationLabel = skinsFactory.createSkinnedJHtmlLabel("FileInformationLabel");
    fileInformationLabel.setHyperlinkeActivatedListener(this);
    fileInformationLabel.setHorizontalAlignment(JLabel.CENTER);
    progressBar = skinsFactory.createSkinnedJProgressBar("ProgressBar", 0, 100);
    progressBar.setStringPainted(true);
    progressStatusTextLabel = skinsFactory.createSkinnedJHtmlLabel("ProgressStatusTextLabel");
    progressStatusTextLabel.setHyperlinkeActivatedListener(this);
    progressStatusTextLabel.setText(" ");
    progressStatusTextLabel.setHorizontalAlignment(JLabel.CENTER);
    progressTransferDetailsLabel = skinsFactory.createSkinnedJHtmlLabel("ProgressTransferDetailsLabel");
    progressTransferDetailsLabel.setHyperlinkeActivatedListener(this);
    progressTransferDetailsLabel.setText(" ");
    progressTransferDetailsLabel.setHorizontalAlignment(JLabel.CENTER);
    cancelUploadButton = skinsFactory.createSkinnedJButton("CancelUploadButton");
    cancelUploadButton.setActionCommand("CancelUpload");
    cancelUploadButton.addActionListener(this);
    configureButton(cancelUploadButton, "screen.4.cancelButton");

    screen4Panel.add(fileInformationLabel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    screen4Panel.add(progressBar, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    screen4Panel.add(progressStatusTextLabel, new GridBagConstraints(0, 2, 1, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    screen4Panel.add(progressTransferDetailsLabel, new GridBagConstraints(0, 3, 1, 1, 1, 0,
            GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    screen4Panel.add(cancelUploadButton, new GridBagConstraints(0, 4, 1, 1, 1, 0, GridBagConstraints.CENTER,
            GridBagConstraints.NONE, insetsDefault, 0, 0));

    // Screen 5 : Thankyou message.
    JPanel screen5Panel = skinsFactory.createSkinnedJPanel("Screen5Panel");
    screen5Panel.setLayout(GRID_BAG_LAYOUT);
    finalMessageLabel = skinsFactory.createSkinnedJHtmlLabel("FinalMessageLabel");
    finalMessageLabel.setHyperlinkeActivatedListener(this);
    finalMessageLabel.setHorizontalAlignment(JLabel.CENTER);
    screen5Panel.add(finalMessageLabel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));

    // Wizard Button panel.
    backButton = skinsFactory.createSkinnedJButton("backButton");
    backButton.setActionCommand("Back");
    backButton.addActionListener(this);
    nextButton = skinsFactory.createSkinnedJButton("nextButton");
    nextButton.setActionCommand("Next");
    nextButton.addActionListener(this);

    buttonsPanel = skinsFactory.createSkinnedJPanel("ButtonsPanel");
    buttonsPanelCardLayout = new CardLayout();
    buttonsPanel.setLayout(buttonsPanelCardLayout);
    JPanel buttonsInvisiblePanel = skinsFactory.createSkinnedJPanel("ButtonsInvisiblePanel");
    JPanel buttonsVisiblePanel = skinsFactory.createSkinnedJPanel("ButtonsVisiblePanel");
    buttonsVisiblePanel.setLayout(GRID_BAG_LAYOUT);
    buttonsVisiblePanel.add(backButton, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.WEST,
            GridBagConstraints.NONE, insetsDefault, 0, 0));
    buttonsVisiblePanel.add(nextButton, new GridBagConstraints(1, 0, 1, 1, 1, 0, GridBagConstraints.EAST,
            GridBagConstraints.NONE, insetsDefault, 0, 0));
    buttonsPanel.add(buttonsInvisiblePanel, "invisible");
    buttonsPanel.add(buttonsVisiblePanel, "visible");

    // Overall content panel.
    appContentPanel = skinsFactory.createSkinnedJPanel("ApplicationContentPanel");
    appContentPanel.setLayout(GRID_BAG_LAYOUT);
    JPanel userGuidancePanel = skinsFactory.createSkinnedJPanel("UserGuidancePanel");
    userGuidancePanel.setLayout(GRID_BAG_LAYOUT);
    primaryPanel = skinsFactory.createSkinnedJPanel("PrimaryPanel");
    primaryPanelCardLayout = new CardLayout();
    primaryPanel.setLayout(primaryPanelCardLayout);
    JPanel navigationPanel = skinsFactory.createSkinnedJPanel("NavigationPanel");
    navigationPanel.setLayout(GRID_BAG_LAYOUT);

    appContentPanel.add(userGuidancePanel, new GridBagConstraints(0, 0, 1, 1, 1, 0.2, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));
    appContentPanel.add(primaryPanel, new GridBagConstraints(0, 1, 1, 1, 1, 0.6, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));
    appContentPanel.add(navigationPanel, new GridBagConstraints(0, 2, 1, 1, 1, 0.2, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsDefault, 0, 0));
    if (includeFooter) {
        log.debug("Adding footer for branding");
        appContentPanel.add(footerLabel, new GridBagConstraints(0, 3, 1, 1, 1, 0, GridBagConstraints.CENTER,
                GridBagConstraints.HORIZONTAL, insetsDefault, 0, 0));
    }
    this.getContentPane().add(appContentPanel);

    userGuidanceLabel = skinsFactory.createSkinnedJHtmlLabel("UserGuidanceLabel");
    userGuidanceLabel.setHyperlinkeActivatedListener(this);
    userGuidanceLabel.setHorizontalAlignment(JLabel.CENTER);

    userGuidancePanel.add(userGuidanceLabel, new GridBagConstraints(0, 0, 1, 1, 1, 1, GridBagConstraints.CENTER,
            GridBagConstraints.BOTH, insetsNone, 0, 0));
    navigationPanel.add(buttonsPanel, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.CENTER,
            GridBagConstraints.HORIZONTAL, insetsNone, 0, 0));

    primaryPanel.add(screen1Panel, "screen1");
    primaryPanel.add(screen2Panel, "screen2");
    primaryPanel.add(screen3Panel, "screen3");
    primaryPanel.add(screen4Panel, "screen4");
    primaryPanel.add(screen5Panel, "screen5");

    // Set preferred sizes
    int preferredWidth = uploaderProperties.getIntProperty("gui.minSizeWidth", 400);
    int preferredHeight = uploaderProperties.getIntProperty("gui.minSizeHeight", 500);
    this.setBounds(new Rectangle(new Dimension(preferredWidth, preferredHeight)));

    // Initialize drop target.
    initDropTarget(new Component[] { this });

    // Revert to default Look and Feel for all future GUI elements (eg Dialog boxes).
    try {
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        log.error("Unable to set default system LookAndFeel", e);
    }

    wizardStepForward();
}