Example usage for javax.swing JTextPane setBackground

List of usage examples for javax.swing JTextPane setBackground

Introduction

In this page you can find the example usage for javax.swing JTextPane setBackground.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The background color of the component.")
public void setBackground(Color bg) 

Source Link

Document

Sets the background color of this component.

Usage

From source file:Main.java

private static Component blackJTextPane() {
    JTextPane pane = new JTextPane();
    pane.setBackground(Color.BLACK);
    pane.setForeground(Color.WHITE);
    pane.setText("Here is example text");
    return pane;//  w  ww. j a  v  a 2s. c  o  m
}

From source file:Main.java

/**
 * Creates a new <code>JTextPane</code> object with the given properties.
 *
 * @param text The text which will appear in the text pane
 * @param backgroundColor The background color
 * @return A <code>JTextPane</code> object
 *///from   ww w. j  av  a  2 s. c o  m
public static JTextPane createJTextPane(String text, Color backgroundColor) {
    JTextPane jTextPane = new JTextPane();
    jTextPane.setBorder(null);
    jTextPane.setEditable(false);
    jTextPane.setBackground(backgroundColor);
    jTextPane.setFont(new Font("Times New Roman", Font.PLAIN, 14));
    if (text != null) {
        jTextPane.setText(text);
    }
    jTextPane.setVerifyInputWhenFocusTarget(false);
    jTextPane.setAutoscrolls(false);
    return jTextPane;
}

From source file:com.awesomecoding.minetestlauncher.Main.java

