mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
actually change spaces
This commit is contained in:
@@ -51,177 +51,177 @@ import static javafx.concurrent.Worker.State.FAILED;
|
||||
|
||||
public class SimpleSwingBrowser extends JFrame {
|
||||
|
||||
private final JFXPanel jfxPanel = new JFXPanel();
|
||||
private WebEngine engine;
|
||||
private final JFXPanel jfxPanel = new JFXPanel();
|
||||
private WebEngine engine;
|
||||
|
||||
private final JPanel panel = new JPanel(new BorderLayout());
|
||||
private final JLabel lblStatus = new JLabel();
|
||||
private final JPanel panel = new JPanel(new BorderLayout());
|
||||
private final JLabel lblStatus = new JLabel();
|
||||
|
||||
private final JButton btnGo = new JButton("Go");
|
||||
private final JTextField txtURL = new JTextField();
|
||||
private final JProgressBar progressBar = new JProgressBar();
|
||||
private final JButton btnGo = new JButton("Go");
|
||||
private final JTextField txtURL = new JTextField();
|
||||
private final JProgressBar progressBar = new JProgressBar();
|
||||
|
||||
|
||||
public SimpleSwingBrowser() {
|
||||
super();
|
||||
initComponents();
|
||||
}
|
||||
public SimpleSwingBrowser() {
|
||||
super();
|
||||
initComponents();
|
||||
}
|
||||
|
||||
|
||||
private void initComponents() {
|
||||
createScene();
|
||||
private void initComponents() {
|
||||
createScene();
|
||||
|
||||
ActionListener al = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
loadURL(txtURL.getText());
|
||||
}
|
||||
};
|
||||
ActionListener al = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
loadURL(txtURL.getText());
|
||||
}
|
||||
};
|
||||
|
||||
btnGo.addActionListener(al);
|
||||
txtURL.addActionListener(al);
|
||||
btnGo.addActionListener(al);
|
||||
txtURL.addActionListener(al);
|
||||
|
||||
progressBar.setPreferredSize(new Dimension(150, 18));
|
||||
progressBar.setStringPainted(true);
|
||||
progressBar.setPreferredSize(new Dimension(150, 18));
|
||||
progressBar.setStringPainted(true);
|
||||
|
||||
JPanel topBar = new JPanel(new BorderLayout(5, 0));
|
||||
topBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
|
||||
topBar.add(txtURL, BorderLayout.CENTER);
|
||||
topBar.add(btnGo, BorderLayout.EAST);
|
||||
JPanel topBar = new JPanel(new BorderLayout(5, 0));
|
||||
topBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
|
||||
topBar.add(txtURL, BorderLayout.CENTER);
|
||||
topBar.add(btnGo, BorderLayout.EAST);
|
||||
|
||||
JPanel statusBar = new JPanel(new BorderLayout(5, 0));
|
||||
statusBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
|
||||
statusBar.add(lblStatus, BorderLayout.CENTER);
|
||||
statusBar.add(progressBar, BorderLayout.EAST);
|
||||
JPanel statusBar = new JPanel(new BorderLayout(5, 0));
|
||||
statusBar.setBorder(BorderFactory.createEmptyBorder(3, 5, 3, 5));
|
||||
statusBar.add(lblStatus, BorderLayout.CENTER);
|
||||
statusBar.add(progressBar, BorderLayout.EAST);
|
||||
|
||||
panel.add(topBar, BorderLayout.NORTH);
|
||||
panel.add(jfxPanel, BorderLayout.CENTER);
|
||||
panel.add(statusBar, BorderLayout.SOUTH);
|
||||
panel.add(topBar, BorderLayout.NORTH);
|
||||
panel.add(jfxPanel, BorderLayout.CENTER);
|
||||
panel.add(statusBar, BorderLayout.SOUTH);
|
||||
|
||||
getContentPane().add(panel);
|
||||
getContentPane().add(panel);
|
||||
|
||||
setPreferredSize(new Dimension(1024, 600));
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
pack();
|
||||
}
|
||||
setPreferredSize(new Dimension(1024, 600));
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
pack();
|
||||
}
|
||||
|
||||
|
||||
private void createScene() {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
WebView view = new WebView();
|
||||
engine = view.getEngine();
|
||||
private void createScene() {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
WebView view = new WebView();
|
||||
engine = view.getEngine();
|
||||
|
||||
engine.titleProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleSwingBrowser.this.setTitle(newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
engine.titleProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
SimpleSwingBrowser.this.setTitle(newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
engine.setOnStatusChanged(new EventHandler<WebEvent<String>>() {
|
||||
@Override
|
||||
public void handle(final WebEvent<String> event) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lblStatus.setText(event.getData());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
engine.setOnStatusChanged(new EventHandler<WebEvent<String>>() {
|
||||
@Override
|
||||
public void handle(final WebEvent<String> event) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
lblStatus.setText(event.getData());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
engine.locationProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> ov, String oldValue, final String newValue) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txtURL.setText(newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
engine.locationProperty().addListener(new ChangeListener<String>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends String> ov, String oldValue, final String newValue) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txtURL.setText(newValue);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
engine.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, final Number newValue) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressBar.setValue(newValue.intValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
engine.getLoadWorker().workDoneProperty().addListener(new ChangeListener<Number>() {
|
||||
@Override
|
||||
public void changed(ObservableValue<? extends Number> observableValue, Number oldValue, final Number newValue) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressBar.setValue(newValue.intValue());
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
engine.getLoadWorker()
|
||||
.exceptionProperty()
|
||||
.addListener(new ChangeListener<Throwable>() {
|
||||
engine.getLoadWorker()
|
||||
.exceptionProperty()
|
||||
.addListener(new ChangeListener<Throwable>() {
|
||||
|
||||
public void changed(ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) {
|
||||
if (engine.getLoadWorker().getState() == FAILED) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JOptionPane.showMessageDialog(
|
||||
panel,
|
||||
(value != null)
|
||||
? engine.getLocation() + "\n" + value.getMessage()
|
||||
: engine.getLocation() + "\nUnexpected error.",
|
||||
"Loading error...",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
public void changed(ObservableValue<? extends Throwable> o, Throwable old, final Throwable value) {
|
||||
if (engine.getLoadWorker().getState() == FAILED) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
JOptionPane.showMessageDialog(
|
||||
panel,
|
||||
(value != null)
|
||||
? engine.getLocation() + "\n" + value.getMessage()
|
||||
: engine.getLocation() + "\nUnexpected error.",
|
||||
"Loading error...",
|
||||
JOptionPane.ERROR_MESSAGE);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
jfxPanel.setScene(new Scene(view));
|
||||
}
|
||||
});
|
||||
}
|
||||
jfxPanel.setScene(new Scene(view));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public void loadURL(final String url) {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String tmp = toURL(url);
|
||||
public void loadURL(final String url) {
|
||||
Platform.runLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String tmp = toURL(url);
|
||||
|
||||
if (tmp == null) {
|
||||
tmp = toURL("http://" + url);
|
||||
}
|
||||
if (tmp == null) {
|
||||
tmp = toURL("http://" + url);
|
||||
}
|
||||
|
||||
engine.load(tmp);
|
||||
}
|
||||
});
|
||||
}
|
||||
engine.load(tmp);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private static String toURL(String str) {
|
||||
try {
|
||||
return new URL(str).toExternalForm();
|
||||
} catch (MalformedURLException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
private static String toURL(String str) {
|
||||
try {
|
||||
return new URL(str).toExternalForm();
|
||||
} catch (MalformedURLException exception) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
|
||||
public void run() {
|
||||
SimpleSwingBrowser browser = new SimpleSwingBrowser();
|
||||
browser.setVisible(true);
|
||||
browser.loadURL("http://oracle.com");
|
||||
}
|
||||
});
|
||||
}
|
||||
public void run() {
|
||||
SimpleSwingBrowser browser = new SimpleSwingBrowser();
|
||||
browser.setVisible(true);
|
||||
browser.loadURL("http://oracle.com");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user