Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/main/java/UI/BLeveledButtonUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,51 @@
import java.awt.*;

/**
* Created by IntelliJ IDEA.
* User: yezheng
* Date: 2006-7-22
* Time: 15:25:17
* To change this template use File | Settings | File Templates.
* BLeveledButtonUI.java
* This class extends BasicButtonUI to create a custom button UI with leveled borders.
* It changes the button's border based on its rollover state.
*/

public class BLeveledButtonUI extends BasicButtonUI {

private static Border border1 = BorderFactory.createRaisedBevelBorder();
private static Border border2 = BorderFactory.createEtchedBorder();//createEtchedBorder(Color.white,Color.gray.brighter());//.createMatteBorder(2,2,2,2,Color.LIGHT_GRAY);//.createEmptyBorder(2, 2, 2, 2);

/**
* Constructs a BLeveledButtonUI.
* Calls the superclass constructor.
*/
public BLeveledButtonUI() {
super();
}

/**
* Installs the UI for a specified component.
* Sets the rollover enabled and applies the default border.
*
* @param c the component where this UI will be installed
*/
public void installUI(JComponent c) {
super.installUI(c);
AbstractButton button = (AbstractButton) c;
button.setRolloverEnabled(true);
button.setBorder(border2);
}

/**
* Paints the specified component.
* Changes the border based on the rollover state of the button.
*
* @param g the Graphics context in which to paint
* @param c the component being painted
*/
public void paint(Graphics g, JComponent c) {
AbstractButton button = (AbstractButton) c;
boolean b1 = button.getModel().isRollover();
boolean b2 = button.getModel().isArmed();
boolean b3 = button.getModel().isSelected();
if (b1) {
//border1.paintBorder(button,g,button.getX(),button.getY(),button.getWidth(),button.getHeight());
button.setBorder(border1);
}else button.setBorder(border2);
} else {
button.setBorder(border2);
}

super.paint(g, c);
}
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/UI/BLeveledButtonUIX.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,51 @@
import java.awt.*;

/**
* Created by IntelliJ IDEA.
* User: ye
* Date: 2007-12-10
* Time: 17:11:21
* To change this template use File | Settings | File Templates.
* BLeveledButtonUIX is a custom button UI that extends BlueishButtonUI.
* It provides a leveled button appearance with different borders for different states.
*/
public class BLeveledButtonUIX extends BlueishButtonUI {
private static Border border1 = BorderFactory.createRaisedBevelBorder();
private static Border border2 = BorderFactory.createEtchedBorder();//createEtchedBorder(Color.white,Color.gray.brighter());//.createMatteBorder(2,2,2,2,Color.LIGHT_GRAY);//.createEmptyBorder(2, 2, 2, 2);

/**
* Constructs a BLeveledButtonUIX.
* Calls the superclass constructor.
*/
public BLeveledButtonUIX() {
super();
}

/**
* Installs the UI for a specified component.
* Sets the rollover enabled and applies the default border.
*
* @param c the component where this UI will be installed
*/
public void installUI(JComponent c) {
super.installUI(c);
AbstractButton button = (AbstractButton) c;
button.setRolloverEnabled(true);
button.setBorder(border2);
}

/**
* Paints the specified component.
* Changes the border based on the rollover, armed, and selected states of the button.
*
* @param g the Graphics context in which to paint
* @param c the component being painted
*/
public void paint(Graphics g, JComponent c) {
AbstractButton button = (AbstractButton) c;
boolean b1 = button.getModel().isRollover();
boolean b2 = button.getModel().isArmed();
boolean b3 = button.getModel().isSelected();
// if (b2) {
// } else
if (b2 || b3) {
button.setBorder(border1);
} else button.setBorder(border2);
} else {
button.setBorder(border2);
}

super.paint(g, c);
}
Expand Down
110 changes: 56 additions & 54 deletions src/main/java/UI/BlueishButtonUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,68 +6,70 @@
import java.awt.*;

