List of usage examples for javax.swing Icon getIconWidth
int getIconWidth();
From source file:org.eobjects.datacleaner.panels.OpenAnalysisJobPanel.java
public OpenAnalysisJobPanel(final FileObject file, final AnalyzerBeansConfiguration configuration, final OpenAnalysisJobActionListener openAnalysisJobActionListener) { super(WidgetUtils.BG_COLOR_LESS_BRIGHT, WidgetUtils.BG_COLOR_LESS_BRIGHT); _file = file;/*from www .ja v a 2s . c o m*/ _openAnalysisJobActionListener = openAnalysisJobActionListener; setLayout(new BorderLayout()); setBorder(WidgetUtils.BORDER_LIST_ITEM); final AnalysisJobMetadata metadata = getMetadata(configuration); final String jobName = metadata.getJobName(); final String jobDescription = metadata.getJobDescription(); final String datastoreName = metadata.getDatastoreName(); final boolean isDemoJob = isDemoJob(metadata); final DCPanel labelListPanel = new DCPanel(); labelListPanel.setLayout(new VerticalLayout(4)); labelListPanel.setBorder(new EmptyBorder(4, 4, 4, 0)); final String title; final String filename = file.getName().getBaseName(); if (Strings.isNullOrEmpty(jobName)) { final String extension = FileFilters.ANALYSIS_XML.getExtension(); if (filename.toLowerCase().endsWith(extension)) { title = filename.substring(0, filename.length() - extension.length()); } else { title = filename; } } else { title = jobName; } final JButton titleButton = new JButton(title); titleButton.setFont(WidgetUtils.FONT_HEADER1); titleButton.setForeground(WidgetUtils.BG_COLOR_BLUE_MEDIUM); titleButton.setHorizontalAlignment(SwingConstants.LEFT); titleButton.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, WidgetUtils.BG_COLOR_MEDIUM)); titleButton.setToolTipText("Open job"); titleButton.setOpaque(false); titleButton.setMargin(new Insets(0, 0, 0, 0)); titleButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); titleButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isDemoDatastoreConfigured(datastoreName, configuration)) { _openAnalysisJobActionListener.openFile(_file); } } }); final JButton executeButton = new JButton(executeIcon); executeButton.setOpaque(false); executeButton.setToolTipText("Execute job directly"); executeButton.setMargin(new Insets(0, 0, 0, 0)); executeButton.setBorderPainted(false); executeButton.setHorizontalAlignment(SwingConstants.RIGHT); executeButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (isDemoDatastoreConfigured(datastoreName, configuration)) { final ImageIcon executeIconLarge = ImageManager.get().getImageIcon(IconUtils.ACTION_EXECUTE); final String question = "Are you sure you want to execute the job\n'" + title + "'?"; final int choice = JOptionPane.showConfirmDialog(null, question, "Execute job?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, executeIconLarge); if (choice == JOptionPane.YES_OPTION) { final Injector injector = _openAnalysisJobActionListener.openAnalysisJob(_file); if (injector != null) { final ResultWindow resultWindow = injector.getInstance(ResultWindow.class); resultWindow.open(); resultWindow.startAnalysis(); } } } } }); final DCPanel titlePanel = new DCPanel(); titlePanel.setLayout(new BorderLayout()); titlePanel.add(DCPanel.around(titleButton), BorderLayout.CENTER); titlePanel.add(executeButton, BorderLayout.EAST); labelListPanel.add(titlePanel); if (!Strings.isNullOrEmpty(jobDescription)) { String desc = StringUtils.replaceWhitespaces(jobDescription, " "); desc = StringUtils.replaceAll(desc, " ", " "); final JLabel label = new JLabel(desc); label.setFont(WidgetUtils.FONT_SMALL); labelListPanel.add(label); } final Icon icon; { if (!StringUtils.isNullOrEmpty(datastoreName)) { final JLabel label = new JLabel(" " + datastoreName); label.setFont(WidgetUtils.FONT_SMALL); labelListPanel.add(label); final Datastore datastore = configuration.getDatastoreCatalog().getDatastore(datastoreName); if (isDemoJob) { icon = demoBadgeIcon; } else { icon = IconUtils.getDatastoreSpecificAnalysisJobIcon(datastore); } } else { icon = ImageManager.get().getImageIcon(IconUtils.MODEL_JOB, IconUtils.ICON_SIZE_LARGE); } } final JLabel iconLabel = new JLabel(icon); iconLabel.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight())); add(iconLabel, BorderLayout.WEST); add(labelListPanel, BorderLayout.CENTER); }
From source file:org.executequery.gui.browser.TableDataTab.java
private Object setTableResultsPanel(DatabaseObject databaseObject) { tableDataChanges.clear();/*from w ww. j a v a 2 s.c o m*/ primaryKeyColumns.clear(); foreignKeyColumns.clear(); this.databaseObject = databaseObject; try { initialiseModel(); tableModel.setCellsEditable(false); tableModel.removeTableModelListener(this); if (isDatabaseTable()) { DatabaseTable databaseTable = asDatabaseTable(); if (databaseTable.hasPrimaryKey()) { primaryKeyColumns = databaseTable.getPrimaryKeyColumnNames(); canEditTableLabel.setText("This table has a primary key(s) and data may be edited here"); } if (databaseTable.hasForeignKey()) { foreignKeyColumns = databaseTable.getForeignKeyColumnNames(); } if (primaryKeyColumns.isEmpty()) { canEditTableLabel.setText("This table has no primary keys defined and is not editable here"); } canEditTableNotePanel.setVisible(alwaysShowCanEditNotePanel); } if (!isDatabaseTable()) { canEditTableNotePanel.setVisible(false); } Log.debug("Retrieving data for table - " + databaseObject.getName()); ResultSet resultSet = databaseObject.getData(true); tableModel.createTable(resultSet); if (table == null) { createResultSetTable(); } tableModel.setNonEditableColumns(primaryKeyColumns); TableSorter sorter = new TableSorter(tableModel); table.setModel(sorter); sorter.setTableHeader(table.getTableHeader()); if (isDatabaseTable()) { SortableHeaderRenderer renderer = new SortableHeaderRenderer(sorter) { private ImageIcon primaryKeyIcon = GUIUtilities .loadIcon(BrowserConstants.PRIMARY_COLUMNS_IMAGE); private ImageIcon foreignKeyIcon = GUIUtilities .loadIcon(BrowserConstants.FOREIGN_COLUMNS_IMAGE); @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); Icon keyIcon = iconForValue(value); if (keyIcon != null) { Icon icon = renderer.getIcon(); if (icon != null) { BufferedImage image = new BufferedImage( icon.getIconWidth() + keyIcon.getIconWidth() + 2, Math.max(keyIcon.getIconHeight(), icon.getIconHeight()), BufferedImage.TYPE_INT_ARGB); Graphics graphics = image.getGraphics(); keyIcon.paintIcon(null, graphics, 0, 0); icon.paintIcon(null, graphics, keyIcon.getIconWidth() + 2, 5); setIcon(new ImageIcon(image)); } else { setIcon(keyIcon); } } return renderer; } private ImageIcon iconForValue(Object value) { if (value != null) { String name = value.toString(); if (primaryKeyColumns.contains(name)) { return primaryKeyIcon; } else if (foreignKeyColumns.contains(name)) { return foreignKeyIcon; } } return null; } }; sorter.setTableHeaderRenderer(renderer); } table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); scroller.getViewport().add(table); removeAll(); add(canEditTableNotePanel, canEditTableNoteConstraints); add(scroller, scrollerConstraints); if (displayRowCount && SystemProperties.getBooleanProperty("user", "browser.query.row.count")) { add(rowCountPanel, rowCountPanelConstraints); rowCountField.setText(String.valueOf(sorter.getRowCount())); } } catch (DataSourceException e) { if (!cancelled) { addErrorLabel(e); } else { addCancelledLabel(); } } finally { tableModel.addTableModelListener(this); } setTableProperties(); validate(); repaint(); return "done"; }
From source file:org.openmicroscopy.shoola.agents.metadata.editor.OriginalMetadataComponent.java
/** Initializes the components. */ private void initComponents() { IconManager icons = IconManager.getInstance(); Icon icon = icons.getIcon(IconManager.DOWNLOAD); downloadButton = new JButton(icon); downloadButton.setBackground(UIUtilities.BACKGROUND_COLOR); downloadButton.setOpaque(false);/*from w w w . ja v a2 s .c om*/ UIUtilities.unifiedButtonLookAndFeel(downloadButton); downloadButton.setToolTipText("Download the metadata file."); downloadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { download(); } }); toolBar = buildToolBar(); toolBar.setBackground(UIUtilities.BACKGROUND_COLOR); JXBusyLabel label = new JXBusyLabel(new Dimension(icon.getIconWidth(), icon.getIconHeight())); label.setBackground(UIUtilities.BACKGROUND_COLOR); label.setBusy(true); JPanel p = new JPanel(); p.setBackground(UIUtilities.BACKGROUND_COLOR); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); p.add(label); p.add(Box.createHorizontalStrut(5)); JLabel l = new JLabel("Loading metadata"); l.setBackground(UIUtilities.BACKGROUND_COLOR); p.add(l); statusBar = UIUtilities.buildComponentPanel(p); statusBar.setBackground(UIUtilities.BACKGROUND_COLOR); setBackground(UIUtilities.BACKGROUND_COLOR); setLayout(new BorderLayout(0, 0)); add(statusBar, BorderLayout.NORTH); }
From source file:org.openmicroscopy.shoola.agents.treeviewer.view.ToolBar.java
/** * Helper method to create the tool bar hosting the management items. * // w w w . j av a 2s . co m * @return See above. */ private JComponent createManagementBar() { bar = new JToolBar(); bar.setFloatable(false); bar.setRollover(true); bar.setBorder(null); JToggleButton button = new JToggleButton(controller.getAction(TreeViewerControl.INSPECTOR)); button.setSelected(true); bar.add(button); button = new JToggleButton(controller.getAction(TreeViewerControl.METADATA)); button.setSelected(true); bar.add(button); JButton b = new JButton(controller.getAction(TreeViewerControl.BROWSE)); UIUtilities.unifiedButtonLookAndFeel(b); bar.add(b); switch (TreeViewerAgent.runAsPlugin()) { case TreeViewer.IMAGE_J: b = UIUtilities.formatButtonFromAction(controller.getAction(TreeViewerControl.VIEW)); UIUtilities.unifiedButtonLookAndFeel(b); b.addMouseListener(new MouseAdapter() { /** * Displays the menu when the user releases the mouse. * @see MouseListener#mouseReleased(MouseEvent) */ public void mouseReleased(MouseEvent e) { controller.showMenu(TreeViewer.VIEW_MENU, (JComponent) e.getSource(), e.getPoint()); } }); bar.add(b); break; default: b = new JButton(controller.getAction(TreeViewerControl.VIEW)); UIUtilities.unifiedButtonLookAndFeel(b); bar.add(b); } bar.add(new JSeparator(JSeparator.VERTICAL)); //Now register the agent if any TaskBar tb = TreeViewerAgent.getRegistry().getTaskBar(); List<JComponent> l = tb.getToolBarEntries(TaskBar.AGENTS); if (l != null) { Iterator<JComponent> i = l.iterator(); JComponent comp; while (i.hasNext()) { comp = i.next(); UIUtilities.unifiedButtonLookAndFeel(comp); bar.add(comp); } bar.add(new JSeparator(JSeparator.VERTICAL)); } fullScreen = new JToggleButton(controller.getAction(TreeViewerControl.FULLSCREEN)); fullScreen.setSelected(model.isFullScreen()); //bar.add(fullScreen); if (TreeViewerAgent.isAdministrator()) { b = new JButton(controller.getAction(TreeViewerControl.UPLOAD_SCRIPT)); UIUtilities.unifiedButtonLookAndFeel(b); bar.add(b); } TreeViewerAction a = controller.getAction(TreeViewerControl.AVAILABLE_SCRIPTS); b = new JButton(a); Icon icon = b.getIcon(); Dimension d = new Dimension(UIUtilities.DEFAULT_ICON_WIDTH, UIUtilities.DEFAULT_ICON_HEIGHT); if (icon != null) d = new Dimension(icon.getIconWidth(), icon.getIconHeight()); busyLabel = new JXBusyLabel(d); busyLabel.setVisible(true); b.addMouseListener((RunScriptAction) a); UIUtilities.unifiedButtonLookAndFeel(b); scriptButton = b; bar.add(b); index = bar.getComponentCount() - 1; bar.add(new JSeparator(JSeparator.VERTICAL)); MouseAdapter adapter = new MouseAdapter() { /** * Shows the menu corresponding to the display mode. */ public void mousePressed(MouseEvent me) { createGroupsAndUsersMenu((Component) me.getSource(), me.getPoint()); } }; a = controller.getAction(TreeViewerControl.SWITCH_USER); IconManager icons = IconManager.getInstance(); menuButton = new JButton(icons.getIcon(IconManager.FILTER_MENU)); menuButton.setVisible(true); menuButton.setText(GROUP_DISPLAY_TEXT); menuButton.setHorizontalTextPosition(SwingConstants.LEFT); menuButton.addMouseListener(adapter); bar.add(menuButton); setPermissions(); return bar; }
From source file:org.openstreetmap.josm.tools.ImageProvider.java
/** * Decorate one icon with an overlay icon. * * @param ground the base image//from w w w . j a v a2 s.c o m * @param overlay the overlay image (can be smaller than the base image) * @param pos position of the overlay image inside the base image (positioned * in one of the corners) * @return an icon that represent the overlay of the two given icons. The second icon is layed * on the first relative to the given position. */ public static ImageIcon overlay(Icon ground, Icon overlay, OverlayPosition pos) { GraphicsConfiguration conf = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration(); int w = ground.getIconWidth(); int h = ground.getIconHeight(); int wo = overlay.getIconWidth(); int ho = overlay.getIconHeight(); BufferedImage img = conf.createCompatibleImage(w, h, Transparency.TRANSLUCENT); Graphics g = img.createGraphics(); ground.paintIcon(null, g, 0, 0); int x = 0, y = 0; switch (pos) { case NORTHWEST: x = 0; y = 0; break; case NORTHEAST: x = w - wo; y = 0; break; case SOUTHWEST: x = 0; y = h - ho; break; case SOUTHEAST: x = w - wo; y = h - ho; break; } overlay.paintIcon(null, g, x, y); return new ImageIcon(img); }
From source file:org.pentaho.ui.xul.swing.tags.SwingButton.java
@Override public void layout() { // check type to see if it's a toggleButton if (type == Type.CHECKBOX || type == Type.RADIO) { final AbstractButton oldButton = getButton(); final AbstractButton button = new JToggleButton(); button.setText(oldButton.getText()); button.setIcon(oldButton.getIcon()); button.setEnabled(oldButton.isEnabled()); button.setSelected(this.selected); setButton(button);/*w w w .j a v a2 s .c o m*/ if (this.getOnclick() != null) { this.setOnclick(this.getOnclick()); } } final AbstractButton button = getButton(); // adjust orientation of label and icon if (this.orientation == Orient.VERTICAL) { button.setHorizontalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setVerticalTextPosition(JButton.BOTTOM); } else { button.setVerticalTextPosition(JButton.TOP); } } else { button.setVerticalTextPosition(JButton.CENTER); if (this.dir == Direction.FORWARD) { button.setHorizontalTextPosition(JButton.RIGHT); } else { button.setHorizontalTextPosition(JButton.LEFT); } } // Square button patch. if no label and icon is square, set min/max to square up button final Icon icon = button.getIcon(); if ("".equals(button.getText()) && icon != null && icon.getIconHeight() == icon.getIconWidth()) { Dimension dim = button.getPreferredSize(); button.setMinimumSize(new Dimension(dim.height, dim.height)); button.setPreferredSize(new Dimension(dim.height, dim.height)); } button.setToolTipText(this.getTooltiptext()); super.layout(); }
From source file:util.ui.UiUtilities.java
/** * Scale Icons to a specific width. The aspect ratio is kept. * * @param icon/*w w w .java 2 s. c o m*/ * The icon to scale. * @param newWidth * The new width of the icon. * @return The scaled Icon. */ public static Icon scaleIcon(Icon icon, int newWidth) { if (icon == null) { return null; } return scaleIcon(icon, newWidth, (int) ((newWidth / (float) icon.getIconWidth()) * icon.getIconHeight())); }
From source file:util.ui.UiUtilities.java
/** * Scales Icons to a specific size// ww w .j a v a2 s .co m * * @param icon * Icon that should be scaled * @param width * scaled width * @param height * scaled height * @return Scaled Icon */ public static Icon scaleIcon(Icon icon, int width, int height) { if (icon == null) { return null; } int currentWidth = icon.getIconWidth(); int currentHeight = icon.getIconHeight(); if ((currentWidth == width) && (currentHeight == height)) { return icon; } try { // Create Image with Icon BufferedImage iconImage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = iconImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); AffineTransform z = g2.getTransform(); g2.setTransform(z); icon.paintIcon(null, g2, 0, 0); g2.dispose(); BufferedImage scaled = scaleDown(iconImage, width, height); // Return new Icon return new ImageIcon(scaled); } catch (Exception ex) { ex.printStackTrace(); } return icon; }
From source file:util.ui.UiUtilities.java
/** * Creates a scaled Version of the Icon. * * The scaled Version will have a Background and a Border. * * @param ic//from w ww . j ava 2 s. c o m * @return ImageIcon * @since 2.1 */ public static ImageIcon createChannelIcon(Icon ic) { BufferedImage img = new BufferedImage(42, 22, BufferedImage.TYPE_INT_RGB); if (ic == null) { ic = new ImageIcon("./imgs/tvbrowser16.png"); } int height = 20; int width = 40; if ((ic.getIconWidth() != 0) && (ic.getIconHeight() != 0)) { double iWidth = ic.getIconWidth(); double iHeight = ic.getIconHeight(); if (iWidth / iHeight < 2.0) { width = (int) (iWidth * (20.0 / iHeight)); } else { height = (int) (iHeight * (40.0 / iWidth)); } } ic = scaleIcon(ic, width, height); Graphics2D g = img.createGraphics(); g.setColor(Color.WHITE); g.fillRect(1, 1, 40, 20); int x = 1 + 20 - ic.getIconWidth() / 2; int y = 1 + 10 - ic.getIconHeight() / 2; ic.paintIcon(null, g, x, y); g.setColor(Color.BLACK); g.drawRect(0, 0, 42, 22); return new ImageIcon(img); }