private void setSizeAndDimensions( @NotNull JTable table, @NotNull JBPopup popup, @NotNull RelativePoint popupPosition, @NotNull List<UsageNode> data) { JComponent content = popup.getContent(); Window window = SwingUtilities.windowForComponent(content); Dimension d = window.getSize(); int width = calcMaxWidth(table); width = (int) Math.max(d.getWidth(), width); Dimension headerSize = ((AbstractPopup) popup).getHeaderPreferredSize(); width = Math.max((int) headerSize.getWidth(), width); width = Math.max(myWidth, width); if (myWidth == -1) myWidth = width; int newWidth = Math.max(width, d.width + width - myWidth); myWidth = newWidth; int rowsToShow = Math.min(30, data.size()); Dimension dimension = new Dimension(newWidth, table.getRowHeight() * rowsToShow); Rectangle rectangle = fitToScreen(dimension, popupPosition, table); dimension = rectangle.getSize(); Point location = window.getLocation(); if (!location.equals(rectangle.getLocation())) { window.setLocation(rectangle.getLocation()); } if (!data.isEmpty()) { TableScrollingUtil.ensureSelectionExists(table); } table.setSize(dimension); // table.setPreferredSize(dimension); // table.setMaximumSize(dimension); // table.setPreferredScrollableViewportSize(dimension); Dimension footerSize = ((AbstractPopup) popup).getFooterPreferredSize(); int newHeight = (int) (dimension.height + headerSize.getHeight() + footerSize.getHeight()) + 4 /* invisible borders, margins etc*/; Dimension newDim = new Dimension(dimension.width, newHeight); window.setSize(newDim); window.setMinimumSize(newDim); window.setMaximumSize(newDim); window.validate(); window.repaint(); table.revalidate(); table.repaint(); }
public void paint(Graphics g) { super.paint(g); Dimension size = getSize(); double w = size.getWidth() - 50; double h = size.getHeight() + 20; try { readFile(); } catch (IOException e) { System.err.println("IO issue"); } barWidth = ((int) (w / numBars)) - 20; pos = 5; int xPos[] = {pos, pos, pos, pos}; int yPos[] = {pos, pos, pos, pos}; maxVal = maxValue(values); double barH, ratio; for (int i = 0; i < numBars - 1; i++) { Color col[] = new Color[numBars]; for (int j = 0; j < numBars - 1; j++) { col[j] = new Color((int) (Math.random() * 0x1000000)); } ratio = (double) values[i] / (double) maxVal; barH = ((h) * ratio) - 10; xPos[0] = pos; xPos[2] = pos + barWidth; xPos[1] = xPos[0]; xPos[3] = xPos[2]; yPos[0] = (int) h; yPos[1] = (int) barH; yPos[2] = yPos[1]; yPos[3] = yPos[0]; System.out.println( "xPos:" + xPos[1] + " yPos:" + yPos[0] + " h:" + h + " barH:" + barH + " ratio:" + ratio + " pos:" + pos); int stringPtsY[] = { ((i + 1) * 20) + 180, ((i + 1) * 20) + 200, ((i + 1) * 20) + 200, ((i + 1) * 20) + 180 }; int stringPtsX[] = {600, 600, 580, 580}; g.setColor(col[i]); g.fillPolygon(xPos, yPos, xPos.length); g.fillPolygon(stringPtsX, stringPtsY, 4); g.setColor(Color.black); g.drawString(labels[i], 610, ((i + 1) * 20) + 195); pos = pos + barWidth + 10; } }
private static Rectangle fitToScreen( @NotNull Dimension newDim, @NotNull RelativePoint popupPosition, JTable table) { Rectangle rectangle = new Rectangle(popupPosition.getScreenPoint(), newDim); ScreenUtil.fitToScreen(rectangle); if (rectangle.getHeight() != newDim.getHeight()) { int newHeight = (int) rectangle.getHeight(); int roundedHeight = newHeight - newHeight % table.getRowHeight(); rectangle.setSize((int) rectangle.getWidth(), Math.max(roundedHeight, table.getRowHeight())); } return rectangle; }
public Container CreateContentPane() { // Create the content-pane-to-be. JPanel contentPane = new JPanel(new BorderLayout()); contentPane.setOpaque(true); // the log panel log = new JTextPane(); log.setEditable(false); log.setBackground(Color.BLACK); logPane = new JScrollPane(log); kit = new HTMLEditorKit(); doc = new HTMLDocument(); log.setEditorKit(kit); log.setDocument(doc); DefaultCaret c = (DefaultCaret) log.getCaret(); c.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE); ClearLog(); // the preview panel previewPane = new DrawPanel(); previewPane.setPaperSize(paper_top, paper_bottom, paper_left, paper_right); // status bar statusBar = new StatusBar(); Font f = statusBar.getFont(); statusBar.setFont(f.deriveFont(Font.BOLD, 15)); Dimension d = statusBar.getMinimumSize(); d.setSize(d.getWidth(), d.getHeight() + 30); statusBar.setMinimumSize(d); // layout Splitter split = new Splitter(JSplitPane.VERTICAL_SPLIT); split.add(previewPane); split.add(logPane); split.setDividerSize(8); contentPane.add(statusBar, BorderLayout.SOUTH); contentPane.add(split, BorderLayout.CENTER); // open the file if (recentFiles[0].length() > 0) { OpenFileOnDemand(recentFiles[0]); } // connect to the last port ListSerialPorts(); if (Arrays.asList(portsDetected).contains(recentPort)) { OpenPort(recentPort); } return contentPane; }
/** * @param className объект класса, позицию фрейма которого нужно получить * @return координату фрейма */ public Point getWindowLocation(Class className) { if (locationWindows == null) locationWindows = new HashMap<>(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension frameSize = getWindowSize(className); if (!locationWindows.containsKey(className)) { Integer x = (int) (screenSize.width / 2 - frameSize.getWidth() / 2); Integer y = (int) (screenSize.height / 2 - frameSize.getHeight() / 2); locationWindows.put(className, new Point(x, y)); } Point point = locationWindows.get(className); if (screenSize.getWidth() < point.getX() + frameSize.getWidth() || screenSize.getHeight() < point.getY() + frameSize.getHeight()) { Integer x = (int) (screenSize.width / 2 - frameSize.getWidth() / 2); Integer y = (int) (screenSize.height / 2 - frameSize.getHeight() / 2); point = new Point(x, y); locationWindows.put(className, point); } return point; }
private void updateUIState(ParamChangeEvent event) { if (updatingUI.compareAndSet(false, true)) { try { if (event != null && canUseGeoCoordinates(product)) { final String parmName = event.getParameter().getName(); if (parmName.startsWith("geo_")) { final GeoPos geoPos1 = new GeoPos((Float) paramNorthLat1.getValue(), (Float) paramWestLon1.getValue()); final GeoPos geoPos2 = new GeoPos((Float) paramSouthLat2.getValue(), (Float) paramEastLon2.getValue()); updateXYParams(geoPos1, geoPos2); } else if (parmName.startsWith("source_x") || parmName.startsWith("source_y")) { syncLatLonWithXYParams(); } } int x1 = ((Number) paramX1.getValue()).intValue(); int y1 = ((Number) paramY1.getValue()).intValue(); int x2 = ((Number) paramX2.getValue()).intValue(); int y2 = ((Number) paramY2.getValue()).intValue(); int sx = ((Number) paramSX.getValue()).intValue(); int sy = ((Number) paramSY.getValue()).intValue(); updateSubsetDefRegion(x1, y1, x2, y2, sx, sy); Dimension s = productSubsetDef.getSceneRasterSize( product.getSceneRasterWidth(), product.getSceneRasterHeight()); subsetWidthLabel.setText(String.valueOf(s.getWidth())); subsetHeightLabel.setText(String.valueOf(s.getHeight())); int sliderBoxX1 = x1 / thumbNailSubSampling; int sliderBoxY1 = y1 / thumbNailSubSampling; int sliderBoxX2 = x2 / thumbNailSubSampling; int sliderBoxY2 = y2 / thumbNailSubSampling; int sliderBoxW = sliderBoxX2 - sliderBoxX1 + 1; int sliderBoxH = sliderBoxY2 - sliderBoxY1 + 1; Rectangle box = getScaledRectangle(new Rectangle(sliderBoxX1, sliderBoxY1, sliderBoxW, sliderBoxH)); imageCanvas.setSliderBoxBounds(box); } finally { updatingUI.set(false); } } }
public void setFrame() { f = new JFrame("数据通讯参数设置"); // 获取屏幕分辨率的工具集 Toolkit tool = Toolkit.getDefaultToolkit(); // 利用工具集获取屏幕的分辨率 Dimension dim = tool.getScreenSize(); // 获取屏幕分辨率的高度 int height = (int) dim.getHeight(); // 获取屏幕分辨率的宽度 int width = (int) dim.getWidth(); // 设置位置 f.setLocation((width - 300) / 2, (height - 400) / 2); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); f.setContentPane(this); f.setSize(320, 260); f.setResizable(false); lblIP = new JLabel("主机名"); txtIp = new JTextField(20); try { InetAddress addr = InetAddress.getLocalHost(); txtIp.setText(addr.getHostAddress().toString()); } catch (Exception ex) { } lblNo = new JLabel("端口号"); cmbNo = new JComboBox(); cmbNo.setEditable(true); cmbNo.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { cmbNo.removeAllItems(); CommPortIdentifier portId = null; Enumeration portList; portList = CommPortIdentifier.getPortIdentifiers(); while (portList.hasMoreElements()) { portId = (CommPortIdentifier) portList.nextElement(); cmbNo.addItem(portId.getName()); } } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } @Override public void popupMenuCanceled(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } }); lblName = new JLabel("工程名"); txtProjectName = new JComboBox(); txtProjectName.setEditable(true); txtProjectName.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { txtProjectName.removeAllItems(); Mongo m1 = null; try { m1 = new Mongo(txtIp.getText().toString(), 27017); } catch (UnknownHostException ex) { ex.printStackTrace(); } for (String name : m1.getDatabaseNames()) { txtProjectName.addItem(name); } m1.close(); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } @Override public void popupMenuCanceled(PopupMenuEvent e) { // To change body of implemented methods use File | Settings | File Templates. } }); lblBote = new JLabel("波特率"); cmbBote = new JComboBox(); cmbBote.addItem(9600); cmbBote.addItem(19200); cmbBote.addItem(57600); cmbBote.addItem(115200); lblLength = new JLabel("数据长度"); cmbLength = new JComboBox(); cmbLength.addItem(8); cmbLength.addItem(7); lblParity = new JLabel("校验"); cmbParity = new JComboBox(); cmbParity.addItem("None"); cmbParity.addItem("Odd"); cmbParity.addItem("Even"); lblStopBit = new JLabel("停止位"); cmbStopBit = new JComboBox(); cmbStopBit.addItem(1); cmbStopBit.addItem(2); lblDelay = new JLabel("刷新"); txtDelay = new JTextField(20); btnOk = new JButton("确定"); btnOk.addActionListener( new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { paramIp = txtIp.getText().toString(); paramName = txtProjectName.getSelectedItem().toString(); paramNo = cmbNo.getSelectedItem().toString(); paramBote = Integer.parseInt(cmbBote.getSelectedItem().toString()); parmLength = Integer.parseInt(cmbLength.getSelectedItem().toString()); parmParity = cmbParity.getSelectedIndex(); parmStopBit = Integer.parseInt(cmbStopBit.getSelectedItem().toString()); parmDelay = Integer.parseInt(txtDelay.getText().toString()); if (!paramName.equals("") && !paramNo.equals("")) { receiveData( paramIp, paramName, paramNo, paramBote, parmLength, parmParity, parmStopBit, parmDelay); } else { } } }); btnCancel = new JButton("取消"); btnCancel.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); JPanel p1 = new JPanel(); p1.setLayout(new GridLayout(9, 2)); p1.add(lblIP); p1.add(txtIp); p1.add(lblNo); p1.add(cmbNo); p1.add(lblName); p1.add(txtProjectName); p1.add(lblBote); p1.add(cmbBote); p1.add(lblLength); p1.add(cmbLength); p1.add(lblParity); p1.add(cmbParity); p1.add(lblStopBit); p1.add(cmbStopBit); p1.add(lblDelay); p1.add(txtDelay); txtDelay.setText("500"); p1.add(btnOk); p1.add(btnCancel); p1.validate(); f.add(p1); f.validate(); }