List of usage examples for javax.swing UIManager get
public static Object get(Object key)
From source file:ExtendedTableCellRenderer.java
public void paint(Graphics g) { super.paint(g); if (underlined) { Insets i = getInsets();//from w w w.j av a2s . co m FontMetrics fm = g.getFontMetrics(); Rectangle textRect = new Rectangle(); Rectangle viewRect = new Rectangle(i.left, i.top, getWidth() - (i.right + i.left), getHeight() - (i.bottom + i.top)); SwingUtilities.layoutCompoundLabel(this, fm, getText(), getIcon(), getVerticalAlignment(), getHorizontalAlignment(), getVerticalTextPosition(), getHorizontalTextPosition(), viewRect, new Rectangle(), textRect, getText() == null ? 0 : ((Integer) UIManager.get("Button.textIconGap")).intValue()); int offset = 2; if (UIManager.getLookAndFeel().isNativeLookAndFeel() && System.getProperty("os.name").startsWith("Windows")) { offset = 1; } g.fillRect(textRect.x + ((Integer) UIManager.get("Button.textShiftOffset")).intValue(), textRect.y + fm.getAscent() + ((Integer) UIManager.get("Button.textShiftOffset")).intValue() + offset, textRect.width, 1); } }
From source file:edu.ku.brc.af.ui.db.ViewBasedDisplayDialog.java
@Override public void createUI() { setBackground(viewBasedPanel.getBackground()); JScrollPane scrollPane = UIHelper.createScrollPane(viewBasedPanel, true); scrollPane.setBorder(BorderFactory.createLineBorder(getBackground(), 8)); contentPanel = scrollPane;/*from w ww .java2s . c o m*/ super.createUI(); viewBasedPanel.setOkCancelBtns(okBtn, cancelBtn); Integer width = (Integer) UIManager.get("ScrollBar.width"); if (width == null) { width = (new JScrollBar()).getPreferredSize().width; } Dimension dim1 = getPreferredSize(); dim1.height += width * 2; if (!UIHelper.isMacOS()) { dim1.width += width; } setSize(dim1); }
From source file:com.haulmont.cuba.desktop.App.java
protected void initLookAndFeelDefaults() { InputMapUIResource inputMap = (InputMapUIResource) UIManager.getLookAndFeelDefaults() .get("FormattedTextField.focusInputMap"); inputMap.remove(KeyStroke.getKeyStroke("ESCAPE")); }
From source file:com.mirth.connect.client.ui.Mirth.java
public static void initUIManager() { try {//w w w . jav a 2 s . c o m PlasticLookAndFeel.setPlasticTheme(new MirthTheme()); PlasticXPLookAndFeel look = new PlasticXPLookAndFeel(); UIManager.setLookAndFeel(look); UIManager.put("win.xpstyle.name", "metallic"); LookAndFeelAddons.setAddon(WindowsLookAndFeelAddons.class); /* * MIRTH-1225 and MIRTH-2019: Create alternate key bindings if CTRL is not the same as * the menu shortcut key (i.e. COMMAND on OSX) */ if (InputEvent.CTRL_MASK != Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) { createAlternateKeyBindings(); } if (SystemUtils.IS_OS_MAC) { OSXAdapter.setAboutHandler(Mirth.class, Mirth.class.getDeclaredMethod("aboutMac", (Class[]) null)); OSXAdapter.setQuitHandler(Mirth.class, Mirth.class.getDeclaredMethod("quitMac", (Class[]) null)); } } catch (Exception e) { e.printStackTrace(); } // keep the tooltips from disappearing ToolTipManager.sharedInstance().setDismissDelay(3600000); // TabbedPane defaults // UIManager.put("TabbedPane.selected", new Color(0xffffff)); // UIManager.put("TabbedPane.background",new Color(225,225,225)); // UIManager.put("TabbedPane.tabAreaBackground",new Color(225,225,225)); UIManager.put("TabbedPane.highlight", new Color(225, 225, 225)); UIManager.put("TabbedPane.selectHighlight", new Color(0xc3c3c3)); UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(0, 0, 0, 0)); // TaskPane defaults UIManager.put("TaskPane.titleBackgroundGradientStart", new Color(0xffffff)); UIManager.put("TaskPane.titleBackgroundGradientEnd", new Color(0xffffff)); // Set fonts UIManager.put("TextPane.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("ToggleButton.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("Panel.font", UIConstants.DIALOG_FONT); UIManager.put("PopupMenu.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("OptionPane.font", UIConstants.DIALOG_FONT); UIManager.put("Label.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("Tree.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("ScrollPane.font", UIConstants.DIALOG_FONT); UIManager.put("TextField.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("Viewport.font", UIConstants.DIALOG_FONT); UIManager.put("MenuBar.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("FormattedTextField.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("DesktopIcon.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("TableHeader.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("ToolTip.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("PasswordField.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("TaskPane.font", UIConstants.TEXTFIELD_BOLD_FONT); UIManager.put("Table.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("TabbedPane.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("ProgressBar.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("CheckBoxMenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("ColorChooser.font", UIConstants.DIALOG_FONT); UIManager.put("Button.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("TextArea.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("Spinner.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("RadioButton.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("TitledBorder.font", UIConstants.TEXTFIELD_BOLD_FONT); UIManager.put("EditorPane.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("RadioButtonMenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("ToolBar.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("MenuItem.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("CheckBox.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("JXTitledPanel.title.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("Menu.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("ComboBox.font", UIConstants.TEXTFIELD_PLAIN_FONT); UIManager.put("JXLoginPanel.banner.font", UIConstants.BANNER_FONT); UIManager.put("List.font", UIConstants.TEXTFIELD_PLAIN_FONT); InputMap im = (InputMap) UIManager.get("Button.focusInputMap"); im.put(KeyStroke.getKeyStroke("pressed ENTER"), "pressed"); im.put(KeyStroke.getKeyStroke("released ENTER"), "released"); try { UIManager.put("wizard.sidebar.image", ImageIO.read(com.mirth.connect.client.ui.Frame.class.getResource("images/wizardsidebar.png"))); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.projity.contrib.calendar.JXXMonthView.java
/** * Resets the UI property to a value from the current look and feel. *//*from w ww . jav a 2s . c o m*/ public void updateUI() { super.updateUI(); String[] daysOfTheWeek = (String[]) UIManager.get("JXMonthView.daysOfTheWeek"); // Use some meaningful default if the UIManager doesn't have anything // for us. // PROJITY_MODIFICATION int w0 = 0; int w1 = 1; if (isChinese()) { w0 = 2; w1 = 3; } if (daysOfTheWeek == null) { daysOfTheWeek = new String[DAYS_IN_WEEK]; Calendar weekCal = calendarInstance(); SimpleDateFormat format = dateFormatInstance("E"); for (int i = 0; i < DAYS_IN_WEEK; i++) { weekCal.set(Calendar.DAY_OF_WEEK, i + 1); daysOfTheWeek[i] = format.format(weekCal.getTime()).substring(w0, w1).toUpperCase(); } // daysOfTheWeek = new String[] { "S", "M", "T", "W", "T", "F", "S" }; } setDaysOfTheWeek(daysOfTheWeek); Color color = UIManager.getColor("JXMonthView.monthStringBackground"); // Use some meaningful default if the UIManager doesn't have anything // for us. if (color == null) { color = Color.WHITE;//PROJITY_MODIFICATION } setMonthStringBackground(color); color = UIManager.getColor("JXMonthView.selectedBackground"); // Use some meaningful default if the UIManager doesn't have anything // for us. if (color == null) { color = Color.LIGHT_GRAY; } setSelectedBackground(color); }
From source file:edu.ku.brc.ui.tmanfe.SpreadSheet.java
/** * //from w ww . j a v a 2s .c om */ protected void buildSpreadsheet() { this.setShowGrid(true); int numRows = model.getRowCount(); scrollPane = new JScrollPane(this, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); setAutoResizeMode(JTable.AUTO_RESIZE_OFF); final SpreadSheet ss = this; JButton cornerBtn = UIHelper.createIconBtn("Blank", IconManager.IconSize.Std16, "SelectAll", new ActionListener() { public void actionPerformed(ActionEvent ae) { ss.selectAll(); } }); cornerBtn.setEnabled(true); scrollPane.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, cornerBtn); // Allows row and collumn selections to exit at the same time setCellSelectionEnabled(true); setRowSelectionAllowed(true); setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); addMouseListener(new MouseAdapter() { /* (non-Javadoc) * @see java.awt.event.MouseAdapter#mousePressed(java.awt.event.MouseEvent) */ @SuppressWarnings("synthetic-access") @Override public void mouseReleased(MouseEvent e) { // XXX For Java 5 Bug prevRowSelInx = getSelectedRow(); prevColSelInx = getSelectedColumn(); if (e.getClickCount() == 2) { int rowIndexStart = getSelectedRow(); int colIndexStart = getSelectedColumn(); ss.editCellAt(rowIndexStart, colIndexStart); if (ss.getEditorComponent() != null && ss.getEditorComponent() instanceof JTextComponent) { ss.getEditorComponent().requestFocus(); final JTextComponent txtComp = (JTextComponent) ss.getEditorComponent(); String txt = txtComp.getText(); FontMetrics fm = txtComp.getFontMetrics(txtComp.getFont()); int x = e.getPoint().x - ss.getEditorComponent().getBounds().x - 1; int prevWidth = 0; for (int i = 0; i < txt.length(); i++) { int width = fm.stringWidth(txt.substring(0, i)); int basePlusHalf = prevWidth + (int) (((width - prevWidth) / 2) + 0.5); //System.out.println(prevWidth + " X[" + x + "] " + width+" ["+txt.substring(0, i)+"] " + i + " " + basePlusHalf); //System.out.println(" X[" + x + "] " + prevWidth + " - "+ basePlusHalf+" - " + width+" ["+txt.substring(0, i)+"] " + i); if (x < width) { // Clearing the selection is needed for Window for some reason final int inx = i + (x <= basePlusHalf ? -1 : 0); SwingUtilities.invokeLater(new Runnable() { @SuppressWarnings("synthetic-access") public void run() { txtComp.setSelectionStart(0); txtComp.setSelectionEnd(0); txtComp.setCaretPosition(inx > 0 ? inx : 0); } }); break; } prevWidth = width; } } } } }); // Create a row-header to display row numbers. // This row-header is made of labels whose Borders, // Foregrounds, Backgrounds, and Fonts must be // the one used for the table column headers. // Also ensure that the row-header labels and the table // rows have the same height. //i have no idea WHY this has to be called. i rearranged //the table and find replace panel, // i started getting an array index out of //bounds on the column header ON MAC ONLY. //tried firing this off, first and it fixed the problem.//meg this.getModel().fireTableStructureChanged(); /* * Create the Row Header Panel */ rowHeaderPanel = new JPanel((LayoutManager) null); if (getColumnModel().getColumnCount() > 0) { TableColumn column = getColumnModel().getColumn(0); TableCellRenderer renderer = getTableHeader().getDefaultRenderer(); if (renderer == null) { renderer = column.getHeaderRenderer(); } Component cellRenderComp = renderer.getTableCellRendererComponent(this, column.getHeaderValue(), false, false, -1, 0); cellFont = cellRenderComp.getFont(); } else { cellFont = (new JLabel()).getFont(); } // Calculate Row Height cellBorder = (Border) UIManager.getDefaults().get("TableHeader.cellBorder"); Insets insets = cellBorder.getBorderInsets(tableHeader); FontMetrics metrics = getFontMetrics(cellFont); rowHeight = insets.bottom + metrics.getHeight() + insets.top; rowLabelWidth = metrics.stringWidth("9999") + insets.right + insets.left; Dimension dim = new Dimension(rowLabelWidth, rowHeight * numRows); rowHeaderPanel.setPreferredSize(dim); // need to call this when no layout manager is used. rhCellMouseAdapter = new RHCellMouseAdapter(this); // Adding the row header labels for (int ii = 0; ii < numRows; ii++) { addRow(ii, ii + 1, false); } JViewport viewPort = new JViewport(); dim.height = rowHeight * numRows; viewPort.setViewSize(dim); viewPort.setView(rowHeaderPanel); scrollPane.setRowHeader(viewPort); // Experimental from the web, but I think it does the trick. addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (!ss.isEditing() && !e.isActionKey() && !e.isControlDown() && !e.isMetaDown() && !e.isAltDown() && e.getKeyCode() != KeyEvent.VK_SHIFT && e.getKeyCode() != KeyEvent.VK_TAB && e.getKeyCode() != KeyEvent.VK_ENTER) { log.error("Grabbed the event as input"); int rowIndexStart = getSelectedRow(); int colIndexStart = getSelectedColumn(); if (rowIndexStart == -1 || colIndexStart == -1) return; ss.editCellAt(rowIndexStart, colIndexStart); Component c = ss.getEditorComponent(); if (c instanceof JTextComponent) ((JTextComponent) c).setText(""); } } }); resizeAndRepaint(); // Taken from a JavaWorld Example (But it works) KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false); KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false); KeyStroke paste = KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(), false); Action ssAction = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { SpreadSheet.this.actionPerformed(e); } }; getInputMap().put(cut, "Cut"); getActionMap().put("Cut", ssAction); getInputMap().put(copy, "Copy"); getActionMap().put("Copy", ssAction); getInputMap().put(paste, "Paste"); getActionMap().put("Paste", ssAction); ((JMenuItem) UIRegistry.get(UIRegistry.COPY)).addActionListener(this); ((JMenuItem) UIRegistry.get(UIRegistry.CUT)).addActionListener(this); ((JMenuItem) UIRegistry.get(UIRegistry.PASTE)).addActionListener(this); setSortOrderCycle(SortOrder.ASCENDING, SortOrder.DESCENDING, SortOrder.UNSORTED); }
From source file:net.sf.jabref.JabRefGUI.java
private void setLookAndFeel() { try {//from www . j ava 2s. com String lookFeel; String systemLookFeel = UIManager.getSystemLookAndFeelClassName(); if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) { // FIXME: Problems with OpenJDK and GTK L&F // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638 if (System.getProperty("java.runtime.name").contains("OpenJDK")) { // Metal L&F lookFeel = UIManager.getCrossPlatformLookAndFeelClassName(); LOGGER.warn( "There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution."); } else { lookFeel = systemLookFeel; } } else { lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL); } // FIXME: Open JDK problem if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel) && !System.getProperty("java.runtime.name").contains("OpenJDK")) { // try to avoid ending up with the ugly Metal L&F Plastic3DLookAndFeel lnf = new Plastic3DLookAndFeel(); Plastic3DLookAndFeel.setCurrentTheme(new SkyBluer()); com.jgoodies.looks.Options.setPopupDropShadowEnabled(true); UIManager.setLookAndFeel(lnf); } else { try { UIManager.setLookAndFeel(lookFeel); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { // specified look and feel does not exist on the classpath, so use system l&f UIManager.setLookAndFeel(systemLookFeel); // also set system l&f as default Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel); // notify the user JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), Localization.lang( "Unable to find the requested look and feel and thus the default one is used."), Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE); LOGGER.warn("Unable to find requested look and feel", e); } } } catch (Exception e) { LOGGER.warn("Look and feel could not be set", e); } // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS); if (overrideDefaultFonts) { int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE); UIDefaults defaults = UIManager.getDefaults(); Enumeration<Object> keys = defaults.keys(); for (Object key : Collections.list(keys)) { if ((key instanceof String) && ((String) key).endsWith(".font")) { FontUIResource font = (FontUIResource) UIManager.get(key); font = new FontUIResource(font.getName(), font.getStyle(), fontSize); defaults.put(key, font); } } } }
From source file:gate.gui.docview.AnnotationStack.java
/** * Draw the annotation stack in a JPanel with a GridBagLayout. *//*www . j a v a 2 s. c o m*/ public void drawStack() { // clear the panel removeAll(); boolean textTooLong = text.length() > maxTextLength; int upperBound = text.length() - (maxTextLength / 2); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; /********************** * First row of text * *********************/ gbc.gridwidth = 1; gbc.insets = new java.awt.Insets(10, 10, 10, 10); JLabel labelTitle = new JLabel("Context"); labelTitle.setOpaque(true); labelTitle.setBackground(Color.WHITE); labelTitle.setBorder(new CompoundBorder( new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250), new Color(250, 250, 250).darker()), new EmptyBorder(new Insets(0, 2, 0, 2)))); labelTitle.setToolTipText("Expression and its context."); add(labelTitle, gbc); gbc.insets = new java.awt.Insets(10, 0, 10, 0); int expressionStart = contextBeforeSize; int expressionEnd = text.length() - contextAfterSize; // for each character for (int charNum = 0; charNum < text.length(); charNum++) { gbc.gridx = charNum + 1; if (textTooLong) { if (charNum == maxTextLength / 2) { // add ellipsis dots in case of a too long text displayed add(new JLabel("..."), gbc); // skip the middle part of the text if too long charNum = upperBound + 1; continue; } else if (charNum > upperBound) { gbc.gridx -= upperBound - (maxTextLength / 2) + 1; } } // set the text and color of the feature value JLabel label = new JLabel(text.substring(charNum, charNum + 1)); if (charNum >= expressionStart && charNum < expressionEnd) { // this part is matched by the pattern, color it label.setBackground(new Color(240, 201, 184)); } else { // this part is the context, no color label.setBackground(Color.WHITE); } label.setOpaque(true); // get the word from which belongs the current character charNum int start = text.lastIndexOf(" ", charNum); int end = text.indexOf(" ", charNum); String word = text.substring((start == -1) ? 0 : start, (end == -1) ? text.length() : end); // add a mouse listener that modify the query label.addMouseListener(textMouseListener.createListener(word)); add(label, gbc); } /************************************ * Subsequent rows with annotations * ************************************/ // for each row to display for (StackRow stackRow : stackRows) { String type = stackRow.getType(); String feature = stackRow.getFeature(); if (feature == null) { feature = ""; } String shortcut = stackRow.getShortcut(); if (shortcut == null) { shortcut = ""; } gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 1; gbc.insets = new Insets(0, 0, 3, 0); // add the header of the row JLabel annotationTypeAndFeature = new JLabel(); String typeAndFeature = type + (feature.equals("") ? "" : ".") + feature; annotationTypeAndFeature.setText(!shortcut.equals("") ? shortcut : stackRow.getSet() != null ? stackRow.getSet() + "#" + typeAndFeature : typeAndFeature); annotationTypeAndFeature.setOpaque(true); annotationTypeAndFeature.setBackground(Color.WHITE); annotationTypeAndFeature .setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250), new Color(250, 250, 250).darker()), new EmptyBorder(new Insets(0, 2, 0, 2)))); if (feature.equals("")) { annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type)); } else { annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type, feature)); } gbc.insets = new java.awt.Insets(0, 10, 3, 10); add(annotationTypeAndFeature, gbc); gbc.insets = new java.awt.Insets(0, 0, 3, 0); // add all annotations for this row HashMap<Integer, TreeSet<Integer>> gridSet = new HashMap<Integer, TreeSet<Integer>>(); int gridyMax = gbc.gridy; for (StackAnnotation ann : stackRow.getAnnotations()) { gbc.gridx = ann.getStartNode().getOffset().intValue() - expressionStartOffset + contextBeforeSize + 1; gbc.gridwidth = ann.getEndNode().getOffset().intValue() - ann.getStartNode().getOffset().intValue(); if (gbc.gridx == 0) { // column 0 is already the row header gbc.gridwidth -= 1; gbc.gridx = 1; } else if (gbc.gridx < 0) { // annotation starts before displayed text gbc.gridwidth += gbc.gridx - 1; gbc.gridx = 1; } if (gbc.gridx + gbc.gridwidth > text.length()) { // annotation ends after displayed text gbc.gridwidth = text.length() - gbc.gridx + 1; } if (textTooLong) { if (gbc.gridx > (upperBound + 1)) { // x starts after the hidden middle part gbc.gridx -= upperBound - (maxTextLength / 2) + 1; } else if (gbc.gridx > (maxTextLength / 2)) { // x starts in the hidden middle part if (gbc.gridx + gbc.gridwidth <= (upperBound + 3)) { // x ends in the hidden middle part continue; // skip the middle part of the text } else { // x ends after the hidden middle part gbc.gridwidth -= upperBound - gbc.gridx + 2; gbc.gridx = (maxTextLength / 2) + 2; } } else { // x starts before the hidden middle part if (gbc.gridx + gbc.gridwidth < (maxTextLength / 2)) { // x ends before the hidden middle part // do nothing } else if (gbc.gridx + gbc.gridwidth < upperBound) { // x ends in the hidden middle part gbc.gridwidth = (maxTextLength / 2) - gbc.gridx + 1; } else { // x ends after the hidden middle part gbc.gridwidth -= upperBound - (maxTextLength / 2) + 1; } } } if (gbc.gridwidth == 0) { gbc.gridwidth = 1; } JLabel label = new JLabel(); Object object = ann.getFeatures().get(feature); String value = (object == null) ? " " : Strings.toString(object); if (value.length() > maxFeatureValueLength) { // show the full text in the tooltip label.setToolTipText((value.length() > 500) ? "<html><textarea rows=\"30\" cols=\"40\" readonly=\"readonly\">" + value.replaceAll("(.{50,60})\\b", "$1\n") + "</textarea></html>" : ((value.length() > 100) ? "<html><table width=\"500\" border=\"0\" cellspacing=\"0\">" + "<tr><td>" + value.replaceAll("\n", "<br>") + "</td></tr></table></html>" : value)); if (stackRow.getCrop() == CROP_START) { value = "..." + value.substring(value.length() - maxFeatureValueLength - 1); } else if (stackRow.getCrop() == CROP_END) { value = value.substring(0, maxFeatureValueLength - 2) + "..."; } else {// cut in the middle value = value.substring(0, maxFeatureValueLength / 2) + "..." + value.substring(value.length() - (maxFeatureValueLength / 2)); } } label.setText(value); label.setBackground(AnnotationSetsView.getColor(stackRow.getSet(), ann.getType())); label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); label.setOpaque(true); label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type, String.valueOf(ann.getId()))); // show the feature values in the tooltip if (!ann.getFeatures().isEmpty()) { String width = (Strings.toString(ann.getFeatures()).length() > 100) ? "500" : "100%"; String toolTip = "<html><table width=\"" + width + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">"; Color color = (Color) UIManager.get("ToolTip.background"); float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); color = Color.getHSBColor(hsb[0], hsb[1], Math.max(0f, hsb[2] - hsb[2] * 0.075f)); // darken the color String hexColor = Integer.toHexString(color.getRed()) + Integer.toHexString(color.getGreen()) + Integer.toHexString(color.getBlue()); boolean odd = false; // alternate background color every other row List<Object> features = new ArrayList<Object>(ann.getFeatures().keySet()); //sort the features into alphabetical order Collections.sort(features, new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { return o1.toString().compareToIgnoreCase(o2.toString()); } }); for (Object key : features) { String fv = Strings.toString(ann.getFeatures().get(key)); toolTip += "<tr align=\"left\"" + (odd ? " bgcolor=\"#" + hexColor + "\"" : "") + "><td><strong>" + key + "</strong></td><td>" + ((fv.length() > 500) ? "<textarea rows=\"20\" cols=\"40\" cellspacing=\"0\">" + StringEscapeUtils .escapeHtml(fv.replaceAll("(.{50,60})\\b", "$1\n")) + "</textarea>" : StringEscapeUtils.escapeHtml(fv).replaceAll("\n", "<br>")) + "</td></tr>"; odd = !odd; } label.setToolTipText(toolTip + "</table></html>"); } else { label.setToolTipText("No features."); } if (!feature.equals("")) { label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type, feature, Strings.toString(ann.getFeatures().get(feature)), String.valueOf(ann.getId()))); } // find the first empty row span for this annotation int oldGridy = gbc.gridy; for (int y = oldGridy; y <= (gridyMax + 1); y++) { // for each cell of this row where spans the annotation boolean xSpanIsEmpty = true; for (int x = gbc.gridx; (x < (gbc.gridx + gbc.gridwidth)) && xSpanIsEmpty; x++) { xSpanIsEmpty = !(gridSet.containsKey(x) && gridSet.get(x).contains(y)); } if (xSpanIsEmpty) { gbc.gridy = y; break; } } // save the column x and row y of the current value TreeSet<Integer> ts; for (int x = gbc.gridx; x < (gbc.gridx + gbc.gridwidth); x++) { ts = gridSet.get(x); if (ts == null) { ts = new TreeSet<Integer>(); } ts.add(gbc.gridy); gridSet.put(x, ts); } add(label, gbc); gridyMax = Math.max(gridyMax, gbc.gridy); gbc.gridy = oldGridy; } // add a button at the end of the row gbc.gridwidth = 1; if (stackRow.getLastColumnButton() != null) { // last cell of the row gbc.gridx = Math.min(text.length(), maxTextLength) + 1; gbc.insets = new Insets(0, 10, 3, 0); gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; add(stackRow.getLastColumnButton(), gbc); gbc.insets = new Insets(0, 0, 3, 0); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; } // set the new gridy to the maximum row we put a value gbc.gridy = gridyMax; } if (lastRowButton != null) { // add a configuration button on the last row gbc.insets = new java.awt.Insets(0, 10, 0, 10); gbc.gridx = 0; gbc.gridy++; add(lastRowButton, gbc); } // add an empty cell that takes all remaining space to // align the visible cells at the top-left corner gbc.gridy++; gbc.gridx = Math.min(text.length(), maxTextLength) + 1; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = GridBagConstraints.REMAINDER; gbc.weightx = 1; gbc.weighty = 1; add(new JLabel(""), gbc); validate(); updateUI(); }
From source file:com.floreantpos.main.SetUpWindow.java
private void initializeFont() { java.util.Enumeration keys = UIManager.getDefaults().keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); Object value = UIManager.get(key); if (value != null && value instanceof FontUIResource) { FontUIResource f = (FontUIResource) value; String fontName = f.getFontName(); Font font = new Font(fontName, f.getStyle(), PosUIManager.getDefaultFontSize()); UIManager.put(key, new FontUIResource(font)); }/* ww w .j a v a 2 s. co m*/ } }
From source file:com.jtstand.swing.StatsPanel.java
public JFreeChart getChartTime() { TreeMap<String, List<TestStepInstance>> s = getGroupedSteps(getFilteringIterator()); if (s == null || s.size() == 0) { return null; }/*from w w w . ja v a 2s.c o m*/ TimeSeriesCollection dataset = new TimeSeriesCollection(); for (Iterator<String> en = s.keySet().iterator(); en.hasNext();) { String groupName = en.next(); List<TestStepInstance> stps = s.get(groupName); // TimeSeries pop = new TimeSeries(groupName, Millisecond.class); TimeSeries pop = new TimeSeries(groupName); for (Iterator<TestStepInstance> it = stps.iterator(); it.hasNext();) { TestStepInstance step = it.next(); Number num = getNumber(step); if (num != null) { switch (chartMode) { case STEP_TIME: pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date(step.getStartTime()), TimeZone.getDefault()), num); break; case SEQUENCE_TIME: // pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date(step.getTestSequenceInstance().getStartTime()), RegularTimePeriod.DEFAULT_TIME_ZONE), num); pop.addOrUpdate(RegularTimePeriod.createInstance(Millisecond.class, new Date(step.getTestSequenceInstance().getCreateTime()), TimeZone.getDefault()), num); break; } } } dataset.addSeries(pop); } JFreeChart chart = null; switch (chartMode) { case STEP_TIME: chart = ChartFactory.createTimeSeriesChart(null, "Step Started Time", getValueString(), dataset, isGrouping(), true, false); break; case SEQUENCE_TIME: chart = ChartFactory.createTimeSeriesChart(null, "Sequence Started Time", getValueString(), dataset, isGrouping(), true, false); break; } chart.setBackgroundPaint((Paint) UIManager.get("Panel.background")); XYPlot plot = chart.getXYPlot(); plot.setBackgroundPaint(Color.white); XYLineAndShapeRenderer renderer5 = new XYLineAndShapeRenderer(); renderer5.setBaseSeriesVisibleInLegend(false); plot.setRenderer(renderer5); plot.setDomainGridlinesVisible(true); plot.setRangeGridlinesVisible(true); plot.setRangeCrosshairVisible(true); plot.setDomainCrosshairVisible(true); // chart.setTitle(valueName); placeLimitMarkers(plot, true); //renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator()); renderer5.setBaseToolTipGenerator(StandardXYToolTipGenerator.getTimeSeriesInstance()); /* coloring */ if (isCategorization()) { // TreeMap<String, Color> cmap = new TreeMap<String, Color>(); int i = 0; for (Iterator<String> it = catstats.keySet().iterator(); it.hasNext(); i++) { String groupName = it.next(); Color c = ChartCategories.getColor(i); for (int j = 0; j < dataset.getSeriesCount(); j++) { TimeSeries ts = dataset.getSeries(j); if (ts.getKey().equals(groupName)) { renderer5.setSeriesPaint(j, c); } } } } else { renderer5.setSeriesPaint(0, ChartCategories.getColor(0)); } // chart.addProgressListener(new ChartProgressListener() { // // public void chartProgress(final ChartProgressEvent progress) { // SwingUtilities.invokeLater( // new Runnable() { // // @Override // public void run() { // // System.out.println("progress:" + progress + " " + progress.getType()); // if (progress.getType() == ChartProgressEvent.DRAWING_FINISHED) { // if (plot != null) { // if (plot.isDomainCrosshairVisible() && plot.isDomainCrosshairLockedOnData()) { //// System.out.println("getDomainCrosshairValue:" + plot.getDomainCrosshairValue()); // double xx = plot.getDomainCrosshairValue(); // if (xx != 0.0) { // long x = (long) xx; // System.out.println(new Date(x)); // for (TestStepInstance step : testStepInstances.getSteps()) { // if (step.getStartTime() != null && step.getStartTime().equals(x)) { // testStepInstances.selectStep(step); // } // } // System.out.println(new Date(x)); // } // } //// if (plot.isRangeCrosshairVisible()) { //// System.out.println("getRangeCrosshairValue:" + plot.getRangeCrosshairValue()); //// } // } // } // } // }); // } // }); // chart.addChangeListener(new ChartChangeListener() { // // public void chartChanged(ChartChangeEvent event) { // System.out.println("event:" + event); // if (event != null) { //// JFreeChart chart = event.getChart(); //// System.out.println("chart:" + chart); //// if (chart != null) { //// System.out.println("title:" + event.getChart().getTitle()); //// } // System.out.println("type:" + event.getType()); // if (plot != null) { // if (plot.isDomainCrosshairVisible()) { // System.out.println("getDomainCrosshairValue:" + plot.getDomainCrosshairValue()); // long x = (long) plot.getDomainCrosshairValue(); // for (TestStepInstance step : testStepInstances.getSteps()) { // if (step.getStartTime() != null && step.getStartTime().equals(x)) { // testStepInstances.selectStep(step); // } // } // System.out.println(new Date(x)); // } // if (plot.isRangeCrosshairVisible()) { // System.out.println("getRangeCrosshairValue:" + plot.getRangeCrosshairValue()); // } // } // } // } // }); chart.setTextAntiAlias(false); return chart; }