private void initialize() {
    fileGetter = new FileGetter(userhome + "\\minetest\\temp\\");
    latest = fileGetter.getContents("http://socialmelder.com/minetest/latest.txt", true);
    currentVersion = latest.split("\n")[0];
    changelog = fileGetter.getContents("http://socialmelder.com/minetest/changelog.html", false);

    try {/*from  w  w w. j a v a2  s .  c  om*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {
        e.printStackTrace();
    }

    frmMinetestLauncherV = new JFrame();
    frmMinetestLauncherV.setResizable(false);
    frmMinetestLauncherV.setIconImage(Toolkit.getDefaultToolkit()
            .getImage(Main.class.getResource("/com/awesomecoding/minetestlauncher/icon.png")));
    frmMinetestLauncherV.setTitle("Minetest Launcher (Version 0.1)");
    frmMinetestLauncherV.setBounds(100, 100, 720, 480);
    frmMinetestLauncherV.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout springLayout = new SpringLayout();
    frmMinetestLauncherV.getContentPane().setLayout(springLayout);

    final JProgressBar progressBar = new JProgressBar();
    springLayout.putConstraint(SpringLayout.WEST, progressBar, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, progressBar, -10, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.EAST, progressBar, -130, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(progressBar);

    final JButton btnDownloadPlay = new JButton("Play!");
    springLayout.putConstraint(SpringLayout.WEST, btnDownloadPlay, 6, SpringLayout.EAST, progressBar);
    springLayout.putConstraint(SpringLayout.SOUTH, btnDownloadPlay, 0, SpringLayout.SOUTH, progressBar);
    springLayout.putConstraint(SpringLayout.EAST, btnDownloadPlay, -10, SpringLayout.EAST,
            frmMinetestLauncherV.getContentPane());
    frmMinetestLauncherV.getContentPane().add(btnDownloadPlay);

    final JLabel label = new JLabel("Ready to play!");
    springLayout.putConstraint(SpringLayout.WEST, label, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, btnDownloadPlay, 0, SpringLayout.NORTH, label);
    springLayout.putConstraint(SpringLayout.SOUTH, label, -37, SpringLayout.SOUTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.NORTH, progressBar, 6, SpringLayout.SOUTH, label);
    frmMinetestLauncherV.getContentPane().add(label);

    JTextPane txtpnNewFeatures = new JTextPane();
    txtpnNewFeatures.setBackground(SystemColor.window);
    springLayout.putConstraint(SpringLayout.NORTH, txtpnNewFeatures, 10, SpringLayout.NORTH,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.WEST, txtpnNewFeatures, 10, SpringLayout.WEST,
            frmMinetestLauncherV.getContentPane());
    springLayout.putConstraint(SpringLayout.SOUTH, txtpnNewFeatures, -10, SpringLayout.NORTH, btnDownloadPlay);
    springLayout.putConstraint(SpringLayout.EAST, txtpnNewFeatures, 0, SpringLayout.EAST, btnDownloadPlay);
    txtpnNewFeatures.setEditable(false);
    txtpnNewFeatures.setContentType("text/html");
    txtpnNewFeatures.setText(changelog);
    txtpnNewFeatures.setFont(new Font("Tahoma", Font.PLAIN, 12));
    frmMinetestLauncherV.getContentPane().add(txtpnNewFeatures);

    File file = new File(userhome + "\\minetest\\version.txt");

    if (!file.exists())
        newVersion = true;
    else {
        String version = fileGetter.getLocalContents(file, false);
        if (!version.equals(currentVersion))
            newVersion = true;
    }

    if (newVersion) {
        label.setText("New Version Available! (" + currentVersion + ")");
        btnDownloadPlay.setText("Download & Play");

        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                Thread t = new Thread() {
                    public void run() {
                        File file = new File(userhome + "\\minetest\\version.txt");
                        String version = fileGetter.getLocalContents(file, false);
                        try {
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\minetest-" + version));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        fileGetter.download(latest.split("\n")[1], userhome + "\\minetest\\temp\\",
                                "minetest.zip", label, progressBar, btnDownloadPlay, currentVersion);
                        try {
                            label.setText("Cleaning up...");
                            btnDownloadPlay.setText("Cleaning up...");
                            FileUtils.deleteDirectory(new File(userhome + "\\minetest\\temp"));
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                        System.exit(0);
                    }
                };
                t.start();
            }
        });
    } else {
        btnDownloadPlay.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                try {
                    label.setText("Launching...");
                    btnDownloadPlay.setEnabled(false);
                    btnDownloadPlay.setText("Launching...");
                    File file = new File(userhome + "\\minetest\\version.txt");
                    String version = fileGetter.getLocalContents(file, false);
                    Runtime.getRuntime()
                            .exec(userhome + "\\minetest\\minetest-" + version + "\\bin\\minetest.exe");
                    System.exit(0);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
        progressBar.setValue(100);
    }
}

From source file:com.hp.alm.ali.idea.content.settings.SettingsPanel.java

private JTextPane createTextPane(Color bgColor) {
    JTextPane pane = new JTextPane();
    pane.setEditable(false);//from  www  .j  av a 2 s  .c  o  m
    pane.setBackground(bgColor);
    pane.setCaret(new NonAdjustingCaret());
    return pane;
}

From source file:com.ethercamp.harmony.desktop.HarmonyDesktop.java

private void showErrorWindow(String title, String body) {
    try {/*from w ww . j a  v a  2 s . co  m*/
        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        //            System.setProperty("apple.awt.UIElement", "false");

        JPanel panel = new JPanel();
        panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));

        JTextArea textArea = new JTextArea(body);
        JScrollPane scrollPane = new JScrollPane(textArea);
        textArea.setLineWrap(true);
        textArea.setFont(Font.getFont(Font.MONOSPACED));
        textArea.setEditable(false);
        textArea.setWrapStyleWord(true);
        scrollPane.setPreferredSize(new Dimension(500, 500));

        JTextPane titleLabel = new JTextPane();
        titleLabel.setContentType("text/html"); // let the text pane know this is what you want
        titleLabel.setText("<html>" + "<b>" + title + "</b>" + "</html>"); // showing off
        titleLabel.setEditable(false);
        titleLabel.setBackground(null);
        titleLabel.setBorder(null);

        panel.add(titleLabel);
        panel.add(scrollPane);

        final JFrame frame = new JFrame();
        frame.setAlwaysOnTop(true);
        moveCenter(frame);
        frame.setVisible(true);

        JOptionPane.showMessageDialog(frame, panel, "Oops. Ethereum Harmony stopped with error.",
                JOptionPane.CLOSED_OPTION);
        System.exit(1);
    } catch (Exception e) {
        log.error("Problem showing error window", e);
    }
}

From source file:com.hp.alm.ali.idea.content.settings.SettingsPanel.java

