Example usage for javax.swing JTextPane setText

List of usage examples for javax.swing JTextPane setText

Introduction

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

Prototype

@BeanProperty(bound = false, description = "the text of this component")
public void setText(String t) 

Source Link

Document

Sets the text of this TextComponent to the specified content, which is expected to be in the format of the content type of this editor.

Usage

From source file:net.sf.jabref.gui.mergeentries.MergeEntries.java

/**
 * Main function for building the merge entry JPanel
 *//*  w w w.j a  v  a 2s.c om*/
private void initialize() {
    doneBuilding = false;
    setupFields();

    // Fill diff mode combo box
    for (String diffText : DIFF_MODES) {
        diffMode.addItem(diffText);
    }
    diffMode.setSelectedIndex(Math.min(Globals.prefs.getInt(JabRefPreferences.MERGE_ENTRIES_DIFF_MODE),
            diffMode.getItemCount() - 1));
    diffMode.addActionListener(e -> {
        updateTextPanes(differentFields);
        storePreference();
    });

    // Create main layout
    String colSpecMain = "left:pref, 5px, center:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, center:3cm:grow";
    String colSpecMerge = "left:pref, 5px, fill:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, fill:3cm:grow";
    String rowSpec = "pref, pref, 10px, fill:5cm:grow, 10px, pref, 10px, fill:3cm:grow";
    StringBuilder rowBuilder = new StringBuilder("");
    for (int i = 0; i < allFields.size(); i++) {
        rowBuilder.append("pref, 2dlu, ");
    }
    rowBuilder.append("pref");

    JPanel mergePanel = new JPanel();
    FormLayout mainLayout = new FormLayout(colSpecMain, rowSpec);
    FormLayout mergeLayout = new FormLayout(colSpecMerge, rowBuilder.toString());
    mainPanel.setLayout(mainLayout);
    mergePanel.setLayout(mergeLayout);

    CellConstraints cc = new CellConstraints();

    mainPanel.add(boldFontLabel(Localization.lang("Use")), cc.xyw(4, 1, 7, "center, bottom"));
    mainPanel.add(diffMode, cc.xy(11, 1, "right, bottom"));

    // Set headings
    JLabel[] headingLabels = new JLabel[6];
    for (int i = 0; i < 6; i++) {
        headingLabels[i] = boldFontLabel(COLUMN_HEADINGS[i]);
        mainPanel.add(headingLabels[i], cc.xy(1 + (i * 2), 2));

    }

    mainPanel.add(new JSeparator(), cc.xyw(1, 3, 11));

    // Start with entry type
    mergePanel.add(boldFontLabel(Localization.lang("Entry type")), cc.xy(1, 1));

    JTextPane leftTypeDisplay = getStyledTextPane();
    leftTypeDisplay.setText(HTML_START + leftEntry.getType() + HTML_END);
    mergePanel.add(leftTypeDisplay, cc.xy(3, 1));
    if (leftEntry.getType().equals(rightEntry.getType())) {
        identicalTypes = true;
    } else {
        identicalTypes = false;
        ButtonGroup group = new ButtonGroup();
        typeRadioButtons = new ArrayList<>(2);
        for (int k = 0; k < 3; k += 2) {
            JRadioButton button = new JRadioButton();
            typeRadioButtons.add(button);
            group.add(button);
            mergePanel.add(button, cc.xy(5 + (k * 2), 1));
            button.addChangeListener(e -> updateAll());
        }
        typeRadioButtons.get(0).setSelected(true);
    }
    JTextPane rightTypeDisplay = getStyledTextPane();
    rightTypeDisplay.setText(HTML_START + rightEntry.getType() + HTML_END);
    mergePanel.add(rightTypeDisplay, cc.xy(11, 1));

    // For all fields in joint add a row and possibly radio buttons
    int row = 2;
    int maxLabelWidth = -1;
    for (String field : allFields) {
        JLabel label = boldFontLabel(new SentenceCaseFormatter().format(field));
        mergePanel.add(label, cc.xy(1, (2 * row) - 1, "left, top"));
        Optional<String> leftString = leftEntry.getFieldOptional(field);
        Optional<String> rightString = rightEntry.getFieldOptional(field);
        if (leftString.equals(rightString)) {
            identicalFields.add(field);
        } else {
            differentFields.add(field);
        }

        maxLabelWidth = Math.max(maxLabelWidth, label.getPreferredSize().width);

        // Left text pane
        if (leftString.isPresent()) {
            JTextPane tf = getStyledTextPane();
            mergePanel.add(tf, cc.xy(3, (2 * row) - 1, "f, f"));
            leftTextPanes.put(field, tf);
        }

        // Add radio buttons if the two entries do not have identical fields
        if (identicalFields.contains(field)) {
            mergedEntry.setField(field, leftString.get()); // Will only happen if both entries have the field and the content is identical
        } else {
            ButtonGroup group = new ButtonGroup();
            List<JRadioButton> list = new ArrayList<>(3);
            for (int k = 0; k < 3; k++) {
                JRadioButton button = new JRadioButton();
                group.add(button);
                mergePanel.add(button, cc.xy(5 + (k * 2), (2 * row) - 1));
                button.addChangeListener(e -> updateAll());
                list.add(button);
            }
            radioButtons.put(field, list);
            if (leftString.isPresent()) {
                list.get(0).setSelected(true);
                if (!rightString.isPresent()) {
                    list.get(2).setEnabled(false);
                }
            } else {
                list.get(0).setEnabled(false);
                list.get(2).setSelected(true);
            }
        }

        // Right text pane
        if (rightString.isPresent()) {
            JTextPane tf = getStyledTextPane();
            mergePanel.add(tf, cc.xy(11, (2 * row) - 1, "f, f"));
            rightTextPanes.put(field, tf);
        }
        row++;
    }

    scrollPane = new JScrollPane(mergePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setBorder(BorderFactory.createEmptyBorder());
    updateTextPanes(allFields);
    mainPanel.add(scrollPane, cc.xyw(1, 4, 11));
    mainPanel.add(new JSeparator(), cc.xyw(1, 5, 11));

    // Synchronize column widths
    String[] rbAlign = { "right", "center", "left" };
    mainLayout.setColumnSpec(1, ColumnSpec.decode(Integer.toString(maxLabelWidth) + "px"));
    Integer maxRBWidth = -1;
    for (int k = 2; k < 5; k++) {
        maxRBWidth = Math.max(maxRBWidth, headingLabels[k].getPreferredSize().width);
    }
    for (int k = 0; k < 3; k++) {
        mergeLayout.setColumnSpec(5 + (k * 2), ColumnSpec.decode(rbAlign[k] + ":" + maxRBWidth + "px"));
    }

    // Setup a PreviewPanel and a Bibtex source box for the merged entry
    mainPanel.add(boldFontLabel(Localization.lang("Merged entry")), cc.xyw(1, 6, 6));

    entryPreview = new PreviewPanel(null, mergedEntry, null, Globals.prefs.get(JabRefPreferences.PREVIEW_0));
    mainPanel.add(entryPreview, cc.xyw(1, 8, 6));

    mainPanel.add(boldFontLabel(Localization.lang("Merged BibTeX source code")), cc.xyw(8, 6, 4));

    sourceView = new JTextArea();
    sourceView.setLineWrap(true);
    sourceView.setFont(new Font("Monospaced", Font.PLAIN, Globals.prefs.getInt(JabRefPreferences.FONT_SIZE)));
    mainPanel.add(new JScrollPane(sourceView), cc.xyw(8, 8, 4));
    sourceView.setEditable(false);

    // Add some margin around the layout
    mainLayout.appendRow(RowSpec.decode(MARGIN));
    mainLayout.appendColumn(ColumnSpec.decode(MARGIN));
    mainLayout.insertRow(1, RowSpec.decode(MARGIN));
    mainLayout.insertColumn(1, ColumnSpec.decode(MARGIN));

    // Everything done, allow any action to actually update the merged entry
    doneBuilding = true;

    updateAll();

    // Show what we've got
    mainPanel.setVisible(true);
    javax.swing.SwingUtilities.invokeLater(() -> scrollPane.getVerticalScrollBar().setValue(0));
}

From source file:net.itransformers.topologyviewer.rightclick.impl.CLIReportViewer.java

public <G> void handleRightClick(JFrame parent, String v, Map<String, String> graphMLParams,
        Map<String, String> rightClickParams, File projectPath, File versionDir) throws Exception {
    Logger logger = Logger.getLogger(CLIReportViewer.class);

    JFrame frame = new JFrame(" report for " + v + " ");
    frame.setSize(600, 400);/*  w  w  w.  jav  a  2s.  c o m*/
    frame.getContentPane().setLayout(new BorderLayout());
    JTextPane text = new JTextPane();
    text.setEditable(true);
    text.setContentType("text/html");
    String postDiscoveryFolderPath = rightClickParams.get("post-discovery-file-path");
    String reportFileName = rightClickParams.get("reportFileName");
    logger.info("CLI report executed in " + versionDir + " for " + File.separator + postDiscoveryFolderPath
            + File.separator + v + File.separator + reportFileName);

    File xmlReport = new File(versionDir.getAbsolutePath() + File.separator + postDiscoveryFolderPath
            + File.separator + v + File.separator + reportFileName);
    if (xmlReport.exists()) {
        text.setText(FileUtils.readFileToString(xmlReport));
        JScrollPane scrollPane = new JScrollPane(text);
        frame.getContentPane().add("Center", scrollPane);
        frame.setVisible(true);

    } else {
        JOptionPane.showMessageDialog(parent, "Report does not exist! Please generate it first!");
    }
}

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Displays help window/*from  w  w w.  j a va  2  s.  c o  m*/
 */
private void help() {
    String msg = "";

    MutableDataSet options = new MutableDataSet();
    Parser parser = Parser.builder(options).build();
    HtmlRenderer renderer = HtmlRenderer.builder(options).build();

    try {
        msg = IOUtils.toString(Main.getFile("Usage.md", this));
        Node document = parser.parse(msg);
        msg = renderer.render(document);
    } catch (IOException e) {
        e.printStackTrace();
    }

    JTextPane area = new JTextPane();
    area.setContentType("text/html");
    area.setText(msg);
    area.setCaretPosition(0);
    area.setEditable(false);

    JScrollPane scrollPane = new JScrollPane(area);
    scrollPane
            .setMaximumSize(new Dimension(GraphicsRunner.SCREEN_SIZE.width, GraphicsRunner.SCREEN_SIZE.height));
    scrollPane.setPreferredSize(
            new Dimension(GraphicsRunner.SCREEN_SIZE.width - 10, GraphicsRunner.SCREEN_SIZE.height - 10));
    scrollPane.scrollRectToVisible(new Rectangle());
    JOptionPane.showMessageDialog(this, scrollPane, "Help", JOptionPane.PLAIN_MESSAGE);
}

From source file:net.itransformers.topologyviewer.rightclick.impl.NodeStatisticsRightClickHandler.java

public <G> void handleRightClick(JFrame parent, String v, Map<String, String> graphMLParams,
        Map<String, String> rightClickParams, File projectPath, File versionDir) throws Exception {
    Logger logger = Logger.getLogger(NodeStatisticsRightClickHandler.class);

    JFrame frame = new JFrame(" report for " + v + " ");
    frame.setSize(300, 200);//w  w w  .j ava2 s. c om
    frame.getContentPane().setLayout(new BorderLayout());
    JTextPane text = new JTextPane();
    text.setEditable(true);
    text.setContentType("text/html");
    StringBuilder sb = new StringBuilder();
    TopologyManagerFrame viewer = (TopologyManagerFrame) parent;
    final GraphViewerPanel viewerPanel = (GraphViewerPanel) viewer.getTabbedPane().getSelectedComponent();
    final MyVisualizationViewer vv = (MyVisualizationViewer) viewerPanel.getVisualizationViewer();
    Graph currentGraph = viewerPanel.getCurrentGraph();
    int inDegree = currentGraph.inDegree(v);
    int outDegree = currentGraph.outDegree(v);
    sb.append("Number of incoming edges: ").append(inDegree);
    sb.append("\n");
    sb.append("Number of outgoing edges: ").append(outDegree);
    text.setText(sb.toString());
    JScrollPane scrollPane = new JScrollPane(text);
    frame.getContentPane().add("Center", scrollPane);
    frame.setVisible(true);

}

From source file:edu.ku.brc.specify.tools.schemalocale.SchemaLocalizerFrame.java

/**
 * //ww  w . j  av a 2 s  .  c  o  m
 */
protected void buildUI() {
    SchemaLocalizerXMLHelper slxh = new SchemaLocalizerXMLHelper(schemaType, tableMgr);
    localizableIO = slxh;
    localizableIO.load(false);

    //stripToSingleLocale("pt", slxh);

    LocalizableStrFactory localizableStrFactory = new LocalizableStrFactory() {
        public LocalizableStrIFace create() {
            SpLocaleItemStr str = new SpLocaleItemStr();
            str.initialize();
            return str;
        }

        public LocalizableStrIFace create(String text, Locale locale) {
            return new SpLocaleItemStr(text, locale); // no initialize needed for this constructor
        }
    };

    LocalizerBasePanel.setLocalizableStrFactory(localizableStrFactory);
    SchemaLocalizerXMLHelper.setLocalizableStrFactory(localizableStrFactory);

    schemaLocPanel = new SchemaLocalizerPanel(null, dataObjFieldFormatMgrCache, uiFieldFormatterMgrCache,
            webLinkMgrCache, schemaType);
    schemaLocPanel.setLocalizableIO(localizableIO);
    schemaLocPanel.setStatusBar(statusBar);

    boolean useDisciplines = AppPreferences.getLocalPrefs().getBoolean("SCHEMA_DISP", false);
    schemaLocPanel.setUseDisciplines(useDisciplines);

    // rods - for now 
    //schemaLocPanel.setIncludeHiddenUI(true);
    schemaLocPanel.buildUI();
    schemaLocPanel.setHasChanged(localizableIO.didModelChangeDuringLoad());

    statusBar.setSectionText(1,
            schemaType == SpLocaleContainer.CORE_SCHEMA ? getResourceString("SchemaLocalizerFrame.FULL_SCHEMA") //$NON-NLS-1$
                    : getResourceString("SchemaLocalizerFrame.WB_SCHEMA")); //$NON-NLS-1$

    UIRegistry.setStatusBar(statusBar);

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    String title = "File"; //$NON-NLS-1$
    String mneu = "F"; //$NON-NLS-1$
    JMenu fileMenu = UIHelper.createLocalizedMenu(menuBar, title, mneu);

    title = "Save"; //$NON-NLS-1$
    mneu = "S"; //$NON-NLS-1$
    JMenuItem saveMenuItem = UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", false, //$NON-NLS-1$
            new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    write();
                }
            });
    saveMenuItem.setEnabled(false);

    title = "Export"; //$NON-NLS-1$
    mneu = "E"; //$NON-NLS-1$
    UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
    {
        public void actionPerformed(ActionEvent e) {
            export();
        }
    });

    title = "SchemaLocalizerFrame.ExportLOCALE"; //$NON-NLS-1$
    mneu = "SchemaLocalizerFrame.ExportLOCALEMnu"; //$NON-NLS-1$
    UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
    {
        public void actionPerformed(ActionEvent e) {
            exportSingleLocale();
        }
    });

    title = "Exit"; //$NON-NLS-1$
    mneu = "x"; //$NON-NLS-1$
    if (!UIHelper.isMacOS()) {
        fileMenu.addSeparator();

        UIHelper.createLocalizedMenuItem(fileMenu, title, mneu, "", true, new ActionListener() //$NON-NLS-1$
        {
            public void actionPerformed(ActionEvent e) {
                shutdown();
            }
        });
    }
    /*
    JMenu toolMenu = UIHelper.createMenu(menuBar, "Tools", "T");
    UIHelper.createMenuItem(toolMenu, "Create Resource Files", "C", "", true, new ActionListener()
    {
    public void actionPerformed(ActionEvent e)
    {
        createResourceFiles();
    }
    });
    */

    menuBar.add(SchemaI18NService.getInstance().createLocaleMenu(this, new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals("locale")) //$NON-NLS-1$
            {
                schemaLocPanel.localeChanged((Locale) evt.getNewValue());
                statusBar.setSectionText(0, SchemaI18NService.getCurrentLocale().getDisplayName());
            }
        }
    }));

    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    setSize(800, 600);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(schemaLocPanel, BorderLayout.CENTER);
    mainPanel.add(statusBar, BorderLayout.SOUTH);

    mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    setContentPane(mainPanel);

    statusBar.setSectionText(0, SchemaI18NService.getCurrentLocale().getDisplayName());

    schemaLocPanel.setSaveMenuItem(saveMenuItem);

    schemaLocPanel.getContainerList().setEnabled(true);

    AppPreferences localPrefs = AppPreferences.getLocalPrefs();
    localPrefs.setDirPath(UIRegistry.getAppDataDir());

    ImageIcon helpIcon = IconManager.getIcon("AppIcon", IconSize.Std16); //$NON-NLS-1$
    HelpMgr.initializeHelp("SpecifyHelp", helpIcon.getImage()); //$NON-NLS-1$

    AppPrefsCache.setUseLocalOnly(true);
    SpecifyAppPrefs.loadColorAndFormatPrefs();

    if (localizableIO.didModelChangeDuringLoad()) {
        saveMenuItem.setEnabled(true);
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame(getResourceString("SchemaLocalizerFrame.CHG_TO_SCHEMA")); //$NON-NLS-1$
                frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

                JTextPane tp = new JTextPane();
                JScrollPane js = new JScrollPane();
                js.getViewport().add(tp);

                tp.setContentType("text/html");
                tp.setText(((SchemaLocalizerXMLHelper) localizableIO).getChangesBuffer());

                frame.setContentPane(js);
                frame.pack();
                frame.setSize(400, 500);
                frame.setVisible(true);
            }
        });
    }
}

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  a 2 s. c o  m
        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:de.ailis.xadrian.components.ComplexEditor.java

