mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 04:38:00 +00:00
Added focus, toggle, and disabled states to FButton and skins.
Note: Keyboard functionality had already been lost _before_ this commit.
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 100 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 81 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 91 KiB After Width: | Height: | Size: 100 KiB |
@@ -6,12 +6,12 @@
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -25,6 +25,8 @@ import java.awt.Graphics2D;
|
||||
import java.awt.Image;
|
||||
import java.awt.Insets;
|
||||
import java.awt.RenderingHints;
|
||||
import java.awt.event.FocusAdapter;
|
||||
import java.awt.event.FocusEvent;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.JButton;
|
||||
@@ -34,7 +36,7 @@ import forge.AllZone;
|
||||
/**
|
||||
* The core JButton used throughout the Forge project. Follows skin font and
|
||||
* theme button styling.
|
||||
*
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class FButton extends JButton {
|
||||
@@ -57,7 +59,7 @@ public class FButton extends JButton {
|
||||
|
||||
/**
|
||||
* Instantiates a new FButton.
|
||||
*
|
||||
*
|
||||
* @param msg
|
||||
* the msg
|
||||
*/
|
||||
@@ -80,6 +82,7 @@ public class FButton extends JButton {
|
||||
this.allImagesPresent = true;
|
||||
}
|
||||
|
||||
// Mouse events
|
||||
this.addMouseListener(new java.awt.event.MouseAdapter() {
|
||||
@Override
|
||||
public void mouseEntered(final java.awt.event.MouseEvent evt) {
|
||||
@@ -92,11 +95,16 @@ public class FButton extends JButton {
|
||||
|
||||
@Override
|
||||
public void mouseExited(final java.awt.event.MouseEvent evt) {
|
||||
if (FButton.this.isEnabled()) {
|
||||
if (FButton.this.isEnabled() && !FButton.this.isFocusOwner()) {
|
||||
FButton.this.imgL = FButton.this.skin.getImage("button.upLEFT");
|
||||
FButton.this.imgM = FButton.this.skin.getImage("button.upCENTER");
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.upRIGHT");
|
||||
}
|
||||
else if (FButton.this.isEnabled() && FButton.this.isFocusOwner()) {
|
||||
FButton.this.imgL = FButton.this.skin.getImage("button.focusLEFT");
|
||||
FButton.this.imgM = FButton.this.skin.getImage("button.focusCENTER");
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.focusRIGHT");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,12 +115,56 @@ public class FButton extends JButton {
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.downRIGHT");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseReleased(final java.awt.event.MouseEvent evt) {
|
||||
if (FButton.this.isEnabled()) {
|
||||
FButton.this.imgL = FButton.this.skin.getImage("button.downLEFT");
|
||||
FButton.this.imgM = FButton.this.skin.getImage("button.downCENTER");
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.downRIGHT");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Focus events
|
||||
this.addFocusListener(new FocusAdapter() {
|
||||
public void focusGained(FocusEvent e) {
|
||||
if (FButton.this.isEnabled()) {
|
||||
FButton.this.imgL = FButton.this.skin.getImage("button.focusLEFT");
|
||||
FButton.this.imgM = FButton.this.skin.getImage("button.focusCENTER");
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.focusRIGHT");
|
||||
}
|
||||
}
|
||||
|
||||
public void focusLost(FocusEvent e) {
|
||||
if (FButton.this.isEnabled()) {
|
||||
FButton.this.imgL = FButton.this.skin.getImage("button.upLEFT");
|
||||
FButton.this.imgM = FButton.this.skin.getImage("button.upCENTER");
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.upRIGHT");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean b0) {
|
||||
if (!b0) {
|
||||
FButton.this.imgL = FButton.this.skin.getImage("button.disabledLEFT");
|
||||
FButton.this.imgM = FButton.this.skin.getImage("button.disabledCENTER");
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.disabledRIGHT");
|
||||
}
|
||||
else {
|
||||
FButton.this.imgL = FButton.this.skin.getImage("button.upLEFT");
|
||||
FButton.this.imgM = FButton.this.skin.getImage("button.upCENTER");
|
||||
FButton.this.imgR = FButton.this.skin.getImage("button.upRIGHT");
|
||||
}
|
||||
|
||||
super.setEnabled(b0);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
*
|
||||
* @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
|
||||
*/
|
||||
@Override
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
@@ -37,7 +37,7 @@ import forge.gui.GuiUtils;
|
||||
/**
|
||||
* Assembles settings from selected or default theme as appropriate. Saves in a
|
||||
* hashtable, access using .get(settingName) method.
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class FSkin {
|
||||
@@ -52,12 +52,12 @@ public class FSkin {
|
||||
private final String font1file = "font1.ttf";
|
||||
private Font tempFont;
|
||||
private final String notfound = "FSkin.java: Can't find ";
|
||||
|
||||
|
||||
private final static String[] SKINS = {"default", "rebel", "smith"};
|
||||
|
||||
|
||||
public static ArrayList<String> getSkins() {
|
||||
ArrayList<String> mySkins = new ArrayList<String>();
|
||||
for(int i = 0; i < SKINS.length; i++) {
|
||||
for (int i = 0; i < SKINS.length; i++) {
|
||||
mySkins.add(SKINS[i]);
|
||||
}
|
||||
return mySkins;
|
||||
@@ -66,7 +66,7 @@ public class FSkin {
|
||||
/**
|
||||
* FSkin constructor. No arguments, will generate default skin settings,
|
||||
* fonts, and backgrounds.
|
||||
*
|
||||
*
|
||||
* @throws Exception
|
||||
* the exception
|
||||
*/
|
||||
@@ -77,7 +77,7 @@ public class FSkin {
|
||||
/**
|
||||
* FSkin constructor, using skin name. Generates custom skin settings,
|
||||
* fonts, and backgrounds.
|
||||
*
|
||||
*
|
||||
* @param skinName
|
||||
* the skin name
|
||||
* @throws Exception
|
||||
@@ -89,7 +89,7 @@ public class FSkin {
|
||||
|
||||
/**
|
||||
* Loads objects from skin folder, prints brief error if not found.
|
||||
*
|
||||
*
|
||||
* @param skinName
|
||||
*/
|
||||
private void loadFontAndImages(final String skinName) {
|
||||
@@ -161,6 +161,14 @@ public class FSkin {
|
||||
this.setImage("button.focusLEFT", image.getSubimage(360, 120, 40, 40));
|
||||
this.setImage("button.focusCENTER", image.getSubimage(400, 120, 1, 40));
|
||||
this.setImage("button.focusRIGHT", image.getSubimage(440, 120, 40, 40));
|
||||
|
||||
this.setImage("button.toggleLEFT", image.getSubimage(360, 160, 40, 40));
|
||||
this.setImage("button.toggleCENTER", image.getSubimage(400, 160, 1, 40));
|
||||
this.setImage("button.toggleRIGHT", image.getSubimage(440, 160, 40, 40));
|
||||
|
||||
this.setImage("button.disabledLEFT", image.getSubimage(360, 200, 40, 40));
|
||||
this.setImage("button.disabledCENTER", image.getSubimage(400, 200, 1, 40));
|
||||
this.setImage("button.disabledRIGHT", image.getSubimage(440, 200, 40, 40));
|
||||
} catch (final IOException e) {
|
||||
System.err.println(this.notfound + this.spriteFile);
|
||||
}
|
||||
@@ -172,7 +180,7 @@ public class FSkin {
|
||||
* </p>
|
||||
* Tries to instantiate an image icon from a filename. Error reported if not
|
||||
* found.
|
||||
*
|
||||
*
|
||||
* @param {@link java.lang.String} address
|
||||
* @return a ImageIcon
|
||||
*/
|
||||
@@ -192,7 +200,7 @@ public class FSkin {
|
||||
* </p>
|
||||
* Uses GuiUtils to grab a font file at an address. Error will be reported
|
||||
* by GuiUtils if not found.
|
||||
*
|
||||
*
|
||||
* @param {@link java.lang.String} address
|
||||
* @return a Font
|
||||
*/
|
||||
@@ -206,7 +214,7 @@ public class FSkin {
|
||||
* <p>
|
||||
* getColorFromPixel.
|
||||
* </p>
|
||||
*
|
||||
*
|
||||
* @param {@link java.lang.Integer} pixel information
|
||||
*/
|
||||
private Color getColorFromPixel(final int pixel) {
|
||||
@@ -220,7 +228,7 @@ public class FSkin {
|
||||
|
||||
/**
|
||||
* Primary font used in titles and buttons and most text output.
|
||||
*
|
||||
*
|
||||
* @return {@link java.awt.font} font1
|
||||
*/
|
||||
public Font getFont1() {
|
||||
@@ -229,7 +237,7 @@ public class FSkin {
|
||||
|
||||
/**
|
||||
* Primary font used in titles and buttons and most text output.
|
||||
*
|
||||
*
|
||||
* @param font10
|
||||
*   an image icon
|
||||
*/
|
||||
@@ -239,7 +247,7 @@ public class FSkin {
|
||||
|
||||
/**
|
||||
* Gets the name.
|
||||
*
|
||||
*
|
||||
* @return Name of skin.
|
||||
*/
|
||||
public String getName() {
|
||||
@@ -256,7 +264,7 @@ public class FSkin {
|
||||
|
||||
/**
|
||||
* Gets a scaled version of an icon from this skin's icon map.
|
||||
*
|
||||
*
|
||||
* @param s0 String icon address
|
||||
* @param w0 int new width
|
||||
* @param h0 int new height
|
||||
@@ -277,9 +285,9 @@ public class FSkin {
|
||||
return new ImageIcon(scaled);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets an icon in this skin's icon map from a BufferedImage.
|
||||
*
|
||||
*
|
||||
* @param s0   String address
|
||||
* @param bi0   BufferedImage
|
||||
*/
|
||||
@@ -287,9 +295,9 @@ public class FSkin {
|
||||
icons.put(s0, new ImageIcon(bi0));
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets an icon in this skin's icon map from an ImageIcon.
|
||||
*
|
||||
*
|
||||
* @param s0   String address
|
||||
* @param i0   ImageIcon
|
||||
*/
|
||||
@@ -299,7 +307,7 @@ public class FSkin {
|
||||
|
||||
/**
|
||||
* Retrieves a color from this skin's color map.
|
||||
*
|
||||
*
|
||||
* @param s0   String color address
|
||||
* @return Color
|
||||
*/
|
||||
@@ -307,9 +315,9 @@ public class FSkin {
|
||||
return colors.get(s0);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets a color in this skin's color map.
|
||||
*
|
||||
*
|
||||
* @param s0   String address
|
||||
* @param c0   Color
|
||||
*/
|
||||
@@ -319,7 +327,7 @@ public class FSkin {
|
||||
|
||||
/**
|
||||
* Retrieves an image from this skin's image map.
|
||||
*
|
||||
*
|
||||
* @param s0   String color address
|
||||
* @return BufferedImage
|
||||
*/
|
||||
@@ -327,9 +335,9 @@ public class FSkin {
|
||||
return images.get(s0);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Sets an image in this skin's image map.
|
||||
*
|
||||
*
|
||||
* @param s0   String address
|
||||
* @param bi0   ImageIcon
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user