public SettingsPanel(final Project prj, Color bgColor) {
    this.prj = prj;
    this.projectConf = prj.getComponent(AliProjectConfiguration.class);

    previewAndConnection = new JPanel(new GridBagLayout());
    previewAndConnection.setOpaque(false);
    GridBagConstraints c2 = new GridBagConstraints();
    c2.gridx = 0;//from w ww .  j a v a 2  s  .c o  m
    c2.gridy = 1;
    c2.gridwidth = 2;
    c2.weighty = 1;
    c2.fill = GridBagConstraints.VERTICAL;
    JPanel filler = new JPanel();
    filler.setOpaque(false);
    previewAndConnection.add(filler, c2);

    passwordPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    passwordPanel.setBackground(bgColor);
    JLabel label = new JLabel("Password");
    label.setFont(label.getFont().deriveFont(Font.BOLD));
    passwordPanel.add(label);
    final JPasswordField password = new JPasswordField(24);
    passwordPanel.add(password);
    JButton connect = new JButton("Login");
    passwordPanel.add(connect);
    final JLabel message = new JLabel();
    passwordPanel.add(message);
    ActionListener connectionAction = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            try {
                checkConnection(projectConf.getLocation(), projectConf.getDomain(), projectConf.getProject(),
                        projectConf.getUsername(), password.getText());
            } catch (AuthenticationFailed e) {
                message.setText(e.getMessage());
                return;
            }
            projectConf.ALM_PASSWORD = password.getText();
            projectConf.fireChanged();
        }
    };
    password.addActionListener(connectionAction);
    connect.addActionListener(connectionAction);

    restService = prj.getComponent(RestService.class);
    restService.addServerTypeListener(this);

    location = createTextPane(bgColor);
    domain = createTextPane(bgColor);
    project = createTextPane(bgColor);
    username = createTextPane(bgColor);

    final JPanel panel = new JPanel(new BorderLayout());
    panel.setBackground(bgColor);
    panel.setBorder(new EmptyBorder(10, 10, 10, 10));

    final JTextPane textPane = new JTextPane();
    textPane.setEditorKit(new HTMLEditorKit());
    textPane.setText(
            "<html><body>HP ALM integration can be configured on <a href=\"ide\">IDE</a> and overridden on <a href=\"project\">project</a> level.</body></html>");
    textPane.setEditable(false);
    textPane.addHyperlinkListener(this);
    textPane.setBackground(bgColor);
    textPane.setCaret(new NonAdjustingCaret());
    panel.add(textPane, BorderLayout.CENTER);

    JPanel content = new JPanel(new BorderLayout());
    content.setBackground(bgColor);
    content.add(panel, BorderLayout.NORTH);
    content.add(previewAndConnection, BorderLayout.WEST);

    preview = new JPanel(new GridBagLayout()) {
        public Dimension getPreferredSize() {
            Dimension dim = super.getPreferredSize();
            // make enough room for the connection status message
            dim.width = Math.max(dim.width, 300);
            return dim;
        }

        public Dimension getMinimumSize() {
            return getPreferredSize();
        }
    };
    connectedTo(restService.getServerTypeIfAvailable());
    preview.setBackground(bgColor);

    final GridBagConstraints c = new GridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = 2;
    c.anchor = GridBagConstraints.WEST;
    preview.add(location, c);
    c.gridwidth = 1;
    c.gridy++;
    preview.add(domain, c);
    c.gridy++;
    preview.add(project, c);
    c.gridy++;
    preview.add(username, c);
    c.gridx++;
    c.gridy--;
    c.gridheight = 2;
    c.weightx = 0;
    c.anchor = GridBagConstraints.SOUTHEAST;
    final LinkLabel reload = new LinkLabel("Reload", IconLoader.getIcon("/actions/sync.png"));
    reload.setListener(new LinkListener() {
        public void linkSelected(LinkLabel linkLabel, Object o) {
            projectConf.fireChanged();
        }
    }, null);
    preview.add(reload, c);

    JPanel previewNorth = new JPanel(new BorderLayout());
    previewNorth.setBackground(bgColor);
    previewNorth.add(preview, BorderLayout.NORTH);

    addToGridBagPanel(0, 0, previewAndConnection, previewNorth);

    setBackground(bgColor);
    setLayout(new BorderLayout());
    add(content, BorderLayout.CENTER);

    onChanged();
    ApplicationManager.getApplication().getComponent(AliConfiguration.class).addListener(this);
    projectConf.addListener(this);
}

From source file:logdruid.ui.DateEditor.java

/**
 * Create the panel.//from   w  ww. j  av a  2  s .  c  om
 */
