/** * Called by the constructor methods to create the default <code>glassPane</code>. By default this * method creates a new <code>JComponent</code> with visibility set to false. * * @return the default <code>glassPane</code> */ protected Component createGlassPane() { JComponent c = new JPanel(); c.setName(this.getName() + ".glassPane"); c.setVisible(false); ((JPanel) c).setOpaque(false); return c; }
/** Returns the current state of the passed in <code>AbstractButton</code>. */ private int getComponentState(JComponent c) { int state = ENABLED; if (!c.isEnabled()) { state = DISABLED; } if (SynthLookAndFeel.getSelectedUI() == this) { return SynthLookAndFeel.getSelectedUIState() | SynthConstants.ENABLED; } AbstractButton button = (AbstractButton) c; ButtonModel model = button.getModel(); if (model.isPressed()) { if (model.isArmed()) { state = PRESSED; } else { state = MOUSE_OVER; } } if (model.isRollover()) { state |= MOUSE_OVER; } if (model.isSelected()) { state |= SELECTED; } if (c.isFocusOwner() && button.isFocusPainted()) { state |= FOCUSED; } if ((c instanceof JButton) && ((JButton) c).isDefaultButton()) { state |= DEFAULT; } return state; }
/** {@inheritDoc} */ @Override public Dimension getMaximumSize(JComponent c) { if (c.getComponentCount() > 0 && c.getLayout() != null) { return null; } AbstractButton b = (AbstractButton) c; SynthContext ss = getContext(c); Dimension size = ss.getStyle() .getGraphicsUtils(ss) .getMaximumSize( ss, ss.getStyle().getFont(ss), b.getText(), getSizingIcon(b), b.getHorizontalAlignment(), b.getVerticalAlignment(), b.getHorizontalTextPosition(), b.getVerticalTextPosition(), b.getIconTextGap(), b.getDisplayedMnemonicIndex()); return size; }
private static void createAndShowGUI() { JComponent newContentPane = new Splitter(); newContentPane.setOpaque(true); frame = new JFrame("Splitting " + EpubUtils.EPUB.getName()); frame.setContentPane(newContentPane); frame.pack(); frame.setVisible(true); }
public void setVisible(boolean bShow, String title) { if (bShow) { String strDir = ""; String strFreq = ""; String strTraynum = ""; m_strHelpFile = getHelpFile(title); String strSampleName = getSampleName(title); String frameBounds = getFrameBounds(title); StringTokenizer tok = new QuotedStringTokenizer(title); if (tok.hasMoreTokens()) strDir = tok.nextToken(); if (tok.hasMoreTokens()) strFreq = tok.nextToken(); if (tok.hasMoreTokens()) strTraynum = tok.nextToken(); else { try { Integer.parseInt(strDir); // if strdir is number, then strdir is empty, and the // strfreq is the number strTraynum = strFreq; strFreq = strDir; strDir = ""; } catch (Exception e) { } } try { setTitle(gettitle(strFreq)); m_lblSampleName.setText("3"); boolean bVast = isVast(strTraynum); CardLayout layout = (CardLayout) m_pnlSampleName.getLayout(); if (!bVast) { if (strSampleName == null) { strSampleName = getSampleName(strDir, strTraynum); } m_lblSampleName.setText(strSampleName); layout.show(m_pnlSampleName, OTHER); } else { m_strDir = strDir; setTrays(); layout.show(m_pnlSampleName, VAST); m_trayTimer.start(); } boolean bSample = bVast || !strSampleName.trim().equals(""); m_pnlSampleName.setVisible(bSample); m_lblLogin.setForeground(getBackground()); m_lblLogin.setVisible(false); m_passwordField.setText(""); m_passwordField.setCaretPosition(0); } catch (Exception e) { Messages.writeStackTrace(e); } setBounds(frameBounds); ExpPanel exp = Util.getActiveView(); if (exp != null) exp.waitLogin(true); } writePersistence(); setVisible(bShow); }
/** * See readObject() and writeObject() in JComponent for more information about serialization in * Swing. */ private void writeObject(ObjectOutputStream s) throws IOException { s.defaultWriteObject(); if (getUIClassID().equals(uiClassID)) { byte count = JComponent.getWriteObjCounter(this); JComponent.setWriteObjCounter(this, --count); if (count == 0 && ui != null) { ui.installUI(this); } } }
private void updateLabelSizes() { Dictionary labelTable = getLabelTable(); if (labelTable != null) { Enumeration labels = labelTable.elements(); while (labels.hasMoreElements()) { JComponent component = (JComponent) labels.nextElement(); component.setSize(component.getPreferredSize()); } } }
/** Enable or disable the components in the compsThatNeedServer list */ private void enableComps() { synchronized (WIDGET_MUTEX) { boolean newEnabledState = (state == STATE_CONNECTED); for (int i = 0; i < compsThatNeedServer.size(); i++) { JComponent comp = (JComponent) compsThatNeedServer.get(i); if (comp.isEnabled() != newEnabledState) { GuiUtils.enableTree(comp, newEnabledState); } } } }
public Component prepareEditor(int index) { Object value = getModel().getElementAt(index); boolean isSelected = isSelectedIndex(index); Component comp = editor.getListCellEditorComponent(this, value, isSelected, index); if (comp instanceof JComponent) { JComponent jComp = (JComponent) comp; if (jComp.getNextFocusableComponent() == null) { jComp.setNextFocusableComponent(this); } } return comp; }
/** * Updates the UIs for the labels in the label table by calling {@code updateUI} on each label. * The UIs are updated from the current look and feel. The labels are also set to their preferred * size. * * @see #setLabelTable * @see JComponent#updateUI */ protected void updateLabelUIs() { Dictionary labelTable = getLabelTable(); if (labelTable == null) { return; } Enumeration labels = labelTable.keys(); while (labels.hasMoreElements()) { JComponent component = (JComponent) labelTable.get(labels.nextElement()); component.updateUI(); component.setSize(component.getPreferredSize()); } }
protected void deleteCurrentPanel() { JComponent tabPane = (JComponent) tabbedPane.getSelectedComponent(); if (tabPane == null) return; WMSPanel wmsPanel = (WMSPanel) tabPane.getClientProperty(Constants.FEATURE_OWNER_PROPERTY); if (tabbedPane.getTabCount() > 2) // actually remove the tab only if there is more than one (plus the "+" tab) tabbedPane.remove(tabPane); else tabbedPane.setTitleAt(1, "New Server"); if (wmsPanel != null) wmsPanel.clearPanel(); }
/** * Create the GUI and show it. As with all GUI code, this must run on the event-dispatching * thread. */ public static void createAndShowGUI(Properties theProperties) { // Create and set up the window. JFrame frame = new JFrame("Remote File Sync"); // frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Create and set up the content pane. JComponent newContentPane = new ProcessFrame(theProperties); newContentPane.setOpaque(true); // content panes must be opaque frame.setContentPane(newContentPane); // Display the window. frame.pack(); frame.setVisible(true); }
protected void clear(JComponent comp) { int nCompCount = comp.getComponentCount(); ArrayList aListComps = new ArrayList(); for (int i = 0; i < comp.getComponentCount(); i++) { Component compChild = comp.getComponent(i); if (compChild instanceof JComponent) { JComponent jcomp = (JComponent) compChild; if (jcomp instanceof JCheckBox || jcomp instanceof JTextField) aListComps.add(comp); else clear(jcomp); } } clear(aListComps); }
/** * Processes key stroke events such as mnemonics and accelerators. * * @param evt the key event to be processed */ protected void processKeyEvent(KeyEvent evt) { MenuSelectionManager.defaultManager().processKeyEvent(evt); if (evt.isConsumed()) { return; } super.processKeyEvent(evt); }
/** * Overridden to enforce the position of the glass component as the zero child. * * @param comp the component to be enhanced * @param constraints the constraints to be respected * @param index the index */ protected void addImpl(Component comp, Object constraints, int index) { super.addImpl(comp, constraints, index); /// We are making sure the glassPane is on top. if (glassPane != null && glassPane.getParent() == this && getComponent(0) != glassPane) { add(glassPane, 0); } }
/** * Called by the constructor methods to create the default <code>contentPane</code>. By default * this method creates a new <code>JComponent</code> add sets a <code>BorderLayout</code> as its * <code>LayoutManager</code>. * * @return the default <code>contentPane</code> */ protected Container createContentPane() { JComponent c = new JPanel(); c.setName(this.getName() + ".contentPane"); c.setLayout( new BorderLayout() { /* This BorderLayout subclass maps a null constraint to CENTER. * Although the reference BorderLayout also does this, some VMs * throw an IllegalArgumentException. */ public void addLayoutComponent(Component comp, Object constraints) { if (constraints == null) { constraints = BorderLayout.CENTER; } super.addLayoutComponent(comp, constraints); } }); return c; }
/** * Removes the component at the specified index from this popup menu. * * @param pos the position of the item to be removed * @exception IllegalArgumentException if the value of <code>pos</code> < 0, or if the value of * <code>pos</code> is greater than the number of items */ public void remove(int pos) { if (pos < 0) { throw new IllegalArgumentException("index less than zero."); } if (pos > getComponentCount() - 1) { throw new IllegalArgumentException("index greater than the number of items."); } super.remove(pos); }
/** Find the top focusable Window, Applet, or InternalFrame */ private static Container getTopAncestor(JComponent c) { for (Container p = c.getParent(); p != null; p = p.getParent()) { if (p instanceof Window && ((Window) p).isFocusableWindow() || p instanceof Applet || p instanceof JInternalFrame) { return p; } } return null; }
public Dimension getPreferredSize(JComponent c) { Dimension prefSize = (getFileChooser().getAccessory() != null) ? WITH_ACCELERATOR_PREF_SIZE : PREF_SIZE; Dimension d = c.getLayout().preferredLayoutSize(c); if (d != null) { return new Dimension( d.width < prefSize.width ? prefSize.width : d.width, d.height < prefSize.height ? prefSize.height : d.height); } else { return prefSize; } }
public void paint(Graphics g) { if (comp != null) { width = comp.getWidth() / 6; height = comp.getHeight() * 2 / 3; } g.setColor(bgColor); g.fillRect(x, y, width, height); g.setColor(fgColor); g.setFont(font); g.drawString(strTray, x / 2 + width / 2, y + height + 10); super.paint(g); }
//////////// // Serialization support. //////////// private void writeObject(ObjectOutputStream s) throws IOException { Vector<Object> values = new Vector<Object>(); s.defaultWriteObject(); // Save the invoker, if its Serializable. if (invoker != null && invoker instanceof Serializable) { values.addElement("invoker"); values.addElement(invoker); } // Save the popup, if its Serializable. if (popup != null && popup instanceof Serializable) { values.addElement("popup"); values.addElement(popup); } s.writeObject(values); if (getUIClassID().equals(uiClassID)) { byte count = JComponent.getWriteObjCounter(this); JComponent.setWriteObjCounter(this, --count); if (count == 0 && ui != null) { ui.installUI(this); } } }
public void paint(Graphics g) { super.paint(g); if (thumbnail != null) { int x = getWidth() / 2 - thumbnail.getIconWidth() / 2; int y = getHeight() / 2 - thumbnail.getIconHeight() / 2; if (y < 0) { y = 0; } if (x < 5) { x = 5; } thumbnail.paintIcon(this, g, x, y); } }
/** * If necessary paints the background of the component, then invokes <code>paint</code>. * * @param g Graphics to paint to * @param c JComponent painting on * @throws NullPointerException if <code>g</code> or <code>c</code> is null * @see javax.swing.plaf.ComponentUI#update * @see javax.swing.plaf.ComponentUI#paint * @since 1.5 */ public void update(Graphics g, JComponent c) { AbstractButton button = (AbstractButton) c; if ((c.getBackground() instanceof UIResource) && button.isContentAreaFilled() && c.isEnabled()) { ButtonModel model = button.getModel(); if (!MetalUtils.isToolBarButton(c)) { if (!model.isArmed() && !model.isPressed() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } else if (model.isRollover() && MetalUtils.drawGradient( c, g, "Button.gradient", 0, 0, c.getWidth(), c.getHeight(), true)) { paint(g, c); return; } } super.update(g, c); }
void fireBinding(JComponent c, KeyStroke ks, KeyEvent e, boolean pressed) { if (c.processKeyBinding(ks, e, JComponent.WHEN_IN_FOCUSED_WINDOW, pressed)) { e.consume(); } }
/** * This method is called when the focused component (and none of its ancestors) want the key * event. This will look up the keystroke to see if any chidren (or subchildren) of the specified * container want a crack at the event. If one of them wants it, then it will "DO-THE-RIGHT-THING" */ public boolean fireKeyboardAction(KeyEvent e, boolean pressed, Container topAncestor) { if (e.isConsumed()) { System.out.println("Acquired pre-used event!"); Thread.dumpStack(); } // There may be two keystrokes associated with a low-level key event; // in this case a keystroke made of an extended key code has a priority. KeyStroke ks; KeyStroke ksE = null; if (e.getID() == KeyEvent.KEY_TYPED) { ks = KeyStroke.getKeyStroke(e.getKeyChar()); } else { if (e.getKeyCode() != e.getExtendedKeyCode()) { ksE = KeyStroke.getKeyStroke(e.getExtendedKeyCode(), e.getModifiers(), !pressed); } ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers(), !pressed); } Hashtable keyMap = containerMap.get(topAncestor); if (keyMap != null) { // this container isn't registered, so bail Object tmp = null; // extended code has priority if (ksE != null) { tmp = keyMap.get(ksE); if (tmp != null) { ks = ksE; } } if (tmp == null) { tmp = keyMap.get(ks); } if (tmp == null) { // don't do anything } else if (tmp instanceof JComponent) { JComponent c = (JComponent) tmp; if (c.isShowing() && c.isEnabled()) { // only give it out if enabled and visible fireBinding(c, ks, e, pressed); } } else if (tmp instanceof Vector) { // more than one comp registered for this Vector v = (Vector) tmp; // There is no well defined order for WHEN_IN_FOCUSED_WINDOW // bindings, but we give precedence to those bindings just // added. This is done so that JMenus WHEN_IN_FOCUSED_WINDOW // bindings are accessed before those of the JRootPane (they // both have a WHEN_IN_FOCUSED_WINDOW binding for enter). for (int counter = v.size() - 1; counter >= 0; counter--) { JComponent c = (JComponent) v.elementAt(counter); // System.out.println("Trying collision: " + c + " vector = "+ v.size()); if (c.isShowing() && c.isEnabled()) { // don't want to give these out fireBinding(c, ks, e, pressed); if (e.isConsumed()) return true; } } } else { System.out.println("Unexpected condition in fireKeyboardAction " + tmp); // This means that tmp wasn't null, a JComponent, or a Vector. What is it? Thread.dumpStack(); } } if (e.isConsumed()) { return true; } // if no one else handled it, then give the menus a crack // The're handled differently. The key is to let any JMenuBars // process the event if (keyMap != null) { Vector v = (Vector) keyMap.get(JMenuBar.class); if (v != null) { Enumeration iter = v.elements(); while (iter.hasMoreElements()) { JMenuBar mb = (JMenuBar) iter.nextElement(); if (mb.isShowing() && mb.isEnabled()) { // don't want to give these out boolean extended = (ksE != null) && !ksE.equals(ks); if (extended) { fireBinding(mb, ksE, e, pressed); } if (!extended || !e.isConsumed()) { fireBinding(mb, ks, e, pressed); } if (e.isConsumed()) { return true; } } } } } return e.isConsumed(); }
public AttributesPanel() { this.setLayout(new BorderLayout()); super.add(box, BorderLayout.CENTER); }
public void setEnabled(boolean b) { super.setEnabled(b); for (Component c : getComponents()) { c.setEnabled(b); } }
@Override public void paint(Graphics g) { super.paint(g); }
/** {@inheritDoc} */ public void removeNotify() { super.removeNotify(); }
/** {@inheritDoc} */ public void addNotify() { super.addNotify(); enableEvents(AWTEvent.KEY_EVENT_MASK); }