preface
When I was young, I chose my major that summer. My parents heard from other elders that it was better to choose computer major. From then on, I have the deep imprint of the institute. From the dormitory to the computer room, from the computer room to the library, C, C++, Java, as long as it is to want to write their own interest in things, a sitting is a few hours, but at that time young, get up, clean up, a road trot goddess, easily loose. Now I’m at work, not surprisingly doing development work, sitting for a long time. I get so busy writing code that I forget to get up and move, and I don’t drink much water. Often wait until the busy end of the waist and legs feel uncomfortable. It was not until this year’s physical examination report came down that I woke up: without a good health, I could not work well and let my boss live the life he wanted.
I tried using my phone to remind myself, but it didn’t work. The mi Wristband’s sedentary alert function is also on. Sometimes, when you are absorbed in writing code, you can just click on it and turn it off. It still doesn’t work. So I think whether I am too lazy, or write code with Idea easy to indulge, in short, it is impossible to change the needs of interesting. So on New Year’s Day, I plan to develop a little Idea anti-addiction plug-in for myself. I call it StopCoding. She should be able to set every how many minutes, will pop up a warning dialog box, pop up once the dialog box, the idea of code edit box automatically lose focus, what all can’t operation, this is don’t finish calculate, the key is the dialog box doesn’t close to, and also shows the rest is the countdown, and even if I changed the system time, the countdown is still valid, Unless I open task Manager, close the Idea process, and then restart Idea. But think about it, idea all shut down, or take a rest.
Here is a brief introduction to her use and development tutorial
Installation Tutorial
The installation
- Search and install StopCoding plugin in IDEA (officially approved)
2. Intranet developers can download the software and install it locallyDownload address
- Local installation:
use
- Step1. Then go to tools->StopCoding in the menu bar
- Step2. Set the parameters that work for you and save.
- Step3. Then happy Coding bar, no need to worry about their addiction. At the end of the working time, she will pop up the next box to remind, of course, this box is not closed. It only shuts down automatically when you have rested enough time.
Development tutorial
The plugin is very simple and the interface is very simple. The techniques used are basically basic Java programming knowledge. So if you’re interested, check it out.
Range of technology
- The basic structure of the plug-in project
- Swing is mainly responsible for the interaction between the two dialog boxes
- Timer as the most basic Timer selection
Plug-in engineering structure
- plugin.xml
This is the core configuration file of the plug-in project. For an explanation of each item, refer to the first part of the introduction to the core configuration file.
- The data package
- SettingData, the configuration information corresponds to the Model
- The DataCenter, the runtime DataCenter, is a static global variable
- service
- TimerService The core code for timing calculations
- task
- RestTask Indicates a scheduled task during rest
- WorkTask Indicates the scheduled task
- ui
- SettingDialog Dialog box for setting information
- TipsDialog Dialog that is alerted when resting
- StopCodingSettingAction Start entry action
Swing
The interface for developing Swing projects in IDEA is actually very simple. Because IDEA provides a series of visual operations, as well as control layout drag and drop. The next step is to briefly introduce the process of creating a dialog box and adding events.
Create dialog
- Step1
- Step2
- Step3
- Note: here is not a detailed expansion of Swing, because the interface of this thing, we need to go to their own practice. There is no manual type of tautology here.
Add event
In fact, the two buttons in the dialog box you just created already have click events created by default.
public class TestDialog extends JDialog {
private JPanel contentPane;
private JButton buttonOK;
private JButton buttonCancel;
public TestDialog(a) {
setContentPane(contentPane);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { onOK(); }});// This is the listener that binds the click event to the OK button
buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { onCancel(); }});// This is the listener that binds the click event to the cancel button
// Other code
}
Copy the code
Of course, we can create different event listeners from any other control. There are many different types of listeners that can be created through the interface, and you can use them whenever you need them.
- step1
- step2
The Timer Timer
In this plugin, you need to use the timing function to calculate both the duchy and rest time. So use the JDK built-in Timer, very convenient. So I’m going to put my usual Timer API here, so you can see how it works.
- A constructor
- Members of the guard
- Schedule is used to add a scheduled task and cancel is used to cancel the task stop timer.
The last
I believe that with these basic introduction, thanks to the interest of small partners want to see the source code and try to write a small plug-in on their own there is no big problem. Anyway, I have to get some rest. Hopefully this plugin has helped you as a programmer, and this article has been a little inspiring. Of course, trouble friends point a like, encourage the workers.
The source address
Reprint please indicate the original address: juejin.cn/post/691408… And author name: Michael Hey hey, thanks!