/**
 * Prints the complex data//from   w  w w .  j  a  v  a 2  s . c o  m
 */
public void print() {
    // Prepare model
    final Map<String, Object> model = new HashMap<String, Object>();
    model.put("complex", this.complex);
    model.put("print", true);
    model.put("config", Config.getInstance());

    // Generate content
    final String content = TemplateFactory.processTemplate(template, model);

    // Put content into a text pane component
    final JTextPane printPane = new JTextPane();
    printPane.setContentType("text/html");
    ((HTMLDocument) printPane.getDocument()).setBase(Main.class.getResource("templates/"));
    printPane.setText(content);

    // Print the text pane
    try {
        printPane.print(null, null, true, null, Config.getInstance().getPrintAttributes(), true);
    } catch (final PrinterException e) {
        JOptionPane.showMessageDialog(null, I18N.getString("error.cantPrint"), I18N.getString("error.title"),
                JOptionPane.ERROR_MESSAGE);
        log.error("Unable to print complex: " + e, e);
    }
}

From source file:it.iit.genomics.cru.igb.bundles.mi.view.MIResultPanel.java

public MIResultPanel(IgbService service, String summary, List<MIResult> results, String label, MIQuery query) {
    setLayout(new BorderLayout());

    this.label = label;

    igbLogger = IGBLogger.getInstance(label);

    colorer = TaxonColorer.getColorer(query.getTaxid());

    Box menuBox = new Box(BoxLayout.X_AXIS);

    Box buttonBox = new Box(BoxLayout.Y_AXIS);
    Box buttonBox1 = new Box(BoxLayout.X_AXIS);

    Box buttonBox3 = new Box(BoxLayout.X_AXIS);
    buttonBox.add(buttonBox1);//ww  w .  j a va  2 s  .  c om

    buttonBox.add(buttonBox3);

    JTextPane querySummary = new JTextPane();
    querySummary.setContentType("text/html");
    querySummary.setEditable(false);
    querySummary.setText(summary);

    menuBox.add(querySummary);

    menuBox.add(buttonBox);

    final JFrame logFrame = new JFrame("MI Bundle Log");
    logFrame.setVisible(false);
    Dimension preferredSize = new Dimension(800, 500);

    logFrame.setPreferredSize(preferredSize);
    logFrame.setMinimumSize(preferredSize);

    logFrame.add(new LogPanel(igbLogger));

    JButton log = new JButton();

    if (igbLogger.hasError()) {
        log.setBackground(Color.red);
    }

    log.setIcon(CommonUtils.getInstance().getIcon("16x16/actions/console.png"));

    log.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            logFrame.setVisible(true);
        }

    });

    buttonBox1.add(log);

    JButton networkButton = new JButton("");
    networkButton.setIcon(new ImageIcon(getClass().getResource("/network.jpg")));
    networkButton.addActionListener(new DisplayNetworkActionListener());

    buttonBox1.add(networkButton);

    buttonBox1.add(new JSeparator(JSeparator.VERTICAL));

    buttonBox1.add(new JLabel("Save: "));
    JButton exportButton = new JButton("text");
    exportButton.setIcon(CommonUtils.getInstance().getIcon("16x16/actions/save.png"));
    exportButton.addActionListener(new ExportActionListener());

    if (false == MICommons.testVersion) {
        buttonBox1.add(exportButton);
    }

    JButton exportXgmmlButton = new JButton("xgmml");
    exportXgmmlButton.setIcon(CommonUtils.getInstance().getIcon("16x16/actions/save.png"));
    exportXgmmlButton.addActionListener(new ExportXgmmlActionListener());
    if (false == MICommons.testVersion) {
        buttonBox1.add(exportXgmmlButton);
    }

    buttonBox1.add(new JSeparator(JSeparator.VERTICAL));

    buttonBox1.add(new JLabel("View structure: "));

    structures = new StructuresPanel(service, label);

    buttonBox1.add(structures.getJmolButton());
    buttonBox1.add(structures.getLinkButton());

    // Filters
    ButtonGroup scoreGroup = new ButtonGroup();
    JRadioButton scoreButton0 = new JRadioButton("<html>" + HTML_SCORE_0 + "</html>");
    JRadioButton scoreButton1 = new JRadioButton("<html>" + HTML_SCORE_1 + "</html>");
    JRadioButton scoreButton2 = new JRadioButton("<html>" + HTML_SCORE_2 + "</html>");
    JRadioButton scoreButton3 = new JRadioButton("<html>" + HTML_SCORE_3 + "</html>");
    scoreButton0.setSelected(true);

    ScoreListener scoreListener = new ScoreListener();
    scoreButton0.addActionListener(scoreListener);
    scoreButton1.addActionListener(scoreListener);
    scoreButton2.addActionListener(scoreListener);
    scoreButton3.addActionListener(scoreListener);

    scoreGroup.add(scoreButton0);
    scoreGroup.add(scoreButton1);
    scoreGroup.add(scoreButton2);
    scoreGroup.add(scoreButton3);

    buttonBox1.add(new JSeparator(JSeparator.VERTICAL));
    buttonBox1.add(new JLabel("Score: "));
    buttonBox1.add(scoreButton0);
    buttonBox1.add(scoreButton1);
    buttonBox1.add(scoreButton2);
    buttonBox1.add(scoreButton3);

    buttonBox3.add(new JLabel("Interaction type: "));

    JCheckBox EvidencePhysicalButton = new JCheckBox(HTML_CHECKBOX_PHYSICAL);
    JCheckBox EvidenceAssociationButton = new JCheckBox(HTML_CHECKBOX_ASSOCIATION);
    JCheckBox EvidenceEnzymaticButton = new JCheckBox(HTML_CHECKBOX_ENZYMATIC);
    JCheckBox EvidenceOtherButton = new JCheckBox(HTML_CHECKBOX_OTHER);
    JCheckBox EvidenceUnspecifiedButton = new JCheckBox(HTML_CHECKBOX_UNSPECIFIED);
    JCheckBox EvidenceStructureButton = new JCheckBox(HTML_CHECKBOX_STRUCTURE);

    EvidencePhysicalButton.setSelected(true);
    EvidenceAssociationButton.setSelected(true);
    EvidenceEnzymaticButton.setSelected(true);
    EvidenceOtherButton.setSelected(true);
    EvidenceUnspecifiedButton.setSelected(true);
    EvidenceStructureButton.setSelected(true);

    buttonBox3.add(EvidencePhysicalButton);
    buttonBox3.add(EvidenceAssociationButton);
    buttonBox3.add(EvidenceEnzymaticButton);
    buttonBox3.add(EvidenceOtherButton);
    buttonBox3.add(EvidenceUnspecifiedButton);
    buttonBox3.add(EvidenceStructureButton);

    EvidenceTypeListener evidenceListener = new EvidenceTypeListener();
    EvidencePhysicalButton.addActionListener(evidenceListener);
    EvidenceAssociationButton.addActionListener(evidenceListener);
    EvidenceEnzymaticButton.addActionListener(evidenceListener);
    EvidenceOtherButton.addActionListener(evidenceListener);
    EvidenceUnspecifiedButton.addActionListener(evidenceListener);
    EvidenceStructureButton.addActionListener(evidenceListener);

    Box tableBox = new Box(BoxLayout.Y_AXIS);

    MITableModel model = new MITableModel(results);

    miTable = new MITable(model, service, query);

    miTable.setFillsViewportHeight(true);

    miTable.setStructuresPanel(structures);

    tableBox.add(miTable.getTableHeader());
    tableBox.add(miTable);

    JScrollPane tableScroll = new JScrollPane(tableBox);

    tableScroll.setMinimumSize(new Dimension(800, 50));
    tableScroll.setPreferredSize(new Dimension(800, 50));
    tableScroll.setMaximumSize(new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));

    structures.setMinimumSize(new Dimension(200, 500));
    structures.setPreferredSize(new Dimension(200, 500));
    structures.setMaximumSize(new Dimension(200, Short.MAX_VALUE));

    resultBox = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tableScroll, structures);
    resultBox.setOneTouchExpandable(true);

    add(menuBox, BorderLayout.NORTH);
    add(resultBox, BorderLayout.CENTER);

}

