List of usage examples for java.awt GridBagConstraints NONE
int NONE
To view the source code for java.awt GridBagConstraints NONE.
Click Source Link
From source file:org.gtdfree.GTDFree.java
private Component getOverviewPane() { if (overview == null) { overview = new JPanel(); overview.setLayout(new GridBagLayout()); int row = 0; JLabel l = new JLabel(Messages.getString("GTDFree.OW.Workflow")); //$NON-NLS-1$ l.setFont(l.getFont().deriveFont((float) (l.getFont().getSize() * 5.0 / 4.0)).deriveFont(Font.BOLD)); overview.add(l, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(18, 18, 7, 18), 0, 0)); overview.add(//from ww w . ja v a 2 s . com new OverviewTabPanel(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_collecting), TAB_COLECT, Messages.getString("GTDFree.Collect")), //$NON-NLS-1$ new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); overview.add( new OverviewTabPanel(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_processing), TAB_PROCESS, Messages.getString("GTDFree.Process")), //$NON-NLS-1$ new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); overview.add( new OverviewTabPanel(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_review), TAB_ORGANIZE, Messages.getString("GTDFree.Organize")), //$NON-NLS-1$ new GridBagConstraints(0, row++, 1, 1, 0, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); overview.add( new OverviewTabPanel(ApplicationHelper.getIcon(ApplicationHelper.icon_name_large_queue_execute), TAB_EXECUTE, Messages.getString("GTDFree.Execute")), //$NON-NLS-1$ new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); l = new JLabel(Messages.getString("GTDFree.OW.Summary")); //$NON-NLS-1$ l.setFont(l.getFont().deriveFont((float) (l.getFont().getSize() * 5.0 / 4.0)).deriveFont(Font.BOLD)); overview.add(l, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(14, 18, 7, 18), 0, 0)); SummaryLabel sl = new SummaryLabel("inbucketCount") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { tabbedPane.setSelectedIndex(TAB_PROCESS); } @Override void updateText(PropertyChangeEvent arg0) { if (getSummaryBean().getInbucketCount() > 0) { label.setText( getSummaryBean().getInbucketCount() + " " + Messages.getString("GTDFree.OW.Bucket") //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("GTDFree.OW.Process")); //$NON-NLS-1$ //$NON-NLS-2$ button.setVisible(true); } else { label.setText(getSummaryBean().getInbucketCount() + " " //$NON-NLS-1$ + Messages.getString("GTDFree.OW.Bucket")); //$NON-NLS-1$ button.setVisible(false); } } }; overview.add(sl, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); sl = new SummaryLabel("pastActions") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { tabbedPane.setSelectedIndex(TAB_ORGANIZE); organizePane.openTicklerForPast(); } @Override void updateText(PropertyChangeEvent arg0) { if (getSummaryBean().getPastActions() > 0) { label.setText( getSummaryBean().getPastActions() + " " + Messages.getString("GTDFree.OW.Reminder") //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("GTDFree.OW.Update")); //$NON-NLS-1$ //$NON-NLS-2$ button.setVisible(true); } else { label.setText(getSummaryBean().getPastActions() + " " //$NON-NLS-1$ + Messages.getString("GTDFree.OW.Reminder")); //$NON-NLS-1$ button.setVisible(false); } } }; overview.add(sl, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); sl = new SummaryLabel("todayActions") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { tabbedPane.setSelectedIndex(TAB_ORGANIZE); organizePane.openTicklerForToday(); } @Override void updateText(PropertyChangeEvent arg0) { if (getSummaryBean().getTodayActions() > 0) { label.setText( getSummaryBean().getTodayActions() + " " + Messages.getString("GTDFree.OW.Due") //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("GTDFree.OW.Tickler")); //$NON-NLS-1$ //$NON-NLS-2$ button.setVisible(true); } else { label.setText( getSummaryBean().getTodayActions() + " " + Messages.getString("GTDFree.OW.Due")); //$NON-NLS-1$ //$NON-NLS-2$ button.setVisible(false); } } }; overview.add(sl, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); sl = new SummaryLabel("queueCount") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { tabbedPane.setSelectedIndex(TAB_EXECUTE); } @Override void updateText(PropertyChangeEvent arg0) { if (getSummaryBean().getQueueCount() > 0) { label.setText( getSummaryBean().getQueueCount() + " " + Messages.getString("GTDFree.OW.Queue") //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("GTDFree.OW.Execute")); //$NON-NLS-1$ //$NON-NLS-2$ button.setVisible(true); } else { label.setText( getSummaryBean().getQueueCount() + " " + Messages.getString("GTDFree.OW.Queue")); //$NON-NLS-1$ //$NON-NLS-2$ button.setVisible(false); } } }; overview.add(sl, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); sl = new SummaryLabel("mainCounts") { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { GTDFree.this.getActionMap().get("importDialog").actionPerformed(e); //$NON-NLS-1$ engine.getGlobalProperties().putProperty("examplesImported", true); //$NON-NLS-1$ updateText(new PropertyChangeEvent(this, "mainCounts", -1, 1)); //$NON-NLS-1$ } @Override void updateText(PropertyChangeEvent arg0) { if (!getEngine().getGlobalProperties().getBoolean("examplesImported", false)) { //$NON-NLS-1$ label.setText(getSummaryBean().getOpenCount() + " " //$NON-NLS-1$ + Messages.getString("GTDFree.OW.Open.1") + " " + getSummaryBean().getTotalCount() //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("GTDFree.OW.Open.2") + " " //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + Messages.getString("GTDFree.OW.Import")); //$NON-NLS-1$ button.setVisible(true); } else { label.setText(getSummaryBean().getOpenCount() + " " //$NON-NLS-1$ + Messages.getString("GTDFree.OW.Open.1") + " " + getSummaryBean().getTotalCount() //$NON-NLS-1$//$NON-NLS-2$ + " " + Messages.getString("GTDFree.OW.Open.2")); //$NON-NLS-1$ //$NON-NLS-2$ button.setVisible(false); } } }; overview.add(sl, new GridBagConstraints(0, row++, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 18, 4, 18), 0, 0)); overview.add(new JPanel(), new GridBagConstraints(0, row++, 1, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 11, 0, 11), 0, 0)); } return overview; }
From source file:tufts.vue.ui.InspectorPane.java
/** labels & values must be of same length */ private void addLabelTextRows(int starty, JLabel[] labels, JComponent[] values, Container gridBag, Font labelFace, Font fieldFace) { // Note that the resulting alignment ends up being somehow FONT dependent! // E.g., works great with Lucida Grand (MacOSX), but with system default, // if the field value is a wrapping JTextPane (thus gets taller as window // gets narrower), the first line of text rises slightly and is no longer // in line with it's label. GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.EAST; c.weighty = 0;//from ww w . j ava2 s.c o m c.gridheight = 1; for (int i = 0; i < labels.length; i++) { //out("ALTR[" + i + "] label=" + GUI.name(labels[i]) + " value=" + GUI.name(values[i])); boolean centerLabelVertically = false; final JLabel label = labels[i]; final JComponent field = values[i]; if (labelFace != null) GUI.apply(labelFace, label); if (field instanceof JTextComponent) { if (field instanceof JTextField) centerLabelVertically = true; // JTextComponent textField = (JTextComponent) field; // editable = textField.isEditable(); // if (field instanceof JTextArea) { // JTextArea textArea = (JTextArea) field; // c.gridheight = textArea.getRows(); // } else if (field instanceof JTextField) } else { if (fieldFace != null) GUI.apply(fieldFace, field); } //------------------------------------------------------- // Add the field label //------------------------------------------------------- c.gridx = 0; c.gridy = starty++; c.insets = labelInsets; c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last in row c.fill = GridBagConstraints.NONE; // the label never grows if (centerLabelVertically) c.anchor = GridBagConstraints.EAST; else c.anchor = GridBagConstraints.NORTHEAST; c.weightx = 0.0; // do not expand gridBag.add(label, c); //------------------------------------------------------- // Add the field value //------------------------------------------------------- c.gridx = 1; c.gridwidth = GridBagConstraints.REMAINDER; // last in row c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.CENTER; //c.anchor = GridBagConstraints.NORTH; c.insets = fieldInsets; c.weightx = 1.0; // field value expands horizontally to use all space gridBag.add(field, c); } // add a default vertical expander to take up extra space // (so the above stack isn't vertically centered if it // doesn't fill the space). c.weighty = 1; c.weightx = 1; c.gridx = 0; c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; JComponent defaultExpander = new JPanel(); defaultExpander.setPreferredSize(new Dimension(Short.MAX_VALUE, 1)); if (DEBUG.BOXES) { defaultExpander.setOpaque(true); defaultExpander.setBackground(Color.red); } else defaultExpander.setOpaque(false); gridBag.add(defaultExpander, c); }
From source file:de.bwravencl.controllerbuddy.gui.Main.java
void updateModesPanel() { if (modesListPanel == null) return;/*from ww w.j av a 2s.c om*/ modesListPanel.removeAll(); final var modes = input.getProfile().getModes(); for (var i = 0; i < modes.size(); i++) { final var mode = modes.get(i); final var modePanel = new JPanel(new GridBagLayout()); modesListPanel.add(modePanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 5)); final var modeNoLabel = new JLabel(rb.getString("MODE_NO_LABEL_PREFIX") + (i + 1)); modeNoLabel.setPreferredSize(new Dimension(100, 15)); modePanel.add(modeNoLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); modePanel.add(Box.createGlue(), new GridBagConstraints(1, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); final var descriptionTextField = new JTextField(mode.getDescription(), 20); modePanel.add(descriptionTextField, new GridBagConstraints(2, 0, 1, 1, 1.0, 1.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); final var setModeDescriptionAction = new SetModeDescriptionAction(mode, descriptionTextField); descriptionTextField.addActionListener(setModeDescriptionAction); descriptionTextField.getDocument().addDocumentListener(setModeDescriptionAction); modePanel.add(Box.createGlue(), new GridBagConstraints(3, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); if (Profile.defaultMode.equals(mode) || OnScreenKeyboard.onScreenKeyboardMode.equals(mode)) { descriptionTextField.setEditable(false); modePanel.add(Box.createHorizontalStrut(BUTTON_DIMENSION.width)); } else { final var deleteButton = new JButton(new RemoveModeAction(mode)); deleteButton.setPreferredSize(BUTTON_DIMENSION); modePanel.add(deleteButton, new GridBagConstraints(4, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } } modesListPanel.add(Box.createGlue(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); modesScrollPane.setViewportView(modesListPanel); }
From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java
private JPanel createBrowserIntegrationPanel(int stentWidth) { MultiBitTitledPanel browserIntegrationPanel = new MultiBitTitledPanel( controller.getLocaliser().getString("showPreferencesPanel.browserIntegrationTitle"), ComponentOrientation.getOrientation(controller.getLocaliser().getLocale())); GridBagConstraints constraints = new GridBagConstraints(); MultiBitTitledPanel.addLeftJustifiedTextAtIndent( controller.getLocaliser().getString("showPreferencesPanel.browserIntegration.messageText"), 3, browserIntegrationPanel);/*from w w w.ja v a 2 s.c o m*/ ButtonGroup browserIntegrationGroup = new ButtonGroup(); ignoreAll = new JRadioButton(controller.getLocaliser().getString("showPreferencesPanel.ignoreAll")); ignoreAll.setOpaque(false); ignoreAll.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont()); fillAutomatically = new JRadioButton( controller.getLocaliser().getString("showPreferencesPanel.fillAutomatically")); fillAutomatically.setOpaque(false); fillAutomatically.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont()); askEveryTime = new JRadioButton(controller.getLocaliser().getString("showPreferencesPanel.askEveryTime")); askEveryTime.setOpaque(false); askEveryTime.setFont(FontSizer.INSTANCE.getAdjustedDefaultFont()); browserIntegrationGroup.add(ignoreAll); browserIntegrationGroup.add(fillAutomatically); browserIntegrationGroup.add(askEveryTime); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; constraints.gridy = 5; constraints.weightx = 0.2; constraints.weighty = 0.3; constraints.gridwidth = 3; constraints.anchor = GridBagConstraints.LINE_START; browserIntegrationPanel.add(ignoreAll, constraints); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; constraints.gridy = 6; constraints.weightx = 0.2; constraints.weighty = 0.3; constraints.anchor = GridBagConstraints.LINE_START; browserIntegrationPanel.add(fillAutomatically, constraints); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; constraints.gridy = 7; constraints.weightx = 0.2; constraints.weighty = 0.3; constraints.anchor = GridBagConstraints.LINE_START; browserIntegrationPanel.add(askEveryTime, constraints); return browserIntegrationPanel; }
From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java
private JPanel createButtonPanel() { JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); buttonPanel.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, SystemColor.windowBorder)); buttonPanel.setOpaque(true);/* w w w. ja va 2 s . co m*/ buttonPanel.setBackground(ColorAndFontConstants.MID_BACKGROUND_COLOR); buttonPanel.setComponentOrientation( ComponentOrientation.getOrientation(controller.getLocaliser().getLocale())); Action helpAction; if (ComponentOrientation.LEFT_TO_RIGHT == ComponentOrientation .getOrientation(controller.getLocaliser().getLocale())) { helpAction = new HelpContextAction(controller, ImageLoader.HELP_CONTENTS_BIG_ICON_FILE, "multiBitFrame.helpMenuText", "multiBitFrame.helpMenuTooltip", "multiBitFrame.helpMenuText", HelpContentsPanel.HELP_PREFERENCES_URL); } else { helpAction = new HelpContextAction(controller, ImageLoader.HELP_CONTENTS_BIG_RTL_ICON_FILE, "multiBitFrame.helpMenuText", "multiBitFrame.helpMenuTooltip", "multiBitFrame.helpMenuText", HelpContentsPanel.HELP_PREFERENCES_URL); } HelpButton helpButton = new HelpButton(helpAction, controller); helpButton.setText(""); helpButton.setToolTipText(controller.getLocaliser().getString("multiBitFrame.helpMenuTooltip")); helpButton.setHorizontalAlignment(SwingConstants.LEADING); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 0; constraints.weightx = 0.3; constraints.weighty = 0.1; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.LINE_START; buttonPanel.add(helpButton, constraints); ShowPreferencesSubmitAction submitAction = new ShowPreferencesSubmitAction(this.bitcoinController, this.exchangeController, this, ImageLoader.createImageIcon(ImageLoader.PREFERENCES_ICON_FILE), mainFrame); MultiBitButton submitButton = new MultiBitButton(submitAction, controller); buttonPanel.add(submitButton); UndoPreferencesChangesSubmitAction undoChangesAction = new UndoPreferencesChangesSubmitAction(controller, ImageLoader.createImageIcon(ImageLoader.UNDO_ICON_FILE)); undoChangesButton = new MultiBitButton(undoChangesAction, controller); buttonPanel.add(undoChangesButton); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; constraints.gridy = 0; constraints.weightx = 0.1; constraints.weighty = 1.0; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.LINE_START; buttonPanel.add(submitButton, constraints); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 2; constraints.gridy = 0; constraints.weightx = 0.1; constraints.weighty = 1.0; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.LINE_START; buttonPanel.add(undoChangesButton, constraints); JPanel fill1 = new JPanel(); fill1.setOpaque(false); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 2; constraints.gridy = 0; constraints.weightx = 200; constraints.weighty = 1; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.LINE_END; buttonPanel.add(fill1, constraints); return buttonPanel; }
From source file:de.bwravencl.controllerbuddy.gui.Main.java
private void updateOverlayPanel() { if (indicatorsListPanel == null) return;//from w w w. j a v a 2 s. c om indicatorsListPanel.removeAll(); for (final var virtualAxis : Input.VirtualAxis.values()) { final var indicatorPanel = new JPanel(new GridBagLayout()); indicatorsListPanel.add(indicatorPanel, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 5)); final var virtualAxisLabel = new JLabel(virtualAxis.toString() + rb.getString("AXIS_LABEL_SUFFIX")); virtualAxisLabel.setPreferredSize(new Dimension(100, 15)); indicatorPanel.add(virtualAxisLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); final var virtualAxisToOverlayAxisMap = input.getProfile().getVirtualAxisToOverlayAxisMap(); final var overlayAxis = virtualAxisToOverlayAxisMap.get(virtualAxis); final var enabled = overlayAxis != null; final var colorLabel = new JLabel(); if (enabled) { colorLabel.setOpaque(true); colorLabel.setBackground(overlayAxis.color); } else colorLabel.setText(rb.getString("INDICATOR_DISABLED_LABEL")); colorLabel.setHorizontalAlignment(SwingConstants.CENTER); colorLabel.setPreferredSize(new Dimension(100, 15)); colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK)); indicatorPanel.add(colorLabel, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); final var colorButton = new JButton(new SelectIndicatorColorAction(virtualAxis)); colorButton.setPreferredSize(BUTTON_DIMENSION); colorButton.setEnabled(enabled); indicatorPanel.add(colorButton, new GridBagConstraints(2, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); final var invertedCheckBox = new JCheckBox(new InvertIndicatorAction(virtualAxis)); invertedCheckBox.setSelected(enabled && overlayAxis.inverted); invertedCheckBox.setEnabled(enabled); indicatorPanel.add(invertedCheckBox, new GridBagConstraints(3, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); final var displayCheckBox = new JCheckBox(new DisplayIndicatorAction(virtualAxis)); displayCheckBox.setSelected(enabled); indicatorPanel.add(displayCheckBox, new GridBagConstraints(4, GridBagConstraints.RELATIVE, 1, 1, 0.0, 0.0, GridBagConstraints.BASELINE, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); } indicatorsListPanel.add(Box.createGlue(), new GridBagConstraints(0, GridBagConstraints.RELATIVE, 1, 1, 1.0, 1.0, GridBagConstraints.FIRST_LINE_START, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); indicatorsScrollPane.setViewportView(indicatorsListPanel); }
From source file:display.ANNFileFilter.java
License:asdf
Yanng() { JPanel toolBars;/*from w ww.j a va 2 s. co m*/ JMenuBar menuBar; JToolBar utilBar, fileBar; JButton toJava, runner, trainer, modify, getTraininger, inputer, newwer, saver, saveAser, loader, helper; JMenu file; final JMenu util; JMenu help; ImageIcon IJava, IRun, ITrain, IModify, INew, ISave, ILoad, IGetTrainingSet, IGetInput, ISaveAs; //initialize main window mainWindow = new JFrame("YANNG - Yet Another Neural Network (simulator) Generator"); mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); mainWindow.setLayout(new BorderLayout()); mainWindow.setSize(675, 525); mainWindow.setIconImage(new ImageIcon(ClassLoader.getSystemResource("display/icons/logo.png")).getImage()); loadingImage = new ImageIcon(ClassLoader.getSystemResource("display/icons/loading.gif")); path = new Vector<String>(); net = new Vector<NeuralNetwork>(); oneNet = new Vector<JPanel>(); tabPanel = new Vector<JPanel>(); readOut = new Vector<JTextArea>(); readOutLocale = new Vector<JScrollPane>(); loadingBar = new Vector<JLabel>(); title = new Vector<JLabel>(); close = new Vector<JButton>(); netName = new Vector<StringBuffer>(); netKind = new Vector<StringBuffer>(); resultsPane = new JTabbedPane(); mainWindow.add(resultsPane); toolBars = new JPanel(); toolBars.setLayout(new FlowLayout(FlowLayout.LEFT)); //create utilities toolbar with 3 buttons utilBar = new JToolBar("Utilities"); IRun = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/running.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); ITrain = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/training.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); IModify = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/modifyNet.png")) .getImage().getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); IGetTrainingSet = new ImageIcon( new ImageIcon(ClassLoader.getSystemResource("display/icons/trainingSet.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); IGetInput = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/input.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); //set the icons/tooltips for the utilitiy bar runner = new JButton(IRun); runner.setToolTipText( "<html>Run the Current Neural Network<br>Once Through with the Current Input</html>"); trainer = new JButton(ITrain); trainer.setToolTipText( "<html>Train the Network with the Current<br>Configuration and Training Set</html>"); modify = new JButton(IModify); modify.setToolTipText("<html>Modify the Network<br>for Fun and Profit</html>"); getTraininger = new JButton(IGetTrainingSet); getTraininger.setToolTipText("Get Training Set from File"); inputer = new JButton(IGetInput); inputer.setToolTipText("Get Input Set from File"); utilBar.add(inputer); utilBar.add(runner); utilBar.add(getTraininger); utilBar.add(trainer); utilBar.add(modify); //create file toolbar fileBar = new JToolBar("file"); ISaveAs = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/saveAs.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); INew = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/new.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); ISave = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/save.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); ILoad = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/load.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); IJava = new ImageIcon(new ImageIcon(ClassLoader.getSystemResource("display/icons/toJava.png")).getImage() .getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH)); newwer = new JButton(INew); newwer.setToolTipText("Create New Neural Network"); saver = new JButton(ISave); saver.setToolTipText("Save Current Network Configuration"); saveAser = new JButton(ISaveAs); saveAser.setToolTipText("Save Network As"); loader = new JButton(ILoad); loader.setToolTipText("Load Network Configuration from File"); toJava = new JButton(IJava); toJava.setToolTipText("Export Network to Java Project"); fileBar.add(newwer); fileBar.add(loader); fileBar.add(saver); fileBar.add(saveAser); fileBar.add(toJava); toolBars.add(fileBar); toolBars.add(utilBar); mainWindow.add(toolBars, BorderLayout.NORTH); //create a menubar with three menus on it menuBar = new JMenuBar(); file = new JMenu("File"); util = new JMenu("Utilities"); help = new JMenu("Help"); //add menu items for file menu load = new JMenuItem("Load Network Configuration"); newNet = new JMenuItem("New Network"); saveAs = new JMenuItem("Save Network As"); save = new JMenuItem("Save Current Configuration"); exportNet = new JMenuItem("Export Network to Java Project"); exportOutput = new JMenuItem("Export Output to Text File"); file.add(load); file.add(newNet); file.addSeparator(); file.add(saveAs); file.add(save); file.addSeparator(); file.add(exportNet); file.add(exportOutput); menuBar.add(file); //add menu items for utilities menu changeConfig = new JMenuItem("Modify Network Settings"); getInput = new JMenuItem("Get Input From File"); getTraining = new JMenuItem("Get Training Set From File"); run = new JMenuItem("Run"); train = new JMenuItem("Train"); getColorMap = new JMenuItem("View Color Map"); getColorMap.setVisible(false); util.add(changeConfig); util.addSeparator(); util.add(getInput); util.add(getTraining); util.addSeparator(); util.add(run); util.add(train); menuBar.add(util); //add menu items for help menu quickStart = new JMenuItem("Quick Start Guide"); searchHelp = new JMenuItem("Programming with Yanng"); about = new JMenuItem("License"); links = new JMenuItem("<html>Links to Resources<br>about Neural Networks</html>"); help.add(quickStart); help.addSeparator(); help.add(searchHelp); help.addSeparator(); help.add(about); help.addSeparator(); help.add(links); menuBar.add(help); mainWindow.setJMenuBar(menuBar); //opens the quickstart guide quickStart.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { File myFile = new File(URLDecoder .decode(ClassLoader.getSystemResource("ann/quick-start.pdf").getFile(), "UTF-8")); Desktop.getDesktop().open(myFile); } catch (IOException ex) { try { Runtime.getRuntime().exec("xdg-open ./yanng/src/ann/quick-start.pdf"); } catch (Exception e) { JOptionPane.showMessageDialog(mainWindow, "Your desktop is not supported by java,\ngo to yanng/src/ann/quick-start.pdf to view the technical manual.", "Desktop not Supported", JOptionPane.ERROR_MESSAGE); } } } }); links.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { File myFile = new File( URLDecoder.decode(ClassLoader.getSystemResource("ann/links.pdf").getFile(), "UTF-8")); Desktop.getDesktop().open(myFile); } catch (IOException ex) { try { Runtime.getRuntime().exec("xdg-open ./yanng/src/ann/links.pdf"); } catch (Exception e) { JOptionPane.showMessageDialog(mainWindow, "Your desktop is not supported by java,\ngo to yanng/src/ann/links.pdf to view the technical manual.", "Desktop not Supported", JOptionPane.ERROR_MESSAGE); } } } }); //Displays license information about.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JTextArea x = new JTextArea("Copyright [2015] [Sam Findler and Michael Scott]\n" + "\n" + "Licensed under the Apache License, Version 2.0 (the \"License\");\n" + "you may not use this file except in compliance with the License.\n" + "You may obtain a copy of the License at\n" + "\n" + "http://www.apache.org/licenses/LICENSE-2.0\n" + "\n" + "Unless required by applicable law or agreed to in writing, software\n" + "distributed under the License is distributed on an \"AS IS\" BASIS,\n" + "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + "See the License for the specific language governing permissions and\n" + "limitations under the License."); JDialog aboutDialog = new JDialog(mainWindow, "License", true); aboutDialog.setSize(500, 250); aboutDialog.setLayout(new FlowLayout()); aboutDialog.add(x); x.setEditable(false); aboutDialog.setVisible(true); } }); //opens the more technical user guide searchHelp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { try { File myFile = new File(URLDecoder .decode(ClassLoader.getSystemResource("ann/technical-manual.pdf").getFile(), "UTF-8")); Desktop.getDesktop().open(myFile); } catch (IOException ex) { try { Runtime.getRuntime().exec("xdg-open ./yanng/src/ann/technical-manual.pdf"); } catch (Exception e) { JOptionPane.showMessageDialog(mainWindow, "Your desktop is not supported by java,\ngo to yanng/src/ann/technical-manual.pdf to view the technical manual.", "Desktop not Supported", JOptionPane.ERROR_MESSAGE); } } } }); //class trains the neural network in the background while the loading bar displays, then prints out the output/connections listings/average error to the readOut pane class Trainer extends SwingWorker<NeuralNetwork, Object> { protected NeuralNetwork doInBackground() { net.get(resultsPane.getSelectedIndex()).trainNet(); setProgress(1); return net.get(resultsPane.getSelectedIndex()); } public void done() { if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) { if (Double.isNaN(net.get(resultsPane.getSelectedIndex()).getAverageError())) JOptionPane.showMessageDialog(mainWindow, "Training Set Formatted Incorrectly", "Formatting Error", JOptionPane.ERROR_MESSAGE); else { printConnections(); readOut.get(resultsPane.getSelectedIndex()).append( "Results of Training " + netName.get(resultsPane.getSelectedIndex()) + ":\n\n"); printOutput(); readOut.get(resultsPane.getSelectedIndex()).append("Average Error = " + net.get(resultsPane.getSelectedIndex()).getAverageError() + "\n\n"); loadingBar.get(resultsPane.getSelectedIndex()).setVisible(false); JOptionPane.showMessageDialog(mainWindow, "<html>If the Input is not displaying as expected, chances are the input was inproperly formatted.<br>See help for more details<html>"); } } else if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) { readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Untrained Map:\n"); printInitMap(); loadingBar.get(resultsPane.getSelectedIndex()).setVisible(false); JOptionPane.showMessageDialog(mainWindow, "<html>If the Input is not displaying as expected, chances are the input was inproperly formatted.<br>See help for more details<html>"); } } } //starts the training class when train is pressed in the utilities menu train.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0) { if (net.get(resultsPane.getSelectedIndex()).getTrainingSet() != null) { loadingBar.get(resultsPane.getSelectedIndex()).setText( "<html><font color = rgb(160,0,0)>Training</font> <font color = rgb(0,0,248)>net...</font></html>"); loadingBar.get(resultsPane.getSelectedIndex()).setVisible(true); (thisTrainer = new Trainer()).execute(); } else JOptionPane.showMessageDialog(mainWindow, "No Input Set Specified", "Empty Signifier Error", JOptionPane.ERROR_MESSAGE); } else JOptionPane.showMessageDialog(mainWindow, "Can't Train Nonexistent Neural Network", "Existential Error", JOptionPane.ERROR_MESSAGE); } }); //associates the toolbar button with the jump rope guy with the training button on the utilities menu trainer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : train.getActionListeners()) { a.actionPerformed(ae); } } }); //runs through one set of inputs and prints the results to the readOut pane run.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) { if (net.get(resultsPane.getSelectedIndex()).getInputSet() != null) { net.get(resultsPane.getSelectedIndex()).runNet(); if (Double.isNaN(net.get(resultsPane.getSelectedIndex()).getAverageError())) JOptionPane.showMessageDialog(mainWindow, "Training Set Formatted Incorrectly", "Formatting Error", JOptionPane.ERROR_MESSAGE); else { readOut.get(resultsPane.getSelectedIndex()).append("Results of Running through Network " + netName.get(resultsPane.getSelectedIndex()) + ":\n\n"); printOutput(); System.out.println("Results:"); for (int i = 0; i < net.get(resultsPane.getSelectedIndex()) .getOutputSet().length; i++) { System.out.println("\n Output of Input Vector " + i + ":"); for (int j = 0; j < net.get(resultsPane.getSelectedIndex()) .getOutputSet()[i].length; j++) { System.out.println(" Output Node " + j + " = " + net.get(resultsPane.getSelectedIndex()).getOutputSet()[i][j]); } } JOptionPane.showMessageDialog(mainWindow, "<html>If the Input is not displaying as expected, chances are the input was inproperly formatted.<br>See help for more details<html>"); } } else JOptionPane.showMessageDialog(mainWindow, "No Input Set Specified", "Empty Signifier Error", JOptionPane.ERROR_MESSAGE); } else if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) { if (net.get(resultsPane.getSelectedIndex()).getInputValues() != null) { loadingBar.get(resultsPane.getSelectedIndex()).setText( "<html><font color = rgb(160,0,0)>Training</font> <font color = rgb(0,0,248)>net...</font></html>"); loadingBar.get(resultsPane.getSelectedIndex()).setVisible(true); (thisTrainer = new Trainer()).execute(); } else JOptionPane.showMessageDialog(mainWindow, "No Input Set Specified", "Empty Signifier Error", JOptionPane.ERROR_MESSAGE); } else JOptionPane.showMessageDialog(mainWindow, "Can't Run Nonexistent Neural Network", "Existential Error", JOptionPane.ERROR_MESSAGE); } }); runner.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : run.getActionListeners()) { a.actionPerformed(ae); } } }); //the following code is for the getTraining button under utilities getTrainingSet = new JFileChooser(); getTrainingSet.setFileFilter(new TrainingFileFilter()); getTraining.addActionListener(new ActionListener() { //this method/class gets a training set (tsv/csv file) and parse it through the neural network. Kind of test that the file is formatted correctly, but if the data is wrong, there isn't much it can do. public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) { int result; result = getTrainingSet.showOpenDialog(mainWindow); if (result == JFileChooser.APPROVE_OPTION) if (getTrainingSet.getSelectedFile().getName().endsWith(".csv") || getTrainingSet.getSelectedFile().getName().endsWith(".tsv") || getTrainingSet.getSelectedFile().getName().endsWith(".txt")) if (net.get(resultsPane.getSelectedIndex()) .parseTrainingSet(getTrainingSet.getSelectedFile())) JOptionPane.showMessageDialog(mainWindow, "<html>Method gives no Garuntee that this File is Formatted Correctly<br>(see help for more details)</html>", "Formatting Warning", JOptionPane.WARNING_MESSAGE); else JOptionPane.showMessageDialog(mainWindow, "File Mismatch with Network Configuration", "Correspondence Error", JOptionPane.ERROR_MESSAGE); else { JOptionPane.showMessageDialog(mainWindow, "Wrong File Type", "Category Error", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(mainWindow, "No File Selected", "Absence Warning", JOptionPane.WARNING_MESSAGE); } } else if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) { int result; result = getTrainingSet.showOpenDialog(mainWindow); if (result == JFileChooser.APPROVE_OPTION) if (getTrainingSet.getSelectedFile().getName().endsWith(".csv") || getTrainingSet.getSelectedFile().getName().endsWith(".tsv") || getTrainingSet.getSelectedFile().getName().endsWith(".txt")) if (net.get(resultsPane.getSelectedIndex()) .parseTrainingSet(getTrainingSet.getSelectedFile())) { JOptionPane.showMessageDialog(mainWindow, "<html>Method gives no Garuntee that this File is Formatted Correctly<br>(see help for more details)</html>", "Formatting Warning", JOptionPane.WARNING_MESSAGE); readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Untrained Map:\n"); printInitMap(); } else JOptionPane.showMessageDialog(mainWindow, "File Mismatch with Network Configuration", "Correspondence Error", JOptionPane.ERROR_MESSAGE); else { JOptionPane.showMessageDialog(mainWindow, "Wrong File Type", "Category Error", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(mainWindow, "No File Selected", "Absence Warning", JOptionPane.WARNING_MESSAGE); } } else { JOptionPane.showMessageDialog(mainWindow, "Can't Train Nonexistent Neural Network", "Existential Error", JOptionPane.ERROR_MESSAGE); } } }); getTraininger.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : getTraining.getActionListeners()) { a.actionPerformed(ae); } } }); //this ends the getTraining section of the code getInput.addActionListener(new ActionListener() { //this method/class gets an input set (tsv/csv file) and parses it through the neural network. Somewhat tests that the file is formatted correctly, but cannot give a garuntee. public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0) { int result; result = getTrainingSet.showOpenDialog(mainWindow); if (result == JFileChooser.APPROVE_OPTION) if (getTrainingSet.getSelectedFile().getName().endsWith(".csv") || getTrainingSet.getSelectedFile().getName().endsWith(".tsv") || getTrainingSet.getSelectedFile().getName().endsWith(".txt")) if (net.get(resultsPane.getSelectedIndex()) .parseInputSet(getTrainingSet.getSelectedFile())) { JOptionPane.showMessageDialog(mainWindow, "<html>Method gives no Garuntee that this File is Formatted Correctly<br>(see help for more details)</html>", "Formatting Warning", JOptionPane.WARNING_MESSAGE); if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Self-Organizing Map")) printInitMap(); } else JOptionPane.showMessageDialog(mainWindow, "File Mismatch with Network Configuration", "Correspondence Error", JOptionPane.ERROR_MESSAGE); else JOptionPane.showMessageDialog(mainWindow, "Wrong File Type", "Category Error", JOptionPane.ERROR_MESSAGE); else JOptionPane.showMessageDialog(mainWindow, "No File Selected", "Absence Warning", JOptionPane.WARNING_MESSAGE); } else { JOptionPane.showMessageDialog(mainWindow, "Can't train nonexistent network", "Existential Error", JOptionPane.ERROR_MESSAGE); } } }); //opens and displays a color map of a SOM getColorMap.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0) { if (netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) { MapNode[][] map; map = net.get(resultsPane.getSelectedIndex()).getMapArray(); int lValue = net.get(resultsPane.getSelectedIndex()).getLatticeValue(); int inputDimensions = net.get(resultsPane.getSelectedIndex()).getInputDimensions(); int[][] colorValues = new int[(lValue * lValue)][3]; double dMax = net.get(resultsPane.getSelectedIndex()).getDataMax(); double dMin = net.get(resultsPane.getSelectedIndex()).getDataMin(); int count = 0; for (int i = 0; i < lValue; i++) { for (int j = 0; j < lValue; j++) { for (int k = 0; k < 3; k++) { Vector tempVec = map[i][j].getWeights(); if (inputDimensions % 3 == 0) { colorValues[count][k] = Integer.parseInt(String.valueOf((Math.round(255 * (Double.parseDouble(String.valueOf(tempVec.elementAt(k)))))))); } if (inputDimensions % 3 == 1) { if (k == 0) colorValues[count][k] = 0; if (k == 1) { colorValues[count][k] = Integer .parseInt(String.valueOf((Math.round(255 * (Double .parseDouble(String.valueOf(tempVec.elementAt(0)))))))); } if (k == 2) colorValues[count][k] = 0; } if (inputDimensions % 3 == 2) { if (k == 2) { colorValues[count][k] = 0; } else colorValues[count][k] = Integer .parseInt(String.valueOf((Math.round(255 * (Double .parseDouble(String.valueOf(tempVec.elementAt(k)))))))); } } count++; } } JFrame frame = new JFrame(); frame.setTitle("Color Map"); frame.setPreferredSize(new Dimension(525, 500)); frame.add(new DrawPanel(colorValues, lValue)); frame.pack(); frame.setVisible(true); } else { JOptionPane.showMessageDialog(mainWindow, "This Feauture is only available for Self-Organizing Maps", "Not a Som Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(mainWindow, "Network does not exist", "Existential Error", JOptionPane.ERROR_MESSAGE); } } }); inputer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : getInput.getActionListeners()) a.actionPerformed(ae); } }); getNet = new JFileChooser(); getNet.setFileFilter(new ANNFileFilter()); //saves the net, or opens save as dialog if net is not saved yet save.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0) { if (!path.get(resultsPane.getSelectedIndex()).equals("")) { net.get(resultsPane.getSelectedIndex()) .save(new File(path.get(resultsPane.getSelectedIndex()))); } else { for (ActionListener a : saveAs.getActionListeners()) { a.actionPerformed(ae); } } } else { JOptionPane.showMessageDialog(mainWindow, "Can't save NonExistent Neural Network", "Existential Error", JOptionPane.ERROR_MESSAGE); } } }); saver.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : save.getActionListeners()) { a.actionPerformed(ae); } } }); //opens dialog for saving the net saveAs.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0) { int result, override; String tempName; result = getNet.showSaveDialog(mainWindow); if (result == JFileChooser.APPROVE_OPTION) if ((new File(tempName = getNet.getSelectedFile().getName())).exists() || (new File(tempName + ".ffn")).exists() || (new File(tempName + ".som")).exists() || (new File(tempName + ".hfn")).exists()) { override = JOptionPane.showConfirmDialog(mainWindow, tempName + " already exists, do you want to override?", "File Exists", JOptionPane.YES_NO_OPTION); if (override == JOptionPane.YES_OPTION) { if (net.get(resultsPane.getSelectedIndex()).save(getNet.getSelectedFile())) { if (tempName.endsWith(".ffn") || tempName.endsWith(".som")) { netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName)); title.get(resultsPane.getSelectedIndex()).setText(tempName + " "); } else if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Feed Forward Network")) { netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName + ".ffn")); title.get(resultsPane.getSelectedIndex()).setText(tempName + ".ffn "); } else if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Self-Organizing Map")) { netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName + ".som")); title.get(resultsPane.getSelectedIndex()).setText(tempName + ".som "); } path.set(resultsPane.getSelectedIndex(), getNet.getSelectedFile().getPath()); } else JOptionPane.showMessageDialog(mainWindow, "Could not save file", "File Error", JOptionPane.ERROR_MESSAGE); } } else { if (net.get(resultsPane.getSelectedIndex()).save(getNet.getSelectedFile())) { if (tempName.endsWith(".ffn") || tempName.endsWith(".som") || tempName.endsWith(".hfn")) { netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName)); title.get(resultsPane.getSelectedIndex()).setText(tempName + " "); } else if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Feed Forward Network")) { netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName + ".ffn")); title.get(resultsPane.getSelectedIndex()).setText(tempName + ".ffn "); } else if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Self-Organizing Map")) { netName.set(resultsPane.getSelectedIndex(), new StringBuffer(tempName + ".som")); title.get(resultsPane.getSelectedIndex()).setText(tempName + ".som "); path.set(resultsPane.getSelectedIndex(), getNet.getSelectedFile().getPath()); } } else JOptionPane.showMessageDialog(mainWindow, "Could not save file", "File Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(mainWindow, "Nothing to Save", "Existetial Error", JOptionPane.ERROR_MESSAGE); } } }); saveAser.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : saveAs.getActionListeners()) { a.actionPerformed(ae); } } }); //loads a net load.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int result; boolean test = true; String tempName; result = getNet.showOpenDialog(mainWindow); if (result == JFileChooser.APPROVE_OPTION) { tempName = getNet.getSelectedFile().getName(); for (StringBuffer names : netName) { if (names.toString().equals(tempName)) test = false; } if (test != false) { //creates and sets the network configuration if (tempName.endsWith(".ffn")) { net.add(new FullyConnectedFeedForwardNet()); } if (tempName.endsWith(".som")) { net.add(new SelfOrganizingMap()); } if (net.get(openNets).load(getNet.getSelectedFile())) try { //adds a close button to the top corner of each tab title.add(new JLabel(tempName + " ")); close.add(new JButton("X")); close.get(openNets).setActionCommand(tempName); close.get(openNets) .setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); close.get(openNets).setMargin(new Insets(0, 0, 0, 0)); tabPanel.add(new JPanel(new GridBagLayout())); tabPanel.get(openNets).setOpaque(false); GridBagConstraints grid = new GridBagConstraints(); grid.fill = GridBagConstraints.HORIZONTAL; grid.gridx = 0; grid.gridy = 0; grid.weightx = 1; tabPanel.get(openNets).add(title.get(openNets), grid); grid.gridx = 1; grid.gridy = 0; grid.weightx = 0; tabPanel.get(openNets).add(close.get(openNets), grid); //adds a loading bar loadingBar.add(new JLabel("", loadingImage, SwingConstants.CENTER)); loadingBar.get(openNets).setHorizontalTextPosition(SwingConstants.LEFT); loadingBar.get(openNets).setVisible(false); path.add(getNet.getSelectedFile().getPath()); netKind.add(new StringBuffer(netType.getSelectedItem().toString())); netName.add(new StringBuffer(tempName)); oneNet.add(new JPanel()); oneNet.get(openNets).setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; //creates the readOut space and formats it so that the scroll pane/text changes size with the window, reserves space for the loading bar readOut.add(new JTextArea("")); readOutLocale.add(new JScrollPane(readOut.get(openNets))); readOut.get(openNets).setEditable(false); constraints.gridx = 0; constraints.gridy = 0; constraints.weighty = 1.0; constraints.weightx = 1.0; constraints.gridwidth = 2; constraints.ipady = 90; oneNet.get(openNets).add(readOutLocale.get(openNets), constraints); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 1; constraints.ipady = 0; constraints.gridwidth = 2; constraints.anchor = GridBagConstraints.PAGE_END; //add everythign to the tabbed pane oneNet.get(openNets).add(loadingBar.get(openNets), constraints); resultsPane.addTab(netName.get(openNets).toString(), oneNet.get(openNets)); resultsPane.setTabComponentAt(openNets, tabPanel.get(openNets)); //display the starting configuration of the network readOut.get(openNets).append("Network: " + netName.get(openNets) + "\n\n"); resultsPane.setSelectedIndex(openNets++); if (tempName.endsWith(".ffn")) printConnections(); if (tempName.endsWith(".som")) { readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Map:\n"); printInitMap(); } //unfortunately difficult way that I made to add the close button functionality to close a tab //it works, but there has to be a better way to do this close.get(resultsPane.getSelectedIndex()).addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent ae) { int result; result = 0; for (StringBuffer names : netName) { if (ae.getActionCommand().equals(names.toString())) { result = JOptionPane.showConfirmDialog(createFFN, "<html>Exiting Without Saving can Cause you to Lose your Progress<br>Are you sure you want to Continue?</html>", "Close Network", JOptionPane.OK_CANCEL_OPTION); resultsPane.setSelectedIndex(netName.indexOf(names)); } } if (result == JOptionPane.OK_OPTION) { net.remove(resultsPane.getSelectedIndex()); oneNet.remove(resultsPane.getSelectedIndex()); readOutLocale.remove(resultsPane.getSelectedIndex()); readOut.remove(resultsPane.getSelectedIndex()); loadingBar.remove(resultsPane.getSelectedIndex()); tabPanel.remove(resultsPane.getSelectedIndex()); title.remove(resultsPane.getSelectedIndex()); close.remove(resultsPane.getSelectedIndex()); netName.remove(resultsPane.getSelectedIndex()); resultsPane.remove(resultsPane.getSelectedIndex()); openNets--; } } }); } catch (Error e) { JOptionPane.showMessageDialog(mainWindow, "File Formatted Incorrectly", "Formatting Error", JOptionPane.ERROR_MESSAGE); } else { //if file was unable to load, remove the newly created neural network and display an error message net.remove(openNets); JOptionPane.showMessageDialog(mainWindow, "File Formatted Incorrectly", "Formatting Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(mainWindow, "File Already Open", "Duality Error", JOptionPane.ERROR_MESSAGE); } } } }); //associates the load toolbar button with load from the file menu loader.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : load.getActionListeners()) a.actionPerformed(ae); } }); textFileChooser = new JFileChooser(); textFileChooser.setFileFilter(new TextFileFilter()); //exports all text from readout to a text file exportOutput.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0) { int result; result = textFileChooser.showSaveDialog(mainWindow); if (result == JFileChooser.APPROVE_OPTION) { if (textFileChooser.getSelectedFile().exists() || (new File(textFileChooser.getSelectedFile().getPath() + ".txt")).exists()) { result = JOptionPane.showConfirmDialog(mainWindow, "The File you have selected already Exists, do you want to Overwrite it?", "File Exits", JOptionPane.YES_NO_OPTION); if (result == JOptionPane.YES_OPTION) { try { if (textFileChooser.getSelectedFile().getPath().endsWith(".txt")) FileUtils.writeStringToFile(textFileChooser.getSelectedFile(), readOut.get(resultsPane.getSelectedIndex()).getText()); else FileUtils.writeStringToFile( new File(textFileChooser.getSelectedFile().getPath() + ".txt"), readOut.get(resultsPane.getSelectedIndex()).getText()); JOptionPane.showMessageDialog(mainWindow, "Succesfully wrote readout to file"); } catch (Exception e) { JOptionPane.showMessageDialog(mainWindow, "Could not write to file", "Error", JOptionPane.ERROR_MESSAGE); } } } else { try { if (textFileChooser.getSelectedFile().getPath().endsWith(".txt")) FileUtils.writeStringToFile(textFileChooser.getSelectedFile(), readOut.get(resultsPane.getSelectedIndex()).getText()); else FileUtils.writeStringToFile( new File(textFileChooser.getSelectedFile().getPath() + ".txt"), readOut.get(resultsPane.getSelectedIndex()).getText()); JOptionPane.showMessageDialog(mainWindow, "Succesfully wrote readout to file"); } catch (Exception e) { JOptionPane.showMessageDialog(mainWindow, "Could not write to file", "Error", JOptionPane.ERROR_MESSAGE); } } } } else { JOptionPane.showMessageDialog(mainWindow, "Nothing to Export", "Existential Error", JOptionPane.ERROR_MESSAGE); } } }); projectFileChooser = new JFileChooser(); projectFileChooser.setFileFilter(new ProjectFileFilter()); //exports a neural network to a java/android project exportNet.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int result, override, override2; String tempName; String templateFile; String directory; String path; if (resultsPane.getTabCount() != 0) { result = projectFileChooser.showSaveDialog(mainWindow); if (result == JFileChooser.APPROVE_OPTION) { path = projectFileChooser.getSelectedFile().getPath(); directory = projectFileChooser.getSelectedFile().getPath().substring(0, projectFileChooser.getSelectedFile().getPath().lastIndexOf(File.separator)); tempName = projectFileChooser.getSelectedFile().getName(); if (projectFileChooser.getSelectedFile().exists() || (new File(directory, tempName + ".java")).exists()) { override = JOptionPane.showConfirmDialog(mainWindow, "Java Class File" + tempName + " already exists, do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (override == JOptionPane.YES_OPTION) { try { if (!(new File(directory, "ann")).exists()) FileUtils.copyDirectoryToDirectory( FileUtils.toFile(ClassLoader.getSystemResource("ann/")), new File(directory)); if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Feed Forward Network")) { templateFile = FileUtils.readFileToString(FileUtils .toFile(ClassLoader.getSystemResource("ann/FFNTemplate.txt"))); templateFile = templateFile.replaceAll("yourpackagename", (new File(directory)).getName()); templateFile = templateFile.replaceAll("YourProjectName", projectFileChooser.getSelectedFile().getName()); if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".ffn")) templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName .get(resultsPane.getSelectedIndex()).toString()); else templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName.get(resultsPane.getSelectedIndex()).toString() + ".ffn"); if (path.indexOf('.') > 0) { FileUtils.writeStringToFile( new File(path.substring(0, path.lastIndexOf('.')) + ".java"), templateFile); } else FileUtils.writeStringToFile(new File(path + ".java"), templateFile); if ((new File(directory, (tempName = netName.get(resultsPane.getSelectedIndex()) .toString()))).exists() || (new File(directory, tempName + ".ffn")).exists()) { override2 = JOptionPane.showConfirmDialog(mainWindow, "Neural Network " + tempName + " already exists, do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (override2 == JOptionPane.YES_OPTION) if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } else { if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } } else if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Self-Organizing Map")) { templateFile = FileUtils.readFileToString(FileUtils .toFile(ClassLoader.getSystemResource("ann/SOMTemplate.txt"))); templateFile = templateFile.replaceAll("yourpackagename", (new File(directory)).getName()); templateFile = templateFile.replaceAll("YourProjectName", projectFileChooser.getSelectedFile().getName()); if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".som")) templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName .get(resultsPane.getSelectedIndex()).toString()); else templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName.get(resultsPane.getSelectedIndex()).toString() + ".som"); if (path.indexOf('.') > 0) { FileUtils.writeStringToFile( new File(path.substring(0, path.lastIndexOf('.')) + ".java"), templateFile); } else FileUtils.writeStringToFile(new File(path + ".java"), templateFile); if ((new File(directory, (tempName = netName.get(resultsPane.getSelectedIndex()) .toString()))).exists() || (new File(directory, tempName + ".som")).exists()) { override2 = JOptionPane.showConfirmDialog(mainWindow, "Neural Network " + tempName + " already exists, do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (override2 == JOptionPane.YES_OPTION) if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } else { if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } } } catch (IOException io) { System.out.println(io); } } } else { try { if (!(new File(directory, "ann")).exists()) FileUtils.copyDirectoryToDirectory( FileUtils.toFile(ClassLoader.getSystemResource("ann/")), new File(directory)); if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Feed Forward Network")) { templateFile = FileUtils.readFileToString( FileUtils.toFile(ClassLoader.getSystemResource("ann/FFNTemplate.txt"))); templateFile = templateFile.replaceAll("yourpackagename", (new File(directory)).getName()); templateFile = templateFile.replaceAll("YourProjectName", projectFileChooser.getSelectedFile().getName()); if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".ffn")) templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName.get(resultsPane.getSelectedIndex()).toString()); else templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName.get(resultsPane.getSelectedIndex()).toString() + ".ffn"); if (path.indexOf('.') > 0) { FileUtils.writeStringToFile( new File(path.substring(0, path.lastIndexOf('.')) + ".java"), templateFile); } else FileUtils.writeStringToFile(new File(path + ".java"), templateFile); if ((new File(directory + File.separator + (tempName = netName.get(resultsPane.getSelectedIndex()).toString()))) .exists() || (new File(directory + File.separator + tempName + ".ffn")) .exists()) { override2 = JOptionPane.showConfirmDialog(mainWindow, "Neural Network " + tempName + " already exists, do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (override2 == JOptionPane.YES_OPTION) if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } else { if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } } else if (netKind.get(resultsPane.getSelectedIndex()).toString() .equals("Self-Organizing Map")) { templateFile = FileUtils.readFileToString( FileUtils.toFile(ClassLoader.getSystemResource("ann/SOMTemplate.txt"))); templateFile = templateFile.replaceAll("yourpackagename", (new File(directory)).getName()); templateFile = templateFile.replaceAll("YourProjectName", projectFileChooser.getSelectedFile().getName()); if (netName.get(resultsPane.getSelectedIndex()).toString().endsWith(".som")) templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName.get(resultsPane.getSelectedIndex()).toString()); else templateFile = templateFile.replaceAll("networkName", (new File(directory)).getName() + File.separator + netName.get(resultsPane.getSelectedIndex()).toString() + ".som"); if (path.indexOf('.') > 0) { FileUtils.writeStringToFile( new File(path.substring(0, path.lastIndexOf('.')) + ".java"), templateFile); } else FileUtils.writeStringToFile(new File(path + ".java"), templateFile); if ((new File(directory, (tempName = netName.get(resultsPane.getSelectedIndex()).toString()))) .exists() || (new File(directory, tempName + ".som")).exists()) { override2 = JOptionPane.showConfirmDialog(mainWindow, "Neural Network " + tempName + " already exists, do you want to overwrite it?", "File Exists", JOptionPane.YES_NO_OPTION); if (override2 == JOptionPane.YES_OPTION) if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } else { if (net.get(resultsPane.getSelectedIndex()) .save(new File(directory + File.separator + tempName))) { JOptionPane.showMessageDialog(mainWindow, "Network Exported to " + (new File(directory)).getName()); } else { JOptionPane.showMessageDialog(mainWindow, "Couldn't save neural network to file, the rest of the project is exported", "Write Error", JOptionPane.ERROR_MESSAGE); } } } } catch (IOException io) { System.out.println(io); } } } } else { JOptionPane.showMessageDialog(mainWindow, "Can't Export NonExistent Neural Network", "Existential Error", JOptionPane.ERROR_MESSAGE); } } }); toJava.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : exportNet.getActionListeners()) a.actionPerformed(ae); } }); //settings menu changeConfig.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Feed Forward Network")) { modifyFFNDialog = new JDialog(mainWindow, "Network Settings", true); modifyFFNDialog.setSize(500, 500); modifyFFNDialog.setLayout(new GridBagLayout()); GridBagConstraints asdf = new GridBagConstraints(); asdf.gridwidth = 5; asdf.gridheight = 1; asdf.gridx = 0; asdf.gridy = 0; asdf.fill = GridBagConstraints.HORIZONTAL; modifyFFNDialog.add(new JSeparator(), asdf); asdf.gridwidth = 5; asdf.gridheight = 15; asdf.weightx = 1.0; asdf.weighty = 1.0; asdf.gridx = 0; asdf.gridy = 1; asdf.fill = GridBagConstraints.BOTH; settings = new JTextArea(); settings.setEditable(false); settings.setBorder(BorderFactory.createEtchedBorder()); modifyFFNDialog.add(settings, asdf); asdf.fill = GridBagConstraints.HORIZONTAL; asdf.gridwidth = 5; asdf.gridheight = 1; asdf.gridx = 0; asdf.gridy = 16; modifyFFNDialog.add(new JSeparator(), asdf); asdf.gridwidth = 2; asdf.gridx = 7; asdf.gridy = 0; modifyFFNDialog.add(new JSeparator(), asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 1; learningRateL = new JLabel("Set Learning Rate:"); modifyFFNDialog.add(learningRateL, asdf); asdf.gridx = 7; asdf.gridy = 2; asdf.fill = GridBagConstraints.HORIZONTAL; learningRateTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance())); learningRateTF.setText(""); modifyFFNDialog.add(learningRateTF, asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 3; momentumL = new JLabel("Set Momentum:"); modifyFFNDialog.add(momentumL, asdf); asdf.gridx = 7; asdf.gridy = 4; asdf.fill = GridBagConstraints.HORIZONTAL; momentumTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance())); momentumTF.setText(""); modifyFFNDialog.add(momentumTF, asdf); asdf.gridx = 7; asdf.gridy = 5; modifyFFNDialog.add(new JSeparator(), asdf); asdf.fill = GridBagConstraints.NONE; /*asdf.gridwidth = 2; asdf.gridheight = 1; asdf.gridx = 7; asdf.gridy = 6; setNoise = new JLabel("Use Noise: "); modifyFFNDialog.add(setNoise, asdf); asdf.gridx = 7; asdf.gridy = 7; asdf.gridwidth = 1; noiseOn = new JRadioButton("yes"); noiseOff = new JRadioButton("no"); noiseGroup = new ButtonGroup(); noiseGroup.add(noiseOn); noiseGroup.add(noiseOff); modifyFFNDialog.add(noiseOn,asdf); asdf.gridx = 8; asdf.gridy = 7; modifyFFNDialog.add(noiseOff,asdf); asdf.gridx = 7; asdf.gridy = 8; asdf.gridwidth = 2; setNoiseRange = new JButton("Set Noise Range"); modifyFFNDialog.add(setNoiseRange,asdf); asdf.gridx = 7; asdf.gridy = 9; setNoiseTiming = new JButton("Set Noise Timing"); modifyFFNDialog.add(setNoiseTiming,asdf);*/ asdf.gridx = 7; asdf.gridy = 10; asdf.fill = GridBagConstraints.HORIZONTAL; modifyFFNDialog.add(new JSeparator(), asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 11; setTrainingStyle = new JLabel("Set Training Style:"); modifyFFNDialog.add(setTrainingStyle, asdf); asdf.gridx = 7; asdf.gridy = 12; asdf.gridwidth = 1; batchOn = new JRadioButton("batch"); onlineOn = new JRadioButton("online"); batchGroup = new ButtonGroup(); batchGroup.add(batchOn); batchGroup.add(onlineOn); modifyFFNDialog.add(batchOn, asdf); asdf.gridx = 8; modifyFFNDialog.add(onlineOn, asdf); asdf.gridx = 7; asdf.gridy = 13; asdf.gridwidth = 2; asdf.fill = GridBagConstraints.HORIZONTAL; modifyFFNDialog.add(new JSeparator(), asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 14; modifyBiases = new JButton("Modify Biases"); modifyFFNDialog.add(modifyBiases, asdf); asdf.gridx = 7; asdf.gridy = 15; trainingCompletionButton = new JButton("Modify End Condition"); modifyFFNDialog.add(trainingCompletionButton, asdf); asdf.fill = GridBagConstraints.HORIZONTAL; asdf.gridy = 16; modifyFFNDialog.add(new JSeparator(), asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridwidth = 1; asdf.gridx = 3; asdf.gridy = 17; asdf.anchor = GridBagConstraints.PAGE_END; modifyFFN = new JButton("OK"); modifyFFNDialog.add(modifyFFN, asdf); asdf.gridx = 7; cancelModifyFFN = new JButton("Cancel"); modifyFFNDialog.add(cancelModifyFFN, asdf); settings.setText(""); settings.append( "\n\n\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append("\n\nMomentum: " + net.get(resultsPane.getSelectedIndex()).getMomentum()); settings.append("\n\nTraining Style: "); if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) { settings.append("batch"); batchOn.setSelected(true); } else { settings.append("online"); onlineOn.setSelected(true); } settings.append("\n\nTraining End Condition: "); if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) { settings.append("Iterative"); settings.append( "\n\nIterations: " + net.get(resultsPane.getSelectedIndex()).getIterations()); } else { settings.append("Ideal Error"); settings.append( "\n\nIdeal Error: " + net.get(resultsPane.getSelectedIndex()).getIdealError()); } //expiremental feature, needs work on the back end to be properly implemented modifyBiases.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JButton addBiases, removeBiases; biasesDialog = new JDialog(modifyFFNDialog, "Set Biases"); biasesDialog.setSize(200, 46); biasesDialog.setLayout(new GridLayout(2, 1)); addBiases = new JButton("Add Bias"); removeBiases = new JButton("Remove Bias"); biasesDialog.add(addBiases); biasesDialog.add(removeBiases); addBiases.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JLabel howManyBiasLayersLabel, whatBiasNodeLabel, whatBiasValueLabel; final JFormattedTextField howManyBiasLayers, whatBiasNode, whatBiasValue; JButton addBiasOK, addBiasCancel; biasesDialog.setVisible(false); addBiasDialog = new JDialog(modifyFFNDialog, "Add Bias"); addBiasDialog.setSize(756, 90); addBiasDialog.setLayout(new GridLayout(4, 2)); howManyBiasLayersLabel = new JLabel("What Layer will get the Bias?"); howManyBiasLayers = new JFormattedTextField( new NumberFormatter(NumberFormat.getIntegerInstance())); whatBiasNodeLabel = new JLabel("Which Node will get the Bias?"); whatBiasNode = new JFormattedTextField( new NumberFormatter(NumberFormat.getIntegerInstance())); whatBiasValueLabel = new JLabel("What Value will the Bias have?"); whatBiasValue = new JFormattedTextField( new NumberFormatter(NumberFormat.getInstance())); addBiasOK = new JButton("OK"); addBiasCancel = new JButton("Cancel"); addBiasDialog.add(howManyBiasLayersLabel); addBiasDialog.add(howManyBiasLayers); addBiasDialog.add(whatBiasNodeLabel); addBiasDialog.add(whatBiasNode); addBiasDialog.add(whatBiasValueLabel); addBiasDialog.add(whatBiasValue); addBiasDialog.add(addBiasOK); addBiasDialog.add(addBiasCancel); addBiasOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (!howManyBiasLayers.getText().equals("") && !whatBiasNode.getText().equals("") && !whatBiasValue.getText().equals("")) { addBiasDialog.setVisible(false); if (net.get(resultsPane.getSelectedIndex()).addBias( Integer.parseInt(howManyBiasLayers.getText()) - 1, Integer.parseInt(whatBiasNode.getText()) - 1, Double.parseDouble(whatBiasValue.getText()))) { } else { JOptionPane.showMessageDialog(modifyFFNDialog, "Existential Error", "Invalid Node for Bias", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(modifyFFNDialog, "Form Error", "Form not completed", JOptionPane.ERROR_MESSAGE); } } }); addBiasCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { addBiasDialog.setVisible(false); } }); addBiasDialog.setVisible(true); } }); removeBiases.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { JLabel howManyBiasLayersLabel, whatBiasNodeLabel; final JFormattedTextField howManyBiasLayers, whatBiasNode; JButton addBiasOK, addBiasCancel; biasesDialog.setVisible(false); removeBiasDialog = new JDialog(modifyFFNDialog, "Remove Bias"); removeBiasDialog.setSize(756, 90); removeBiasDialog.setLayout(new GridLayout(3, 2)); howManyBiasLayersLabel = new JLabel("What Layer will lose the Bias?"); howManyBiasLayers = new JFormattedTextField( new NumberFormatter(NumberFormat.getIntegerInstance())); whatBiasNodeLabel = new JLabel("Which Node will get the Bias?"); whatBiasNode = new JFormattedTextField( new NumberFormatter(NumberFormat.getIntegerInstance())); addBiasOK = new JButton("OK"); addBiasCancel = new JButton("Cancel"); removeBiasDialog.add(howManyBiasLayersLabel); removeBiasDialog.add(howManyBiasLayers); removeBiasDialog.add(whatBiasNodeLabel); removeBiasDialog.add(whatBiasNode); removeBiasDialog.add(addBiasOK); removeBiasDialog.add(addBiasCancel); addBiasOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (!howManyBiasLayers.getText().equals("") && !whatBiasNode.getText().equals("")) { addBiasDialog.setVisible(false); if (net.get(resultsPane.getSelectedIndex()).removeBias( Integer.parseInt(howManyBiasLayers.getText()) - 1, Integer.parseInt(whatBiasNode.getText()) - 1)) { } else { JOptionPane.showMessageDialog(modifyFFNDialog, "Existential Error", "Invalid Node for Bias", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(modifyFFNDialog, "Form Error", "Form not completed", JOptionPane.ERROR_MESSAGE); } } }); addBiasCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { addBiasDialog.setVisible(false); } }); removeBiasDialog.setVisible(true); } }); biasesDialog.setVisible(true); } }); trainingCompletionButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { final JDialog iterationsDialog; JLabel numberOfIterationsLabel; final JFormattedTextField numberOfIterations; JButton iterationsOK, iterationsCancel; iterationsDialog = new JDialog(modifyFFNDialog, "Set Iterations"); iterationsDialog.setSize(765, 75); iterationsDialog.setLayout(new GridLayout(2, 2)); numberOfIterationsLabel = new JLabel("How Many Iterations do you want to Train?"); numberOfIterations = new JFormattedTextField( new NumberFormatter(NumberFormat.getIntegerInstance())); iterationsOK = new JButton("OK"); iterationsCancel = new JButton("Cancel"); iterationsDialog.add(numberOfIterationsLabel); iterationsDialog.add(numberOfIterations); iterationsDialog.add(iterationsOK); iterationsDialog.add(iterationsCancel); iterationsOK.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (!numberOfIterations.getText().equals("")) { iterationsDialog.setVisible(false); if (net.get(resultsPane.getSelectedIndex()) .setIterations(Integer.parseInt(numberOfIterations.getText()))) { settings.setText(""); settings.append("\n\n\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append("\n\nMomentum: " + net.get(resultsPane.getSelectedIndex()).getMomentum()); settings.append("\n\nTraining Style: "); if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) { settings.append("batch"); batchOn.setSelected(true); } else { settings.append("online"); onlineOn.setSelected(true); } settings.append("\n\nTraining End Condition: "); if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) { settings.append("Iterative"); settings.append("\n\nIterations: " + net.get(resultsPane.getSelectedIndex()).getIterations()); } else { settings.append("Ideal Error"); settings.append("\n\nIdeal Error: " + net.get(resultsPane.getSelectedIndex()).getIdealError()); } modifyFFNDialog.setVisible(true); } else { JOptionPane.showMessageDialog(modifyFFNDialog, "Invalid Number of Iterations", "Math Error", JOptionPane.ERROR_MESSAGE); } } else { JOptionPane.showMessageDialog(iterationsDialog, "Field not filled out", "Form Error", JOptionPane.ERROR_MESSAGE); } } }); iterationsCancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { iterationsDialog.setVisible(false); } }); iterationsDialog.setVisible(true); } }); modifyFFN.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (!learningRateTF.getText().equals("")) { net.get(resultsPane.getSelectedIndex()) .setLearningRate(Double.parseDouble(learningRateTF.getText())); learningRateTF.setText(""); } if (!momentumTF.getText().equals("")) { net.get(resultsPane.getSelectedIndex()) .setMomentum(Double.parseDouble(momentumTF.getText())); momentumTF.setText(""); } if (batchOn.isSelected()) { net.get(resultsPane.getSelectedIndex()).setBatchvOnline(true); } else { net.get(resultsPane.getSelectedIndex()).setBatchvOnline(false); } modifyFFNDialog.setVisible(false); } }); learningRateTF.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (learningRateTF.getText() != "") { net.get(resultsPane.getSelectedIndex()) .setLearningRate(Double.parseDouble(learningRateTF.getText())); } settings.setText(""); settings.append("\n\n\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append( "\n\nMomentum: " + net.get(resultsPane.getSelectedIndex()).getMomentum()); settings.append("\n\nTraining Style: "); if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) { settings.append("batch"); batchOn.setSelected(true); } else { settings.append("online"); onlineOn.setSelected(true); } settings.append("\n\nTraining End Condition: "); if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) { settings.append("Iterative"); settings.append("\n\nIterations: " + net.get(resultsPane.getSelectedIndex()).getIterations()); } else { settings.append("Ideal Error"); settings.append("\n\nIdeal Error: " + net.get(resultsPane.getSelectedIndex()).getIdealError()); } modifyFFNDialog.setVisible(true); } }); momentumTF.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (momentumTF.getText() != "") { net.get(resultsPane.getSelectedIndex()) .setMomentum(Double.parseDouble(momentumTF.getText())); } settings.setText(""); settings.append("\n\n\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append( "\n\nMomentum: " + net.get(resultsPane.getSelectedIndex()).getMomentum()); settings.append("\n\nTraining Style: "); if (net.get(resultsPane.getSelectedIndex()).getBatchvOnline()) { settings.append("batch"); batchOn.setSelected(true); } else { settings.append("online"); onlineOn.setSelected(true); } settings.append("\n\nTraining End Condition: "); if (net.get(resultsPane.getSelectedIndex()).getUseIteration()) { settings.append("Iterative"); settings.append("\n\nIterations: " + net.get(resultsPane.getSelectedIndex()).getIterations()); } else { settings.append("Ideal Error"); settings.append("\n\nIdeal Error: " + net.get(resultsPane.getSelectedIndex()).getIdealError()); } modifyFFNDialog.setVisible(true); } }); cancelModifyFFN.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { modifyFFNDialog.setVisible(false); } }); modifyFFNDialog.setVisible(true); } if (resultsPane.getTabCount() != 0 && netKind.get(resultsPane.getSelectedIndex()).toString().equals("Self-Organizing Map")) { modifySOMDialog = new JDialog(mainWindow, "Network Settings", true); modifySOMDialog.setSize(500, 400); modifySOMDialog.setLayout(new GridBagLayout()); GridBagConstraints asdf = new GridBagConstraints(); asdf.gridwidth = 5; asdf.gridheight = 1; asdf.gridx = 0; asdf.gridy = 0; asdf.fill = GridBagConstraints.HORIZONTAL; modifySOMDialog.add(new JSeparator(), asdf); asdf.gridwidth = 5; asdf.gridheight = 15; asdf.weightx = 1.0; asdf.weighty = 1.0; asdf.gridx = 0; asdf.gridy = 1; asdf.fill = GridBagConstraints.BOTH; settings = new JTextArea(); settings.setEditable(false); settings.setBorder(BorderFactory.createEtchedBorder()); modifySOMDialog.add(settings, asdf); asdf.fill = GridBagConstraints.HORIZONTAL; asdf.gridwidth = 5; asdf.gridheight = 1; asdf.gridx = 0; asdf.gridy = 16; modifySOMDialog.add(new JSeparator(), asdf); asdf.gridwidth = 2; asdf.gridx = 7; asdf.gridy = 0; modifySOMDialog.add(new JSeparator(), asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 1; mIterationL = new JLabel("Set Number of Iterations:"); modifySOMDialog.add(mIterationL, asdf); asdf.gridx = 7; asdf.gridy = 2; asdf.fill = GridBagConstraints.HORIZONTAL; mIterationTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance())); mIterationTF.setText(""); modifySOMDialog.add(mIterationTF, asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 3; mLRL = new JLabel("Set Learning Rate (0-1):"); modifySOMDialog.add(mLRL, asdf); asdf.gridx = 7; asdf.gridy = 4; asdf.fill = GridBagConstraints.HORIZONTAL; mLRTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance())); mLRTF.setText(""); modifySOMDialog.add(mLRTF, asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 5; mMaxL = new JLabel("Set Data Maximum:"); modifySOMDialog.add(mMaxL, asdf); asdf.gridx = 7; asdf.gridy = 6; asdf.fill = GridBagConstraints.HORIZONTAL; mMaxTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance())); mMaxTF.setText(""); modifySOMDialog.add(mMaxTF, asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridx = 7; asdf.gridy = 7; mMinL = new JLabel("Set Data Minimum:"); modifySOMDialog.add(mMinL, asdf); asdf.gridx = 7; asdf.gridy = 8; asdf.fill = GridBagConstraints.HORIZONTAL; mMinTF = new JFormattedTextField(new NumberFormatter(NumberFormat.getNumberInstance())); mMinTF.setText(""); modifySOMDialog.add(mMinTF, asdf); asdf.fill = GridBagConstraints.HORIZONTAL; asdf.gridy = 16; modifySOMDialog.add(new JSeparator(), asdf); asdf.fill = GridBagConstraints.NONE; asdf.gridwidth = 1; asdf.gridx = 3; asdf.gridy = 17; asdf.anchor = GridBagConstraints.PAGE_END; modifySOM = new JButton("OK"); modifySOMDialog.add(modifySOM, asdf); asdf.gridx = 7; cancelModifySOM = new JButton("Cancel"); modifySOMDialog.add(cancelModifySOM, asdf); settings.setText(""); settings.append("\n\nNumber of Iterations: " + net.get(resultsPane.getSelectedIndex()).getNumIterations()); settings.append( "\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append("\n\nData Maximum: " + net.get(resultsPane.getSelectedIndex()).getDataMax()); settings.append("\n\nData Minimum: " + net.get(resultsPane.getSelectedIndex()).getDataMin()); mIterationTF.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (mIterationTF.getText() != "") { net.get(resultsPane.getSelectedIndex()) .setNumIterations(Integer.parseInt(mIterationTF.getText())); settings.setText(""); settings.append("\n\nNumber of Iterations: " + net.get(resultsPane.getSelectedIndex()).getNumIterations()); settings.append("\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append("\n\nData Maximum: " + net.get(resultsPane.getSelectedIndex()).getDataMax()); settings.append("\n\nData Minimum: " + net.get(resultsPane.getSelectedIndex()).getDataMin()); } } }); mLRTF.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if ((mLRTF.getText() != "") && ((Double.parseDouble(mLRTF.getText())) <= 1.0)) { net.get(resultsPane.getSelectedIndex()) .setLearningRate(Double.parseDouble(mLRTF.getText())); settings.setText(""); settings.append("\n\nNumber of Iterations: " + net.get(resultsPane.getSelectedIndex()).getNumIterations()); settings.append("\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append("\n\nData Maximum: " + net.get(resultsPane.getSelectedIndex()).getDataMax()); settings.append("\n\nData Minimum: " + net.get(resultsPane.getSelectedIndex()).getDataMin()); } else { JOptionPane.showMessageDialog(mLRTF, "Pick a number from 0 - 1", "Incorrect Value", JOptionPane.ERROR_MESSAGE); mLRTF.setText(""); } } }); mMaxTF.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if ((mMaxTF.getText() != "") && (((Double.parseDouble(mMaxTF.getText())) > net .get(resultsPane.getSelectedIndex()).getDataMin()))) { net.get(resultsPane.getSelectedIndex()) .setDataMax(Double.parseDouble(mMaxTF.getText())); settings.setText(""); settings.append("\n\nNumber of Iterations: " + net.get(resultsPane.getSelectedIndex()).getNumIterations()); settings.append("\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append("\n\nData Maximum: " + net.get(resultsPane.getSelectedIndex()).getDataMax()); settings.append("\n\nData Minimum: " + net.get(resultsPane.getSelectedIndex()).getDataMin()); } else { JOptionPane.showMessageDialog(mMaxTF, "Max value must be greater than Min value", "Incorrect Value", JOptionPane.ERROR_MESSAGE); mMaxTF.setText(""); } } }); mMinTF.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if ((mMinTF.getText() != "") && ((Double.parseDouble(mMinTF.getText())) < net .get(resultsPane.getSelectedIndex()).getDataMax())) { net.get(resultsPane.getSelectedIndex()) .setDataMin(Double.parseDouble(mMinTF.getText())); settings.setText(""); settings.append("\n\nNumber of Iterations: " + net.get(resultsPane.getSelectedIndex()).getNumIterations()); settings.append("\n\nLearning Rate: " + net.get(resultsPane.getSelectedIndex()).getLearningRate()); settings.append("\n\nData Maximum: " + net.get(resultsPane.getSelectedIndex()).getDataMax()); settings.append("\n\nData Minimum: " + net.get(resultsPane.getSelectedIndex()).getDataMin()); } else { JOptionPane.showMessageDialog(mMinTF, "Min value must be less than Max value", "Incorrect Value", JOptionPane.ERROR_MESSAGE); mMinTF.setText(""); } } }); modifySOM.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { boolean error = false; if (!("".equals(mIterationTF.getText()))) { net.get(resultsPane.getSelectedIndex()) .setNumIterations(Integer.parseInt(mIterationTF.getText())); } if (!("".equals(mLRTF.getText()))) { if ((Double.parseDouble(mLRTF.getText())) > 1.0) { error = true; mLRTF.setText(""); } else net.get(resultsPane.getSelectedIndex()) .setLearningRate(Double.parseDouble(mLRTF.getText())); } if (!("".equals(mMaxTF.getText()))) { if (((Double.parseDouble(mMaxTF.getText())) < net .get(resultsPane.getSelectedIndex()).getDataMin())) { error = true; mMaxTF.setText(""); } else net.get(resultsPane.getSelectedIndex()) .setDataMax(Double.parseDouble(mMaxTF.getText())); } if (!("".equals(mMinTF.getText()))) { if ((Double.parseDouble(mMinTF.getText())) > net.get(resultsPane.getSelectedIndex()) .getDataMax()) { error = true; mMinTF.setText(""); } else net.get(resultsPane.getSelectedIndex()) .setDataMin(Double.parseDouble(mMinTF.getText())); } if (error == true) { JOptionPane.showMessageDialog(modifySOMDialog, "One or more fields have incorrect values", "Incorrect Value", JOptionPane.ERROR_MESSAGE); } else { modifySOMDialog.setVisible(false); readOut.get(resultsPane.getSelectedIndex()).append("\nUpdated Map:\n"); printInitMap(); } } }); cancelModifySOM.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { modifySOMDialog.setVisible(false); } }); modifySOMDialog.setVisible(true); } } }); modify.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : changeConfig.getActionListeners()) { a.actionPerformed(ae); } } }); //The following code is for the newNet button under file: //create a dialog to be activated when "New Network" is pressed in the file menu newDialog = new JDialog(mainWindow, "New Network", true); newDialog.setSize(375, 100); newDialog.setLayout(new GridLayout(3, 2)); //going to change the layout to GridBagLayout for better customization name = new JLabel("Network Name:"); newName = new JTextField(10); type = new JLabel("Type of Network:"); netTypes = new String[] { "Feed Forward Network", "Self-Organizing Map" }; netType = new JComboBox<String>(netTypes); netType.setSelectedItem("Feed Forward Network"); createNewNet = new JButton("create"); cancelNew = new JButton("cancel"); newDialog.add(name); newDialog.add(newName); newDialog.add(type); newDialog.add(netType); newDialog.add(createNewNet); newDialog.add(cancelNew); //utilities for a second dialog(Feed Forward Network) in the process of creating a new network number = new JLabel("Enter the number of layers you want for your network:"); howManyLayers = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance())); createFFNArchitecture = new JButton("OK"); cancelFFN = new JButton("Cancel"); howManyNodes = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance())); createFFN = new JButton("OK"); cancelNodes = new JButton("Cancel"); //Written by Michael Scott somLattice = new JLabel(" Lattice number for your Map:"); somLatticeField = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance())); somLatticeField.setFocusLostBehavior(1); somMax = new JLabel(" Maximum value of your input (if known):"); somMaxField = new JFormattedTextField(new NumberFormatter(NumberFormat.getInstance())); somMaxField.setFocusLostBehavior(1); somMin = new JLabel(" Minimum value of your input (if known):"); somMinField = new JFormattedTextField(new NumberFormatter(NumberFormat.getInstance())); somMinField.setFocusLostBehavior(1); somDim = new JLabel(" Node Dimensions:"); somDimField = new JFormattedTextField(new NumberFormatter(NumberFormat.getIntegerInstance())); somDimField.setFocusLostBehavior(1); createSOM = new JButton("OK"); cancelSOM = new JButton("Cancel"); //displays the newDialog window when newNet is pressed newNet.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { newDialog.setVisible(true); } }); newwer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { newDialog.setVisible(true); } }); //makes hitting enter in the text box do the same thing as clicking "create" newName.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : createNewNet.getActionListeners()) { a.actionPerformed(ae); } } }); //when create net is pressed, this reads the selections from the newNet dialog and creates the approriate next dialog createNewNet.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { int test; test = 0; for (StringBuffer names : netName) { if (names.toString().equals(newName.getText())) test = 1; } if (test == 0) if (!newName.getText().equals("")) { if (netType.getSelectedIndex() == 0) { //if the net selected is Feed Forward, create and display the prompt for a feed forward network newDialog.setVisible(false); fFNDialog = new JDialog(mainWindow, newName.getText(), true); fFNDialog.setSize(919, 65); fFNDialog.setLayout(new GridLayout(2, 2)); fFNDialog.add(number); fFNDialog.add(howManyLayers); fFNDialog.add(createFFNArchitecture); fFNDialog.add(cancelFFN); fFNDialog.setVisible(true); } //Written by Michael Scott if (netType.getSelectedIndex() == 1) { newDialog.setVisible(false); sOMDialog = new JDialog(mainWindow, newName.getText(), true); sOMDialog.setSize(500, 180); sOMDialog.setLayout(new GridLayout(5, 2)); sOMDialog.add(somLattice); sOMDialog.add(somLatticeField); sOMDialog.add(somDim); sOMDialog.add(somDimField); sOMDialog.add(somMax); sOMDialog.add(somMaxField); sOMDialog.add(somMin); sOMDialog.add(somMinField); sOMDialog.add(createSOM); sOMDialog.add(cancelSOM); sOMDialog.setVisible(true); } } else JOptionPane.showMessageDialog(createNewNet, "Network must have a Name", "Namelessness Error", JOptionPane.ERROR_MESSAGE); else { JOptionPane.showMessageDialog(createNewNet, "Network " + newName.getText() + " already exists", "Existential Naming Error", JOptionPane.ERROR_MESSAGE); newName.setText(""); } } }); //beginning of section about creating Feed Forward Networks //cancel clears the name field and hides the newDialog dialog cancelNew.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { newDialog.setVisible(false); newName.setText(""); } }); //makes hitting enter the same as clicking "ok" howManyLayers.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : createFFNArchitecture.getActionListeners()) { a.actionPerformed(ae); } } }); //create a prompt for the first layer to determine how many nodes will go into the first layer createFFNArchitecture.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (!howManyLayers.getText().equals("") && (layers = Integer.parseInt(howManyLayers.getText())) > 1) { nodeConfiguration = new int[layers]; //create an array to hold the node configuration that will be passed to the Net constructor layer = 1; //create a variable to hold the current layer the prompt series is on numberofNodes = new JLabel("How many nodes do you want in layer " + layer + "?"); fFNDialog.setVisible(false); howManyNodesDialog = new JDialog(mainWindow, newName.getText(), true); howManyNodesDialog.setSize(919, 65); howManyNodesDialog.setLayout(new GridLayout(2, 2)); howManyNodesDialog.add(numberofNodes); howManyNodesDialog.add(howManyNodes); howManyNodesDialog.add(createFFN); howManyNodesDialog.add(cancelNodes); howManyNodesDialog.setVisible(true); } else { //if the string is not valid, pop up an error message JOptionPane.showMessageDialog(fFNDialog, "<html>Number Out of Bounds<br>Please Enter a Number Greater than 1</html>", "Out of Bounds", JOptionPane.ERROR_MESSAGE); } } }); //runs each time ok is pressed, until all the layers have a vaule for the number of nodes in the layer createFFN.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (!howManyNodes.getText().equals("") && (nodeConfiguration[layer - 1] = Integer.parseInt(howManyNodes.getText())) > 0) { if (layer == layers) { try { //adds a close button to the top corner of each tab title.add(new JLabel(newName.getText() + " ")); close.add(new JButton("X")); close.get(openNets).setActionCommand(newName.getText()); close.get(openNets).setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); close.get(openNets).setMargin(new Insets(0, 0, 0, 0)); tabPanel.add(new JPanel(new GridBagLayout())); tabPanel.get(openNets).setOpaque(false); GridBagConstraints grid = new GridBagConstraints(); grid.fill = GridBagConstraints.HORIZONTAL; grid.gridx = 0; grid.gridy = 0; grid.weightx = 1; tabPanel.get(openNets).add(title.get(openNets), grid); grid.gridx = 1; grid.gridy = 0; grid.weightx = 0; tabPanel.get(openNets).add(close.get(openNets), grid); //adds a loading bar loadingBar.add(new JLabel("", loadingImage, SwingConstants.CENTER)); loadingBar.get(openNets).setHorizontalTextPosition(SwingConstants.LEFT); loadingBar.get(openNets).setVisible(false); //creates and sets the network configuration net.add(new FullyConnectedFeedForwardNet(nodeConfiguration)); netKind.add(new StringBuffer(netType.getSelectedItem().toString())); netName.add(new StringBuffer(newName.getText())); oneNet.add(new JPanel()); oneNet.get(openNets).setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; //creates the readOut space and formats it so that the scroll pane/text changes size with the window, reserves space for the loading bar readOut.add(new JTextArea("")); readOutLocale.add(new JScrollPane(readOut.get(openNets))); readOut.get(openNets).setEditable(false); constraints.gridx = 0; constraints.gridy = 0; constraints.weighty = 1.0; constraints.weightx = 1.0; constraints.gridwidth = 2; constraints.ipady = 90; oneNet.get(openNets).add(readOutLocale.get(openNets), constraints); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 1; constraints.ipady = 0; constraints.gridwidth = 2; constraints.anchor = GridBagConstraints.PAGE_END; //add everythign to the tabbed pane oneNet.get(openNets).add(loadingBar.get(openNets), constraints); resultsPane.addTab(netName.get(openNets).toString(), oneNet.get(openNets)); resultsPane.setTabComponentAt(openNets, tabPanel.get(openNets)); path.add(""); //display the starting configuration of the network readOut.get(openNets).append("Network: " + netName.get(openNets) + "\n\n"); resultsPane.setSelectedIndex(openNets++); printConnections(); //erases all the text in the setup fields and closes the window howManyNodes.setValue(null); howManyLayers.setText(""); newName.setText(""); howManyNodesDialog.setVisible(false); //unfortunately difficult way that I made to add the close button functionality to close a tab //it works, but there has to be a better way to do this close.get(resultsPane.getSelectedIndex()).addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent ae) { int result; result = 0; for (StringBuffer names : netName) { if (ae.getActionCommand().equals(names.toString())) { result = JOptionPane.showConfirmDialog(createFFN, "<html>Exiting Without Saving can Cause you to Lose your Progress<br>Are you sure you want to Continue?</html>", "Close Network", JOptionPane.OK_CANCEL_OPTION); resultsPane.setSelectedIndex(netName.indexOf(names)); } } if (result == JOptionPane.OK_OPTION) { net.remove(resultsPane.getSelectedIndex()); oneNet.remove(resultsPane.getSelectedIndex()); readOutLocale.remove(resultsPane.getSelectedIndex()); readOut.remove(resultsPane.getSelectedIndex()); loadingBar.remove(resultsPane.getSelectedIndex()); tabPanel.remove(resultsPane.getSelectedIndex()); title.remove(resultsPane.getSelectedIndex()); close.remove(resultsPane.getSelectedIndex()); netName.remove(resultsPane.getSelectedIndex()); resultsPane.remove(resultsPane.getSelectedIndex()); openNets--; } } }); } catch (OutOfMemoryError e) { JOptionPane.showMessageDialog(mainWindow, "<html>Net too Large for Memory.<br>Try Closing some of the Nets.</html>", "Memory Error", JOptionPane.ERROR_MESSAGE); } } else { layer++; howManyNodes.setText(""); numberofNodes.setText("How many nodes do you want in layer " + layer + "?"); } } else { JOptionPane.showMessageDialog(createFFN, "<html>Number Out of Bounds<br>Please Enter a Number Greater than 0", "Out of Bounds", JOptionPane.ERROR_MESSAGE); } } }); //makes hitting enter in text box the same as clicking ok howManyNodes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { for (ActionListener a : createFFN.getActionListeners()) { a.actionPerformed(ae); } } }); //cancels the node prompt cancelNodes.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { newName.setText(""); howManyLayers.setText(""); howManyNodes.setText(""); howManyNodesDialog.setVisible(false); } }); //cancel clears both name fields so far filled in the series of dialogs and hides the dialog cancelFFN.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { newName.setText(""); howManyLayers.setText(""); fFNDialog.setVisible(false); } }); //end of section about creating FFNs //end of section about newNet //Method to create a SOM createSOM.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (somLatticeField.getText().equals("") || somDimField.getText().equals("")) { JOptionPane.showMessageDialog(createSOM, "<html>Empty Field<br>Please Fill All Fields", "Empty Field", JOptionPane.ERROR_MESSAGE); } else { if (somMaxField.getText().equals("")) somMaxField.setText("100"); if (somMinField.getText().equals("")) somMinField.setText("0"); if (Double.parseDouble(somMaxField.getText().replace(",", "")) < Double .parseDouble(somMinField.getText().replace(",", ""))) { JOptionPane.showMessageDialog(createSOM, "MIN GREATER THAN MAX!!!!", "Stupidity Error", JOptionPane.ERROR_MESSAGE); } try { //adds a close button to the top corner of each tab title.add(new JLabel(newName.getText() + " ")); close.add(new JButton("X")); close.get(openNets).setActionCommand(newName.getText()); close.get(openNets).setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); close.get(openNets).setMargin(new Insets(0, 0, 0, 0)); tabPanel.add(new JPanel(new GridBagLayout())); tabPanel.get(openNets).setOpaque(false); GridBagConstraints grid = new GridBagConstraints(); grid.fill = GridBagConstraints.HORIZONTAL; grid.gridx = 0; grid.gridy = 0; grid.weightx = 1; tabPanel.get(openNets).add(title.get(openNets), grid); grid.gridx = 1; grid.gridy = 0; grid.weightx = 0; tabPanel.get(openNets).add(close.get(openNets), grid); //adds a loading bar loadingBar.add(new JLabel("", loadingImage, SwingConstants.CENTER)); loadingBar.get(openNets).setHorizontalTextPosition(SwingConstants.LEFT); loadingBar.get(openNets).setVisible(false); //creates and sets the network configuration net.add(new SelfOrganizingMap()); netKind.add(new StringBuffer(netType.getSelectedItem().toString())); netName.add(new StringBuffer(newName.getText())); oneNet.add(new JPanel()); oneNet.get(openNets).setLayout(new GridBagLayout()); GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; //creates the readOut space and formats it so that the scroll pane/text changes size with the window, reserves space for the loading bar readOut.add(new JTextArea("")); readOutLocale.add(new JScrollPane(readOut.get(openNets))); readOut.get(openNets).setEditable(false); constraints.gridx = 0; constraints.gridy = 0; constraints.weighty = 1.0; constraints.weightx = 1.0; constraints.gridwidth = 2; constraints.ipady = 90; oneNet.get(openNets).add(readOutLocale.get(openNets), constraints); constraints.fill = GridBagConstraints.HORIZONTAL; constraints.gridx = 0; constraints.gridy = 1; constraints.ipady = 0; constraints.gridwidth = 2; constraints.anchor = GridBagConstraints.PAGE_END; //add everythign to the tabbed pane oneNet.get(openNets).add(loadingBar.get(openNets), constraints); resultsPane.addTab(netName.get(openNets).toString(), oneNet.get(openNets)); resultsPane.setTabComponentAt(openNets, tabPanel.get(openNets)); path.add(""); //display the starting configuration of the network readOut.get(openNets).append("Network: " + netName.get(openNets) + "\n\n"); resultsPane.setSelectedIndex(openNets++); try { net.get(resultsPane.getSelectedIndex()) .setLatticeValue(Integer.parseInt(somLatticeField.getText().replace(",", ""))); net.get(resultsPane.getSelectedIndex()) .setDataMax(Double.parseDouble(somMaxField.getText().replace(",", ""))); net.get(resultsPane.getSelectedIndex()) .setDataMin(Double.parseDouble(somMinField.getText().replace(",", ""))); net.get(resultsPane.getSelectedIndex()) .setInputDimensions(Integer.parseInt(somDimField.getText().replace(",", ""))); net.get(resultsPane.getSelectedIndex()).runNet(); readOut.get(resultsPane.getSelectedIndex()).append("Initial Untrained Map:\n"); printInitMap(); if (!getColorMap.isVisible()) { util.addSeparator(); util.add(getColorMap); getColorMap.setVisible(true); } //erases all the text in the setup fields and closes the window newName.setText(""); somLatticeField.setText(""); somDimField.setText(""); somMaxField.setText(""); somMinField.setText(""); sOMDialog.setVisible(false); //unfortunately difficult way that I made to add the close button functionality to close a tab //it works, but there has to be a better way to do this close.get(resultsPane.getSelectedIndex()).addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent ae) { int result; result = 0; for (StringBuffer names : netName) { if (ae.getActionCommand().equals(names.toString())) { result = JOptionPane.showConfirmDialog(createSOM, "<html>Exiting Without Saving can Cause you to Lose your Progress<br>Are you sure you want to Continue?</html>", "Close Network", JOptionPane.OK_CANCEL_OPTION); resultsPane.setSelectedIndex(netName.indexOf(names)); } } if (result == JOptionPane.OK_OPTION) { net.remove(resultsPane.getSelectedIndex()); oneNet.remove(resultsPane.getSelectedIndex()); readOutLocale.remove(resultsPane.getSelectedIndex()); readOut.remove(resultsPane.getSelectedIndex()); loadingBar.remove(resultsPane.getSelectedIndex()); tabPanel.remove(resultsPane.getSelectedIndex()); title.remove(resultsPane.getSelectedIndex()); close.remove(resultsPane.getSelectedIndex()); netName.remove(resultsPane.getSelectedIndex()); resultsPane.remove(resultsPane.getSelectedIndex()); openNets--; } } }); } catch (Exception e) { net.remove(resultsPane.getSelectedIndex()); oneNet.remove(resultsPane.getSelectedIndex()); readOutLocale.remove(resultsPane.getSelectedIndex()); readOut.remove(resultsPane.getSelectedIndex()); loadingBar.remove(resultsPane.getSelectedIndex()); tabPanel.remove(resultsPane.getSelectedIndex()); title.remove(resultsPane.getSelectedIndex()); close.remove(resultsPane.getSelectedIndex()); netName.remove(resultsPane.getSelectedIndex()); resultsPane.remove(resultsPane.getSelectedIndex()); openNets--; JOptionPane.showMessageDialog(sOMDialog, "Numbers too large to parse", "Parse error", JOptionPane.ERROR_MESSAGE); } } catch (OutOfMemoryError e) { JOptionPane.showMessageDialog(mainWindow, "<html>Net too Large for Memory.<br>Try Closing some of the Nets.</html>", "Memory Error", JOptionPane.ERROR_MESSAGE); } } } }); cancelSOM.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { newName.setText(""); somLatticeField.setText(""); somMaxField.setText(""); somMinField.setText(""); sOMDialog.setVisible(false); } }); //end of SOM creation mainWindow.setVisible(true); }
From source file:org.esa.beam.visat.toolviews.stat.StatisticsPanel.java
private JPanel createStatPanel(Stx stx, final Mask regionalMask, final Mask qualityMask, int stxIdx, RasterDataNode raster) {//w ww .j a v a 2s. com final Histogram histogram = stx.getHistogram(); final int row = stxIdx + 1; // account for header boolean includeFileMetaData = statisticsCriteriaPanel.isIncludeFileMetaData(); boolean includeMaskMetaData = statisticsCriteriaPanel.isIncludeMaskMetaData(); boolean includeBandMetaData = statisticsCriteriaPanel.isIncludeBandMetaData(); boolean includeBinningInfo = statisticsCriteriaPanel.isIncludeBinningInfo(); ; boolean includeTimeMetaData = statisticsCriteriaPanel.isIncludeTimeMetaData(); boolean isIncludeTimeSeriesMetaData = statisticsCriteriaPanel.isIncludeTimeSeriesMetaData(); boolean includeProjectionParameters = statisticsCriteriaPanel.isIncludeProjectionParameters(); boolean includeColumnBreaks = statisticsCriteriaPanel.isIncludeColBreaks(); // Initialize all spreadsheet table indices to -1 (default don't use value) if (stxIdx == 0 || metaDataFieldsHashMap == null || primaryStatisticsFieldsHashMap == null) { initHashMaps(); } XIntervalSeries histogramSeries = new XIntervalSeries("Histogram"); double histDomainBounds[] = { histogram.getLowValue(0), histogram.getHighValue(0) }; double histRangeBounds[] = { Double.NaN, Double.NaN }; if (!fixedHistDomainAllPlots || (fixedHistDomainAllPlots && !fixedHistDomainAllPlotsInitialized)) { if (!statisticsCriteriaPanel.isLogMode()) { if (statisticsCriteriaPanel.plotsThreshDomainSpan()) { if (statisticsCriteriaPanel.plotsThreshDomainLow() >= 0.1) { histDomainBounds[0] = histogram .getPTileThreshold((statisticsCriteriaPanel.plotsThreshDomainLow()) / 100)[0]; } if (statisticsCriteriaPanel.plotsThreshDomainHigh() <= 99.9) { histDomainBounds[1] = histogram .getPTileThreshold(statisticsCriteriaPanel.plotsThreshDomainHigh() / 100)[0]; } } else if (statisticsCriteriaPanel.plotsDomainSpan()) { if (!Double.isNaN(statisticsCriteriaPanel.plotsDomainLow())) { histDomainBounds[0] = statisticsCriteriaPanel.plotsDomainLow(); } if (!Double.isNaN(statisticsCriteriaPanel.plotsDomainHigh())) { histDomainBounds[1] = statisticsCriteriaPanel.plotsDomainHigh(); } } } else { histDomainBounds[0] = histogram.getBinLowValue(0, 0); histDomainBounds[1] = histogram.getHighValue(0); } // if (!LogMode && plotsThreshDomainSpan && plotsThreshDomainLow >= 0.1 && plotsThreshDomainHigh <= 99.9) { // histDomainBounds[0] = histogram.getPTileThreshold((plotsThreshDomainLow) / 100)[0]; // histDomainBounds[1] = histogram.getPTileThreshold(plotsThreshDomainHigh / 100)[0]; // // } else { // histDomainBounds[0] = histogram.getBinLowValue(0, 0); // histDomainBounds[1] = histogram.getHighValue(0); // } if (fixedHistDomainAllPlots && !fixedHistDomainAllPlotsInitialized) { histDomainBoundsAllPlots[0] = histDomainBounds[0]; histDomainBoundsAllPlots[1] = histDomainBounds[1]; fixedHistDomainAllPlotsInitialized = true; } } else { histDomainBounds[0] = histDomainBoundsAllPlots[0]; histDomainBounds[1] = histDomainBoundsAllPlots[1]; } int[] bins = histogram.getBins(0); for (int j = 0; j < bins.length; j++) { histogramSeries.add(histogram.getBinLowValue(0, j), histogram.getBinLowValue(0, j), j < bins.length - 1 ? histogram.getBinLowValue(0, j + 1) : histogram.getHighValue(0), bins[j]); } String logTitle = (statisticsCriteriaPanel.isLogMode()) ? "Log10 of " : ""; ChartPanel histogramPanel = createChartPanel(histogramSeries, logTitle + raster.getName() + " (" + raster.getUnit() + ")", "Frequency in #Pixels", new Color(0, 0, 127), histDomainBounds, histRangeBounds); // histogramPanel.setPreferredSize(new Dimension(300, 200)); if (statisticsCriteriaPanel.exactPlotSize()) { histogramPanel.setMinimumSize(new Dimension(statisticsCriteriaPanel.plotSizeWidth(), statisticsCriteriaPanel.plotSizeHeight())); histogramPanel.setPreferredSize(new Dimension(statisticsCriteriaPanel.plotSizeWidth(), statisticsCriteriaPanel.plotSizeHeight())); histogramPanel.setMaximumSize(new Dimension(statisticsCriteriaPanel.plotSizeWidth(), statisticsCriteriaPanel.plotSizeHeight())); } else { histogramPanel.setMinimumSize(new Dimension(plotMinWidth, plotMinHeight)); histogramPanel.setPreferredSize(new Dimension(plotMinWidth, plotMinHeight)); } XIntervalSeries percentileSeries = new XIntervalSeries("Percentile"); // if (1 == 2 && LogMode) { // percentileSeries.add(0, // 0, // 1, // Math.pow(10, histogram.getLowValue(0))); // for (int j = 1; j < 99; j++) { // percentileSeries.add(j, // j, // j + 1, // Math.pow(10, histogram.getPTileThreshold(j / 100.0)[0])); // } // percentileSeries.add(99, // 99, // 100, // Math.pow(10, histogram.getHighValue(0))); // // } else { // percentileSeries.add(0, // 0, // 0.25, // histogram.getLowValue(0)); // // for (double j = 0.25; j < 99.75; j += .25) { // percentileSeries.add(j, // j, // j + 1, // histogram.getPTileThreshold(j / 100.0)[0]); // } // percentileSeries.add(99.75, // 99.75, // 100, // histogram.getHighValue(0)); // } // // double fraction = 0; // for (int j = 0; j < bins.length; j++) { // // fraction = (1.0) * j / bins.length; // // if (fraction > 0 && fraction < 1) { // percentileSeries.add(histogram.getBinLowValue(0, j), // histogram.getBinLowValue(0, j), // j < bins.length - 1 ? histogram.getBinLowValue(0, j + 1) : histogram.getHighValue(0), // histogram.getPTileThreshold(fraction)[0]); // } // // // } // // double test = fraction; double[] percentileDomainBounds = { Double.NaN, Double.NaN }; double[] percentileRangeBounds = { Double.NaN, Double.NaN }; ChartPanel percentilePanel = null; if (invertPercentile) { double increment = .01; for (double j = 0; j < 100; j += increment) { double fraction = j / 100.0; double nextFraction = (j + increment) / 100.0; if (fraction > 0.0 && fraction < 1.0 && nextFraction > 0.0 && nextFraction < 1.0) { double thresh = histogram.getPTileThreshold(fraction)[0]; double nextThresh = histogram.getPTileThreshold(nextFraction)[0]; percentileSeries.add(thresh, thresh, nextThresh, j); } } if (!statisticsCriteriaPanel.isLogMode()) { percentileDomainBounds[0] = histDomainBounds[0]; percentileDomainBounds[1] = histDomainBounds[1]; } percentileRangeBounds[0] = 0; percentileRangeBounds[1] = 100; percentilePanel = createScatterChartPanel(percentileSeries, logTitle + raster.getName() + " (" + raster.getUnit() + ")", "Percent Threshold", new Color(0, 0, 0), percentileDomainBounds, percentileRangeBounds); } else { percentileSeries.add(0, 0, 0.25, histogram.getLowValue(0)); for (double j = 0.25; j < 99.75; j += .25) { percentileSeries.add(j, j, j + 1, histogram.getPTileThreshold(j / 100.0)[0]); } percentileSeries.add(99.75, 99.75, 100, histogram.getHighValue(0)); percentileDomainBounds[0] = 0; percentileDomainBounds[1] = 100; percentileRangeBounds[0] = histDomainBounds[0]; percentileRangeBounds[1] = histDomainBounds[1]; percentilePanel = createScatterChartPanel(percentileSeries, "Percent_Threshold", logTitle + raster.getName() + " (" + raster.getUnit() + ")", new Color(0, 0, 0), percentileDomainBounds, percentileRangeBounds); } // percentilePanel.setPreferredSize(new Dimension(300, 200)); if (statisticsCriteriaPanel.exactPlotSize()) { percentilePanel.setMinimumSize(new Dimension(statisticsCriteriaPanel.plotSizeWidth(), statisticsCriteriaPanel.plotSizeHeight())); percentilePanel.setPreferredSize(new Dimension(statisticsCriteriaPanel.plotSizeWidth(), statisticsCriteriaPanel.plotSizeHeight())); percentilePanel.setMaximumSize(new Dimension(statisticsCriteriaPanel.plotSizeWidth(), statisticsCriteriaPanel.plotSizeHeight())); } else { percentilePanel.setMinimumSize(new Dimension(plotMinWidth, plotMinHeight)); percentilePanel.setPreferredSize(new Dimension(plotMinWidth, plotMinHeight)); } int size = raster.getRasterHeight() * raster.getRasterWidth(); int validPixelCount = histogram.getTotals()[0]; int dataRows = 0; // new Object[]{"RasterSize(Pixels)", size}, // new Object[]{"SampleSize(Pixels)", histogram.getTotals()[0]}, Object[][] totalPixels = null; if (statisticsCriteriaPanel.includeTotalPixels()) { int totalPixelCount = stx.getRawTotal(); double percentFilled = (totalPixelCount > 0) ? (1.0 * validPixelCount / totalPixelCount) : 0; totalPixels = new Object[][] { new Object[] { "Regional_Pixels", stx.getRawTotal() }, new Object[] { "Valid_Pixels", validPixelCount }, new Object[] { "Fraction_Valid", percentFilled } }; } else { totalPixels = new Object[][] { new Object[] { "Valid_Pixels", validPixelCount } }; } dataRows += totalPixels.length; Object[][] firstData = new Object[][] { new Object[] { "Mean", stx.getMean() } }; dataRows += firstData.length; Object[][] minMaxData = null; if (statisticsCriteriaPanel.includeMinMax()) { minMaxData = new Object[][] { new Object[] { "Minimum", stx.getMinimum() }, new Object[] { "Maximum", stx.getMaximum() } }; dataRows += minMaxData.length; } Object[] medianObject = null; if (statisticsCriteriaPanel.includeMedian()) { medianObject = new Object[] { "Median", stx.getMedianRaster() }; dataRows++; } Object[][] secondData = new Object[][] { new Object[] { "Standard_Deviation", stx.getStandardDeviation() }, new Object[] { "Variance", getVariance(stx) }, new Object[] { "Coefficient_of_Variation", getCoefficientOfVariation(stx) } }; dataRows += secondData.length; Object[][] binningInfo = null; if (statisticsCriteriaPanel.isIncludeBinningInfo()) { binningInfo = new Object[][] { new Object[] { "Total_Bins", histogram.getNumBins()[0] }, new Object[] { "Bin_Width", getBinSize(histogram) }, new Object[] { "Bin_Min", histogram.getLowValue(0) }, new Object[] { "Bin_Max", histogram.getHighValue(0) } }; dataRows += binningInfo.length; } Object[][] histogramStats = null; if (statisticsCriteriaPanel.includeHistogramStats()) { if (statisticsCriteriaPanel.isLogMode()) { histogramStats = new Object[][] { new Object[] { "Mean(LogBinned)", Math.pow(10, histogram.getMean()[0]) }, new Object[] { "Median(LogBinned)", Math.pow(10, stx.getMedian()) }, new Object[] { "StandardDeviation(LogBinned)", Math.pow(10, histogram.getStandardDeviation()[0]) } }; } else { histogramStats = new Object[][] { new Object[] { "Mean(Binned)", histogram.getMean()[0] }, new Object[] { "Median(Binned)", stx.getMedian() }, new Object[] { "StandardDeviation(Binned)", histogram.getStandardDeviation()[0] } }; } dataRows += histogramStats.length; } Object[][] percentData = new Object[statisticsCriteriaPanel.getPercentThresholdsList().size()][]; for (int i = 0; i < statisticsCriteriaPanel.getPercentThresholdsList().size(); i++) { int value = statisticsCriteriaPanel.getPercentThresholdsList().get(i); double percent = value / 100.0; String percentString = Integer.toString(value); Object[] pTileThreshold; if (statisticsCriteriaPanel.isLogMode()) { pTileThreshold = new Object[] { percentString + "%Threshold(Log)", Math.pow(10, histogram.getPTileThreshold(percent)[0]) }; } else { pTileThreshold = new Object[] { percentString + "%Threshold", histogram.getPTileThreshold(percent)[0] }; } percentData[i] = pTileThreshold; } dataRows += percentData.length; Object[][] tableData = new Object[dataRows][]; int tableDataIdx = 0; if (totalPixels != null) { for (int i = 0; i < totalPixels.length; i++) { tableData[tableDataIdx] = totalPixels[i]; tableDataIdx++; } } if (firstData != null) { for (int i = 0; i < firstData.length; i++) { tableData[tableDataIdx] = firstData[i]; tableDataIdx++; } } if (medianObject != null) { tableData[tableDataIdx] = medianObject; tableDataIdx++; } if (minMaxData != null) { for (int i = 0; i < minMaxData.length; i++) { tableData[tableDataIdx] = minMaxData[i]; tableDataIdx++; } } if (secondData != null) { for (int i = 0; i < secondData.length; i++) { tableData[tableDataIdx] = secondData[i]; tableDataIdx++; } } if (binningInfo != null) { for (int i = 0; i < binningInfo.length; i++) { tableData[tableDataIdx] = binningInfo[i]; tableDataIdx++; } } if (histogramStats != null) { for (int i = 0; i < histogramStats.length; i++) { tableData[tableDataIdx] = histogramStats[i]; tableDataIdx++; } } if (percentData != null) { for (int i = 0; i < percentData.length; i++) { tableData[tableDataIdx] = percentData[i]; tableDataIdx++; } } numStxFields = tableData.length; int fieldIdx = 0; // Initialize indices if (stxIdx == 0) { primaryStatisticsFieldsHashMap.put(PrimaryStatisticsFields.FileRefNum, fieldIdx); fieldIdx++; primaryStatisticsFieldsHashMap.put(PrimaryStatisticsFields.BandName, fieldIdx); fieldIdx++; primaryStatisticsFieldsHashMap.put(PrimaryStatisticsFields.MaskName, fieldIdx); fieldIdx++; primaryStatisticsFieldsHashMap.put(PrimaryStatisticsFields.QualityMaskName, fieldIdx); fieldIdx++; stxFieldsStartIdx = fieldIdx; fieldIdx += numStxFields; stxFieldsEndIdx = fieldIdx - 1; if (includeBandMetaData) { if (includeColumnBreaks) { metaDataFieldsHashMap.put(MetaDataFields.BandMetaDataBreak, fieldIdx); fieldIdx++; } metaDataFieldsHashMap.put(MetaDataFields.BandName, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.BandUnit, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.BandValidExpression, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.BandDescription, fieldIdx); fieldIdx++; } if (includeMaskMetaData) { if (includeColumnBreaks) { metaDataFieldsHashMap.put(MetaDataFields.RegionalMaskMetaDataBreak, fieldIdx); fieldIdx++; } metaDataFieldsHashMap.put(MetaDataFields.RegionalMaskName, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.RegionalMaskDescription, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.RegionalMaskExpression, fieldIdx); fieldIdx++; if (includeColumnBreaks) { metaDataFieldsHashMap.put(MetaDataFields.QualityMaskMetaDataBreak, fieldIdx); fieldIdx++; } metaDataFieldsHashMap.put(MetaDataFields.QualityMaskName, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.QualityMaskDescription, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.QualityMaskExpression, fieldIdx); fieldIdx++; } if (includeTimeMetaData || isIncludeTimeSeriesMetaData) { if (includeColumnBreaks) { metaDataFieldsHashMap.put(MetaDataFields.TimeMetaDataBreak, fieldIdx); fieldIdx++; } if (includeTimeMetaData) { metaDataFieldsHashMap.put(MetaDataFields.StartDate, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.StartTime, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.EndDate, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.EndTime, fieldIdx); fieldIdx++; } if (isIncludeTimeSeriesMetaData) { metaDataFieldsHashMap.put(MetaDataFields.TimeSeriesDate, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.TimeSeriesTime, fieldIdx); fieldIdx++; } } if (includeFileMetaData) { if (includeColumnBreaks) { metaDataFieldsHashMap.put(MetaDataFields.FileMetaDataBreak, fieldIdx); fieldIdx++; } metaDataFieldsHashMap.put(MetaDataFields.FileName, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.FileType, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.FileFormat, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.FileWidth, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.FileHeight, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.Sensor, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.Platform, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.Resolution, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.DayNight, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.Orbit, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.ProcessingVersion, fieldIdx); fieldIdx++; metaDataFieldsHashMap.put(MetaDataFields.Projection, fieldIdx); fieldIdx++; } if (includeProjectionParameters) { metaDataFieldsHashMap.put(MetaDataFields.ProjectionParameters, fieldIdx); fieldIdx++; } } if (statsSpreadsheet == null) { statsSpreadsheet = new Object[numStxRegions + 2][fieldIdx]; // add 1 row to account for the header and 1 more empty row because JTable for some reason displays // only half of the last row when row count is large } String startDateString = ""; String startTimeString = ""; String endDateString = ""; String endTimeString = ""; if (includeTimeMetaData) { ProductData.UTC startDateTimeCorrected; ProductData.UTC endDateTimeCorrected; // correct time (invert start and end time if end time later than start time if (getProduct().getStartTime() != null && getProduct().getEndTime() != null) { if (getProduct().getStartTime().getMJD() <= getProduct().getEndTime().getMJD()) { startDateTimeCorrected = getProduct().getStartTime(); endDateTimeCorrected = getProduct().getEndTime(); } else { startDateTimeCorrected = getProduct().getEndTime(); endDateTimeCorrected = getProduct().getStartTime(); } if (startDateTimeCorrected != null) { String[] startDateTimeStringArray = startDateTimeCorrected.toString().split(" "); if (startDateTimeStringArray.length >= 2) { startDateString = startDateTimeStringArray[0].trim(); startTimeString = startDateTimeStringArray[1].trim(); } } if (endDateTimeCorrected != null) { String[] endDateTimeStringArray = endDateTimeCorrected.toString().split(" "); if (endDateTimeStringArray.length >= 2) { endDateString = endDateTimeStringArray[0].trim(); endTimeString = endDateTimeStringArray[1].trim(); } } } } String timeSeriesDate = ""; String timeSeriesTime = ""; if (isIncludeTimeSeriesMetaData) { String bandName = raster.getName(); String productDateTime = convertBandNameToProductTime(bandName); if (productDateTime != null) { String[] endDateTimeStringArray = productDateTime.split(" "); if (endDateTimeStringArray.length >= 2) { timeSeriesDate = endDateTimeStringArray[0].trim(); timeSeriesTime = endDateTimeStringArray[1].trim(); } } } String maskName = ""; String maskDescription = ""; String maskExpression = ""; if (regionalMask != null) { maskName = regionalMask.getName(); maskDescription = regionalMask.getDescription(); maskExpression = regionalMask.getImageConfig().getValue("expression"); } String qualityMaskName = ""; String qualityMaskDescription = ""; String qualityMaskExpression = ""; if (qualityMask != null) { qualityMaskName = qualityMask.getName(); qualityMaskDescription = qualityMask.getDescription(); qualityMaskExpression = qualityMask.getImageConfig().getValue("expression"); } addFieldToSpreadsheet(row, PrimaryStatisticsFields.FileRefNum, getProduct().getRefNo()); addFieldToSpreadsheet(row, PrimaryStatisticsFields.BandName, raster.getName()); addFieldToSpreadsheet(row, PrimaryStatisticsFields.MaskName, maskName); addFieldToSpreadsheet(row, PrimaryStatisticsFields.QualityMaskName, qualityMaskName); addFieldToSpreadsheet(row, MetaDataFields.TimeMetaDataBreak, COLUMN_BREAK); addFieldToSpreadsheet(row, MetaDataFields.StartDate, startDateString); addFieldToSpreadsheet(row, MetaDataFields.StartTime, startTimeString); addFieldToSpreadsheet(row, MetaDataFields.EndDate, endDateString); addFieldToSpreadsheet(row, MetaDataFields.EndTime, endTimeString); addFieldToSpreadsheet(row, MetaDataFields.TimeSeriesDate, timeSeriesDate); addFieldToSpreadsheet(row, MetaDataFields.TimeSeriesTime, timeSeriesTime); addFieldToSpreadsheet(row, MetaDataFields.FileMetaDataBreak, COLUMN_BREAK); addFieldToSpreadsheet(row, MetaDataFields.FileName, getProduct().getName()); addFieldToSpreadsheet(row, MetaDataFields.FileType, getProduct().getProductType()); addFieldToSpreadsheet(row, MetaDataFields.FileWidth, getProduct().getSceneRasterWidth()); addFieldToSpreadsheet(row, MetaDataFields.FileFormat, getProductFormatName(getProduct())); addFieldToSpreadsheet(row, MetaDataFields.FileHeight, getProduct().getSceneRasterHeight()); addFieldToSpreadsheet(row, MetaDataFields.Sensor, ProductUtils.getMetaData(getProduct(), ProductUtils.METADATA_POSSIBLE_SENSOR_KEYS)); addFieldToSpreadsheet(row, MetaDataFields.Platform, ProductUtils.getMetaData(getProduct(), ProductUtils.METADATA_POSSIBLE_PLATFORM_KEYS)); addFieldToSpreadsheet(row, MetaDataFields.Resolution, ProductUtils.getMetaData(getProduct(), ProductUtils.METADATA_POSSIBLE_RESOLUTION_KEYS)); addFieldToSpreadsheet(row, MetaDataFields.DayNight, ProductUtils.getMetaData(getProduct(), ProductUtils.METADATA_POSSIBLE_DAY_NIGHT_KEYS)); addFieldToSpreadsheet(row, MetaDataFields.Orbit, ProductUtils.getMetaDataOrbit(getProduct())); addFieldToSpreadsheet(row, MetaDataFields.ProcessingVersion, ProductUtils.getMetaData(getProduct(), ProductUtils.METADATA_POSSIBLE_PROCESSING_VERSION_KEYS)); // Determine projection String projection = ""; String projectionParameters = ""; GeoCoding geo = getProduct().getGeoCoding(); // determine if using class CrsGeoCoding otherwise display class if (geo != null) { if (geo instanceof CrsGeoCoding) { projection = geo.getMapCRS().getName().toString() + "(obtained from CrsGeoCoding)"; projectionParameters = geo.getMapCRS().toString().replaceAll("\n", " ").replaceAll(" ", ""); } else if (geo.toString() != null) { String projectionFromMetaData = ProductUtils.getMetaData(getProduct(), ProductUtils.METADATA_POSSIBLE_PROJECTION_KEYS); if (projectionFromMetaData != null && projectionFromMetaData.length() > 0) { projection = projectionFromMetaData + "(obtained from MetaData)"; } else { projection = "unknown (" + geo.getClass().toString() + ")"; } } } addFieldToSpreadsheet(row, MetaDataFields.Projection, projection); addFieldToSpreadsheet(row, MetaDataFields.ProjectionParameters, projectionParameters); addFieldToSpreadsheet(row, MetaDataFields.BandMetaDataBreak, COLUMN_BREAK); addFieldToSpreadsheet(row, MetaDataFields.BandName, raster.getName()); addFieldToSpreadsheet(row, MetaDataFields.BandUnit, raster.getUnit()); addFieldToSpreadsheet(row, MetaDataFields.BandValidExpression, raster.getValidPixelExpression()); addFieldToSpreadsheet(row, MetaDataFields.BandDescription, raster.getDescription()); addFieldToSpreadsheet(row, MetaDataFields.RegionalMaskMetaDataBreak, COLUMN_BREAK); addFieldToSpreadsheet(row, MetaDataFields.RegionalMaskName, maskName); addFieldToSpreadsheet(row, MetaDataFields.RegionalMaskDescription, maskDescription); addFieldToSpreadsheet(row, MetaDataFields.RegionalMaskExpression, maskExpression); addFieldToSpreadsheet(row, MetaDataFields.QualityMaskMetaDataBreak, COLUMN_BREAK); addFieldToSpreadsheet(row, MetaDataFields.QualityMaskName, qualityMaskName); addFieldToSpreadsheet(row, MetaDataFields.QualityMaskDescription, qualityMaskDescription); addFieldToSpreadsheet(row, MetaDataFields.QualityMaskExpression, qualityMaskExpression); // Add Header first time through if (row <= 1) { int k = stxFieldsStartIdx; for (int i = 0; i < tableData.length; i++) { Object value = tableData[i][0]; if (k < statsSpreadsheet[0].length && k <= stxFieldsEndIdx) { statsSpreadsheet[0][k] = value; k++; } } } // account for header as added row if (row < statsSpreadsheet.length) { int k = stxFieldsStartIdx; for (int i = 0; i < tableData.length; i++) { Object value = tableData[i][1]; if (k < statsSpreadsheet[row].length && k <= stxFieldsEndIdx) { statsSpreadsheet[row][k] = value; k++; } } } int numPlots = 0; if (statisticsCriteriaPanel.showPercentPlots()) { numPlots++; } if (statisticsCriteriaPanel.showHistogramPlots()) { numPlots++; } JPanel plotContainerPanel = null; if (numPlots > 0) { plotContainerPanel = new JPanel(new GridLayout(1, numPlots)); if (statisticsCriteriaPanel.showHistogramPlots()) { plotContainerPanel.add(histogramPanel); } if (statisticsCriteriaPanel.showPercentPlots()) { plotContainerPanel.add(percentilePanel); } } TableModel tableModel = new DefaultTableModel(tableData, new String[] { "Name", "Value" }) { @Override public Class<?> getColumnClass(int columnIndex) { return columnIndex == 0 ? String.class : Number.class; } @Override public boolean isCellEditable(int row, int column) { return false; } }; final JTable table = new JTable(tableModel); table.setDefaultRenderer(Number.class, new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { final Component label = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); if (value instanceof Float || value instanceof Double) { setHorizontalTextPosition(RIGHT); setText(getFormattedValue((Number) value)); } return label; } private String getFormattedValue(Number value) { if (value.doubleValue() < 0.001 && value.doubleValue() > -0.001 && value.doubleValue() != 0.0) { return new DecimalFormat("0.####E0").format(value.doubleValue()); } String format = "%." + Integer.toString(statisticsCriteriaPanel.decimalPlaces()) + "f"; return String.format(format, value.doubleValue()); } }); table.addMouseListener(popupHandler); // TEST CODE generically preferred size of each column based on longest expected entry // fails a bit because decimal formatting is not captured // stub of code commented out in case we want to make it work // meanwhile longest entry is being used SEE below // int column0Length = 0; // int column1Length = 0; // FontMetrics fm = table.getFontMetrics(table.getFont()); // for (int rowIndex = 0; rowIndex < table.getRowCount(); rowIndex++) { // String test = table.getValueAt(rowIndex,0).toString(); // int currColumn0Length = fm.stringWidth(table.getValueAt(rowIndex,0).toString()); // if (currColumn0Length > column0Length) { // column0Length = currColumn0Length; // } // // String test2 = table.getValueAt(rowIndex,1).toString(); // int currColumn1Length = fm.stringWidth(table.getValueAt(rowIndex,1).toString()); // if (currColumn1Length > column1Length) { // column1Length = currColumn1Length; // } // } // Set preferred size of each column based on longest expected entry FontMetrics fm = table.getFontMetrics(table.getFont()); TableColumn column = null; int col1PreferredWidth = -1; if (statisticsCriteriaPanel.isLogMode()) { col1PreferredWidth = fm.stringWidth("StandardDeviation(LogBinned):") + 10; } else { col1PreferredWidth = fm.stringWidth("StandardDeviation(Binned):") + 10; } // int col1PreferredWidth = fm.stringWidth("wwwwwwwwwwwwwwwwwwwwwwwwww"); int col2PreferredWidth = fm.stringWidth("1234567890") + 10; int tablePreferredWidth = col1PreferredWidth + col2PreferredWidth; for (int i = 0; i < 2; i++) { column = table.getColumnModel().getColumn(i); if (i == 0) { column.setPreferredWidth(col1PreferredWidth); column.setMaxWidth(col1PreferredWidth); } else { column.setPreferredWidth(col2PreferredWidth); } } JPanel textContainerPanel = new JPanel(new BorderLayout(2, 2)); // textContainerPanel.setBackground(Color.WHITE); textContainerPanel.add(table, BorderLayout.CENTER); textContainerPanel.addMouseListener(popupHandler); JPanel statsPane = GridBagUtils.createPanel(); GridBagConstraints gbc = GridBagUtils.createConstraints(""); gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.NORTHWEST; gbc.weightx = 1; gbc.weighty = 1; Dimension dim = table.getPreferredSize(); table.setPreferredSize(new Dimension(tablePreferredWidth, dim.height)); statsPane.add(table, gbc); statsPane.setPreferredSize(new Dimension(tablePreferredWidth, dim.height)); JPanel plotsPane = null; if (plotContainerPanel != null) { plotsPane = GridBagUtils.createPanel(); plotsPane.setBackground(Color.WHITE); // plotsPane.setBorder(UIUtils.createGroupBorder(" ")); /*I18N*/ GridBagConstraints gbcPlots = GridBagUtils.createConstraints(""); gbcPlots.gridy = 0; if (statisticsCriteriaPanel.exactPlotSize()) { gbcPlots.fill = GridBagConstraints.NONE; } else { gbcPlots.fill = GridBagConstraints.BOTH; } gbcPlots.anchor = GridBagConstraints.NORTHWEST; gbcPlots.weightx = 0.5; gbcPlots.weighty = 1; plotsPane.add(plotContainerPanel, gbcPlots); } JPanel mainPane = GridBagUtils.createPanel(); mainPane.setBorder(UIUtils.createGroupBorder(getSubPanelTitle(regionalMask, qualityMask, raster))); /*I18N*/ GridBagConstraints gbcMain = GridBagUtils.createConstraints(""); gbcMain.gridx = 0; gbcMain.gridy = 0; gbcMain.anchor = GridBagConstraints.NORTHWEST; if (plotsPane != null) { gbcMain.fill = GridBagConstraints.VERTICAL; gbcMain.weightx = 0; } else { gbcMain.fill = GridBagConstraints.BOTH; gbcMain.weightx = 1; } if (statisticsCriteriaPanel.showStatsList()) { gbcMain.weighty = 1; mainPane.add(statsPane, gbcMain); gbcMain.gridx++; } gbcMain.weightx = 1; gbcMain.weighty = 1; gbcMain.fill = GridBagConstraints.BOTH; if (plotsPane != null) { mainPane.add(plotsPane, gbcMain); } return mainPane; }