List of usage examples for javax.swing JScrollPane setVerticalScrollBarPolicy
@BeanProperty(preferred = true, enumerationValues = { "ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED", "ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER", "ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS" }, description = "The scrollpane vertical scrollbar policy") public void setVerticalScrollBarPolicy(int policy)
From source file:com.prodigy4440.view.MainJFrame.java
public final void initComponents() { List<Image> icons = new LinkedList<>(); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited16x16.png")).getImage()); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited32x32.png")).getImage()); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited48x48.png")).getImage()); icons.add(new ImageIcon(getClass().getResource("/com/prodigy4440/ited72x72.png")).getImage()); this.setIconImages(icons); ActionHandler actionHandler = new ActionHandler(this); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(620, 520); this.setLocationRelativeTo(null); this.setTitle("Untitled Document- IgboTextEditor"); southJPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); SoftBevelBorder sbb = new SoftBevelBorder(SoftBevelBorder.LOWERED); southJPanel.setBorder(sbb);/*from w ww.j a va 2 s . c o m*/ menuBar = new JMenuBar(); fileJMenu = new JMenu("File"); fileJMenu.setMnemonic('F'); editJMenu = new JMenu("Edit"); editJMenu.setMnemonic('E'); formatJMenu = new JMenu("Format"); formatJMenu.setMnemonic('A'); viewJMenu = new JMenu("View"); viewJMenu.setMnemonic('V'); helpJMenu = new JMenu("Help"); helpJMenu.setMnemonic('H'); newDocumentJMenuItem = new JMenuItem("New"); newDocumentJMenuItem.addActionListener(actionHandler); newDocumentJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK)); openJMenuItem = new JMenuItem("Open"); openJMenuItem.addActionListener(actionHandler); openJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK)); saveJMenuItem = new JMenuItem("Save"); saveJMenuItem.addActionListener(actionHandler); saveJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK)); printJMenuItem = new JMenuItem("Print"); printJMenuItem.addActionListener(actionHandler); printJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.CTRL_MASK)); exitJMenuItem = new JMenuItem("Exit"); exitJMenuItem.addActionListener(actionHandler); undoJMenuItem = new JMenuItem("Undo"); undoJMenuItem.addActionListener(actionHandler); undoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Event.CTRL_MASK)); redoJMenuItem = new JMenuItem("Redo"); redoJMenuItem.addActionListener(actionHandler); redoJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, Event.CTRL_MASK)); copyJMenuItem = new JMenuItem("Copy"); copyJMenuItem.addActionListener(actionHandler); copyJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK)); cutJMenuItem = new JMenuItem("Cut"); cutJMenuItem.addActionListener(actionHandler); cutJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK)); pasteJMenuItem = new JMenuItem("Paste"); pasteJMenuItem.addActionListener(actionHandler); pasteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Event.CTRL_MASK)); deleteJMenuItem = new JMenuItem("Delete"); deleteJMenuItem.addActionListener(actionHandler); deleteJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK)); selectAllJMenuItem = new JMenuItem("Select All"); selectAllJMenuItem.addActionListener(actionHandler); selectAllJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK)); findJMenuItem = new JMenuItem("Find"); findJMenuItem.addActionListener(actionHandler); findJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, Event.CTRL_MASK)); replaceJMenuItem = new JMenuItem("Replace"); replaceJMenuItem.addActionListener(actionHandler); replaceJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK)); wordWrapJCheckBoxMenuItem = new JCheckBoxMenuItem("Word Wrap"); wordWrapJCheckBoxMenuItem.addActionListener(actionHandler); wordWrapJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, Event.CTRL_MASK)); fontJMenuItem = new JMenuItem("Font"); fontJMenuItem.addActionListener(actionHandler); colorJMenuItem = new JMenuItem("Color"); colorJMenuItem.addActionListener(actionHandler); statusBarJCheckBoxMenuItem = new JCheckBoxMenuItem("Status Bar"); statusBarJCheckBoxMenuItem.addActionListener(actionHandler); statusBarJCheckBoxMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.ALT_MASK)); helpJMenuItem = new JMenuItem("Help"); helpJMenuItem.addActionListener(actionHandler); helpJMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK)); aboutJMenuItem = new JMenuItem("About"); aboutJMenuItem.addActionListener(actionHandler); statusJLabel = new JLabel("Status:"); //Main text area setup textArea = new JTextArea(); undoManager = new UndoManager(); wordSearcher = new WordSearcher(textArea); textArea.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.WHITE)); document = textArea.getDocument(); document.addUndoableEditListener(new UndoableEditListener() { @Override public void undoableEditHappened(UndoableEditEvent e) { undoManager.addEdit(e.getEdit()); } }); font = new Font("Tahoma", Font.PLAIN, 16); textArea.setFont(font); color = Color.BLUE; textArea.setForeground(color); undoManager = new UndoManager(); fileJMenu.add(newDocumentJMenuItem); fileJMenu.addSeparator(); fileJMenu.add(openJMenuItem); fileJMenu.add(saveJMenuItem); fileJMenu.addSeparator(); fileJMenu.add(printJMenuItem); fileJMenu.addSeparator(); fileJMenu.add(exitJMenuItem); editJMenu.add(undoJMenuItem); editJMenu.add(redoJMenuItem); editJMenu.addSeparator(); editJMenu.add(copyJMenuItem); editJMenu.add(cutJMenuItem); editJMenu.add(pasteJMenuItem); editJMenu.addSeparator(); editJMenu.add(deleteJMenuItem); editJMenu.add(selectAllJMenuItem); editJMenu.addSeparator(); editJMenu.add(findJMenuItem); editJMenu.add(replaceJMenuItem); formatJMenu.add(wordWrapJCheckBoxMenuItem); formatJMenu.add(fontJMenuItem); formatJMenu.add(colorJMenuItem); viewJMenu.add(statusBarJCheckBoxMenuItem); helpJMenu.add(helpJMenuItem); helpJMenu.add(aboutJMenuItem); menuBar.add(fileJMenu); menuBar.add(editJMenu); menuBar.add(formatJMenu); menuBar.add(viewJMenu); menuBar.add(helpJMenu); southJPanel.setVisible(false); southJPanel.add(statusJLabel); //JScrollPane setup JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); //setting uo the Jframe this.setJMenuBar(menuBar); this.add(scrollPane, BorderLayout.CENTER); this.add(southJPanel, BorderLayout.SOUTH); textArea.addMouseListener(new MouseInputListener() { @Override public void mouseClicked(MouseEvent e) { Highlighter h = textArea.getHighlighter(); h.removeAllHighlights(); } @Override public void mousePressed(MouseEvent e) { Highlighter h = textArea.getHighlighter(); h.removeAllHighlights(); } @Override public void mouseReleased(MouseEvent e) { } @Override public void mouseEntered(MouseEvent e) { } @Override public void mouseExited(MouseEvent e) { } @Override public void mouseDragged(MouseEvent e) { } @Override public void mouseMoved(MouseEvent e) { } }); textArea.addKeyListener(new IgboKeyListener(textArea)); }
From source file:com.rapidminer.gui.properties.OperatorPropertyPanel.java
@Override public Component getComponent() { if (dockableComponent == null) { JScrollPane scrollPane = new ExtendedJScrollPane(this); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); scrollPane.setBorder(null);/*from ww w.j a va 2 s . c o m*/ dockableComponent = new JPanel(new BorderLayout()); JPanel toolBarPanel = new JPanel(new BorderLayout()); ViewToolBar toolBar = new ViewToolBar(); JToggleButton toggleExpertModeButton = mainFrame.TOGGLE_EXPERT_MODE_ACTION.createToggleButton(); toggleExpertModeButton.setText(null); toolBar.add(toggleExpertModeButton); showHelpAction.setSelected(isShowParameterHelp()); JToggleButton helpToggleButton = showHelpAction.createToggleButton(); helpToggleButton.setText(null); toolBar.add(helpToggleButton); Action infoOperatorAction = new InfoOperatorAction() { private static final long serialVersionUID = 6758272768665592429L; @Override protected Operator getOperator() { return mainFrame.getFirstSelectedOperator(); } }; toolBar.add(infoOperatorAction); JToggleButton enableOperatorButton = new ToggleActivationItem(mainFrame.getActions()) .createToggleButton(); enableOperatorButton.setText(null); toolBar.add(enableOperatorButton); Action renameOperatorAction = new ResourceAction(true, "rename_in_processrenderer") { { setCondition(OPERATOR_SELECTED, MANDATORY); } private static final long serialVersionUID = -3104160320178045540L; @Override public void actionPerformed(ActionEvent e) { Operator operator = mainFrame.getFirstSelectedOperator(); String name = SwingTools.showInputDialog("rename_operator", operator.getName()); if (name != null && name.length() > 0) { operator.rename(name); } } }; toolBar.add(renameOperatorAction); toolBar.add(new DeleteOperatorAction()); breakpointButton.addToToolBar(toolBar); // toolBar.add(mainFrame.getActions().MAKE_DIRTY_ACTION); toolBarPanel.add(toolBar, BorderLayout.NORTH); JPanel headerPanel = new JPanel(); headerPanel.setBackground(SwingTools.LIGHTEST_BLUE); headerPanel.add(headerLabel); headerPanel.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.LIGHT_GRAY)); toolBarPanel.add(headerPanel, BorderLayout.SOUTH); dockableComponent.add(toolBarPanel, BorderLayout.NORTH); dockableComponent.add(scrollPane, BorderLayout.CENTER); // compatibility level and warnings JPanel southPanel = new JPanel(new BorderLayout()); southPanel.add(expertModeHintLabel, BorderLayout.CENTER); compatibilityLabel.setLabelFor(compatibilityLevelSpinner); compatibilityLevelSpinner.setPreferredSize( new Dimension(80, (int) compatibilityLevelSpinner.getPreferredSize().getHeight())); compatibilityPanel.add(compatibilityLabel); compatibilityPanel.add(compatibilityLevelSpinner); southPanel.add(compatibilityPanel, BorderLayout.SOUTH); dockableComponent.add(southPanel, BorderLayout.SOUTH); } return dockableComponent; }
From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java
private JPanel setUpFieldListPanel() { JPanel inputPanel = new JPanel(); // Panel Layout GridBagLayout gbl = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); con.weightx = 0;/*from w ww.j a va 2 s .c o m*/ con.insets = new Insets(5, 5, 0, 5); con.fill = GridBagConstraints.HORIZONTAL; inputPanel.setLayout(gbl); // Border TitledBorder titledBorder1 = new TitledBorder(BorderFactory.createLineBorder(new Color(153, 153, 153), 2), Localization.lang("Work options")); inputPanel.setBorder(titledBorder1); inputPanel.setMinimumSize(new Dimension(10, 10)); JScrollPane fieldScroller = new JScrollPane(fieldList); fieldScroller.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); // insert buttons insertButton.addActionListener(event -> insertTextForTag(override.isSelected())); // Radio buttons append.setToolTipText(Localization.lang("Append the selected text to BibTeX field")); append.setMnemonic(KeyEvent.VK_A); append.setSelected(true); override.setToolTipText(Localization.lang("Override the BibTeX field by the selected text")); override.setMnemonic(KeyEvent.VK_O); override.setSelected(false); //Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(append); group.add(override); JPanel radioPanel = new JPanel(new GridLayout(0, 1)); radioPanel.add(append); radioPanel.add(override); // insert sub components JLabel label1 = new JLabel(Localization.lang("Available BibTeX fields")); con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(label1, con); inputPanel.add(label1); con.gridwidth = GridBagConstraints.REMAINDER; con.gridheight = 8; con.weighty = 1; con.fill = GridBagConstraints.BOTH; gbl.setConstraints(fieldScroller, con); inputPanel.add(fieldScroller); con.fill = GridBagConstraints.HORIZONTAL; con.weighty = 0; con.gridwidth = 2; gbl.setConstraints(radioPanel, con); inputPanel.add(radioPanel); con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(insertButton, con); inputPanel.add(insertButton); return inputPanel; }
From source file:PagingTester.java
public static JScrollPane createPagingScrollPaneForTable(JTable jt) { JScrollPane jsp = new JScrollPane(jt); TableModel tmodel = jt.getModel(); // Don't choke if this is called on a regular table . . . if (!(tmodel instanceof PagingModel)) { return jsp; }//from www. j av a 2s. com // Okay, go ahead and build the real scrollpane final PagingModel model = (PagingModel) tmodel; final JButton upButton = new JButton(new ArrowIcon(ArrowIcon.UP)); upButton.setEnabled(false); // starts off at 0, so can't go up final JButton downButton = new JButton(new ArrowIcon(ArrowIcon.DOWN)); if (model.getPageCount() <= 1) { downButton.setEnabled(false); // One page...can't scroll down } upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageUp(); // If we hit the top of the data, disable the up button. if (model.getPageOffset() == 0) { upButton.setEnabled(false); } downButton.setEnabled(true); } }); downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { model.pageDown(); // If we hit the bottom of the data, disable the down button. if (model.getPageOffset() == (model.getPageCount() - 1)) { downButton.setEnabled(false); } upButton.setEnabled(true); } }); // Turn on the scrollbars; otherwise we won't get our corners. jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); // Add in the corners (page up/down). jsp.setCorner(ScrollPaneConstants.UPPER_RIGHT_CORNER, upButton); jsp.setCorner(ScrollPaneConstants.LOWER_RIGHT_CORNER, downButton); return jsp; }
From source file:ac.openmicrolabs.view.gui.OMLLoggerView.java
private JPanel createContentPane(final TimeSeriesCollection t, final String graphTitle, final double graphTimeRange, final String[] signals) { btmPanel.remove(reportButton);//from w ww .ja v a 2s . co m chanLabel = new JLabel[signals.length]; int activeSignalCount = 0; for (int i = 0; i < signals.length; i++) { chanLabel[i] = new JLabel(h.format("label", (char) ((i / PIN_COUNT) + ASCII_OFFSET) + "-0x" + String.format("%02x", (i % PIN_COUNT) + SLAVE_BITS).toUpperCase())); chanLabel[i].setHorizontalAlignment(JLabel.CENTER); if (signals[i] != null) { activeSignalCount++; } else { chanLabel[i].setEnabled(false); } } typeLabel = new JLabel[activeSignalCount]; valLabel = new JLabel[activeSignalCount]; minLabel = new JLabel[activeSignalCount]; maxLabel = new JLabel[activeSignalCount]; avgLabel = new JLabel[activeSignalCount]; int index = 0; for (int i = 0; i < signals.length; i++) { if (signals[i] != null) { typeLabel[index] = new JLabel(h.format("body", signals[i])); typeLabel[index].setHorizontalAlignment(JLabel.CENTER); index++; } } for (int i = 0; i < activeSignalCount; i++) { valLabel[i] = new JLabel(); valLabel[i].setHorizontalAlignment(JLabel.CENTER); minLabel[i] = new JLabel(); minLabel[i].setHorizontalAlignment(JLabel.CENTER); maxLabel[i] = new JLabel(); maxLabel[i].setHorizontalAlignment(JLabel.CENTER); avgLabel[i] = new JLabel(); avgLabel[i].setHorizontalAlignment(JLabel.CENTER); } // Set up main panel. JPanel mainPanel = new JPanel(); mainPanel.setLayout(null); mainPanel.setBackground(Color.white); // Create graph. snsChart = ChartFactory.createTimeSeriesChart(graphTitle, GRAPH_X_LABEL, GRAPH_Y_LABEL, t, true, true, false); final XYPlot plot = snsChart.getXYPlot(); ValueAxis axis = plot.getDomainAxis(); axis.setAutoRange(true); axis.setFixedAutoRange(graphTimeRange); axis = plot.getRangeAxis(); axis.setRange(graphMinY, graphMaxY); ChartPanel snsChartPanel = new ChartPanel(snsChart); snsChartPanel.setPreferredSize(new Dimension(FRAME_WIDTH - PAD20, GRAPH_HEIGHT - PAD10)); // Set up graph panel. final JPanel graphPanel = new JPanel(); graphPanel.setSize(FRAME_WIDTH - PAD20, GRAPH_HEIGHT); graphPanel.setLocation(0, 0); graphPanel.setBackground(Color.white); graphPanel.add(snsChartPanel); // Set up results panel. final JPanel resultsPanel = createResultsPane(); // Set up scroll pane. final JScrollPane scrollPane = new JScrollPane(resultsPanel); scrollPane.setSize(FRAME_WIDTH - PAD20, FRAME_HEIGHT - BTM_HEIGHT - GRAPH_HEIGHT + PAD8); scrollPane.setLocation(PAD5, GRAPH_HEIGHT); scrollPane.setBackground(Color.white); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); // Set results panel size. resultsPanel.setPreferredSize(new Dimension(PAD40 + (signals.length * RESULTS_COL_WIDTH), FRAME_HEIGHT - BTM_HEIGHT - GRAPH_HEIGHT - PAD120)); resultsPanel.revalidate(); // Set up bottom panel. btmPanel.setLayout(null); btmPanel.setSize(FRAME_WIDTH, BTM_HEIGHT); btmPanel.setLocation(0, this.getHeight() - BTM_HEIGHT); btmPanel.setBackground(Color.white); // Instantiate bottom panel objects. footerLabel.setSize(LABEL_WIDTH, LABEL_HEIGHT); footerLabel.setLocation(LABEL_X, LABEL_Y); footerLabel.setText(""); doneButton.setIcon(new ImageIcon("img/22x22/stop.png")); doneButton.setSize(DONE_WIDTH, DONE_HEIGHT); doneButton.setLocation(FRAME_WIDTH - PAD20 - doneButton.getWidth(), PAD15); progressBar = new JProgressBar(); progressBar.setSize(FRAME_WIDTH - PAD40 - doneButton.getWidth() - footerLabel.getWidth(), PAD20); progressBar.setValue(0); progressBar.setLocation(footerLabel.getWidth() + PAD10, PAD22); // Populate bottom panel. btmPanel.add(footerLabel); btmPanel.add(progressBar); btmPanel.add(doneButton); // Populate main panel. mainPanel.add(graphPanel); mainPanel.add(scrollPane); mainPanel.add(btmPanel); return mainPanel; }
From source file:de.codesourcery.eve.skills.ui.components.impl.ImportMarketLogFileComponent.java
private JPanel createSplitPanePanel(JComponent top, JScrollPane bottom) { final JScrollPane resultPane = new JScrollPane(top); resultPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); resultPane.setMinimumSize(new Dimension(400, 150)); resultPane.setPreferredSize(new Dimension(600, 200)); bottom.setMinimumSize(new Dimension(100, 200)); bottom.setPreferredSize(new Dimension(600, 300)); final JSplitPane pane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, top, bottom); // pane.setResizeWeight( 0.5 ); pane.setDividerLocation(200);//from ww w . j a v a 2 s .c o m pane.setContinuousLayout(true); final JPanel contentPanel = new JPanel(); contentPanel.setLayout(new BorderLayout()); contentPanel.add(pane); return contentPanel; }
From source file:com.jamfsoftware.jss.healthcheck.ui.HealthReport.java
/** * Creates a new Health Report JPanel window from the Health Check JSON string. * Will throw errors if the JSON is not formatted correctly. *///from ww w .j a v a 2 s .c om public HealthReport(final String JSON) throws Exception { LOGGER.debug("[DEBUG] - JSON String (Copy entire below line)"); LOGGER.debug(JSON.replace("\n", "")); LOGGER.debug("Attempting to parse Health Report JSON"); JsonElement report = new JsonParser().parse(JSON); JsonObject healthcheck = ((JsonObject) report).get("healthcheck").getAsJsonObject(); Boolean show_system_info = true; JsonObject system = null; //Check if the check JSON contains system information and show/hide panels accordingly later. system = ((JsonObject) report).get("system").getAsJsonObject(); final JsonObject data = ((JsonObject) report).get("checkdata").getAsJsonObject(); this.JSSURL = extractData(healthcheck, "jss_url"); if (extractData(system, "iscloudjss").contains("true")) { show_system_info = false; isCloudJSS = true; } PanelIconGenerator iconGen = new PanelIconGenerator(); PanelGenerator panelGen = new PanelGenerator(); //Top Level Frame final JFrame frame = new JFrame("JSS Health Check Report"); //Top Level Content JPanel outer = new JPanel(new BorderLayout()); //Two Blank Panels for the Sides JPanel blankLeft = new JPanel(); blankLeft.add(new JLabel(" ")); JPanel blankRight = new JPanel(); blankRight.add(new JLabel(" ")); blankLeft.setMinimumSize(new Dimension(100, 100)); blankRight.setMinimumSize(new Dimension(100, 100)); //Header JPanel header = new JPanel(); header.add(new JLabel("Total Computers: " + extractData(healthcheck, "totalcomputers"))); header.add(new JLabel("Total Mobile Devices: " + extractData(healthcheck, "totalmobile"))); header.add(new JLabel("Total Users: " + extractData(healthcheck, "totalusers"))); int total_devices = Integer.parseInt(extractData(healthcheck, "totalcomputers")) + Integer.parseInt(extractData(healthcheck, "totalmobile")); SimpleDateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm:ss"); Date dateobj = new Date(); header.add(new JLabel("JSS Health Check Report Performed On " + df.format(dateobj))); //Foooter JPanel footer = new JPanel(); JButton view_report_json = new JButton("View Report JSON"); footer.add(view_report_json); JButton view_activation_code = new JButton("View Activation Code"); footer.add(view_activation_code); JButton test_again = new JButton("Run Test Again"); footer.add(test_again); JButton view_text_report = new JButton("View Text Report"); footer.add(view_text_report); JButton about_and_terms = new JButton("About and Terms"); footer.add(about_and_terms); //Middle Content, set the background white and give it a border JPanel content = new JPanel(new GridLayout(2, 3)); content.setBackground(Color.WHITE); content.setBorder(BorderFactory.createLineBorder(Color.BLACK)); //Setup Outer Placement outer.add(header, BorderLayout.NORTH); outer.add(footer, BorderLayout.SOUTH); outer.add(blankLeft, BorderLayout.WEST); outer.add(blankRight, BorderLayout.EAST); outer.add(content, BorderLayout.CENTER); //Don't show system info if it is hosted. JPanel system_info = null; JPanel database_health = null; if (show_system_info) { //Read all of the System information variables from the JSON and perform number conversions. String[][] sys_info = { { "Operating System", extractData(system, "os") }, { "Java Version", extractData(system, "javaversion") }, { "Java Vendor", extractData(system, "javavendor") }, { "Processor Cores", extractData(system, "proc_cores") }, { "Is Clustered?", extractData(system, "clustering") }, { "Web App Directory", extractData(system, "webapp_dir") }, { "Free Memory", Double.toString( round((Double.parseDouble(extractData(system, "free_memory")) / 1000000000), 2)) + " GB" }, { "Max Memory", Double.toString( round((Double.parseDouble(extractData(system, "max_memory")) / 1000000000), 2)) + " GB" }, { "Memory currently in use", Double.toString(round( (Double.parseDouble(extractData(system, "memory_currently_in_use")) / 1000000000), 2)) + " GB" }, { "Total space", Double.toString( round((Double.parseDouble(extractData(system, "total_space")) / 1000000000), 2)) + " GB" }, { "Free Space", Double.toString(round( (Double.parseDouble(extractData(system, "usable_space")) / 1000000000), 2)) + " GB" } }; //Generate the system info panel. String systemInfoIcon = iconGen.getSystemInfoIconType( Integer.parseInt(extractData(healthcheck, "totalcomputers")) + Integer.parseInt(extractData(healthcheck, "totalmobile")), extractData(system, "javaversion"), Double.parseDouble(extractData(system, "max_memory"))); system_info = panelGen.generateContentPanelSystem("System Info", sys_info, "JSS Minimum Requirements", "http://www.jamfsoftware.com/resources/casper-suite-system-requirements/", systemInfoIcon); //Get all of the DB information. String[][] db_health = { { "Database Size", extractData(system, "database_size") + " MB" } }; if (extractData(system, "database_size").equals("0")) { db_health[0][0] = "Unable to connect to database."; } String[][] large_sql_tables = extractArrayData(system, "largeSQLtables", "table_name", "table_size"); String[][] db_health_for_display = ArrayUtils.addAll(db_health, large_sql_tables); //Generate the DB Health panel. String databaseIconType = iconGen.getDatabaseInfoIconType(total_devices, Double.parseDouble(extractData(system, "database_size")), extractArrayData(system, "largeSQLtables", "table_name", "table_size").length); database_health = panelGen.generateContentPanelSystem("Database Health", db_health_for_display, "Too Large SQL Tables", "https://google.com", databaseIconType); if (!databaseIconType.equals("green")) { this.showLargeDatabase = true; } } int password_strenth = 0; if (extractData(data, "password_strength", "uppercase?").contains("true")) { password_strenth++; } if (extractData(data, "password_strength", "lowercase?").contains("true")) { password_strenth++; } if (extractData(data, "password_strength", "number?").contains("true")) { password_strenth++; } if (extractData(data, "password_strength", "spec_chars?").contains("true")) { password_strenth++; } String password_strength_desc = ""; if (password_strenth == 4) { password_strength_desc = "Excellent"; } else if (password_strenth == 3 || password_strenth == 2) { password_strength_desc = "Good"; } else if (password_strenth == 1) { this.strongerPassword = true; password_strength_desc = "Poor"; } else { this.strongerPassword = true; password_strength_desc = "Needs Updating"; } if (extractData(data, "loginlogouthooks", "is_configured").contains("false")) { this.loginInOutHooks = true; } try { if (Integer.parseInt(extractData(data, "device_row_counts", "computers").trim()) != Integer .parseInt(extractData(data, "device_row_counts", "computers_denormalized").trim())) { this.computerDeviceTableCountMismatch = true; } if (Integer.parseInt(extractData(data, "device_row_counts", "mobile_devices").trim()) != Integer .parseInt(extractData(data, "device_row_counts", "mobile_devices_denormalized").trim())) { this.mobileDeviceTableCountMismatch = true; } } catch (Exception e) { System.out.println("Unable to parse device row counts."); } if ((extractData(system, "mysql_version").contains("5.6.16") || extractData(system, "mysql_version").contains("5.6.20")) && (extractData(system, "os").contains("OS X") || extractData(system, "os").contains("Mac") || extractData(system, "os").contains("OSX"))) { this.mysql_osx_version_bug = true; } //Get all of the information for the JSS ENV and generate the panel. String[][] env_info = { { "Checkin Frequency", extractData(data, "computercheckin", "frequency") + " Minutes" }, { "Log Flushing", extractData(data, "logflushing", "log_flush_time") }, { "Log In/Out Hooks", extractData(data, "loginlogouthooks", "is_configured") }, { "Computer EA", extractData(data, "computerextensionattributes", "count") }, { "Mobile Deivce EA", extractData(data, "mobiledeviceextensionattributes", "count") }, { "Password Strength", password_strength_desc }, { "SMTP Server", extractData(data, "smtpserver", "server") }, { "Sender Email", extractData(data, "smtpserver", "sender_email") }, { "GSX Connection", extractData(data, "gsxconnection", "status") } }; String[][] vpp_accounts = extractArrayData(data, "vppaccounts", "name", "days_until_expire"); String[][] ldap_servers = extractArrayData(data, "ldapservers", "name", "type", "address", "id"); String envIconType = iconGen.getJSSEnvIconType(Integer.parseInt(extractData(healthcheck, "totalcomputers")), Integer.parseInt(extractData(data, "computercheckin", "frequency")), Integer.parseInt(extractData(data, "computerextensionattributes", "count")), Integer.parseInt(extractData(data, "mobiledeviceextensionattributes", "count"))); JPanel env = panelGen.generateContentPanelEnv("JSS Environment", env_info, vpp_accounts, ldap_servers, "", "", envIconType); //Get all of the group information from the JSON, merge the arrays, and then generate the groups JPanel. String[][] groups_1 = ArrayUtils.addAll( extractArrayData(data, "computergroups", "name", "nested_groups_count", "criteria_count", "id"), extractArrayData(data, "mobiledevicegroups", "name", "nested_groups_count", "criteria_count", "id")); String[][] groups_2 = ArrayUtils.addAll(groups_1, extractArrayData(data, "usergroups", "name", "nested_groups_count", "criteria_count", "id")); String groupIconType = iconGen.getGroupIconType("groups", countJSONObjectSize(data, "computergroups") + countJSONObjectSize(data, "mobiledevicegroups") + countJSONObjectSize(data, "usergroups")); JPanel groups = panelGen.generateContentPanelGroups("Groups", groups_2, "", "", groupIconType); if (groupIconType.equals("yellow") || groupIconType.equals("red")) { this.showGroupsHelp = true; } //Get all of the information for the printers, policies and scripts, then generate the panel. String[][] printers = extractArrayData(data, "printer_warnings", "model"); String[][] policies = extractArrayData(data, "policies_with_issues", "name", "ongoing", "checkin_trigger"); String[][] scripts = extractArrayData(data, "scripts_needing_update", "name"); String[][] certs = { { "SSL Cert Issuer", extractData(data, "tomcat", "ssl_cert_issuer") }, { "SLL Cert Expires", extractData(data, "tomcat", "cert_expires") }, { "MDM Push Cert Expires", extractData(data, "push_cert_expirations", "mdm_push_cert") }, { "Push Proxy Expires", extractData(data, "push_cert_expirations", "push_proxy") }, { "Change Management Enabled?", extractData(data, "changemanagment", "isusinglogfile") }, { "Log File Path:", extractData(data, "changemanagment", "logpath") } }; String policiesScriptsIconType = iconGen.getPoliciesAndScriptsIconType( extractArrayData(data, "policies_with_issues", "name", "ongoing", "checkin_trigger").length, extractArrayData(data, "scripts_needing_update", "name").length); JPanel policies_scripts = panelGen.generateContentPanelPoliciesScripts( "Policies, Scripts, Certs and Change", policies, scripts, printers, certs, "", "", policiesScriptsIconType); if (extractArrayData(data, "policies_with_issues", "name", "ongoing", "checkin_trigger").length > 0) { this.showPolicies = true; } if (extractArrayData(data, "scripts_needing_update", "name").length > 0) { this.showScripts = true; } if (extractData(data, "changemanagment", "isusinglogfile").contains("false")) { this.showChange = true; } this.showCheckinFreq = iconGen.showCheckinFreq; this.showExtensionAttributes = iconGen.showCheckinFreq; this.showSystemRequirements = iconGen.showSystemRequirements; this.showScalability = iconGen.showScalability; //Update Panel Gen Variables updatePanelGenVariables(panelGen); //Generate the Help Section. content.add(panelGen.generateContentPanelHelp("Modifications to Consider", "", "", "blank")); //If contains system information, add those panels, otherwise just continue adding the rest of the panels. if (show_system_info) { content.add(system_info); content.add(database_health); } content.add(env); content.add(groups); content.add(policies_scripts); //View report action listner. //Opens a window with the health report JSON listed view_report_json.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel middlePanel = new JPanel(); middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Health Report JSON")); // create the middle panel components JTextArea display = new JTextArea(16, 58); display.setEditable(false); //Make a new GSON object so the text can be Pretty Printed. Gson gson = new GsonBuilder().setPrettyPrinting().create(); String pp_json = gson.toJson(JSON.trim()); display.append(JSON); JScrollPane scroll = new JScrollPane(display); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //Add Textarea in to middle panel middlePanel.add(scroll); JFrame frame = new JFrame(); frame.add(middlePanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); //Action listener for the Terms, About and Licence button. //Opens a new window with the AS IS License, 3rd Party Libs used and a small about section about_and_terms.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel middlePanel = new JPanel(); middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "About, Licence and Terms")); // create the middle panel components JTextArea display = new JTextArea(16, 58); display.setEditable(false); display.append(StringConstants.ABOUT); display.append("\n\nThird Party Libraries Used:"); display.append( " Apache Commons Codec, Google JSON (gson), Java X JSON, JDOM, JSON-Simple, MySQL-connector"); display.append(StringConstants.LICENSE); JScrollPane scroll = new JScrollPane(display); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //Add Textarea in to middle panel middlePanel.add(scroll); JFrame frame = new JFrame(); frame.add(middlePanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); //Listener for a button click to open a window containing the activation code. view_activation_code.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(frame, extractData(data, "activationcode", "code") + "\nExpires: " + extractData(data, "activationcode", "expires")); } }); view_text_report.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JPanel middlePanel = new JPanel(); middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Text Health Report")); // create the middle panel components JTextArea display = new JTextArea(16, 58); display.setEditable(false); //Make a new GSON object so the text can be Pretty Printed. display.append(new HealthReportHeadless(JSON).getReportString()); JScrollPane scroll = new JScrollPane(display); scroll.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); //Add Textarea in to middle panel middlePanel.add(scroll); JFrame frame = new JFrame(); frame.add(middlePanel); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); //Listener for the Test Again button. Opens a new UserPrompt object and keeps the Health Report open in the background. test_again.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { new UserPrompt(); } catch (Exception ex) { ex.printStackTrace(); } } }); frame.add(outer); frame.setExtendedState(JFrame.MAXIMIZED_BOTH); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.setVisible(true); DetectVM vm_checker = new DetectVM(); if (EnvironmentUtil.isMac()) { if (vm_checker.getIsVM()) { JOptionPane.showMessageDialog(new JFrame(), "The tool has detected that it is running in a OSX Virtual Machine.\nThe opening of links is not supported on OSX VMs.\nPlease open the tool on a non-VM computer and run it again OR\nyou can also copy the JSON from the report to a non-VM OR view the text report.\nIf you are not running a VM, ignore this message.", "VM Detected", JOptionPane.ERROR_MESSAGE); } } }
From source file:lol.search.RankedStatsPage.java
private JScrollPane championSelectPanel() { JPanel mainPanel = new JPanel(new FlowLayout()); //mainPanel.setBorder(BorderFactory.createLineBorder(Color.WHITE)); mainPanel.setBackground(backgroundColor); for (int i = 0; i < this.objChampRankedList.size(); i++) { int position = counter; ImageIcon champImageIcon = this.OBJ_RANKED_STATS_BY_ID.getChampionIconOf(this.champKeyList.get(i)); JButton champButton = new JButton(); champButton.setIcon(champImageIcon); if (i == 0) { champButton.setIcon(this.profileIcon); champButton.setToolTipText("Overall Stats"); }//w w w. j a va 2s. c o m champButton.setPreferredSize(new Dimension(55, 55)); champButton.setBackground(Color.BLACK); champButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { //button pressed background.setIcon(OBJ_GAME_STATIC_DATA.getBackgroundImageIcon(champKeyList.get(position))); loadArtLabel.setIcon(OBJ_GAME_STATIC_DATA.initLoadingArt(champKeyList.get(position))); nameHeader.setText(OBJ_ALL_CHAMPS_BY_ID.getChampNameFromId(champIdList.get(position))); titleHeader.setText(" " + OBJ_ALL_CHAMPS_BY_ID.getChampTitleFromId(champIdList.get(position))); String sessionsWon = ""; String sessionsLost = ""; String winPercentString = ""; try { int won = objChampRankedList.get(position).getJSONObject("stats") .getInt("totalSessionsWon"); sessionsWon = Integer.toString(won); int lost = objChampRankedList.get(position).getJSONObject("stats") .getInt("totalSessionsLost"); sessionsLost = Integer.toString(lost); winPercentString = getWinPercentage(won, lost); totalGamesInt = won + lost; avgKillsLabelValue.setText(new DecimalFormat("##.##") .format((double) objChampRankedList.get(position).getJSONObject("stats") .getInt("totalChampionKills") / (double) totalGamesInt)); avgAssistsLabelValue .setText(new DecimalFormat("##.##").format((double) objChampRankedList.get(position) .getJSONObject("stats").getInt("totalAssists") / (double) totalGamesInt)); avgDeathsLabelValue.setText(new DecimalFormat("##.##") .format((double) objChampRankedList.get(position).getJSONObject("stats") .getInt("totalDeathsPerSession") / (double) totalGamesInt)); avgMinionKillsLabelValue.setText(new DecimalFormat("##.##") .format((double) objChampRankedList.get(position).getJSONObject("stats") .getInt("totalMinionKills") / (double) totalGamesInt)); avgDoubleKillsLabelValue.setText(new DecimalFormat("##.##") .format((double) objChampRankedList.get(position).getJSONObject("stats") .getInt("totalDoubleKills") / (double) totalGamesInt)); avgTripleKillsLabelValue.setText(new DecimalFormat("##.##") .format((double) objChampRankedList.get(position).getJSONObject("stats") .getInt("totalTripleKills") / (double) totalGamesInt)); avgQuadKillsLabelValue.setText(new DecimalFormat("##.##") .format((double) objChampRankedList.get(position).getJSONObject("stats") .getInt("totalQuadraKills") / (double) totalGamesInt)); avgPentaKillsLabelValue.setText(new DecimalFormat("##.##") .format((double) objChampRankedList.get(position).getJSONObject("stats") .getInt("totalPentaKills") / (double) totalGamesInt)); totalKillsLabelValue.setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalChampionKills"))); totalDeathsLabelValue .setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalDeathsPerSession"))); totalAssistsLabelValue .setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalAssists"))); totalMinionsLabelValue .setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalMinionKills"))); totalDoubleKillsLabelValue .setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalDoubleKills"))); totalTripleKillsLabelValue .setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalTripleKills"))); totalQuadKillsLabelValue .setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalQuadraKills"))); totalPentaKillsLabelValue .setText(new DecimalFormat("#######").format((double) objChampRankedList .get(position).getJSONObject("stats").getInt("totalPentaKills"))); } catch (JSONException ex) { Logger.getLogger(RankedStatsPage.class.getName()).log(Level.SEVERE, null, ex); } totalWins.setText(sessionsWon); totalLosses.setText(sessionsLost); winPercent.setText(winPercentString + "%"); totalGamesPlayed.setText(String.valueOf(totalGamesInt)); masterFrame.revalidate(); masterFrame.repaint(); } }); champButton.setToolTipText(OBJ_ALL_CHAMPS_BY_ID.getChampNameFromId(champIdList.get(position))); champButtons.add(champButton); //champButton.setBorder(BorderFactory.createLineBorder(Color.BLACK)); counter++; } for (int i = 0; i < champButtons.size(); i++) { mainPanel.add(champButtons.get(i)); mainPanel.revalidate(); } JScrollPane scrollPane = new JScrollPane(mainPanel); scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER); scrollPane.setPreferredSize(new Dimension(1200, 85)); scrollPane.setBackground(new Color(0, 0, 0, 100)); scrollPane.setBorder(BorderFactory.createLineBorder(Color.BLACK)); scrollPane.getHorizontalScrollBar().setUI(new BasicScrollBarUI() { @Override protected void configureScrollBarColors() { this.thumbColor = new Color(124, 124, 124, 255); this.trackColor = Color.BLACK; } }); return scrollPane; }
From source file:com.vgi.mafscaling.MafCompare.java
/** * Initialize the contents of the frame. */// w w w .j a v a2 s . c o m private void initialize() { try { ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg")); setTitle(Title); setIconImage(tableImage.getImage()); setBounds(100, 100, 621, 372); setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE); setSize(Config.getCompWindowSize()); setLocation(Config.getCompWindowLocation()); setLocationRelativeTo(null); setVisible(false); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { Utils.clearTable(origMafTable); Utils.clearTable(newMafTable); Utils.clearTable(compMafTable); Config.setCompWindowSize(getSize()); Config.setCompWindowLocation(getLocation()); origMafData.clear(); newMafData.clear(); } }); JPanel dataPanel = new JPanel(); GridBagLayout gbl_dataPanel = new GridBagLayout(); gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 }; gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 }; gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 }; gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 }; dataPanel.setLayout(gbl_dataPanel); getContentPane().add(dataPanel); JLabel origLabel = new JLabel(origMaf); GridBagConstraints gbc_origLabel = new GridBagConstraints(); gbc_origLabel.anchor = GridBagConstraints.PAGE_START; gbc_origLabel.insets = new Insets(1, 1, 1, 5); gbc_origLabel.weightx = 0; gbc_origLabel.weighty = 0; gbc_origLabel.gridx = 0; gbc_origLabel.gridy = 0; gbc_origLabel.gridheight = 2; dataPanel.add(origLabel, gbc_origLabel); JLabel newLabel = new JLabel(newMaf); GridBagConstraints gbc_newLabel = new GridBagConstraints(); gbc_newLabel.anchor = GridBagConstraints.PAGE_START; gbc_newLabel.insets = new Insets(1, 1, 1, 5); gbc_newLabel.weightx = 0; gbc_newLabel.weighty = 0; gbc_newLabel.gridx = 0; gbc_newLabel.gridy = 2; gbc_newLabel.gridheight = 2; dataPanel.add(newLabel, gbc_newLabel); JLabel compLabel = new JLabel("Change"); GridBagConstraints gbc_compLabel = new GridBagConstraints(); gbc_compLabel.anchor = GridBagConstraints.PAGE_START; gbc_compLabel.insets = new Insets(1, 1, 1, 5); gbc_compLabel.weightx = 0; gbc_compLabel.weighty = 0; gbc_compLabel.gridx = 0; gbc_compLabel.gridy = 4; dataPanel.add(compLabel, gbc_compLabel); JLabel origVoltLabel = new JLabel("volt"); GridBagConstraints gbc_origVoltLabel = new GridBagConstraints(); gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_origVoltLabel.weightx = 0; gbc_origVoltLabel.weighty = 0; gbc_origVoltLabel.gridx = 1; gbc_origVoltLabel.gridy = 0; dataPanel.add(origVoltLabel, gbc_origVoltLabel); JLabel origGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_origGsLabel = new GridBagConstraints(); gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_origGsLabel.insets = new Insets(1, 1, 1, 5); gbc_origGsLabel.weightx = 0; gbc_origGsLabel.weighty = 0; gbc_origGsLabel.gridx = 1; gbc_origGsLabel.gridy = 1; dataPanel.add(origGsLabel, gbc_origGsLabel); JLabel newVoltLabel = new JLabel("volt"); GridBagConstraints gbc_newVoltLabel = new GridBagConstraints(); gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START; gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5); gbc_newVoltLabel.weightx = 0; gbc_newVoltLabel.weighty = 0; gbc_newVoltLabel.gridx = 1; gbc_newVoltLabel.gridy = 2; dataPanel.add(newVoltLabel, gbc_newVoltLabel); JLabel newGsLabel = new JLabel(" g/s"); GridBagConstraints gbc_newGsLabel = new GridBagConstraints(); gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START; gbc_newGsLabel.insets = new Insets(1, 1, 1, 5); gbc_newGsLabel.weightx = 0; gbc_newGsLabel.weighty = 0; gbc_newGsLabel.gridx = 1; gbc_newGsLabel.gridy = 3; dataPanel.add(newGsLabel, gbc_newGsLabel); JLabel compPctLabel = new JLabel(" % "); GridBagConstraints gbc_compPctLabel = new GridBagConstraints(); gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START; gbc_compPctLabel.insets = new Insets(1, 1, 1, 5); gbc_compPctLabel.weightx = 0; gbc_compPctLabel.weighty = 0; gbc_compPctLabel.gridx = 1; gbc_compPctLabel.gridy = 4; dataPanel.add(compPctLabel, gbc_compPctLabel); JPanel tablesPanel = new JPanel(); GridBagLayout gbl_tablesPanel = new GridBagLayout(); gbl_tablesPanel.columnWidths = new int[] { 0 }; gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 }; gbl_tablesPanel.columnWeights = new double[] { 0.0 }; gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 }; tablesPanel.setLayout(gbl_tablesPanel); JScrollPane mafScrollPane = new JScrollPane(tablesPanel); mafScrollPane.setMinimumSize(new Dimension(1600, 107)); mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20)); mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER); mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); GridBagConstraints gbc_mafScrollPane = new GridBagConstraints(); gbc_mafScrollPane.weightx = 1.0; gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START; gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL; gbc_mafScrollPane.gridx = 2; gbc_mafScrollPane.gridy = 0; gbc_mafScrollPane.gridheight = 5; dataPanel.add(mafScrollPane, gbc_mafScrollPane); origMafTable = new JTable(); origMafTable.setColumnSelectionAllowed(true); origMafTable.setCellSelectionEnabled(true); origMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); origMafTable.setRowHeight(RowHeight); origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); origMafTable.setTableHeader(null); Utils.initializeTable(origMafTable, ColumnWidth); GridBagConstraints gbc_origMafTable = new GridBagConstraints(); gbc_origMafTable.anchor = GridBagConstraints.PAGE_START; gbc_origMafTable.insets = new Insets(0, 0, 0, 0); gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_origMafTable.weightx = 1.0; gbc_origMafTable.weighty = 0; gbc_origMafTable.gridx = 0; gbc_origMafTable.gridy = 0; tablesPanel.add(origMafTable, gbc_origMafTable); excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true); newMafTable = new JTable(); newMafTable.setColumnSelectionAllowed(true); newMafTable.setCellSelectionEnabled(true); newMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); newMafTable.setRowHeight(RowHeight); newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount)); newMafTable.setTableHeader(null); Utils.initializeTable(newMafTable, ColumnWidth); GridBagConstraints gbc_newMafTable = new GridBagConstraints(); gbc_newMafTable.anchor = GridBagConstraints.PAGE_START; gbc_newMafTable.insets = new Insets(0, 0, 0, 0); gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_newMafTable.weightx = 1.0; gbc_newMafTable.weighty = 0; gbc_newMafTable.gridx = 0; gbc_newMafTable.gridy = 1; tablesPanel.add(newMafTable, gbc_newMafTable); excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true); compMafTable = new JTable(); compMafTable.setColumnSelectionAllowed(true); compMafTable.setCellSelectionEnabled(true); compMafTable.setBorder(new LineBorder(new Color(0, 0, 0))); compMafTable.setRowHeight(RowHeight); compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount)); compMafTable.setTableHeader(null); Utils.initializeTable(compMafTable, ColumnWidth); NumberFormatRenderer numericRenderer = new NumberFormatRenderer(); numericRenderer.setFormatter(new DecimalFormat("0.000")); compMafTable.setDefaultRenderer(Object.class, numericRenderer); GridBagConstraints gbc_compMafTable = new GridBagConstraints(); gbc_compMafTable.anchor = GridBagConstraints.PAGE_START; gbc_compMafTable.insets = new Insets(0, 0, 0, 0); gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL; gbc_compMafTable.weightx = 1.0; gbc_compMafTable.weighty = 0; gbc_compMafTable.gridx = 0; gbc_compMafTable.gridy = 2; tablesPanel.add(compMafTable, gbc_compMafTable); compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true); TableModelListener origTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = origMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, newMafTable); Utils.ensureColumnCount(colCount, compMafTable); origMafData.clear(); String origY, origX, newY; for (int i = 0; i < colCount; ++i) { origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) { origX = origMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, origX)) origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false); newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } origMafData.fireSeriesChanged(); } } }; TableModelListener newTableListener = new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { int colCount = newMafTable.getColumnCount(); Utils.ensureColumnCount(colCount, origMafTable); Utils.ensureColumnCount(colCount, compMafTable); newMafData.clear(); String newY, newX, origY; for (int i = 0; i < colCount; ++i) { newY = newMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, newY)) { newX = newMafTable.getValueAt(0, i).toString(); if (Pattern.matches(Utils.fpRegex, newX)) newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false); origY = origMafTable.getValueAt(1, i).toString(); if (Pattern.matches(Utils.fpRegex, origY)) compMafTable.setValueAt( ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i); } else break; } newMafData.fireSeriesChanged(); } } }; origMafTable.getModel().addTableModelListener(origTableListener); newMafTable.getModel().addTableModelListener(newTableListener); Action action = new AbstractAction() { private static final long serialVersionUID = 8148393537657380215L; public void actionPerformed(ActionEvent e) { TableCellListener tcl = (TableCellListener) e.getSource(); if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) { if (Pattern.matches(Utils.fpRegex, origMafTable.getValueAt(1, tcl.getColumn()).toString())) { double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString()) / 100.0 + 1.0; newMafTable.setValueAt( Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr, 1, tcl.getColumn()); } } else compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn()); } }; setCompMafCellListener(new TableCellListener(compMafTable, action)); // CHART JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, false, true, false); chart.setBorderVisible(true); chartPanel = new ChartPanel(chart, true, true, true, true, true); chartPanel.setAutoscrolls(true); GridBagConstraints gbl_chartPanel = new GridBagConstraints(); gbl_chartPanel.anchor = GridBagConstraints.PAGE_START; gbl_chartPanel.fill = GridBagConstraints.BOTH; gbl_chartPanel.insets = new Insets(1, 1, 1, 1); gbl_chartPanel.weightx = 1.0; gbl_chartPanel.weighty = 1.0; gbl_chartPanel.gridx = 0; gbl_chartPanel.gridy = 5; gbl_chartPanel.gridheight = 1; gbl_chartPanel.gridwidth = 3; dataPanel.add(chartPanel, gbl_chartPanel); XYSplineRenderer lineRenderer = new XYSplineRenderer(3); lineRenderer.setUseFillPaint(true); lineRenderer.setBaseToolTipGenerator( new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new DecimalFormat("0.00"), new DecimalFormat("0.00"))); Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f); lineRenderer.setSeriesStroke(0, stroke); lineRenderer.setSeriesStroke(1, stroke); lineRenderer.setSeriesPaint(0, new Color(201, 0, 0)); lineRenderer.setSeriesPaint(1, new Color(0, 0, 255)); lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5)); lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5)); lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() { private static final long serialVersionUID = -4045338273187150888L; public String generateLabel(XYDataset dataset, int series) { XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series); return xys.getDescription(); } }); NumberAxis mafvDomain = new NumberAxis(XAxisName); mafvDomain.setAutoRangeIncludesZero(false); mafvDomain.setAutoRange(true); mafvDomain.setAutoRangeStickyZero(false); NumberAxis mafgsRange = new NumberAxis(YAxisName); mafgsRange.setAutoRangeIncludesZero(false); mafgsRange.setAutoRange(true); mafgsRange.setAutoRangeStickyZero(false); XYSeriesCollection lineDataset = new XYSeriesCollection(); origMafData.setDescription(origMaf); newMafData.setDescription(newMaf); lineDataset.addSeries(origMafData); lineDataset.addSeries(newMafData); XYPlot plot = chart.getXYPlot(); plot.setRangePannable(true); plot.setDomainPannable(true); plot.setDomainGridlinePaint(Color.DARK_GRAY); plot.setRangeGridlinePaint(Color.DARK_GRAY); plot.setBackgroundPaint(new Color(224, 224, 224)); plot.setDataset(0, lineDataset); plot.setRenderer(0, lineRenderer); plot.setDomainAxis(0, mafvDomain); plot.setRangeAxis(0, mafgsRange); plot.mapDatasetToDomainAxis(0, 0); plot.mapDatasetToRangeAxis(0, 0); LegendTitle legend = new LegendTitle(plot.getRenderer()); legend.setItemFont(new Font("Arial", 0, 10)); legend.setPosition(RectangleEdge.TOP); chart.addLegend(legend); } catch (Exception e) { logger.error(e); } }
From source file:org.jfree.chart.demo.SuperDemo.java
private JPanel createSourceCodePanel() { JPanel jpanel = new JPanel(new BorderLayout()); jpanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4)); JEditorPane jeditorpane = new JEditorPane(); jeditorpane.setEditable(false);//w ww . ja v a 2s .c o m java.net.URL url = (SuperDemo.class).getResource("source.html"); if (url != null) try { jeditorpane.setPage(url); } catch (IOException ioexception) { System.err.println("Attempted to read a bad URL: " + url); } else System.err.println("Couldn't find file: source.html"); JScrollPane jscrollpane = new JScrollPane(jeditorpane); jscrollpane.setVerticalScrollBarPolicy(20); jscrollpane.setPreferredSize(new Dimension(250, 145)); jscrollpane.setMinimumSize(new Dimension(10, 10)); jpanel.add(jscrollpane); return jpanel; }