public DateEditor(Repository rep) {
    repository = rep;
    model = new MyTableModel2(data, header);

    GridBagLayout gridBagLayout = new GridBagLayout();
    gridBagLayout.columnWidths = new int[] { 15, 550, 15 };
    gridBagLayout.rowHeights = new int[] { 152, 300 };
    gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0 };
    gridBagLayout.rowWeights = new double[] { 0.0, 1.0 };
    setLayout(gridBagLayout);

    JPanel panel_1 = new JPanel();
    GridBagConstraints gbc_panel_1 = new GridBagConstraints();
    gbc_panel_1.fill = GridBagConstraints.BOTH;
    gbc_panel_1.insets = new Insets(5, 0, 5, 5);
    gbc_panel_1.gridx = 1;
    gbc_panel_1.gridy = 0;
    add(panel_1, gbc_panel_1);
    panel_1.setLayout(new BorderLayout(0, 0));

    table = new JTable(model);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setBorder(UIManager.getBorder("TextPane.border"));
    table.setPreferredScrollableViewportSize(new Dimension(0, 0));
    table.setFillsViewportHeight(true);

    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            // ((table.getSelectedRow()!=-1)?table.convertRowIndexToModel(table.getSelectedRow()):-1)
            // persist repository
            // display selected row

            if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1) >= 0) {
                /*
                 * recEditor = new RecordingEditor(repository
                 * .getRecordings().get(((table.getSelectedRow()!=-1)?table.
                 * convertRowIndexToModel(table.getSelectedRow()):-1)),
                 * repository); jPanelDetail.removeAll();
                 */
                // jPanelDetail.add(recEditor, gbc_jPanelDetail);
                DateFormat df = repository.getDateFormat(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                if (df != null) {
                    textFieldName.setText((String) df.getName());
                    textFieldPattern.setText((String) df.getPattern());
                    textField.setText((String) df.getDateFormat());
                }
                // jPanelDetail.revalidate();
                // jPanelDetail.repaint();
                // jPanelDetail.setVisible(true);
                // reloadTable(); those 2 ********
                // jPanelDetail.revalidate();
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    panel_1.add(scrollPane, BorderLayout.CENTER);
    // Set up column sizes.
    initColumnSizes(table);

    JPanel panel = new JPanel();
    FlowLayout flowLayout = (FlowLayout) panel.getLayout();
    flowLayout.setAlignment(FlowLayout.LEFT);
    flowLayout.setVgap(2);
    flowLayout.setHgap(2);
    panel_1.add(panel, BorderLayout.SOUTH);

    JButton btnNew = new JButton("New");
    panel.add(btnNew);
    btnNew.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            DateFormat df = new DateFormat("name", "\\w{3}\\s[0-9]{1}/[0-9]{2}/[0-9]{2}\\s\\d\\d:\\d\\d:\\d\\d",
                    "EEE. MM/dd/yy HH:mm:ss");
            repository.addDateFormat(df);
            data.add(new Object[] { df.getName(), df.getPattern(), df.getDateFormat() });
            table.repaint();
        }
    });

    JButton btnDuplicate = new JButton("Duplicate");
    btnDuplicate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            if (((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1) >= 0) {
                DateFormat df = repository.getDateFormat(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                repository.addDateFormat(df);
                reloadTable();
                // data.add(new Object[] { table.getRowCount()+1,
                // df.getName(),df.getDateFormat()});
                table.repaint();
            }
        }
    });
    panel.add(btnDuplicate);

    JButton btnDelete = new JButton("Delete");
    btnDelete.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int selectedRow = ((table.getSelectedRow() != -1)
                    ? table.convertRowIndexToModel(table.getSelectedRow())
                    : -1);
            if (selectedRow >= 0) {
                repository.deleteDateFormat(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                data.remove(
                        ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                                : -1));
                reloadTable();
                table.setRowSelectionInterval(selectedRow, selectedRow);
                table.repaint();
            }
        }
    });
    panel.add(btnDelete);

    jPanelDetail = new JPanel();
    gbc_jPanelDetail = new GridBagConstraints();
    gbc_jPanelDetail.anchor = GridBagConstraints.NORTH;
    gbc_jPanelDetail.fill = GridBagConstraints.HORIZONTAL;
    gbc_jPanelDetail.gridx = 1;
    gbc_jPanelDetail.gridy = 1;
    add(jPanelDetail, gbc_jPanelDetail);
    GridBagLayout gbl_jPanelDetail = new GridBagLayout();
    gbl_jPanelDetail.columnWidths = new int[] { 169 };
    gbl_jPanelDetail.rowHeights = new int[] { 0, 0, 0, 0, 150, 0 };
    gbl_jPanelDetail.columnWeights = new double[] { 1.0, 0.0 };
    gbl_jPanelDetail.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, 1.0, 0.0 };
    jPanelDetail.setLayout(gbl_jPanelDetail);

    JPanel panel_2 = new JPanel();
    panel_2.setBorder(null);
    GridBagConstraints gbc_panel_2 = new GridBagConstraints();
    gbc_panel_2.gridwidth = 2;
    gbc_panel_2.anchor = GridBagConstraints.NORTHWEST;
    gbc_panel_2.insets = new Insets(0, 0, 5, 0);
    gbc_panel_2.gridx = 0;
    gbc_panel_2.gridy = 0;
    jPanelDetail.add(panel_2, gbc_panel_2);
    panel_2.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));

    JLabel label = new JLabel("Name");
    panel_2.add(label);

    textFieldName = new JTextField();
    textFieldName.setColumns(20);
    panel_2.add(textFieldName);

    JPanel panel_3 = new JPanel();
    FlowLayout flowLayout_1 = (FlowLayout) panel_3.getLayout();
    flowLayout_1.setAlignment(FlowLayout.LEFT);
    panel_3.setBorder(null);
    GridBagConstraints gbc_panel_3 = new GridBagConstraints();
    gbc_panel_3.insets = new Insets(0, 0, 5, 0);
    gbc_panel_3.gridwidth = 2;
    gbc_panel_3.anchor = GridBagConstraints.NORTHWEST;
    gbc_panel_3.gridx = 0;
    gbc_panel_3.gridy = 1;
    jPanelDetail.add(panel_3, gbc_panel_3);

    labelPattern = new JLabel("Pattern");
    panel_3.add(labelPattern);

    textFieldPattern = new JTextField();
    textFieldPattern.setColumns(40);
    panel_3.add(textFieldPattern);

    JButton btnSave = new JButton("Save");
    btnSave.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DateFormat df1 = repository.getDateFormat(
                    ((table.getSelectedRow() != -1) ? table.convertRowIndexToModel(table.getSelectedRow())
                            : -1));
            df1.update(textFieldName.getText(), textFieldPattern.getText(), textField.getText());
            reloadTable();
        }
    });

    JPanel panel_4 = new JPanel();
    FlowLayout flowLayout_2 = (FlowLayout) panel_4.getLayout();
    flowLayout_2.setAlignment(FlowLayout.LEFT);
    GridBagConstraints gbc_panel_4 = new GridBagConstraints();
    gbc_panel_4.anchor = GridBagConstraints.WEST;
    gbc_panel_4.insets = new Insets(0, 0, 5, 5);
    gbc_panel_4.gridx = 0;
    gbc_panel_4.gridy = 2;
    jPanelDetail.add(panel_4, gbc_panel_4);

    JLabel lblFastDateFormat = new JLabel("FastDateFormat");
    panel_4.add(lblFastDateFormat);

    textField = new JTextField();
    panel_4.add(textField);
    textField.setColumns(30);

    JPanel panel_5 = new JPanel();
    FlowLayout flowLayout_3 = (FlowLayout) panel_5.getLayout();
    flowLayout_3.setAlignment(FlowLayout.LEFT);
    GridBagConstraints gbc_panel_5 = new GridBagConstraints();
    gbc_panel_5.insets = new Insets(0, 0, 5, 5);
    gbc_panel_5.fill = GridBagConstraints.BOTH;
    gbc_panel_5.gridx = 0;
    gbc_panel_5.gridy = 3;
    jPanelDetail.add(panel_5, gbc_panel_5);

    JLabel lblSampleLabel = new JLabel("Sample");
    panel_5.add(lblSampleLabel);

    JPanel panel_6 = new JPanel();
    panel_6.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
    GridBagConstraints gbc_panel_6 = new GridBagConstraints();
    gbc_panel_6.ipady = 1;
    gbc_panel_6.ipadx = 1;
    gbc_panel_6.insets = new Insets(0, 0, 5, 5);
    gbc_panel_6.fill = GridBagConstraints.BOTH;
    gbc_panel_6.gridx = 0;
    gbc_panel_6.gridy = 4;
    jPanelDetail.add(panel_6, gbc_panel_6);
    panel_6.setLayout(new BorderLayout(0, 0));

    JTextPane textPane = new JTextPane();
    textPane.setBackground(UIManager.getColor("windowBorder"));
    panel_6.add(textPane);
    GridBagConstraints gbc_btnSave = new GridBagConstraints();
    gbc_btnSave.anchor = GridBagConstraints.WEST;
    gbc_btnSave.insets = new Insets(0, 0, 0, 5);
    gbc_btnSave.gridx = 0;
    gbc_btnSave.gridy = 5;
    jPanelDetail.add(btnSave, gbc_btnSave);
    reloadTable();
}

