public void mouseEntered(MouseEvent evt) { if (list != null) { TransferHandler th1 = getFileChooser().getTransferHandler(); TransferHandler th2 = list.getTransferHandler(); if (th1 != th2) { list.setTransferHandler(th1); } if (getFileChooser().getDragEnabled() != list.getDragEnabled()) { list.setDragEnabled(getFileChooser().getDragEnabled()); } } }
public SwingDnDFrame() { setTitle("SwingDnDTest"); JTabbedPane tabbedPane = new JTabbedPane(); JList list = SampleComponents.list(); tabbedPane.addTab("List", list); JTable table = SampleComponents.table(); tabbedPane.addTab("Table", table); JTree tree = SampleComponents.tree(); tabbedPane.addTab("Tree", tree); JFileChooser fileChooser = new JFileChooser(); tabbedPane.addTab("File Chooser", fileChooser); JColorChooser colorChooser = new JColorChooser(); tabbedPane.addTab("Color Chooser", colorChooser); final JTextArea textArea = new JTextArea(4, 40); JScrollPane scrollPane = new JScrollPane(textArea); scrollPane.setBorder(new TitledBorder(new EtchedBorder(), "Drag text here")); JTextField textField = new JTextField("Drag color here"); textField.setTransferHandler(new TransferHandler("background")); tabbedPane.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { textArea.setText(""); } }); tree.setDragEnabled(true); table.setDragEnabled(true); list.setDragEnabled(true); fileChooser.setDragEnabled(true); colorChooser.setDragEnabled(true); textField.setDragEnabled(true); add(tabbedPane, BorderLayout.NORTH); add(scrollPane, BorderLayout.CENTER); add(textField, BorderLayout.SOUTH); pack(); }
public SQLiteDataBrowser() { SQLiteDbManager dbManager = new SQLiteDbManager(); setLayout(new BorderLayout()); showTablesList = new JList(); showTablesList.setLayoutOrientation(JList.VERTICAL_WRAP); showTablesList.setSelectedIndex(ListSelectionModel.SINGLE_SELECTION); showTablesList.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); showTablesList.setFont(new Font("Times New Roman", Font.PLAIN, 13)); showTablesList.setDragEnabled(false); showTablesList.setFixedCellWidth(150); showTablesList.setVisibleRowCount(-1); showTablesList.setEnabled(false); showTablesListScroller = new JScrollPane(showTablesList); showTablesListScroller.setBorder( BorderFactory.createTitledBorder(new LineBorder(Color.BLACK), "List of Tables")); showTablesListScroller.setPreferredSize(new Dimension(160, this.getHeight())); add(showTablesListScroller, BorderLayout.EAST); loadDbPanel = new JPanel(new FlowLayout()); loadDbPanel.setBackground(new Color(0xe8e8e8)); loadDbPanel.setPreferredSize(new Dimension(getWidth(), 40)); loadDbLabel = new JLabel("Load SQLite Database: "); loadDbLabel.setToolTipText("Possible extensions being .sqlite|.sqlite3|.db|.db3"); loadedDbPath = new JTextField("Click browse to choose the database file.", 60); loadedDbPath.setForeground(Color.GRAY); loadedDbPath.setFont(new Font("Times New Roman", Font.ITALIC, 13)); loadedDbPath.setEditable(false); lastFolderLocation = new File(Utils.getUserHome()); fc = new JFileChooser(lastFolderLocation); browseDb = new JButton("Browse"); browseDb.addActionListener( actionEvent -> { int retVal = fc.showOpenDialog(SQLiteDataBrowser.this); if (retVal == JFileChooser.APPROVE_OPTION) { File dbPath = fc.getSelectedFile(); if (Utils.checkIfSQLiteDb(dbPath)) { loadedDbPath.setText(dbPath.toString()); lastFolderLocation = fc.getCurrentDirectory(); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { dbManager.setDbPath(dbPath.toString()); dbManager.initialize(); showTablesList.setListData(dbManager.getTables().toArray()); showTablesList.setEnabled(true); } catch (SQLException e) { e.printStackTrace(); } return null; } }.execute(); } else { JOptionPane.showMessageDialog( SQLiteDataBrowser.this, "The Selected file is not in SQLite Format", "File Format Error", JOptionPane.ERROR_MESSAGE); loadedDbPath.setText("Click browse to choose the database file."); } } }); loadDbPanel.add(loadDbLabel); loadDbPanel.add(loadedDbPath); loadDbPanel.add(browseDb); loadDbRecords = new JLabel("Records Fetched (Rows x Cols): "); loadDbRecords.setFont(new Font("Times New Roman", Font.ITALIC, 12)); loadDbPanel.add(loadDbRecords); loadDbRecordsCount = new JLabel(); loadDbRecordsCount.setFont(new Font("Times New Roman", Font.ITALIC, 12)); loadDbPanel.add(loadDbRecordsCount); final class DataBrowserTableModal extends DefaultTableModel { public DataBrowserTableModal() {} public DataBrowserTableModal(Object[][] tableData, Object[] colNames) { super(tableData, colNames); } @Override public void setDataVector(Object[][] tableData, Object[] colNames) { super.setDataVector(tableData, colNames); } @Override public boolean isCellEditable(int row, int column) { return false; } } DataBrowserTableModal tableModal = new DataBrowserTableModal(); defaultTableModel = tableModal; table = new JTable(); table.setModel(defaultTableModel); showTablesList.addMouseListener( new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { JList list = (JList) evt.getSource(); if (evt.getClickCount() == 2) { String tableName = list.getSelectedValue().toString(); new SwingWorker<Void, Void>() { @Override protected Void doInBackground() throws Exception { try { ResultSet rs = dbManager.executeQuery("SELECT * from " + tableName); Vector<String> columnNames = dbManager.getColumnNames(rs); Vector<Vector<Object>> tableData = new Vector<>(); while (rs.next()) { Vector<Object> vector = new Vector<>(); for (int i = 1; i <= columnNames.size(); i++) { vector.add(rs.getObject(i)); } tableData.add(vector); } defaultTableModel.setDataVector(tableData, columnNames); } catch (SQLException e) { e.printStackTrace(); } loadDbRecordsCount.setText( defaultTableModel.getRowCount() + " x " + defaultTableModel.getColumnCount()); if (defaultTableModel.getColumnCount() < 5) { table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); } else { table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); } return null; } }.execute(); } } }); tableScrollPane = new JScrollPane(table); tableScrollPane.setHorizontalScrollBarPolicy( ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); tableScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); tableScrollPane.setPreferredSize(new Dimension(getWidth(), getHeight())); add(tableScrollPane, BorderLayout.CENTER); add(loadDbPanel, BorderLayout.NORTH); }
public ShowResults(SharkPanel _sp, String _files[], double _scores[], int _nrpairs[]) { sp = _sp; files = _files; scores = _scores; nrpairs = _nrpairs; LogFile lf = new LogFile("SearchResults_"); DefaultListModel listModel = new DefaultListModel(); for (int i = 0; i < files.length; i++) { GetImageFile gif = new GetImageFile(files[i]); Integer ii = new Integer(_nrpairs[i]); int tmpval = (int) (1000.0 * _scores[i]); Double dd = new Double((double) tmpval / 1000.0); String tmp = gif.getImageString(); String s = tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length()) + "\t" + ii.toString() + "\t" + dd.toString(); String ddval = dd.toString(); while (ddval.length() < 5) ddval += "0"; if (i < 9) listModel.addElement( " " + (i + 1) + ". " + ddval + " " + tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length())); else listModel.addElement( (i + 1) + ". " + ddval + " " + tmp.substring(tmp.lastIndexOf('\\') + 1, tmp.length())); lf.write(s); } lf.close(); setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); list = new JList(listModel); list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.setDragEnabled(false); list.addMouseListener(new MouseClickListener()); JScrollPane listView = new JScrollPane(list); listView.setPreferredSize(new Dimension(250, 250)); showButton = new JButton("Visual comparison"); showButton.addActionListener(this); showButton.setMnemonic('V'); showButton.setEnabled(false); JButton closeButton = new JButton("Close"); closeButton.addActionListener(this); closeButton.setMnemonic('C'); JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); panel.add(listView, BorderLayout.CENTER); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); JPanel panel2 = new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS)); panel2.add(showButton); panel2.add(Box.createRigidArea(new Dimension(10, 1))); panel2.add(closeButton); add(panel); add(Box.createRigidArea(new Dimension(1, 10))); add(panel2); if (frame != null) frame.dispose(); frame = new JFrame("I3S: Search results"); frame.setContentPane(this); frame.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.dispose(); frame = null; } }); frame.setSize(new Dimension(400, 300)); frame.setLocation(200, 200); ImageIcon imageIcon = new ImageIcon(this.getClass().getResource("/Simages/icon.gif")); frame.setIconImage(imageIcon.getImage()); frame.pack(); frame.setVisible(true); }
public ThumbMaker() { super("ThumbMaker"); // grab the preferences so that they can be used to fill out the layout ThumbMakerPreferences myPrefs = ThumbMakerPreferences.getInstance(); // content pane JPanel pane = new JPanel(); pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS)); setContentPane(pane); // top panel JPanel top = new JPanel(); top.setLayout(new BoxLayout(top, BoxLayout.X_AXIS)); pane.add(top); // left-hand panel JPanel left = new JPanel(); left.setLayout(new BoxLayout(left, BoxLayout.Y_AXIS)); top.add(left); // horizontal padding top.add(Box.createHorizontalStrut(5)); // label for file list JLabel listLabel = GUIUtil.makeLabel("Files to process:"); listLabel.setDisplayedMnemonic('f'); String listTip = "List of files from which to create thumbnails"; listLabel.setToolTipText(listTip); left.add(GUIUtil.pad(listLabel)); // list of files to convert list = new JList(); listLabel.setLabelFor(list); list.setToolTipText(listTip); list.setModel(new DefaultListModel()); list.setDragEnabled(true); changeFilesInList = new ThumbTransferHandler(); list.setTransferHandler(changeFilesInList); left.add(new JScrollPane(list)); // progress bar progress = new JProgressBar(0, 1); progress.setString("[Drag and drop files onto list to begin]"); progress.setStringPainted(true); progress.setToolTipText("Status of thumbnail processing operation"); left.add(progress); // panel for process and remove buttons JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); // add files button addFiles = new JButton("Add Files"); addFiles.setMnemonic('d'); addFiles.setToolTipText("Add files to be processed."); addFiles.addActionListener(this); p.add(addFiles); p.add(Box.createHorizontalStrut(5)); // process button process = new JButton("Process"); process.setMnemonic('p'); process.setToolTipText("Begin creating thumbnails"); process.addActionListener(this); p.add(process); p.add(Box.createHorizontalStrut(5)); // remove button remove = new JButton("Remove"); remove.setMnemonic('v'); remove.setToolTipText("Remove selected files from the list"); remove.addActionListener(this); p.add(remove); left.add(GUIUtil.pad(p)); // right-hand panel JPanel right = new JPanel(); right.setLayout(new BoxLayout(right, BoxLayout.Y_AXIS)); top.add(right); // panel for resolution settings p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); // resolution label JLabel resLabel = GUIUtil.makeLabel("Resolution: "); resLabel.setDisplayedMnemonic('s'); resLabel.setToolTipText("Resolution of the thumbnails"); p.add(resLabel); // x resolution text box xres = GUIUtil.makeTextField(myPrefs.getStringPref(ThumbMakerPreferences.RES_WIDTH_PREF_NAME), 2); resLabel.setLabelFor(xres); xres.setToolTipText("Thumbnail width"); p.add(xres); // "by" label JLabel byLabel = GUIUtil.makeLabel(" by "); byLabel.setDisplayedMnemonic('y'); p.add(byLabel); // y resolution text box yres = GUIUtil.makeTextField(myPrefs.getStringPref(ThumbMakerPreferences.RES_HEIGHT_PREF_NAME), 2); byLabel.setLabelFor(yres); yres.setToolTipText("Thumbnail height"); p.add(yres); right.add(GUIUtil.pad(p)); right.add(Box.createVerticalStrut(8)); // aspect ratio checkbox aspect = new JCheckBox("Maintain aspect ratio", true); aspect.setMnemonic('m'); aspect.setToolTipText( "When checked, thumbnails are not stretched, " + "but rather padded with the background color."); aspect.addActionListener(this); right.add(GUIUtil.pad(aspect)); // make sure that the check box is initialized correctly aspect.setSelected( myPrefs .getStringPref(ThumbMakerPreferences.DO_MAINTAIN_ASPECT_PREF_NAME) .equalsIgnoreCase(ThumbMakerPreferences.BOOLEAN_TRUE_STRING)); // panel for background color p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); // load the color values from the preferences int redValueNumber = myPrefs.getIntegerPref(ThumbMakerPreferences.RED_VALUE_PREF_NAME); int greenValueNumber = myPrefs.getIntegerPref(ThumbMakerPreferences.GREEN_VALUE_PREF_NAME); int blueValueNumber = myPrefs.getIntegerPref(ThumbMakerPreferences.BLUE_VALUE_PREF_NAME); // background color label colorLabel = GUIUtil.makeLabel("Background color: "); String colorTip = "Thumbnail background color"; colorLabel.setToolTipText(colorTip); p.add(colorLabel); // background color colorBox = new JPanel(); colorBox.setToolTipText(colorTip); colorBox.setBorder(new LineBorder(Color.black, 1)); Dimension colorBoxSize = new Dimension(45, 15); colorBox.setMaximumSize(colorBoxSize); colorBox.setMinimumSize(colorBoxSize); colorBox.setPreferredSize(colorBoxSize); colorBox.setBackground(new Color(redValueNumber, greenValueNumber, blueValueNumber)); p.add(colorBox); right.add(GUIUtil.pad(p)); right.add(Box.createVerticalStrut(2)); // red slider redLabel = GUIUtil.makeLabel("R"); red = new JSlider(0, 255, redValueNumber); redValue = GUIUtil.makeLabel("" + redValueNumber); redValue.setToolTipText("Red color component slider"); right.add(makeSlider(redLabel, red, redValue, "Red")); // green slider greenLabel = GUIUtil.makeLabel("G"); green = new JSlider(0, 255, greenValueNumber); greenValue = GUIUtil.makeLabel("" + greenValueNumber); greenValue.setToolTipText("Green color component slider"); right.add(makeSlider(greenLabel, green, greenValue, "Green")); // blue slider blueLabel = GUIUtil.makeLabel("B"); blue = new JSlider(0, 255, blueValueNumber); blueValue = GUIUtil.makeLabel("" + blueValueNumber); right.add(makeSlider(blueLabel, blue, blueValue, "Blue")); right.add(Box.createVerticalStrut(8)); // panel for algorithm p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); // algorithm label JLabel algorithmLabel = GUIUtil.makeLabel("Algorithm: "); algorithmLabel.setDisplayedMnemonic('l'); String algorithmTip = "Resizing algorithm to use"; algorithmLabel.setToolTipText(algorithmTip); p.add(algorithmLabel); // algorithm combo box algorithm = GUIUtil.makeComboBox( new String[] {"Smooth", "Standard", "Fast", "Replicate", "Area averaging"}); algorithmLabel.setLabelFor(algorithm); algorithm.setToolTipText(algorithmTip); p.add(algorithm); // set the algorithm value from the preferences algorithm.setSelectedIndex(myPrefs.getIntegerPref(ThumbMakerPreferences.RESIZE_ALG_PREF_NAME)); right.add(GUIUtil.pad(p)); // panel for output format p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); // format label JLabel formatLabel = GUIUtil.makeLabel("Format: "); formatLabel.setDisplayedMnemonic('f'); String formatTip = "Thumbnail output format"; formatLabel.setToolTipText(formatTip); p.add(formatLabel); // format combo box format = GUIUtil.makeComboBox(new String[] {"PNG", "JPG"}); formatLabel.setLabelFor(format); format.setToolTipText(formatTip); p.add(format); // set the format value from the preferences format.setSelectedIndex(myPrefs.getIntegerPref(ThumbMakerPreferences.THUMB_FORMAT_PREF_NAME)); right.add(GUIUtil.pad(p)); right.add(Box.createVerticalStrut(5)); // panel for prepend string p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); // prepend label JLabel prependLabel = GUIUtil.makeLabel("Prepend: "); prependLabel.setDisplayedMnemonic('e'); String prependTip = "Starting string for each thumbnail filename"; prependLabel.setToolTipText(prependTip); p.add(prependLabel); // prepend field prepend = GUIUtil.makeTextField( myPrefs.getStringPref(ThumbMakerPreferences.STRING_TO_PREPEND_PREF_NAME), 4); prependLabel.setLabelFor(prepend); prepend.setToolTipText(prependTip); p.add(prepend); p.add(Box.createHorizontalStrut(5)); // append label JLabel appendLabel = GUIUtil.makeLabel("Append: "); appendLabel.setDisplayedMnemonic('a'); String appendTip = "Ending string for each thumbnail filename"; appendLabel.setToolTipText(appendTip); p.add(appendLabel); // append field append = GUIUtil.makeTextField( myPrefs.getStringPref(ThumbMakerPreferences.STRING_TO_APPEND_PREF_NAME), 4); appendLabel.setLabelFor(append); append.setToolTipText(appendTip); p.add(append); right.add(GUIUtil.pad(p)); // vertical padding right.add(Box.createVerticalGlue()); // bottom panel JPanel bottom = new JPanel(); bottom.setLayout(new BoxLayout(bottom, BoxLayout.X_AXIS)); pane.add(bottom); // output folder label JLabel outputLabel = GUIUtil.makeLabel("Output folder: "); outputLabel.setDisplayedMnemonic('o'); String outputTip = "Thumbnail output folder"; outputLabel.setToolTipText(outputTip); bottom.add(outputLabel); // output folder field String filePath = new File(myPrefs.getStringPref(ThumbMakerPreferences.FILE_PATH_STRING_PREF_NAME)) .getAbsolutePath(); output = GUIUtil.makeTextField(filePath, 8); outputLabel.setLabelFor(output); output.setToolTipText(outputTip); // start this in default and then lock down so "..." is used output.setEditable(false); output.setBackground(Color.LIGHT_GRAY); bottom.add(output); // add a file chooser button "..." dotDotDot = new JButton("..."); dotDotDot.setMnemonic('.'); dotDotDot.setToolTipText("Select destination directory."); dotDotDot.addActionListener(this); bottom.add(dotDotDot); right.add(GUIUtil.pad(p)); setFromPreferences(); addWindowListener(this); }
JPanel getPanel(int infoWidth, int infoHeight) { //For layout purposes, put things in separate panels //Create the list and list view to handle the list of //Jmol Instances. instanceList = new JList(new DefaultListModel()); instanceList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); instanceList.setTransferHandler(new ArrayListTransferHandler(this)); instanceList.setCellRenderer(new InstanceCellRenderer()); instanceList.setDragEnabled(true); instanceList.setPreferredSize(new Dimension(350, 200)); JScrollPane instanceListView = new JScrollPane(instanceList); instanceListView.setPreferredSize(new Dimension(350, 200)); JPanel instanceSet = new JPanel(); instanceSet.setLayout(new BorderLayout()); instanceSet.add(new JLabel(listLabel), BorderLayout.NORTH); instanceSet.add(instanceListView, BorderLayout.CENTER); instanceSet.add(new JLabel(GT._("double-click and drag to reorder")), BorderLayout.SOUTH); //Create the Instance add button. addInstanceButton = new JButton(GT._("Add Present Jmol State as Instance...")); addInstanceButton.addActionListener(this); JPanel buttonPanel = new JPanel(); buttonPanel.setMaximumSize(new Dimension(350, 50)); showInstanceButton = new JButton(GT._("Show Selected")); showInstanceButton.addActionListener(this); deleteInstanceButton = new JButton(GT._("Delete Selected")); deleteInstanceButton.addActionListener(this); buttonPanel.add(showInstanceButton); buttonPanel.add(deleteInstanceButton); // width height or %width JPanel paramPanel = appletParamPanel(); paramPanel.setMaximumSize(new Dimension(350, 70)); //Instance selection JPanel instanceButtonPanel = new JPanel(); instanceButtonPanel.add(addInstanceButton); instanceButtonPanel.setSize(300, 70); JPanel p = new JPanel(); p.setLayout(new BorderLayout()); p.add(instanceButtonPanel, BorderLayout.NORTH); p.add(buttonPanel, BorderLayout.SOUTH); JPanel instancePanel = new JPanel(); instancePanel.setLayout(new BorderLayout()); instancePanel.add(instanceSet, BorderLayout.CENTER); instancePanel.add(p, BorderLayout.SOUTH); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BorderLayout()); rightPanel.setMinimumSize(new Dimension(350, 350)); rightPanel.setMaximumSize(new Dimension(350, 1000)); rightPanel.add(paramPanel, BorderLayout.NORTH); rightPanel.add(instancePanel, BorderLayout.CENTER); rightPanel.setBorder(BorderFactory.createTitledBorder(GT._("Jmol Instances:"))); //Create the overall panel JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); JPanel leftPanel = getLeftPanel(infoWidth, infoHeight); leftPanel.setMaximumSize(new Dimension(350, 1000)); //Add everything to this panel. panel.add(leftPanel, BorderLayout.CENTER); panel.add(rightPanel, BorderLayout.EAST); enableButtons(instanceList); return panel; }