Example usage for javax.swing SwingConstants CENTER

List of usage examples for javax.swing SwingConstants CENTER

Introduction

In this page you can find the example usage for javax.swing SwingConstants CENTER.

Prototype

int CENTER

To view the source code for javax.swing SwingConstants CENTER.

Click Source Link

Document

The central position in an area.

Usage

From source file:org.eclipse.om2m.ipe.sample.gui.GUI.java

/**
 * Creates the frame.// w  ww  . j  av  a  2 s . c  o  m
 */
public GUI() {
    setLocationByPlatform(true);
    setVisible(false);
    setResizable(false);
    setTitle("Sample Simulated IPE");
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 500) / 2, (screenSize.height - 570) / 2, 497, 570);

    contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPanel);
    contentPanel.setLayout(null);

    // Lamp0 Switcher0
    JPanel panel_Lamp0 = new JPanel();
    panel_Lamp0.setBounds(10, 5, 319, 260);
    contentPanel.add(panel_Lamp0);
    panel_Lamp0.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp0.setLayout(null);
    LABEL_LAMP_0.setIcon(iconLampOFF);
    LABEL_LAMP_0.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_0.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_0.setBounds(10, 9, 149, 240);
    panel_Lamp0.add(LABEL_LAMP_0);

    // Lamp0 Switch Button
    JButton button_Lamp0 = new JButton();
    button_Lamp0.setOpaque(false);
    button_Lamp0.setPressedIcon(iconButtonON);
    button_Lamp0.setIcon(iconButtonOFF);
    button_Lamp0.setBounds(187, 44, 122, 155);
    panel_Lamp0.add(button_Lamp0);
    button_Lamp0.setMinimumSize(new Dimension(30, 23));
    button_Lamp0.setMaximumSize(new Dimension(30, 23));
    button_Lamp0.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher0 = new JLabel("Switch LAMP_0");
    labelSwitcher0.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher0.setFocusCycleRoot(true);
    labelSwitcher0.setBorder(null);
    labelSwitcher0.setAutoscrolls(true);
    labelSwitcher0.setBounds(187, 199, 118, 29);
    panel_Lamp0.add(labelSwitcher0);
    // Listener for Lamp0 Switch Button
    button_Lamp0.addActionListener(new java.awt.event.ActionListener() {
        // Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp0 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp0 state
                    SampleMonitor.switchLamp(LAMP_0);
                }
            }.start();
        }
    });

    // Lamp1 Switcher 1
    JPanel panel_Lamp1 = new JPanel();
    panel_Lamp1.setBounds(10, 271, 319, 260);
    contentPanel.add(panel_Lamp1);
    panel_Lamp1.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp1.setLayout(null);

    LABEL_LAMP_1.setIcon(iconLampOFF);
    LABEL_LAMP_1.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_1.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_1.setBounds(10, 9, 154, 240);
    panel_Lamp1.add(LABEL_LAMP_1);

    // Lamp1 Switch Button
    JButton button_Lamp1 = new JButton();
    button_Lamp1.setOpaque(false);
    button_Lamp1.setPressedIcon(iconButtonON);
    button_Lamp1.setIcon(iconButtonOFF);
    button_Lamp1.setBounds(187, 44, 122, 156);
    panel_Lamp1.add(button_Lamp1);
    button_Lamp1.setMinimumSize(new Dimension(30, 23));
    button_Lamp1.setMaximumSize(new Dimension(30, 23));
    button_Lamp1.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher1 = new JLabel("Switch LAMP_1");
    labelSwitcher1.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher1.setFocusCycleRoot(true);
    labelSwitcher1.setBorder(null);
    labelSwitcher1.setAutoscrolls(true);
    labelSwitcher1.setBounds(187, 199, 118, 29);
    panel_Lamp1.add(labelSwitcher1);
    // Listener for Lamp1 Switch Button
    button_Lamp1.addActionListener(new java.awt.event.ActionListener() {
        //Switch Button clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp1 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp1 state
                    SampleMonitor.switchLamp(LAMP_1);
                }
            }.start();
        }
    });

    // Switcher All lamps
    JButton buttonAllLamp = new JButton();
    buttonAllLamp.setOpaque(false);
    buttonAllLamp.setPressedIcon(iconButtonON);
    buttonAllLamp.setIcon(iconButtonOFF);
    buttonAllLamp.setBounds(339, 190, 145, 168);
    contentPanel.add(buttonAllLamp);
    buttonAllLamp.setMinimumSize(new Dimension(30, 23));
    buttonAllLamp.setMaximumSize(new Dimension(30, 23));
    buttonAllLamp.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitchAll = new JLabel("Switch All");
    labelSwitchAll.setAutoscrolls(true);
    labelSwitchAll.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitchAll.setFocusCycleRoot(true);
    labelSwitchAll.setBorder(null);
    labelSwitchAll.setBounds(371, 369, 85, 29);
    contentPanel.add(labelSwitchAll);
    // Listener of Switch all Button
    buttonAllLamp.addActionListener(new java.awt.event.ActionListener() {
        // Switch Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change all lamps states
            new Thread() {
                public void run() {
                    // Send switch all request to create a content with the current State
                    SampleMonitor.switchAll();
                }
            }.start();
        }
    });

    lampObserver = new SampleModel.LampObserver() {

        @Override
        public void onLampStateChange(String lampId, boolean state) {
            setLabel(lampId, state);
        }
    };
    SampleModel.addObserver(lampObserver);
}

