source: trunk/src/org/expeditee/items/widgets/ButtonWidget.java@ 1102

Last change on this file since 1102 was 1102, checked in by davidb, 6 years ago

Reworking of the code-base to separate logic from graphics. This version of Expeditee now supports a JFX graphics as an alternative to SWING

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1package org.expeditee.items.widgets;
2import java.awt.BorderLayout;
3import java.awt.Dimension;
4import java.net.URL;
5
6import javax.swing.JButton;
7import javax.swing.JPanel;
8import javax.swing.border.EmptyBorder;
9
10import org.expeditee.core.Colour;
11import org.expeditee.gio.swing.SwingConversions;
12import org.expeditee.items.Text;
13
14import com.kitfox.svg.app.beans.SVGIcon;
15
16//Will be the default class for Rubbish Bin, Reset and Undo Button Widgets
17public class ButtonWidget extends SwingWidget
18{
19 protected JButton clicked_ = new JButton("");
20 protected SVGIcon icon_ = null;
21
22 public ButtonWidget(int dimension, String filePath, Text source, String[] args)
23 {
24 //Controls how the widget is displayed
25 super(source, new JPanel(new BorderLayout()), 80, -1, 80, -1);
26
27 clicked_.setBorder(new EmptyBorder(0, 0, 0, 0));
28 clicked_.setBackground(SwingConversions.toSwingColor(Colour.WHITE));
29
30 Dimension size = new Dimension(dimension, dimension);
31 icon_ = new SVGIcon();
32
33 try {
34 URL imageURL = ClassLoader.getSystemResource(filePath);
35 icon_.setSvgURI(imageURL.toURI());
36 // This STILL works, unsure why. Don't remove it has an affect on the button appearance.
37 icon_.setUseAntiAlias(true);
38 icon_.setScaleToFit(true);
39 icon_.setPreferredSize(size);
40 clicked_.setIcon(icon_);
41 _swingComponent.add(clicked_);
42 this.setWidgetEdgeThickness(0.0f);
43 this.setWidgetEdgeColor(Colour.WHITE);
44 } catch(Exception e) {
45 //Set a default image if image is missing
46 System.out.println("Unable to load image from directory");
47 }
48 }
49
50 @Override
51 protected String[] getArgs()
52 {
53 // TODO Auto-generated method stub
54 return null;
55 }
56
57 public boolean itemHeldWhileClicked(Widget bw)
58 {
59 // TODO Auto-generated method stub
60 return false;
61 }
62
63 public boolean getdropInteractableStatus()
64 {
65 return false;
66 }
67
68 @Override
69 public boolean setPositions(WidgetCorner src, float x, float y)
70 {
71 boolean result = super.setPositions(src, x, y);
72
73 int iw_x_dim = getWidth();
74 int iw_y_dim = getHeight();
75
76 icon_.setPreferredSize(new Dimension(iw_x_dim, iw_y_dim));
77
78 return result;
79 }
80}
Note: See TracBrowser for help on using the repository browser.