List of usage examples for java.awt.event HierarchyListener HierarchyListener
HierarchyListener
From source file:com.mac.tarchan.desktop.event.EventQuery.java
/** * ???????????/*from w ww . j a va 2 s . com*/ * * @param hierarchyChanged ? * @return ?? * @see <a href="http://terai.xrea.jp/Swing/DefaultFocus.html ">Window?????? - Java Swing Tips</a> * @see HierarchyListener#hierarchyChanged(HierarchyEvent) */ public EventQuery ready(final HierarchyListener hierarchyChanged) { for (Component child : list) { child.addHierarchyListener(new HierarchyListener() { public void hierarchyChanged(HierarchyEvent e) { if (e.getChangeFlags() == HierarchyEvent.DISPLAYABILITY_CHANGED) hierarchyChanged.hierarchyChanged(e); } }); } return this; }
From source file:com.haulmont.cuba.desktop.gui.components.DesktopTabSheet.java
protected void detachTab(final int tabIndex) { final JComponent tabContent = (JComponent) impl.getComponentAt(tabIndex); TabImpl tabAtIndex = null;// w w w. j a va2 s . c om 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); }
From source file:org.tinymediamanager.ui.settings.GeneralSettingsPanel.java
private void initMemorySlider() { Path file = Paths.get("extra.txt"); int maxMemory = 512; if (Files.exists(file)) { // parse out memory option from extra.txt try {//from w w w.jav a 2 s . c o m String extraTxt = Utils.readFileToString(file); Matcher matcher = MEMORY_PATTERN.matcher(extraTxt); if (matcher.find()) { maxMemory = Integer.parseInt(matcher.group(1)); String dimension = matcher.group(2); if ("k".equalsIgnoreCase(dimension)) { maxMemory /= 1024; } if ("g".equalsIgnoreCase(dimension)) { maxMemory *= 1024; } } } catch (Exception e) { maxMemory = 512; } } sliderMemory.setValue(maxMemory); // add a listener to write the actual memory state to extra.txt addHierarchyListener(new HierarchyListener() { private boolean oldState = false; @Override public void hierarchyChanged(HierarchyEvent e) { if (oldState != isShowing()) { oldState = isShowing(); if (!isShowing()) { writeMemorySettings(); } } } }); }
From source file:org.wandora.application.gui.topicpanels.ProcessingTopicPanel.java
private void showRichErrorDialog(String msg) { final JTextArea area = new JTextArea(); area.setFont(errorMessageFont);/*from w ww. j a v a 2 s .c o m*/ //area.setPreferredSize(new Dimension(520, 180)); area.setEditable(false); area.setText(msg); // Make the JOptionPane resizable using the HierarchyListener area.addHierarchyListener(new HierarchyListener() { public void hierarchyChanged(HierarchyEvent e) { Window window = SwingUtilities.getWindowAncestor(area); if (window instanceof Dialog) { Dialog dialog = (Dialog) window; if (!dialog.isResizable()) { dialog.setResizable(true); } } } }); JScrollPane scroller = new JScrollPane(area); scroller.setPreferredSize(new Dimension(520, 180)); JOptionPane.showMessageDialog(Wandora.getWandora(), scroller, "Errors", JOptionPane.PLAIN_MESSAGE); }
From source file:self.philbrown.javaQuery.$.java
/** * Registers common component changes/*from w w w. j a v a2s.c o m*/ * @param function receives an instance of javaQuery with the changed view selected, as well as the * following arguments: * <ol> * <li>{@link changeEvent} to define the type of event that was triggered * <li>The associated event * </ol> * @return * @see changeEvent */ public $ change(final Function function) { for (final Component component : views) { component.addInputMethodListener(new InputMethodListener() { @Override public void caretPositionChanged(InputMethodEvent event) { function.invoke($.with(component), ChangeEvent.INPUT_CARET_POSITION_CHANGED, event); } @Override public void inputMethodTextChanged(InputMethodEvent event) { function.invoke($.with(component), ChangeEvent.INPUT_METHOD_TEXT_CHANGED, event); } }); component.addHierarchyBoundsListener(new HierarchyBoundsListener() { @Override public void ancestorMoved(HierarchyEvent event) { function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCESTOR_MOVED, event); } @Override public void ancestorResized(HierarchyEvent event) { function.invoke($.with(component), ChangeEvent.HIERARCHY_ANCENSTOR_RESIZED, event); } }); component.addHierarchyListener(new HierarchyListener() { @Override public void hierarchyChanged(HierarchyEvent event) { function.invoke($.with(component), ChangeEvent.HIERARCHY_CHANGED, event); } }); component.addPropertyChangeListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent event) { function.invoke($.with(component), ChangeEvent.PROPERTY_CHANGED, event); } }); component.addComponentListener(new ComponentListener() { @Override public void componentHidden(ComponentEvent event) { function.invoke($.with(component), ChangeEvent.COMPONENT_HIDDEN, event); } @Override public void componentMoved(ComponentEvent event) { function.invoke($.with(component), ChangeEvent.COMPONENT_MOVED, event); } @Override public void componentResized(ComponentEvent event) { function.invoke($.with(component), ChangeEvent.COMPONENT_RESIZED, event); } @Override public void componentShown(ComponentEvent event) { function.invoke($.with(component), ChangeEvent.COMPONENT_SHOWN, event); } }); if (component instanceof Container) { ((Container) component).addContainerListener(new ContainerListener() { @Override public void componentAdded(ContainerEvent event) { function.invoke($.with(component), ChangeEvent.COMPONENT_ADDED, event); } @Override public void componentRemoved(ContainerEvent event) { function.invoke($.with(component), ChangeEvent.COMPONENT_REMOVED, event); } }); } } return this; }