From source file:de.huxhorn.lilith.swing.LicenseAgreementDialog.java

private void initUI() {
    JPanel content = new JPanel();
    content.setLayout(new BorderLayout());
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER));

    JTextPane licenseTextPane = new JTextPane();
    HTMLEditorKit htmlEditorKit = new HTMLEditorKit();

    String licenseText = null;/*from  w  ww.java  2  s . c o  m*/
    InputStream licenseStream = LicenseAgreementDialog.class.getResourceAsStream("/licenses/license.html");
    if (licenseStream != null) {
        try {
            licenseText = IOUtils.toString(licenseStream, StandardCharsets.UTF_8);
        } catch (IOException ex) {
            if (logger.isErrorEnabled())
                logger.error("Exception while loading license!", ex);
            IOUtilities.interruptIfNecessary(ex);
        } finally {
            IOUtilities.closeQuietly(licenseStream);
        }
    }
    if (licenseText == null) {
        if (logger.isErrorEnabled())
            logger.error("Couldn't find license text! Exiting!");
        System.exit(-1);
    }

    licenseTextPane.setEditorKit(htmlEditorKit);
    licenseTextPane.setEditable(false);
    licenseTextPane.setText(licenseText);
    JScrollPane licenseScrollPane = new JScrollPane(licenseTextPane);
    licenseScrollPane.setPreferredSize(new Dimension(640, 480));

    content.add(licenseScrollPane, BorderLayout.CENTER);
    content.add(buttonPanel, BorderLayout.SOUTH);

    AcceptAction acceptAction = new AcceptAction();
    DeclineAction declineAction = new DeclineAction();

    JButton acceptButton = new JButton(acceptAction);
    JButton declineButton = new JButton(declineAction);

    buttonPanel.add(acceptButton);
    buttonPanel.add(declineButton);
    setContentPane(content);
    licenseTextPane.setCaretPosition(0);
    declineButton.requestFocusInWindow();
}