From source file:lu.lippmann.cdb.ext.hydviga.ui.GapFillingFrame.java

/**
 * Constructor./*w  w w.  j  av  a  2 s.com*/
 */
public GapFillingFrame(final AbstractTabView atv, final Instances dataSet, final Attribute attr,
        final int dateIdx, final int valuesBeforeAndAfter, final int position, final int gapsize,
        final StationsDataProvider gcp, final boolean inBatchMode) {
    super();

    setTitle("Gap filling for " + attr.name() + " ("
            + dataSet.attribute(dateIdx).formatDate(dataSet.instance(position).value(dateIdx)) + " -> "
            + dataSet.attribute(dateIdx).formatDate(dataSet.instance(position + gapsize).value(dateIdx)) + ")");
    LogoHelper.setLogo(this);

    this.atv = atv;

    this.dataSet = dataSet;
    this.attr = attr;
    this.dateIdx = dateIdx;
    this.valuesBeforeAndAfter = valuesBeforeAndAfter;
    this.position = position;
    this.gapsize = gapsize;

    this.gcp = gcp;

    final Instances testds = WekaDataProcessingUtil.buildFilteredDataSet(dataSet, 0,
            dataSet.numAttributes() - 1, Math.max(0, position - valuesBeforeAndAfter),
            Math.min(position + gapsize + valuesBeforeAndAfter, dataSet.numInstances() - 1));

    this.attrNames = WekaTimeSeriesUtil.getNamesOfAttributesWithoutGap(testds);

    this.isGapSimulated = (this.attrNames.contains(attr.name()));
    this.originaldataSet = new Instances(dataSet);
    if (this.isGapSimulated) {
        setTitle(getTitle() + " [SIMULATED GAP]");
        /*final JXLabel fictiveGapLabel=new JXLabel("                                                                        FICTIVE GAP");
        fictiveGapLabel.setForeground(Color.RED);
        fictiveGapLabel.setFont(new Font(fictiveGapLabel.getFont().getName(), Font.PLAIN,fictiveGapLabel.getFont().getSize()*2));
        final JXPanel fictiveGapPanel=new JXPanel();
        fictiveGapPanel.setLayout(new BorderLayout());
        fictiveGapPanel.add(fictiveGapLabel,BorderLayout.CENTER);
        getContentPane().add(fictiveGapPanel,BorderLayout.NORTH);*/
        this.attrNames.remove(attr.name());
        this.originalDataBeforeGapSimulation = dataSet.attributeToDoubleArray(attr.index());
        for (int i = position; i < position + gapsize; i++)
            dataSet.instance(i).setMissing(attr);
    }

    final Object[] attrNamesObj = this.attrNames.toArray();

    this.centerPanel = new JXPanel();
    this.centerPanel.setLayout(new BorderLayout());
    getContentPane().add(this.centerPanel, BorderLayout.CENTER);

    //final JXPanel algoPanel=new JXPanel();
    //getContentPane().add(algoPanel,BorderLayout.NORTH);
    final JXPanel filterPanel = new JXPanel();
    //filterPanel.setLayout(new BoxLayout(filterPanel, BoxLayout.Y_AXIS));      
    filterPanel.setLayout(new GridBagLayout());
    final GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.insets = new Insets(10, 10, 10, 10);
    getContentPane().add(filterPanel, BorderLayout.WEST);

    final JXComboBox algoCombo = new JXComboBox(Algo.values());
    algoCombo.setBorder(new TitledBorder("Algorithm"));
    filterPanel.add(algoCombo, gbc);
    gbc.gridy++;

    final JXLabel infoLabel = new JXLabel("Usable = with no missing values on the period");
    //infoLabel.setBorder(new TitledBorder(""));
    filterPanel.add(infoLabel, gbc);
    gbc.gridy++;

    final JList<Object> timeSeriesList = new JList<Object>(attrNamesObj);
    timeSeriesList.setBorder(new TitledBorder("Usable time series"));
    timeSeriesList.setSelectionMode(DefaultListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    final JScrollPane jcpMap = new JScrollPane(timeSeriesList);
    jcpMap.setPreferredSize(new Dimension(225, 150));
    jcpMap.setMinimumSize(new Dimension(225, 150));
    filterPanel.add(jcpMap, gbc);
    gbc.gridy++;

    final JXPanel mapPanel = new JXPanel();
    mapPanel.setBorder(new TitledBorder(""));
    mapPanel.setLayout(new BorderLayout());
    mapPanel.add(gcp.getMapPanel(Arrays.asList(attr.name()), this.attrNames, true), BorderLayout.CENTER);
    filterPanel.add(mapPanel, gbc);
    gbc.gridy++;

    final JXLabel mssLabel = new JXLabel(
            "<html>Most similar usable serie: <i>[... computation ...]</i></html>");
    mssLabel.setBorder(new TitledBorder(""));
    filterPanel.add(mssLabel, gbc);
    gbc.gridy++;

    final JXLabel nsLabel = new JXLabel("<html>Nearest usable serie: <i>[... computation ...]</i></html>");
    nsLabel.setBorder(new TitledBorder(""));
    filterPanel.add(nsLabel, gbc);
    gbc.gridy++;

    final JXLabel ussLabel = new JXLabel("<html>Upstream serie: <i>[... computation ...]</i></html>");
    ussLabel.setBorder(new TitledBorder(""));
    filterPanel.add(ussLabel, gbc);
    gbc.gridy++;

    final JXLabel dssLabel = new JXLabel("<html>Downstream serie: <i>[... computation ...]</i></html>");
    dssLabel.setBorder(new TitledBorder(""));
    filterPanel.add(dssLabel, gbc);
    gbc.gridy++;

    final JCheckBox hideOtherSeriesCB = new JCheckBox("Hide the others series");
    hideOtherSeriesCB.setSelected(DEFAULT_HIDE_OTHER_SERIES_OPTION);
    filterPanel.add(hideOtherSeriesCB, gbc);
    gbc.gridy++;

    final JCheckBox showErrorCB = new JCheckBox("Show error on plot");
    filterPanel.add(showErrorCB, gbc);
    gbc.gridy++;

    final JCheckBox zoomCB = new JCheckBox("Auto-adjusted size");
    zoomCB.setSelected(DEFAULT_ZOOM_OPTION);
    filterPanel.add(zoomCB, gbc);
    gbc.gridy++;

    final JCheckBox multAxisCB = new JCheckBox("Multiple axis");
    filterPanel.add(multAxisCB, gbc);
    gbc.gridy++;

    final JCheckBox showEnvelopeCB = new JCheckBox("Show envelope (all algorithms, SLOW)");
    filterPanel.add(showEnvelopeCB, gbc);
    gbc.gridy++;

    final JXButton showModelButton = new JXButton("Show the model");
    filterPanel.add(showModelButton, gbc);
    gbc.gridy++;

    showModelButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            final JXFrame dialog = new JXFrame();
            dialog.setTitle("Model");
            LogoHelper.setLogo(dialog);
            dialog.getContentPane().removeAll();
            dialog.getContentPane().setLayout(new BorderLayout());
            final JTextPane modelTxtPane = new JTextPane();
            modelTxtPane.setText(gapFiller.getModel());
            modelTxtPane.setBackground(Color.WHITE);
            modelTxtPane.setEditable(false);
            final JScrollPane jsp = new JScrollPane(modelTxtPane, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
            jsp.setSize(new Dimension(400 - 20, 400 - 20));
            dialog.getContentPane().add(jsp, BorderLayout.CENTER);
            dialog.setSize(new Dimension(400, 400));
            dialog.setLocationRelativeTo(centerPanel);
            dialog.pack();
            dialog.setVisible(true);
        }
    });

    algoCombo.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
                showModelButton.setEnabled(gapFiller.hasExplicitModel());
            } catch (final Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    timeSeriesList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(final ListSelectionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
                mapPanel.removeAll();
                final List<String> currentlySelected = new ArrayList<String>();
                currentlySelected.add(attr.name());
                for (final Object sel : timeSeriesList.getSelectedValues())
                    currentlySelected.add(sel.toString());
                mapPanel.add(gcp.getMapPanel(currentlySelected, attrNames, true), BorderLayout.CENTER);
            } catch (final Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    hideOtherSeriesCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (final Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    showErrorCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    zoomCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    showEnvelopeCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    multAxisCB.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            try {
                refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()),
                        timeSeriesList.getSelectedIndices(), hideOtherSeriesCB.isSelected(),
                        showErrorCB.isSelected(), zoomCB.isSelected(), showEnvelopeCB.isSelected(),
                        multAxisCB.isSelected());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    });

    this.inBatchMode = inBatchMode;

    if (!inBatchMode) {
        try {
            refresh(Algo.valueOf(algoCombo.getSelectedItem().toString()), new int[0],
                    DEFAULT_HIDE_OTHER_SERIES_OPTION, false, DEFAULT_ZOOM_OPTION, false, false);
            showModelButton.setEnabled(gapFiller.hasExplicitModel());
        } catch (Exception e1) {
            e1.printStackTrace();
        }
    }

    if (!inBatchMode) {
        /* automatically select computed series */
        new AbstractSimpleAsync<Void>(true) {
            @Override
            public Void execute() throws Exception {
                mostSimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(testds, attr, attrNames,
                        false);
                mssLabel.setText("<html>Most similar usable serie: <b>" + mostSimilar + "</b></html>");

                nearest = gcp.findNearestStation(attr.name(), attrNames);
                nsLabel.setText("<html>Nearest usable serie: <b>" + nearest + "</b></html>");

                upstream = gcp.findUpstreamStation(attr.name(), attrNames);
                if (upstream != null) {
                    ussLabel.setText("<html>Upstream usable serie: <b>" + upstream + "</b></html>");
                } else {
                    ussLabel.setText("<html>Upstream usable serie: <b>N/A</b></html>");
                }

                downstream = gcp.findDownstreamStation(attr.name(), attrNames);
                if (downstream != null) {
                    dssLabel.setText("<html>Downstream usable serie: <b>" + downstream + "</b></html>");
                } else {
                    dssLabel.setText("<html>Downstream usable serie: <b>N/A</b></html>");
                }

                timeSeriesList.setSelectedIndices(
                        new int[] { attrNames.indexOf(mostSimilar), attrNames.indexOf(nearest),
                                attrNames.indexOf(upstream), attrNames.indexOf(downstream) });

                return null;
            }

            @Override
            public void onSuccess(final Void result) {
            }

            @Override
            public void onFailure(final Throwable caught) {
                caught.printStackTrace();
            }
        }.start();
    } else {
        try {
            mostSimilar = WekaTimeSeriesSimilarityUtil.findMostSimilarTimeSerie(testds, attr, attrNames, false);
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        nearest = gcp.findNearestStation(attr.name(), attrNames);
        upstream = gcp.findUpstreamStation(attr.name(), attrNames);
        downstream = gcp.findDownstreamStation(attr.name(), attrNames);
    }
}

