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:PaintUtils.java

/**
 * Returns the bounds that the text of a label will be drawn into.
 * Takes into account the current font metrics.
 *///from w  w  w .  jav  a  2s.  co  m
public static Rectangle getTextBounds(Graphics g, JLabel label) {
    FontMetrics fm = g.getFontMetrics();
    Rectangle2D r2d = fm.getStringBounds(label.getText(), g);
    Rectangle rect = r2d.getBounds();
    int xOffset = 0;
    switch (label.getHorizontalAlignment()) {
    case SwingConstants.RIGHT:
    case SwingConstants.TRAILING:
        xOffset = label.getBounds().width - rect.width;
        break;
    case SwingConstants.CENTER:
        xOffset = (label.getBounds().width - rect.width) / 2;
        break;
    default:
    case SwingConstants.LEFT:
    case SwingConstants.LEADING:
        xOffset = 0;
        break;
    }
    int yOffset = 0;
    switch (label.getVerticalAlignment()) {
    case SwingConstants.TOP:
        yOffset = 0;
        break;
    case SwingConstants.CENTER:
        yOffset = (label.getBounds().height - rect.height) / 2;
        break;
    case SwingConstants.BOTTOM:
        yOffset = label.getBounds().height - rect.height;
        break;
    }
    return new Rectangle(xOffset, yOffset, rect.width, rect.height);
}

From source file:com.igormaznitsa.sciareto.ui.editors.PictureViewer.java

public PictureViewer(@Nonnull final Context context, @Nonnull final File file) throws IOException {
    super();/*from w w w . ja  va 2s .co m*/
    this.title = new TabTitle(context, this, file);
    this.label = new JLabel();

    this.label.setHorizontalTextPosition(JLabel.CENTER);
    this.label.setVerticalTextPosition(JLabel.CENTER);
    this.label.setHorizontalAlignment(SwingConstants.CENTER);
    this.label.setVerticalAlignment(SwingConstants.CENTER);

    loadContent(file);
}

From source file:edu.ku.brc.specify.config.init.DisciplinePanel.java

/**
 * Creates a dialog for entering database name and selecting the appropriate driver.
 *///from   w w w.j a  va 2s  .  c  o  m
public DisciplinePanel(final String helpContext, final JButton nextBtn, final JButton prevBtn) {
    super("DISCIPLINE", helpContext, nextBtn, prevBtn);

    String header = getResourceString("DISP_INFO") + ":";

    CellConstraints cc = new CellConstraints();

    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,p,f:p:g", "p,6px,p,2px,p"), this);
    int row = 1;

    builder.add(createLabel(header, SwingConstants.CENTER), cc.xywh(1, row, 3, 1));
    row += 2;

    Vector<DisciplineType> dispList = new Vector<DisciplineType>();
    for (DisciplineType disciplineType : DisciplineType.getDisciplineList()) {
        if (disciplineType.getType() == 0) {
            dispList.add(disciplineType);
        }
    }

    Collections.sort(dispList);

    disciplines = createComboBox(dispList);

    disciplines.setSelectedIndex(-1);

    // Discipline 
    JLabel lbl = createI18NFormLabel("DSP_TYPE", SwingConstants.RIGHT);
    lbl.setFont(bold);
    builder.add(lbl, cc.xy(1, row));
    builder.add(disciplines, cc.xy(3, row));
    row += 2;

    makeStretchy = true;
    disciplineName = createField(builder, "DISP_NAME", true, row, 64);
    row += 2;

    updateBtnUI();

    disciplines.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            updateBtnUI();

            if (disciplines.getSelectedIndex() > -1) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        DisciplineType dt = (DisciplineType) disciplines.getSelectedItem();
                        disciplineName.setText(dt.getTitle());
                    }
                });
            }
        }
    });
}

From source file:com.stefanbrenner.droplet.ui.DevicePanel.java

/**
 * Create the panel./* ww  w  .j av  a  2 s .c  o m*/
 */
