/** * Displays an error message with the default title "Error". * * @param parent the parent, to make the dialog modal; can be null * @param msg the error message to display */ public static void showErrorMessage(Component parent, String msg) { showErrorMessage(parent, msg, "Error"); }
/** * Returns an ImageIcon from the given name. * * @param name the filename without path * @return the ImageIcon or null if not available */ public static ImageIcon getIcon(String name) { String filename; filename = getImageFilename(name); if (filename != null) return new ImageIcon(GUIHelper.class.getClassLoader().getResource(filename)); else return null; }
/** * Tries to determine the internal frame this container is part of. * * @param cont the container to start with * @return the parent internal frame if one exists or null if not */ public static JInternalFrame getParentInternalFrame(Container cont) { return (JInternalFrame) getParent(cont, JInternalFrame.class); }
/** * Tries to determine the component this panel is part of in this order: * 1. dialog, 2. child, 3. frame. * * @param comp the component to get the parent component for, must * be a container actually * @return the parent component if one exists or null if not * @see #getParentDialog(Container) * @see #getParentFrame(Container) */ public static Component getParentComponent(Component comp) { Component result; Container cont; if (comp == null) return null; if (comp instanceof Container) cont = (Container) comp; else return null; result = getParentDialog(cont); if (result == null) result = getParentFrame(cont); return result; }
/** * Either displays or hides the bookmarks. * * @param value true if to show bookmarks */ protected void showBookmarks(boolean value) { m_PanelBookmarks.setVisible(value); if (m_PanelBookmarks.isVisible()) m_ButtonBookmarks.setIcon(GUIHelper.getIcon("arrow-head-up.png")); else m_ButtonBookmarks.setIcon(GUIHelper.getIcon("arrow-head-down.png")); }
WindowEvent event; if (getParentDialog(cont) != null) { dialog = getParentDialog(cont); dialog.setVisible(false); else if (getParentFrame(cont) != null) { jintframe = getParentInternalFrame(cont); if (jintframe != null) { jintframe.doDefaultCloseAction(); frame = getParentFrame(cont); if (frame instanceof JFrame) { jframe = (JFrame) frame;
/** * Sets the text for the prefix label. Mnemonics can be indicated by a * preceding underscore "_". * * @param value the text to display * @see GUIHelper#MNEMONIC_INDICATOR */ public void setPrefix(String value) { char mnemonic; String caption; mnemonic = GUIHelper.getMnemonic(value); caption = GUIHelper.stripMnemonic(value); m_LabelPrefix.setText(caption); if (mnemonic != '\0') m_LabelPrefix.setDisplayedMnemonic(mnemonic); else m_LabelPrefix.setDisplayedMnemonicIndex(-1); if (value.length() > 0) m_LabelPrefixSpacer.setText(" "); else m_LabelPrefixSpacer.setText(""); }
/** * Tries to determine the frame the container is part of. * * @return the parent frame if one exists or null if not */ public Frame getParentFrame() { return GUIHelper.getParentFrame(this); }
/** * Tries to determine the dialog this panel is part of. * * @return the parent dialog if one exists or null if not */ public Dialog getParentDialog() { return GUIHelper.getParentDialog(this); }
/** * Tries to determine the internal frame this panel is part of. * * @return the parent internal frame if one exists or null if not */ public JInternalFrame getParentInternalFrame() { return GUIHelper.getParentInternalFrame(this); }
lbl.setDisplayedMnemonic(GUIHelper.getMnemonic(label)); lbl.setLabelFor(comp);
/** * Initializes the widgets. */ protected void initGUI() { setIconImage(GUIHelper.getIcon("waikato.png").getImage()); }
/** * Performs the actual choosing of an object. * * @return the chosen object or null if none chosen */ protected Font doChoose() { if (m_FontChooser == null) { if (GUIHelper.getParentDialog(this) != null) m_FontChooser = new FontChooser(GUIHelper.getParentDialog(this)); else m_FontChooser = new FontChooser(GUIHelper.getParentFrame(this)); } m_FontChooser.setCurrent(getCurrent()); m_FontChooser.setVisible(true); return m_FontChooser.getCurrent(); }
/** * Displays an error message with the default title "Error". * * @param parent the parent, to make the dialog modal; can be null * @param msg the error message to display * @param t the exception to append to the message */ public static void showErrorMessage(Component parent, String msg, Throwable t) { showErrorMessage(parent, msg + "\n" + Utils.throwableToString(t), "Error"); }
/** * Returns a popup menu when right-clicking on the edit field. * * @return the menu, null if non available */ protected JPopupMenu getPopupMenu() { JPopupMenu result; JMenuItem menuitem; result = new JPopupMenu(); menuitem = new JMenuItem("Copy", GUIHelper.getIcon("copy.gif")); menuitem.setAccelerator(KeyStroke.getKeyStroke("control pressed C")); menuitem.addActionListener(e -> copyToClipboard()); result.add(menuitem); menuitem = new JMenuItem("Paste", GUIHelper.getIcon("paste.gif")); menuitem.setAccelerator(KeyStroke.getKeyStroke("control pressed V")); menuitem.setEnabled(isEditable() && ClipboardHelper.canPasteStringFromClipboard()); menuitem.addActionListener(e -> pasteFromClipboard()); result.add(menuitem); if (m_PopupMenuCustomizer != null) { result.addSeparator(); m_PopupMenuCustomizer.customizePopupMenu(this, result); } return result; }
/** * Tries to determine the internal frame this component is part of. * * @param comp the component to start with * @return the parent internal frame if one exists or null if not */ public static JInternalFrame getParentInternalFrame(Component comp) { if (comp instanceof Container) return (JInternalFrame) getParent((Container) comp, JInternalFrame.class); else return null; }
public void actionPerformed(ActionEvent e) { String msg = checkInput(); if (msg == null) { m_Option = APPROVE_OPTION; setVisible(false); } else { GUIHelper.showErrorMessage(ApprovalDialog.this, msg); } } });
/** * For initializing the GUI. */ @Override protected void initGUI() { JPanel panel; super.initGUI(); setLayout(new BorderLayout()); m_PanelProperties = new ParameterPanel(); add(new BaseScrollPane(m_PanelProperties), BorderLayout.CENTER); m_PanelButtons = new JPanel(new BorderLayout()); add(m_PanelButtons, BorderLayout.SOUTH); panel = new JPanel(new FlowLayout(FlowLayout.LEFT)); m_PanelButtons.add(panel, BorderLayout.WEST); m_ButtonLoad = new JButton(GUIHelper.getIcon("open.gif")); m_ButtonLoad.addActionListener((ActionEvent e) -> loadProperties()); panel.add(m_ButtonLoad); m_ButtonSave = new JButton(GUIHelper.getIcon("save.gif")); m_ButtonSave.addActionListener((ActionEvent e) -> saveProperties()); panel.add(m_ButtonSave); }
/** * Tries to determine the dialog this container is part of. * * @param cont the container to get the dialog for * @return the parent dialog if one exists or null if not */ public static Dialog getParentDialog(Container cont) { return (Dialog) getParent(cont, Dialog.class); }
/** * Pops up a print dialog. */ public void printText() { String msg; try { print(null, null, true, null, null, true); } catch (Exception ex) { ex.printStackTrace(); msg = "Failed to print:\n" + ex; if (getParentDialog() != null) GUIHelper.showErrorMessage(getParentDialog(), msg); else GUIHelper.showErrorMessage(getParentFrame(), msg); } }