From source file:main.UIController.java

/************* TO GREGORIAN *************/

public void updateDayComboImladris() {
    UI window = this.getUi();

    JComboBox yen = window.getYen();
    JTextField loa = window.getLoa();
    JComboBox period = window.getPeriod();
    JComboBox day = window.getDayOfLoa();
    JButton convert = window.getToGregorian();
    JTextPane result = window.getResGregorian();
    int yenNum = yen.getSelectedIndex() + 1;
    String value = loa.getText();
    if (!value.isEmpty()) {
        try {//from www  .jav  a  2s. c o m
            int loaNum = Integer.parseInt(value);
            if (loaNum > 0 && loaNum <= 144) {
                int periodNum = period.getSelectedIndex() + 1;
                if (periodNum == ImladrisCalendar.YESTARE || periodNum == ImladrisCalendar.METTARE) {
                    day.setEnabled(false);
                    day.setModel(new DefaultComboBoxModel());
                    convert.setEnabled(true);
                    result.setText("");
                } else {
                    int daySel = 0;
                    if (day.isEnabled()) {
                        daySel = day.getSelectedIndex() + 1;
                    }
                    ArrayList<Integer> days = ImladrisInfo.getInstance().getDaysArray(yenNum, loaNum,
                            periodNum);
                    day.setModel(new DefaultComboBoxModel(days.toArray()));
                    if (daySel > 0 && daySel <= days.size()) {
                        day.setSelectedIndex(daySel - 1);
                    }
                    day.setEnabled(true);
                    convert.setEnabled(true);
                    result.setText("");
                }
            } else {
                day.setEnabled(false);
                convert.setEnabled(false);
                day.setModel(new DefaultComboBoxModel());
                result.setText("");
            }
        } catch (NumberFormatException e) {
            day.setEnabled(false);
            convert.setEnabled(false);
            day.setModel(new DefaultComboBoxModel());
            result.setText("");
        }
    } else {
        day.setEnabled(false);
        convert.setEnabled(false);
        day.setModel(new DefaultComboBoxModel());
        result.setText("");
    }
}