Example usage for java.awt BorderLayout PAGE_END

List of usage examples for java.awt BorderLayout PAGE_END

Introduction

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

Prototype

String PAGE_END

To view the source code for java.awt BorderLayout PAGE_END.

Click Source Link

Document

The component comes after the last line of the layout's content.

Usage

From source file:components.ListDialog.java

private ListDialog(Frame frame, Component locationComp, String labelText, String title, Object[] data,
        String initialValue, String longValue) {
    super(frame, title, true);

    //Create and initialize the buttons.
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(this);
    ////from w  w  w. j  a  v  a2 s .com
    final JButton setButton = new JButton("Set");
    setButton.setActionCommand("Set");
    setButton.addActionListener(this);
    getRootPane().setDefaultButton(setButton);

    //main part of the dialog
    list = new JList(data) {
        //Subclass JList to workaround bug 4832765, which can cause the
        //scroll pane to not let the user easily scroll up to the beginning
        //of the list.  An alternative would be to set the unitIncrement
        //of the JScrollBar to a fixed value. You wouldn't get the nice
        //aligned scrolling, but it should work.
        public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
            int row;
            if (orientation == SwingConstants.VERTICAL && direction < 0
                    && (row = getFirstVisibleIndex()) != -1) {
                Rectangle r = getCellBounds(row, row);
                if ((r.y == visibleRect.y) && (row != 0)) {
                    Point loc = r.getLocation();
                    loc.y--;
                    int prevIndex = locationToIndex(loc);
                    Rectangle prevR = getCellBounds(prevIndex, prevIndex);

                    if (prevR == null || prevR.y >= r.y) {
                        return 0;
                    }
                    return prevR.height;
                }
            }
            return super.getScrollableUnitIncrement(visibleRect, orientation, direction);
        }
    };

    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    if (longValue != null) {
        list.setPrototypeCellValue(longValue); //get extra space
    }
    list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    list.setVisibleRowCount(-1);
    list.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                setButton.doClick(); //emulate button click
            }
        }
    });
    JScrollPane listScroller = new JScrollPane(list);
    listScroller.setPreferredSize(new Dimension(250, 80));
    listScroller.setAlignmentX(LEFT_ALIGNMENT);

    //Create a container so that we can add a title around
    //the scroll pane.  Can't add a title directly to the
    //scroll pane because its background would be white.
    //Lay out the label and scroll pane from top to bottom.
    JPanel listPane = new JPanel();
    listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
    JLabel label = new JLabel(labelText);
    label.setLabelFor(list);
    listPane.add(label);
    listPane.add(Box.createRigidArea(new Dimension(0, 5)));
    listPane.add(listScroller);
    listPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

    //Lay out the buttons from left to right.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
    buttonPane.add(Box.createHorizontalGlue());
    buttonPane.add(cancelButton);
    buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
    buttonPane.add(setButton);

    //Put everything together, using the content pane's BorderLayout.
    Container contentPane = getContentPane();
    contentPane.add(listPane, BorderLayout.CENTER);
    contentPane.add(buttonPane, BorderLayout.PAGE_END);

    //Initialize values.
    setValue(initialValue);
    pack();
    setLocationRelativeTo(locationComp);
}

From source file:it.imtech.configuration.StartWizard.java

/**
 * Creates a new wizard with active card (Select Language/Server)
 *//*from   w ww.  j  av  a 2 s.  c om*/