From source file:org.eclipse.om2m.ipu.sample.GUI.java

/**
 * Creates the frame./*from w w  w  . ja  v a2s  .  c  o  m*/
 */
public GUI() {
    setLocationByPlatform(true);
    setResizable(false);
    setTitle("Sample Simulated IPU");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setBounds((screenSize.width - 500) / 2, (screenSize.height - 570) / 2, 497, 570);

    contentPanel = new JPanel();
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPanel);
    contentPanel.setLayout(null);

    // Lamp0 Switcher0
    JPanel panel_Lamp0 = new JPanel();
    panel_Lamp0.setBounds(10, 5, 319, 260);
    contentPanel.add(panel_Lamp0);
    panel_Lamp0.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp0.setLayout(null);
    LABEL_LAMP_0.setIcon(iconLampOFF);
    LABEL_LAMP_0.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_0.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_0.setBounds(10, 9, 149, 240);
    panel_Lamp0.add(LABEL_LAMP_0);

    // Lamp0 Switch Button
    JButton button_Lamp0 = new JButton();
    button_Lamp0.setOpaque(false);
    button_Lamp0.setPressedIcon(iconButtonON);
    button_Lamp0.setIcon(iconButtonOFF);
    button_Lamp0.setBounds(187, 44, 122, 155);
    panel_Lamp0.add(button_Lamp0);
    button_Lamp0.setMinimumSize(new Dimension(30, 23));
    button_Lamp0.setMaximumSize(new Dimension(30, 23));
    button_Lamp0.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher0 = new JLabel("Switch LAMP_0");
    labelSwitcher0.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher0.setFocusCycleRoot(true);
    labelSwitcher0.setBorder(null);
    labelSwitcher0.setAutoscrolls(true);
    labelSwitcher0.setBounds(187, 199, 118, 29);
    panel_Lamp0.add(labelSwitcher0);
    // Listener for Lamp0 Switch Button
    button_Lamp0.addActionListener(new java.awt.event.ActionListener() {
        // Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp0 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp0 state
                    Switchs.switchLamp(LAMP_0, !SampleMonitor.LAMPS.get(LAMP_0).getState());
                }
            }.start();
        }
    });

    // Lamp1 Switcher 1
    JPanel panel_Lamp1 = new JPanel();
    panel_Lamp1.setBounds(10, 271, 319, 260);
    contentPanel.add(panel_Lamp1);
    panel_Lamp1.setBorder(new LineBorder(new Color(0, 0, 0), 1, true));
    panel_Lamp1.setLayout(null);

    LABEL_LAMP_1.setIcon(iconLampOFF);
    LABEL_LAMP_1.setHorizontalTextPosition(SwingConstants.CENTER);
    LABEL_LAMP_1.setHorizontalAlignment(SwingConstants.CENTER);
    LABEL_LAMP_1.setBounds(10, 9, 154, 240);
    panel_Lamp1.add(LABEL_LAMP_1);

    // Lamp1 Switch Button
    JButton button_Lamp1 = new JButton();
    button_Lamp1.setOpaque(false);
    button_Lamp1.setPressedIcon(iconButtonON);
    button_Lamp1.setIcon(iconButtonOFF);
    button_Lamp1.setBounds(187, 44, 122, 156);
    panel_Lamp1.add(button_Lamp1);
    button_Lamp1.setMinimumSize(new Dimension(30, 23));
    button_Lamp1.setMaximumSize(new Dimension(30, 23));
    button_Lamp1.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitcher1 = new JLabel("Switch LAMP_1");
    labelSwitcher1.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitcher1.setFocusCycleRoot(true);
    labelSwitcher1.setBorder(null);
    labelSwitcher1.setAutoscrolls(true);
    labelSwitcher1.setBounds(187, 199, 118, 29);
    panel_Lamp1.add(labelSwitcher1);
    // Listener for Lamp1 Switch Button
    button_Lamp1.addActionListener(new java.awt.event.ActionListener() {
        //Switch Button clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change Lamp1 State
            new Thread() {
                public void run() {
                    // Send switch request to switch lamp1 state
                    Switchs.switchLamp(LAMP_1, !SampleMonitor.LAMPS.get(LAMP_1).getState());
                }
            }.start();
        }
    });

    // Switcher All lamps
    JButton buttonAllLamp = new JButton();
    buttonAllLamp.setOpaque(false);
    buttonAllLamp.setPressedIcon(iconButtonON);
    buttonAllLamp.setIcon(iconButtonOFF);
    buttonAllLamp.setBounds(339, 190, 145, 168);
    contentPanel.add(buttonAllLamp);
    buttonAllLamp.setMinimumSize(new Dimension(30, 23));
    buttonAllLamp.setMaximumSize(new Dimension(30, 23));
    buttonAllLamp.setPreferredSize(new Dimension(30, 23));

    JLabel labelSwitchAll = new JLabel("Switch All");
    labelSwitchAll.setAutoscrolls(true);
    labelSwitchAll.setFont(new Font("Vani", Font.BOLD | Font.ITALIC, 14));
    labelSwitchAll.setFocusCycleRoot(true);
    labelSwitchAll.setBorder(null);
    labelSwitchAll.setBounds(371, 369, 85, 29);
    contentPanel.add(labelSwitchAll);
    // Listener of Switch all Button
    buttonAllLamp.addActionListener(new java.awt.event.ActionListener() {
        // Switch Button Clicked
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            // Change all lamps states
            new Thread() {
                public void run() {
                    // Send switch all request to create a content with the current State
                    Switchs.switchAll(!(SampleMonitor.LAMPS.get(LAMP_0).getState()
                            && SampleMonitor.LAMPS.get(LAMP_1).getState()));
                }
            }.start();
        }
    });
}

