use of javax.swing.JApplet in project voltdb by VoltDB.
the class DatabaseManagerSwing method main.
public void main() {
JMenu jmenu;
JMenuItem mitem;
try {
prefs = new DBMPrefs(fMain instanceof JApplet);
} catch (Exception e) {
System.err.println("Failed to load preferences. Proceeding with defaults:\n");
}
if (prefs == null) {
setLF(CommonSwing.Native);
} else {
autoRefresh = prefs.autoRefresh;
displayRowCounts = prefs.showRowCounts;
showSys = prefs.showSysTables;
showSchemas = prefs.showSchemas;
gridFormat = prefs.resultGrid;
showTooltips = prefs.showTooltips;
setLF(prefs.laf);
}
// (ulrivo): An actual icon. N.b., this adds some tips to the tip map
fMain.getContentPane().add(createToolBar(), "North");
if (fMain instanceof java.awt.Frame) {
((java.awt.Frame) fMain).setIconImage(CommonSwing.getIcon("Frame"));
}
if (fMain instanceof java.awt.Window) {
((java.awt.Window) fMain).addWindowListener(this);
}
JMenuBar bar = new JMenuBar();
// used shortcuts: CERGTSIUDOLM
String[] fitems = { "-Connect...", "--", "OOpen Script...", "-Save Script...", "-Save Result...", "--", "-Exit" };
jmenu = addMenu(bar, "File", fitems);
// All actions after Connect and the divider are local.
for (int i = 2; i < jmenu.getItemCount(); i++) {
mitem = jmenu.getItem(i);
if (mitem != null) {
localActionList.add(mitem);
}
}
Object[] vitems = { "RRefresh Tree", boxAutoRefresh, "--", boxRowCounts, boxShowSys, boxShowSchemas, boxShowGrid };
addMenu(bar, "View", vitems);
String[] sitems = { "SSELECT", "IINSERT", "UUPDATE", "DDELETE", "EEXECUTE", "---", "-CREATE TABLE", "-DROP TABLE", "-CREATE INDEX", "-DROP INDEX", "--", "CCOMMIT*", "LROLLBACK*", "-CHECKPOINT*", "-SCRIPT", "-SET", "-SHUTDOWN", "--", "-Test Script" };
addMenu(bar, "Command", sitems);
mRecent = new JMenu("Recent");
mRecent.setMnemonic(KeyEvent.VK_R);
bar.add(mRecent);
ButtonGroup lfGroup = new ButtonGroup();
lfGroup.add(rbNativeLF);
lfGroup.add(rbJavaLF);
lfGroup.add(rbMotifLF);
boxShowSchemas.setSelected(showSchemas);
boxShowGrid.setSelected(gridFormat);
boxTooltips.setSelected(showTooltips);
boxShowGrid.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, Event.CTRL_MASK));
boxAutoRefresh.setSelected(autoRefresh);
boxRowCounts.setSelected(displayRowCounts);
boxShowSys.setSelected(showSys);
rbNativeLF.setActionCommand("LFMODE:" + CommonSwing.Native);
rbJavaLF.setActionCommand("LFMODE:" + CommonSwing.Java);
rbMotifLF.setActionCommand("LFMODE:" + CommonSwing.Motif);
tipMap.put(mitemUpdateSchemas, "Refresh the schema list in this menu");
tipMap.put(rbAllSchemas, "Display items in all schemas");
tipMap.put(mitemAbout, "Display product information");
tipMap.put(mitemHelp, "Display advice for obtaining help");
tipMap.put(boxAutoRefresh, "Refresh tree (and schema list) automatically" + "when YOU modify database objects");
tipMap.put(boxShowSchemas, "Display object names in tree like schemaname.basename");
tipMap.put(rbNativeLF, "Set Look and Feel to Native for your platform");
tipMap.put(rbJavaLF, "Set Look and Feel to Java");
tipMap.put(rbMotifLF, "Set Look and Feel to Motif");
boxTooltips.setToolTipText("Display tooltips (hover text), like this");
tipMap.put(boxAutoCommit, "Shows current Auto-commit mode. Click to change");
tipMap.put(boxLogging, "Shows current JDBC DriverManager logging mode. Click to change");
tipMap.put(boxShowSys, "Show system tables in table tree to the left");
tipMap.put(boxShowGrid, "Show query results in grid (in text if off)");
tipMap.put(boxRowCounts, "Show row counts with table names in tree");
boxAutoRefresh.setMnemonic(KeyEvent.VK_C);
boxShowSchemas.setMnemonic(KeyEvent.VK_Y);
boxAutoCommit.setMnemonic(KeyEvent.VK_A);
boxShowSys.setMnemonic(KeyEvent.VK_Y);
boxShowGrid.setMnemonic(KeyEvent.VK_G);
boxRowCounts.setMnemonic(KeyEvent.VK_C);
boxLogging.setMnemonic(KeyEvent.VK_L);
rbAllSchemas.setMnemonic(KeyEvent.VK_ASTERISK);
rbNativeLF.setMnemonic(KeyEvent.VK_N);
rbJavaLF.setMnemonic(KeyEvent.VK_J);
rbMotifLF.setMnemonic(KeyEvent.VK_M);
mitemUpdateSchemas.setMnemonic(KeyEvent.VK_U);
Object[] soptions = { // Added: (weconsultants@users) New menu options
rbNativeLF, rbJavaLF, rbMotifLF, "--", "-Set Fonts", "--", boxAutoCommit, "--", "-Disable MaxRows", "-Set MaxRows to 100", "--", boxLogging, "--", "-Insert test data" };
addMenu(bar, "Options", soptions);
String[] stools = { "-Dump", "-Restore", "-Transfer" };
jmenu = addMenu(bar, "Tools", stools);
jmenu.setEnabled(TT_AVAILABLE);
localActionList.add(jmenu);
for (int i = 0; i < jmenu.getItemCount(); i++) {
mitem = jmenu.getItem(i);
if (mitem != null) {
localActionList.add(mitem);
}
}
mnuSchemas.setMnemonic(KeyEvent.VK_S);
bar.add(mnuSchemas);
JMenu mnuHelp = new JMenu("Help");
mnuHelp.setMnemonic(KeyEvent.VK_H);
mnuHelp.add(mitemAbout);
mnuHelp.add(mitemHelp);
mnuHelp.add(boxTooltips);
rbAllSchemas.addActionListener(schemaListListener);
// May be illegal:
mitemUpdateSchemas.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent) {
updateSchemaList();
}
});
mitemHelp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent) {
JOptionPane.showMessageDialog(fMain.getContentPane(), HELP_TEXT, "HELP", JOptionPane.INFORMATION_MESSAGE);
}
});
mitemAbout.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent) {
JOptionPane.showMessageDialog(fMain.getContentPane(), ABOUT_TEXT, "About", JOptionPane.INFORMATION_MESSAGE);
}
});
boxTooltips.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent actionevent) {
showTooltips = boxTooltips.isSelected();
resetTooltips();
}
});
bar.add(mnuHelp);
if (fMain instanceof JApplet) {
((JApplet) fMain).setJMenuBar(bar);
} else if (fMain instanceof JFrame) {
((JFrame) fMain).setJMenuBar(bar);
}
initGUI();
sRecent = new String[iMaxRecent];
// Modified: (weconsultants@users)Mode code to CommonSwing for general use
if (!(fMain instanceof JApplet)) {
CommonSwing.setFramePositon((JFrame) fMain);
}
// Modified: (weconsultants@users) Changed from deprecated show()
((Component) fMain).setVisible(true);
// (ulrivo): load query from command line
if (defScript != null) {
if (defDirectory != null) {
defScript = defDirectory + File.separator + defScript;
}
// if insert stmet is thousands of records...skip showing it
// as text. Too huge.
sqlScriptBuffer = DatabaseManagerCommon.readFile(defScript);
if (4096 <= sqlScriptBuffer.length()) {
int eoThirdLine = sqlScriptBuffer.indexOf('\n');
if (eoThirdLine > 0) {
eoThirdLine = sqlScriptBuffer.indexOf('\n', eoThirdLine + 1);
}
if (eoThirdLine > 0) {
eoThirdLine = sqlScriptBuffer.indexOf('\n', eoThirdLine + 1);
}
if (eoThirdLine < 1) {
eoThirdLine = 100;
}
txtCommand.setText("............... Script File loaded: " + defScript + " ..................... \n" + "............... Click Execute or Clear " + "...................\n" + sqlScriptBuffer.substring(0, eoThirdLine + 1) + "..........................................." + "..............................\n" + "............................................." + "............................\n");
txtCommand.setEnabled(false);
} else {
txtCommand.setText(sqlScriptBuffer);
sqlScriptBuffer = null;
txtCommand.setEnabled(true);
}
}
// This must be done AFTER all tip texts are put into the map
resetTooltips();
txtCommand.requestFocus();
}
use of javax.swing.JApplet in project voltdb by VoltDB.
the class DatabaseManagerSwing method connect.
/**
* This stuff is all quick, except for the refreshTree().
* This unit can be kicked off in main Gui thread. The refreshTree
* will be backgrounded and this method will return.
*/
public void connect(Connection c) {
schemaFilter = null;
if (c == null) {
return;
}
if (cConn != null) {
try {
cConn.close();
} catch (SQLException e) {
// Added: (weconsultants@users)
CommonSwing.errorMessage(e);
}
}
cConn = c;
// Added: (weconsultants@users) Need to barrow to get the table rowcounts
rowConn = c;
try {
dMeta = cConn.getMetaData();
isOracle = (dMeta.getDatabaseProductName().indexOf("Oracle") >= 0);
sStatement = cConn.createStatement();
updateAutoCommitBox();
// Workaround for EXTREME SLOWNESS getting this info from O.
showIndexDetails = !isOracle;
Driver driver = DriverManager.getDriver(dMeta.getURL());
ConnectionSetting newSetting = new ConnectionSetting(dMeta.getDatabaseProductName(), driver.getClass().getName(), dMeta.getURL(), dMeta.getUserName().replaceAll("@localhost", ""), "");
Hashtable settings = ConnectionDialogCommon.loadRecentConnectionSettings();
ConnectionDialogCommon.addToRecentConnectionSettings(settings, newSetting);
ConnectionDialogSwing.setConnectionSetting(newSetting);
refreshTree();
clearResultPanel();
if (fMain instanceof JApplet) {
getAppletContext().showStatus("JDBC Connection established to a " + dMeta.getDatabaseProductName() + " v. " + dMeta.getDatabaseProductVersion() + " database as '" + dMeta.getUserName() + "'.");
}
} catch (SQLException e) {
// Added: (weconsultants@users)
CommonSwing.errorMessage(e);
} catch (IOException e) {
// Added: (weconsultants@users)
CommonSwing.errorMessage(e);
} catch (Exception e) {
CommonSwing.errorMessage(e);
}
}
use of javax.swing.JApplet in project knime-core by knime.
the class SubnodeLayoutJSONEditorPage method createJSONEditorComposite.
private Composite createJSONEditorComposite(final Composite parent) {
Composite composite = new Composite(parent, SWT.NONE);
composite.setLayout(new GridLayout(1, true));
composite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
if (isWindows()) {
Composite embedComposite = new Composite(composite, SWT.EMBEDDED | SWT.NO_BACKGROUND);
final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 0;
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
gridLayout.horizontalSpacing = 0;
embedComposite.setLayout(gridLayout);
embedComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
Frame frame = SWT_AWT.new_Frame(embedComposite);
Panel heavyWeightPanel = new Panel();
heavyWeightPanel.setLayout(new BoxLayout(heavyWeightPanel, BoxLayout.Y_AXIS));
frame.add(heavyWeightPanel);
frame.setFocusTraversalKeysEnabled(false);
// Use JApplet with JRootPane as layer in between heavyweightPanel and RTextScrollPane
// This reduces flicker on resize in RSyntaxTextArea
JApplet applet = new JApplet();
JRootPane root = applet.getRootPane();
Container contentPane = root.getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
heavyWeightPanel.add(applet);
m_textArea = new RSyntaxTextArea(10, 60);
m_textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JSON);
m_textArea.setCodeFoldingEnabled(true);
m_textArea.setAntiAliasingEnabled(true);
RTextScrollPane sp = new RTextScrollPane(m_textArea);
sp.setDoubleBuffered(true);
m_textArea.setText(m_jsonDocument);
m_textArea.setEditable(true);
m_textArea.setEnabled(true);
contentPane.add(sp);
Dimension size = sp.getPreferredSize();
embedComposite.setSize(size.width, size.height);
// forward focus to RSyntaxTextArea
embedComposite.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
ViewUtils.runOrInvokeLaterInEDT(new Runnable() {
@Override
public void run() {
m_textArea.requestFocus();
m_textArea.setCaretPosition(m_caretPosition);
}
});
}
@Override
public void focusLost(final FocusEvent e) {
// do nothing
}
});
// delete content of status line, when something is inserted or deleted
m_textArea.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void changedUpdate(final DocumentEvent arg0) {
if (!composite.isDisposed()) {
composite.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
if (m_statusLine != null && !m_statusLine.isDisposed()) {
m_statusLine.setText("");
updateModelFromJson();
}
}
});
}
}
@Override
public void insertUpdate(final DocumentEvent arg0) {
/* do nothing */
}
@Override
public void removeUpdate(final DocumentEvent arg0) {
/* do nothing */
}
});
// remember caret position
m_textArea.addCaretListener(new CaretListener() {
@Override
public void caretUpdate(final CaretEvent arg0) {
m_caretPosition = arg0.getDot();
}
});
} else {
m_text = new Text(composite, SWT.MULTI | SWT.BORDER | SWT.WRAP | SWT.V_SCROLL);
GridData layoutData = new GridData(GridData.FILL_BOTH);
layoutData.widthHint = 600;
layoutData.heightHint = 400;
m_text.setLayoutData(layoutData);
m_text.addModifyListener(new ModifyListener() {
@Override
public void modifyText(final ModifyEvent e) {
m_jsonDocument = m_text.getText();
if (m_statusLine != null && !m_statusLine.isDisposed()) {
m_statusLine.setText("");
updateModelFromJson();
}
}
});
m_text.setText(m_jsonDocument);
}
// add status line
m_statusLine = new Label(composite, SWT.SHADOW_NONE | SWT.WRAP);
GridData statusGridData = new GridData(SWT.LEFT | SWT.FILL, SWT.BOTTOM, true, false);
int maxHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(3);
statusGridData.heightHint = maxHeight + 5;
// seems to have no impact on the layout. The height will still be 3 rows (at least on Windows 8)
statusGridData.minimumHeight = new PixelConverter(m_statusLine).convertHeightInCharsToPixels(1);
m_statusLine.setLayoutData(statusGridData);
compareNodeIDs();
return composite;
}
Aggregations