public DevicePanel(final JComponent parent, final IDroplet droplet, final T device) {

    this.parent = parent;

    setDevice(device);

    setLayout(new BorderLayout(0, 5));
    setBorder(BorderFactory.createLineBorder(Color.BLACK));
    setBackground(DropletColors.getBackgroundColor(device));

    BeanAdapter<T> adapter = new BeanAdapter<T>(device, true);

    // device name textfield
    txtName = BasicComponentFactory.createTextField(adapter.getValueModel(IDevice.PROPERTY_NAME));
    txtName.setHorizontalAlignment(SwingConstants.CENTER);
    txtName.setColumns(1);
    txtName.setToolTipText(device.getName());
    adapter.addBeanPropertyChangeListener(IDevice.PROPERTY_NAME, new PropertyChangeListener() {

        @Override
        public void propertyChange(final PropertyChangeEvent event) {
            txtName.setToolTipText(device.getName());
        }
    });
    add(txtName, BorderLayout.NORTH);

    // actions panel with scroll pane
    actionsPanel = new JPanel();
    actionsPanel.setLayout(new BoxLayout(actionsPanel, BoxLayout.Y_AXIS));
    actionsPanel.setBackground(getBackground());

    JScrollPane scrollPane = new JScrollPane(actionsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    // resize vertical scrollbar
    scrollPane.getVerticalScrollBar().putClientProperty("JComponent.sizeVariant", "mini"); //$NON-NLS-1$ //$NON-NLS-2$
    SwingUtilities.updateComponentTreeUI(scrollPane);
    // we need no border
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    add(scrollPane, BorderLayout.CENTER);

    {
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));

        createAddButton(panel);

        // remove button
        JButton btnRemove = new JButton(Messages.getString("ActionDevicePanel.removeDevice")); //$NON-NLS-1$
        btnRemove.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent action) {
                int retVal = JOptionPane.showConfirmDialog(DevicePanel.this,
                        Messages.getString("ActionDevicePanel.removeDevice") + " '" + device.getName() + "'?", //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
                        StringUtils.EMPTY, JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (retVal == JOptionPane.YES_OPTION) {
                    droplet.removeDevice(device);
                }
            }
        });
        btnRemove.setFocusable(false);
        panel.add(btnRemove);

        add(panel, BorderLayout.SOUTH);
    }

}

From source file:edu.ku.brc.specify.ui.DBObjSearchDialog.java

/**
 * Constructs a search dialog from form infor and from search info.
 * @param viewSetName the viewset name/*from  www .j a  v  a 2s .  c om*/
 * @param viewName the form name from the viewset
 * @param searchName the search name, this is looked up by name in the "search_config.xml" file
 * @param title the title (should be already localized before passing in)
 * @param className the name of the class to be created from the selected results
 * @param idFieldName the name of the field in the clas that is the primary key which is filled in from the search table id
 * @throws HeadlessException an exception
 */
public DBObjSearchDialog(final Frame parent, final String viewSetName, final String viewName,
        final String searchName, final String title, final String className, final String idFieldName,
        final String helpContext) throws HeadlessException {
    super(parent, title, true, OK_BTN | CANCEL_BTN, null);

    if (StringUtils.isNotEmpty(helpContext)) {
        this.whichBtns |= HELP_BTN;
        setHelpContext(helpContext);
    }

    this.parent = parent;
    this.panel = new DBObjSearchPanel(viewSetName, viewName, searchName, className, idFieldName,
            SwingConstants.CENTER);
    if (panel == null) {
        log.error("ViewSet[" + viewSetName + "] View[" + viewName + "] searchName[" + searchName
                + "] className[" + className + "] could not be created.");
    }
}

From source file:channel.metadata.ChannelMetadataPanel.java

/**
 * Initializes the panel//from w ww .j  av a  2  s.  co  m
 */
private void init() {
    setLayout(new MigLayout("insets 0 0 0 0", "[grow,fill]", "[grow,fill]"));

    mTable = new JTable(mChannelProcessingManager.getChannelMetadataModel());

    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) mTable.getDefaultRenderer(String.class);
    renderer.setHorizontalAlignment(SwingConstants.CENTER);

    mTable.getSelectionModel().addListSelectionListener(this);
    mTable.addMouseListener(new MouseSupport());

    mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_STATE)
            .setCellRenderer(new ColoredStateCellRenderer());
    mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_PRIMARY_TO)
            .setCellRenderer(new AliasedValueCellRenderer(Attribute.PRIMARY_ADDRESS_TO));
    mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_PRIMARY_FROM)
            .setCellRenderer(new AliasedValueCellRenderer(Attribute.PRIMARY_ADDRESS_FROM));
    mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_SECONDARY_TO)
            .setCellRenderer(new AliasedValueCellRenderer(Attribute.SECONDARY_ADDRESS_TO));
    mTable.getColumnModel().getColumn(ChannelMetadataModel.COLUMN_SECONDARY_FROM)
            .setCellRenderer(new AliasedValueCellRenderer(Attribute.SECONDARY_ADDRESS_FROM));

    JScrollPane scrollPane = new JScrollPane(mTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    add(scrollPane);

    //        new TableColumnWidthMonitor(mTable, PROPERTY_PREFIX, new int[] {15,15,15,15,25,25,25,25,15,40});
}