From source file:edu.snu.leader.discrete.simulator.SimulatorLauncherGUI.java

JTextPane createErrorPane(String errorMessage, Component component, final JTabbedPane tabbedPane,
        final int tabIndex) {
    final JTextPane errorPane = new JTextPane();

    errorPane.setEditable(false);/*from  w  ww .j  ava2  s  .  c  o m*/
    errorPane.setText(errorMessage);
    errorPane.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent arg0) {
            errorPane.setBackground(Color.YELLOW);
            tabbedPane.setSelectedIndex(tabIndex);
        }

        @Override
        public void focusLost(FocusEvent arg0) {
            errorPane.setBackground(Color.WHITE);
        }
    });

    component.requestFocusInWindow();

    return errorPane;
}

From source file:org.nebulaframework.ui.swing.cluster.ClusterMainUI.java

/**
 * Setup the General Tab Pane/*  w ww  .  ja v a 2  s  . c o m*/
 * 
 * @return JPanel for pane
 */
private JPanel setupGeneralTab() {

    JPanel generalTab = new JPanel();
    generalTab.setLayout(new BorderLayout());

    /* -- Create Main Panels -- */

    JPanel centerPanel = new JPanel();
    JPanel northPanel = new JPanel();
    JPanel southPanel = new JPanel();

    generalTab.add(centerPanel, BorderLayout.CENTER);
    generalTab.add(northPanel, BorderLayout.NORTH);

    /* -- Create Center Contents -- */

    // Statistics Panel
    JPanel statsPanel = setupStatsPanel();

    // Log Panel
    JPanel logPanel = new JPanel();
    logPanel.setLayout(new BorderLayout());
    logPanel.setBorder(BorderFactory.createTitledBorder("Log Output"));
    JTextPane logTextPane = new JTextPane();
    logTextPane.setEditable(false);
    logTextPane.setBackground(Color.BLACK);
    logTextPane.setForeground(Color.WHITE);

    logPanel.add(new JScrollPane(logTextPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
    addUIElement("general.log", logTextPane); // Add to component map

    JPanel logOptionsPanel = new JPanel();
    logPanel.add(logOptionsPanel, BorderLayout.SOUTH);
    logOptionsPanel.setLayout(new FlowLayout(FlowLayout.RIGHT));

    final JCheckBox logScrollCheckbox = new JCheckBox("Auto-Scroll Log");
    logScrollCheckbox.setSelected(true);
    logScrollCheckbox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JTextPaneAppender.setAutoScroll(logScrollCheckbox.isSelected());
        }

    });
    logOptionsPanel.add(logScrollCheckbox);

    // Enable Logging
    JTextPaneAppender.setTextPane(logTextPane);

    centerPanel.setLayout(new BorderLayout(10, 10));
    centerPanel.add(statsPanel, BorderLayout.NORTH);
    centerPanel.add(logPanel, BorderLayout.CENTER);

    /* -- Create Buttons (South) -- */

    generalTab.add(southPanel, BorderLayout.SOUTH);

    final JButton shutdownButton = new JButton("Shutdown");
    shutdownButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            doShutdownCluster();
        }
    });

    southPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 10));
    southPanel.add(shutdownButton);
    addUIElement("general.shutdown", shutdownButton); // Add to components map

    return generalTab;
}