/**
* Created by IntelliJ IDEA.
* User: Ye
* Date: 2006-4-11
* Time: 16:28:51
* To change this template use File | Settings | File Templates.
* BlueishButtonUI.java
* This class extends BasicButtonUI to create a custom button UI with a blueish theme.
* It provides a unique look and feel for buttons in a Swing application.
*/
public class BlueishButtonUI extends BasicButtonUI
{
public class BlueishButtonUI extends BasicButtonUI {

private static Color blueishBackgroundOver = new Color(214, 214, 214);
private static Color blueishBorderOver = new Color(152, 180, 226);
private static Color blueishBackgroundOver = new Color(214, 214, 214);
private static Color blueishBorderOver = new Color(152, 180, 226);

private static Color blueishBackgroundSelected = new Color(192, 192, 192);
private static Color blueishBorderSelected = new Color(49, 106, 197);
private static Color blueishBackgroundSelected = new Color(192, 192, 192);
private static Color blueishBorderSelected = new Color(49, 106, 197);

public BlueishButtonUI()
{
super();
}
/**
* Constructs a BlueishButtonUI.
* Calls the superclass constructor.
*/
public BlueishButtonUI() {
super();
}

public void installUI(JComponent c)
{
/**
* Installs the UI for a specified component.
* Sets the rollover enabled, makes the button non-opaque, and adjusts text position.
*
* @param c the component where this UI will be installed
*/
public void installUI(JComponent c) {
super.installUI(c);
AbstractButton b = (AbstractButton) c;
b.setRolloverEnabled(true);
b.setOpaque(false);
b.setHorizontalTextPosition(JButton.CENTER);
b.setVerticalTextPosition(JButton.BOTTOM);
}

super.installUI(c);
AbstractButton b = (AbstractButton) c;
b.setRolloverEnabled(true);
b.setOpaque(false);
b.setHorizontalTextPosition(JButton.CENTER);
b.setVerticalTextPosition(JButton.BOTTOM);

}

public void paint(Graphics g, JComponent c)
{
AbstractButton button = (AbstractButton) c;
if (button.getModel().isRollover() || button.getModel().isArmed()
|| button.getModel().isSelected())
{

Color oldColor = g.getColor();
if (button.getModel().isSelected())
{
g.setColor(blueishBackgroundSelected);
} else
{
g.setColor(blueishBackgroundOver);
}
g.fillRect(0, 0, c.getWidth() - 1, c.getHeight() - 1);

if (button.getModel().isSelected())
{
g.setColor(blueishBorderSelected);
} else
{
g.setColor(blueishBorderOver);
}
g.drawRect(0, 0, c.getWidth() - 1, c.getHeight() - 1);
/**
* Paints the specified component.
* Changes the background and border colors based on the button's state.
*
* @param g the Graphics context in which to paint
* @param c the component being painted
*/
public void paint(Graphics g, JComponent c) {
AbstractButton button = (AbstractButton) c;
if (button.getModel().isRollover() || button.getModel().isArmed() || button.getModel().isSelected()) {
Color oldColor = g.getColor();
if (button.getModel().isSelected()) {
g.setColor(blueishBackgroundSelected);
} else {
g.setColor(blueishBackgroundOver);
}
g.fillRect(0, 0, c.getWidth() - 1, c.getHeight() - 1);

g.setColor(oldColor);
if (button.getModel().isSelected()) {
g.setColor(blueishBorderSelected);
} else {
g.setColor(blueishBorderOver);
}
g.drawRect(0, 0, c.getWidth() - 1, c.getHeight() - 1);

g.setColor(oldColor);
}

super.paint(g, c);
}
super.paint(g, c);
}

}
65 changes: 64 additions & 1 deletion src/main/java/UI/ButtonBorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@
public class ButtonBorder extends AbstractBorder
{

/**
* Paints the border of the specified component.
* Determines the state of the button (pressed, rollover, enabled) and calls the appropriate paint method.
*
* @param c the component for which this border is being painted
* @param g the Graphics context in which to paint
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
public void paintBorder(Component c, Graphics g, int x, int y, int width,
int height)
{
Expand Down Expand Up @@ -66,34 +77,86 @@ public void paintBorder(Component c, Graphics g, int x, int y, int width,
}
}

/**
* Paints the border for a normal (default) button state.
*
* @param b the button being painted
* @param g the Graphics context in which to paint
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
protected void paintNormal(AbstractButton b, Graphics g, int x, int y,
int width, int height)
{
}

/**
* Paints the border for a disabled button state.
*
* @param b the button being painted
* @param g the Graphics context in which to paint
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
protected void paintDisabled(AbstractButton b, Graphics g, int x, int y,
int width, int height)
{
}

/**
* Paints the border for a rollover button state.
*
* @param b the button being painted
* @param g the Graphics context in which to paint
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
protected void paintRollover(AbstractButton b, Graphics g, int x, int y,
int width, int height)
{
}

/**
* Paints the border for a pressed button state.
*
* @param b the button being painted
* @param g the Graphics context in which to paint
* @param x the x position of the painted border
* @param y the y position of the painted border
* @param width the width of the painted border
* @param height the height of the painted border
*/
protected void paintPressed(AbstractButton b, Graphics g, int x, int y,
int width, int height)
{
}

/**
* Returns the insets of the border.
*
* @param c the component for which this border insets value applies
* @return the insets of the border
*/
public Insets getBorderInsets(Component c)
{
return getBorderInsets(c, new Insets(0, 0, 0, 0));
}

/**
* Reinitializes the insets parameter with this border's current insets.
*
* @param c the component for which this border insets value applies
* @param insets the object to be reinitialized
* @return the insets of the border
*/
public Insets getBorderInsets(Component c, Insets insets)
{
return insets;
}

}
Loading