From source file:de.tor.tribes.ui.components.TimePicker.java

private void initSpecialComponents() {
    for (int i = 0; i < hourLabels.length; i++) {
        CrossedLabel label = new CrossedLabel();
        hourLabels[i] = label;//from  ww  w. ja  va 2s. com

        if (i < 10) {
            label.setText("0" + Integer.toString(i));
        } else {
            label.setText(Integer.toString(i));
        }

        label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label.setBorder(javax.swing.BorderFactory.createLineBorder(Constants.DS_BACK));
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setOpaque(true);
        label.setBackground(Constants.DS_BACK_LIGHT);
        label.setFont(smallFont);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (selectedHour != null) {
                    selectedHour.uncross();
                }
                selectedHour = ((CrossedLabel) e.getSource());
                selectedHour.cross();

                for (int i = 0; i < hourLabels.length; i++)
                    if (hourLabels[i] == selectedHour) {
                        pHour = i;
                        break;
                    }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                ((CrossedLabel) e.getSource()).setBackground(highlight);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                ((CrossedLabel) e.getSource()).setBackground(Constants.DS_BACK_LIGHT);
            }
        });
    }
    addHourLabels();

    for (int i = 0; i < minuteLabels.length; i++) {
        CrossedLabel label = new CrossedLabel();
        minuteLabels[i] = label;

        if (i < 10) {
            label.setText(":0" + Integer.toString(i));
        } else {
            label.setText(":" + Integer.toString(i));
        }

        label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        label.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));
        label.setHorizontalAlignment(SwingConstants.CENTER);
        label.setOpaque(true);
        label.setBackground(Color.WHITE);
        label.setFont(smallFont);
        label.addMouseListener(new MouseListener() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (selectedMinute != null) {
                    selectedMinute.uncross();
                }
                selectedMinute = ((CrossedLabel) e.getSource());
                selectedMinute.cross();

                for (int i = 0; i < minuteLabels.length; i++)
                    if (minuteLabels[i] == selectedMinute) {
                        pMinute = i;
                        break;
                    }
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                ((CrossedLabel) e.getSource()).setBackground(highlight);
            }

            @Override
            public void mouseExited(MouseEvent e) {
                ((CrossedLabel) e.getSource()).setBackground(Color.WHITE);
            }
        });
    }
    addMinuteLabels(false);
}

From source file:edu.ku.brc.ui.ProgressFrame.java

/**
 * @param title/*from  w ww  .  j ava  2s  .  c om*/
 * @param iconName
 */
protected void createUI(final String title, final String iconName) {
    PanelBuilder builder = new PanelBuilder(new FormLayout("p,2px,f:p:g", "p,5px,p,5px,p,10px,p"));
    CellConstraints cc = new CellConstraints();

    overallProgress = new JProgressBar();
    processProgress = new JProgressBar();
    desc = createLabel("");
    closeBtn = createButton("Cancel");

    processProgress.setStringPainted(true);
    overallProgress.setStringPainted(true);

    desc.setHorizontalAlignment(SwingConstants.CENTER);
    builder.add(desc, cc.xywh(1, 1, 3, 1));

    builder.add(createLabel("Process:"), cc.xy(1, 3)); // I18N
    builder.add(processProgress, cc.xy(3, 3));

    builder.add(overallLbl = createLabel("Overall:"), cc.xy(1, 5)); // I18N
    builder.add(overallProgress, cc.xy(3, 5));

    builder.add(closeBtn, cc.xy(1, 7));

    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel mainPanel = new JPanel(new BorderLayout());
    if (StringUtils.isNotEmpty(iconName)) {
        PanelBuilder iconBldr = new PanelBuilder(
                new FormLayout("8px, f:p:g,130px,f:p:g", "8px,f:p:g,130px,f:p:g, 8px"));
        iconBldr.add(new JLabel(IconManager.getIcon(iconName)), cc.xy(3, 3));
        mainPanel.add(iconBldr.getPanel(), BorderLayout.WEST);
        mainPanel.add(builder.getPanel(), BorderLayout.CENTER);

    } else {
        mainPanel = builder.getPanel();
    }

    setContentPane(mainPanel);

    setSize(new Dimension(500, 125));

    setTitle(title);

    overallProgress.setIndeterminate(true);

    instance = this;
    closeBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            instance.setVisible(false);
            System.exit(0);
        }
    });

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    ImageIcon appIcon = IconManager.getIcon("AppIcon"); //$NON-NLS-1$
    if (appIcon != null) {
        setIconImage(appIcon.getImage());
    }

    pack();
}

