-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStickyCorners.java
More file actions
215 lines (187 loc) · 5.46 KB
/
Copy pathStickyCorners.java
File metadata and controls
215 lines (187 loc) · 5.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import java.awt.AWTException;
import java.awt.Cursor;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.PopupMenu;
import java.awt.Robot;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URI;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.UIManager;
/**
* Sticky Corners for Windows 7
* @author Jayden Weaver
*
*/
public class StickyCorners {
//Create a System Tray
static SystemTray tray;
//Create frame
static JFrame frame = new JFrame("Sticky Corners");
//Create Setting Variables
static boolean topRightCorner = true;
static boolean topLeftCorner = false;
static boolean bottomLeftCorner = false;
static boolean bottomRightCorner = false;
public static void main(String args[]){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e){
//do nothing...there's no point...
}
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
frame.setVisible(false);
hideToSystemTray();
}
});
//Panel 1 Content
JPanel panel1 = new JPanel();
JCheckBox topRightHandCorner = new JCheckBox("Top Right Corner");
topRightHandCorner.setSelected(true); //set selected, because default
JCheckBox bottomRightHandCorner = new JCheckBox("Bottom Right Corner");
JButton saveSettings = new JButton("Save Settings");
saveSettings.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
topRightCorner = topRightHandCorner.isSelected();
bottomRightCorner = bottomRightHandCorner.isSelected();
}
});
JButton exitCompletely = new JButton("Exit Program");
exitCompletely.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);
}
});
panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
panel1.add(topRightHandCorner);
panel1.add(bottomRightHandCorner);
panel1.add(saveSettings);
panel1.add(exitCompletely);
//Panel 2 Content
JPanel panel2 = new JPanel();
//Panel 2 Layout
panel2.setLayout(new BoxLayout(panel2, BoxLayout.Y_AXIS));
//Author
JLabel author = new JLabel("Jayden Weaver");
//Year
JLabel year = new JLabel("2017");
/*
* Start Twitter Label
*/
JLabel twitter = new JLabel("@WeaverFever69");
twitter.setCursor(new Cursor(Cursor.HAND_CURSOR));
twitter.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
try{
Desktop.getDesktop().browse(new URI("http://www.twitter.com/weaverfever69")); //twitter account
}
catch(Exception ex){
System.err.println(ex);
}
}});
/*
* End Twitter Label
*/
/*
* Start Github Label
*/
JLabel github = new JLabel("github.com/jayden2013");
github.setCursor(new Cursor(Cursor.HAND_CURSOR));
github.addMouseListener(new MouseAdapter(){
public void mouseClicked(MouseEvent e){
try{
Desktop.getDesktop().browse(new URI("http://www.github.com/jayden2013")); //github account
}
catch(Exception ex){
System.err.println(ex);
}
}
});
/*
* End Github Label
*/
//Add all labels
panel2.add(author);
panel2.add(twitter);
panel2.add(github);
panel2.add(year);
//Create Tabbed Pane
JTabbedPane tabs = new JTabbedPane();
//Add Everything to Tabbed Pane
tabs.add("Settings", panel1);
tabs.add("About", panel2);
frame.add(tabs);
try {
frame.setVisible(true);
Robot robot = new Robot(); //beep boop
Point p;
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
int width = (int) screenSize.getWidth();
int height = (int) screenSize.getHeight();
while(true){
p = MouseInfo.getPointerInfo().getLocation();
if (p.getX() >= width && p.getY() <= 20 && topRightCorner){
robot.mouseMove(width - 10, 5);
}
if (p.getX() >= width && p.getY() >= height - 20 && bottomRightCorner){
robot.mouseMove(width - 10, height - 10);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Hides program in System Tray.
*/
private static void hideToSystemTray(){
tray = SystemTray.getSystemTray();
Image image = Toolkit.getDefaultToolkit().getImage("icon.jpg");
PopupMenu popup = new PopupMenu();
MenuItem defaultItem = new MenuItem("Settings");
defaultItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
frame.setVisible(true);
frame.setExtendedState(JFrame.NORMAL);
}
});
popup.add(defaultItem);
defaultItem = new MenuItem("Close");
defaultItem.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
frame.dispose();
System.exit(0);
}
});
popup.add(defaultItem);
TrayIcon trayIcon = new TrayIcon(image, "Sticky Corners", popup);
trayIcon.setImageAutoSize(true);
try {
tray.add(trayIcon);
} catch (AWTException e1) {
e1.printStackTrace();
}
}
}