From source file:org.executequery.base.DockedTabContainer.java

/**
 * Returns the tab pane at the specified position.
 *
 * @param position - the position of the pane
 *//*from w  ww.j a  va  2  s  .c om*/
protected TabPane getTabPaneForPosition(int position) {
    switch (position) {
    case SwingConstants.NORTH:
    case SwingConstants.NORTH_WEST:
    case SwingConstants.NORTH_EAST:
        return northTabPane;
    case SwingConstants.SOUTH:
    case SwingConstants.SOUTH_WEST:
    case SwingConstants.SOUTH_EAST:
        return southTabPane;
    case SwingConstants.CENTER:
        return scrollingTabPane;
    }
    return null;
}

From source file:org.executequery.base.DockedTabContainer.java

protected int getTabPanePosition(DockedTabPane tabPane) {
    if (tabPane == northTabPane) {
        if (orientation == SwingConstants.WEST) {
            return SwingConstants.NORTH_WEST;
        } else {/*from w  w  w.ja v  a2  s.  c o  m*/
            return SwingConstants.NORTH_EAST;
        }
    } else if (tabPane == southTabPane) {
        if (orientation == SwingConstants.WEST) {
            return SwingConstants.SOUTH_WEST;
        } else if (orientation == SwingConstants.CENTER) {
            return SwingConstants.SOUTH;
        } else {
            return SwingConstants.SOUTH_EAST;
        }
    }
    return SwingConstants.NORTH_WEST; // default
}

