use of java.awt.event.HierarchyListener in project freeplane by freeplane.
the class UITextChanger method setFocusWhenShowed.
private void setFocusWhenShowed(final JTextField focusOwner) {
focusOwner.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if (focusOwner.isShowing()) {
final Window windowAncestor = SwingUtilities.getWindowAncestor(focusOwner);
if (windowAncestor.isFocused()) {
focusOwner.requestFocusInWindow();
} else {
windowAncestor.addWindowFocusListener(new WindowFocusListener() {
@Override
public void windowLostFocus(WindowEvent e) {
// intentionally left blank
}
@Override
public void windowGainedFocus(WindowEvent e) {
focusOwner.requestFocusInWindow();
windowAncestor.removeWindowFocusListener(this);
}
});
}
focusOwner.removeHierarchyListener(this);
}
}
});
}
use of java.awt.event.HierarchyListener in project cuba by cuba-platform.
the class DetachedFrame method initUI.
private void initUI() {
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
glassPane = new DisabledGlassPane();
JRootPane rootPane = SwingUtilities.getRootPane(this);
rootPane.setGlassPane(glassPane);
final java.awt.Component topLevelGlassPane = DesktopComponentsHelper.getTopLevelFrame(parentContainer).getGlassPane();
topLevelGlassPane.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) == HierarchyEvent.SHOWING_CHANGED) {
if (topLevelGlassPane.isVisible()) {
glassPane.activate(null);
} else {
glassPane.deactivate();
}
}
}
});
}
use of java.awt.event.HierarchyListener in project cuba by cuba-platform.
the class DesktopTabSheet method detachTab.
protected void detachTab(final int tabIndex) {
final JComponent tabContent = (JComponent) impl.getComponentAt(tabIndex);
TabImpl tabAtIndex = null;
for (TabImpl tab : tabs) {
if (DesktopComponentsHelper.getComposition(tab.getComponent()) == tabContent) {
tabAtIndex = tab;
if (tab.isLazy() && !tab.isLazyInitialized()) {
initLazyTab(tabContent);
}
break;
}
}
if (tabAtIndex == null) {
throw new IllegalStateException("Unable to find tab to detach");
}
final TabImpl tabToDetach = tabAtIndex;
final ButtonTabComponent tabComponent = tabToDetach.getButtonTabComponent();
final JFrame frame = new DetachedFrame(tabComponent.getCaption(), impl);
frame.setLocationRelativeTo(DesktopComponentsHelper.getTopLevelFrame(this));
impl.remove(tabContent);
updateTabsEnabledState();
frame.setSize(impl.getSize());
frame.add(tabContent);
final HierarchyListener listener = new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if ((e.getChangeFlags() & HierarchyEvent.DISPLAYABILITY_CHANGED) == HierarchyEvent.DISPLAYABILITY_CHANGED && !impl.isDisplayable()) {
attachTab(frame, tabToDetach);
impl.removeHierarchyListener(this);
}
}
};
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
attachTab(frame, tabToDetach);
impl.removeHierarchyListener(listener);
}
});
impl.addHierarchyListener(listener);
frame.setVisible(true);
}
use of java.awt.event.HierarchyListener in project freeplane by freeplane.
the class PresentationController method createPanel.
private Component createPanel() {
final Component presentationEditor = presentationEditorController.createPanel(modeController);
presentationEditor.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if (0 != (e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED))
presentationState.setHighlightsNodes(e.getComponent().isShowing());
}
});
return new JAutoScrollBarPane(presentationEditor);
}
use of java.awt.event.HierarchyListener in project freeplane by freeplane.
the class SurveyRunner method runServey.
public void runServey(String id, String title, String question, String surveyUrl) {
if (!freeplaneSurveyProperties.mayAskUserToFillSurvey(surveyId))
return;
this.surveyId = id;
freeplaneSurveyProperties.setNextSurveyDay(MINIMAL_DAYS_BETWEEN_SURVEYS);
final JButton go = new JButton("With pleasure");
go.setToolTipText("Thank you so much!");
final JButton notInterested = new JButton("Not interested");
notInterested.setToolTipText("We shall not repeat this question, but may be ask you another one.");
final JButton remindMeLater = new JButton("Remind me later");
remindMeLater.setToolTipText("The same question can be repeated some days later.");
final JButton never = new JButton("Don't ask me anything again");
never.setToolTipText("We are sorry! We shall never ask you any question like this again.");
final JButton[] options = new JButton[] { go, notInterested, remindMeLater, never };
final OptionButtonListener optionButtonListener = new OptionButtonListener();
for (JButton button : options) button.addActionListener(optionButtonListener);
final List<Image> iconImages = UITools.getFrame().getIconImages();
final JEditorPane messageComponent = new JEditorPane("text/html", question);
messageComponent.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createLineBorder(Color.BLACK), BorderFactory.createEmptyBorder(10, 10, 10, 10)));
messageComponent.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
try {
final URL url = e.getURL();
openSurvey(url);
} catch (Exception ex) {
}
userVisitedVotingLink = true;
SwingUtilities.getWindowAncestor(messageComponent).setVisible(false);
}
}
});
messageComponent.setEditable(false);
messageComponent.addHierarchyListener(new HierarchyListener() {
@Override
public void hierarchyChanged(HierarchyEvent e) {
if (messageComponent.isShowing()) {
messageComponent.removeHierarchyListener(this);
final Window window = SwingUtilities.getWindowAncestor(messageComponent);
if (window instanceof JDialog)
((JDialog) window).setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
window.setIconImages(iconImages);
}
}
});
final int userDecision = JOptionPane.showOptionDialog(UITools.getCurrentFrame(), messageComponent, title, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION, null, options, remindMeLater);
switch(userDecision) {
case JOptionPane.CLOSED_OPTION:
if (userVisitedVotingLink)
freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
break;
default:
switch(Options.values()[userDecision]) {
case GO_OPTION:
try {
freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
final URL survey = new URL(surveyUrl);
openSurvey(survey);
} catch (Exception e) {
}
break;
case NOT_INTERESTED_OPTION:
freeplaneSurveyProperties.markSurveyAsFilled(surveyId);
break;
case REMIND_ME_LATER_OPTION:
freeplaneSurveyProperties.setNextSurveyDay(MINIMAL_DAYS_BETWEEN_SURVEY_REMINDERS);
freeplaneSurveyProperties.activateRemindMeLater();
break;
case NEVER_OPTION:
freeplaneSurveyProperties.setNeverShowSurvey();
break;
}
}
}
Aggregations