public StartWizard() {
    Globals.setGlobalVariables();
    ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE, Globals.loader);

    if (!checkAppDataFiles()) {
        JOptionPane.showMessageDialog(null, Utility.getBundleString("copy_appdata", bundle),
                Utility.getBundleString("copy_appdata_title", bundle), JOptionPane.ERROR_MESSAGE);
        System.exit(1);
    }

    DOMConfigurator.configure(Globals.LOG4J);
    logger = Logger.getLogger(StartWizard.class);
    logger.info("Starting Application Phaidra Importer");

    mainFrame = new JFrame();

    if (Utility.internetConnectionAvailable()) {
        Globals.ONLINE = true;
    }

    it.imtech.utility.Utility.cleanUndoDir();

    XMLConfiguration internalConf = setConfiguration();
    logger.info("Configuration path estabilished");

    XMLConfiguration config = setConfigurationPaths(internalConf, bundle);

    headerPanel = new HeaderPanel();
    footerPanel = new FooterPanel();

    JButton nextButton = (JButton) footerPanel.getComponentByName("next_button");
    JButton prevButton = (JButton) footerPanel.getComponentByName("prev_button");

    nextButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (getCurrentCard() instanceof ChooseServer) {
                ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                        Globals.loader);

                try {
                    mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

                    Server selected = chooseServer.getSelectedServer();
                    logger.info("Selected Server = " + selected.getServername());
                    SelectedServer.getInstance(null).makeEmpty();
                    SelectedServer.getInstance(selected);

                    if (Globals.ONLINE) {
                        logger.info("Testing server connection...");
                        ChooseServer.testServerConnection(SelectedServer.getInstance(null).getBaseUrl());
                    }
                    chooseFolder.updateLanguage();

                    MetaUtility.getInstance().preInitializeData();
                    logger.info("Preinitialization done (Vocabulary and Languages");

                    c1.next(cardsPanel);
                    mainFrame.setCursor(null);
                } catch (Exception ex) {
                    logger.error(ex.getMessage());
                    JOptionPane.showMessageDialog(new Frame(),
                            Utility.getBundleString("preinitializemetadataex", bundle));
                }
            } else if (getCurrentCard() instanceof ChooseFolder) {
                mainFrame.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
                boolean error = chooseFolder.checkFolderSelectionValidity();

                if (error == false) {
                    BookImporter x = BookImporter.getInstance();
                    mainFrame.setCursor(null);
                    mainFrame.setVisible(false);
                }
            }
        }
    });

    prevButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent event) {
            if (getCurrentCard() instanceof ChooseServer) {
                ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                        Globals.loader);
                String title = Utility.getBundleString("dialog_1_title", bundle);
                String text = Utility.getBundleString("dialog_1", bundle);

                ConfirmDialog confirm = new ConfirmDialog(mainFrame, true, title, text,
                        Utility.getBundleString("confirm", bundle), Utility.getBundleString("back", bundle));

                confirm.setVisible(true);
                boolean close = confirm.getChoice();
                confirm.dispose();

                if (close == true) {
                    mainFrame.dispose();
                }
            } else {
                c1.previous(cardsPanel);
            }
        }
    });

    cardsPanel = new JPanel(new CardLayout());
    cardsPanel.setBackground(Color.WHITE);

    chooseServer = new ChooseServer(config);
    chooseFolder = new ChooseFolder();

    cardsPanel.add(chooseServer, "1");
    cardsPanel.add(chooseFolder, "2");

    cardsPanel.setLayout(c1);
    c1.show(cardsPanel, "1");

    //Main Panel style
    mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(BorderLayout.NORTH, headerPanel);
    mainPanel.add(BorderLayout.CENTER, cardsPanel);
    mainPanel.add(BorderLayout.PAGE_END, footerPanel);
    mainFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

    mainFrame.addWindowListener(new java.awt.event.WindowAdapter() {
        @Override
        public void windowClosing(java.awt.event.WindowEvent windowEvent) {
            ResourceBundle bundle = ResourceBundle.getBundle(Globals.RESOURCES, Globals.CURRENT_LOCALE,
                    Globals.loader);
            String title = Utility.getBundleString("dialog_1_title", bundle);
            String text = Utility.getBundleString("dialog_1", bundle);

            ConfirmDialog confirm = new ConfirmDialog(mainFrame, true, title, text,
                    Utility.getBundleString("confirm", bundle), Utility.getBundleString("back", bundle));

            confirm.setVisible(true);
            boolean close = confirm.getChoice();
            confirm.dispose();

            if (close == true) {
                mainFrame.dispose();
            }
        }
    });

    //Add Style 
    mainFrame.getContentPane().setBackground(Color.white);
    mainFrame.getContentPane().setLayout(new BorderLayout());
    mainFrame.getContentPane().setPreferredSize(new Dimension(640, 400));
    mainFrame.getContentPane().add(BorderLayout.CENTER, mainPanel);
    mainFrame.pack();

    //Center frame in the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (dim.width - mainFrame.getSize().width) / 2;
    int y = (dim.height - mainFrame.getSize().height) / 2;
    mainFrame.setLocation(x, y);

    mainFrame.setVisible(true);
}

From source file:gui.DownloadManagerGUI.java

