use of javax.swing.JScrollPane in project Smack by igniterealtime.
the class EnhancedDebugger method addAdhocPacketPanel.
private void addAdhocPacketPanel() {
// Create UI elements for sending ad-hoc messages.
final JTextArea adhocMessages = new JTextArea();
adhocMessages.setEditable(true);
adhocMessages.setForeground(new Color(1, 94, 35));
tabbedPane.add("Ad-hoc message", new JScrollPane(adhocMessages));
tabbedPane.setToolTipTextAt(3, "Panel that allows you to send adhoc packets");
// Add pop-up menu.
JPopupMenu menu = new JPopupMenu();
JMenuItem menuItem = new JMenuItem("Message");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<message to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><body></body></message>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("IQ Get");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<iq type=\"get\" to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><query xmlns=\"\"></query></iq>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("IQ Set");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<iq type=\"set\" to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"><query xmlns=\"\"></query></iq>");
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Presence");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText("<presence to=\"\" id=\"" + StringUtils.randomString(5) + "-X\"/>");
}
});
menu.add(menuItem);
menu.addSeparator();
menuItem = new JMenuItem("Send");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (!"".equals(adhocMessages.getText())) {
AdHocPacket packetToSend = new AdHocPacket(adhocMessages.getText());
try {
connection.sendStanza(packetToSend);
} catch (InterruptedException | NotConnectedException e1) {
LOGGER.log(Level.WARNING, "exception", e);
}
}
}
});
menu.add(menuItem);
menuItem = new JMenuItem("Clear");
menuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
adhocMessages.setText(null);
}
});
menu.add(menuItem);
// Add listener to the text area so the popup menu can come up.
adhocMessages.addMouseListener(new PopupListener(menu));
}
use of javax.swing.JScrollPane in project Smack by igniterealtime.
the class EnhancedDebugger method addInformationPanel.
private void addInformationPanel() {
// Create UI elements for connection information.
JPanel informationPanel = new JPanel();
informationPanel.setLayout(new BorderLayout());
// Add the Host information
JPanel connPanel = new JPanel();
connPanel.setLayout(new GridBagLayout());
connPanel.setBorder(BorderFactory.createTitledBorder("XMPPConnection information"));
JLabel label = new JLabel("Host: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
JFormattedTextField field = new JFormattedTextField(connection.getXMPPServiceDomain());
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the Port information
label = new JLabel("Port: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(connection.getPort());
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's User information
label = new JLabel("User: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
userField = new JFormattedTextField();
userField.setMinimumSize(new java.awt.Dimension(150, 20));
userField.setMaximumSize(new java.awt.Dimension(150, 20));
userField.setEditable(false);
userField.setBorder(null);
connPanel.add(userField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's creationTime information
label = new JLabel("Creation time: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd HH:mm:ss:SS"));
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setValue(creationTime);
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's creationTime information
label = new JLabel("Status: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
statusField = new JFormattedTextField();
statusField.setMinimumSize(new java.awt.Dimension(150, 20));
statusField.setMaximumSize(new java.awt.Dimension(150, 20));
statusField.setValue("Active");
statusField.setEditable(false);
statusField.setBorder(null);
connPanel.add(statusField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection panel to the information panel
informationPanel.add(connPanel, BorderLayout.NORTH);
// Add the Number of sent packets information
JPanel packetsPanel = new JPanel();
packetsPanel.setLayout(new GridLayout(1, 1));
packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));
statisticsTable = new DefaultTableModel(new Object[][] { { "IQ", 0, 0 }, { "Message", 0, 0 }, { "Presence", 0, 0 }, { "Other", 0, 0 }, { "Total", 0, 0 } }, new Object[] { "Type", "Received", "Sent" }) {
// CHECKSTYLE:OFF
private static final long serialVersionUID = -6793886085109589269L;
@Override
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON
return false;
}
};
JTable table = new JTable(statisticsTable);
// Allow only single a selection
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
packetsPanel.add(new JScrollPane(table));
// Add the packets panel to the information panel
informationPanel.add(packetsPanel, BorderLayout.CENTER);
tabbedPane.add("Information", new JScrollPane(informationPanel));
tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection");
}
use of javax.swing.JScrollPane in project apjp by jvansteirteghem.
the class Main method main.
public static void main(final String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
System.setProperty("sun.net.http.allowRestrictedHeaders", "true");
Security.addProvider(new IAIK());
Properties properties = new Properties();
properties.load(new FileInputStream("APJP_LOCAL.properties"));
APJP.APJP_KEY = properties.getProperty("APJP_KEY", "");
APJP.APJP_LOGGER_ID = "APJP";
APJP.APJP_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_PROXY_SERVER";
APJP.APJP_LOCAL_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_PROXY_SERVER";
APJP.APJP_LOCAL_HTTP_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTP_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTP_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTP_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTP_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTP_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_ID = "APJP_LOCAL_HTTP_SERVER";
APJP.APJP_LOCAL_HTTP_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL = new String[10];
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
for (int i = 0; i < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_URL", "");
for (int j = 0; j < APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
APJP.APJP_REMOTE_HTTP_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTP_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
}
}
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_PROXY_SERVER";
APJP.APJP_LOCAL_HTTPS_PROXY_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_LOCAL_HTTPS_SERVER_ADDRESS = properties.getProperty("APJP_LOCAL_HTTPS_SERVER_ADDRESS", "");
try {
APJP.APJP_LOCAL_HTTPS_SERVER_PORT = new Integer(properties.getProperty("APJP_LOCAL_HTTPS_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_LOCAL_HTTPS_SERVER_PORT = 0;
}
APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_ID = "APJP_LOCAL_HTTPS_SERVER";
APJP.APJP_LOCAL_HTTPS_SERVER_LOGGER_LEVEL = 1;
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL = new String[10];
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY = new String[10][5];
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE = new String[10][5];
for (int i = 0; i < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY.length; i = i + 1) {
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_URL[i] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_URL", "");
for (int j = 0; j < APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i].length; j = j + 1) {
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_KEY[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_KEY", "");
APJP.APJP_REMOTE_HTTPS_SERVER_REQUEST_PROPERTY_VALUE[i][j] = properties.getProperty("APJP_REMOTE_HTTPS_SERVER_" + (i + 1) + "_REQUEST_PROPERTY_" + (j + 1) + "_VALUE", "");
}
}
APJP.APJP_HTTP_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTP_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_HTTP_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTP_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_HTTP_PROXY_SERVER_PORT = 0;
}
APJP.APJP_HTTP_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTP_PROXY_SERVER_USERNAME", "");
APJP.APJP_HTTP_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTP_PROXY_SERVER_PASSWORD", "");
APJP.APJP_HTTPS_PROXY_SERVER_ADDRESS = properties.getProperty("APJP_HTTPS_PROXY_SERVER_ADDRESS", "");
try {
APJP.APJP_HTTPS_PROXY_SERVER_PORT = new Integer(properties.getProperty("APJP_HTTPS_PROXY_SERVER_PORT", "0"));
} catch (Exception e) {
APJP.APJP_HTTPS_PROXY_SERVER_PORT = 0;
}
APJP.APJP_HTTPS_PROXY_SERVER_USERNAME = properties.getProperty("APJP_HTTPS_PROXY_SERVER_USERNAME", "");
APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD = properties.getProperty("APJP_HTTPS_PROXY_SERVER_PASSWORD", "");
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication passwordAuthentication = null;
if (this.getRequestorType() == Authenticator.RequestorType.PROXY) {
if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTP") == true) {
passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTP_PROXY_SERVER_USERNAME, APJP.APJP_HTTP_PROXY_SERVER_PASSWORD.toCharArray());
} else {
if (this.getRequestingURL().getProtocol().equalsIgnoreCase("HTTPS") == true) {
passwordAuthentication = new PasswordAuthentication(APJP.APJP_HTTPS_PROXY_SERVER_USERNAME, APJP.APJP_HTTPS_PROXY_SERVER_PASSWORD.toCharArray());
}
}
}
return passwordAuthentication;
}
});
logger = Logger.getLogger(APJP.APJP_LOGGER_ID);
final ProxyServer proxyServer = new ProxyServer();
final JTextArea outputTextArea = new JTextArea();
outputTextArea.setEditable(false);
outputTextArea.setLineWrap(true);
outputTextArea.setBackground(new Color(0, 0, 0));
outputTextArea.setForeground(new Color(255, 255, 255));
outputTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
final JScrollPane outputScrollPane = new JScrollPane(outputTextArea);
final OutputStream outputStream = new OutputStream() {
public void write(final int b) throws IOException {
outputTextArea.append(new String(new char[] { (char) b }));
}
public void write(final byte[] b, final int off, final int len) throws IOException {
outputTextArea.append(new String(b, off, len));
}
};
final PrintStream printStream = new PrintStream(outputStream, true);
System.setOut(printStream);
final JButton startButton = new JButton();
startButton.setText("Start");
startButton.setPreferredSize(new Dimension(100, 30));
startButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
outputTextArea.setText("");
logger.log(1, "START_PROXY_SERVER");
try {
proxyServer.start();
logger.log(1, "START_PROXY_SERVER: OK");
} catch (Exception e) {
logger.log(1, "START_PROXY_SERVER: EXCEPTION", e);
logger.log(1, "START_PROXY_SERVER: NOT OK");
}
HTTPRequests httpRequests = HTTPRequests.getHTTPRequests();
logger.log(1, "TEST_HTTP_REQUESTS");
try {
httpRequests.test();
logger.log(1, "TEST_HTTP_REQUESTS: OK");
} catch (Exception e) {
logger.log(1, "TEST_HTTP_REQUESTS: EXCEPTION", e);
logger.log(1, "TEST_HTTP_REQUESTS: NOT OK");
}
HTTPSRequests httpsRequests = HTTPSRequests.getHTTPSRequests();
logger.log(1, "TEST_HTTPS_REQUESTS");
try {
httpsRequests.test();
logger.log(1, "TEST_HTTPS_REQUESTS: OK");
} catch (Exception e) {
logger.log(1, "TEST_HTTPS_REQUESTS: EXCEPTION", e);
logger.log(1, "TEST_HTTPS_REQUESTS: NOT OK");
}
}
});
final JButton stopButton = new JButton();
stopButton.setText("Stop");
stopButton.setPreferredSize(new Dimension(100, 30));
stopButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
outputTextArea.setText("");
logger.log(1, "STOP_PROXY_SERVER");
try {
proxyServer.stop();
logger.log(1, "STOP_PROXY_SERVER: OK");
} catch (Exception e) {
logger.log(1, "STOP_PROXY_SERVER: EXCEPTION", e);
logger.log(1, "STOP_PROXY_SERVER: NOT OK");
}
}
});
final Panel buttonPanel = new Panel();
buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
buttonPanel.add(startButton);
buttonPanel.add(stopButton);
final ImageIcon imageIcon = new ImageIcon("APJP_LOCAL.png");
final JFrame frame = new JFrame();
frame.setIconImage(imageIcon.getImage());
frame.setSize(675, 375);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
frame.add(buttonPanel, BorderLayout.NORTH);
frame.add(outputScrollPane, BorderLayout.CENTER);
if (SystemTray.isSupported()) {
final TrayIcon trayIcon = new TrayIcon(imageIcon.getImage());
trayIcon.setImageAutoSize(true);
trayIcon.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent actionEvent) {
frame.setVisible(!frame.isVisible());
}
});
SystemTray.getSystemTray().add(trayIcon);
}
frame.setVisible(true);
} catch (Exception e) {
logger.log(1, "EXCEPTION", e);
}
}
});
}
use of javax.swing.JScrollPane in project jna by java-native-access.
the class ShapedWindowDemo method main.
public static void main(String[] args) {
try {
System.setProperty("sun.java2d.noddraw", "true");
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
}
final JFrame frame = new JFrame("Shaped Window Demo");
MouseInputAdapter handler = new MouseInputAdapter() {
private Point offset;
private void showPopup(MouseEvent e) {
final JPopupMenu m = new JPopupMenu();
m.add(new AbstractAction("Hide") {
public void actionPerformed(ActionEvent e) {
frame.setState(JFrame.ICONIFIED);
}
private static final long serialVersionUID = 1L;
});
m.add(new AbstractAction("Close") {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
private static final long serialVersionUID = 1L;
});
m.pack();
m.show(e.getComponent(), e.getX(), e.getY());
}
public void mousePressed(MouseEvent e) {
offset = e.getPoint();
if (e.isPopupTrigger()) {
showPopup(e);
}
}
public void mouseDragged(MouseEvent e) {
if (!SwingUtilities.isLeftMouseButton(e))
return;
Point where = e.getPoint();
where.translate(-offset.x, -offset.y);
Point loc = frame.getLocationOnScreen();
loc.translate(where.x, where.y);
frame.setLocation(loc.x, loc.y);
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
showPopup(e);
}
}
};
frame.addMouseListener(handler);
frame.addMouseMotionListener(handler);
ClockFace face = new ClockFace(new Dimension(150, 150));
frame.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.MOVE_CURSOR));
frame.getContentPane().add(face);
frame.setUndecorated(true);
try {
Shape mask = new Area(new Ellipse2D.Float(0, 0, 150, 150));
WindowUtils.setWindowMask(frame, mask);
if (WindowUtils.isWindowAlphaSupported()) {
WindowUtils.setWindowAlpha(frame, .7f);
}
frame.setIconImage(face.getIconImage());
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setLocation(100, 100);
frame.setVisible(true);
} catch (UnsatisfiedLinkError e) {
e.printStackTrace();
String msg = e.getMessage() + "\nError loading the JNA library";
JTextArea area = new JTextArea(msg);
area.setOpaque(false);
area.setFont(UIManager.getFont("Label.font"));
area.setEditable(false);
area.setColumns(80);
area.setRows(8);
area.setWrapStyleWord(true);
area.setLineWrap(true);
JOptionPane.showMessageDialog(frame, new JScrollPane(area), "Library Load Error: " + System.getProperty("os.name") + "/" + System.getProperty("os.arch"), JOptionPane.ERROR_MESSAGE);
System.exit(1);
}
}
use of javax.swing.JScrollPane in project OpenNotebook by jaltekruse.
the class ObjectPropertiesFrame method generatePanel.
/**
* Generates a menu for adjusting the properties of a mathobject.
*
* @param o - object to base menu panel on
*/
public void generatePanel(MathObject o) {
System.out.println("generate panel" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (o == null) {
return;
}
this.getContentPane().removeAll();
object = o;
JPanel panel = mainPanel;
mainPanel.removeAll();
adjusters.removeAllElements();
listAdjusters.removeAllElements();
this.setTitle(o.getType());
JTabbedPane panelTabs = null;
JPanel tabOneContents = null, tabTwoContents = null;
GridBagConstraints con = new GridBagConstraints();
con.fill = GridBagConstraints.BOTH;
con.weightx = 1;
con.weighty = 1;
con.insets = new Insets(2, 2, 2, 2);
con.gridx = 0;
con.gridy = 0;
System.out.println("end init stuff" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (o instanceof GraphObject || (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())) {
// there are too many attributes and actions for the graph to put them all in one panel
// add a tabbed pane to make it more reasonable and avoid scrolling
panelTabs = new JTabbedPane();
this.getContentPane().add(panelTabs);
tabOneContents = new JPanel();
tabOneContents.setLayout(new GridBagLayout());
tabTwoContents = new JPanel();
tabTwoContents.setLayout(new GridBagLayout());
System.out.println("1 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
JScrollPane tabScrollPane = new JScrollPane(panelTabs);
tabScrollPane.getVerticalScrollBar().setUnitIncrement(16);
tabScrollPane.getHorizontalScrollBar().setUnitIncrement(16);
System.out.println("2 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
tabScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
if (o instanceof GraphObject) {
panelTabs.add("Nav", tabOneContents);
panelTabs.add("Grid", tabTwoContents);
panel = tabOneContents;
} else if (o instanceof ExpressionObject) {
panelTabs.add("Expression", tabOneContents);
panelTabs.add("Solve", tabTwoContents);
panel = tabOneContents;
}
System.out.println("3 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
this.getContentPane().add(tabScrollPane);
System.out.println("4 " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
} else {
this.getContentPane().add(scrollPane);
}
System.out.println("done with tabs " + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
con.weighty = .01;
JPanel actionPics = new JPanel();
actionPics.setLayout(new GridLayout(0, 4, 4, 4));
JPanel otherActions = new JPanel();
otherActions.setLayout(new GridLayout(0, 1, 4, 4));
ImageIcon pic;
JButton button;
if (!notebookPanel.isInStudentMode()) {
for (final String s : o.getActions()) {
pic = getIconForAction(s);
if (pic != null)
createButton(s, 0, 0, 0, 0, actionPics);
else
createButton(s, 0, 0, 0, 0, otherActions);
}
}
System.out.println("teacher actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
boolean skipAction;
for (final String s : o.getStudentActions()) {
skipAction = false;
if (object instanceof GraphObject) {
// use more intuitive
for (String str : graphNavActions) {
if (s.equals(str)) {
skipAction = true;
break;
}
}
}
if (object instanceof ExpressionObject) {
// in a separate panel to make the list of actions smaller
for (String str : expressionOpActions) {
if (s.equals(str)) {
skipAction = true;
break;
}
}
}
if (skipAction) {
continue;
}
pic = getIconForAction(s);
if (pic != null)
createButton(s, 0, 0, 0, 0, actionPics);
else
createButton(s, 0, 0, 0, 0, otherActions);
}
System.out.println("student actions done" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (otherActions.getComponentCount() != 0) {
// only add panel for actions if components have been added to it
panel.add(otherActions, con);
con.gridy++;
}
if (actionPics.getComponentCount() != 0) {
// only add panel for action pics if components have been added to it
panel.add(actionPics, con);
con.gridy++;
}
if (object instanceof GraphObject) {
panel.add(createGraphNavigator(), con);
con.gridy++;
}
if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode()) {
// there are too many attributes and actions for the expression to put them all in one panel
// added a tabbed pane to make it more reasonable and avoid scrolling
// this line moves to the other tab to place components there
panel = tabTwoContents;
}
if (object instanceof ExpressionObject) {
panel.add(createExpressionModifier(), con);
con.gridy++;
}
//Switch back to tab one if in teacher mode, to allow attribute adjusters to be on the first tab
if (o instanceof ExpressionObject && !notebookPanel.isInStudentMode())
panel = tabOneContents;
con.fill = GridBagConstraints.HORIZONTAL;
if (o instanceof GraphObject) {
// there are too many attributes and actions for the graph to put them all in one panel
// added a tabbed pane to make it more reasonable and avoid scrolling
// this line moves to the other tab to place components there
panel = new JPanel();
panel.setLayout(new GridBagLayout());
con.anchor = GridBagConstraints.PAGE_START;
tabTwoContents.add(panel, con);
con.anchor = GridBagConstraints.CENTER;
}
con.fill = GridBagConstraints.BOTH;
for (MathObjectAttribute mAtt : o.getAttributes()) {
if (notebookPanel.isInStudentMode() && mAtt.isStudentEditable() || (!notebookPanel.isInStudentMode() && mAtt.isUserEditable())) {
// only show editing dialog if in teacher mode (not student)
//or if the attribute has been left student editable
adjusters.add(getAdjuster(mAtt, notebookPanel, panel));
if (mAtt instanceof StringAttribute) {
// make string panels stretch vertically
con.weighty = 1;
con.fill = GridBagConstraints.BOTH;
} else {
// make all others stretch very little vertically
con.weighty = 0;
con.fill = GridBagConstraints.HORIZONTAL;
}
panel.add(adjusters.get(adjusters.size() - 1), con);
con.gridy++;
}
}
System.out.println("end att adjusters:" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
con.weighty = 1;
if (o instanceof GraphObject) {
// see above comments about tabs for some objects
panel = tabOneContents;
}
for (ListAttribute list : o.getLists()) {
if ((notebookPanel.isInStudentMode() && list.isStudentEditable()) || (!notebookPanel.isInStudentMode() && list.isUserEditable())) {
// only show editing dialog if in teacher mode (not student)
//or if the attribute has been left student editable
listAdjusters.add(new ListAdjuster(list, notebookPanel, panel));
panel.add(listAdjusters.get(listAdjusters.size() - 1), con);
con.gridy++;
}
}
System.out.println("end lists:" + +(new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
if (panel.getComponentCount() == 0) {
panel.add(new JLabel("No actions for this object"), con);
}
panel.revalidate();
this.pack();
this.update();
this.setSize(this.getWidth() + 30, this.getHeight());
System.out.println("done making props frame" + (new Date().getTime() - notebookPanel.getOpenNotebook().timeAtStart));
}
Aggregations