List of usage examples for java.awt GridBagConstraints NONE
int NONE
To view the source code for java.awt GridBagConstraints NONE.
Click Source Link
From source file:org.openmicroscopy.shoola.agents.metadata.editor.UserProfile.java
/** * Builds the panel hosting the user's details. * //from ww w .j a v a 2 s.c om * @return See above. */ private JPanel buildContentPanel() { ExperimenterData user = (ExperimenterData) model.getRefObject(); boolean editable = model.isUserOwner(user); if (!editable) editable = MetadataViewerAgent.isAdministrator(); details = EditorUtil.convertExperimenter(user); JPanel content = new JPanel(); content.setBorder(BorderFactory.createTitledBorder("User")); content.setBackground(UIUtilities.BACKGROUND_COLOR); Entry<String, String> entry; Iterator<Entry<String, String>> i = details.entrySet().iterator(); JComponent label; JTextField area; String key, value; content.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.WEST; c.insets = new Insets(0, 2, 2, 0); //Add log in name but cannot edit. c.gridx = 0; c.gridy = 0; c.gridwidth = GridBagConstraints.REMAINDER;//end row c.fill = GridBagConstraints.HORIZONTAL; content.add(buildProfileCanvas(), c); c.gridy++; c.gridx = 0; label = EditorUtil.getLabel(EditorUtil.DISPLAY_NAME, true); label.setBackground(UIUtilities.BACKGROUND_COLOR); c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE;//reset to default c.weightx = 0.0; content.add(label, c); c.gridx++; content.add(Box.createHorizontalStrut(5), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER;//end row c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; loginArea.setText(user.getUserName()); loginArea.setEnabled(false); loginArea.setEditable(false); if (MetadataViewerAgent.isAdministrator() && !model.isSystemUser(user.getId()) && !model.isSelf()) { loginArea.setEnabled(true); loginArea.getDocument().addDocumentListener(this); } content.add(loginArea, c); while (i.hasNext()) { ++c.gridy; c.gridx = 0; entry = i.next(); key = entry.getKey(); value = entry.getValue(); label = EditorUtil.getLabel(key, EditorUtil.FIRST_NAME.equals(key) || EditorUtil.LAST_NAME.equals(key)); area = new JTextField(value); area.setBackground(UIUtilities.BACKGROUND_COLOR); area.setEditable(editable); area.setEnabled(editable); if (editable) area.getDocument().addDocumentListener(this); items.put(key, area); label.setBackground(UIUtilities.BACKGROUND_COLOR); c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE;//reset to default c.weightx = 0.0; content.add(label, c); c.gridx++; content.add(Box.createHorizontalStrut(5), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER;//end row c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; content.add(area, c); } c.gridx = 0; c.gridy++; label = EditorUtil.getLabel(EditorUtil.DEFAULT_GROUP, false); c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE;//reset to default c.weightx = 0.0; content.add(label, c); c.gridx++; content.add(Box.createHorizontalStrut(5), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; content.add(groupsBox, c); c.gridy++; content.add(permissionsPane, c); c.gridx = 0; c.gridy++; label = EditorUtil.getLabel(EditorUtil.GROUP_OWNER, false); c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE; //reset to default c.weightx = 0.0; content.add(label, c); c.gridx++; content.add(Box.createHorizontalStrut(5), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; //end row c.fill = GridBagConstraints.NONE; c.weightx = 1.0; content.add(ownerBox, c); if (activeBox.isVisible()) { c.gridx = 0; c.gridy++; label = EditorUtil.getLabel(EditorUtil.ACTIVE, false); c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE; c.weightx = 0.0; content.add(label, c); c.gridx++; content.add(Box.createHorizontalStrut(5), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.NONE; c.weightx = 1.0; content.add(activeBox, c); } if (adminBox.isVisible()) { c.gridx = 0; c.gridy++; label = EditorUtil.getLabel(EditorUtil.ADMINISTRATOR, false); c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE; c.weightx = 0.0; content.add(label, c); c.gridx++; content.add(Box.createHorizontalStrut(5), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.NONE; c.weightx = 1.0; content.add(adminBox, c); } c.gridx = 0; c.gridy++; content.add(Box.createHorizontalStrut(10), c); c.gridy++; label = UIUtilities.setTextFont(EditorUtil.MANDATORY_DESCRIPTION, Font.ITALIC); label.setForeground(UIUtilities.REQUIRED_FIELDS_COLOR); c.weightx = 0.0; content.add(label, c); return content; }
From source file:uk.ac.ucl.chem.ccs.clinicalgui.DisplayJobPanel.java
private void initGUI() { if (ajo == null) { try {/*from ww w . ja v a 2 s . c o m*/ setPreferredSize(new Dimension(400, 300)); } catch (Exception e) { e.printStackTrace(); } //JLabel l = new JLabel("No simulation running"); //this.add(l); //this.setEnabled(false); return; } System.out.println("I am not null: drawing the display job panel"); try { TableLayout thisLayout = new TableLayout(new double[][] { { TableLayout.FILL }, { TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.FILL } }); thisLayout.setHGap(5); thisLayout.setVGap(5); this.setLayout(thisLayout); { jPanel1 = new JPanel(); TableLayout jPanel1Layout = new TableLayout(new double[][] { { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED }, { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL } }); jPanel1Layout.setHGap(5); jPanel1Layout.setVGap(5); jPanel1.setLayout(jPanel1Layout); jPanel1.setLayout(jPanel1Layout); jPanel1.setBorder(BorderFactory.createEtchedBorder()); this.add(jPanel1, "0, 0, 0, 2"); jPanel1.setPreferredSize(new java.awt.Dimension(630, 305)); jPanel1.setSize(630, 305); { dtails = new JPanel(); GridLayout dtailsLayout = new GridLayout(1, 1); dtailsLayout.setColumns(1); dtailsLayout.setHgap(5); dtailsLayout.setVgap(5); dtails.setBorder(BorderFactory.createTitledBorder("Job Details")); jPanel1.add(dtails, "0, 0, 2, 4"); dtails.setLayout(dtailsLayout); { jobDetailsSP = new JScrollPane(); dtails.add(jobDetailsSP); { jPanel3 = new JPanel(); TableLayout jPanel3Layout = new TableLayout( new double[][] { { TableLayout.PREFERRED, TableLayout.FILL }, { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL } }); jPanel3Layout.setHGap(5); jPanel3Layout.setVGap(5); jPanel3.setLayout(jPanel3Layout); jobDetailsSP.setViewportView(jPanel3); jPanel3.setBackground(new java.awt.Color(156, 199, 219)); { jLabel2 = new JLabel(); jPanel3.add(jLabel2, "0, 0"); jLabel2.setText("Job Start Time"); } { jLabel3 = new JLabel(); jPanel3.add(jLabel3, "0, 1"); jLabel3.setText("Resource ID"); } { jLabel4 = new JLabel(); jPanel3.add(jLabel4, "0, 2"); jLabel4.setText("Job Type"); } { jLabel5 = new JLabel(); jPanel3.add(jLabel5, "0, 3"); jLabel5.setText("Status"); } { jLabel6 = new JLabel(); jPanel3.add(jLabel6, "0, 4"); jLabel6.setText("Machine"); } { jLabel7 = new JLabel(); jPanel3.add(jLabel7, "0, 5"); jLabel7.setText("CPUs Requested"); } { jLabel8 = new JLabel(); jPanel3.add(jLabel8, "0, 6"); jLabel8.setText("Configuration File"); } { jLabel9 = new JLabel(); jPanel3.add(jLabel9, "0, 7"); jLabel9.setText("Job Arguments"); } { jLabel10 = new JLabel(); jPanel3.add(jLabel10, "0, 8"); jLabel10.setText("Job Stdout"); } { jLabel11 = new JLabel(); jPanel3.add(jLabel11, "0, 9"); jLabel11.setText("Job Stderr"); } { jLabel12 = new JLabel(); jPanel3.add(jLabel12, "0, 10"); jLabel12.setText("Job Stdin"); } { jLabel13 = new JLabel(); jPanel3.add(jLabel13, "0, 11"); jLabel13.setText("Resource Endpoint"); } { jobName = new JTextField(); jPanel3.add(jobName, "1, 0"); jobName.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobName.setOpaque(true); jobName.setBackground(new java.awt.Color(255, 255, 255)); jobName.setEditable(false); } { resourceID = new JTextField(); jPanel3.add(resourceID, "1, 1"); resourceID.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); resourceID.setOpaque(true); resourceID.setBackground(new java.awt.Color(255, 255, 255)); resourceID.setEditable(false); } { jobType = new JTextField(); jPanel3.add(jobType, "1, 2"); jobType.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobType.setBackground(new java.awt.Color(255, 255, 255)); jobType.setOpaque(true); jobType.setEditable(false); } { jobStatus = new JLabel(); jPanel3.add(jobStatus, "1, 3"); jobStatus.setOpaque(true); jobStatus.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobStatus.setBackground(new java.awt.Color(255, 255, 255)); } { rm = new JTextField(); jPanel3.add(rm, "1, 4"); rm.setBackground(new java.awt.Color(255, 255, 255)); rm.setOpaque(true); rm.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); rm.setEditable(false); } { jobCpus = new JTextField(); jPanel3.add(jobCpus, "1, 5"); jobCpus.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobCpus.setOpaque(true); jobCpus.setBackground(new java.awt.Color(255, 255, 255)); jobCpus.setEditable(false); } { jobConf = new JTextField(); jPanel3.add(jobConf, "1, 6"); jobConf.setBackground(new java.awt.Color(255, 255, 255)); jobConf.setOpaque(true); jobConf.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobConf.setEditable(false); } { jobArgs = new JTextField(); jPanel3.add(jobArgs, "1, 7"); jobArgs.setBackground(new java.awt.Color(255, 255, 255)); jobArgs.setOpaque(true); jobArgs.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobArgs.setEditable(false); } { jobSdtout = new JTextField(); jPanel3.add(jobSdtout, "1, 8"); jobSdtout.setBackground(new java.awt.Color(255, 255, 255)); jobSdtout.setOpaque(true); jobSdtout.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobSdtout.setEditable(false); } { jobStderr = new JTextField(); jPanel3.add(jobStderr, "1, 9"); jobStderr.setBackground(new java.awt.Color(255, 255, 255)); jobStderr.setOpaque(true); jobStderr.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobStderr.setEditable(false); } { jobStdin = new JTextField(); jPanel3.add(jobStdin, "1, 10"); jobStdin.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobStdin.setBackground(new java.awt.Color(255, 255, 255)); jobStdin.setOpaque(true); jobStdin.setEditable(false); } { jobEPR = new JTextField(); jPanel3.add(jobEPR, "1, 11"); jobEPR.setOpaque(true); jobEPR.setBorder(new LineBorder(new java.awt.Color(0, 0, 0), 1, false)); jobEPR.setBackground(new java.awt.Color(255, 255, 255)); jobEPR.setEditable(false); } } } } { controls = new JPanel(); TableLayout controlsLayout = new TableLayout(new double[][] { { TableLayout.FILL }, { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL } }); controlsLayout.setHGap(5); controlsLayout.setVGap(5); controls.setLayout(controlsLayout); controls.setBorder(BorderFactory.createTitledBorder("Operations")); jPanel1.add(controls, "3, 0, 4, 2"); { updateStatus = new JButton(); controls.add(updateStatus, "0, 0"); updateStatus.setText("Update Job Status"); updateStatus.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (updateStatus.getText().equals("Start Job")) { StartCall sc = new StartCall(ajo, ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-lifetime"), ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-port"), ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-dn"), ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-server"), ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-pw"), ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.myproxy-un")); ajo = sc.makeCall(); updatePanel(); } else { pollJobState(); } } }); } { teminateJob = new JButton(); controls.add(teminateJob, "0, 1"); teminateJob.setText("Terminate Job"); teminateJob.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { TerminateSimCall tsc = new TerminateSimCall(ajo.getEndPoint()); DisplayJobPanel.this.setCursor(new Cursor(Cursor.WAIT_CURSOR)); boolean tcsstatus = tsc.makeCall(); DisplayJobPanel.this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); if (tcsstatus) { ajo.setState(AHEJobObject.GRIDSAM_TERMINATING); updateState(); } else { ErrorMessage em = new ErrorMessage(DisplayJobPanel.this, "Error terminating job. Check log for details"); ; } } }); } { vizButton = new JButton(); controls.add(vizButton, "0, 2"); vizButton.setText("Visualize"); vizButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String h = "localhost"; int p = 65250; int w = 1024 * 1024; VizSteererWindow vs = new VizSteererWindow(h, p, w, (JFrame) DisplayJobPanel.this.getTopLevelAncestor()); } }); } { deleteFiles = new JCheckBox(); controls.add(deleteFiles, "0, 3"); deleteFiles.setText("Delete staged files when destroying job"); deleteFiles.setFont(new java.awt.Font("Sansserif", 0, 11)); deleteFiles.setSelected(true); } } { polling = new JPanel(); GridBagLayout pollingLayout = new GridBagLayout(); pollingLayout.rowWeights = new double[] { 0.1, 0.1, 0.1, 0.1 }; pollingLayout.rowHeights = new int[] { 7, 7, 7, 7 }; pollingLayout.columnWeights = new double[] { 0.0, 0.1 }; pollingLayout.columnWidths = new int[] { 109, 7 }; polling.setBorder(BorderFactory.createTitledBorder("Status Polling")); jPanel1.add(polling, "3, 3, 4, 4"); polling.setLayout(pollingLayout); { jLabel1 = new JLabel(); polling.add(jLabel1, new GridBagConstraints(0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); jLabel1.setText("Set the polling interval "); jLabel1.setFont(new java.awt.Font("Sansserif", 0, 11)); } { jSlider1 = new JSlider(); polling.add(jSlider1, new GridBagConstraints(0, 1, 2, 2, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0)); jSlider1.setMaximum(60); jSlider1.setValue(0); //jSlider1.setMinorTickSpacing(1); //jSlider1.createStandardLabels(5); Hashtable lab = new Hashtable(); lab.put(new Integer(0), new JLabel("0")); lab.put(new Integer(20), new JLabel("10")); lab.put(new Integer(40), new JLabel("20")); lab.put(new Integer(60), new JLabel("30")); jSlider1.setLabelTable(lab); jSlider1.setPaintTicks(true); jSlider1.setPaintLabels(true); jSlider1.setSnapToTicks(false); jSlider1.setMajorTickSpacing(2); jSlider1.setFont(new java.awt.Font("Sansserif", 0, 11)); jSlider1.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { if (jSlider1.getValue() != 0) { Integer i = new Integer(jSlider1.getValue()); time1.setText(Float.toString(i.floatValue() / 2)); if (pollingButton.getText().equals("Stop Polling")) { pollTimer.stop(); pollTimer.setInitialDelay(jSlider1.getValue() * 30000); pollTimer.setDelay(jSlider1.getValue() * 30000); pollTimer.start(); } } else { if (pollingButton.getText().equals("Stop Polling")) { pollTimer.stop(); pollingButton.setText("Start Polling"); } time1.setText("0.0"); } } }); } { pollingButton = new JButton(); polling.add(pollingButton, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.SOUTHEAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); pollingButton.setText("Start Polling"); pollingButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (jSlider1.getValue() > 0) { if (pollingButton.getText().equals("Start Polling")) { pollTimer = new Timer(jSlider1.getValue() * 30000, new ActionListener() { public void actionPerformed(ActionEvent evt) { pollJobState(); } }); pollTimer.setInitialDelay(1); pollTimer.start(); pollingButton.setText("Stop Polling"); } else { pollTimer.stop(); pollingButton.setText("Start Polling"); } } } }); } { time = new JLabel(); polling.add(time, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); time.setBackground(new java.awt.Color(255, 255, 255)); time.setText("Every"); } { jLabel14 = new JLabel(); polling.add(jLabel14, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.EAST, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); jLabel14.setText("mins"); } { time1 = new JLabel(); polling.add(time1, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.VERTICAL, new Insets(0, 0, 0, 0), 0, 0)); time1.setText("0.0"); ; } } } { jPanel2 = new JPanel(); GridLayout jPanel2Layout = new GridLayout(1, 1); jPanel2Layout.setColumns(1); jPanel2Layout.setHgap(5); jPanel2Layout.setVgap(5); jPanel2.setLayout(jPanel2Layout); TitledBorder title2; title2 = BorderFactory.createTitledBorder("Job Output"); jPanel2.setBorder(title2); this.add(jPanel2, "0, 3, 0, 4"); jPanel2.setPreferredSize(new java.awt.Dimension(630, 254)); { jTabbedPane1 = new JTabbedPane(); jPanel2.add(jTabbedPane1); { gridsamStatus = new JPanel(); GridLayout gridsamStatusLayout = new GridLayout(1, 1); gridsamStatusLayout.setColumns(1); gridsamStatusLayout.setHgap(5); gridsamStatusLayout.setVgap(5); gridsamStatus.setLayout(gridsamStatusLayout); jTabbedPane1.addTab("AHE Job Status", null, gridsamStatus, null); { jScrollPane1 = new JScrollPane(); gridsamStatus.add(jScrollPane1); { gridsamStatusResults = new JTextArea(); jScrollPane1.setViewportView(gridsamStatusResults); gridsamStatusResults.setFont(new java.awt.Font("Monospaced", 0, 12)); } } } { stagedFiles = new JPanel(); TableLayout stagedFilesLayout = new TableLayout(new double[][] { { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.PREFERRED }, { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.PREFERRED } }); stagedFilesLayout.setHGap(5); stagedFilesLayout.setVGap(5); stagedFiles.setLayout(stagedFilesLayout); jTabbedPane1.addTab("Staged Files", null, stagedFiles, null); { filesScrollPane = new JScrollPane(); stagedFiles.add(filesScrollPane, "0, 0, 5, 4"); { outputFilesTable = new JTable(); int col1 = 0, col2 = 0; int fsize = outputFilesTable.getFont().getSize() - 5; Object data[][] = new Object[ajo.getOutfiles().size() + ajo.getInfiles().size()][3]; int i = 0; if (ajo.getOutfiles() != null) { Iterator it = ajo.getOutfiles().iterator(); while (it.hasNext()) { JobFileElement je = (JobFileElement) it.next(); data[i][0] = new Boolean(true); data[i][1] = je.getName(); if (je.getName().length() > col1) { col1 = je.getName().length(); } String url = Tools.getUrlNoUP(je.getRemotepath()); data[i][2] = url; if (url.length() > col2) { col2 = url.length(); } i++; } } if (ajo.getInfiles() != null) { Iterator it = ajo.getInfiles().iterator(); while (it.hasNext()) { JobFileElement je = (JobFileElement) it.next(); data[i][0] = new Boolean(false); data[i][1] = je.getName(); if (je.getName().length() > col1) { col1 = je.getName().length(); } String url = Tools.getUrlNoUP(je.getRemotepath()); data[i][2] = url; if (url.length() > col2) { col2 = url.length(); } i++; } } String colNames[] = { "Download", "File Name", "File Location" }; TableModel outputFilesTableModel = new MyTableModel(data, colNames); outputFilesTable.setIntercellSpacing(new Dimension(3, 3)); outputFilesTable.setModel(outputFilesTableModel); outputFilesTable.getColumnModel().getColumn(0).setPreferredWidth(70); outputFilesTable.getColumnModel().getColumn(1).setPreferredWidth(col1 * fsize); outputFilesTable.getColumnModel().getColumn(2).setPreferredWidth(col2 * fsize); outputFilesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); filesScrollPane.setViewportView(outputFilesTable); this.addComponentListener(new ComponentAdapter() { public void componentResized(ComponentEvent e) { if (outputFilesTable.getWidth() < filesScrollPane.getWidth()) { outputFilesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); } else { outputFilesTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); } } }); } } { downloadButton = new JButton(); stagedFiles.add(downloadButton, "5, 5"); downloadButton.setText("Download"); downloadButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { int outFileSize = ajo.getOutfiles().size(); for (int row = 0; row < outputFilesTable.getRowCount(); row++) { if (((Boolean) outputFilesTable.getValueAt(row, 0)) .booleanValue() == true) { if (row < outFileSize) { JobFileElement je = (JobFileElement) ajo.getOutfiles() .elementAt(row); if (fileLocation != null) { je.setLocalpath(Tools.checkURL(fileLocation) + je.getName()); } downloadFiles.add(je); } else { JobFileElement je = (JobFileElement) ajo.getInfiles() .elementAt(row - outFileSize); if (fileLocation != null) { je.setLocalpath(Tools.checkURL(fileLocation) + je.getName()); } downloadFiles.add(je); } } } StageFilesIn task = new StageFilesIn( ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.ahedavserver"), ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.ahedavuser"), ClinicalGuiClient.prop .getProperty("uk.ac.ucl.chem.ccs.aheclient.ahedavpasswd")); task.init(downloadFiles); ProgressMonitor progressMonitor = new ProgressMonitor(DisplayJobPanel.this, "Downloading Files", null, 0, task.getLength()); //progressMonitor.setMillisToDecideToPopup(1); progressMonitor.setMillisToPopup(100); //jProgressBar1.setMaximum(task.getLength()); //jProgressBar1.setValue(0); while (task.filesToStage()) { if (task.stageNext()) { progressMonitor.setProgress(task.getCurrent()); } else { cat.error(task.getError()); } } } }); } { changeLocationButton = new JButton(); stagedFiles.add(changeLocationButton, "4, 5"); changeLocationButton.setText("Local Dir"); changeLocationButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { JFileChooser fc = new JFileChooser(); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); int returnVal = fc.showOpenDialog(DisplayJobPanel.this); if (returnVal == JFileChooser.APPROVE_OPTION) { File file = fc.getSelectedFile(); fileLocation = file.getAbsolutePath(); //System.out.println(fileLocation); } } }); } } { if (ajo.getReGSWSEPR() != null) { regSteering = new JPanel(); TableLayout steerLayout = new TableLayout( new double[][] { { TableLayout.FILL }, { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL } }); regSteering.setLayout(steerLayout); steeredApp = true; jTabbedPane1.addTab("ReG Steering", null, regSteering, null); { JLabel look = new JLabel("Steering address"); steerERP = new JTextField(); steer = new JButton("Start Steerer"); steer.setEnabled(false); steer.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { vs = new VizSteererWindow(h, p, w, DisplayJobPanel.this.getTopLevelAncestor()); } }); regSteering.add(look, "0,1"); regSteering.add(steerERP, "0,2"); regSteering.add(steer, "0,3"); } } } } } updatePanel(); this.setPreferredSize(new java.awt.Dimension(630, 605)); this.setSize(630, 605); this.setOpaque(false); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.multibit.viewsystem.swing.view.panels.ShowPreferencesPanel.java
/** * Create the messaging server panel which consists of MultiBit style header * and our Netbean visual editor designed panel * @param stentWidth/*from www. j a va 2s .c o m*/ * @return */ private JPanel createMessagingServerPanel(int stentWidth) { MultiBitTitledPanel panel = new MultiBitTitledPanel("Messaging Servers", ComponentOrientation.getOrientation(controller.getLocaliser().getLocale())); // Create layout like other panels GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 0; constraints.gridy = 3; constraints.weightx = 0.1; constraints.weighty = 0.3; constraints.gridwidth = 1; constraints.gridheight = 1; constraints.anchor = GridBagConstraints.LINE_START; JPanel indent = MultiBitTitledPanel.getIndentPanel(1); panel.add(indent, constraints); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 1; constraints.gridy = 4; constraints.weightx = 0.3; constraints.weighty = 0.3; constraints.gridwidth = 1; constraints.anchor = GridBagConstraints.LINE_START; JPanel stent = MultiBitTitledPanel.createStent(stentWidth); panel.add(stent, constraints); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 2; constraints.gridy = 3; constraints.weightx = 0.05; constraints.weighty = 0.3; constraints.gridwidth = 1; constraints.anchor = GridBagConstraints.CENTER; panel.add(MultiBitTitledPanel.createStent(MultiBitTitledPanel.SEPARATION_BETWEEN_NAME_VALUE_PAIRS), constraints); // Now insert our custom panel messagingServerPanel = new CSMessagingServerPanel(); constraints.fill = GridBagConstraints.NONE; constraints.gridx = 1; constraints.gridy = 5; constraints.weightx = 1; constraints.weighty = 1; constraints.gridwidth = 1; constraints.anchor = GridBagConstraints.LINE_START; panel.add(messagingServerPanel, constraints); // fill up right side JPanel fill1 = new JPanel(); fill1.setOpaque(false); constraints.fill = GridBagConstraints.BOTH; constraints.gridx = 4; constraints.gridy = 10; constraints.weightx = 20; constraints.weighty = 1; constraints.gridwidth = 1; constraints.anchor = GridBagConstraints.LINE_END; panel.add(fill1, constraints); return panel; }
From source file:org.apache.taverna.activities.rest.ui.config.RESTActivityConfigurationPanel.java
private JPanel createAdvancedTab() { JPanel jpAdvanced = new JPanel(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.gridx = 0;/*from w w w .j av a 2s. co m*/ c.gridy = 0; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(8, 10, 2, 4); JLabel jlExpectHeaderInfoIcon = new JLabel(infoIcon); jlExpectHeaderInfoIcon .setToolTipText("<html>Ticking this checkbox may significantly improve performance when<br>" + "large volumes of data are sent to the remote server and a redirect<br>" + "from the original URL to the one specified by the server is likely.<br>" + "<br>" + "However, this checkbox <b>must not</b> be ticked to allow this activity<br>" + "to post updates to Twitter.</html>"); jpAdvanced.add(jlExpectHeaderInfoIcon, c); c.gridx++; c.weightx = 1.0; c.insets = new Insets(8, 0, 2, 8); cbSendHTTPExpectHeader = new JCheckBox("Send HTTP Expect request-header field"); jpAdvanced.add(cbSendHTTPExpectHeader, c); c.gridx = 0; c.gridy++; c.weightx = 0; c.insets = new Insets(2, 10, 5, 4); JLabel jlShowRedirectionOutputPortInfoIcon = new JLabel(infoIcon); jlShowRedirectionOutputPortInfoIcon .setToolTipText("<html>\"Redirection\" output port displays the URL of the final redirect<br>" + "that has yielded the output data on the \"Response Body\" port.</html>"); jpAdvanced.add(jlShowRedirectionOutputPortInfoIcon, c); c.gridx++; c.weightx = 1.0; c.insets = new Insets(2, 0, 5, 8); cbShowRedirectionOutputPort = new JCheckBox("Show \"Redirection\" output port"); jpAdvanced.add(cbShowRedirectionOutputPort, c); c.gridx = 0; c.gridy++; c.weightx = 0; c.insets = new Insets(2, 10, 5, 4); JLabel jlShowActualUrlPortInfoIcon = new JLabel(infoIcon); jlShowActualUrlPortInfoIcon .setToolTipText("<html>\"Actual URL\" output port displays the URL used by the REST service<br>" + "with the actual parameter values.</html>"); jpAdvanced.add(jlShowActualUrlPortInfoIcon, c); c.gridx++; c.weightx = 1.0; c.insets = new Insets(2, 0, 5, 8); cbShowActualUrlPort = new JCheckBox("Show \"Actual URL\" output port"); jpAdvanced.add(cbShowActualUrlPort, c); c.gridx = 0; c.gridy++; c.weightx = 0; c.insets = new Insets(2, 10, 5, 4); JLabel jlShowResponseHeadersPortInfoIcon = new JLabel(infoIcon); jlShowResponseHeadersPortInfoIcon .setToolTipText("<html>\"Response headers\" output port displays the HTTP headers<br>" + "received from the final (after redirection) HTTP call.</html>"); jpAdvanced.add(jlShowResponseHeadersPortInfoIcon, c); c.gridx++; c.weightx = 1.0; c.insets = new Insets(2, 0, 5, 8); cbShowResponseHeadersPort = new JCheckBox("Show \"Response headers\" output port"); jpAdvanced.add(cbShowResponseHeadersPort, c); c.gridx = 0; c.gridy++; c.weightx = 0; c.insets = new Insets(2, 10, 5, 4); JLabel jlEscapeParametersInfoIcon = new JLabel(infoIcon); jlEscapeParametersInfoIcon.setToolTipText("<html>Determines if parameters you pass to form the full URL<br>" + " of the REST service will be URL-escaped.</html>"); jpAdvanced.add(jlEscapeParametersInfoIcon, c); c.gridx++; c.weightx = 1.0; c.insets = new Insets(2, 0, 5, 8); cbEscapeParameters = new JCheckBox("Escape URL parameter values"); jpAdvanced.add(cbEscapeParameters, c); c.gridx = 0; c.gridy++; c.weightx = 0; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.NONE; c.insets = new Insets(2, 10, 5, 4); JLabel jlHTTPHeadersInfoIcon = new JLabel(infoIcon); jlHTTPHeadersInfoIcon.setToolTipText("<html>Set additional HTTP headers</html>"); jpAdvanced.add(jlHTTPHeadersInfoIcon, c); c.gridx = 1; c.weightx = 0; c.weighty = 0; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.NONE; c.insets = new Insets(2, 10, 5, 4); addHeaderButton = new JButton("Add HTTP header"); addHeaderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { httpHeadersTableModel.addEmptyRow(); httpHeadersTable.getSelectionModel().setSelectionInterval(httpHeadersTableModel.getRowCount() - 1, httpHeadersTableModel.getRowCount() - 1); } }); removeHeaderButton = new JButton("Remove HTTP header"); removeHeaderButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int row = httpHeadersTable.getSelectedRow(); httpHeadersTableModel.removeRow(row); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(addHeaderButton, FlowLayout.LEFT); buttonPanel.add(removeHeaderButton); jpAdvanced.add(buttonPanel, c); c.gridx = 1; c.gridy++; c.weightx = 0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; c.insets = new Insets(2, 10, 5, 4); httpHeadersTableModel = new HTTPHeadersTableModel(); httpHeadersTable = new JTable(httpHeadersTableModel); httpHeadersTable.setGridColor(Color.GRAY); httpHeadersTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setVisibleRowCount(httpHeadersTable, 3); JScrollPane headersTableScrollPane = new JScrollPane(httpHeadersTable); jpAdvanced.add(headersTableScrollPane, c); return (jpAdvanced); }
From source file:com.microsoft.azure.hdinsight.spark.ui.SparkSubmissionContentPanel.java
private void addCommandlineArgsLineItem() { JLabel commandLineArgs = new JLabel("Command line arguments"); commandLineArgs.setToolTipText(/*from ww w.j a va 2 s . c o m*/ "Command line arguments used in your main class; multiple arguments should be split by space."); add(commandLineArgs, new GridBagConstraints(0, ++displayLayoutCurrentRow, 1, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(margin, margin, 0, 0), 0, 0)); commandLineTextField = new JTextField(); commandLineTextField.setToolTipText( "Command line arguments used in your main class; multiple arguments should be split by space."); add(commandLineTextField, new GridBagConstraints(1, displayLayoutCurrentRow, 0, 1, 1, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL, new Insets(margin, margin, 0, margin), 0, 0)); }
From source file:org.photovault.swingui.PhotoInfoEditor.java
private void addLabelTextRows(JLabel[] labels, JComponent[] textFields, GridBagLayout gridbag, Container container) {//from ww w.j a v a2s . c o m GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.EAST; c.insets = new Insets(2, 2, 2, 2); int numLabels = labels.length; for (int i = 0; i < numLabels; i++) { c.anchor = GridBagConstraints.EAST; c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last c.fill = GridBagConstraints.NONE; //reset to default c.weightx = 0.0; //reset to default gridbag.setConstraints(labels[i], c); container.add(labels[i]); c.anchor = GridBagConstraints.WEST; c.gridwidth = GridBagConstraints.REMAINDER; //end row c.weightx = 1.0; gridbag.setConstraints(textFields[i], c); container.add(textFields[i]); } }
From source file:org.metawidget.integrationtest.swing.allwidgets.SwingAllWidgetsTest.java
protected void runTest(AdvancedWidgetProcessor<JComponent, SwingMetawidget> processor) throws Exception { // Model/* w ww. ja va2 s.co m*/ AllWidgets allWidgets = new AllWidgets$$EnhancerByCGLIB$$1234(); // App SwingMetawidget metawidget = new SwingMetawidget(); metawidget.setConfig("org/metawidget/integrationtest/swing/allwidgets/metawidget.xml"); metawidget.addWidgetProcessor(processor); metawidget.addWidgetProcessor(new ReflectionBindingProcessor()); metawidget.setMetawidgetLayout(new SeparatorLayoutDecorator(new SeparatorLayoutDecoratorConfig().setLayout( new org.metawidget.swing.layout.GridBagLayout(new GridBagLayoutConfig().setNumberOfColumns(2))))); metawidget.setToInspect(allWidgets); metawidget.add(new Stub("mystery")); // Test missing components try { metawidget.getValue("no-such-component"); fail(); } catch (MetawidgetException e1) { assertEquals("No component named 'no-such-component'", e1.getMessage()); try { metawidget.getValue("textbox", "no-such-component"); fail(); } catch (MetawidgetException e2) { assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage()); try { metawidget.getValue("textbox", "no-such-component1", "no-such-component2"); fail(); } catch (MetawidgetException e3) { assertEquals( "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'", e3.getMessage()); } } } try { metawidget.setValue(null, "no-such-component"); fail(); } catch (MetawidgetException e1) { assertEquals("No component named 'no-such-component'", e1.getMessage()); try { metawidget.setValue(null, "textbox", "no-such-component"); fail(); } catch (MetawidgetException e2) { assertEquals("No component named 'textbox', 'no-such-component'", e2.getMessage()); try { metawidget.setValue(null, "textbox", "no-such-component1", "no-such-component2"); fail(); } catch (MetawidgetException e3) { assertEquals( "No such component 'no-such-component1' of 'textbox', 'no-such-component1', 'no-such-component2'", e3.getMessage()); } } } // Check what created, and edit it assertEquals("Textbox*:", ((JLabel) metawidget.getComponent(0)).getText()); assertTrue(metawidget.getComponent(1) instanceof JTextField); assertEquals("Textbox", metawidget.getValue("textbox")); ((JTextField) metawidget.getComponent(1)).setText("Textbox1"); assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText()); assertTrue(metawidget.getComponent(3) instanceof JTextField); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(3)).gridx); assertEquals("Limited Textbox", metawidget.getValue("limitedTextbox")); ((JTextField) metawidget.getComponent(3)).setText("Limited Textbox1"); assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText()); assertTrue(metawidget.getComponent(5) instanceof JScrollPane); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(5)).gridx); assertEquals("Textarea", metawidget.getValue("textarea")); JTextArea textarea = (JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView(); assertEquals(2, textarea.getRows()); assertEquals(true, textarea.getLineWrap()); assertEquals(true, textarea.getWrapStyleWord()); textarea.setText("Textarea1"); assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText()); assertTrue(metawidget.getComponent(7) instanceof JPasswordField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(7)).gridx); assertEquals("Password", metawidget.getValue("password")); ((JPasswordField) metawidget.getComponent(7)).setText("Password1"); // Primitives assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText()); assertTrue(metawidget.getComponent(9) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(9)).gridx); assertTrue(Byte.MAX_VALUE == (Byte) metawidget.getValue("bytePrimitive")); assertTrue(-5 == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel()) .getMinimum()); assertTrue( Byte.MAX_VALUE == (Byte) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(9)).getModel()) .getMaximum()); assertEquals(0, ((JSpinner.DefaultEditor) ((JSpinner) metawidget.getComponent(9)).getEditor()) .getTextField().getColumns()); JSpinner spinner = (JSpinner) metawidget.getComponent(9); spinner.setValue(spinner.getModel().getPreviousValue()); assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText()); assertTrue(metawidget.getComponent(11) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(11)).gridx); assertEquals(String.valueOf(Byte.MIN_VALUE), metawidget.getValue("byteObject")); ((JTextField) metawidget.getComponent(11)).setText(String.valueOf(Byte.MIN_VALUE + 1)); assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText()); assertTrue(metawidget.getComponent(13) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(13)).gridx); assertTrue(Short.MAX_VALUE == (Short) metawidget.getValue("shortPrimitive")); assertTrue(-6 == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13)).getModel()) .getMinimum()); assertTrue(Short.MAX_VALUE == (Short) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(13)) .getModel()).getMaximum()); spinner = (JSpinner) metawidget.getComponent(13); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getPreviousValue()); assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText()); assertTrue(metawidget.getComponent(15) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(15)).gridx); assertEquals(String.valueOf(Short.MIN_VALUE), metawidget.getValue("shortObject")); ((JTextField) metawidget.getComponent(15)).setText(String.valueOf(Short.MIN_VALUE + 1)); assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText()); assertTrue(metawidget.getComponent(17) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(17)).gridx); assertTrue(Integer.MAX_VALUE == (Integer) metawidget.getValue("intPrimitive")); assertTrue(Integer.MIN_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17)) .getModel()).getMinimum()); assertTrue(Integer.MAX_VALUE == (Integer) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(17)) .getModel()).getMaximum()); spinner = (JSpinner) metawidget.getComponent(17); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getPreviousValue()); assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText()); assertTrue(metawidget.getComponent(19) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(19)).gridx); assertEquals(String.valueOf(Integer.MIN_VALUE), metawidget.getValue("integerObject")); ((JTextField) metawidget.getComponent(19)).setText(String.valueOf(Integer.MIN_VALUE + 1)); assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText()); assertTrue(metawidget.getComponent(21) instanceof JSlider); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(21)).gridx); assertEquals(1, ((JSlider) metawidget.getComponent(21)).getMinimum()); assertEquals(100, ((JSlider) metawidget.getComponent(21)).getMaximum()); assertTrue(32 == (Integer) metawidget.getValue("rangedInt")); ((JSlider) metawidget.getComponent(21)).setValue(33); assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText()); assertTrue(metawidget.getComponent(23) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(23)).gridx); assertEquals("33", metawidget.getValue("rangedInteger")); ((JTextField) metawidget.getComponent(23)).setText(String.valueOf(34)); assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText()); assertTrue(metawidget.getComponent(25) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(25)).gridx); assertTrue(42 == (Long) metawidget.getValue("longPrimitive")); assertTrue(-7 == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel()) .getMinimum()); assertTrue( Long.MAX_VALUE == (Long) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(25)).getModel()) .getMaximum()); spinner = (JSpinner) metawidget.getComponent(25); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getNextValue()); assertTrue(metawidget.getComponent(26) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(26)).gridx); assertEquals("43", metawidget.getValue("longObject")); ((JTextField) metawidget.getComponent(26)).setText("44"); assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText()); assertTrue(metawidget.getComponent(28) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(28)).gridx); assertEquals(4.2f, metawidget.getValue("floatPrimitive")); assertEquals(-Float.MAX_VALUE, ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel()).getMinimum()); assertTrue(2048 == (Float) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(28)).getModel()) .getMaximum()); spinner = (JSpinner) metawidget.getComponent(28); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getNextValue()); assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText()); assertTrue(metawidget.getComponent(30) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(30)).gridx); assertEquals("4.3", metawidget.getValue("floatObject")); ((JTextField) metawidget.getComponent(30)).setText("5.4"); assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText()); assertTrue(metawidget.getComponent(32) instanceof JSpinner); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(32)).gridx); assertEquals(42.2d, metawidget.getValue("doublePrimitive")); assertTrue(-8 == (Double) ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel()) .getMinimum()); assertEquals(Double.MAX_VALUE, ((SpinnerNumberModel) ((JSpinner) metawidget.getComponent(32)).getModel()).getMaximum()); spinner = (JSpinner) metawidget.getComponent(32); assertEquals(0, ((JSpinner.DefaultEditor) spinner.getEditor()).getTextField().getColumns()); spinner.setValue(spinner.getModel().getNextValue()); assertTrue(metawidget.getComponent(33) instanceof JTextField); assertEquals(0, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridx); assertEquals(2, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(33)).gridwidth); assertEquals("43.3", metawidget.getValue("doubleObject")); ((JTextField) metawidget.getComponent(33)).setText("54.4"); assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText()); assertTrue(metawidget.getComponent(35) instanceof JTextField); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(35)).gridx); assertEquals("A", metawidget.getValue("charPrimitive")); ((JTextField) metawidget.getComponent(35)).setText("Z"); assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText()); assertTrue(metawidget.getComponent(37) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx); assertEquals("Z", metawidget.getValue("characterObject")); ((JTextField) metawidget.getComponent(37)).setText("A"); assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText()); assertTrue(metawidget.getComponent(39) instanceof JCheckBox); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(39)).gridx); assertTrue(false == (Boolean) metawidget.getValue("booleanPrimitive")); ((JCheckBox) metawidget.getComponent(39)).setSelected(true); assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText()); assertTrue(metawidget.getComponent(41) instanceof JComboBox); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(37)).gridx); assertEquals(3, ((JComboBox) metawidget.getComponent(41)).getItemCount()); assertEquals(Boolean.TRUE, metawidget.getValue("booleanObject")); ((JComboBox) metawidget.getComponent(41)).setSelectedItem(Boolean.FALSE); assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText()); assertTrue(metawidget.getComponent(43) instanceof JComboBox); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(43)).gridx); assertEquals(4, ((JComboBox) metawidget.getComponent(43)).getItemCount()); assertEquals("dropdown1", metawidget.getValue("dropdown")); ((JComboBox) metawidget.getComponent(43)).setSelectedItem("foo1"); assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText()); assertTrue(metawidget.getComponent(45) instanceof JComboBox); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(45)).gridx); JComboBox combo = (JComboBox) metawidget.getComponent(45); assertEquals(5, combo.getItemCount()); assertEquals("Foo #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "foo2", 1, false, false)) .getText()); assertEquals("Dropdown #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "dropdown2", 1, false, false)).getText()); assertEquals("Bar #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "bar2", 1, false, false)) .getText()); assertEquals("Baz #2", ((JLabel) combo.getRenderer().getListCellRendererComponent(new JList(), "baz2", 1, false, false)) .getText()); assertEquals("dropdown2", metawidget.getValue("dropdownWithLabels")); ((JComboBox) metawidget.getComponent(45)).setSelectedItem("bar2"); assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText()); assertTrue(metawidget.getComponent(47) instanceof JComboBox); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(47)).gridx); assertEquals(3, ((JComboBox) metawidget.getComponent(47)).getItemCount()); assertTrue(0 == (Byte) metawidget.getValue("notNullDropdown")); ((JComboBox) metawidget.getComponent(47)).setSelectedItem((byte) 1); assertEquals("Not Null Object Dropdown*:", ((JLabel) metawidget.getComponent(48)).getText()); assertTrue(metawidget.getComponent(49) instanceof JComboBox); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(49)).gridx); assertEquals(6, ((JComboBox) metawidget.getComponent(49)).getItemCount()); assertEquals("dropdown3", metawidget.getValue("notNullObjectDropdown")); ((JComboBox) metawidget.getComponent(49)).setSelectedIndex(0); assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText()); assertTrue(metawidget.getComponent(51) instanceof SwingMetawidget); SwingMetawidget metawidgetNested = (SwingMetawidget) metawidget.getComponent(51); assertEquals("Further Nested Widgets:", ((JLabel) metawidgetNested.getComponent(0)).getText()); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(1)).gridx); SwingMetawidget metawidgetFurtherNested = (SwingMetawidget) metawidgetNested.getComponent(1); assertEquals("Further Nested Widgets:", ((JLabel) metawidgetFurtherNested.getComponent(0)).getText()); assertTrue(metawidgetFurtherNested.getComponent(1) instanceof SwingMetawidget); assertEquals(((SwingMetawidget) metawidgetFurtherNested.getComponent(1)).getComponentCount(), 0); assertEquals("Nested Textbox 1:", ((JLabel) metawidgetFurtherNested.getComponent(2)).getText()); assertTrue(metawidgetFurtherNested.getComponent(3) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout()) .getConstraints(metawidgetFurtherNested.getComponent(3)).gridx); assertEquals("Nested Textbox 1", metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox1")); ((JTextField) metawidgetFurtherNested.getComponent(3)).setText("Nested Textbox 1.1 (further)"); assertEquals("Nested Textbox 2:", ((JLabel) metawidgetFurtherNested.getComponent(4)).getText()); assertTrue(metawidgetFurtherNested.getComponent(5) instanceof JTextField); // (should be 1, as in next row, if getEffectiveNumberOfColumns is working) assertEquals(1, ((GridBagLayout) metawidgetFurtherNested.getLayout()) .getConstraints(metawidgetFurtherNested.getComponent(5)).gridx); assertEquals("Nested Textbox 2", metawidget.getValue("nestedWidgets", "furtherNestedWidgets", "nestedTextbox2")); ((JTextField) metawidgetFurtherNested.getComponent(5)).setText("Nested Textbox 2.2 (further)"); assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText()); assertTrue(metawidgetNested.getComponent(3) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(3)).gridx); assertEquals("Nested Textbox 1", metawidget.getValue("nestedWidgets", "nestedTextbox1")); ((JTextField) metawidgetNested.getComponent(3)).setText("Nested Textbox 1.1"); assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText()); assertTrue(metawidgetNested.getComponent(5) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(5)).gridx); assertEquals("Nested Textbox 2", metawidget.getValue("nestedWidgets", "nestedTextbox2")); ((JTextField) metawidgetNested.getComponent(5)).setText("Nested Textbox 2.2"); assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText()); assertTrue(metawidget.getComponent(53) instanceof SwingMetawidget); metawidgetNested = (SwingMetawidget) metawidget.getComponent(53); assertEquals("Nested Textbox 1:", ((JLabel) metawidgetNested.getComponent(2)).getText()); assertTrue(metawidgetNested.getComponent(3) instanceof JLabel); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(3)).gridx); assertEquals("Nested Textbox 1", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox1")); assertEquals("Nested Textbox 2:", ((JLabel) metawidgetNested.getComponent(4)).getText()); assertTrue(metawidgetNested.getComponent(5) instanceof JLabel); assertEquals(1, ((GridBagLayout) metawidgetNested.getLayout()) .getConstraints(metawidgetNested.getComponent(5)).gridx); assertEquals("Nested Textbox 2", metawidget.getValue("readOnlyNestedWidgets", "nestedTextbox2")); assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText()); assertEquals("Nested Textbox 1, Nested Textbox 2", ((JTextField) metawidget.getComponent(55)).getText()); ((JTextField) metawidget.getComponent(55)).setText("Nested Textbox 1.01, Nested Textbox 2.02"); assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText()); assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText()); assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText()); assertTrue(metawidget.getComponent(59) instanceof JTextField); assertEquals(1, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(59)).gridx); DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); assertEquals(dateFormat.format(allWidgets.getDate()), metawidget.getValue("date")); ((JTextField) metawidget.getComponent(59)).setText("bad date"); JPanel separatorPanel = (JPanel) metawidget.getComponent(60); assertEquals("Section Break", ((JLabel) separatorPanel.getComponent(0)).getText()); assertEquals(GridBagConstraints.REMAINDER, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(60)).gridwidth); assertTrue(separatorPanel.getComponent(1) instanceof JSeparator); assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText()); assertTrue(metawidget.getComponent(62) instanceof JLabel); assertEquals("Read Only", metawidget.getValue("readOnly")); assertTrue(metawidget.getComponent(63) instanceof JButton); assertEquals(3, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).gridx); assertEquals(GridBagConstraints.NONE, ((GridBagLayout) metawidget.getLayout()).getConstraints(metawidget.getComponent(63)).fill); JButton button = ((JButton) metawidget.getComponent(63)); assertEquals("Do Action", button.getText()); assertTrue(button.isEnabled()); try { button.doClick(); fail(); } catch (Exception e) { assertEquals("doAction called", e.getCause().getCause().getMessage()); } assertEquals(64, metawidget.getComponentCount()); // Check painting JFrame frame = new JFrame(); metawidget.paint(frame.getGraphics()); // Check MetawidgetException try { processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget); fail(); } catch (Exception e) { assertEquals("Could not parse 'bad date'", e.getCause().getCause().getMessage()); } // Check saving String now = dateFormat.format(new GregorianCalendar().getTime()); ((JTextField) metawidget.getComponent(59)).setText(now); processor.getClass().getMethod("save", SwingMetawidget.class).invoke(processor, metawidget); // Check read-only metawidget.setReadOnly(true); assertEquals("Textbox:", ((JLabel) metawidget.getComponent(0)).getText()); assertEquals("Textbox1", ((JLabel) metawidget.getComponent(1)).getText()); assertEquals("Limited Textbox:", ((JLabel) metawidget.getComponent(2)).getText()); assertEquals("Limited Textbox1", ((JLabel) metawidget.getComponent(3)).getText()); assertEquals("Textarea:", ((JLabel) metawidget.getComponent(4)).getText()); assertEquals("Textarea1", ((JTextArea) ((JScrollPane) metawidget.getComponent(5)).getViewport().getView()).getText()); assertEquals("Password:", ((JLabel) metawidget.getComponent(6)).getText()); assertTrue(metawidget.getComponent(7) instanceof JPanel); assertEquals("Byte Primitive:", ((JLabel) metawidget.getComponent(8)).getText()); assertEquals("126", ((JLabel) metawidget.getComponent(9)).getText()); assertEquals("Byte Object:", ((JLabel) metawidget.getComponent(10)).getText()); assertEquals("-127", ((JLabel) metawidget.getComponent(11)).getText()); assertEquals("Short Primitive:", ((JLabel) metawidget.getComponent(12)).getText()); assertEquals("32766", ((JLabel) metawidget.getComponent(13)).getText()); assertEquals("Short Object:", ((JLabel) metawidget.getComponent(14)).getText()); assertEquals("-32767", ((JLabel) metawidget.getComponent(15)).getText()); assertEquals("Int Primitive:", ((JLabel) metawidget.getComponent(16)).getText()); assertEquals("2147483646", ((JLabel) metawidget.getComponent(17)).getText()); assertEquals("Integer Object:", ((JLabel) metawidget.getComponent(18)).getText()); assertEquals("-2147483647", ((JLabel) metawidget.getComponent(19)).getText()); assertEquals("Ranged Int:", ((JLabel) metawidget.getComponent(20)).getText()); assertEquals("33", ((JLabel) metawidget.getComponent(21)).getText()); assertEquals("Ranged Integer:", ((JLabel) metawidget.getComponent(22)).getText()); assertEquals("34", ((JLabel) metawidget.getComponent(23)).getText()); assertEquals("Long Primitive:", ((JLabel) metawidget.getComponent(24)).getText()); assertEquals("43", ((JLabel) metawidget.getComponent(25)).getText()); assertEquals("44", ((JLabel) metawidget.getComponent(26)).getText()); assertEquals("Float Primitive:", ((JLabel) metawidget.getComponent(27)).getText()); assertTrue(((JLabel) metawidget.getComponent(28)).getText().startsWith("4.3") || ((JLabel) metawidget.getComponent(28)).getText().startsWith("4.299")); assertEquals("nullInBundle:", ((JLabel) metawidget.getComponent(29)).getText()); assertEquals("5.4", ((JLabel) metawidget.getComponent(30)).getText()); assertEquals("Double Primitive:", ((JLabel) metawidget.getComponent(31)).getText()); assertTrue(((JLabel) metawidget.getComponent(32)).getText().startsWith("42.3") || ((JLabel) metawidget.getComponent(32)).getText().startsWith("42.299")); assertEquals("54.4", ((JLabel) metawidget.getComponent(33)).getText()); assertEquals("Char Primitive:", ((JLabel) metawidget.getComponent(34)).getText()); assertEquals("Z", ((JLabel) metawidget.getComponent(35)).getText()); assertEquals("Character Object:", ((JLabel) metawidget.getComponent(36)).getText()); assertEquals("A", ((JLabel) metawidget.getComponent(37)).getText()); assertEquals("Boolean Primitive:", ((JLabel) metawidget.getComponent(38)).getText()); assertEquals("true", ((JLabel) metawidget.getComponent(39)).getText()); assertEquals("Boolean Object:", ((JLabel) metawidget.getComponent(40)).getText()); assertEquals("No", ((JLabel) metawidget.getComponent(41)).getText()); assertEquals("Dropdown:", ((JLabel) metawidget.getComponent(42)).getText()); assertEquals("foo1", ((JLabel) metawidget.getComponent(43)).getText()); assertEquals("Dropdown With Labels:", ((JLabel) metawidget.getComponent(44)).getText()); assertEquals("Bar #2", ((JLabel) metawidget.getComponent(45)).getText()); assertEquals("Not Null Dropdown:", ((JLabel) metawidget.getComponent(46)).getText()); assertEquals("1", ((JLabel) metawidget.getComponent(47)).getText()); assertEquals("Not Null Object Dropdown:", ((JLabel) metawidget.getComponent(48)).getText()); assertEquals("foo3", ((JLabel) metawidget.getComponent(49)).getText()); assertEquals("Nested Widgets:", ((JLabel) metawidget.getComponent(50)).getText()); assertEquals("Further Nested Widgets:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(0)).getText()); assertEquals("Further Nested Widgets:", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(0)).getText()); assertEquals("Nested Textbox 1:", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(2)).getText()); assertEquals("Nested Textbox 1.1 (further)", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(3)).getText()); assertEquals("Nested Textbox 2:", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(4)).getText()); assertEquals("Nested Textbox 2.2 (further)", ((JLabel) ((SwingMetawidget) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(1)) .getComponent(5)).getText()); assertEquals("Nested Textbox 1:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(2)).getText()); assertEquals("Nested Textbox 1.1", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(3)).getText()); assertEquals("Nested Textbox 2:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(4)).getText()); assertEquals("Nested Textbox 2.2", ((JLabel) ((SwingMetawidget) metawidget.getComponent(51)).getComponent(5)).getText()); assertEquals("Read Only Nested Widgets:", ((JLabel) metawidget.getComponent(52)).getText()); assertEquals("Further Nested Widgets:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(0)).getText()); assertEquals("Nested Textbox 1:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(2)).getText()); assertEquals("Nested Textbox 1", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(3)).getText()); assertEquals("Nested Textbox 2:", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(4)).getText()); assertEquals("Nested Textbox 2", ((JLabel) ((SwingMetawidget) metawidget.getComponent(53)).getComponent(5)).getText()); assertEquals("Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(54)).getText()); assertEquals("Nested Textbox 1.01, Nested Textbox 2.02", ((JLabel) metawidget.getComponent(55)).getText()); assertEquals("Read Only Nested Widgets Dont Expand:", ((JLabel) metawidget.getComponent(56)).getText()); assertEquals("Nested Textbox 1, Nested Textbox 2", ((JLabel) metawidget.getComponent(57)).getText()); assertEquals("Date:", ((JLabel) metawidget.getComponent(58)).getText()); assertEquals(now, ((JLabel) metawidget.getComponent(59)).getText()); assertEquals("Section Break", ((JLabel) ((JPanel) metawidget.getComponent(60)).getComponent(0)).getText()); assertEquals("Read Only:", ((JLabel) metawidget.getComponent(61)).getText()); assertEquals("Read Only", ((JLabel) metawidget.getComponent(62)).getText()); assertEquals("Do Action", ((JButton) metawidget.getComponent(63)).getText()); assertTrue(!((JButton) metawidget.getComponent(63)).isEnabled()); assertEquals(metawidget.getComponentCount(), 64); // Test Binding.onStartBuild clears the state assertTrue(null != metawidget.getClientProperty(processor.getClass())); processor.onStartBuild(metawidget); assertEquals(null, metawidget.getClientProperty(processor.getClass())); }
From source file:us.paulevans.basicxslt.BasicXSLTFrame.java
/** * Builds the auto-save panel/*from w ww. j av a2s .com*/ * @return */ private JPanel buildAutosavePanel() { int row; JPanel buttons; JPanel autosavePanel; row = 0; buttons = new JPanel(new FlowLayout(FlowLayout.LEFT)); buttons.add(addXslBtn = new JButton(stringFactory.getString(LabelStringFactory.MAIN_FRAME_ADD_XSL_BTN))); buttons.add(removeCheckedBtn = new JButton( stringFactory.getString(LabelStringFactory.MAIN_FRAME_REMOVE_CHECKED_BTN))); addXslBtn.addActionListener(this); removeCheckedBtn.addActionListener(this); autosavePanel = new JPanel(xslPanelLayout); GUIUtils.add(autosavePanel, buttons, xslPanelLayout, xslPanelConstraints, row++, 0, 1, 3, GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); GUIUtils.add(autosavePanel, new JLabel(stringFactory.getString(LabelStringFactory.MAIN_FRAME_AUTOSAVERESULT)), xslPanelLayout, xslPanelConstraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); GUIUtils.add(autosavePanel, autosaveCb = new JCheckBox(), xslPanelLayout, xslPanelConstraints, row, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); autosaveCb.addActionListener(this); GUIUtils.add(autosavePanel, autosavePathTf = new JTextField(AppConstants.TF_LENGTH - 4), xslPanelLayout, xslPanelConstraints, row, 2, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); GUIUtils.add(autosavePanel, browseAutosavePathBtn = new JButton( stringFactory.getString(LabelStringFactory.MAIN_FRAME_BROWSE_BTN)), xslPanelLayout, xslPanelConstraints, row, 3, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); GUIUtils.add(autosavePanel, validateAutosaveBtn = new JButton( stringFactory.getString(LabelStringFactory.MAIN_FRAME_VALIDATE_BTN)), xslPanelLayout, xslPanelConstraints, row++, 4, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); validateAutosaveBtn.addActionListener(this); GUIUtils.add(autosavePanel, new JLabel(stringFactory.getString(LabelStringFactory.MAIN_FRAME_SUPRESS_OUTPUT_WINDOW)), xslPanelLayout, xslPanelConstraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); GUIUtils.add(autosavePanel, suppressOutputWindowCb = new JCheckBox(), xslPanelLayout, xslPanelConstraints, row++, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); GUIUtils.add(autosavePanel, outputAsTextIfXmlLabel = new JLabel( stringFactory.getString(LabelStringFactory.MAIN_FRAME_DISPLAY_OUTPUT_AS_TEXT_IF_XML)), xslPanelLayout, xslPanelConstraints, row, 0, 1, 1, GridBagConstraints.EAST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); GUIUtils.add(autosavePanel, outputAsTextIfXml = new JCheckBox(), xslPanelLayout, xslPanelConstraints, row++, 1, 1, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, GUIUtils.SMALL_INSETS); suppressOutputWindowCb.addActionListener(this); return autosavePanel; }
From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java
/** * @return// w w w. ja va 2s .com */ private JPanel createColorCategoriesPanel() { JPanel categoryColorsConfigurationPanel = new JPanel(new GridBagLayout()); categoryColorsConfigurationPanel.setPreferredSize(new Dimension(180, 200)); GridBagConstraints itemConstraint = new GridBagConstraints(); JLabel categoryColorsLabel = new ResourceLabel( "plotter.configuration_dialog.color_scheme_dialog.category_colors"); { itemConstraint.fill = GridBagConstraints.HORIZONTAL; itemConstraint.anchor = GridBagConstraints.WEST; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.insets = new Insets(0, 5, 5, 5); itemConstraint.weightx = 1.0; categoryColorsConfigurationPanel.add(categoryColorsLabel, itemConstraint); } // add button panel { JPanel buttonPanel = new JPanel(new GridBagLayout()); // remove scheme button { removeCategoryColorButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.remove_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { removeSelectedColorAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.RELATIVE; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(removeCategoryColorButton, itemConstraint); } { addCategoryButton = new JButton(new ResourceAction(true, "plotter.configuration_dialog.color_scheme_dialog.add_category_color_button") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { Color oldColor = Color.white; Color newSchemeColor = createColorDialog(oldColor); if (newSchemeColor != null && !newSchemeColor.equals(oldColor)) { addColorAction(newSchemeColor); } } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; buttonPanel.add(addCategoryButton, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.anchor = GridBagConstraints.EAST; itemConstraint.insets = new Insets(0, 5, 5, 5); categoryColorsConfigurationPanel.add(buttonPanel, itemConstraint); } { JPanel categoryListPanel = new JPanel(new GridBagLayout()); // add list of categorie colors { colorList = new JList<Color>(nominalColorListModel); categoryColorsLabel.setLabelFor(colorList); colorList.setCellRenderer(new ColorListCellRenderer()); colorList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); MouseAdapter ma = new MouseAdapter() { private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JList<?> list = (JList<?>) e.getSource(); list.setSelectedIndex(list.locationToIndex(e.getPoint())); Color selectedColor = (Color) list.getSelectedValue(); if (selectedColor == null) { return; } removeMenuItem.setEnabled(nominalColorListModel.getSize() > 2); popupMenu.show(list, x, y); } @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } @Override public void mouseReleased(MouseEvent e) { if (e.isPopupTrigger()) { myPopupEvent(e); } } }; colorList.addMouseListener(ma); colorList.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) { return; // Nothing to be done } @Override public void keyReleased(KeyEvent e) { return; // Nothing to be done } @Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); if (key == KeyEvent.VK_DELETE) { if (nominalColorListModel.getSize() > 2) { removeSelectedColorAction(); } } if (key == KeyEvent.VK_F2) { replaceSelectedColorAction(); } if (key == KeyEvent.VK_UP && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorUpAction(); } if (key == KeyEvent.VK_DOWN && SwingTools.isControlOrMetaDown(e)) { moveSelectedColorDownAction(); } } }); colorListScrollPane = new JScrollPane(colorList); colorListScrollPane.setPreferredSize(new Dimension(170, 200)); colorListScrollPane.setMaximumSize(new Dimension(170, 200)); colorListScrollPane.setMinimumSize(new Dimension(170, 180)); colorListScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); colorListScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); itemConstraint = new GridBagConstraints(); itemConstraint.fill = GridBagConstraints.BOTH; itemConstraint.weightx = 0.0; itemConstraint.weighty = 0.5; itemConstraint.gridwidth = GridBagConstraints.RELATIVE; categoryListPanel.add(colorListScrollPane, itemConstraint); } // add up/down button panel { JPanel upAndDownButtonPanel = new JPanel(new GridBagLayout()); // add up button { JButton upButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_up") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorUpAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(upButton, itemConstraint); } // add down button { JButton downButton = new JButton( new ResourceAction(true, "plotter.configuration_dialog.move_color_down") { private static final long serialVersionUID = 1L; @Override public void actionPerformed(ActionEvent e) { moveSelectedColorDownAction(); } }); itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 0; itemConstraint.fill = GridBagConstraints.NONE; itemConstraint.insets = new Insets(0, 2, 0, 12); upAndDownButtonPanel.add(downButton, itemConstraint); } // add spacer panel { JPanel spacer = new JPanel(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 0; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; upAndDownButtonPanel.add(spacer, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.VERTICAL; categoryListPanel.add(upAndDownButtonPanel, itemConstraint); } itemConstraint = new GridBagConstraints(); itemConstraint.gridwidth = GridBagConstraints.REMAINDER; itemConstraint.weightx = 1; itemConstraint.weighty = 1; itemConstraint.fill = GridBagConstraints.BOTH; categoryColorsConfigurationPanel.add(categoryListPanel, itemConstraint); } return categoryColorsConfigurationPanel; }