public DownloadManagerGUI(String name) {
    super(name);//from   w w w  .jav  a 2s .  c  o  m

    setLayout(new BorderLayout());

    preferences = Preferences.userRoot().node("db");
    final PreferencesDTO preferencesDTO = getPreferences();

    LookAndFeel.setLaf(preferencesDTO.getPreferencesInterfaceDTO().getLookAndFeelName());

    createFileHierarchy();

    mainToolbar = new MainToolBar();
    categoryPanel = new CategoryPanel(
            preferencesDTO.getPreferencesSaveDTO().getPreferencesDirectoryCategoryDTOs());
    downloadPanel = new DownloadPanel(this, preferencesDTO.getPreferencesSaveDTO().getDatabasePath(),
            preferencesDTO.getPreferencesConnectionDTO().getConnectionTimeOut(),
            preferencesDTO.getPreferencesConnectionDTO().getReadTimeOut());
    messagePanel = new MessagePanel(this);
    JTabbedPane mainTabPane = new JTabbedPane();
    mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, categoryPanel, mainTabPane);
    mainSplitPane.setOneTouchExpandable(true);
    statusPanel = new StatusPanel();
    addNewDownloadDialog = new AddNewDownloadDialog(this);

    mainTabPane.addTab(messagesBundle.getString("downloadManagerGUI.mainTabPane.downloadPanel"), downloadPanel);
    mainTabPane.addTab(messagesBundle.getString("downloadManagerGUI.mainTabPane.messagePanel"), messagePanel);

    preferenceDialog = new PreferenceDialog(this, preferencesDTO);

    aboutDialog = new AboutDialog(this);

    categoryPanel.setCategoryPanelListener((fileExtensions, downloadCategory) -> downloadPanel
            .setDownloadsByDownloadPath(fileExtensions, downloadCategory));

    //     preferenceDialog.setDefaults(preferencesDTO);

    addNewDownloadDialog.setAddNewDownloadListener(textUrl -> {
        Objects.requireNonNull(textUrl, "textUrl");
        if (textUrl.equals(""))
            throw new IllegalArgumentException("textUrl is empty");

        String downloadName;
        try {
            downloadName = ConnectionUtil.getRealFileName(textUrl);
        } catch (IOException e) {
            logger.error("Can't get real name of file that you want to download." + textUrl);
            messageLogger.error("Can't get real name of file that you want to download." + textUrl);
            downloadName = ConnectionUtil.getFileName(textUrl);
        }
        String fileExtension = FilenameUtils.getExtension(downloadName);
        File downloadPathFile = new File(
                preferencesDTO.getPreferencesSaveDTO().getPathByFileExtension(fileExtension));
        File downloadRangeFile = new File(preferencesDTO.getPreferencesSaveDTO().getTempDirectory());
        int maxNum = preferencesDTO.getPreferencesConnectionDTO().getMaxConnectionNumber();

        Download download = null;

        List<Download> downloads = downloadPanel.getDownloadList();
        String properDownloadName = getProperNameForDownload(downloadName, downloads, downloadPathFile);

        // todo must set stretegy pattern
        switch (ProtocolType.valueOfByDesc(textUrl.getProtocol())) {
        case HTTP:
            download = new HttpDownload(downloadPanel.getNextDownloadID(), textUrl, properDownloadName, maxNum,
                    downloadPathFile, downloadRangeFile, ProtocolType.HTTP);
            break;
        case FTP:
            // todo must be created ...
            break;
        case HTTPS:
            download = new HttpsDownload(downloadPanel.getNextDownloadID(), textUrl, properDownloadName, maxNum,
                    downloadPathFile, downloadRangeFile, ProtocolType.HTTPS);
            break;
        }

        downloadPanel.addDownload(download);
    });

    // Add panels to display.
    add(mainToolbar, BorderLayout.PAGE_START);
    add(mainSplitPane, BorderLayout.CENTER);
    add(statusPanel, BorderLayout.PAGE_END);

    setJMenuBar(initMenuBar());

    mainToolbar.setMainToolbarListener(new MainToolbarListener() {
        @Override
        public void newDownloadEventOccured() {
            addNewDownloadDialog.setVisible(true);
            addNewDownloadDialog.onPaste();
        }

        @Override
        public void pauseEventOccured() {
            downloadPanel.actionPause();
            mainToolbar.setStateOfButtonsControl(false, false, false, false, false, true); // canceled
        }

        @Override
        public void resumeEventOccured() {
            downloadPanel.actionResume();
        }

        @Override
        public void pauseAllEventOccured() {
            downloadPanel.actionPauseAll();
        }

        @Override
        public void clearEventOccured() {
            downloadPanel.actionClear();
        }

        @Override
        public void clearAllCompletedEventOccured() {
            downloadPanel.actionClearAllCompleted();
        }

        @Override
        public void reJoinEventOccured() {
            downloadPanel.actionReJoinFileParts();
        }

        @Override
        public void reDownloadEventOccured() {
            downloadPanel.actionReDownload();
        }

        @Override
        public void propertiesEventOccured() {
            downloadPanel.actionProperties();
        }

        @Override
        public void preferencesEventOccured() {
            preferenceDialog.setVisible(true);
        }
    });

    downloadPanel.setDownloadPanelListener(new DownloadPanelListener() {
        @Override
        public void stateChangedEventOccured(DownloadStatus downloadState) {
            updateButtons(downloadState);
        }

        @Override
        public void downloadSelected(Download download) {
            statusPanel.setStatus(download.getDownloadName());
        }
    });

    preferenceDialog.setPreferencesListener(new PreferencesListener() {
        @Override
        public void preferencesSet(PreferencesDTO preferenceDTO) {
            setPreferencesOS(preferenceDTO);
        }

        @Override
        public void preferenceReset() {
            PreferencesDTO resetPreferencesDTO = getPreferences();
            preferenceDialog.setPreferencesDTO(resetPreferencesDTO);
            categoryPanel.setTreeModel(
                    resetPreferencesDTO.getPreferencesSaveDTO().getPreferencesDirectoryCategoryDTOs());
        }

        @Override
        public void preferenceDefaults() {
            PreferencesDTO defaultPreferenceDTO = new PreferencesDTO();
            resetAndSetPreferencesDTOFromConf(defaultPreferenceDTO);
            preferenceDialog.setPreferencesDTO(defaultPreferenceDTO);
            categoryPanel.setTreeModel(
                    defaultPreferenceDTO.getPreferencesSaveDTO().getPreferencesDirectoryCategoryDTOs());
        }
    });

    // Handle window closing events.
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent windowEvent) {
            int action = JOptionPane.showConfirmDialog(DownloadManagerGUI.this,
                    "Do you realy want to exit the application?", "Confirm Exit", JOptionPane.OK_CANCEL_OPTION);
            if (action == JOptionPane.OK_OPTION) {
                logger.info("Window Closing");
                downloadPanel.actionPauseAll();
                dispose();
                System.gc();
            }
        }
    });

    Authenticator.setDefault(new DialogAuthenticator(this));

    setIconImage(
            Utils.createIcon(messagesBundle.getString("downloadManagerGUI.mainFrame.iconPath")).getImage());

    setMinimumSize(new Dimension(640, 480));
    // Set window size.
    pack();
    setSize(900, 580);

    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    setVisible(true);
}