From source file:org.executequery.base.DockedTabContainer.java

/**
 * Overrides here to return an appropriate size
 * depneding on orinetation/position and visibility
 * of the minimised buttons panel./*from  w  ww.java  2 s  .  c  o  m*/
 *
 * @return this components preferred size
 */
public Dimension getPreferredSize() {
    if (buttonPanel == null) {
        return new Dimension(splitPane.getWidth(), getHeight());
    } else {
        if (orientation == SwingConstants.CENTER) {
            return new Dimension(getWidth(), buttonPanel.getHeight());
        } else {
            return new Dimension(buttonPanel.getWidth(), getHeight());
        }
    }
}

From source file:org.executequery.base.DockedTabContainer.java

/**
 * Adds the specified component as a docked tab component
 * in the specified position.//w  w w  .  j ava 2s . c  om
 *
 * @param the tab title
 * @param the tab icon
 * @param the component
 * @param the tab's tool tip
 * @param the position - one of SwingConstants.NORTH | SOUTH
 */
public void addDockedTab(String title, Icon icon, Component component, String tip, int position) {

    // make sure the split pane is visible
    splitPane.setVisible(true);

    DockedTabPane tabPane = null;

    // check if we have a north tab pane.
    // if not, add there regardless of specified position
    if (northTabPane == null && orientation != CENTER) {

        northTabPane = new DockedTabPane(this);
        splitPane.setLeftComponent(northTabPane);
        tabPane = northTabPane;

        // if we have minimised tabs but added a tab pane
        // restore it to its previous size
        //if (buttonPanel != null) {
        //desktopMediator.resetPaneToPreferredSizes(orientation, true);
        //}

    } else {

        switch (position) {
        case SwingConstants.NORTH:
        case SwingConstants.NORTH_WEST:
        case SwingConstants.NORTH_EAST:
            tabPane = northTabPane;
            break;
        case SwingConstants.SOUTH:
        case SwingConstants.SOUTH_WEST:
        case SwingConstants.SOUTH_EAST:
            if (southTabPane == null) {
                southTabPane = new DockedTabPane(this);
                southPaneCreated();
            }
            tabPane = southTabPane;
            break;
        case SwingConstants.CENTER:
            if (scrollingTabPane == null) {
                scrollingTabPane = new ScrollingTabPane(this);
                splitPane.setLeftComponent(scrollingTabPane);
                splitPane.setGlassPaneVisible(SwingUtilities.BOTTOM, true);
                splitPane.setGlassPaneVisible(SwingUtilities.TOP, false);
                splitPane.setResizeWeight(1.0);
                if (southTabPane != null) {
                    splitPane.setDividerSize(ApplicationConstants.SPLIT_PANE_DIVIDER_SIZE);
                }
            }
            scrollingTabPane.addTab(position, title, icon, component, tip);
            return;
        }

    }

    if (tabPane != null) {
        tabPane.addTab(position, title, icon, component, tip);
    }

    if (orientation != SwingConstants.CENTER) {
        desktopMediator.resetPaneToPreferredSizes(orientation, true);
    }

}

From source file:org.executequery.base.DockedTabContainer.java

