1 | package org.expeditee.items.widgets;
|
---|
2 | import java.awt.BorderLayout;
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.awt.Dimension;
|
---|
5 | import java.net.URL;
|
---|
6 |
|
---|
7 | import javax.swing.JButton;
|
---|
8 | import javax.swing.JPanel;
|
---|
9 | import javax.swing.border.EmptyBorder;
|
---|
10 |
|
---|
11 | import org.expeditee.items.Text;
|
---|
12 |
|
---|
13 | import com.kitfox.svg.app.beans.SVGIcon;
|
---|
14 |
|
---|
15 | //Will be the default class for Rubbish Bin, Reset and Undo Button Widgets
|
---|
16 | public class ButtonWidget extends InteractiveWidget{
|
---|
17 |
|
---|
18 | protected JButton clicked_ = new JButton("");
|
---|
19 | protected SVGIcon icon_ = null;
|
---|
20 |
|
---|
21 | public ButtonWidget(int dimension, String filePath, Text source, String[] args)
|
---|
22 | {
|
---|
23 | //Controls how the widget is displayed
|
---|
24 | super(source, new JPanel(new BorderLayout()), 80, -1, 80, -1);
|
---|
25 |
|
---|
26 | clicked_.setBorder(new EmptyBorder(0, 0, 0, 0));
|
---|
27 | clicked_.setBackground(Color.white);
|
---|
28 |
|
---|
29 | Dimension size = new Dimension(dimension, dimension);
|
---|
30 | icon_ = new SVGIcon();
|
---|
31 | try{
|
---|
32 | URL imageURL = ClassLoader.getSystemResource(filePath);
|
---|
33 | icon_.setSvgURI(imageURL.toURI());
|
---|
34 | //This STILL works, unsure why. Don't remove it has an affect on the button appearance.
|
---|
35 | icon_.setUseAntiAlias(true);
|
---|
36 | icon_.setScaleToFit(true);
|
---|
37 | icon_.setPreferredSize(size);
|
---|
38 | clicked_.setIcon(icon_);
|
---|
39 | _swingComponent.add(clicked_);
|
---|
40 | this.setWidgetEdgeThickness(0.0f);
|
---|
41 | this.setWidgetEdgeColor(Color.white);
|
---|
42 | }
|
---|
43 | catch(Exception e){
|
---|
44 |
|
---|
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 | // TODO Auto-generated method stub
|
---|
53 | return null;
|
---|
54 | }
|
---|
55 | public boolean itemHeldWhileClicked(InteractiveWidget bw) {
|
---|
56 | // TODO Auto-generated method stub
|
---|
57 | return false;
|
---|
58 | }
|
---|
59 | public boolean getdropInteractableStatus(){
|
---|
60 | return false;
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | boolean setPositions(WidgetCorner src, float x, float y) {
|
---|
65 | boolean result = super.setPositions(src, x, y);
|
---|
66 |
|
---|
67 | int iw_x_dim = getWidth();
|
---|
68 | int iw_y_dim = getHeight();
|
---|
69 |
|
---|
70 | icon_.setPreferredSize(new Dimension(iw_x_dim, iw_y_dim));
|
---|
71 |
|
---|
72 | return result;
|
---|
73 | }
|
---|
74 | }
|
---|