From source file:org.orbisgis.view.map.MapEditor.java

/**
 * Constructor//from   w  ww  .j a v a  2 s  .  c  o m
 */
public MapEditor() {
    super(new BorderLayout());
    dockingPanelParameters = new DockingPanelParameters();
    dockingPanelParameters.setName("map_editor");
    updateMapLabel();
    dockingPanelParameters.setTitleIcon(OrbisGISIcon.getIcon("map"));
    dockingPanelParameters.setMinimizable(false);
    dockingPanelParameters.setExternalizable(false);
    dockingPanelParameters.setCloseable(false);
    dockingPanelParameters.setLayout(mapEditorPersistence);
    layeredPane.add(mapControl, 1);
    layeredPane.add(mapsManager, 0);
    mapsManager.setVisible(false);
    mapsManager.setMapsManagerPersistence(mapEditorPersistence.getMapsManagerPersistence());
    // when the layout is loaded, this editor will load the map element linked with this layout
    mapEditorPersistence.addPropertyChangeListener(MapEditorPersistence.PROP_DEFAULTMAPCONTEXT,
            EventHandler.create(PropertyChangeListener.class, this, "onSerialisationMapChange"));
    add(layeredPane, BorderLayout.CENTER);
    add(mapStatusBar, BorderLayout.PAGE_END);
    //Declare Tools of Map Editors
    //Add the tools in the docking Panel title
    createActions();
    dockingPanelParameters.setDockActions(actions.getActions());
    // Tools that will be created later will also be set in the docking panel
    // thanks to this listener
    actions.addPropertyChangeListener(new ActionDockingListener(dockingPanelParameters));
    //Set the Drop target
    dragDropHandler = new MapTransferHandler();
    this.setTransferHandler(dragDropHandler);
}

From source file:modnlp.capte.AlignmentInterfaceWS.java

