Mercurial > hg > ltpda-connection-manager
changeset 7:ea3ae6ce9fea default tip
Improved Java interface look.
author | Daniele Nicolodi <daniele@grinta.net> |
---|---|
date | Wed, 23 Nov 2011 20:27:21 +0100 |
parents | 670905eb688a |
children | |
files | ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.form ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.java |
diffstat | 2 files changed, 132 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.form Wed Jun 02 18:02:25 2010 +0200 +++ b/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.form Wed Nov 23 20:27:21 2011 +0100 @@ -1,13 +1,17 @@ <?xml version="1.0" encoding="UTF-8" ?> -<Form version="1.3" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> +<Form version="1.6" maxVersion="1.7" type="org.netbeans.modules.form.forminfo.JDialogFormInfo"> <Properties> <Property name="defaultCloseOperation" type="int" value="2"/> - <Property name="title" type="java.lang.String" value="Select a connection"/> + <Property name="title" type="java.lang.String" value="Select database"/> + <Property name="resizable" type="boolean" value="false"/> </Properties> <SyntheticProperties> <SyntheticProperty name="formSizePolicy" type="int" value="1"/> </SyntheticProperties> + <Events> + <EventHandler event="keyPressed" listener="java.awt.event.KeyListener" parameters="java.awt.event.KeyEvent" handler="formKeyPressed"/> + </Events> <AuxValues> <AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="0"/> <AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/> @@ -23,20 +27,17 @@ <Layout> <DimensionLayout dim="0"> <Group type="103" groupAlignment="0" attributes="0"> - <Group type="102" attributes="0"> - <Group type="103" groupAlignment="0" attributes="0"> + <Group type="102" alignment="1" attributes="0"> + <EmptySpace max="-2" attributes="0"/> + <Group type="103" groupAlignment="1" attributes="0"> + <Component id="scrollPane" alignment="0" pref="409" max="32767" attributes="0"/> <Group type="102" alignment="1" attributes="0"> - <EmptySpace min="-2" pref="183" max="-2" attributes="0"/> - <Component id="cancelButton" max="32767" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> <Component id="newButton" max="32767" attributes="0"/> - <EmptySpace max="-2" attributes="0"/> + <EmptySpace min="-2" pref="184" max="-2" attributes="0"/> + <Component id="cancelButton" max="32767" attributes="0"/> + <EmptySpace type="unrelated" max="-2" attributes="0"/> <Component id="selectButton" max="32767" attributes="0"/> </Group> - <Group type="102" alignment="1" attributes="0"> - <EmptySpace max="-2" attributes="0"/> - <Component id="jScrollPane1" pref="400" max="32767" attributes="0"/> - </Group> </Group> <EmptySpace max="-2" attributes="0"/> </Group> @@ -45,15 +46,15 @@ <DimensionLayout dim="1"> <Group type="103" groupAlignment="0" attributes="0"> <Group type="102" alignment="1" attributes="0"> - <EmptySpace pref="20" max="32767" attributes="0"/> - <Component id="jScrollPane1" min="-2" pref="225" max="-2" attributes="0"/> <EmptySpace max="-2" attributes="0"/> + <Component id="scrollPane" pref="212" max="32767" attributes="0"/> + <EmptySpace type="separate" max="-2" attributes="0"/> <Group type="103" groupAlignment="2" attributes="0"> + <Component id="newButton" alignment="2" min="-2" max="-2" attributes="0"/> <Component id="selectButton" alignment="2" min="-2" max="-2" attributes="0"/> - <Component id="newButton" alignment="2" min="-2" max="-2" attributes="0"/> <Component id="cancelButton" alignment="2" min="-2" max="-2" attributes="0"/> </Group> - <EmptySpace min="-2" pref="207" max="-2" attributes="0"/> + <EmptySpace max="-2" attributes="0"/> </Group> </Group> </DimensionLayout> @@ -83,7 +84,7 @@ <EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="selectButtonActionPerformed"/> </Events> </Component> - <Container class="javax.swing.JScrollPane" name="jScrollPane1"> + <Container class="javax.swing.JScrollPane" name="scrollPane"> <AuxValues> <AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/> </AuxValues> @@ -93,12 +94,55 @@ <Component class="javax.swing.JTable" name="databasesTable"> <Properties> <Property name="model" type="javax.swing.table.TableModel" editor="org.netbeans.modules.form.editors2.TableModelEditor"> - <Table columnCount="3" rowCount="0"> - <Column editable="false" title="Hostname" type="java.lang.String"/> + <Table columnCount="3" rowCount="8"> + <Column editable="false" title="Hostname" type="java.lang.String"> + <Data value="1"/> + <Data value="2"/> + <Data value="3"/> + <Data value="4"/> + <Data value="5"/> + <Data value="6"/> + <Data value="7"/> + <Data value="8"/> + </Column> <Column editable="false" title="Database" type="java.lang.String"/> <Column editable="false" title="Username" type="java.lang.String"/> </Table> </Property> + <Property name="columnModel" type="javax.swing.table.TableColumnModel" editor="org.netbeans.modules.form.editors2.TableColumnModelEditor"> + <TableColumnModel selectionModel="0"> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + <Column maxWidth="-1" minWidth="-1" prefWidth="-1" resizable="true"> + <Title/> + <Editor/> + <Renderer/> + </Column> + </TableColumnModel> + </Property> + <Property name="focusable" type="boolean" value="false"/> + <Property name="gridColor" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor"> + <Color blue="cc" green="cc" red="cc" type="rgb"/> + </Property> + <Property name="intercellSpacing" type="java.awt.Dimension" editor="org.netbeans.beaninfo.editors.DimensionEditor"> + <Dimension value="[0, 0]"/> + </Property> + <Property name="rowHeight" type="int" value="24"/> + <Property name="selectionModel" type="javax.swing.ListSelectionModel" editor="org.netbeans.modules.form.editors2.JTableSelectionModelEditor"> + <JTableSelectionModel selectionMode="0"/> + </Property> + <Property name="showVerticalLines" type="boolean" value="false"/> + <Property name="tableHeader" type="javax.swing.table.JTableHeader" editor="org.netbeans.modules.form.editors2.JTableHeaderEditor"> + <TableHeader reorderingAllowed="true" resizingAllowed="true"/> + </Property> </Properties> </Component> </SubComponents>
--- a/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.java Wed Jun 02 18:02:25 2010 +0200 +++ b/ConnectionManager/src/connectionmanager/DatabaseSelectorDialog.java Wed Nov 23 20:27:21 2011 +0100 @@ -1,9 +1,21 @@ package connectionmanager; +import java.awt.Component; import java.awt.Point; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; +import javax.swing.JLabel; +import javax.swing.JTable; import javax.swing.table.DefaultTableModel; +import javax.swing.table.DefaultTableCellRenderer; + + +class CellRenderer extends DefaultTableCellRenderer { + public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { + return super.getTableCellRendererComponent(table, value, isSelected, false, row, column); + } +} + public class DatabaseSelectorDialog extends javax.swing.JDialog { @@ -15,12 +27,16 @@ public DatabaseSelectorDialog(java.awt.Frame parent) { super(parent, true); initComponents(); + getRootPane().setDefaultButton(selectButton); + databasesTable.setDefaultRenderer(Object.class, new CellRenderer()); databasesTable.addMouseListener(new MouseListenerDoubleClick()); } public DatabaseSelectorDialog() { super(new javax.swing.JFrame(), true); initComponents(); + getRootPane().setDefaultButton(selectButton); + databasesTable.setDefaultRenderer(Object.class, new CellRenderer()); databasesTable.addMouseListener(new MouseListenerDoubleClick()); } @@ -48,11 +64,17 @@ cancelButton = new javax.swing.JButton(); newButton = new javax.swing.JButton(); selectButton = new javax.swing.JButton(); - jScrollPane1 = new javax.swing.JScrollPane(); + scrollPane = new javax.swing.JScrollPane(); databasesTable = new javax.swing.JTable(); setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); - setTitle("Select a connection"); + setTitle("Select database"); + setResizable(false); + addKeyListener(new java.awt.event.KeyAdapter() { + public void keyPressed(java.awt.event.KeyEvent evt) { + formKeyPressed(evt); + } + }); cancelButton.setText("Cancel"); cancelButton.addActionListener(new java.awt.event.ActionListener() { @@ -77,7 +99,14 @@ databasesTable.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { - + {"1", null, null}, + {"2", null, null}, + {"3", null, null}, + {"4", null, null}, + {"5", null, null}, + {"6", null, null}, + {"7", null, null}, + {"8", null, null} }, new String [] { "Hostname", "Database", "Username" @@ -98,37 +127,41 @@ return canEdit [columnIndex]; } }); - jScrollPane1.setViewportView(databasesTable); + databasesTable.setFocusable(false); + databasesTable.setGridColor(new java.awt.Color(204, 204, 204)); + databasesTable.setIntercellSpacing(new java.awt.Dimension(0, 0)); + databasesTable.setRowHeight(24); + databasesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); + databasesTable.setShowVerticalLines(false); + scrollPane.setViewportView(databasesTable); org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(layout.createSequentialGroup() - .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) - .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .add(183, 183, 183) + .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() + .addContainerGap() + .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) + .add(org.jdesktop.layout.GroupLayout.LEADING, scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 409, Short.MAX_VALUE) + .add(layout.createSequentialGroup() + .add(newButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .add(184, 184, 184) .add(cancelButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(newButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) - .add(selectButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .addContainerGap() - .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))) + .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED) + .add(selectButton, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup() - .addContainerGap(20, Short.MAX_VALUE) - .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 225, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) - .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) + .addContainerGap() + .add(scrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 212, Short.MAX_VALUE) + .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.CENTER) + .add(newButton) .add(selectButton) - .add(newButton) .add(cancelButton)) - .add(207, 207, 207)) + .addContainerGap()) ); pack(); @@ -161,6 +194,20 @@ } }//GEN-LAST:event_newButtonActionPerformed + private void formKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formKeyPressed + System.out.printf("key %d is %d\n", evt.getKeyCode(), evt.VK_DOWN); + if (evt.getKeyCode() == evt.VK_DOWN) { + int row = databasesTable.getSelectedRow() + 1; + databasesTable.addRowSelectionInterval(row, row); + return; + } + if (evt.getKeyCode() == evt.VK_UP) { + int row = databasesTable.getSelectedRow() - 1; + databasesTable.addRowSelectionInterval(row, row); + return; + } + }//GEN-LAST:event_formKeyPressed + private void doClose() { setVisible(false); dispose(); @@ -169,13 +216,14 @@ public void add(String hostname, String database, String username) { DefaultTableModel model = (DefaultTableModel) databasesTable.getModel(); model.insertRow(model.getRowCount(), new Object[]{hostname, database, username}); + databasesTable.addRowSelectionInterval(0, 0); } // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton cancelButton; private javax.swing.JTable databasesTable; - private javax.swing.JScrollPane jScrollPane1; private javax.swing.JButton newButton; + private javax.swing.JScrollPane scrollPane; private javax.swing.JButton selectButton; // End of variables declaration//GEN-END:variables }