From source file:com.aw.core.format.FillerFormat.java

public static String fillFormat(String source, char fillerCharacter, int length, int aligment,
        boolean fillInclusiveEmptyString) {
    if (StringUtils.isEmpty(source))
        return source;

    if (source.length() > length)
        return source.substring(0, length);
    //throw new AWBusinessException("No se puede llenar '"+source+"' pues tamao excede "+length);
    source = source.trim();//from  ww w .j a  va  2  s  .  c  o m
    if (source.length() == length)
        return source;
    if (!fillInclusiveEmptyString && source.length() == 0)
        return source;

    if (source.length() > length)
        return source.substring(0, length);

    StringBuffer buf = new StringBuffer(length);

    if (aligment == SwingConstants.CENTER) {
        int left = (length - source.length()) / 2;
        int right = length - (source.length() + left);
        fill(buf, fillerCharacter, left);
        buf.append(source);
        fill(buf, fillerCharacter, right);
    } else {
        if (aligment == SwingConstants.LEFT)
            buf.append(source);
        fill(buf, fillerCharacter, length - source.length());
        if (aligment == SwingConstants.RIGHT)
            buf.append(source);
    }
    return buf.toString();
}

From source file:edu.harvard.mcz.imagecapture.TemplatePickerDialog.java

protected void init(ICImage image) {
    setBounds(100, 100, 450, 300);/*w ww  .j av  a 2 s. c  om*/
    StringBuffer title = new StringBuffer();
    title.append("Change Template");
    if (image != null) {
        title.append(" for ").append(image.getFilename());
    }
    this.setTitle(title.toString());
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new BorderLayout(0, 0));
    {
        lblTemplate = new JLabel("Template");
        lblTemplate.setHorizontalAlignment(SwingConstants.CENTER);
        contentPanel.add(lblTemplate, BorderLayout.NORTH);
    }
    {
        comboBoxTemplatePicker = new JComboBox<String>();
        comboBoxTemplatePicker.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                // TODO Auto-generated method stub
                PositionTemplate defaultTemplate;
                try {
                    defaultTemplate = new PositionTemplate((String) comboBoxTemplatePicker.getSelectedItem());

                    File fileToCheck = new File(ImageCaptureProperties
                            .assemblePathWithBase(imageToTemplate.getPath(), imageToTemplate.getFilename()));

                    BufferedImage imagefile = ImageIO.read(fileToCheck);

                    int x = defaultTemplate.getBarcodeULPosition().width;
                    int y = defaultTemplate.getBarcodeULPosition().height;
                    int w = defaultTemplate.getBarcodeSize().width;
                    int h = defaultTemplate.getBarcodeSize().height;
                    setBarcodeImage(imagefile.getSubimage(x, y, w, h));

                } catch (NullPointerException e1) {
                    log.error(e1.getMessage());
                } catch (NoSuchTemplateException e1) {
                    log.error(e1.getMessage());
                } catch (IOException e1) {
                    log.error(e1.getMessage());
                }
            }

        });
        contentPanel.add(comboBoxTemplatePicker, BorderLayout.SOUTH);
    }
    {
        JPanel panel = new JPanel();
        contentPanel.add(panel, BorderLayout.CENTER);
        panel.setLayout(new BorderLayout(0, 0));
        {
            lblFileName = new JLabel("FileName");
            panel.add(lblFileName, BorderLayout.NORTH);
        }
        {
            labelBarcodeImage = new JLabel("Catalog Number Barcode");
            labelBarcodeImage.setIcon(new ImageIcon(TemplatePickerDialog.class
                    .getResource("/edu/harvard/mcz/imagecapture/resources/gnome-mime-image.png")));
            panel.add(labelBarcodeImage, BorderLayout.CENTER);
        }
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("OK");
            okButton.setActionCommand("OK");
            okButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    // TODO Auto-generated method stub
                    ICImageLifeCycle ils = new ICImageLifeCycle();
                    try {
                        String newTemplateID = (String) comboBoxTemplatePicker.getSelectedItem();
                        if (newTemplateID != null) {
                            imageToTemplate.setTemplateId(newTemplateID);
                            ils.attachDirty(imageToTemplate);
                            setVisible(false);
                        }
                    } catch (SaveFailedException e1) {
                        log.error(e1.getMessage(), e1);
                    }
                }

            });
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.setActionCommand("Cancel");
            cancelButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    setVisible(false);
                }

            });
            buttonPane.add(cancelButton);
        }
    }
    if (image != null) {
        try {
            boolean result = setupForImage(image);
        } catch (UnreadableFileException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}