public AlignmentInterfaceWS() {
    //Setup file chooser 
    super(new BorderLayout());
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    this.setSize(dim.width, dim.height);

    //Create the log first, because the action listeners
    //need to refer to it.
    log = new JTextArea(5, 20);
    log.setMargin(new Insets(5, 5, 5, 5));
    log.setEditable(false);//from  w w w  .j  av a 2s  . c  o m
    JScrollPane logScrollPane = new JScrollPane(log);

    //Create a file chooser
    fc = new JFileChooser();

    //Uncomment one of the following lines to try a different
    //file selection mode.  The first allows just directories
    //to be selected (and, at least in the Java look and feel,
    //shown).  The second allows both files and directories
    //to be selected.  If you leave these lines commented out,
    //then the default mode (FILES_ONLY) will be used.
    //
    //fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    //fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

    //Create the open button.  We use the image from the JLF
    //Graphics Repository (but we extracted it from the jar).
    alignButton = new JButton("Align Texts");
    alignButton.addActionListener(this);
    openButton = new JButton("Open Source File...");
    openButton.addActionListener(this);

    //Create the save button.  We use the image from the JLF
    //Graphics Repository (but we extracted it from the jar).
    saveButton = new JButton("Open Target File...");
    saveButton.addActionListener(this);

    //Create two JText fields for input source and target language codes

    sl = new JTextField("en");
    sourcel = sl.getText();
    sol = new JLabel("Source");
    tl = new JTextField("es");
    targetl = tl.getText();
    tol = new JLabel("Target");
    splitButton = new JCheckBox("Splitter");
    splitButton.setMnemonic(KeyEvent.VK_C);
    splitButton.setSelected(true);
    splitButton.addItemListener(this);
    convLine = new JCheckBox("Convert EOL");
    convLine.setMnemonic(KeyEvent.VK_S);
    convLine.setSelected(true);
    convLine.addItemListener(this);
    sl.addActionListener(this);
    tl.addActionListener(this);

    //For layout purposes, put the buttons in a separate panel
    JPanel buttonPanel = new JPanel(); //use FlowLayout
    buttonPanel.add(openButton);
    buttonPanel.add(saveButton);

    //Make another panel for the aligner button
    JPanel alignPanel = new JPanel();
    alignPanel.add(convLine);
    alignPanel.add(splitButton);
    alignPanel.add(sol);
    alignPanel.add(sl);
    alignPanel.add(tol);
    alignPanel.add(tl);
    alignPanel.add(alignButton);

    //Add the buttons and the log to this panel.
    add(buttonPanel, BorderLayout.PAGE_START);
    add(logScrollPane, BorderLayout.CENTER);
    add(alignPanel, BorderLayout.PAGE_END);
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.ui.SaveChartDialog.java

/**
 * Creates and lays out the controls inside this dialog's content pane.
 * <p>// w w  w  . j av  a 2 s.c  om
 * This method is called upon initialization only.
 * </p>
 */
private void initControls() {
    JPanel sizePanel = new JPanel(new GridLayout(2, 3, 4, 4));
    sizePanel.setBorder(BorderFactory.createTitledBorder(Messages.DI_IMAGESIZE));

    // Add a spinner for choosing width
    sizePanel.add(new JLabel(Messages.DI_WIDTH, SwingConstants.RIGHT));
    int width = ChartPanel.DEFAULT_WIDTH;
    int minWidth = ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH;
    int maxWidth = ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH;
    SpinnerModel widthSettings = new SpinnerNumberModel(width, minWidth, maxWidth, 1);
    sizePanel.add(widthSpinner = new JSpinner(widthSettings));
    sizePanel.add(new JLabel(Messages.DI_PIXELS));

    // Add a spinner for choosing height
    sizePanel.add(new JLabel(Messages.DI_HEIGHT, SwingConstants.RIGHT));
    int height = ChartPanel.DEFAULT_HEIGHT;
    int minHeight = ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT;
    int maxHeight = ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT;
    SpinnerModel heightSettings = new SpinnerNumberModel(height, minHeight, maxHeight, 1);
    sizePanel.add(heightSpinner = new JSpinner(heightSettings));
    sizePanel.add(new JLabel(Messages.DI_PIXELS));

    // Add Save and Cancel buttons
    JPanel buttons = new JPanel(new GridLayout(1, 2, 4, 0));
    buttons.add(btnSave = Utils.createButton(Messages.DI_SAVE, null, this));
    buttons.add(btnCancel = Utils.createButton(Messages.DI_CANCEL, null, this));
    Box buttonsBox = Box.createHorizontalBox();
    buttonsBox.add(Box.createHorizontalGlue());
    buttonsBox.add(buttons);
    buttonsBox.add(Box.createHorizontalGlue());

    Container contentPane = getContentPane();
    contentPane.add(sizePanel, BorderLayout.NORTH);
    contentPane.add(Box.createVerticalStrut(Utils.BORDER_SIZE / 2));
    contentPane.add(buttonsBox, BorderLayout.PAGE_END);
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    Utils.setStandardBorder(getRootPane());
}

From source file:eu.apenet.dpt.standalone.gui.dateconversion.DateConversionRulesDialog.java

private void createDataConversionRulesList() {
    Vector<String> columnNames = new Vector<String>();
    columnNames.add(labels.getString("dateConversion.valueRead"));
    columnNames.add(labels.getString("dateConversion.valueConverted"));
    dm = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);
    dm.addRow(new Vector<String>());
    dm.addTableModelListener(new TableModelListener() {
        public void tableChanged(TableModelEvent e) {
            if (ruleTable.getEditingRow() != ruleTable.getRowCount() - 1
                    && (StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                            && StringUtils.isEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1)))) {
                dm.removeRow(ruleTable.getEditingRow());
            }//from   ww  w  . j a v a  2s.  c om
            if (ruleTable.getEditingRow() == ruleTable.getRowCount() - 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 0))
                        && StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    dm.addRow(new Vector<String>());
                }
            }
            if (ruleTable.getEditingColumn() == 1) {
                if (StringUtils.isNotEmpty((String) dm.getValueAt(ruleTable.getEditingRow(), 1))
                        && !isCorrectDateFormat((String) dm.getValueAt(ruleTable.getEditingRow(), 1))) {
                    createOptionPaneForIsoDate(ruleTable.getEditingRow(), 1);
                }
            }
        }
    });

    ruleTable = new JTable(dm);
    oldModel = new DefaultTableModel(xmlFilehandler.loadDataFromFile(FILENAME), columnNames);

    JButton saveButton = new JButton(labels.getString("saveBtn"));
    saveButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            for (int i = 0; i < data.size() - 1; i++) {
                Vector<String> vector = data.elementAt(i);
                if (vector.elementAt(1) != null && !isCorrectDateFormat((String) vector.elementAt(1))) {
                    createOptionPaneForIsoDate(i, 1);
                }
            }
            xmlFilehandler.saveDataToFile(data, FILENAME);
            saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                    new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
        }
    });

    JButton closeButton = new JButton(labels.getString("quit"));
    closeButton.addActionListener(new ActionListener() {
        // boolean cancel = true;

        public void actionPerformed(ActionEvent e) {
            /*System.out.println(Boolean.toString(oldModel.getRowCount() == (ruleTable.getModel().getRowCount() - 1)) + "<<" + oldModel.getRowCount() + ", " + (ruleTable.getModel().getRowCount() - 1));
            if (oldModel.getRowCount() != ruleTable.getModel().getRowCount() - 1) {
            cancel = showUnsavedChangesDialog();
            } else {
            for (int i = 0; i < (ruleTable.getModel().getRowCount() - 1); i++) {
                for (int j = 0; j <= 1; j++) {
                    System.out.println(oldModel.getValueAt(i, j) == ruleTable.getModel().getValueAt(i, j) + " >> " + oldModel.getValueAt(i, j) + ", " + ruleTable.getModel().getValueAt(i, j));
                    if (oldModel.getValueAt(i, j) != ruleTable.getModel().getValueAt(i, j)) {
                        cancel = showUnsavedChangesDialog();
                    }
                }
            }
            }
            if (cancel) {*/
            dispose();
            //  }
        }
    });

    JButton downloadButton = new JButton(labels.getString("downloadBtn"));
    downloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (ruleTable.isEditing()) {
                ruleTable.getCellEditor().stopCellEditing();
            }
            Vector<Vector<String>> data = ((DefaultTableModel) ruleTable.getModel()).getDataVector();
            File currentLocation = new File(retrieveFromDb.retrieveOpenLocation());
            JFileChooser fileChooser = new JFileChooser(currentLocation);
            fileChooser.setDialogType(JFileChooser.SAVE_DIALOG);
            fileChooser.setFileFilter(new FileNameExtensionFilter("XML file", "xml"));
            int returnedVal = fileChooser.showSaveDialog(getParent());

            if (returnedVal == JFileChooser.APPROVE_OPTION) {
                String fileName = fileChooser.getSelectedFile().toString();
                if (!fileName.endsWith(".xml")) {
                    fileName = fileName + ".xml";
                }
                xmlFilehandler.saveDataToFile(data, fileName);
                //additionally save data to standard file
                xmlFilehandler.saveDataToFile(data, FILENAME);
                saveMessage.setText(MessageFormat.format(labels.getString("dateConversion.saveMsg"),
                        new SimpleDateFormat("HH:mm:ss").format(Calendar.getInstance().getTime())));
            }
        }
    });

    JPanel contentPanel = new JPanel(new BorderLayout());
    contentPanel.add(new JScrollPane(ruleTable));
    saveMessage = new JLabel();
    contentPanel.add(saveMessage, BorderLayout.SOUTH);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 3));
    buttonPanel.add(saveButton);
    buttonPanel.add(closeButton);
    buttonPanel.add(downloadButton);

    JPanel pane = new JPanel(new BorderLayout());
    pane.add(contentPanel, BorderLayout.PAGE_START);
    pane.add(buttonPanel, BorderLayout.PAGE_END);
    add(pane);
}

