diff --git a/samples/toolWindow/src/META-INF/plugin.xml b/samples/toolWindow/src/META-INF/plugin.xml index f03aff8fb4ce..a2bee104d0d3 100644 --- a/samples/toolWindow/src/META-INF/plugin.xml +++ b/samples/toolWindow/src/META-INF/plugin.xml @@ -21,7 +21,7 @@ - + diff --git a/samples/toolWindow/src/com/intellij/openapi/toolWindow/MyToolWindow.form b/samples/toolWindow/src/com/intellij/openapi/toolWindow/MyToolWindow.form new file mode 100644 index 000000000000..9f96ba9a95dd --- /dev/null +++ b/samples/toolWindow/src/com/intellij/openapi/toolWindow/MyToolWindow.form @@ -0,0 +1,63 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/samples/toolWindow/src/com/intellij/openapi/toolWindow/MyToolWindowFactory.java b/samples/toolWindow/src/com/intellij/openapi/toolWindow/MyToolWindowFactory.java index 2ed394c574e3..ad015ecc2818 100644 --- a/samples/toolWindow/src/com/intellij/openapi/toolWindow/MyToolWindowFactory.java +++ b/samples/toolWindow/src/com/intellij/openapi/toolWindow/MyToolWindowFactory.java @@ -7,6 +7,9 @@ import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import javax.swing.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Calendar; /** * Created by IntelliJ IDEA. @@ -16,16 +19,61 @@ import javax.swing.*; */ public class MyToolWindowFactory implements ToolWindowFactory { - // Creates the tool window content. + private JButton refreshToolWindowButton; + private JButton hideToolWindowButton; + private JLabel currentDate; + private JLabel currentTime; + private JLabel timeZone; + private JPanel myToolWindowContent; + private ToolWindow myToolWindow; + + + public MyToolWindowFactory() { + hideToolWindowButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + myToolWindow.hide(null); + } + }); + refreshToolWindowButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + MyToolWindowFactory.this.currentDateTime(); + } + }); + } + + // Create the tool window content. public void createToolWindowContent(Project project, ToolWindow toolWindow) { - ToolDialog myDialog = new ToolDialog(); - myDialog.toolWin = toolWindow; - myDialog.currentDateTime(); - JPanel myContentPanel = myDialog.getPanel(); + myToolWindow = toolWindow; + this.currentDateTime(); ContentFactory contentFactory = ContentFactory.SERVICE.getInstance(); - Content content = contentFactory.createContent(myContentPanel, "", false); + Content content = contentFactory.createContent(myToolWindowContent, "", false); toolWindow.getContentManager().addContent(content); } + public void currentDateTime() { + // Get current date and time + Calendar instance = Calendar.getInstance(); + currentDate.setText(String.valueOf(instance.get(Calendar.DAY_OF_MONTH)) + "/" + + String.valueOf(instance.get(Calendar.MONTH) + 1) + "/" + String.valueOf(instance.get(Calendar.YEAR))); + currentDate.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Calendar-icon.png"))); + int min = instance.get(Calendar.MINUTE); + String strMin; + if (min < 10) { + strMin = "0" + String.valueOf(min); + } else { + strMin = String.valueOf(min); + } + currentTime.setText(instance.get(Calendar.HOUR_OF_DAY) + ":" + strMin); + currentTime.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-icon.png"))); + // Get time zone + long gmt_Offset = instance.get(Calendar.ZONE_OFFSET); // offset from GMT in milliseconds + String str_gmt_Offset = String.valueOf(gmt_Offset / 3600000); + str_gmt_Offset = (gmt_Offset > 0) ? "GMT + " + str_gmt_Offset : "GMT - " + str_gmt_Offset; + timeZone.setText(str_gmt_Offset); + timeZone.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-zone-icon.png"))); + + + } + } diff --git a/samples/toolWindow/src/com/intellij/openapi/toolWindow/ToolDialog.form b/samples/toolWindow/src/com/intellij/openapi/toolWindow/ToolDialog.form deleted file mode 100644 index a338eb20f24e..000000000000 --- a/samples/toolWindow/src/com/intellij/openapi/toolWindow/ToolDialog.form +++ /dev/null @@ -1,83 +0,0 @@ - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
diff --git a/samples/toolWindow/src/com/intellij/openapi/toolWindow/ToolDialog.java b/samples/toolWindow/src/com/intellij/openapi/toolWindow/ToolDialog.java deleted file mode 100644 index e7a9bcb0cb8f..000000000000 --- a/samples/toolWindow/src/com/intellij/openapi/toolWindow/ToolDialog.java +++ /dev/null @@ -1,94 +0,0 @@ -package com.intellij.openapi.toolWindow; - -import com.intellij.openapi.wm.ToolWindow; - -import javax.swing.*; -import java.awt.event.*; -import java.util.Calendar; - -public class ToolDialog extends JDialog { - private JPanel contentPane; - private JButton buttonRefresh; - private JButton buttonHide; - - private JLabel cirrentDate; - private JLabel currentTime; - private JLabel timeZone; - public ToolWindow toolWin; - - - public ToolDialog() { - setContentPane(contentPane); - setModal(true); - getRootPane().setDefaultButton(buttonRefresh); - - - buttonRefresh.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onOK(); - } - }); - - buttonHide.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }); - -// call onCancel() when cross is clicked - setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); - addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - onCancel(); - } - }); - -// call onCancel() on ESCAPE - contentPane.registerKeyboardAction(new ActionListener() { - public void actionPerformed(ActionEvent e) { - onCancel(); - } - }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); - } - - private void onOK() { -// Refresh tool window. - this.currentDateTime(); - dispose(); - } - - private void onCancel() { -// Hide tool window. - toolWin.hide(null); - dispose(); - } - - public JPanel getPanel() { - return contentPane; - } - - public void currentDateTime() { - // Get current date and time - Calendar instance = Calendar.getInstance(); - cirrentDate.setText(String.valueOf(instance.get(Calendar.DAY_OF_MONTH)) + "/" - + String.valueOf(instance.get(Calendar.MONTH) + 1) + "/" + String.valueOf(instance.get(Calendar.YEAR))); - cirrentDate.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Calendar-icon.png"))); - int min = instance.get(Calendar.MINUTE); - String strMin; - if (min < 10) { - strMin = "0" + String.valueOf(min); - } else { - strMin = String.valueOf(min); - } - currentTime.setText(instance.get(Calendar.HOUR_OF_DAY) + ":" + strMin); - currentTime.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-icon.png"))); - // Get time zone - long gmt_Offset = instance.get(Calendar.ZONE_OFFSET); // offset from GMT in milliseconds - String str_gmt_Offset = String.valueOf(gmt_Offset / 3600000); - str_gmt_Offset = (gmt_Offset > 0) ? "GMT + " + str_gmt_Offset : "GMT - " + str_gmt_Offset; - timeZone.setText(str_gmt_Offset); - timeZone.setIcon(new ImageIcon(getClass().getResource("/com/intellij/openapi/toolWindow/Time-zone-icon.png"))); - - - } -}