Package ipm.gerdc.baccarat.util

Source Code of ipm.gerdc.baccarat.util.UIFactory

/**
* @Author: Edmond Hoi
* @Description: IPM-ESAP-GERDC
* @Date: 2010.09.01
*/
package ipm.gerdc.baccarat.util;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.table.TableModel;

public class UIFactory {
  public static Box.Filler addSmallSpace() {
    return addSpace(5, 5, 5);
  }

  public static Box.Filler addSpace(int mx, int wd, int ht) {
    return new Box.Filler(new Dimension(wd, ht), new Dimension(mx - wd, ht), new Dimension(mx, ht));
  }

  public static Font makeFonts(int fontsize) {
    if (fontsize >= 20) {
      return new Font(TextFactory.textList.get("FontName"), Font.BOLD, fontsize);
    } else {
      return new Font(TextFactory.textList.get("FontName"), Font.PLAIN, fontsize);
    }
  }

  public static ImageIcon makeImageIcon(String image) {
    return new ImageIcon(UIFactory.class.getResource("images/" + image + (Character.isUpperCase(image.charAt(0)) ? ".jpg" : ".png")));
  }

  public static JButton makeImageButton(String name, String image, ActionListener al) {
    JButton button = makeJButton(name, image, al);
    button.setHorizontalTextPosition(JButton.CENTER);
    button.setVerticalTextPosition(JButton.CENTER);
    button.setForeground(Color.white);
    button.setFont(UIFactory.makeFonts(38));
    button.setBorder(null);
    return button;
  }

  public static JButton makeJButton(String name, String image, ActionListener al) {
    JButton button = new JButton(name, UIFactory.makeImageIcon(image.length() == 0 ? name : image));
    button.setToolTipText(name);
    button.addActionListener(al);
    return button;
  }

  public static JLabel makeJLabel(String name, int fontsize) {
    JLabel label = new JLabel(name);
    label.setFont(makeFonts(fontsize));
    return label;
  }

  public static JPanel makeJPanel(String type) {
    JPanel panel = new JPanel();
    if (type.equals("LEFT")) {
      panel.setLayout(new FlowLayout(FlowLayout.LEFT));
    } else if (type.equals("CENTER")) {
      panel.setLayout(new FlowLayout(FlowLayout.CENTER));
    } else if (type.equals("RIGHT")) {
      panel.setLayout(new FlowLayout(FlowLayout.RIGHT));
    }
    return panel;
  }

  public static JSlider makeJSlider(int min, int max, int value) {
    JSlider slider = new JSlider(JSlider.HORIZONTAL, min, max, value);
    slider.setMinorTickSpacing(5);
    slider.setMajorTickSpacing(100);
    slider.setPaintTicks(true);
    slider.setPaintLabels(true);
    slider.setLabelTable(slider.createStandardLabels(10));
    slider.setPreferredSize(new Dimension(380, 50));
    return slider;
  }

  public static JTextField makeJTextField(int size, int fontsize) {
    JTextField textField = new JTextField(size);
    textField.setFont(makeFonts(fontsize));
    return textField;
  }

  public static JToggleButton makeJToggleButton(String name, String image, ActionListener al) {
    JToggleButton button = new JToggleButton(name, makeImageIcon(image.length() == 0 ? name : image));
    button.setToolTipText(name);
    button.setBorder(null);
    button.addActionListener(al);
    return button;
  }

  public static void setColumnSizes(JTable table, TableModel model, int columns[]) {
    for (int i = 0; i < columns.length; i++) {
      table.getColumnModel().getColumn(i).setPreferredWidth(columns[i]);
    }
  }

  public static final UIFactory INSTANCE = new UIFactory();
}
TOP

Related Classes of ipm.gerdc.baccarat.util.UIFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.