From source file:components.FrameDemo2.java

/**
 * Create the GUI and show it.  For thread safety,
 * this method should be invoked from the
 * event-dispatching thread.//from   w w  w.j  a v a 2s. c  o  m
 */
private static void createAndShowGUI() {
    //Use the Java look and feel.
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
    }

    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

    //Instantiate the controlling class.
    JFrame frame = new JFrame("FrameDemo2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Create and set up the content pane.
    FrameDemo2 demo = new FrameDemo2();

    //Add components to it.
    Container contentPane = frame.getContentPane();
    contentPane.add(demo.createOptionControls(), BorderLayout.CENTER);
    contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END);
    frame.getRootPane().setDefaultButton(defaultButton);

    //Display the window.
    frame.pack();
    frame.setLocationRelativeTo(null); //center it
    frame.setVisible(true);
}

From source file:FrameDemo2.java

/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 *//* w  ww .ja va2 s . c om*/
private static void createAndShowGUI() {
    // Use the Java look and feel.
    try {
        UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    } catch (Exception e) {
    }

    // Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

    // Instantiate the controlling class.
    JFrame frame = new JFrame("FrameDemo2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    FrameDemo2 demo = new FrameDemo2();

    // Add components to it.
    Container contentPane = frame.getContentPane();
    contentPane.add(demo.createOptionControls(), BorderLayout.CENTER);
    contentPane.add(demo.createButtonPane(), BorderLayout.PAGE_END);
    frame.getRootPane().setDefaultButton(defaultButton);

    // Display the window.
    frame.pack();
    frame.setLocationRelativeTo(null); // center it
    frame.setVisible(true);
}

From source file:dnd.BasicDnD.java

public BasicDnD() {
    super(new BorderLayout());
    JPanel leftPanel = createVerticalBoxPanel();
    JPanel rightPanel = createVerticalBoxPanel();

    //Create a table model.
    DefaultTableModel tm = new DefaultTableModel();
    tm.addColumn("Column 0");
    tm.addColumn("Column 1");
    tm.addColumn("Column 2");
    tm.addColumn("Column 3");
    tm.addRow(new String[] { "Table 00", "Table 01", "Table 02", "Table 03" });
    tm.addRow(new String[] { "Table 10", "Table 11", "Table 12", "Table 13" });
    tm.addRow(new String[] { "Table 20", "Table 21", "Table 22", "Table 23" });
    tm.addRow(new String[] { "Table 30", "Table 31", "Table 32", "Table 33" });

    //LEFT COLUMN
    //Use the table model to create a table.
    table = new JTable(tm);
    leftPanel.add(createPanelForComponent(table, "JTable"));

    //Create a color chooser.
    colorChooser = new JColorChooser();
    leftPanel.add(createPanelForComponent(colorChooser, "JColorChooser"));

    //RIGHT COLUMN
    //Create a textfield.
    textField = new JTextField(30);
    textField.setText("Favorite foods:\nPizza, Moussaka, Pot roast");
    rightPanel.add(createPanelForComponent(textField, "JTextField"));

    //Create a scrolled text area.
    textArea = new JTextArea(5, 30);
    textArea.setText("Favorite shows:\nBuffy, Alias, Angel");
    JScrollPane scrollPane = new JScrollPane(textArea);
    rightPanel.add(createPanelForComponent(scrollPane, "JTextArea"));

    //Create a list model and a list.
    DefaultListModel listModel = new DefaultListModel();
    listModel.addElement("Martha Washington");
    listModel.addElement("Abigail Adams");
    listModel.addElement("Martha Randolph");
    listModel.addElement("Dolley Madison");
    listModel.addElement("Elizabeth Monroe");
    listModel.addElement("Louisa Adams");
    listModel.addElement("Emily Donelson");
    list = new JList(listModel);
    list.setVisibleRowCount(-1);/*w w  w .j  av a  2  s .  c o  m*/
    list.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    list.setTransferHandler(new TransferHandler() {

        public boolean canImport(TransferHandler.TransferSupport info) {
            // we only import Strings
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            if (dl.getIndex() == -1) {
                return false;
            }
            return true;
        }

        public boolean importData(TransferHandler.TransferSupport info) {
            if (!info.isDrop()) {
                return false;
            }

            // Check for String flavor
            if (!info.isDataFlavorSupported(DataFlavor.stringFlavor)) {
                displayDropLocation("List doesn't accept a drop of this type.");
                return false;
            }

            JList.DropLocation dl = (JList.DropLocation) info.getDropLocation();
            DefaultListModel listModel = (DefaultListModel) list.getModel();
            int index = dl.getIndex();
            boolean insert = dl.isInsert();
            // Get the current string under the drop.
            String value = (String) listModel.getElementAt(index);

            // Get the string that is being dropped.
            Transferable t = info.getTransferable();
            String data;
            try {
                data = (String) t.getTransferData(DataFlavor.stringFlavor);
            } catch (Exception e) {
                return false;
            }

            // Display a dialog with the drop information.
            String dropValue = "\"" + data + "\" dropped ";
            if (dl.isInsert()) {
                if (dl.getIndex() == 0) {
                    displayDropLocation(dropValue + "at beginning of list");
                } else if (dl.getIndex() >= list.getModel().getSize()) {
                    displayDropLocation(dropValue + "at end of list");
                } else {
                    String value1 = (String) list.getModel().getElementAt(dl.getIndex() - 1);
                    String value2 = (String) list.getModel().getElementAt(dl.getIndex());
                    displayDropLocation(dropValue + "between \"" + value1 + "\" and \"" + value2 + "\"");
                }
            } else {
                displayDropLocation(dropValue + "on top of " + "\"" + value + "\"");
            }

            /**  This is commented out for the basicdemo.html tutorial page.
                       **  If you add this code snippet back and delete the
                       **  "return false;" line, the list will accept drops
                       **  of type string.
                      // Perform the actual import.  
                      if (insert) {
            listModel.add(index, data);
                      } else {
            listModel.set(index, data);
                      }
                      return true;
            */
            return false;
        }

        public int getSourceActions(JComponent c) {
            return COPY;
        }

        protected Transferable createTransferable(JComponent c) {
            JList list = (JList) c;
            Object[] values = list.getSelectedValues();

            StringBuffer buff = new StringBuffer();

            for (int i = 0; i < values.length; i++) {
                Object val = values[i];
                buff.append(val == null ? "" : val.toString());
                if (i != values.length - 1) {
                    buff.append("\n");
                }
            }
            return new StringSelection(buff.toString());
        }
    });
    list.setDropMode(DropMode.ON_OR_INSERT);

    JScrollPane listView = new JScrollPane(list);
    listView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(listView, "JList"));

    //Create a tree.
    DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode("Mia Familia");
    DefaultMutableTreeNode sharon = new DefaultMutableTreeNode("Sharon");
    rootNode.add(sharon);
    DefaultMutableTreeNode maya = new DefaultMutableTreeNode("Maya");
    sharon.add(maya);
    DefaultMutableTreeNode anya = new DefaultMutableTreeNode("Anya");
    sharon.add(anya);
    sharon.add(new DefaultMutableTreeNode("Bongo"));
    maya.add(new DefaultMutableTreeNode("Muffin"));
    anya.add(new DefaultMutableTreeNode("Winky"));
    DefaultTreeModel model = new DefaultTreeModel(rootNode);
    tree = new JTree(model);
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    JScrollPane treeView = new JScrollPane(tree);
    treeView.setPreferredSize(new Dimension(300, 100));
    rightPanel.add(createPanelForComponent(treeView, "JTree"));

    //Create the toggle button.
    toggleDnD = new JCheckBox("Turn on Drag and Drop");
    toggleDnD.setActionCommand("toggleDnD");
    toggleDnD.addActionListener(this);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel, rightPanel);
    splitPane.setOneTouchExpandable(true);

    add(splitPane, BorderLayout.CENTER);
    add(toggleDnD, BorderLayout.PAGE_END);
    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}