1 | package org.expeditee.items.widgets;
|
---|
2 | import java.awt.BorderLayout;
|
---|
3 | import java.awt.Dimension;
|
---|
4 | import java.net.URL;
|
---|
5 |
|
---|
6 | import javax.swing.JButton;
|
---|
7 | import javax.swing.JPanel;
|
---|
8 | import javax.swing.border.EmptyBorder;
|
---|
9 |
|
---|
10 | import org.expeditee.core.Colour;
|
---|
11 | import org.expeditee.gio.swing.SwingConversions;
|
---|
12 | import org.expeditee.items.Text;
|
---|
13 |
|
---|
14 | import com.kitfox.svg.app.beans.SVGIcon;
|
---|
15 |
|
---|
16 | //Will be the default class for Rubbish Bin, Reset and Undo Button Widgets
|
---|
17 | public 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 | }
|
---|