private TabComponent getTabComponent(String title) {

    String tabTitle = title.toUpperCase();
    int[] positions = { SwingConstants.NORTH, SwingConstants.SOUTH, SwingConstants.CENTER };
    for (int tabPosition : positions) {

        List<TabComponent> tabs = getOpenTabs(tabPosition);
        if (tabs != null) {

            for (TabComponent tab : tabs) {

                if (StringUtils.startsWithIgnoreCase(tab.getTitle(), tabTitle)) {

                    return tab;
                }//from  w  w w .jav  a 2  s . c o m

            }
        }

    }

    return null;
}

From source file:org.executequery.base.DockedTabContainer.java

/**
 * Removes the specified tab pane from this component.
 *
 * @param the tab pane to be removed/*from   ww  w.jav a  2s . c  o m*/
 */
protected void removeTabPane(DockedTabPane tabPane) {
    if (tabPane == northTabPane && orientation != SwingConstants.CENTER) {
        splitPane.setLeftComponent(null);
        northTabPane = null;
        // if we have a south pane, switch it
        if (southTabPane != null) {
            northTabPane = southTabPane;
            southPaneRemoved();
            splitPane.setLeftComponent(northTabPane);
        }
    } else if (tabPane == southTabPane) {
        southPaneRemoved();
    }

    // if they're both null and this is not the 
    // center component - hide the split pane
    if (orientation != SwingConstants.CENTER && northTabPane == null && southTabPane == null) {
        splitPane.setVisible(false);

        // if the button panel is null also, remove this panel
        if (buttonPanel == null) {

            if (minimisedComponents != null) {
                minimisedComponents.clear();
                minimisedComponents = null;
            }
            desktopMediator.removeDockedContainer(this);
            return;
        }
    }

    if (splitPane.isVisible()) {
        splitPane.validate();
    } else {
        desktopMediator.resetPaneToPreferredSizes(orientation, false);
    }
    validate();
    repaint();
}

From source file:org.executequery.base.DockedTabContainer.java

/** 
 * Restores the specified tab component from a minimised state.
 *
 * @param the tab component to restore//from w  ww . java2s. co  m
 */
protected void restoreTabComponent(TabComponent tabComponent) {
    //boolean restore = false;
    minimisedComponents.remove(tabComponent);

    if (minimisedComponents.size() == 0) {
        remove(buttonPanel);
        buttonPanel = null;
    }

    if (orientation != SwingConstants.CENTER) {
        // a restored tab is always added to the north pane
        if (northTabPane == null) {
            northTabPane = new DockedTabPane(this);
            // check the split pane
            if (splitPane == null) {
                initSplitPane();
            } else if (!splitPane.isVisible()) {
                splitPane.setVisible(true);
            }
            splitPane.setLeftComponent(northTabPane);
            desktopMediator.resetPaneToPreferredSizes(orientation, true);
        }
        northTabPane.addTab(tabComponent);
        northTabPane.setSelectedTab(tabComponent);
    } else { // for center only
        if (southTabPane == null) {
            southTabPane = new DockedTabPane(this);
            southPaneCreated();
        }
        southTabPane.addTab(tabComponent);
        southTabPane.setSelectedTab(tabComponent);
    }

    validate();
    repaint();

    // fire the event
    fireTabRestored(new DockedTabEvent(tabComponent));
}

From source file:org.exist.launcher.Launcher.java

protected void showMessageAndExit(String title, String message, boolean logs) {
    final JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    final JLabel label = new JLabel(message);
    label.setHorizontalAlignment(SwingConstants.CENTER);
    panel.add(label, BorderLayout.CENTER);
    if (logs) {/*from   ww  w . ja va  2  s . c o  m*/
        final JButton displayLogs = new JButton("View Log");
        displayLogs.addActionListener(new LogActionListener());
        label.setHorizontalAlignment(SwingConstants.CENTER);
        panel.add(displayLogs, BorderLayout.SOUTH);
    }

    utilityPanel.showMessages();
    utilityPanel.toFront();
    utilityPanel.setVisible(true);

    JOptionPane.showMessageDialog(splash, panel, title, JOptionPane.WARNING_MESSAGE);
    //System.exit(SystemExitCodes.CATCH_ALL_GENERAL_ERROR_EXIT_CODE);
}