001: /*
002: * Copyright (C) 2004-2005 Nicky BRAMANTE
003: *
004: * This file is part of FreeQueryBuilder
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
019: *
020: * Send questions or suggestions to nickyb@users.sourceforge.net
021: */
022:
023: package it.frb.admin;
024:
025: import java.awt.Color;
026: import java.awt.Component;
027: import java.awt.Dimension;
028: import java.awt.Font;
029: import java.awt.Frame;
030: import java.awt.Graphics;
031: import java.awt.Insets;
032: import java.awt.Window;
033: import java.awt.event.ActionListener;
034:
035: import javax.swing.AbstractButton;
036: import javax.swing.Action;
037: import javax.swing.Icon;
038: import javax.swing.ImageIcon;
039: import javax.swing.JButton;
040: import javax.swing.SwingUtilities;
041: import javax.swing.UIManager;
042:
043: import javax.swing.border.EmptyBorder;
044: import javax.swing.border.LineBorder;
045:
046: public class UIUtilities {
047: public final static String MAJOR_VERSION = "2005";
048: public final static String MINOR_VERSION = "06_01";
049:
050: public final static Dimension CUSTOM_BUTTON_DIMENSION = new Dimension(
051: 80, 20);
052: public final static EmptyBorder NO_BORDER = new EmptyBorder(0, 0,
053: 0, 0);
054:
055: public static AbstractButton customize(AbstractButton btn) {
056: return setAllSize(btn, CUSTOM_BUTTON_DIMENSION);
057: }
058:
059: public static AbstractButton setAllSize(AbstractButton btn,
060: Dimension dim) {
061: btn.setPreferredSize(dim);
062: btn.setMaximumSize(dim);
063: btn.setMinimumSize(dim);
064:
065: return btn;
066: }
067:
068: public static JButton createCustomButton(Action a) {
069: return (JButton) customize(new JButton(a));
070: }
071:
072: public static JButton createCustomButton(String text) {
073: return (JButton) customize(new JButton(text));
074: }
075:
076: public static JButton createCustomButton(String text,
077: ActionListener l) {
078: JButton btn = createCustomButton(text);
079: btn.addActionListener(l);
080:
081: return btn;
082: }
083:
084: public static Frame getFrameAncestor(Component component) {
085: if (component instanceof Frame)
086: return (Frame) component;
087:
088: Window window = SwingUtilities.getWindowAncestor(component);
089:
090: if (window instanceof Frame)
091: return (Frame) window;
092:
093: return null;
094: }
095:
096: public static void centerOnScreen(Window window) {
097: Dimension dimScreen = window.getToolkit().getScreenSize();
098: Dimension dimThis = window.getSize();
099:
100: window.setLocation((dimScreen.width / 2) - (dimThis.width / 2),
101: (dimScreen.height / 2) - (dimThis.height / 2));
102: }
103:
104: public static void fullScreen(Window window) {
105: Dimension dimScreen = window.getToolkit().getScreenSize();
106:
107: window.setLocation(-4, -4);
108: window.setSize(dimScreen.width + 8, dimScreen.height + 8);
109: }
110: }
|