/** * Adds a component to a panel with a grid bag layout * * @param comp * @param panel * @param gridx * @param gridy */ public static void addToGridBag(final Component comp, final JPanel panel, final int gridx, final int gridy) { addToGridBag(comp, panel, gridx, gridy, 1, 1); }
public void centerOnScreen() { WidgetUtils.centerOnScreen(this); }
public static DCPanel decorateWithShadow(final JComponent comp) { final boolean outline; if (comp instanceof DCTablePanel) { // table panels has it's own special outline outline = false; } else { outline = true; } return decorateWithShadow(comp, outline, 4); }
@Override public void uncaughtException(final Thread t, final Throwable e) { if (isIgnoreIssue(e)) { logger.debug("Ignoring uncaught exception", e); return; } if (e instanceof RestrictedFunctionalityException) { logger.debug("Handling restricted functionality exception", e); final StringBuilder sb = new StringBuilder(e.getMessage()); final RestrictedFunctionalityCallToAction[] callToActions = ((RestrictedFunctionalityException) e).getCallToActions(); for (final RestrictedFunctionalityCallToAction callToAction : callToActions) { sb.append('\n'); sb.append(" - " + callToAction.getName() + " - " + callToAction.getHref()); } final String detailedMessage = sb.toString(); WidgetUtils .invokeSwingAction(() -> WidgetUtils.showErrorMessage("Restricted functionality", detailedMessage)); return; } logger.error("Thread " + t.getName() + " threw uncaught exception", e); WidgetUtils.invokeSwingAction(() -> WidgetUtils.showErrorMessage("Unexpected error!", e)); }
@Override protected JComponent getDialogContent() { final DCPanel contentPanel = new DCPanel(); contentPanel.setLayout(new GridBagLayout()); final DCPanel listPanel = new DCPanel(); listPanel.setBackground(WidgetUtils.COLOR_WELL_BACKGROUND); listPanel.setLayout(new VerticalLayout()); listPanel.add(_serverList); final DCLabel label = DCLabel.dark("Please select the Hadoop cluster to connect to:"); label.setFont(WidgetUtils.FONT_HEADER2); WidgetUtils.addToGridBag(label, contentPanel, 0, 0, 1.0, 0.0); WidgetUtils.addToGridBag(listPanel, contentPanel, 0, 1, 1, 2, GridBagConstraints.NORTH, 10, 1.0, 1.0); WidgetUtils.addToGridBag(_optionsButton, contentPanel, 1, 1, GridBagConstraints.SOUTH); WidgetUtils.addToGridBag(_okButton, contentPanel, 1, 2, GridBagConstraints.NORTH); final JScrollPane scrolleable = WidgetUtils.scrolleable(contentPanel); scrolleable.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); final DCPanel outerPanel = new DCPanel(WidgetUtils.COLOR_DEFAULT_BACKGROUND); outerPanel.setLayout(new BorderLayout()); outerPanel.add(scrolleable, BorderLayout.CENTER); outerPanel.setPreferredSize(getDialogWidth(), 300); return outerPanel; }
protected JComponent wrapInScrollPane(final JComponent panel) { final JScrollPane scroll = WidgetUtils.scrolleable(panel); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); return scroll; }
public AnalysisResult getResult() { if (_result == null && _worker != null) { try { _result = _worker.get(); } catch (final Exception e) { WidgetUtils.showErrorMessage("Unable to fetch result", e); } } return _result; }
final InputColumn<?>[] currentValue = _callback.getColumns(); if (currentValue == null || currentValue.length == 0) { WidgetUtils.showErrorMessage("No columns selected", "Cannot reorder columns, when none is selected."); return; WidgetUtils.showErrorMessage("Nothing to reorder", "You need to have at least two selected colummns to be able to reorder them."); return; panel.setBorder(new EmptyBorder(10, 10, 10, 10)); panel.setLayout(new BorderLayout()); panel.add(WidgetUtils.decorateWithShadow(tablePanel), BorderLayout.CENTER); panel.add(buttonPanel, BorderLayout.SOUTH); size.height = Math.max(size.height, 600); dialog.setSize(size); WidgetUtils.centerOnScreen(dialog); dialog.setVisible(true);
private void appendMessage(final String message) { WidgetUtils.invokeSwingAction(() -> _executionLogTextArea.append(message)); }
public static JButton createDefaultButton(final String text, final Icon icon) { final JButton b = createBasicButton(text, icon); WidgetUtils.setDefaultButtonStyle(b); return b; }
dropTableButton.addActionListener(e -> { if (!confirmTextField.getText().trim().equalsIgnoreCase(_table.getName().trim())) { WidgetUtils.showErrorMessage("Enter the table's name to confirm", "The names do not match. Please enter '" + _table.getName() + "' if you wish to drop the table."); WidgetUtils.addToGridBag(label, panel, 0, row, 2, 1, GridBagConstraints.CENTER, 4, 1.0, 1.0); row++; WidgetUtils.addToGridBag(confirmTextField, panel, 0, row, 2, 1); row++; WidgetUtils.addToGridBag(dropTableButton, panel, 0, row, 0.5, 0.1); WidgetUtils.addToGridBag(cancelButton, panel, 1, row, 0.5, 0.1);
_centerPanel.setVisible(false); final DCPanel decoratedLimitTextField = WidgetUtils.decorateWithShadow(_limitTextField, false, 0); WidgetUtils.addToGridBag(DCLabel.dark("Max rows:"), buttonPanel, 1, 1, GridBagConstraints.CENTER); WidgetUtils.addToGridBag(decoratedLimitTextField, buttonPanel, 2, 1, GridBagConstraints.CENTER); WidgetUtils.addToGridBag(_queryButton, buttonPanel, 1, 2, 2, 1); final DCPanel decoratedTextField = WidgetUtils.decorateWithShadow(scrolledTextArea);
public static void showErrorMessage(final String shortMessage, final String detailedMessage, final Throwable exception) { final Throwable presentedException = ErrorUtils.unwrapForPresentation(exception); if (exception == null) { showErrorMessage(shortMessage, detailedMessage); return; } final String finalDetailedMessage = detailedMessage == null ? "" : detailedMessage; final String finalShortMessage = shortMessage == null ? "" : shortMessage; final ErrorInfo info = new ErrorInfo(finalShortMessage, finalDetailedMessage, null, "error", presentedException, ErrorLevel.SEVERE, null); final JXErrorPane errorPane = new JXErrorPane(); errorPane.setErrorInfo(info); final JDialog dialog = JXErrorPane.createDialog(null, errorPane); centerOnScreen(dialog); JXErrorPane.setDefaultLocale(Locale.ENGLISH); dialog.setLocale(Locale.ENGLISH); dialog.setModal(true); dialog.setTitle(finalShortMessage); dialog.setVisible(true); dialog.toFront(); }
public static JButton createDarkButton(final String text, final Icon icon) { final JButton b = createBasicButton(text, icon); WidgetUtils.setDarkButtonStyle(b); return b; }
@Override protected void paintComponent(final Graphics g) { final int width = getWidth(); final int height = getHeight(); if (isOpaque()) { g.setColor(WidgetUtils.BG_COLOR_DARK); g.fillRect(0, 0, width, height); } final int barWidth; if (isIndeterminate()) { barWidth = 0; } else { barWidth = getBarWidth(getValue()); } if (barWidth > 0) { g.setColor(_progressBarColor); g.fillRect(0, 0, barWidth, height / 2); g.setColor(WidgetUtils.slightlyDarker(_progressBarColor)); g.fillRect(0, height / 2, barWidth, height / 2); g.setColor(WidgetUtils.slightlyBrighter(_progressBarColor)); g.drawRect(0, 0, barWidth, height); } } }
@Override protected Color getSelectColor() { return WidgetUtils.slightlyDarker(WidgetUtils.BG_COLOR_BLUE_DARK); }
public static void setAppropriateFont(final JLabel label) { final String text = label.getText(); if (text == null) { return; } Font font = label.getFont(); final int canDisplay = font.canDisplayUpTo(text); if (canDisplay != -1) { logger.info("Default font ('{}') was unable to display text ('{}'), searching for alternative.", font.getName(), text); // if the label contains undisplayable characters, look for a // different font able of displaying the characters. font = findCompatibleFont(text, font); label.setFont(font); } }
WidgetUtils.addToGridBag(DCLabel.bright("<html><b>Original name </b></html>"), formPanel, 1, row, 1, 1, GridBagConstraints.EAST, 20); WidgetUtils.addToGridBag(DCLabel.bright("<html><b>New name </b></html>"), formPanel, 2, row, 1, 1, GridBagConstraints.EAST, 20); final JXTextField textField = entry.getValue(); WidgetUtils.addToGridBag( new JLabel(imageManager.getImageIcon("images/model/variable.png", IconUtils.ICON_SIZE_SMALL)), formPanel, 0, row); WidgetUtils.addToGridBag(DCLabel.bright(columnName), formPanel, 1, row, GridBagConstraints.WEST); WidgetUtils.addToGridBag(textField, formPanel, 2, row, GridBagConstraints.WEST); WidgetUtils.addToGridBag(formPanel, centerPanel, 0, 0, 1, 1, GridBagConstraints.NORTH, 4, 0, 0); WidgetUtils.addToGridBag(buttonPanel, centerPanel, 0, 2, 1, 1, GridBagConstraints.CENTER, 4, 0, 0.1); centerPanel.setBorder(WidgetUtils.BORDER_TOP_PADDING); return WidgetUtils.scrolleable(outerPanel);
private JComponent scrolleable(final JComponent comp) { final JScrollPane scroll = WidgetUtils.scrolleable(comp); scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); return scroll; }
@Override protected void process(final List<Task> chunks) { for (final Task task : chunks) { try { task.execute(); } catch (final Exception e) { WidgetUtils.showErrorMessage("Error processing transfer chunk: " + task, e); } } }